Beispiel #1
0
        protected void OnStartInternally(object arguments)
        {
            string[] args = (string[])arguments;

            try
            {
                /*if (!IsAdministrator())
                 * {
                 *  // Restart program and run as admin
                 *  var exeName = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
                 *  ProcessStartInfo startInfo = new ProcessStartInfo(exeName);
                 *  startInfo.Verb = "runas";
                 *  System.Diagnostics.Process.Start(startInfo);
                 *  Environment.Exit(0);
                 *  return;
                 * }*/



                // check multiple processes
                //commented by khazbak to avoid requirement to start in admin mode

                /*
                 * if (bool.Parse(SystemConfigurations.GetAppSetting("CheckMultipleInstances")))
                 * {
                 *  string currProcName = Process.GetCurrentProcess().ProcessName;
                 *  int currProcID = Process.GetCurrentProcess().Id;
                 *  Process[] processes = Process.GetProcessesByName(currProcName);
                 *  if (processes.Length > 1)
                 *  {
                 *      foreach (Process p in processes)
                 *      {
                 *          if (p.Id != currProcID)
                 *          {
                 *              int id = p.Id;
                 *              p.Kill();
                 *              SystemLogger.WriteOnConsoleAsync(true, "Process has been killed ID: " + id, ConsoleColor.Gray, ConsoleColor.White, false);
                 *          }
                 *      }
                 *  }
                 * }*/

                Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);

                SystemLogger.LogEventAsync("Starting FIX Service...");

                try
                {
                    if (bool.Parse(SystemConfigurations.GetAppSetting("ReinitializeCounters")))
                    {
                        Counters.ReInitialize();
                    }
                    else
                    {
                        Counters.Initialize();
                    }
                }
                catch (Exception ex)
                {
                    SystemLogger.WriteOnConsoleAsync(true, "Error initializing counters, Error: " + ex.ToString(), ConsoleColor.Red, ConsoleColor.Black, true);
                }


                DatabaseMethods db = new DatabaseMethods();
                if (!db.IsTodaySequenceReset()) // reset the counters only if the service starts for first time today
                {
                    Counters.ResetCounters();
                }
                // Check queue existance
                if (bool.Parse(SystemConfigurations.GetAppSetting("CheckQueueExistance")))
                {
                    CheckAndSetPermissionsToQueues();
                }
                FixExchangesInfo.Initialize();
                Currencies.Initialize();
                StocksDefinitions.Initialize();
                Lookups.Initialize();
                string seqFilePath = SystemConfigurations.GetAppSetting("SequenceFilePath");
                if (!db.IsTodaySequenceReset())
                {
                    SystemLogger.LogEventAsync("Resetting FIX sequence..");
                    db.UpdateTodaySequenceReset();
                    SystemLogger.LogEventAsync("Sequence reset successfully");
                    //try
                    //{
                    //    System.IO.File.Delete(seqFilePath);
                    //}
                    //catch (Exception ex)
                    //{
                    //    Counters.IncrementCounter(CountersConstants.ExceptionMessages);
                    //    SystemLogger.WriteOnConsoleAsync(true, "Deleting Sequence File Error: " + ex.Message, ConsoleColor.Red, ConsoleColor.Black, true);
                    //}
                }


                Router responsesRouter = new Router(typeof(ResponsesProcessor), int.Parse(SystemConfigurations.GetAppSetting("ResponsesRouterProcessorsNum")));

                m_FixSessionStatusChangedDelegate = new FixSessionStatusChangedDelegate(OnFixStatusChange);


                bool AllowMcsdAllocation = Convert.ToBoolean(SystemConfigurations.GetAppSetting("AllowMcsdAllocation")); // maghrabi

                if (AllowMcsdAllocation)                                                                                 //MCSD
                {
                    Router mcsdResponsesRouter = new Router(typeof(ResponsesProcessorMcsd), int.Parse(SystemConfigurations.GetAppSetting("McsdResponsesRouterProcessorsNum")));
                    McsdGatwayManager.Initialize(mcsdResponsesRouter); // maghrabi
                    McsdGatwayManager.LoginToMCSD();                   // maghrabi
                }

                string fixClientSettings = Environment.CurrentDirectory + @"\" + SystemConfigurations.GetAppSetting("FixClientSettingsFile");
                string fixServerSettings = Environment.CurrentDirectory + @"\" + SystemConfigurations.GetAppSetting("FixServerSettingsFile");
                MarketFixClient.Initialize(fixClientSettings, responsesRouter, m_FixSessionStatusChangedDelegate);
                SvcFixServer.InitializeServer(fixServerSettings);
                OrdersManager.Initialize();
                Sessions.Initialize();
                //RepSessions.Initialize();
                InitializeService();

                if (_resetSequenceNumber)
                {
                    //  MarketFixClient.ResetSequence();
                }

                MarketFixClient.Logon();



                SystemLogger.WriteOnConsoleAsync(true, "Awaiting for Fix server response ...", ConsoleColor.Yellow, ConsoleColor.Black, false);
                System.Windows.Forms.Application.Run(new frmMonitor()); //maghrabi
                //while (true) { Console.ReadKey(); }
                //StopService();
            }
            catch (Exception ex)
            {
                Counters.IncrementCounter(CountersConstants.ExceptionMessages);
                SystemLogger.WriteOnConsoleAsync(true, "Main Error: " + ex.ToString(), ConsoleColor.Red, ConsoleColor.Black, true);

                try
                {
                    string[] cc = SystemConfigurations.GetAppSetting("SupportMailCC").Split(',');
                    NotificationSender.Send(true, true, false, SystemConfigurations.GetAppSetting("SupportMailFrom"), SystemConfigurations.GetAppSetting("SupportMailTo"), cc, "Fix Service Down", "Fix Service Down",
                                            string.Format("Service startup error state on machine {0} at {1}, Error : {2}", SystemConfigurations.GetMachineIP(), DateTime.Now.ToString(), ex.ToString()), null);
                }
                catch (Exception inex)
                {
                    Counters.IncrementCounter(CountersConstants.ExceptionMessages);
                    SystemLogger.WriteOnConsoleAsync(true, "Sending Mail Error: " + inex.Message, ConsoleColor.Red, ConsoleColor.Black, false);
                }

                //Console.ReadKey();
            }
        }
Beispiel #2
0
 static void sh_Closed(object sender, EventArgs e)
 {
     try
     {
         Counters.IncrementCounter(CountersConstants.ExceptionMessages);
         string[] cc = SystemConfigurations.GetAppSetting("SupportMailCC").Split(',');
         NotificationSender.Send(true, true, false, SystemConfigurations.GetAppSetting("SupportMailFrom"), SystemConfigurations.GetAppSetting("SupportMailTo"), cc, "Fix Orders Service Closed", "Fix Orders Service Closed",
                                 string.Format("Fix Orders Service has been closed on machine {0} at {1}", SystemConfigurations.GetMachineIP(), DateTime.Now.ToString()), null);
     }
     catch (Exception ex)
     {
         SystemLogger.WriteOnConsoleAsync(true, "Sending Mail Error: " + ex.Message, ConsoleColor.Red, ConsoleColor.Black, true);
     }
 }