/// <summary>
        /// 过滤资源
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        private static ResourcesModel filterResources(string url)
        {
            ResourcesModel result = null;

            // 域名
            var host = new Uri(url).Host;

            if (string.IsNullOrEmpty(host))
            {
                return(null);
            }
            // 筛选域名 (不在列表中,不进行下载)
            if (OpenHostFilterState)
            {
                var isContains = ContainsHostList.Exists(item => item.Contains(host));
                if (!isContains)
                {
                    return(null);
                }
            }

            // 文件扩展名
            var fileExt = new FileInfo(url).Extension;

            result = new ResourcesModel()
            {
                Url = url, Ext = fileExt, Host = host
            };

            return(result);
        }
示例#2
0
        internal async Task SafePages(int listLocation = -1)
        {
            JSONContainer idSettings = JSONContainer.NewObject();

            idSettings.TryAddField(JSON_ID, nextId);
            await ResourcesModel.WriteJSONObjectToFile(StorageDirectory + ID_SAFEFILE, idSettings);

            if (listLocation == -1)
            {
                foreach (string file in Directory.GetFiles(StorageDirectory))
                {
                    if (file.Contains("page-") && file.EndsWith(".json"))
                    {
                        File.Delete(file);
                    }
                }
                int pages = (pageStorables.Count - 1) / PAGESIZE;
                for (int i = 0; i <= pages; i++)
                {
                    await SafePage(i);
                }
            }
            else
            {
                int page = listLocation / PAGESIZE;
                await SafePage(page);
            }
        }
示例#3
0
        internal static async Task <bool> LoadQuotes()
        {
            LoadFileOperation quoteSettings = await ResourcesModel.LoadToJSONObject(ResourcesModel.QuoteSettingsFilePath);

            if (quoteSettings.Success)
            {
                if (quoteSettings.Result.GetField(ref nextQuoteId, JSON_QUOTEID))
                {
                    string[] files = Directory.GetFiles(ResourcesModel.QuotesDirectory);
                    foreach (string filename in files)
                    {
                        if (filename.EndsWith("json") && filename.Contains("quotes-"))
                        {
                            LoadFileOperation QuoteFile = await ResourcesModel.LoadToJSONObject(filename);

                            if (QuoteFile.Success)
                            {
                                handleQuoteJSON(QuoteFile.Result);
                            }
                        }
                    }
                    return(true);
                }
            }
            return(false);
        }
示例#4
0
        internal async Task <bool> InitialLoad()
        {
            LoadFileOperation storageSettings = await ResourcesModel.LoadToJSONObject(StorageDirectory + ID_SAFEFILE);

            if (storageSettings.Success)
            {
                if (storageSettings.Result.TryGetField(JSON_ID, out nextId))
                {
                    string[] files = Directory.GetFiles(StorageDirectory);
                    foreach (string filename in files)
                    {
                        if (filename.EndsWith("json") && filename.Contains("page-"))
                        {
                            LoadFileOperation PageFile = await ResourcesModel.LoadToJSONObject(filename);

                            if (PageFile.Success)
                            {
                                handlePageJSON(PageFile.Result);
                            }
                        }
                    }
                    return(true);
                }
            }
            return(false);
        }
