Example #1
0
        /// <summary>
        /// Uninstall all events for the given object type. This is typically used to uninstall scheduler items while removing packages.
        /// </summary>
        private async Task UninstallItemsAsync(Type type)
        {
            string asmName   = type.Assembly.GetName().Name;
            string eventType = type.FullName + ", " + asmName;

            using (SchedulerDataProvider dataProvider = new SchedulerDataProvider()) {
                IScheduling schedEvt = null;
                try {
                    schedEvt = (IScheduling)Activator.CreateInstance(type);
                } catch (Exception exc) {
                    throw new InternalError("The specified object does not support the required IScheduling interface.", exc);
                }
                if (schedEvt != null)
                {
                    try {
                        // Event.ImplementingAssembly == asmName
                        List <DataProviderFilterInfo> filters = new List <DataProviderFilterInfo> {
                            new DataProviderFilterInfo {
                                Field = "Event.ImplementingAssembly", Operator = "==", Value = asmName
                            }
                        };
                        await dataProvider.RemoveItemsAsync(filters);// we ignore whether the remove fails
                    } catch (Exception exc) {
                        throw new InternalError("UninstallItems for the specified type {0} failed.", eventType, exc);
                    }
                }
            }
        }
Example #2
0
 public ProcessMrp(ProductionDomainContext context, IScheduling scheduling, ICapacityScheduling capacityScheduling, IMessageHub messageHub, IRebuildNets rebuildNets)
 {
     _messageHub         = messageHub;
     _context            = context;
     _scheduling         = scheduling;
     _capacityScheduling = capacityScheduling;
     _demandForecast     = new DemandForecast(context, this);
     _rebuildNets        = rebuildNets;
 }
