public void Start()
		{
			if (disposed)
				throw new ObjectDisposedException(GetType().Name);

			if (engineMutex.WaitOne())
			{
				try
				{
					if (appPortMutex.WaitOne())
					{
						try 
						{
							try 
							{
								engine = new GarminProtocolEngine((short)((int)settings["gpsProductId"].Value),
									(short)((int)settings["gpsSoftwareVersion"].Value),
									(string)settings["gpsProductDescription"].Value,
									(uint)((long)settings["gpsUnitId"].Value), (int)settings["snrMin"].Value,
									(int)settings["snrMax"].Value);

								appPort = application.GetPort(this, (string)settings["appPort"].Value);
								appPort.Read += new PortReadEvent(appPort_Read);
								appPort.Error += new PortErrorEvent(appPort_Error);
								appPort.Open();

								outputThread = new EventThread(new EventThreadCallback(OutputThreadCallback));
								outputThread.Priority = ThreadPriority.Normal;
								outputThread.Start();

								protocolTimer.Change(0, 1000);
							}
							catch
							{
								protocolTimer.Change(Timeout.Infinite, Timeout.Infinite);
								if (outputThread != null)
								{
									outputThread.Abort();
									outputThread = null;
								}
								if (appPort != null)
								{
									appPort.Close();
									appPort.Dispose();
									appPort = null;
								}
								engine = null;
								throw;
							}
						}
						finally
						{
							appPortMutex.ReleaseMutex();
						}
					}
					else
						throw new Exception("Failed to lock application port mutex");
				}
				finally
				{
					engineMutex.ReleaseMutex();
				}
			}
			else
				throw new Exception("Failed to lock protocol engine mutex");

			started = true;
		}
Пример #2
0
        public void Start()
        {
            if (disposed)
            {
                throw new ObjectDisposedException(GetType().Name);
            }

            if (engineMutex.WaitOne())
            {
                try
                {
                    if (appPortMutex.WaitOne())
                    {
                        try
                        {
                            try
                            {
                                engine = new GarminProtocolEngine((short)((int)settings["gpsProductId"].Value),
                                                                  (short)((int)settings["gpsSoftwareVersion"].Value),
                                                                  (string)settings["gpsProductDescription"].Value,
                                                                  (uint)((long)settings["gpsUnitId"].Value), (int)settings["snrMin"].Value,
                                                                  (int)settings["snrMax"].Value);

                                appPort        = application.GetPort(this, (string)settings["appPort"].Value);
                                appPort.Read  += new PortReadEvent(appPort_Read);
                                appPort.Error += new PortErrorEvent(appPort_Error);
                                appPort.Open();

                                outputThread          = new EventThread(new EventThreadCallback(OutputThreadCallback));
                                outputThread.Priority = ThreadPriority.Normal;
                                outputThread.Start();

                                protocolTimer.Change(0, 1000);
                            }
                            catch
                            {
                                protocolTimer.Change(Timeout.Infinite, Timeout.Infinite);
                                if (outputThread != null)
                                {
                                    outputThread.Abort();
                                    outputThread = null;
                                }
                                if (appPort != null)
                                {
                                    appPort.Close();
                                    appPort.Dispose();
                                    appPort = null;
                                }
                                engine = null;
                                throw;
                            }
                        }
                        finally
                        {
                            appPortMutex.ReleaseMutex();
                        }
                    }
                    else
                    {
                        throw new Exception("Failed to lock application port mutex");
                    }
                }
                finally
                {
                    engineMutex.ReleaseMutex();
                }
            }
            else
            {
                throw new Exception("Failed to lock protocol engine mutex");
            }

            started = true;
        }
Пример #3
0
        protected void MainProcessing()
        {
            Logger.Info <SactaProxy>("Arrancando Servicio.");

            MainTaskSync = new System.Threading.ManualResetEvent(false);
            EventThread.Start();
            MainTaskConfigured = ConfigureService();
            StartWebServer();
            History.Add(HistoryItems.ServiceStarted);
            do
            {
                EventThread.Enqueue("MainProcessing", () =>
                {
                    try
                    {
                        if (MainTaskConfigured == false)
                        {
                            StopManagers(true);
                            StopWebServer();
                            MainTaskConfigured = ConfigureService();
                            StartWebServer();
                        }
                        GlobalStateManager.MainStandbyCheck((isDual, isMain) =>
                        {
                            if (isDual)
                            {
                                if (isMain && !PS.IsStarted)
                                {
                                    //Logger.Info<SactaProxy>("Entrando en Modo DUAL-MAIN");
                                    History.Add(HistoryItems.ServiceInMode, "", "", "Master");
                                    StartManagers();
                                }
                                else if (!isMain && PS.IsStarted)
                                {
                                    //Logger.Info<SactaProxy>("Entrando en Modo DUAL-STANDBY");
                                    History.Add(HistoryItems.ServiceInMode, "", "", "Standby");
                                    StopManagers();
                                }
                            }
                            else
                            {
                                if (!PS.IsStarted)
                                {
                                    //Logger.Info<SactaProxy>("Entrando en Modo SINGLE");
                                    History.Add(HistoryItems.ServiceInMode, "", "", "Simple");
                                    StartManagers();
                                }
                            }
                        });
                    }
                    catch
                    {
                    }
                });
            }while (MainTaskSync.WaitOne(TimeSpan.FromSeconds(2)) == false);

            StopManagers(true);
            StopWebServer();
            History.Add(HistoryItems.ServiceEnded);
            EventThread.ControlledStop();
            Logger.Info <SactaProxy>("Servicio Detenido.");
        }