示例#5
0
        /// <summary>
        /// 保存资源
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public async Task <NarutoResult> Save(ResourcesModel model)
        {
            #region 参数校检

            if (model == null)
            {
                return(new NarutoFailResult($"{nameof(model)}参数不能为空"));
            }
            if (model.Name.IsNullOfEmpty())
            {
                return(new NarutoFailResult($"{nameof(model.Name)}参数不能为空"));
            }
            if (model.DisplayName.IsNullOfEmpty())
            {
                return(new NarutoFailResult($"{nameof(model.DisplayName)}参数不能为空"));
            }
            #endregion
            //验证资源名称是否存在
            //验证是否存在
            if ((await resourcesStorage.ExistsResource(model.Id, model.Name)))
            {
                return(new NarutoFailResult("当前资源名称已经存在!"));
            }
            //调用数据访问
            var res = await resourcesStorage.AddUpdResources(model);

            if (res)
            {
                return(new NarutoSuccessResult("操作成功"));
            }
            return(new NarutoFailResult("操作失败"));
        }
        public void Import(string input)
        {
            var files = JsonConvert.DeserializeObject <ResourceFile[]>(input);

            using (var context = new ResourcesModel())
            {
                context.Configuration.AutoDetectChangesEnabled = false;

                var fileEntities = context.TextResources__ResourceFile
                                   .Include(x => x.TextResources__ResourceKey.Select(y => y.TextResources__ResourceValue))
                                   .ToList();

                var existingLanguageIds = context.TextResources__Language.Select(x => x.LanguageID).ToArray();

                var existingEnvironmentIds = context.TextResources__Environment.Select(x => x.TextResourcesEnvironmentID).ToArray();

                foreach (var resourceFile in files.Where(x => existingEnvironmentIds.Contains(x.TextResourcesEnvironment_TextResourcesEnvironmentID.GetValueOrDefault())))
                {
                    var fileEntity = fileEntities.FirstOrDefault(x => x.ResourceFileID == resourceFile.ResourceFileID);
                    if (fileEntity == null)
                    {
                        fileEntity = _mapper.Map <TextResources__ResourceFile>(resourceFile);
                        context.TextResources__ResourceFile.Add(fileEntity);
                    }

                    foreach (var resourceKey in resourceFile.ResourceKeys.Where(x => existingEnvironmentIds.Contains(x.TextResourcesEnvironment_TextResourcesEnvironmentID.GetValueOrDefault())))
                    {
                        var keyEntity = fileEntity.TextResources__ResourceKey.FirstOrDefault(x => x.ResourceKeyID == resourceKey.ResourceKeyID);
                        if (keyEntity == null)
                        {
                            keyEntity = _mapper.Map <TextResources__ResourceKey>(resourceKey);
                            context.TextResources__ResourceKey.Add(keyEntity);
                            fileEntity.TextResources__ResourceKey.Add(keyEntity);
                        }
                        foreach (var resourceValue in resourceKey.ResourceValues.Where(x => existingLanguageIds.Contains(x.Language_LanguageID.GetValueOrDefault())))
                        {
                            var valueEntity = keyEntity.TextResources__ResourceValue.FirstOrDefault(x => x.Language_LanguageID == resourceValue.Language_LanguageID);
                            if (valueEntity == null)
                            {
                                valueEntity = _mapper.Map <TextResources__ResourceValue>(resourceValue);
                                context.TextResources__ResourceValue.Add(valueEntity);
                                keyEntity.TextResources__ResourceValue.Add(valueEntity);
                            }
                        }
                    }
                }

                //var fileEntities = _mapper.Map<TextResources__ResourceFile[]>(files);
                //context.TextResources__ResourceFile.AddRange(fileEntities);
                context.ChangeTracker.DetectChanges();
                try
                {
                    context.SaveChanges();
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException ex)
                {
                }
            }
        }
示例#7
0
        internal async Task SafePage(int page)
        {
            JSONContainer entryList = JSONContainer.NewArray();

            for (int i = page * PAGESIZE; i < pageStorables.Count && i < (page + 1) * PAGESIZE; i++)
            {
                entryList.Add(pageStorables[i].ToJSON());
            }
            await ResourcesModel.WriteJSONObjectToFile(string.Format("{0}page-{1}.json", StorageDirectory, page), entryList);
        }
示例#8
0
        internal static async Task SafeQuotePage(int page)
        {
            JSONObject quoteListJSON = new JSONObject();

            for (int i = page * QUOTE_PAGESIZE; i < QuoteList.Count && i < (page + 1) * QUOTE_PAGESIZE; i++)
            {
                quoteListJSON.Add(QuoteList[i].ToJSON());
            }
            await ResourcesModel.WriteJSONObjectToFile(string.Format("{0}quotes-{1}.json", ResourcesModel.QuotesDirectory, page), quoteListJSON);
        }
示例#9
0
        public void resources_model()
        {
            var model  = NewResourcesModel;
            var model2 = new ResourcesModel(model.ToResources());

            var model3 = NewResourcesModel;

            model.ShouldBe(model2);
            model.ShouldNotBe(model3);
        }
