Ejemplo n.º 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);
            }
        }
Ejemplo n.º 2
0
        public VRASController InitializeConfiguration()
        {
            try
            {
                // init the controller
                VRASController vrasController = new VRASController(this.vrasXsdConfig.Settings, this.isService);

                // fill in each batch
                foreach (BatchType b in this.vrasXsdConfig.Batch)
                {
                    // make a new batch
                    Batch newBatch = new Batch(this.vrasXsdConfig.Settings, b.BatchSettings);

                    // start filling it up
                    // add the sources
                    foreach (SourceType s in b.CopyCollection.CopyCollection.SourceFolder)
                    {
                        newBatch.AddSource(s);
                    }

                    // sort the Tiers in the archive section
                    foreach (DestinationType d in b.CopyCollection.CopyCollection.DestinationFolder)
                    {
                        d.ArchiveSettings.SortLines();
                        newBatch.AddDestination(d);
                    }

                    // now we can add the batch
                    vrasController.AddBatch(newBatch);
                }

                return(vrasController);
            }
            catch
            {
                return(null);
            }
        }