Exemplo n.º 1
0
        private static bool UpdateInterfaceService(Hashtable paramTable)
        {
            string path = paramTable[IMParameter.InterfaceDirectory] as string;

            // update Adapter Service config
            AdapterServiceCfgMgt serviceMgt = new AdapterServiceCfgMgt();

            serviceMgt.FileName = path + "\\" + serviceMgt.FileName;
            if (serviceMgt.Load())
            {
                serviceMgt.Config.NotifyStatusToIM   = true;
                serviceMgt.Config.IMWindowCaption    = paramTable[IMParameter.IMCaption] as string;
                serviceMgt.Config.ConfigDBConnection = paramTable[IMParameter.ConfigDBConnection] as string;
                serviceMgt.Config.DataDBConnection   = paramTable[IMParameter.DataDBConnection] as string;
                serviceMgt.Config.ServiceName        = paramTable[IMParameter.ServiceName] as string;
                //US29442
                #region
                serviceMgt.Config.GarbageCollection.MaxRecordCountLimitation = 500;
                #endregion
                if (!serviceMgt.Save())
                {
                    GCError.SetLastError("Save config file failed. " + serviceMgt.FileName);
                    GCError.SetLastError(serviceMgt.LastError);
                    return(false);
                }
            }
            else
            {
                GCError.SetLastError("Load config file failed. " + serviceMgt.FileName);
                GCError.SetLastError(serviceMgt.LastError);
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
        public static bool SetServiceStatus(string serviceName, AdapterStatus status)
        {
            try
            {
                ServiceController sc = new ServiceController(serviceName);

                switch (status)
                {
                case AdapterStatus.Running:
                    sc.Start(new string[] { AdapterConfigArgument.InIM });
                    sc.WaitForStatus(ServiceControllerStatus.Running, new TimeSpan(0, 0, 0, 0, TimeOut));
                    break;

                case AdapterStatus.Stopped:
                    sc.Stop();
                    sc.WaitForStatus(ServiceControllerStatus.Stopped, new TimeSpan(0, 0, 0, 0, TimeOut));
                    break;
                }

                return(true);
            }
            catch (Exception err)
            {
                GCError.SetLastError("Set service status failed. service name: " + serviceName + " status: " + status.ToString());
                GCError.SetLastError(err);
                return(false);
            }
        }
Exemplo n.º 3
0
        private static bool UpdateInterfaceScript(Hashtable paramTable, DeviceDir directory, DeviceFileType type, bool essentialFile)
        {
            DeviceFile[] files = directory.Files.FindFiles(type);

            if (files == null || files.Length < 1)
            {
                if (essentialFile)
                {
                    GCError.SetLastError("Cannot find script file of type: " + type.ToString());
                    return(false);
                }
                else
                {
                    return(true);
                }
            }

            foreach (DeviceFile file in files)
            {
                if (!UpdateInterfaceScript(paramTable, file, type, essentialFile))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 4
0
        private static bool UpdateInterfaceConfig(Hashtable paramTable)
        {
            string path = paramTable[IMParameter.InterfaceDirectory] as string;

            //update Adapter Config config
            AdapterConfigCfgMgt configMgt = new AdapterConfigCfgMgt();

            configMgt.FileName = path + "\\" + configMgt.FileName;
            if (configMgt.Load())
            {
                configMgt.Config.ConfigDBConnection = paramTable[IMParameter.ConfigDBConnection] as string;
                configMgt.Config.DataDBConnection   = paramTable[IMParameter.DataDBConnection] as string;
                if (!configMgt.Save())
                {
                    GCError.SetLastError("Save config file failed. " + configMgt.FileName);
                    GCError.SetLastError(configMgt.LastError);
                    return(false);
                }
            }
            else
            {
                GCError.SetLastError("Load config file failed. " + configMgt.FileName);
                GCError.SetLastError(configMgt.LastError);
                return(false);
            }

            return(true);
        }
Exemplo n.º 5
0
        public static bool ExecuteAssemblyDirectly(string filename, string arg)
        {
            try
            {
                _process = null;

                ProcessStartInfo pi = new ProcessStartInfo();
                pi.WorkingDirectory = Path.GetDirectoryName(filename);
                pi.FileName         = filename;
                pi.Arguments        = arg;

                //Process proc = Process.Start(filename,arg);
                Process proc = Process.Start(pi);
                if (proc != null)
                {
                    proc.EnableRaisingEvents = false;
                    _process = proc;
                    return(true);
                }
                else
                {
                    GCError.SetLastError("Cannot start process." + filename + " " + arg);
                    return(false);
                }
            }
            catch (Exception err)
            {
                GCError.SetLastError("Start process failed." + filename + " " + arg);
                GCError.SetLastError(err);
                return(false);
            }
        }
Exemplo n.º 6
0
        public static GCDeviceCollection LoadDeviceDirectory(string devicePath)
        {
            if (!IsDevicePath(devicePath))
            {
                return(null);
            }

            try
            {
                GCError.ClearLastError();
                GCDeviceCollection dlist      = new GCDeviceCollection();
                string[]           subFolders = Directory.GetDirectories(devicePath);
                foreach (string sf in subFolders)
                {
                    string   folder = devicePath + "\\" + sf;
                    GCDevice device = LoadDevice(folder);
                    dlist.Add(device);
                }
                return(dlist);
            }
            catch (Exception e)
            {
                GCError.SetLastError(e);
                return(null);
            }
        }
Exemplo n.º 7
0
        public static bool DeleteDevice(string devicePath)
        {
            try
            {
                if (!Directory.Exists(devicePath))
                {
                    return(true);
                }

                string[] subDirs = Directory.GetDirectories(devicePath);
                foreach (string dir in subDirs)
                {
                    if (!DeleteDevice(dir))
                    {
                        return(false);
                    }
                }

                string[] files = Directory.GetFiles(devicePath);
                foreach (string f in files)
                {
                    File.Delete(f);
                }

                Directory.Delete(devicePath);
                return(true);
            }
            catch (Exception e)
            {
                GCError.SetLastError(e);
                return(false);
            }
        }
Exemplo n.º 8
0
 private static object GetStatus(string serviceName)
 {
     try
     {
         ServiceController sc = new ServiceController(serviceName);
         return(sc.Status);
     }
     catch (Exception err)
     {
         GCError.SetLastError("Get service status failed. service name: " + serviceName);
         GCError.SetLastError(err);
         return(null);
     }
 }
Exemplo n.º 9
0
        private static bool UpdateInterfaceScript(Hashtable paramTable, DeviceFile file, DeviceFileType type, bool essentialFile)
        {
            if (file == null)
            {
                if (essentialFile)
                {
                    GCError.SetLastError("Cannot find script file of type: " + type.ToString());
                    return(false);
                }
                else
                {
                    return(true);
                }
            }

            string path     = paramTable[IMParameter.InterfaceDirectory] as string;
            string filename = path + "\\" + file.Location;

            try
            {
                string str = "";

                using (StreamReader sr = File.OpenText(filename))
                {
                    str = sr.ReadToEnd();
                }

                foreach (DictionaryEntry de in paramTable)
                {
                    string key   = de.Key as string;
                    string value = de.Value as string;
                    str = str.Replace(key, value);
                }

                using (StreamWriter sw = File.CreateText(filename))
                {
                    sw.Write(str);
                }

                return(true);
            }
            catch (Exception err)
            {
                GCError.SetLastError("Error when processing file: " + filename);
                GCError.SetLastError(err);
                return(false);
            }
        }
Exemplo n.º 10
0
 public static bool SetServiceStartStyle(string serviceName, int code)
 {
     try
     {
         using (RegistryKey key = Registry.LocalMachine.OpenSubKey
                                      ("SYSTEM\\CurrentControlSet\\Services\\" + serviceName, true))
         {
             key.SetValue("Start", code, RegistryValueKind.DWord);
         }
         return(true);
     }
     catch (Exception err)
     {
         GCError.SetLastError("Set service start style failed. service name: " + serviceName);
         GCError.SetLastError(err);
         return(false);
     }
 }
Exemplo n.º 11
0
        public static bool SaveDevice(IDevice device)
        {
            if (device == null)
            {
                return(false);
            }

            try
            {
                GCError.ClearLastError();
                return(_SaveDeviceDir(device));
            }
            catch (Exception e)
            {
                GCError.SetLastError(e);
                return(false);
            }
        }
Exemplo n.º 12
0
        public static GCDevice LoadDevice(string devicePath)
        {
            if (!IsDevicePath(devicePath))
            {
                return(null);
            }

            try
            {
                GCError.ClearLastError();
                DeviceDir dir = _LoadDeviceDir(devicePath);
                return(new GCDevice(dir, devicePath));
            }
            catch (Exception e)
            {
                GCError.SetLastError(e);
                return(null);
            }
        }
Exemplo n.º 13
0
        public static bool UpdateDBConnection(string interfacesPath, string dataDB, string configDB)
        {
            string[] pathList = Directory.GetDirectories(ConfigHelper.GetFullPath(interfacesPath));
            if (pathList == null)
            {
                return(false);
            }

            foreach (string path in pathList)
            {
                AdapterServiceCfgMgt mgtSerivce = new AdapterServiceCfgMgt();
                mgtSerivce.FileName = path + "\\" + mgtSerivce.FileName;
                if (mgtSerivce.Load())
                {
                    mgtSerivce.Config.DataDBConnection   = dataDB;
                    mgtSerivce.Config.ConfigDBConnection = configDB;
                    if (!mgtSerivce.Save())
                    {
                        GCError.SetLastError(mgtSerivce.LastError);
                        return(false);
                    }
                }
                else
                {
                    GCError.SetLastError(mgtSerivce.LastError);
                    return(false);
                }

                AdapterConfigCfgMgt mgtConfig = new AdapterConfigCfgMgt();
                mgtConfig.FileName = path + "\\" + mgtConfig.FileName;
                if (mgtConfig.Load())
                {
                    mgtConfig.Config.DataDBConnection   = dataDB;
                    mgtConfig.Config.ConfigDBConnection = configDB;
                    if (!mgtConfig.Save())
                    {
                        GCError.SetLastError(mgtConfig.LastError);
                        return(false);
                    }
                }
                else
                {
                    GCError.SetLastError(mgtConfig.LastError);
                    return(false);
                }

                AdapterMonitorCfgMgt mgtMonitor = new AdapterMonitorCfgMgt();
                mgtMonitor.FileName = path + "\\" + mgtMonitor.FileName;
                if (mgtMonitor.Load())
                {
                    mgtMonitor.Config.DataDBConnection   = dataDB;
                    mgtMonitor.Config.ConfigDBConnection = configDB;
                    if (!mgtMonitor.Save())
                    {
                        GCError.SetLastError(mgtMonitor.LastError);
                        return(false);
                    }
                }
                else
                {
                    GCError.SetLastError(mgtMonitor.LastError);
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 14
0
        public bool ExecuteAssembly(string filename, string arg, bool showForm)
        {
            try
            {
                Form          dlg = null;
                TextBox       tb  = null;
                StringBuilder sb  = new StringBuilder();

                string str1 = "---------------- Invoking Begin " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToLongTimeString() + "----------------\r\n";
                string str2 = "Command: " + filename + "\r\n";
                string str3 = "Argument: " + arg + "\r\n";
                sb.Append(str1).Append(str2).Append(str3);

                if (showForm)
                {
                    dlg            = new Form();
                    dlg.Text       = "Executing Command...";
                    dlg.Size       = new Size(500, 500);
                    dlg.ControlBox = false;
                    tb             = new TextBox();
                    tb.Dock        = DockStyle.Fill;
                    tb.BackColor   = Color.Black;
                    tb.ForeColor   = Color.White;
                    tb.ScrollBars  = ScrollBars.Vertical;
                    tb.WordWrap    = true;
                    tb.Multiline   = true;
                    dlg.Controls.Add(tb);
                    //dlg.Owner = this;
                    dlg.TopMost = true;
                    dlg.Cursor  = Cursors.WaitCursor;
                    dlg.Show();

                    tb.Text += str1 + str2 + str3;
                    Application.DoEvents();
                }

                ProcessStartInfo psi = new ProcessStartInfo(filename, arg);
                psi.WorkingDirectory       = Path.GetDirectoryName(filename);
                psi.RedirectStandardOutput = true;
                psi.RedirectStandardError  = true;
                psi.UseShellExecute        = false;
                psi.CreateNoWindow         = true;

                //waitEvent.Reset();
                Process proc = Process.Start(psi);
                proc.WaitForExit();

                //if the output is too much may cause a dead lock, see HYS.Common.DataAccess.DataBase.OSQLExec() for solution,
                //that is to move WaitForExit() after ReadLine(), but then we cannot get the complete output message.

                while (proc.StandardOutput.Peek() > -1)
                {
                    string msg = proc.StandardOutput.ReadLine().Trim();
                    sb.AppendLine(msg);

                    if (showForm)
                    {
                        tb.Text          += msg + "\r\n";
                        tb.SelectionStart = tb.Text.Length - 1;
                        tb.ScrollToCaret();
                        Application.DoEvents();
                        Thread.Sleep(50);
                    }
                }

                string str4 = "---------------- Invoking End " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToLongTimeString() + "----------------\r\n\r\n";
                sb.Append(str4);

                if (showForm)
                {
                    tb.Text          += str4;
                    tb.SelectionStart = tb.Text.Length - 1;
                    tb.ScrollToCaret();
                    Application.DoEvents();
                    Thread.Sleep(1000);
                }

                //string logPath = Path.GetDirectoryName(filename) + "\\..\\..\\Log";     //to IM log
                string logPath = Application.StartupPath + "\\Log";
                if (!Directory.Exists(logPath))
                {
                    Directory.CreateDirectory(logPath);
                }
                string logFile = logPath + "\\command.log";
                File.AppendAllText(logFile, sb.ToString());

                if (showForm)
                {
                    dlg.Dispose();
                }

                return(true);
            }
            catch (Exception err)
            {
                GCError.SetLastError("Start process failed." + filename + " " + arg);
                GCError.SetLastError(err);
                return(false);
            }
        }