示例#10
0
        private static async Task LoadGuildModerationLog(ulong guildId)
        {
            GuildModerationLog guildModerationLog = new GuildModerationLog(guildId);

            if (Directory.Exists(guildModerationLog.UserDirectory))
            {
                foreach (string filepath in Directory.EnumerateFiles(guildModerationLog.UserDirectory, "*.json"))
                {
                    LoadFileOperation load = await ResourcesModel.LoadToJSONObject(filepath);

                    if (load.Success)
                    {
                        UserModerationLog userModerationLog = new UserModerationLog(guildModerationLog);
                        if (userModerationLog.FromJSON(load.Result))
                        {
                            guildModerationLog.userLogs.Add(userModerationLog.UserId, userModerationLog);
                            if (userModerationLog.IsBanned)
                            {
                                if (userModerationLog.BannedUntil.Value < DateTimeOffset.MaxValue)
                                {
                                    AddTimeLimitedInfractionReference(userModerationLog);
                                }
                            }
                            else if (userModerationLog.IsMuted)
                            {
                                if (userModerationLog.MutedUntil.Value < DateTimeOffset.MaxValue)
                                {
                                    AddTimeLimitedInfractionReference(userModerationLog);
                                }
                            }
                        }
                    }
                }
            }
            if (Directory.Exists(guildModerationLog.ChannelDirectory))
            {
                foreach (string filepath in Directory.EnumerateFiles(guildModerationLog.ChannelDirectory, "*.json"))
                {
                    LoadFileOperation load = await ResourcesModel.LoadToJSONObject(filepath);

                    if (load.Success)
                    {
                        ChannelModerationLog channelModerationLog = new ChannelModerationLog(guildModerationLog);
                        if (channelModerationLog.FromJSON(load.Result))
                        {
                            guildModerationLog.channelLogs.Add(channelModerationLog.ChannelId, channelModerationLog);
                        }
                    }
                }
            }
            GuildLogs.Add(guildModerationLog.GuildId, guildModerationLog);
        }
示例#11
0
        public static async Task SaveAll()
        {
            JSONContainer json = JSONContainer.NewArray();

            foreach (MinecraftGuild guild in guilds)
            {
                if (guild.NameAndColorFound)
                {
                    json.Add(guild.ToJSON());
                }
            }
            await ResourcesModel.WriteJSONObjectToFile(ResourcesModel.GuildsFilePath, json);
        }
        public string Export()
        {
            using (var context = new ResourcesModel())
            {
                var files = context.TextResources__ResourceFile
                            .Include(x => x.TextResources__ResourceKey.Select(y => y.TextResources__ResourceValue))
                            .ToList();

                var dto = _mapper.Map <ResourceFile[]>(files);

                return(JsonConvert.SerializeObject(dto, Formatting.Indented));
            }
        }
示例#13
0
        protected void FillResources()
        {
            var filterModel = resourcesFilterControl.Model;

            var query = from n in HbSession.Query <UM_Resource>()
                        where n.DateDeleted == null
                        select n;

            if (filterModel.ProjectID == Guid.Empty)
            {
                query = from n in query
                        where n.ProjectID == null
                        select n;
            }
            else
            {
                query = from n in query
                        where n.ProjectID == filterModel.ProjectID
                        select n;
            }

            var resources = query.ToList();

            var keyword = (filterModel.Keyword ?? String.Empty).Trim();

            if (!String.IsNullOrWhiteSpace(keyword))
            {
                var list = (from n in resources
                            where n.Name.Contains(keyword) ||
                            n.Value.Contains(keyword)
                            select n).ToList();


                var @set = FullHierarchyTraversal(list, resources).ToHashSet();
                resources = @set.ToList();
            }

            var converter = new ResourceEntityModelConverter(HbSession);

            var model = new ResourcesModel
            {
                List = resources.Select(n => converter.Convert(n)).ToList()
            };

            resourcesControl.Model = model;
            resourcesControl.DataBind();
        }
        public ActionResult Index(string culture)
        {
            var resources = new ResourcesModel();
            // Get Resources

            var items              = new Dictionary <String, String>();
            var resourceSet        = Resources.MobileResource.ResourceManager.GetResourceSet(CultureInfo.CurrentCulture, true, true);
            var CurrentCultureDict = resourceSet.GetEnumerator();

            while (CurrentCultureDict.MoveNext())
            {
                items[(String)CurrentCultureDict.Key] = EscapeJsString(Resources.MobileResource.ResourceManager.GetString((String)CurrentCultureDict.Key));
            }

            resources.Items = items;

            return(View(resources));
        }
