Пример #1
0
        /// <summary>
        /// Execute the task logic.
        /// </summary>
        public void Execute()
        {
            ConcentratorService.Initialize();

            if (TraceSource == null)
            {
                TraceSource = new TraceSource(Name, SourceLevels.All);

                // When a trace source is initialized, but is not configured in the application configuration only the System.Diagnostics.DefaultTraceListener will exist
                if (TraceSource.Listeners.Count == 1 && TraceSource.Listeners[0] is DefaultTraceListener)
                {
                    TraceSource.Listeners.Clear();
                    TraceSource.Listeners.AddRange(Trace.Listeners);
                }
            }

            foreach (var traceListener in TraceSource.Listeners.Cast <TraceListener>())
            {
                traceListener.Name = Name;
            }

            var dashes = new String(Enumerable.Repeat('-', Name.Length + 6).ToArray());

            TraceEvent(TraceEventType.Start, dashes);
            TraceEvent(TraceEventType.Start, "-- {0} --", Name);
            TraceEvent(TraceEventType.Start, dashes);

            UnitProvider = new Lazy <IUnitOfWork>(ServiceLocator.GetInstance <IUnitOfWork>);

            try
            {
                using (Database = new Database(Environments.Current.Connection, Database.MsSqlClientProvider))
                {
                    ExecuteTask();
                }
            }
            catch (Exception exception)
            {
                TraceSource.TraceData(TraceEventType.Critical, 0, exception);
            }
            finally
            {
                if (UnitProvider.IsValueCreated)
                {
                    UnitProvider.Value.Dispose();
                }

                TraceEvent(TraceEventType.Stop, dashes);
            }
        }
Пример #2
0
        static TaskBase()
        {
            try
            {
                CommandLineHelper.Bind <TaskBase>();

                if (ShowConsole)
                {
                    AllocConsole();
                }

                foreach (var taskBaseType in Assembly.GetEntryAssembly().GetTypes().Where(type => typeof(TaskBase).IsAssignableFrom(type)))
                {
                    CommandLineHelper.Bind(taskBaseType);
                    EmbeddedResourceHelper.Bind(taskBaseType);
                }

                ConcentratorService.Initialize();
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }