コード例 #1
0
ファイル: CanvasItem.cs プロジェクト: zaki3gh/CanvasPlay
        /// <summary>
        ///  外部に保存した手描き入力を読み込む.
        /// </summary>
        /// <param name="sourceArchive"></param>
        /// <returns></returns>
        public static async Task ImportAsync(System.IO.Compression.ZipArchive sourceArchive)
        {
            if (sourceArchive == null)
            {
                throw new ArgumentNullException("sourceArchive");
            }

            var workdir = await ApplicationData.Current.TemporaryFolder.CreateFolderAsync("ItemImport", CreationCollisionOption.ReplaceExisting);

            await ZipArchiveHelper.ExtractFromFileAsync(sourceArchive, workdir);

            var itemsDir = await workdir.GetFoldersAsync();

            foreach (var itemDir in itemsDir)
            {
                var item = new CanvasItem();
                if (!await item.SaveAsync())
                {
                    continue;
                }

                var propertyFile = (await workdir.TryGetItemAsync(String.Format(PropertyEntryNameFormat, itemDir.Name))) as StorageFile;
                if (propertyFile == null)
                {
                    continue;
                }
                var propertyText = await FileIO.ReadTextAsync(propertyFile, Windows.Storage.Streams.UnicodeEncoding.Utf8);

                item.DeserializeProperties(propertyText);
                await propertyFile.DeleteAsync();

                var newItemDir = await ApplicationData.Current.LocalFolder.GetFolderAsync(item.InternalName);

                foreach (var file in await itemDir.GetFilesAsync())
                {
                    await file.MoveAsync(newItemDir, file.Name, NameCollisionOption.ReplaceExisting);
                }

                if (!await item.LoadAsync())
                {
                    continue;
                }
                await CanvasItemManager.Current.AddItemAsync(item);
            }
            await workdir.DeleteAsync();
        }
コード例 #2
0
        /// <summary>
        ///  管理されている手描き入力アイテムをロードする.
        /// </summary>
        /// <returns></returns>
        public async Task LoadAllItemsAsync()
        {
            if (this.itemsDataContainer == null)
            {
                return;
            }

            List <string> removeList = null;

            foreach (var itemData in this.itemsDataContainer.Values)
            {
                var item = new CanvasItem(itemData.Key)
                {
                    DisplayName = itemData.Value as string,
                };

                var success = await item.LoadAsync();

                if (!success)
                {
                    if (removeList == null)
                    {
                        removeList = new List <string>();
                    }
                    removeList.Add(itemData.Key);
                    continue;
                }

                this.itemsCore.Add(item);
            }

            // 登録情報だけあってファイルがない物は登録解除する
            if (removeList != null)
            {
                foreach (var rm in removeList)
                {
                    this.itemsDataContainer.Values.Remove(rm);
                }
            }
        }