コード例 #1
0
        public ArkItemsData(ArkItemsData items, List <ArkItemsData> mods) : this()
        {
            if (items?.Items != null)
            {
                Items.AddRange(items.Items);
            }

            foreach (var mod in mods)
            {
                if (mod?.Items != null)
                {
                    Items.AddRange(mod.Items);
                }
            }
        }
コード例 #2
0
        public async Task LoadOrUpdate(int[] modIds)
        {
            Task updateTask = null;

            lock (_lock)
            {
                if (_updateTask == null)
                {
                    updateTask = _updateTask = Task.Run(async() =>
                    {
                        try
                        {
                            // items.json
                            var data = await DownloadResource <ArkItemsData>(_obeliskUrl + _itemsUrl, _itemsFileName);
                            if (data != null)
                            {
                                Items = data;
                            }

                            // _manifest.json
                            var manifest = await DownloadResource <ObeliskManifest>(_obeliskUrl + _manifestUrl, _manifestFileName);
                            if (manifest != null)
                            {
                                Manifest = manifest;
                            }

                            // mods
                            if (modIds?.Length > 0)
                            {
                                foreach (var modId in modIds)
                                {
                                    var strModId = modId.ToString();
                                    var mod      = Manifest?.Files?.FirstOrDefault(x => x.Value?.Mod?.Id.Equals(strModId) == true && x.Key.EndsWith("/items.json", StringComparison.OrdinalIgnoreCase));

                                    var modData = await DownloadResource <ArkItemsData>(mod.HasValue ? _obeliskUrl + mod.Value.Key : null, $"obelisk-wiki-items-{modId}.json", skipDownload: mod == null);
                                    if (modData != null)
                                    {
                                        ViewModel.Workspace.Instance.Console.AddLog("Loaded item data for " + (mod.HasValue ? $"{mod.Value.Value.Mod.Title} ({modId})" : $"'{modId}'") + ".");
                                        Mods.Add(modData);
                                    }
                                    //else
                                    //{
                                    //    ViewModel.Workspace.Instance.Console.AddLog($"Mod '{modId}' is not supported and could result in some data missing from the web app.");
                                    //}
                                }
                            }

                            Data = new ArkItemsData(Items, Mods);
                        }
                        finally
                        {
                            lock (_lock)
                            {
                                _updateTask = null;
                            }
                        }
                    });
                }
                else
                {
                    updateTask = _updateTask;
                }
            }

            await updateTask;
        }