示例#15
0
        internal static async Task SafeQuote(int listLocation = -1)
        {
            JSONObject quoteSettings = new JSONObject();

            quoteSettings.AddField(JSON_QUOTEID, nextQuoteId);
            await ResourcesModel.WriteJSONObjectToFile(ResourcesModel.QuoteSettingsFilePath, quoteSettings);

            if (listLocation == -1)
            {
                int pages = (QuoteList.Count - 1) / QUOTE_PAGESIZE;
                for (int i = 0; i <= pages; i++)
                {
                    await SafeQuotePage(i);
                }
            }
            else
            {
                int page = listLocation / QUOTE_PAGESIZE;
                await SafeQuotePage(page);
            }
        }
示例#16
0
        /// <summary>
        /// 新增编辑资源s
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task <bool> AddUpdResources(ResourcesModel model)
        {
            //参数校检
            model.IsNotNull();
            //实体转换
            var entity = model.ToEntity();

            //将密钥明文存储 到描述中
            entity.Secrets?.ForEach(a =>
            {
                //将密码的明文存储到描述字段中
                a.Description = a.Value;
                a.Value       = a.Value.Sha256Encrypt();
            });
            //定义一个返回值
            var returnValue = true;

            //验证新增修改
            if (model.Id.IsNullOrEmpty())
            {
                //默认启用
                entity.Enabled = true;
                await mongoRepository.Command <ApiResource>().AddAsync(entity);
            }
            else
            {
                returnValue = await mongoRepository.Command <ApiResource>().UpdateAsync(a => a.Id == entity.Id, new Dictionary <string, object>
                {
                    { "Updated", DateTime.UtcNow },
                    { "Name", entity.Name },
                    { "Description", entity.Description },
                    { "DisplayName", entity.DisplayName },
                    { "Enabled", entity.Enabled },
                    { "Secrets", entity.Secrets },
                    { "Scopes", entity.Scopes },
                });
            }

            return(returnValue);
        }
示例#17
0
        public static async Task Load()
        {
            var fileOperation = await ResourcesModel.LoadToJSONObject(ResourcesModel.GuildsFilePath);

            if (fileOperation.Success)
            {
                if (fileOperation.Result.IsArray)
                {
                    foreach (JSONField guild_json in fileOperation.Result.Array)
                    {
                        if (guild_json.IsObject)
                        {
                            MinecraftGuild guild = new MinecraftGuild();
                            if (guild.FromJSON(guild_json.Container))
                            {
                                guilds.Add(guild);
                            }
                        }
                    }
                }
            }
        }
示例#18
0
 /// <summary>
 /// 转换成实体
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public static Entities.ApiResource ToEntity(this ResourcesModel model)
 {
     return(Mapper.Map <Entities.ApiResource>(model));
 }
示例#19
0
 public MineBuildingModel(ABuildingView view, ResourcesModel resourcesModel, CityDatabase cityDatabase) : base(view,
                                                                                                               resourcesModel, cityDatabase)
 {
 }
 public void PurchaseBuilding(ResourcesModel purchaser, ResourcesModel cost)
 {
     purchaser.Gold  -= cost.Gold;
     purchaser.Wood  -= cost.Wood;
     purchaser.Stone -= cost.Stone;
 }
 public bool TryPurchaseBuilding(ResourcesModel purchaser, ResourcesModel cost)
 {
     return(purchaser.Gold >= cost.Gold &&
            purchaser.Wood >= cost.Wood &&
            purchaser.Stone >= cost.Stone);
 }
示例#22
0
 public async Task <NarutoResult> Save(ResourcesModel info) => await resourceService.Save(info);
示例#23
0
        public Task Save()
        {
            JSONContainer json = ToJSON();

            return(ResourcesModel.WriteJSONObjectToFile($"{Parent.UserDirectory}/{UserId}.json", json));
        }
示例#24
0
 public ABuildingModel(ABuildingView view, ResourcesModel resourcesModel, CityDatabase cityDatabase)
 {
     _cityDatabase   = cityDatabase;
     _view           = view;
     _resourcesModel = resourcesModel;
 }