Example #1
0
        /// <summary>
        /// OnStart(): Put startup code here
        /// </summary>
        /// <param name="args"></param>
        protected override void OnStart(string[] args)
        {
            try
            {
                VRASLogEvent.SetIsService(true);
                VRASLogEvent.EventSourceDefault = "VRAS Service";

                VRASLogEvent.PrimeEventLogSource(VRASLogEvent.EventSourceDefault, VRASLogEvent.EventLogName);

                Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);

                // true for service
                this.loader = new VRASLoader(true);

                if (!File.Exists(VRAS.VRASLogEvent.ConfigFile))
                {
                    string txt = "Could not find the configuration file: " + VRAS.VRASLogEvent.ConfigFile;

                    VRASLogEvent.LogMesage(
                        VRASLogEvent.EventLogName,
                        txt,
                        System.Diagnostics.EventLogEntryType.Error,
                        Convert.ToInt32(VRAS.VRASLogEvent.EventIDs.SetupError),
                        VRASLogEvent.EventSourceDefault);

                    Environment.Exit(1);
                }

                // if the config is valid do some work
                if (this.loader.LoadConfiguration(VRASLogEvent.ConfigFile))
                {
                    VRASLogEvent.LogMesage(
                        VRASLogEvent.EventLogName,
                        "Configuration Loaded starting Initialization.",
                        System.Diagnostics.EventLogEntryType.Information,
                        Convert.ToInt32(VRAS.VRASLogEvent.EventIDs.Starting),
                        VRASLogEvent.EventSourceDefault);

                    this.controler = this.loader.InitializeConfiguration();
                    if (this.controler == null)
                    {
                        throw new Exception("Error initializing the configuration");
                    }

                    this.controler.ValidateBatches();
                    this.controler.StartBatches();
                }
            }
            catch (Exception ex)
            {
                VRASLogEvent.LogMesage(
                    VRASLogEvent.EventLogName,
                    "Error: " + ex.Message,
                    System.Diagnostics.EventLogEntryType.Error,
                    Convert.ToInt32(VRAS.VRASLogEvent.EventIDs.ErrorID),
                    VRASLogEvent.EventSourceDefault);
            }
        }
Example #2
0
        public static void DocommandLineWork(string configFile)
        {
            try
            {
                VRASLogEvent.SetIsService(false);

                // to test as a service would run run this line
                // VRASLoader loader = new VRASLoader(true);
                VRASLoader     loader = new VRASLoader(false);
                VRASController controler;

                // if the config is valid do some work
                Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
                if (loader.LoadConfiguration(configFile))
                {
                    controler = loader.InitializeConfiguration();

                    controler.ValidateBatches();

                    controler.StartBatches();

                    // wait for the batch to get done
                    while (!controler.DoneYet())
                    {
                        Thread.Sleep(5000);
                    }

                    controler.Cleanup();
                }
                else
                {
                    throw new Exception("Error loading config file");
                }
            }
            catch (Exception ex)
            {
                VRASLogEvent.LogMesage(
                    VRASLogEvent.EventLogName,
                    String.Format("Error: {0}", ex.Message),
                    System.Diagnostics.EventLogEntryType.Error,
                    Convert.ToInt32(VRAS.VRASLogEvent.EventIDs.FileCopyError),
                    VRASLogEvent.EventSourceDefault);
            }
        }