I am not a developer, so explain it like I am five. Does not have to go into detail, just point me in a direction I will spend the next 2-4 weeks of free time (hopefully) trying to work through it.
Our retail system runs on a UniData database, commands include "listuser" "kill __" etc.
We have a web service that can be seen externally.
I want to make a rudimentary iOS app that can "listuser" and see output of connected users, read through the list, and type in a user name then send the "kill ___" command back through the web service to our server.
I created a batch file with the listuser command, then wrote some C# code that will pass output into XML document, I just want to be able to trigger this & load the XML from my iOS app.
public XmlDocument ListUnidataUser(string VisibleStores)
{
Process p = new Process();
// Redirect the output stream of the child process.
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = #"\\server\c$\ud\listuser.bat";
p.Start();
// Do not wait for the child process to exit before
// reading to the end of its redirected stream.
// p.WaitForExit();
// Read the output stream first and then wait.
string output = p.StandardOutput.ReadToEnd();
XmlDocument xml = new XmlDocument();
xml.LoadXml(output);
p.WaitForExit();
return xml;
}
After this, I have no idea what I am doing. This goes in our web service, which can see these local servers, then the web service holds that XML. How do I make a connection from an external app?
If it is easier to learn, I wouldn't mind trying first to make C# code that can be run externally to grab this, and using a service like Xamarin to compile it for iOS, but I am curious to feel my way around Xcode as well.
Please don't flame me, I can hear the jimmies rustling by my approach to coding this.
It's always good to learn something new, and I for one think that the iOS framework really has a good structure - so good luck.
As for your problem:
If possible for you, don't use XML as data protocol - mobile frameworks are much better at interpreting JSON, it's even integrated in the language itself (NSJSONSerializer for example) or you get good libraries for it.
For contacting your Webservice, have a look at NSURLSession or, if you prefer a library with some more functionality, AFNetworking (or AlamoFire if you're using Swift.
In general, look at some tutorials on the Ray Wenderlich website - they are great for learning about developing for iOS, eg the one on AlamoFire.
Related
I used Keras in Python to design a neural network calculating something like a noise-reducing-function. It works pretty good so far, and now I want to use this network to clean the data inside a Unity-Project of mine.
I would not have thought that this could be so difficult. I could only find one python interpreter in the asset store, which does not support external python librarys. IronPython is not an option either, because I need to include the Keras Packages.
I found a KerasSharp Project on GitHub, but there is no documentation on how to load an already trained network, and training it at the beginning is not an option. Furthermore it seems like there is no one working on the project anymore, due to the commit history and unanswered questions. Accessing the script via network APIs is probably not an good option either, due to the latency. I need the calculation for every frame.
So my question is: Is there any way I can load a Keras/Tensorflow model in C# or Unity
OR
Can I somehow access the python script which is calculating the noise-reducing-function using the Keras model?
If your situation allows for you to start the python script after Unity, you can try starting the python script as a subprocess as described here:
http://answers.unity.com/answers/14156/view.html
If you do not require the other process to be running before the Unity
one, you could have your Unity project launch that via Process and
then redirect stdin/out to streams and communicate through these.
Example:
Process otherProcess = new Process ();
otherProcess.StartInfo.FileName = path;
otherProcess.StartInfo.CreateNoWindow = true;
otherProcess.StartInfo.UseShellExecute = false;
otherProcess.StartInfo.RedirectStandardInput = true;
otherProcess.StartInfo.RedirectStandardOutput = true;
// Now communicate via streams
// otherProcess.StandardOutput
// and
// otherProcess.StandardInput
It is also possible that grabbing a running process by name or pid and
then setting the forwarding would work, but I've not tested this and
it does seem rather doubtful.
This setup would require that your python script be able to take in data from standard in, and output its results over standard out.
I am trying to solve a difficult task, for part of which a console application was written several years ago. The source code of the console application has been lost and to rewrite it would most likely take several hundred hours. I have been able to use the console application by hacking it into the top level application using the following snippet:
solver = new Process();
solver.StartInfo.FileName = "HPTSolver.exe";
solver.StartInfo.UseShellExecute = false;
solver.StartInfo.RedirectStandardInput = true;
solver.Start();
I can then trigger the console application by providing the necessary input parameters via
solver.StandardInput.WriteLine("RunCalculation");
The result of the console application is saved out to a text file and in the top level application I currently wait for the file to be created before continuing:
while (!File.Exists("result.txt"))
Thread.Sleep(50);
So finally my question is related to this final part where I wait for the results file to be created. Although my current solution works it is clearly the most naive solution. Is there a better solution to detect the creation of the result file and allow the top level application to continue? I have already tried reading the standard output of the console application but data is only output when the application closes, so thats not an option.
Have you thought about using the FileSystemWatcher?
MSDN Link
Hope that helps
Paul
What about waiting for the console application to exit?
solver = new Process();
solver.StartInfo.FileName = "HPTSolver.exe";
solver.StartInfo.UseShellExecute = false;
solver.StartInfo.RedirectStandardInput = true;
solver.Start();
solver.WaitForExit()
Or you could grab the StdOut and watch for specific messages.
I wrote an application a while ago in C# NET that basically allows the .exe I created to start/stop when the java application (Minecraft) starts and stops.
I would like to extend some more functionality to my application by basically allowing users to type commands into my console app, and in turn send these commands to the .jar file that is running.
I read something a while ago on stackoverflow that said there were some APIs that would basically let you manage Java apps inside of a C# NET app but I can't find it now.
Does anyone know how I could go about doing this?
If you launch and manage the java app from C# using the Process class, you can send input from your C# app to the launched java app process via Process.StandardInput.
Minecraft accepts commands from system in and responds to system out.
When you start minecraft from your application you basicly creates a new process. This process has two streams, one for system out and one for system in. You need to get hold of those streams. If you send characters to the system in stream, then they will be interpreted as commands to minecraft. If you read from the system out stream then you will get minecrafts response.
Your next task would be to let your users send commands to minecraft. One way to do this would be to let your users type in commands on a web page that you store in a file. You could have a separate thread read from the file and write the commands to minecraft's system in stream.
From searching I can see this has been asked time and time again, but not adequately enough, so here goes. I'm a hobbyist developer with no budget. A program I've been developing has been in need of regular bugfixes, and me and users are getting tired of having to manually update.
Me, because my current solution of updating a text file through FTP and my download links on the website, and then hoping users will see the "there's an update message", and finally getting them to then be bothered to manually download the update, well quite frankly, is abysmal.
Users, because, well, "Are you ever going to implement auto-update?" "Will there ever be an auto-update feature?" And if I happen to screw up the update process, pitchforks start arriving.
Over the past I have looked into:
WinSparkle - No in-app updates, and the DLL is 500 KB. My current solution is a few KBs in the executable and has no in-app updates.
.NET Application Update Component - Unfortunately I can't comprehend the documentation.
Eduardo Olivera's AutoUpdate - This doesn't appear to support anything other than working with files that aren't in use.
wyUpdate - wyBuild isn't free, and while the wyUpdate specification is available, it's simply too complex and time-consuming to go through.
AppLife Update - Ditto the last sentence.
ClickOnce - Workarounds for implementing launching on startup are massive, horrendous and not worth it for such a simple feature. Publishing is a pain; manual FTP and replace of all files is required for servers without FrontPage Extensions.
It's quite disappointing that the situation on Windows is like this when you've got really nice and simple implementations for Mac OS X like Sparkle.
Implement it yourself! It will be fun. Create a separate application that only contains update logic i.e., fetch the files online, download them, replace local files, and show that visually to the user.
So your main application could check for updates, and if they exist it would prompt the user with the possibility to update. If the user wants to, it will run the update program, close itself (so the update can happen) and presto.
The only things you need are readily avaliable in C#, FTP access and IO.
Edit: I know it's not something terribly easy, but it's a perfect chance to learn:
How to (properly) download files, in an abstracted way that can be extended to ftp, http, etc.
How to (properly) do a simple task over many files - copying or overwriting them (this implies error handling).
Practice (because there's no "proper" way) to layer and encapsulate a piece of software.
How to deal with the OS/other software (antivirus/firewall/etc) not cooperating.
These are all things we all need to know well - If it takes some weeks to code an updater it means you were needing some weeks of learning. If you don't need to learn, time to hone your skills! If you don't know if you need, time to find out! :)
Note: I know I do need to learn better file and network I/O
Should've updated this ages ago, oops!
But anyway, I've been using SparkleDotNET for a while now and it's been working absolutely wonderfully. There's a few little bugs here and there but I've already helped get some of them squashed, and hopefully I'll be able to get rid of the others too :)
For those who have the time to run the publish functionality of Visual Studio, and whose app is relatively self-contained, and doesn't require anything like launching on startup, I'd recommend ClickOnce for sure. MetroTwit uses it and it's got a nice in-app updater interface, so it seems flexible (at least to a certain degree). For launching on startup, it's possible to do so, but methods to do so are quite hacky and don't work that well.
You can try Autoupdater.NET from GitHub I developed it my self and it works very well in my applications. You just have to add one line in your code and it's done. Also, it is open source so you can modify and use as you want.
You even can not to develop an external application but implement it as your application's module, e.g. into namespace Update, and use dynamic assembly builder to generate an exe, start it and exit app main, start it again when update will be finished.
Some more info.
There is also DDay update which is open source and is used by one of my customers. We/they are primarily interested in it in the context of a windows service at it works reasonably well for that.
For a more powerful solution, you may want to look at Google Omaha. It's what Chrome uses. You can get both in-app and automatic updates in the background when your application isn't running.
Try with MD5-Update it is absolutely free and easy no configuration need in your app only add library and publish the files.
https://github.com/jrz-soft-mx/MD5-Update/
1. Your need a web server with PHP for publish your files please include updt.exe.
2. Add index.php for make list of update files. aviable on github repository https://github.com/jrz-soft-mx/MD5-Update/blob/main/Tools/Tools.zip o create new app with this code.
<?php
$_dat = array();
$_dir=new RecursiveDirectoryIterator(".");
foreach (new RecursiveIteratorIterator($_dir) as $_itm) {
$_fil = str_replace(".".DIRECTORY_SEPARATOR, "", $_itm);
if(!is_dir($_fil) && $_fil != "index.php"){
$_dat[]=array('StrFil' => "$_fil", 'StrMd5' => strtoupper(md5_file($_fil)), 'lonSiz' => filesize($_fil));
}
}
echo json_encode($_dat, JSON_UNESCAPED_UNICODE);
?>
3. Add nuget repository at your proyect
PM> Install-Package MD5.Update
4. Call the library when your app stars, with your update folder url, update all files and download your new app on updt folder, for replace your app need updt.exe
string strUrl = "http://yourdomain.com/app/";
if (MD5Update.MD5Update.Check(strUrl, true))
{
Process.Start(AppDomain.CurrentDomain.BaseDirectory + #"updt.exe", AppDomain.CurrentDomain.FriendlyName + " " + Process.GetCurrentProcess().ProcessName);
Application.Exit();
}
5. updt.exe for replace the current app with the new app updt folder to app. aviable on github repository https://github.com/jrz-soft-mx/MD5-Update/blob/main/Tools/Tools.zip o create new app with this code.
try
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
List<string> lisArg = Environment.GetCommandLineArgs().ToList();
if (lisArg.Count < 2)
{
MessageBox.Show("Please provide App Excutable Name and Procees name");
Application.Exit();
return;
}
string strAppName = lisArg[1];
string strAppProcees = lisArg[2];
Process[] lisPro = Process.GetProcessesByName(strAppProcees);
foreach (Process Pro in lisPro)
{
if (Pro.Id != Process.GetCurrentProcess().Id)
{
Pro.Kill();
Thread.Sleep(1000);
}
}
string strAppMain = AppDomain.CurrentDomain.BaseDirectory + strAppName;
string strAppUpdate = AppDomain.CurrentDomain.BaseDirectory + #"updt\" + strAppName;
if (!File.Exists(strAppMain))
{
MessageBox.Show("App Excutable dosent exists");
Application.Exit();
return;
}
if (!File.Exists(strAppUpdate))
{
MessageBox.Show("App Excutable Updated dosent exists");
Application.Exit();
return;
}
File.Copy(strAppUpdate, strAppMain, true);
long fileSize = 0;
FileInfo currentFile = new FileInfo(strAppMain);
while (fileSize < currentFile.Length)
{
fileSize = currentFile.Length;
Thread.Sleep(1000);
currentFile.Refresh();
}
Process.Start(strAppMain);
}
catch (Exception Ex)
{
MessageBox.Show("An error ocurred");
File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + #"updt_" + DateTime.Now.ToString("yyyyMMddTHHmmss") + " .txt", Ex.ToString());
Application.Exit();
}
all guys are right specially look at the abatishchev reply.but i think some thing other need that guy forgot it. try to develop your project "modular".put them your code in class library as you can.so during the fix operation replace one of them.think a bout database fix.some time you need to add a column to your database table.what do you do for these cases?
a have developed an update project.in that , i have three kind of fixes.
1- BUG in program operation and need to replace a DDL file
2- Bug in program and need to update currently program executive file
3- bug or change the database and need to execute a sql server query
in a table on web host i put the version history and every time that my app start check for new version.if any update exist check for its type and download it and do the suitable action depend on the update kind and parameters
good luck dude
I work for a company that makes application's in C#.
recently we got a customer asking us to look in to rebuilding an application written in PHP.
This application receives GPS data from car mounted boxes and processes that into workable information.
The manufacturer for the GPS device has a PHP class that parses the received information and extracts coordinates. We were looking in to rewriting the PHP class to a C# class so we can use it and adapt it. And here it comes, on the manufacturers website there is a singel line of text that got my skin krawling:
"The encoding format and contents of the transmitted data are subject to constant changes.
This is caused by implementations of additional features by new module firmware versions which makes it virtually impossible to document it and for you to properly decode it yourself."
So i am now looking for a option to use the "constantly changing" PHP class and access it in C#. Some thing link a shell only exposing some function's i need. Except i have no idea how i can do this. Can any one help me find a solution for this.
I know it's a really hacky solution, but if you need a bit of PHP code that you don't want to have to repeatedly port to C# each time, you could try the following approach, although it means that you would need the php command line tool on the target machine.
First step is to have a php script that continously reads data off stdin, decodes it using this special class from the vendor, and writes the result out to stdout. Really simple example:
<?php
include("VendorDecodingClass.php");
while(true)
{
$input = fgets(STDIN); //read off of the stdin stream
//can't remember if this is valid, but somehow check that there is some data
if($input)
{
//pass it off to the vendor decoding class
$output = VendorDecoding::decode($input);
fwrite(STDOUT, $output); //write the results back out
}
//sleep here so you don't suck up CPU like crazy
//(1 second may be a bit long tho, may want usleep)
//Edit: From Tom Haigh, fgets will block, so the sleep isn't necessary
//sleep(1);
}
?>
Anyway, once you have that in place, in your C# application, right at the start, create a new Process to run that script and then save the Process instance somewhere, so you can reference the STDIN and STDOUT at a later point. Example:
ProcessStartInfo procStartInfo = new ProcessStartInfo("php", "yourscript.php");
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
procStartInfo.CreateNoWindow = true;
Process proc = new Process(); //store this variable somewhere
proc.StartInfo = procStartInfo;
proc.Start();
Then, when you want to decode your data, you just write to the stdin of the php process you created, and wait for a response on the stdout. Using the stdin/stdout approach is a lot more efficient than creating a new process each time you want to decode some data, because the overhead of creating that process can be noticeable.
proc.StandardInput.WriteLine(somedata); //somedata is whatever you want to decode
//may need to wait here, or perhaps catch an exception on the next line?
String result = proc.StandardOutput.ReadLine();
//now result should contain the result of the decoding process
Disclaimer here, I haven't tested any of this code, but that is the general gist of how I might do it.
Something else I just thought of, you will want some mechanism for terminating that PHP process. It may be OK to use Process.Kill, but if the decoding does any file IO, or anything critical you may want to send an interrupt signal to the php script somehow.
I assume the php script is on your machine and returns usefull data. The first -not very elegant solution- that pops into my mind is the following:
Make sure your machine has the php commandline installed, so that you are able to run the php script from commandline. To execute a commandlinetool from C# see code for that here. The returned data now probably needs to get processed my your C# program.
I have never tried this and do not know anyone that has, but I remember comming across this sometime ago and thought I would throw it out there as a possible option for you.
Phalanger is a compiler project that compiles PHP code to IL, so you can use that then have a managed assembly that you reference from your code directly.
If the format is a regex you can try to put it in an application setting file (not resources, these are compiled WITH the application, you can't change them without recompiling the app).
Application settings are not changeable by the user but you can do that by editing the XML.
Or you can set the settings to user mode and then you can change the format from inside your application code.
Why don't you just launch the PHP script from C#, have it output its results to a file and then use that file as input for your C# program?
Personally, I would setup a PHP web service with a proper and stable API that the C# project can access, implement the manufacturers supplied PHP class in the web service and let it be.