Beispiel #1
0
        public frmReuseSettings(SySal.OperaDb.OperaDbConnection conn, long[] ids)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
            _conn = conn;
            System.Data.DataSet ds = new System.Data.DataSet();
            SySal.OperaDb.OperaDbDataAdapter da = new SySal.OperaDb.OperaDbDataAdapter("SELECT DESCRIPTION FROM TB_PROGRAMSETTINGS WHERE EXECUTABLE='AreaScan2Driver.exe'", _conn);
            da.Fill(ds);
            //dataGrid1.SetDataBinding(ds, "Table");
            string qry = "SELECT ID, DESCRIPTION FROM TB_PROGRAMSETTINGS WHERE EXECUTABLE = 'AreaScan2Driver.exe'";

            if (chkDisplayAll.Checked == true)
            {
                qry = "SELECT ID, DESCRIPTION FROM TB_PROGRAMSETTINGS WHERE DRIVERLEVEL=1";
            }
            Utilities.FillListBox(lstAvailable, qry, _conn);
        }
Beispiel #2
0
        private bool Init()
        {
            string configfile = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName + ".xml";

            System.Xml.Serialization.XmlSerializer xmlc = new System.Xml.Serialization.XmlSerializer(typeof(Configuration));
            System.Xml.Serialization.XmlSerializer xmls = new System.Xml.Serialization.XmlSerializer(typeof(NExT.NExTConfiguration));
            SySal.OperaDb.OperaDbConnection        conn = null;
            try
            {
                TheConfig = (Configuration)xmlc.Deserialize(new System.IO.StringReader(System.IO.File.ReadAllText(configfile)));
                System.Collections.ArrayList dynsrvparams = new System.Collections.ArrayList();
                if (TheConfig.DBServer.Length > 0)
                {
                    NExT.NExTConfiguration.ServerParameter sp = new SySal.NExT.NExTConfiguration.ServerParameter();
                    sp.Name  = "DBServer";
                    sp.Value = SySal.OperaDb.OperaDbCredentials.Decode(TheConfig.DBServer);
                    dynsrvparams.Add(sp);
                    sp       = new SySal.NExT.NExTConfiguration.ServerParameter();
                    sp.Name  = "DBUsr";
                    sp.Value = SySal.OperaDb.OperaDbCredentials.Decode(TheConfig.DBUserName);
                    sp       = new SySal.NExT.NExTConfiguration.ServerParameter();
                    sp.Name  = "DBPwd";
                    sp.Value = SySal.OperaDb.OperaDbCredentials.Decode(TheConfig.DBPassword);
                    conn     = new SySal.OperaDb.OperaDbConnection(
                        SySal.OperaDb.OperaDbCredentials.Decode(TheConfig.DBServer),
                        SySal.OperaDb.OperaDbCredentials.Decode(TheConfig.DBUserName),
                        SySal.OperaDb.OperaDbCredentials.Decode(TheConfig.DBPassword)
                        );
                    conn.Open();

                    IPHostEntry iph   = Dns.Resolve(Dns.GetHostName());
                    string[]    idstr = new string[iph.Aliases.Length + iph.AddressList.Length];
                    idstr[0] = iph.HostName;
                    int i;
                    for (i = 0; i < iph.Aliases.Length; i++)
                    {
                        idstr[i] = iph.Aliases[i];
                    }
                    for (i = 0; i < iph.AddressList.Length; i++)
                    {
                        idstr[i + iph.Aliases.Length] = iph.AddressList[i].ToString();
                    }
                    string selstr = "LOWER(TB_MACHINES.ADDRESS)='" + iph.HostName.ToLower() + "'";
                    foreach (string s in idstr)
                    {
                        selstr += (" OR ADDRESS='" + s + "'");
                    }
                    DataSet ds = new DataSet();
                    SySal.OperaDb.OperaDbDataAdapter da = new SySal.OperaDb.OperaDbDataAdapter("SELECT TB_SITES.ID, TB_SITES.NAME, TB_MACHINES.ID, TB_MACHINES.NAME, TB_MACHINES.ADDRESS FROM TB_SITES INNER JOIN TB_MACHINES ON (TB_MACHINES.ID_SITE = TB_SITES.ID AND TB_MACHINES.ISDATAPROCESSINGSERVER = 1 AND (" + selstr + "))", conn, null);
                    da.Fill(ds);
                    if (ds.Tables[0].Rows.Count < 1)
                    {
                        throw new Exception("Can't find myself in OperaDb registered machines. This service is made unavailable.");
                    }
                    long   IdSite         = SySal.OperaDb.Convert.ToInt64(ds.Tables[0].Rows[0][0]);
                    string SiteName       = ds.Tables[0].Rows[0][1].ToString();
                    long   IdMachine      = SySal.OperaDb.Convert.ToInt64(ds.Tables[0].Rows[0][2]);
                    string MachineName    = ds.Tables[0].Rows[0][3].ToString();
                    string MachineAddress = ds.Tables[0].Rows[0][4].ToString();
                    object o = (TheConfig.DBConfigQuery.Length <= 0) ? null : new SySal.OperaDb.OperaDbCommand(TheConfig.DBConfigQuery.Replace("_ID_MACHINE_", IdMachine.ToString()), conn, null).ExecuteScalar();
                    if (o != null && o != System.DBNull.Value)
                    {
                        TheConfig.Services = (NExT.NExTConfiguration)xmls.Deserialize(new System.IO.StringReader(o.ToString()));
                    }
                    conn.Close();
                    conn = null;
                }
                SySal.NExT.NExTServer.SetupConfiguration(TheConfig.Services, (SySal.NExT.NExTConfiguration.ServerParameter [])dynsrvparams.ToArray(typeof(SySal.NExT.NExTConfiguration.ServerParameter)));
                WS = new SySal.Web.WebServer(TheConfig.WWWPort, this);
            }
            catch (Exception x)
            {
                MessageBox.Show("Cannot read/apply server configuration file \"" + configfile + "\".\r\nAttempting to write a sample file.\r\n\r\nError:\r\n" + x.ToString(), "Error reading configuration", MessageBoxButtons.OK, MessageBoxIcon.Error);
                try
                {
                    System.IO.StringWriter sw = new System.IO.StringWriter();
                    xmlc.Serialize(sw, TheConfig);
                    sw.WriteLine();
                    sw.WriteLine("------------");
                    sw.WriteLine();
                    xmls.Serialize(sw, TheConfig.Services);
                    System.IO.File.WriteAllText(configfile, sw.ToString());
                }
                catch (Exception) { }
                return(false);
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }
            return(true);
        }
        /// <summary>
        /// Set things in motion.
        /// </summary>
        protected override void OnStart(string[] args)
        {
            try
            {
                int i;
                if (!EventLog.Exists("Opera"))
                {
                    EventLog.CreateEventSource("OperaDataProcServer", "Opera");
                }
                EventLog.Source = "OperaDataProcServer";
                EventLog.Log    = "Opera";

                System.Configuration.AppSettingsReader asr = new System.Configuration.AppSettingsReader();
                try
                {
                    DBServer   = SySal.OperaDb.OperaDbCredentials.Decode((string)asr.GetValue("DBServer", typeof(string)));
                    DBUserName = SySal.OperaDb.OperaDbCredentials.Decode((string)asr.GetValue("DBUserName", typeof(string)));
                    DBPassword = SySal.OperaDb.OperaDbCredentials.Decode((string)asr.GetValue("DBPassword", typeof(string)));
                }
                catch (Exception x)
                {
                    throw new Exception("Encryption error in credentials.\r\nPlease fill in valid encrypted data (you can use OperaDbGUILogin, for instance), or run the service as the appropriate user.");
                }
                SySal.OperaDb.OperaDbConnection conn = new SySal.OperaDb.OperaDbConnection(DBServer, DBUserName, DBPassword);
                conn.Open();

                IPHostEntry iph   = Dns.Resolve(Dns.GetHostName());
                string []   idstr = new string[iph.Aliases.Length + iph.AddressList.Length];
                idstr[0] = iph.HostName;
                for (i = 0; i < iph.Aliases.Length; i++)
                {
                    idstr[i] = iph.Aliases[i];
                }
                for (i = 0; i < iph.AddressList.Length; i++)
                {
                    idstr[i + iph.Aliases.Length] = iph.AddressList[i].ToString();
                }
                string selstr = "LOWER(TB_MACHINES.ADDRESS)='" + iph.HostName.ToLower() + "'";
                foreach (string s in idstr)
                {
                    selstr += (" OR ADDRESS='" + s + "'");
                }
                DataSet ds = new DataSet();
                SySal.OperaDb.OperaDbDataAdapter da = new SySal.OperaDb.OperaDbDataAdapter("SELECT TB_SITES.ID, TB_SITES.NAME, TB_MACHINES.ID, TB_MACHINES.NAME, TB_MACHINES.ADDRESS FROM TB_SITES INNER JOIN TB_MACHINES ON (TB_MACHINES.ID_SITE = TB_SITES.ID AND TB_MACHINES.ISDATAPROCESSINGSERVER = 1 AND (" + selstr + "))", conn, null);
                da.Fill(ds);
                if (ds.Tables[0].Rows.Count < 1)
                {
                    throw new Exception("Can't find myself in OperaDb registered machines. This service is made unavailable.");
                }
                IdSite         = SySal.OperaDb.Convert.ToInt64(ds.Tables[0].Rows[0][0]);
                SiteName       = ds.Tables[0].Rows[0][1].ToString();
                IdMachine      = SySal.OperaDb.Convert.ToInt64(ds.Tables[0].Rows[0][2]);
                MachineName    = ds.Tables[0].Rows[0][3].ToString();
                MachineAddress = ds.Tables[0].Rows[0][4].ToString();

                object val;
                val = ReadOverride("DPS_MachinePowerClass", conn);
                if (val != System.DBNull.Value)
                {
                    MachinePowerClass = Convert.ToInt32(val.ToString());
                }
                else
                {
                    MachinePowerClass = (int)asr.GetValue("MachinePowerClass", typeof(int));
                }

                val = ReadOverride("DPS_PeakWorkingSetMB", conn);
                if (val != System.DBNull.Value)
                {
                    PeakWorkingSetMB = Convert.ToInt32(val.ToString());
                }
                else
                {
                    PeakWorkingSetMB = (int)asr.GetValue("PeakWorkingSetMB", typeof(int));
                }

                val = ReadOverride("DPS_ResultLiveSeconds", conn);
                if (val != System.DBNull.Value)
                {
                    ResultLiveTime = System.TimeSpan.FromSeconds(Convert.ToInt32(val.ToString()));
                }
                else
                {
                    ResultLiveTime = System.TimeSpan.FromSeconds((int)asr.GetValue("ResultLiveSeconds", typeof(int)));
                }

                val = ReadOverride("DPS_LowPriority", conn);
                if (val != System.DBNull.Value)
                {
                    LowPriority = Convert.ToBoolean(val.ToString());
                }
                else
                {
                    LowPriority = (bool)asr.GetValue("LowPriority", typeof(bool));
                }

                val = ReadOverride("ExeRepository", conn);
                if (val != System.DBNull.Value)
                {
                    ExeRepository = val.ToString();
                }
                else
                {
                    ExeRepository = asr.GetValue("MachinePowerClass", typeof(string)).ToString();
                }

                val = ReadOverride("DPS_WWWPort", conn);
                if (val != System.DBNull.Value)
                {
                    WebPort = Convert.ToInt32(val.ToString());
                }
                else
                {
                    WebPort = (int)asr.GetValue("WWWPort", typeof(int));
                }

                bool showexc = false;
                val = ReadOverride("DPS_WWWShowExceptions", conn);
                if (val != System.DBNull.Value)
                {
                    showexc = Convert.ToBoolean(val.ToString());
                }
                else
                {
                    showexc = (bool)asr.GetValue("WWWShowExceptions", typeof(bool));
                }

                val = ReadOverride("DPS_MaxOutputText", conn);
                if (val != System.DBNull.Value)
                {
                    MaxOutputText = Convert.ToInt32(val.ToString());
                }
                else
                {
                    try
                    {
                        MaxOutputText = (int)asr.GetValue("MaxOutputText", typeof(int));
                    }
                    catch (Exception)
                    {
                        MaxOutputText = 65536;
                    }
                }

                ChannelServices.RegisterChannel(new TcpChannel((int)SySal.DAQSystem.OperaPort.DataProcessingServer));
                DPS = new SySal.DAQSystem.MyDataProcessingServer(EventLog);
                RemotingServices.Marshal(DPS, "DataProcessingServer.rem");
                conn.Close();

                WebAccess wa = null;
                if (WebPort > 0)
                {
                    WA = new SySal.Web.WebServer(WebPort, wa = new WebAccess());
                }
                if (wa != null)
                {
                    wa.SetShowExceptions(showexc);
                }

                EventLog.WriteEntry("Service starting\r\nThread Priority: " + (LowPriority ? "Below normal" : "Normal") + "\r\nPeak working set (MB): " + PeakWorkingSetMB + "\r\nMachine power class: " + MachinePowerClass + "\r\nSelf-identification yields:\r\nSite: " + SiteName + "\r\nSite Id: " + IdSite + "\r\nMachine: " + MachineName + "\r\nMachine Id: " + IdMachine + "\r\nMachine Address: " + MachineAddress, EventLogEntryType.Information);
            }
            catch (System.Exception x)
            {
                EventLog.WriteEntry("Service startup failure:\n" + x.ToString(), EventLogEntryType.Error);
                throw x;
            }
        }
