Exemplo n.º 1
0
        /// <summary>
        /// This method is called when the service gets a request to start.
        /// </summary>
        /// <param name="args">Any command line arguments</param>
        public void OnStart(string[] args)
        {
            try
            {
                string strMsmqHost            = GetConfig.Reco3Config.MSMQ.HostName;
                string strMSMQConversionQueue = GetConfig.Reco3Config.MSMQ.ConversionQueue;
                string strMSMQHealthQueue     = GetConfig.Reco3Config.MSMQ.HealthQueueName;

                _conversionQueue = new BatchQueue.BatchQueue();
                _conversionQueue.Configuration = GetConfig;
                _conversionQueue.SetEndpoint(strMsmqHost, strMSMQConversionQueue, false, true);



                _clientHealthQueue = new BatchQueue.BatchQueue();
                _clientHealthQueue.Configuration = GetConfig;
                _clientHealthQueue.SetEndpoint(strMsmqHost, strMSMQHealthQueue, false, true);



                //_conversionQueue.SendMsg(new Reco3Msg(3, 57));

                /*
                 * // Must look at this again!....
                 *
                 */
            }
            catch (Exception ex)
            {
                ConsoleHarness.WriteToConsole(ConsoleColor.Red, string.Format("OnStart, Exception raised: {0}", ex.Message));
            }
        }
Exemplo n.º 2
0
 public static void Main(string[] args)
 {
     if (args.Contains("-i", StringComparer.InvariantCultureIgnoreCase))
     {
         WindowsServiceInstaller.RuntimeInstall <ServiceImplementation>();
     }
     else if (args.Contains("-u", StringComparer.InvariantCultureIgnoreCase))
     {
         WindowsServiceInstaller.RuntimeUnInstall <ServiceImplementation>();
     }
     else
     {
         using (var implementation = new ServiceImplementation())
         {
             if (Environment.UserInteractive)
             {
                 ConsoleHarness.Run(args, implementation);
             }
             else
             {
                 ServiceBase.Run(new WindowsServiceHarness(implementation));
             }
         }
     }
 }
