Пример #1
0
        public Configuration(bool LoadDefault)
        {
            if (LoadDefault)
            {
                TextReader xmlIn = null;

                try
                {
                    //DAF Display
                    String dirStr = defaultDirectory + confDirectory + DEFAULT_FILE_NAME;
                    System.Console.Out.WriteLine("log Directory = " + dirStr);

                    //MySQLDBType = DBConfiguration.DBTypes.MYSQL;
                    xmlIn = new StreamReader(defaultDirectory + confDirectory + DEFAULT_FILE_NAME);
                    XmlSerializer s = new XmlSerializer(typeof(Configuration));
                    CloneConfiguration((Configuration)s.Deserialize(xmlIn));
                }
                catch (Exception e)
                {
                    DeviceEntry.LogToFile("********* Configuration:Error:" + e.Message);
                    DeviceEntry.LogToFile("Agent Start Failed.\n Problem with " + DEFAULT_FILE_NAME);
                    throw new AgentException("Agent Start Failed.\n Problem with " + DEFAULT_FILE_NAME);
                }
                finally
                {
                    if (xmlIn != null)
                    {
                        xmlIn.Close();
                    }
                }
            }
        }
Пример #2
0
        public StreamReader GetConfiguration()
        {
            //StreamWriter sw = new StreamWriter(file);
            //StreamReader sr = new StreamReader(file);

            //TextReader xmlIn = null;
            StreamReader xmlIn = null;

            try
            {
                //DAF Display
                String dirStr = defaultDirectory + confDirectory + DEFAULT_FILE_NAME;
                System.Console.Out.WriteLine("log Directory = " + dirStr);

                xmlIn = new StreamReader(defaultDirectory + confDirectory + DEFAULT_FILE_NAME);
                XmlSerializer s = new XmlSerializer(typeof(Configuration));
                CloneConfiguration((Configuration)s.Deserialize(xmlIn));
            }
            catch (Exception e)
            {
                Console.WriteLine("GetConfiguration:Error:" + e.Message);
                DeviceEntry.LogToFile("AGetConfiguration:Error: " + e.Message);
            }

            //sw.Close();


            return(xmlIn);
        }
Пример #3
0
        public short getConfig(StreamWriter writer)
        {
            string configini = "mtcagent.ini";

            try
            {
                FileStream file = new FileStream(configini, FileMode.Open,
                                                 FileAccess.Read, FileShare.Read);

                // Create a new stream to read from a file
                StreamReader sr = new StreamReader(file);

                // Read contents of file into a string
                string logdata = sr.ReadToEnd();
                //DeviceEntry.LogToFile("getConfig: Config file data  " + logdata);
                writer.Write(logdata);
            }
            catch (Exception e)
            {
                Console.WriteLine("getConfig:Error:" + e.Message);
                DeviceEntry.LogToFile("getConfig:Error: " + e.Message);
                return(ReturnValue.ERROR);
            }
            return(ReturnValue.SUCCESS);
        }
Пример #4
0
        //ReturnValue.ERROR is
        //1) when Devices.xml could not be loaded
        //2) No Header found in Devices.xml
        //3) No bufferSize, sender, or version in Header Element
        public virtual void Start(int ipport)
        {
            try
            {
                DeviceEntry ldap = new DeviceEntry();
                //DAF 2008-08-03 Added
                DeviceEntry.LogToFile("LDAP DeviceEntry Starting");
                ldap.LDAPDeviceEntry();
                DeviceEntry.LogToFile("LDAP DeviceEntry Finished");

                if (data.loadConfig() == ReturnValue.ERROR)
                {
                    DeviceEntry.LogToFile("Agent Start Failed.\n Problem in Devices.xml");
                    throw new AgentException("Agent Start Failed.\n Problem in Devices.xml");
                }
                hst = new HttpServer(data, ipport);
                hst.Start();
            }
            catch (AgentException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                DeviceEntry.LogToFile("Agent Start Failed.  " + e);
                throw new AgentException("Agent Start Failed.", e);
            }
        }
