How do you store user app data in .net core console app - console-application

My scenario is I'm building a small cli app that I want to be able store user specific data in some kind of user local cache.
I guess I'm looking for something similar to the Environment.SpecialFolder.ApplicationData path, but in dotnet core and cross platform friendly.

I know it is not exactly the same, but I solved it by storing the data in the application folder like so:
var userDataPath = Path.Combine(AppContext.BaseDirectory, "userdata.json");
Of course you can also take a subfolder of AppContext.BaseDirectory.

Related

Apex Oracle : How to get image URL?

I'm running Apex 19.2 on Oracle 18c and I would like to get some images URL to show them in the application. The images are stored in the database as blob (not static images).
For the moment what I did is creating an ORDS Restfull Service that connects to database and load the images. The images are then accessible via an URL that I insert in my pages
<img src="URL to my Restfull service module with the image identifier">
This works well but I find it quite complex and most importantly, it's very slow and doesn't cache the image. Whenever I load the page I have to wait for the image to load (even though it's very small : 50kb)
Does anyone have a solution for this please ? Is there any Apex out of the box solution like for static imaes ?
Thanks,
Cheers
There is no direct method to expose BLOBs to the end user as it would be kind of complicated to secure these files. I can suggest the following two methods:
Use the code just like you did it, but consider putting it in an application process. This way, you can use all your session variables directly. You will then be able to generate a link that does exactly what you want, or call the process from a button or branch. There is a nice tutorial here:
https://oracle-base.com/articles/misc/apex-tips-file-download-from-a-button-or-link
Using APEX_UTIL.GET_BLOB_FILE_SRC
This function only works out of a apex session and requires you to set up an application page with an item that holds a primary key to your table. I doubt that this is what you want.
Note that APEX_MAIL.GET_IMAGES_URL does not work for your use case - this only works for files in your shared components application files or workspace files.
I actually like your approach, because it may be more lightweight than 1). That the image gets loaded again every time probably does not depend on the method you are using. I guess it is more likely due to the headers you are sending out. Take a look at the cache-control headers on this page:
https://developer.mozilla.org/de/docs/Web/HTTP/Headers/Cache-Control
Maybe check out APEX_MAIL.GET_IMAGES_URL
It is supposed to do essentially what you need so perhaps you can use it.

Django multiple Project using same database tables

I've been reading through related articles regarding using same database for multiple django projects however, I have not been able to come up with a fix yet.
I've tried relative and absolute pathing when importing but it gives "attempted relative import beyond top-level package" error when I try to access parent directory.
Project 1 gets the users to write to database by filling in a form and Project 2 retrieves data written in by users from database.
I'm using Postgresql for database. I've tried writing exactly same models.py for both projects but it seems like in database they appear as separate relations/tables. E.g. for table named school in both models.py, it would look like project1_school and project2_school in Postgres database.
Is there a way to write to and read from same tables of same database?
Thank you so much in advance.
I think that you might be confuse with the difference between Projects and Applications.
Projects vs. apps
What’s the difference between a project and an app? An app is a Web application that does something – e.g., a Weblog system, a database of public records or a small poll app. A project is a collection of configuration and apps for a particular website. A project can contain multiple apps. An app can be in multiple projects.
Writing your first Django app, part 1
So in you particular case, I would say that your actual projects, both of them, could be applications of one project. The main reason, why I think this is a better approach, is that both are gonna use the same data, one application writes while the other retrieve it. One could even argue that they actually could be the same application. But this may depend on many factors of your business.
BTW, is really hard for me to imagine a situation where it would be a good idea to have two projects using the same database. Even if both projects need to share data, I would not think in using on database. I would try to solve it at an application level. But I you need for some reason to share information at database level, there are tools to connect both databases.

Deploying Django as standalone internal app?

I'm developing an tool using Django for internal use at my organization. It's used to search and tag documents (using Haystack and Solr), and will be employed on different projects. My team currently has a working prototype and we want to deploy it 'in the wild.'
Our security environment is strict. Project documents are located on subfolders on a network drive, and access to these folders is restricted based on users' Windows credentials (we also have an MS SQL server that uses the same credentials). A user can only access the projects they are involved in. Since we're an exclusively Microsoft shop, if we want to deploy our app on the company intranet, we'll need to use an IIS server to deal with these permissions. No one on the team has the requisite knowledge to work with IIS, Active Directory, and our IT department is already over-extended. In short, we're not web developers and we don't have immediate access to anybody experienced.
My hacky solution is to forgo IIS entirely and have each end user run a lightweight server locally (namely, CherryPy) while each retaining access to a common project-specific database (e.g. a SQLite DB living on the network drive or a DB on the MS SQL server). In order to use the tool, they would just launch an all-in-one batch script and point their browser to 127.0.0.1:8000. I recognize how ugly this is, but I feel like it leverages the security measures already in place (note that never expect more than 10 simultaneous users on a given project). Is this a terrible idea, and if so, what's a better solution?
I've dealt with a similar situation (primary development was geared toward a normal deployment situation, but some users have a requirement to use the application on a standalone workstation). Rather than deploy web and db servers on a standalone workstation, I just run the app with the Django internal development server and a SQLite DB. I didn't use CherryPy, but hopefully this is somewhat useful to you.
My current solution makes a nice executable for users not familiar with the command line (who also have trouble remembering the URL to put in their browser) but is also relatively easy development:
Use PyInstaller to package up the Django app into single executable. Once you figure this out, don't continue to do it by hand, add it to your continuous integration system (or at least write a script).
Modify the manage.py to:
Detect if the app is frozen by PyInstaller and there are no arguments (i.e.: user executed it by double clicking it) and if so, then run execute_from_command_line(..) with arguments to start the Django development server.
Right before running the execute_from_command_line(..), pop off a thread that does a time.sleep(2) (to let the development server come up fully) and then webbrowser.open_new("http://127.0.0.1:8000").
Modify the app's settings.py to detect if frozen and change things around such as the path to the DB server, enabling the development server, etc.
A couple additional notes.
If you go with SQLite, Windows file locking on network shares may not be adequate if you have concurrent writing to the DB; concurrent readers should be fine. Additionally, since you'll have different DB files for different projects you'll have to figure out a way for the user to indicate which file to use. Maybe prompt in app, or build the same app multiple times with different settings.py files. Variety of a ways to hit this nail...
If you go with MSSQL (or any client/server DB), the app will have to know the DB credentials (which means they could be extracted by a knowledgable user). This presents a security risk that may not be acceptable. Basically, don't try to have the only layer of security within the app that the user is executing. The DB credentials used by the app that a user is executing should only have the access that the user is allowed.

