Ejemplo n.º 1
0
        public static void Main(string[] args)
        {
            #if DEBUG
            using (var host = new NancyHost(new Uri(ConfigurationManager.AppSettings["ManagementConsole"])))
            {
                host.Start();

                Console.WriteLine("Running on " + ConfigurationManager.AppSettings["ManagementConsole"]);

                using (var echoClient = EchoClient.Current)

                    using (var sapClient = ServerConnection.Current)
                    {
                        // attempt connection; 0 = success
                        if (sapClient.Connect() == 0)
                        {
                            Console.WriteLine("Successfully connected to " + sapClient.GetCompany().CompanyName + "!");

                            var helper = new HelperMethods(sapClient.GetCompany());
                            helper.AddUserDefinedFields();
                            helper.SaveFinCocode();
                        }
                        else
                        {
                            Console.WriteLine("Error " + sapClient.GetErrorCode() + ": " + sapClient.GetErrorMessage());
                        }

                        Console.ReadLine();
                    }
            }
            #endif
        }
        protected override void OnStart(string[] args)
        {
            // Update the service state to Start Pending.
            ServiceStatus serviceStatus = new ServiceStatus();

            serviceStatus.dwCurrentState = ServiceState.SERVICE_START_PENDING;
            serviceStatus.dwWaitHint     = 60000;
            SetServiceStatus(this.ServiceHandle, ref serviceStatus);

            Helpers.LogInfo($"In OnStart..");

            #region Timers

            Timer timer = new Timer(1000 * 60 * Convert.ToInt32(ConfigurationManager.AppSettings["SyncIntervalInMinutes"]));
            timer.Elapsed += new ElapsedEventHandler(this.OnTimer);
            timer.Start();

            Timer reconnectTimer = new Timer();
            reconnectTimer.Interval = 420000; // 15 mins
            reconnectTimer.Elapsed += new ElapsedEventHandler(this.OnReconnect);
            reconnectTimer.Start();

            #endregion

            var host = new NancyHost(new Uri(ConfigurationManager.AppSettings["ManagementConsole"]));
            host.Start();

            var echoClient = EchoClient.Current;
            var sapClient  = ServerConnection.Current;

            // attempt connection; 0 = success
            if (sapClient.Connect() == 0)
            {
                Helpers.LogInfo($"Successfully connected to {sapClient.GetCompany().CompanyName}!");

                var helper = new HelperMethods(sapClient.GetCompany());
                helper.AddUserDefinedFields();
                helper.SaveFinCocode();
            }
            else
            {
                Helpers.LogAppError($"{sapClient.GetErrorCode()}: {sapClient.GetErrorMessage()}");
            }

            // Update the service state to Running.
            serviceStatus.dwCurrentState = ServiceState.SERVICE_RUNNING;
            SetServiceStatus(this.ServiceHandle, ref serviceStatus);
        }
Ejemplo n.º 3
0
        public static void Main(string[] args)
        {
            //Starting Nancy service here as console application
            if (args != null && args.Length > 0 && args[0] == "debug")
            {
                using (var host = new NancyHost(new Uri(ConfigurationManager.AppSettings["ManagementConsole"])))
                {
                    host.Start();

                    Console.WriteLine("Running on " + ConfigurationManager.AppSettings["ManagementConsole"]);

                    using (var echoClient = EchoClient.Current)

                        using (var sapClient = ServerConnection.Current)
                        {
                            // attempt connection; 0 = success
                            if (sapClient.Connect() == 0)
                            {
                                Console.WriteLine("Successfully connected to " + sapClient.GetCompany().CompanyName + "!");
                                var helper = new HelperMethods(sapClient.GetCompany());
                                helper.AddUserDefinedFields();
                                helper.SaveFinCocode();
                            }
                            else
                            {
                                Console.WriteLine("Error " + sapClient.GetErrorCode() + ": " + sapClient.GetErrorMessage());
                            }

                            Console.ReadLine();
                        }
                }
            }
            else //Starting a normal windows service by default
            {
                ServiceBase[] ServicesToRun;
                ServicesToRun = new ServiceBase[]
                {
                    new WorkbenchSapAgentService()
                };
                ServiceBase.Run(ServicesToRun);
            }
        }