Пример #5
0
 public void LDAPDeviceEntry()
 {
     try
     {
         DeviceEntry.LogToFile("********** Starting LDAP DeviceEntry *************");
         deviceURI = @config.DeviceURI;
         serverURI = config.ServerURL;
         useLDAP   = config.UseLDAP;
         portId    = config.PortId;
         if (!useLDAP)
         {
             DeviceEntry.LogToFile("DeviceEntry:Use of LDAP not selected (useLDAP is false)");
         }
         else
         {
             DeviceEntry.LogToFile("DeviceEntry:PortId = :" + config.PortId);
             loginDN    = config.LoginDN;
             passwd     = config.Passwd;
             searchbase = config.AdminDN;
             container  = config.Container;
             company    = config.Company;
             deviceName = config.DeviceName;
             descript   = config.Description;
             serialno   = config.Serialno;
             DeviceEntry.LogToFile("DeviceEntry:descript = :" + config.Description);
             string newDN = "(cn=" + deviceName + ",ou=" + company + "," + container + ")";    // Works to check for a device presence
             //LDAPSearch:cn=LinuxEMC1,ou=NIST,ou=Devices,dc=mtconnect,dc=org
             string ret1 = DeviceEntry.SearchLDAP(serverURI, portId, loginDN, passwd, searchbase, newDN);
             DeviceEntry.LogToFile("DeviceEntry::Return = :" + ret1);
             if (ret1.Equals("OK"))
             {
                 SleepFor(waitTime);
                 string ret2 = AddRootLDAP(serverURI, portId, loginDN, passwd, container, company, descript);
                 DeviceEntry.LogToFile("DeviceEntry:AddRoot:Return = :" + ret2);
                 SleepFor(waitTimeMsg);
                 string ret3 = AddEntryLDAP(serverURI, portId, loginDN, passwd, container, deviceName,
                                            company, deviceURI, descript, serialno);
                 DeviceEntry.LogToFile("DeviceEntry:AddEntry:Return = :" + ret3);
             }
         }
     }
     catch (Exception e)
     {
         Console.WriteLine("Error:" + e.Message);
         LogToFile("DeviceEntry:Exception Loading mtcagent.ini failed. " + e.Message);
         throw new AgentException("Error:Loading mtcagent.ini failed. ", e);
         //return "Error";
     }
 }
Пример #6
0
 public virtual void Stop()
 {
     try
     {
         if (hst != null)
         {
             hst.Stop();
         }
     }
     catch (Exception e)
     {
         DeviceEntry.LogToFile("Agent Stop Failed.  " + e);
         throw new AgentException("Agent Stop Failed.", e);
     }
 }
Пример #7
0
        public short getLog(StreamWriter writer)
        {
            string loginp = "DeviceEntry2.log";

            try
            {
                //System.Diagnostics.Process.Start(@"copy DeviceEntry.log DeviceEntry2.log /Y");
                System.Diagnostics.Process.Start(@"CopyLog.bat"); //works
            }
            catch (Exception ex)                                  /*if an error ocurrs, show a warning*/
            {
                string st = ex.Message.ToString();
                DeviceEntry.LogToFile("getLog: copy failed " + ex);
            }

            try
            {
                FileStream file = new FileStream(loginp, FileMode.Open,
                                                 FileAccess.Read, FileShare.Read);

                // Create a new stream to read from a file
                StreamReader sr = new StreamReader(file);

                // Read contents of file into a string
                string loghead = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><MTConnectAgent>";
                string logdata = sr.ReadToEnd();
                string logends = "</MTConnectAgent>";
                DeviceEntry.LogToFile("getLog: Log file data  " + logdata);
                writer.Write(loghead + logdata + logends);
            }
            catch (Exception e)
            {
                Console.WriteLine("getLog:Error:" + e.Message);
                DeviceEntry.LogToFile("getLog:Error: " + e.Message);
                return(ReturnValue.ERROR);
            }
            return(ReturnValue.SUCCESS);
        }