//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()
        {
            try {
                /* DeviceEntry ldap = new DeviceEntry(this.config);
                 * LogToFile.Log("LDAP DeviceEntry Starting");
                 * ldap.LDAPDeviceEntry();
                 * LogToFile.Log("LDAP DeviceEntry Finished");*/

                if (data.loadConfig() == ReturnValue.ERROR)
                {
                    LogToFile.Log("Agent Start Failed.\n Problem in Devices.xml");
                    throw new AgentException("Agent Start Failed.\n Problem in Devices.xml");
                }
                //to check Devices.xml about nativeUnits and Units.
                //data.checkConfig(); //throw exception
                hst = new HttpServer(data);
                hst.Start();
            } catch (AgentException e) {
                if (e.InnerException != null)
                {
                    LogToFile.Log(e.Message + e.InnerException.Message);
                }
                else
                {
                    LogToFile.Log(e.Message);
                }
                throw e;
            } catch (System.UnauthorizedAccessException eu) {
                //Cannot use Local System Account
                throw eu;
            } catch (Exception e) {
                LogToFile.Log("Agent Start has Failed.  " + e);
                throw new AgentException("Agent Start has Failed.  ", e);
            }
        }
예제 #2
0
        public Configuration(bool LoadDefault)
        {
            if (LoadDefault)
            {
                TextReader xmlIn = null;

                try
                {
                    xmlIn = new StreamReader(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + Path.DirectorySeparatorChar + DEFAULT_FILE_NAME);
                    XmlSerializer s = new XmlSerializer(typeof(Configuration));
                    CloneConfiguration((Configuration)s.Deserialize(xmlIn));
                }
                catch (Exception e)
                {
                    LogToFile.Log("Agent Start has Failed.\n Problem with " + DEFAULT_FILE_NAME + ". " + e.Message);
                    throw new AgentException("Agent Start has Failed.\n Problem with " + DEFAULT_FILE_NAME + ". " + e.Message);
                }
                finally
                {
                    if (xmlIn != null)
                    {
                        xmlIn.Close();
                    }
                }
            }
        }
 public virtual void Stop()
 {
     try {
         hst.Stop();
     } catch (Exception e) {
         LogToFile.Log("Agent Stop has Failed.  " + e);
         throw new AgentException("Agent Stop has Failed.  ", e);
     }
 }
 public Agent()
 {
     data             = new Data();
     this.exeFilePath = Assembly.GetExecutingAssembly().Location;
     config           = new Configuration(true); //LOAD_DEFAULT_CONFIGURATION = true
     LogToFile.Initialize(config.UseLogFile);
     data.currentXSLTHREF = config.CurrentXSLTHREF;
     data.probeXSLTHREF   = config.ProbeXSLTHREF;
     data.errorXSLTHREF   = config.ErrorXSLTHREF;
 }
 //return value as double if _value can be converted to double otherwise throw exception
 internal static double getDValue(String _timestamp, String _deviceName, String _dataItemName, String _value, String _workPieceId, String _partId)
 {
     try {
         return(Double.Parse(_value));
     } catch (ArgumentNullException) {
         String msg = "Missing value for " + StoreSampleToString(_timestamp, _deviceName, _dataItemName, _value, _workPieceId, _partId);
         LogToFile.Log(msg);
         throw new AgentException(msg);
     } catch (Exception) //FormatException, OverflowException
     {
         String msg = "Value \"" + _value + "\" can not converted into number for " + StoreSampleToString(_timestamp, _deviceName, _dataItemName, _value, _workPieceId, _partId);
         LogToFile.Log(msg);
         throw new AgentException(msg);
     }
 }
예제 #6
0
 internal void Start()
 {
     if (this.IsStarted)
     {
         return;
     }
     if (this.Listener == null)
     {
         this.Listener = new HttpListener();
     }
     this.Listener.Prefixes.Add("http://+:5000/");
     this.IsStarted = true;
     try {
         this.Listener.Start();
     } catch (System.Net.HttpListenerException ex) {
         LogToFile.Log("HttpServer.Start Error: " + ex);
         throw new AgentException("Agent Start Failed.  Please make sure port 5000 is available for Agent.");
     }
     IAsyncResult result = this.Listener.BeginGetContext(new AsyncCallback(WebRequestCallback), this.Listener);
 }