Exemplo n.º 1
0
            public async Task AddDataAsync()
            {
                DataProviderGetRecords <SiteDefinition> info = await SiteDefinition.GetSitesAsync(0, 0, null, null);

                SiteDomain_List = (from s in info.Data orderby s.SiteDomain select new SelectionItem <string>()
                {
                    Text = s.SiteDomain,
                    Value = s.SiteDomain,
                    Tooltip = this.__ResStr("switchSite", "Switch to site \"{0}\"", s.SiteDomain),
                }).ToList();
                SiteDomain = Manager.CurrentSite.SiteDomain;

                ControlPanelConfigData config = await ControlPanelConfigDataProvider.GetConfigAsync();

                UserId_List = config.Users;
                UserId      = Manager.UserId;

                int superuserRole = Resource.ResourceAccess.GetSuperuserRoleId();

                if (Manager.UserRoles != null && Manager.UserRoles.Contains(superuserRole))
                {
                    SuperuserCurrent = true;// the current user is a superuser
                }
                else if (Manager.HasSuperUserRole)
                {
                    SuperuserStillActive = true;
                }
                else
                {
                    SuperuserStillActive = false;
                }
            }
Exemplo n.º 2
0
        /// <summary>
        /// Called by the framework when the component needs to be rendered as HTML.
        /// </summary>
        /// <param name="model">The model being rendered by the component.</param>
        /// <returns>The component rendered as HTML.</returns>
        public async Task <string> RenderAsync(int model)
        {
            if (Sites == null)
            {
                Dictionary <int, StringTT> sites             = new Dictionary <int, StringTT>();
                DataProviderGetRecords <SiteDefinition> recs = await SiteDefinition.GetSitesAsync(0, 0, null, null);

                foreach (SiteDefinition site in recs.Data)
                {
                    sites.Add(site.Identity,
                              new StringTT {
                        Text    = site.Identity.ToString(),
                        Tooltip = site.SiteDomain,
                    }
                              );
                }
                Sites = sites;
            }

            StringTT stringTT;

            if (Sites.ContainsKey(model))
            {
                stringTT = Sites[model];
            }
            else
            {
                stringTT = new StringTT {
                    Text    = __ResStr("none", "(none)"),
                    Tooltip = __ResStr("noneTT", "")
                };
            }
            return(await StringTTDisplayComponent.RenderStringTTAsync(this, stringTT, "yt_siteid"));
        }
Exemplo n.º 3
0
        private GridDefinition GetGridModel()
        {
            return(new GridDefinition {
                ModuleGuid = Module.ModuleGuid,
                SettingsModuleGuid = Module.PermanentGuid,
                RecordType = typeof(BrowseItem),
                AjaxUrl = GetActionUrl(nameof(SitesBrowse_GridData)),
                DirectDataAsync = async(int skip, int take, List <DataProviderSortInfo> sort, List <DataProviderFilterInfo> filters) => {
                    ModuleDefinition siteEditModule = await ModuleDefinition.LoadAsync(new Guid("522296A0-B03B-49b7-B849-AB4149466E0D"));

                    ConfirmRemovalModule confirmModule = new ConfirmRemovalModule();

                    DataProviderGetRecords <SiteDefinition> info = await SiteDefinition.GetSitesAsync(skip, take, sort, filters);

                    return new DataSourceResult {
                        Data = (from s in info.Data select new BrowseItem(Module, siteEditModule, confirmModule, s)).ToList <object>(),
                        Total = info.Total
                    };
                },
            });
        }
Exemplo n.º 4
0
        // IINSTALLABLEMODEL2
        // IINSTALLABLEMODEL2
        // IINSTALLABLEMODEL2

        public async Task <bool> UpgradeModelAsync(List <string> errorList, string lastSeenVersion)
        {
            // Convert pre 1.1.1 data to new format (for all sites)
            if (Package.CompareVersion(lastSeenVersion, AreaRegistration.CurrentPackage.Version) < 0 &&
                Package.CompareVersion(lastSeenVersion, "1.1.1") < 0)
            {
                DataProviderGetRecords <SiteDefinition> info = await SiteDefinition.GetSitesAsync(0, 0, null, null);

                foreach (SiteDefinition site in info.Data)
                {
                    using (UserLoginInfoDataProvider userLoginInfoDP = new UserLoginInfoDataProvider(site.Identity)) {
                        const int chunk = 100;
                        int       skip  = 0;
                        for (; ; skip += chunk)
                        {
                            DataProviderGetRecords <LoginInfo> list = await userLoginInfoDP.GetItemsAsync(skip, chunk, null, null);

                            if (list.Data.Count <= 0)
                            {
                                break;
                            }
                            foreach (LoginInfo l in list.Data)
                            {
                                await RemoveItemAsync(l.UserId);

#pragma warning disable 0618 // Type or member is obsolete
                                await AddItemAsync(l.UserId, l.OldLoginProvider, l.OldProviderKey);

#pragma warning restore 0618 // Type or member is obsolete
                            }
                        }
                    }
                }
            }
            return(true);
        }
Exemplo n.º 5
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();
        }