Example #3
0
        private async Task RunItemAsync(SchedulerDataProvider schedDP, SchedulerItemData item)
        {
            long logId = DateTime.UtcNow.Ticks;

            SchedulerLog.SetCurrent(logId, 0, item.Name);

            item.IsRunning = true;
            item.RunTime   = new TimeSpan();
            item.Last      = DateTime.UtcNow;

            try {
                await schedDP.UpdateItemAsync(item);
            } catch (Exception exc) {
                Logging.AddErrorLog("Updating scheduler item {0} failed.", item.Name, exc);
            }

            StringBuilder errors  = new StringBuilder();
            DateTime?     nextRun = null;// called event handlers can return a next run time

            try {
                item.Errors = null;

                DateTime now = DateTime.UtcNow;
                {
                    string m = $"Scheduler event - running scheduler item '{item.Name}'.";
                    Logging.AddLog(m);
                    errors.AppendLine(m);
                }

                Type tp = null;
                try {
                    Assembly asm = Assemblies.Load(item.Event.ImplementingAssembly);
                    tp = asm.GetType(item.Event.ImplementingType);
                } catch (Exception exc) {
                    throw new InternalError("Scheduler item '{0}' could not be loaded (Type={1}, Assembly={2}) - {3}", item.Name, item.Event.ImplementingType, item.Event.ImplementingAssembly, ErrorHandling.FormatExceptionMessage(exc));
                }

                if (item.SiteSpecific)
                {
                    DataProviderGetRecords <SiteDefinition> info = await SiteDefinition.GetSitesAsync(0, 0, null, null);

                    foreach (SiteDefinition site in info.Data)
                    {
                        IScheduling schedEvt = null;
                        try {
                            schedEvt = (IScheduling)Activator.CreateInstance(tp);
                        } catch (Exception exc) {
                            string m = $"Scheduler item '{item.Name}' could not be instantiated (Type={item.Event.ImplementingType}, Assembly={item.Event.ImplementingAssembly}) - {ErrorHandling.FormatExceptionMessage(exc)}";
                            Logging.AddLog(m);
                            errors.AppendLine(m);
                        }

                        if (schedEvt != null)
                        {
                            YetaWFManager.MakeThreadInstance(site, null, true);// set up a manager for the site

                            SchedulerLog.LimitTo(YetaWFManager.Manager);
                            SchedulerLog.SetCurrent(logId, site.Identity, item.Name);

                            SchedulerItemBase itemBase = new SchedulerItemBase {
                                Name = item.Name, Description = item.Description, EventName = item.Event.Name, Enabled = true, Frequency = item.Frequency, Startup = item.Startup, SiteSpecific = true
                            };
                            try {
                                await schedEvt.RunItemAsync(itemBase);
                            } catch (Exception exc) {
                                string m = $"An error occurred in scheduler item '{site.Identity}: {item.Name}' - {ErrorHandling.FormatExceptionMessage(exc)}";
                                Logging.AddLog(m);
                                errors.AppendLine(m);
                            }

                            foreach (var s in itemBase.Log)
                            {
                                string m = $"{site.Identity}: {s}";
                                Logging.AddLog(m);
                                errors.AppendLine(m);
                            }
                            if (itemBase.NextRun != null && (nextRun == null || (DateTime)itemBase.NextRun < nextRun))
                            {
                                nextRun = itemBase.NextRun;
                            }

                            YetaWFManager.RemoveThreadInstance();

                            YetaWFManager.MakeThreadInstance(null, null, true);// restore scheduler's manager
                            SchedulerLog.LimitTo(YetaWFManager.Manager);
                            SchedulerLog.SetCurrent();
                        }
                    }
                }
                else
                {
                    IScheduling schedEvt = null;
                    try {
                        schedEvt = (IScheduling)Activator.CreateInstance(tp);
                    } catch (Exception exc) {
                        string m = $"Scheduler item '{item.Name}' could not be instantiated (Type={item.Event.ImplementingType}, Assembly={item.Event.ImplementingAssembly}) - {ErrorHandling.FormatExceptionMessage(exc)}";
                        Logging.AddLog(m);
                        errors.AppendLine(m);
                    }

                    if (schedEvt != null)
                    {
                        SchedulerItemBase itemBase = new SchedulerItemBase {
                            Name = item.Name, Description = item.Description, EventName = item.Event.Name, Enabled = true, Frequency = item.Frequency, Startup = item.Startup, SiteSpecific = false
                        };
                        try {
                            await schedEvt.RunItemAsync(itemBase);
                        } catch (Exception exc) {
                            string m = $"An error occurred in scheduler item '{item.Name}' - {ErrorHandling.FormatExceptionMessage(exc)}";
                            Logging.AddLog(m);
                            errors.AppendLine(m);
                        }
                        foreach (var s in itemBase.Log)
                        {
                            Logging.AddLog(s);
                            errors.AppendLine(s);
                        }

                        if (itemBase.NextRun != null && (nextRun == null || (DateTime)itemBase.NextRun < nextRun))
                        {
                            nextRun = itemBase.NextRun;
                        }
                    }
                }

                TimeSpan diff = DateTime.UtcNow - now;
                item.RunTime = diff;
                {
                    string m = $"Elapsed time for scheduler item '{item.Name}' was {diff} (hh:mm:ss.ms).";
                    Logging.AddLog(m);
                    errors.AppendLine(m);
                }
            } catch (Exception exc) {
                string m = $"Scheduler item {item.Name} failed - {ErrorHandling.FormatExceptionMessage(exc)}";
                Logging.AddErrorLog(m);
                errors.AppendLine(m);
            }

            if (item.RunOnce)
            {
                item.Enabled = false;
            }

            item.IsRunning = false;

            item.SetNextRuntime();
            if (nextRun != null)
            {
                Logging.AddLog($"Next run at {nextRun} (UTC)");
                item.Next    = nextRun;
                item.Enabled = true;
            }
            item.Errors = errors.ToString();

            try {
                await schedDP.UpdateItemAsync(item);
            } catch (Exception exc) {
                string m = $"Updating scheduler item {item.Name} failed - {ErrorHandling.FormatExceptionMessage(exc)}";
                Logging.AddErrorLog(m);
                errors.AppendLine(m);
            }

            SchedulerLog.SetCurrent();
        }
 public SchedulingController(IScheduling repo, IBelaVistaRepository repositoryContext)
 {
     _repo = repo;
     _repositoryContext = repositoryContext;
 }
