I asked a similar question a while back and never really got an answer, so I'll try again...
I have an application that has a component that works like DropBox. The user puts a file into a folder and it's copied to the server. Then all other users clients will download the file.
I need to determine the correct way of getting the file onto the server. The file will either be copied to the server or FTP'd in.
I need to determine when to use FTP. Obviously if the user is not connected to the network, then the file needs to be FTP'd in. For example, if the user takes their laptop home or on the road - away from the office - they they are not "connected" to the network and FTP needs to be used.
However, if the user is sitting at a desk in the office, then they are "connected" to the network.
The question is: How do I make the determination to FTP the file or just copy it? How can the app know if it's directly connected to the network?
One way you could accomplish this would be to check the DNS resolution of the server. If it resolves to an internal address, then the client is local and would be capable of performing a direct copy.
You could also just simply try the copy, or a less intensive get directory listing using the file path in your application. If that fails, failover to ftp transfer.
Is ftp available both internally and externally? If so, it would probably be simpler to utilize it for both transfers. It seems to me that it really wouldn't matter how the file got to the server as long as it was on the server.
Overkill is implementing more than one server and switching on detection of a network.
Just FTP it and you don't have to worry about the connection type at all.
Checking DNS resolution is probably not a good idea. DNS results are normally cached. Checking for active known company gateway addresses is probably a better bet, but if you just implement FTP, who cares?
thinking out loud, ip address range 10.b.c.d, 172.16.c.d, 192.168.c.d for instance and/or a dynamic dns check - Im pretty sure I could 99% of the time give a correct answer. I actually have software that checks the network interfaces in use from a PC and if it's the local wifi connection then 'probes' a set of addresses to see which MySQL server is up .. maybe the same approach would help Kevin
I have a web app where users can add any style property they want to the Style attribute of any DOM element on a web page.
The ID and the Style attributes of each DOM element are used to create a JSON array and sent to the backend to be converted into Dotnet objects. Then the deserialized data are used to create or update a CSS file.
The problem is I don't know ahead of time which properties of the Style attribute the user of my app will add to the JSON array.
I can't help but think that a quick and dirty way to accomplish this would be to use a dynamic type to call JsonConvert.DeserializeObject (if you're using JSON.NET), and then use a little bit of reflection to pick out the public properties from here.
The in-build JSON functionality isn't great at these kinds of things. If you use a third party parser like Newtonsoft[^] it supports dynamic JSON better as it will build a collection of objects from the JSON that you can then traverse.
Without the containing object, you will find your properties in the Key/Value pairs of the outer loop.
The way I got to all of this kind of stuff (I'm reading JSON from tmdb.org) was setting up this kind of test in a small console app, and using the debugger to step through and look at each of the JObject, JToken, and JProperty objects as it went through. I managed to get how it all holds together pretty quickly that way.
i am working with EF code first. so initially i have no tables in database. so i wrote some class and when query those class then i saw EF code first create those tables in db but when i create sql server view in db and later map that view with my code in c# & EF project and when i try to query that view then i was getting error message.
Additional information: The model backing the 'TestDBContext' context has changed since the database was created. Consider using Code First Migrations to update the database
i understand that EF is telling me to do the migration but if i migrate then EF will create that view in db again when the view is in db already exist.
so tell me how could i inform EF that my view is already is in db so migration is not required.
please guide me. thanks
EF Code first does not support views, and you cannot use views as entities. If you tried to do that, it would explain the message. It's designed so that if you want a view you can define a view model and load it with an IQueryable in order to handle projections, rather than DB side code objects.
If you want to map views, you'll need toshould do Database First so that it can lean on an .edmx mapping.
Edit: Corrected content based on Mr Deeming's answer.
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
EF Code first does not support views, and you cannot use views as entities.
Yes it does, and yes you can.
You can't create a view through automatic migrations, but a manual migration with the CREATE / DROP VIEW commands will work fine.
Configure the mapping from the entity to the view, and EF won't know the difference.
The only problem you might encounter is if your view isn't updateable, and you need to add, update or remove entities from it. In that case, you'd need to use MapToStoredProcedures[^] to map the insert, updated and delete commands to stored procedures.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer