private static void Main(string[] args) { string name = Assembly.GetExecutingAssembly().Location; string path = Path.GetDirectoryName(name); string cfgPath = Path.Combine(path, "../data/enviriot.xst"); int flag = Environment.UserInteractive ? 0 : 1; for (int i = 0; i < args.Length; i++) { if (string.IsNullOrWhiteSpace(args[i])) { continue; } if (args[i].Length > 1 && (args[i][0] == '/' || args[i][0] == '-')) { switch (args[i][1]) { case 's': flag = 1; break; case 'i': flag = 2; break; case 'u': flag = 3; break; } } else if (File.Exists(args[i])) { cfgPath = Path.GetFullPath(args[i]); } } Directory.SetCurrentDirectory(path); if (flag != 1) { if (!CSWindowsServiceRecoveryProperty.Win32.AttachConsole(-1)) // Attach to a parent process console { CSWindowsServiceRecoveryProperty.Win32.AllocConsole(); // Alloc a new console if none available } } int p = (int)Environment.OSVersion.Platform; _isLinux = (p == 4) || (p == 6) || (p == 128); if (flag == 0) { var srv = new Programm(cfgPath); if (srv.Start()) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Press Enter to Exit"); Console.ResetColor(); Console.Read(); srv.Stop(); } else { Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine("Enviriot start FAILED; press Enter to Exit"); Console.ResetColor(); Console.Read(); } Console.ForegroundColor = ConsoleColor.Gray; } else if (flag == 1) { try { HAServer.Run(cfgPath); } catch (Exception ex) { Log.Error("{0}", ex.ToString()); } } else if (flag == 2) { try { HAServer.InstallService(name); } catch (Exception ex) { Log.Error("{0}", ex.ToString()); } } else if (flag == 3) { try { HAServer.UninstallService(name); } catch (Exception ex) { Log.Error("{0}", ex.ToString()); } } }
private static void Main(string[] args) { string name=Assembly.GetExecutingAssembly().Location; string path=Path.GetDirectoryName(name); string cfgPath=Path.Combine(path, "../data/Server.xst"); int flag=Environment.UserInteractive?0:1; for(int i=0; i<args.Length; i++) { if(string.IsNullOrWhiteSpace(args[i])) { continue; } if(args[i].Length>1 && (args[i][0]=='/' || args[i][0]=='-')) { switch(args[i][1]) { case 's': flag=1; break; case 'i': flag=2; break; case 'u': flag=3; break; } } else if(File.Exists(args[i])) { cfgPath=Path.GetFullPath(args[i]); } } Directory.SetCurrentDirectory(path); if(flag!=1) { if(!CSWindowsServiceRecoveryProperty.Win32.AttachConsole(-1)) // Attach to a parent process console CSWindowsServiceRecoveryProperty.Win32.AllocConsole(); // Alloc a new console if none available } if(flag==0) { var srv=new Programm(cfgPath); if(srv.Start()) { Console.ForegroundColor=ConsoleColor.Green; Console.WriteLine("X13 Home automation server v.{0}", Assembly.GetExecutingAssembly().GetName().Version.ToString(4)); Console.WriteLine("Press Enter to exit"); Console.ResetColor(); Console.Read(); srv.Stop(); } else { Console.ForegroundColor=ConsoleColor.Magenta; Console.WriteLine("X13 Home automation server start FAILED; press Enter to Exit"); Console.ResetColor(); Console.Read(); } Console.ForegroundColor=ConsoleColor.Gray; } else if(flag==1) { try { HAServer.Run(cfgPath); } catch(Exception ex) { Log.Error("{0}", ex.ToString()); } } else if(flag==2) { try { HAServer.InstallService(name); } catch(Exception ex) { Log.Error("{0}", ex.ToString()); } } else if(flag==3) { try { HAServer.UninstallService(name); } catch(Exception ex) { Log.Error("{0}", ex.ToString()); } } }
public HAServer(string cfgPath) { InitializeComponent(); _instance = new Programm(cfgPath); }
public HAServer(string cfgPath) { InitializeComponent(); _instance=new Programm(cfgPath); }