Example #5
0
        public async Task <string> RenderAsync(SchedulerEvent model)
        {
            HtmlBuilder hb = new HtmlBuilder();

            List <Type> schedulerEvents         = YetaWF.Modules.Scheduler.Support.Scheduler.Instance.SchedulerEvents;
            List <SelectionItem <string> > list = new List <SelectionItem <string> >();

            foreach (Type type in schedulerEvents)
            {
                IScheduling         isched = (IScheduling)Activator.CreateInstance(type);
                SchedulerItemBase[] items  = isched.GetItems();
                foreach (SchedulerItemBase item in items)
                {
                    list.Add(new SelectionItem <string>()
                    {
                        Text    = item.EventName,
                        Tooltip = item.Description,
                        Value   = item.EventName + "," + type.FullName + "," + type.Assembly.GetName().Name
                    });
                }
            }
            if (list.Count == 0)
            {
                throw new Error(__ResStr("noEvents", "No events are available"));
            }

            string select;

            if (string.IsNullOrWhiteSpace(model.Name))
            {
                select = list.First().Value;
            }
            else
            {
                select = model.Name + "," + model.ImplementingType + "," + model.ImplementingAssembly;
            }

            EventUI eventUI = new EventUI {
                DropDown      = select,
                DropDown_List = list,
            };

            using (Manager.StartNestedComponent(FieldName)) {
                hb.Append($@"
<div id='{ControlId}' class='yt_yetawf_scheduler_event t_edit'>
    <div class='t_event'>
        {await HtmlHelper.ForEditAsync(eventUI, nameof(eventUI.DropDown))}
        {await HtmlHelper.ForEditAsync(model, nameof(model.Name))}
        {await HtmlHelper.ForEditAsync(model, nameof(model.ImplementingAssembly))}
        {await HtmlHelper.ForEditAsync(model, nameof(model.ImplementingType))}
    </div>
    <div class='t_info'>
        <div class='t_row t_implementingassembly'>
            <div class='t_labels'>
                {await HtmlHelper.ForLabelAsync(model, nameof(model.ImplementingAssembly))}
            </div>
            <div class='t_vals'>
                <span class='t_implasm'>{Utility.HtmlEncode(model.ImplementingAssembly)}</span>
            </div>
        </div>
        <div class='t_row t_implementingtype'>
            <div class='t_labels'>
                {await HtmlHelper.ForLabelAsync(model, nameof(model.ImplementingType))}
            </div>
            <div class='t_vals'>
                <span class='t_impltype'>{Utility.HtmlEncode(model.ImplementingType)}</span>
            </div>
        </div>
        <div class='t_row t_eventbuiltindescription'>
            <div class='t_labels'>
                {await HtmlHelper.ForLabelAsync(model, nameof(model.EventBuiltinDescription))}
            </div>
            <div class='t_vals'>
                <span class='t_description'>{Utility.HtmlEncode(model.EventBuiltinDescription)}</span>
            </div>
        </div>
    </div>
</div>");

                Manager.ScriptManager.AddLast($@"new YetaWF_Scheduler.EventEditComponent('{ControlId}');");
            }

            return(hb.ToString());
        }
Example #6
0
        public SchedulingMessaging(IScheduling <Envelope <T> > scheduling)
        {
            this.scheduling = scheduling;

            handler = new DelegatingScheduleHandler <Envelope <T> >(scheduling, new IScheduleHandler <Envelope <T> >[] { this });
        }
Example #7
0
 public DelegatingScheduleHandler(IScheduling <T> scheduling, IEnumerable <IScheduleHandler <T> > scheduleHandlers)
 {
     this.scheduling       = scheduling;
     this.scheduleHandlers = scheduleHandlers;
 }
Example #8
0
 public DelegatingScheduler(IScheduling <T> scheduling)
 {
     this.scheduling = scheduling;
 }