Qt cross platform safe way of storing data in an SQLite database?

I'm trying to figure out the safest way of storing chat history for my application on the clients computer. By "safe" I mean so that my application is allowed to actually read/write to the SQLite database. Clients will range from Windows, OS X and Linux users. So i need to find a way on each platform of determining where I'm allowed to create a SQLite database for storing the message history.
Problems I've run into in the past were for example when people used terminal clients for example Citrix where the users is not allowed to write to almost any directory. The drive is often a shared network drive.
Some ideas:
Include an empty database.db within my installer that contains prebuilt tables. And store the database next to my executable. However I'm almost certain that not all clients will be allowed to read/write here, for example Windows users who do not have admin rights.
Use QStandardPaths::writableLocation and create the database at the first run time
Locate the users home dir and create the database at the first run time
Any ideas if there is a really good solution to this problem?

Create a new website when installing web services

I'm trying to add a web setup project for my web services project to make a reasonably complex installation easier for the end user. But the defaults are getting in my way and I'm not sure how to adjust them.
My requirements are:
Create a new website & app pool
When creating the new app pool, needs to be set to .Net 4, classic mode with user selectable user account to run the app pool
Install the web service to a custom path under C:\Program Files\<comapany name>\Services folder to meet company standards
Create a SQL database adding a login & db_datawriter roles to the account selected for the app pool
Run SQL statement to build initial database
Creating a SQL database and Logins (4 & 5) seems possible through Custom Actions as I'll get to run my code at install time. But the web setup project by default only allows users to select from existing websites and app pools (1 & 2) and doesn't seem to allow me to customise this process except to add an image, this also means that the physical path for the selected website is used.
An option would be to create a suitable website & app pool prior to installation and remove it if it goes unused, then the user would simply need to select the website/app-pool I've created for them (not ideal but..) but there isn't a pre-installation step for me to attach such custom code to and I'm not sure how to interface with IIS reliably & programmatically.
Can anyone suggest the best way for me to approach creating the installer outlined above as I don't think web setup projects are fit for purpose at this stage, but would prefer not to have to waste a day learning WIX or NSIS.
1 & 3) Creating a new app pool isn't possible as there is no way to run custom code pre-installation in web setup projects, in my case it turned out to be acceptable for a user to create the website/app pool in IIS before installation. You can modify the Virtual Directory of the existing site through Microsoft.Web.Administration.dll (got the idea from here) if desired, by passing [TARGETSITE] to CustomActionData so you can find the Application object needed to modify the Virtual Directory.
2) This is achieved by referencing the Microsoft.Web.Administration.dll (got the idea from here) and using it to change application pool properties, you will need to pass the appPool name to the Custom action by adding /AppPool="[TARGETAPPPOOL]" to the CustomActionData for the CustomAction.
FYI - The available properties you may pass to CustomActionData are documented here but are incomplete (excluding [TARGETAPPPOOL] and [TARGETSITE] for example)
I used this code to modify the app pool:
Microsoft.Web.Administration.ServerManager serverManager = new ServerManager();
var appPoolName = base.Context.Parameters["AppPool"].ToString();
var appPool = serverManager.ApplicationPools.SingleOrDefault( pool => pool.Name == appPoolName );
appPool.ManagedRuntimeVersion = "v4.0";
appPool.ManagedPipelineMode = ManagedPipelineMode.Classic;
serverManager.CommitChanges();
4 - 5) Simply open a SQL Connection from a custom action and run the relevant SQL Scripts, you won't be able to add the true accounts ie: NT AUTHORITY\NETWORK SERVICE or NT AUTHORITY\ANONYMOUS, but may use the virtual user accounts IIS creates IIS APPPOOL\<app pool name>.
If you need to develop a sophisticated installer but don't want to spend even a day learning installer technologies then your best bet is probably to hire a consultant to do it for you.