Beispiel #4
0
 void ProcOpRefresh(string selection)
 {
     //SySal.OperaDb.OperaDbConnection Conn = null;
     System.Windows.Forms.Cursor oldcursor = Cursor;
     Cursor = Cursors.WaitCursor;
     try
     {
         if (Conn == null)
         {
             Conn = new SySal.OperaDb.OperaDbConnection(Credentials.DBServer, Credentials.DBUserName, Credentials.DBPassword);
             Conn.Open();
         }
         ProcOpTree.BeginUpdate();
         ProcOpTree.Nodes.Clear();
         System.Data.DataSet ds = new System.Data.DataSet();
         SySal.OperaDb.OperaDbDataAdapter da = new SySal.OperaDb.OperaDbDataAdapter("SELECT /*+INDEX_RANGE (TB_PROC_OPERATIONS IX_PROC_OPERATIONS_PARENT) */ TB_PROC_OPERATIONS.ID, TB_PROGRAMSETTINGS.DESCRIPTION, TB_PROGRAMSETTINGS.EXECUTABLE, TB_PROC_OPERATIONS.STARTTIME, TB_PROC_OPERATIONS.SUCCESS, TB_PROC_OPERATIONS.ID_EVENTBRICK, TB_PROC_OPERATIONS.ID_PLATE FROM TB_PROC_OPERATIONS INNER JOIN TB_PROGRAMSETTINGS ON (TB_PROC_OPERATIONS.ID_PROGRAMSETTINGS = TB_PROGRAMSETTINGS.ID) WHERE (TB_PROC_OPERATIONS.ID_PARENT_OPERATION IS NULL " + selection + ") ORDER BY STARTTIME DESC", Conn, null);
         da.Fill(ds);
         System.Collections.Stack nodestack = new System.Collections.Stack();
         foreach (System.Data.DataRow dr in ds.Tables[0].Rows)
         {
             int image = 2;
             if (dr[4].ToString() == "N")
             {
                 image = 1;
             }
             else if (dr[4].ToString() == "Y")
             {
                 image = 0;
             }
             string addinfo = " ";
             if (dr[5] != System.DBNull.Value)
             {
                 addinfo += "B#" + dr[5].ToString() + " ";
             }
             if (dr[6] != System.DBNull.Value)
             {
                 addinfo += "P#" + dr[6].ToString() + " ";
             }
             TreeNode tn = new TreeNode("#" + dr[0].ToString() + ": " + dr[1].ToString() + addinfo + "(" + dr[2].ToString() + ") - (" + Convert.ToDateTime(dr[3]).ToString("dd/MM/yyyy HH:mm:ss") + ")", image, image);
             tn.Tag = Convert.ToInt64(dr[0]);
             ProcOpTree.Nodes.Add(tn);
             nodestack.Push(tn);
         }
         TreeNode nextnode = null;
         while (nodestack.Count > 0)
         {
             nextnode = (TreeNode)nodestack.Pop();
             ds       = new System.Data.DataSet();
             da       = new SySal.OperaDb.OperaDbDataAdapter("SELECT /*+INDEX(TB_PROC_OPERATIONS IX_PROC_OPERATIONS_PARENT) */ TB_PROC_OPERATIONS.ID FROM TB_PROC_OPERATIONS WHERE (TB_PROC_OPERATIONS.ID_PARENT_OPERATION = " + nextnode.Tag.ToString() + ") ORDER BY STARTTIME DESC", Conn, null);
             da.Fill(ds);
             foreach (System.Data.DataRow dr in ds.Tables[0].Rows)
             {
                 TreeNode tn = new TreeNode("");
                 tn.Tag = Convert.ToInt64(dr[0]);
                 nextnode.Nodes.Add(tn);
                 nodestack.Push(tn);
             }
         }
         ProcOpTree.EndUpdate();
         //Conn.Close();
     }
     catch (Exception x)
     {
         if (Conn != null)
         {
             Conn.Close();
             Conn = null;
         }
         ProcOpTree.EndUpdate();
         MessageBox.Show(x.ToString(), "Error refreshing process operation information");
     }
     Cursor = oldcursor;
 }