Пример #1
0
        private async Task <List <PageBarInfo.PanelEntry> > GetPanelsAsync()
        {
            SavedCacheInfo info = GetCache(Module.ModuleGuid);

            if (info == null || info.UserId != Manager.UserId || info.Language != Manager.UserLanguage)
            {
                // We only reload the pages when the user is new (logon/logoff), otherwise we would build this too often
                List <PageBarInfo.PanelEntry> list = new SerializableList <PageBarInfo.PanelEntry>();
                foreach (LocalPage page in Module.PageList)
                {
                    AddPage(list, await YetaWF.Core.Pages.PageDefinition.LoadPageDefinitionByUrlAsync(page.Url), page.Popup);
                }
                if (!string.IsNullOrWhiteSpace(Module.PagePattern))
                {
                    SerializableList <PageBarInfo.PanelEntry> listPattern = new SerializableList <PageBarInfo.PanelEntry>();
                    Regex regPages = new Regex(Module.PagePattern);
                    foreach (PageDefinition.DesignedPage desPage in await YetaWF.Core.Pages.PageDefinition.GetDesignedPagesAsync())
                    {
                        Match m = regPages.Match(desPage.Url);
                        if (m.Success)
                        {
                            if ((from p in Module.PageList where p.Url == desPage.Url select p).FirstOrDefault() == null)
                            {
                                AddPage(listPattern, await YetaWF.Core.Pages.PageDefinition.LoadPageDefinitionAsync(desPage.PageGuid), false);
                            }
                        }
                    }
                    listPattern = new SerializableList <PageBarInfo.PanelEntry>(listPattern.OrderBy((m) => m.Caption.ToString()).ToList());
                    list.AddRange(listPattern);
                }
                info = new SavedCacheInfo {
                    PanelEntries = list,
                    Language     = Manager.UserLanguage,
                    UserId       = Manager.UserId,
                };
                SetCache(Module.ModuleGuid, info);
            }
            return(info.PanelEntries);
        }
Пример #2
0
 public MysetInfo(List <MysetItemInfo> infos)
 {
     MysetItems = new SerializableList <MysetItemInfo>();
     MysetItems.AddRange(infos);
 }
Пример #3
0
        public override void Collet()
        {
            SerializableList <T> allItems = new SerializableList <T>();
            int           i      = 1;
            FileInfo      info   = new FileInfo(string.Format(this.fileName, i));
            XmlSerializer writer = getXmlSerializer();

            try
            {
                while (info.Exists)
                {
                    logger.Debug("Loading file \"{0}\".", string.Format(this.fileName, i));
                    using (FileStream file = File.Open(info.FullName, FileMode.Open))
                    {
                        T[] list = (T[])writer.Deserialize(file);
                        allItems.AddRange(list);
                    }

                    i++;
                    info = new FileInfo(string.Format(this.fileName, i));
                }
            }
            catch (Exception exp)
            {
                logger.Error(exp, "Loading xml serilized items failed. Leaveing the split files.");
                return;
            }

            logger.Info("{0} files was loaded from the split files.", allItems.Count);
            if (allItems.Count == 0)
            {
                return;
            }

            try
            {
                var name = string.Format(this.fileName, "all");
                logger.Info("Saving all {0} items to {1}", allItems.Count, name);
                Write(allItems, name);

                logger.Debug("Removing split files.");
                i    = 1;
                name = string.Format(this.fileName, i);
                info = new FileInfo(name);
                while (info.Exists)
                {
                    try
                    {
                        logger.Trace("Removing split file \"{0}\".", name);
                        File.Delete(info.FullName);

                        i++;
                        name = string.Format(this.fileName, i);
                        info = new FileInfo(name);
                    }
                    catch (Exception exp)
                    {
                        logger.Error(exp, "Unable to remove split file \"{0}\".", name);
                    }
                }
            }
            catch (Exception exp)
            {
                logger.Error(exp, "Saving xml serilized items failed. Leaveing the split files.");
            }
        }