Exemplo n.º 3
0
        public void QueueRoadmapFleet()
        {
            try
            {
                ConsoleHarness.WriteToConsole(ConsoleColor.Green, string.Format("QueueRoadmapFleet, Starting."));
                DatabaseContext dbx = new DatabaseContext();

                BatchQueue.BatchQueue queue = new BatchQueue.BatchQueue();
                queue.IsLocalQueue = false;
                string strMSMQHost            = GetConfig.Reco3Config.MSMQ.HostName;
                string strMSMQSimulationQueue = GetConfig.Reco3Config.MSMQ.SimulationQueue;
                queue.IsLocalQueue = true;
                queue.SetRecieverEndpoint(strMSMQHost, strMSMQSimulationQueue);

                List <string> VINs = GetList(@"H:\Tools\Reco3Core\MissedVehicles.csv");
                foreach (string vin in VINs)
                {
                    Vehicle  vehicle = dbx.Vehicle.Where(x => x.VIN == vin).First();
                    Reco3Msg msg     = new Reco3Msg();
                    msg.MsgType   = Reco3MsgType.PendingRoadmapSimulation;
                    msg.RoadmapId = 6;
                    msg.VehicleId = vehicle.VehicleId;
                    queue.SendMsg(msg);
                }
                ConsoleHarness.WriteToConsole(ConsoleColor.Green, string.Format("QueueRoadmapFleet, Done! Processed {0} vehicles.", VINs.Count));
            }
            catch (Exception e)
            {
                ConsoleHarness.WriteToConsole(ConsoleColor.Red, string.Format("QueueRoadmapFleet, Exception raised: {0}", e.Message));
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Rolls back to the state of the counter, and performs the normal rollback.
        /// </summary>
        /// <param name="savedState">The saved state for the installation.</param>
        public override void Rollback(System.Collections.IDictionary savedState)
        {
            ConsoleHarness.WriteToConsole(ConsoleColor.White, "Rolling back service {0}.", Configuration.Name);

            // load the assembly file name and the config
            ConfigureInstallers();
            base.Rollback(savedState);
        }
Exemplo n.º 5
0
 /// <summary>
 /// This method is called when the service gets a request to stop.
 /// </summary>
 public void OnStop()
 {
     try
     {
         _conversionQueue.ShutDown();
         _clientHealthQueue.ShutDown();
     }
     catch (Exception ex)
     {
         ConsoleHarness.WriteToConsole(ConsoleColor.Red, string.Format("OnStop, Exception raised: {0}", ex.Message));
     }
 }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            Tracer.Initialize(@"C:\WeatherCenter\Logs", "WeatherService", Process.GetCurrentProcess().Id.ToString(CultureInfo.InvariantCulture), Environment.UserInteractive);

            if (args.Contains("-install", StringComparer.InvariantCultureIgnoreCase))
            {
                Tracer.WriteLine("Starting install...");

                try
                {
                    WindowsServiceInstaller.RuntimeInstall <ServiceImplementation>();
                }
                catch (Exception exception)
                {
                    Tracer.WriteException("Service install", exception);
                }

                Tracer.WriteLine("Install complete");
            }
            else if (args.Contains("-uninstall", StringComparer.InvariantCultureIgnoreCase))
            {
                Tracer.WriteLine("Starting uninstall...");

                try
                {
                    WindowsServiceInstaller.RuntimeUnInstall <ServiceImplementation>();
                }
                catch (Exception exception)
                {
                    Tracer.WriteException("Service uninstall", exception);
                }

                Tracer.WriteLine("Uninstall complete");
            }
            else
            {
                Tracer.WriteLine("Starting service");

                var implementation = new ServiceImplementation();

                if (Environment.UserInteractive)
                {
                    ConsoleHarness.Run(args, implementation);
                }
                else
                {
                    ServiceBase.Run(new WindowsServiceHarness(implementation));
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Installer class, to use run InstallUtil against this .exe
        /// </summary>
        /// <param name="savedState">The saved state for the installation.</param>
        public override void Install(System.Collections.IDictionary savedState)
        {
            ConsoleHarness.WriteToConsole(ConsoleColor.White, "Installing service {0}.", Configuration.Name);

            // install the service
            ConfigureInstallers();
            base.Install(savedState);

            // wire up the event log source, if provided
            if (!string.IsNullOrWhiteSpace(Configuration.EventLogSource))
            {
                // create the source if it doesn't exist
                if (!EventLog.SourceExists(Configuration.EventLogSource))
                {
                    EventLog.CreateEventSource(Configuration.EventLogSource, "Application");
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Removes the counters, then calls the base uninstall.
        /// </summary>
        /// <param name="savedState">The saved state for the installation.</param>
        public override void Uninstall(System.Collections.IDictionary savedState)
        {
            ConsoleHarness.WriteToConsole(ConsoleColor.White, "Un-Installing service {0}.", Configuration.Name);

            // load the assembly file name and the config
            ConfigureInstallers();
            base.Uninstall(savedState);

            // wire up the event log source, if provided
            if (!string.IsNullOrWhiteSpace(Configuration.EventLogSource))
            {
                // create the source if it doesn't exist
                if (EventLog.SourceExists(Configuration.EventLogSource))
                {
                    EventLog.DeleteEventSource(Configuration.EventLogSource);
                }
            }
        }
Exemplo n.º 9
0
        // The main entry point for the windows service application.
        static void Main(string[] args)
        {
            try
            {
                // If install was a command line flag, then run the installer at runtime.
                if (args.Contains("-install", StringComparer.InvariantCultureIgnoreCase))
                {
                    WindowsServiceInstaller.RuntimeInstall <ServiceImplementation>();
                }

                // If uninstall was a command line flag, run uninstaller at runtime.
                else if (args.Contains("-uninstall", StringComparer.InvariantCultureIgnoreCase))
                {
                    WindowsServiceInstaller.RuntimeUnInstall <ServiceImplementation>();
                }

                // Otherwise, fire up the service as either console or windows service based on UserInteractive property.
                else
                {
                    var implementation = new ServiceImplementation();

                    // If started from console, file explorer, etc, run as console app.
                    if (Environment.UserInteractive)
                    {
                        ConsoleHarness.Run(args, implementation);
                    }

                    // Otherwise run as a windows service
                    else
                    {
                        ServiceBase.Run(new WindowsServiceHarness(implementation));
                    }
                }
            }
            catch (Exception ex)
            {
                // Write to console
                ConsoleHarness.WriteToConsole(ConsoleColor.Red, "An exception occurred in Main(): {0}", ex);

                // Write to log
                Logger.Instance.Log(true, pEx: ex);
            }
        }
Exemplo n.º 10
0
        // Handles login to webserver - returns valid token for use in further transactions - called on service start to renew token
        public static async Task <string> LoginAsync(string webServerAddress, string username, string password)
        {
            string token  = "";
            var    values = new Dictionary <string, string>
            {
                { "username", username },
                { "password", password }
            };

            var content = new FormUrlEncodedContent(values);

            var response = await Globals.Client.PostAsync(webServerAddress + "/login", content);

            var responseString = await response.Content.ReadAsStringAsync();

            LoginResponseJSON payload = JsonConvert.DeserializeObject <LoginResponseJSON>(responseString);

            if (payload.status.Equals("success"))
            {
                // Login was successful, update global token
                Globals.Token = payload.token;
                token         = Globals.Token;
            }
            else if (payload.status.Equals("error"))
            {
                // The login details likely incorrect or some other error - login was unsuccessful
                // First set the TokenInvalid flag to true
                // Trigger a console display on screen with error message that credentials are invalid
                Globals.InvalidateToken();
                token = "";

                // If the status is ever 'error' during login, then the service shouldn't continue, there is a credentials
                // Misconfiguration in the App config file. Log to Error folder

                ConsoleHarness.WriteToConsole(ConsoleColor.Red, "ERROR: Problem logging in to Web Server, Credentials likely invalid. Username: {0}, Password: {1}", Globals.WebServerUsername, Globals.WebServerPassword);
            }

            return(token);
        }
Exemplo n.º 11
0
        private static void Main(string[] args)
        {
            try
            {
                // install or uninstall windows service
                if (args.Contains("-install", StringComparer.InvariantCultureIgnoreCase))
                {
                    WindowsServiceInstaller.RuntimeInstall <WebDAVService>();
                }
                else if (args.Contains("-uninstall", StringComparer.InvariantCultureIgnoreCase))
                {
                    WindowsServiceInstaller.RuntimeUnInstall <WebDAVService>();
                }

                // otherwise, fire up the service as either console or windows service based on UserInteractive property.
                // if started from console, file explorer, etc, run as console app.
                // otherwise run as a windows service
                else
                {
                    var implementation = new WebDAVService();
                    if (Environment.UserInteractive)
                    {
                        ConsoleHarness.Run(args, implementation);
                    }
                    else
                    {
                        Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
                        ServiceBase.Run(new WindowsServiceHarness(implementation));
                    }
                }
            }

            catch (Exception ex)
            {
                ConsoleHarness.WriteToConsole(ConsoleColor.Red, "An exception occurred in Main(): {0}", ex);
            }
        }
Exemplo n.º 12
0
        private static void Main(string[] arguments)
        {
            var options = Args.Parse <StreamWatchOptions>(arguments);

            if (IsSetupRequested(options))
            {
                Environment.Exit(0);
            }

            using (var application = Container.GetInstance <IWindowsService>())
            {
                if (Environment.UserInteractive || options.RunAsConsole)
                {
                    ConsoleHarness.Run(arguments, application);
                }
                else
                {
                    using (var harness = new WindowsServiceHarness(application))
                    {
                        ServiceBase.Run(harness);
                    }
                }
            }
        }
Exemplo n.º 13
0
        private static void Main(string[] args)
        {
            try
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                config.AppSettings.Settings["LDAP_SETTING"].Value = ActiveDirectory.RootPath;
                ConsoleHarness.WriteToConsole(ConsoleColor.Yellow, "Application is linked to the Domain: " + config.AppSettings.Settings["LDAP_SETTING"].Value);

                if (config.ConnectionStrings.ConnectionStrings["OnlineFilesEntities"] == null || config.ConnectionStrings.ConnectionStrings["OnlineFilesEntities"].ConnectionString == "")
                {
                    ConsoleHarness.WriteToConsole(ConsoleColor.Red, "Connection String (OnlineFilesEntities) is not set in the WebConfig.");
                    ConsoleHarness.WriteToConsole(ConsoleColor.Red, "Hit Any Key to Exit");
                    Console.ReadKey();
                    return;
                }

                config.Save(ConfigurationSaveMode.Full);

                using (var context = new OnlineFilesEntities())
                {
                    bool hadError = false;
                    if (!context.CatalogCollections.Any())
                    {
                        ConsoleHarness.WriteToConsole(ConsoleColor.Red, "No Online Catalog Collections Created.");
                        ConsoleHarness.WriteToConsole(ConsoleColor.Yellow, "Please create an entry in the 'CatalogCollection' and 'Catalog' tables.");
                        ConsoleHarness.WriteToConsole(ConsoleColor.Yellow, @"insert into [CatalogCollection] ([Name]) values ('Default Catalog Collection');");
                        hadError = true;
                    }
                    if (!context.Catalogs.Any())
                    {
                        ConsoleHarness.WriteToConsole(ConsoleColor.Red, @"Missing a default catalog in the database.");
                        ConsoleHarness.WriteToConsole(ConsoleColor.Yellow, @"
insert into [Catalog] ([fk_CatalogCollectionId], [Name], [Offline], [Server], [DatabaseName], [UserName], [Password], [fk_CatalogStatusId])
select 
		pk_CatalogCollectionID					[fk_CatalogCollectionId],
		'Default Catalog'						[Name],
		0										[Offline],
		'Name of SQL Server'					[Server],
		'Name of the Database for the Catalog'	[DatabaseName],
		'Username to connect as'				[UserName],
		'Password to use'						[Password],
		1										[fk_CatalogStatusId]
from
	CatalogCollection;"    );
                        hadError = true;
                    }
                    if (hadError)
                    {
                        ConsoleHarness.WriteToConsole(ConsoleColor.Red, "Hit Any Key to Exit");
                        Console.ReadKey();
                        return;
                    }

                    if (!context.Folders.Any(d => d.pk_FolderId == new Guid()))
                    {
                        ConsoleHarness.WriteToConsole(ConsoleColor.Red, @"The Root Folder does not exist!");

                        ConsoleHarness.WriteToConsole(ConsoleColor.Yellow, @"
insert into [Folder]
(pk_FolderId, fk_ParentFolderId, Name, CreateDt, fk_CatalogCollectionId, Win32FileAttribute, isDeleted, DeletedDt, DeletedBy, Owner, CreatedBy)
select top 1
	'00000000-0000-0000-0000-000000000000',
	null,
	'Root',
	getdate(),
	pk_CatalogCollectionID,
	16,
	0,
	null,
	null,
	'00000000-0000-0000-0000-000000000000',
	'00000000-0000-0000-0000-000000000000'
from 
	[CatalogCollection];"    );

                        ConsoleHarness.WriteToConsole(ConsoleColor.Red, "Hit Any Key to Exit");
                        Console.ReadKey();
                        return;
                    }
                    if (!context.SecurityObjects.Any() && !args.Contains("-SyncADS", StringComparer.CurrentCultureIgnoreCase))
                    {
                        ConsoleHarness.WriteToConsole(ConsoleColor.Red, @"Active Directory has not been Syncronized.");
                        ConsoleHarness.WriteToConsole(ConsoleColor.Yellow, @"Run the program with option '-SyncADS'.");
                        ConsoleHarness.WriteToConsole(ConsoleColor.Red, "Hit Any Key to Exit");
                        Console.ReadKey();
                        return;
                    }
                }

                // if install was a command line flag, then run the installer at runtime.
                if (args.Contains(" - install", StringComparer.InvariantCultureIgnoreCase))
                {
                    WindowsServiceInstaller.RuntimeInstall <ServiceImplementation>();
                }

                // if uninstall was a command line flag, run uninstaller at runtime.
                else if (args.Contains("-uninstall", StringComparer.InvariantCultureIgnoreCase))
                {
                    WindowsServiceInstaller.RuntimeUnInstall <ServiceImplementation>();
                }

                // otherwise, fire up the service as either console or windows service based on UserInteractive property.
                else
                {
                    if (args.Contains("-SyncADS", StringComparer.CurrentCultureIgnoreCase))
                    {
                        ActiveDirectory.Syncrhonize();
                    }

                    var implementation = new ServiceImplementation();

                    // if started from console, file explorer, etc, run as console app.
                    if (Environment.UserInteractive)
                    {
                        ConsoleHarness.Run(args, implementation);
                    }

                    // otherwise run as a windows service
                    else
                    {
                        Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
                        ServiceBase.Run(new WindowsServiceHarness(implementation));
                    }
                }
            }

            catch (Exception ex)
            {
                ConsoleHarness.WriteToConsole(ConsoleColor.Red, "An exception occurred in Main(): {0}", ex);
                ConsoleHarness.WriteToConsole(ConsoleColor.Red, "Hit Any Key to Exit");
                Console.ReadKey();
            }
        }