Exemple #1
0
        /// <summary>
        ///  アイテム用のページに移動する.
        /// </summary>
        /// <param name="reason">理由</param>
        /// <param name="item">ページに表示する手描きアイテム</param>
        private void NavigateToItemPage(CanvasPageNavigationReason reason, CanvasItem item)
        {
            var nav = new CanvasPageNavigation()
            {
                Reason = reason,
                Item   = item,
            };

            this.Frame.Navigate(typeof(CanvasPage), nav.Serialize());
        }
Exemple #2
0
        /// <summary>
        ///  手描き入力アイテムを削除する.
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public async Task RemoveItemAsync(CanvasItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            await item.RemoveAsync();

            this.itemsCore.Remove(item);
            this.itemsDataContainer.Values.Remove(item.InternalName);
        }
Exemple #3
0
        /// <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();
        }
Exemple #4
0
        /// <summary>
        ///  手描き入力アイテムを追加する.
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public async Task AddItemAsync(CanvasItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            if ((App.CurrentApp.OnLaunchedDispatcher == null) ||
                App.CurrentApp.OnLaunchedDispatcher.HasThreadAccess)
            {
                AddItemCore(item);
            }
            else
            {
                await App.CurrentApp.OnLaunchedDispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
                                                                   () => { AddItemCore(item); });
            }
        }
Exemple #5
0
        /// <summary>
        /// 外部ファイルに保存されたアイテムを読み込む.
        /// </summary>
        /// <returns></returns>
        private async Task ImportItemsAsync()
        {
            var picker = new Windows.Storage.Pickers.FileOpenPicker();

            picker.FileTypeFilter.Add(".zip");
            var file = await picker.PickSingleFileAsync();

            if (file == null)
            {
                return;
            }

            this.ItemsChanging = true;
            using (var zipArchive = await ZipArchiveHelper.CreateZipArchiveFromFileAsync(file, System.IO.Compression.ZipArchiveMode.Read))
            {
                await CanvasItem.ImportAsync(zipArchive);
            }
            this.ItemsChanging = false;
        }
        /// <summary>
        ///  文字列から復元する.
        /// </summary>
        /// <param name="input">シリアライズされた文字列</param>
        /// <returns></returns>
        public bool Deserialize(string input)
        {
            JsonArray json;

            if (!JsonArray.TryParse(input, out json))
            {
                return(false);
            }

            CanvasPageNavigationReason reason;

            if (!Enum.TryParse(json.GetStringAt(0), out reason))
            {
                return(false);
            }
            this.Reason = reason;

            this.Item = CanvasItemManager.Current.GetItemByInternalName(json.GetStringAt(1));

            return(true);
        }
Exemple #7
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);
                }
            }
        }
        /// <summary>
        /// このページには、移動中に渡されるコンテンツを設定します。前のセッションからページを
        /// 再作成する場合は、保存状態も指定されます。
        /// </summary>
        /// <param name="navigationParameter">このページが最初に要求されたときに
        /// <see cref="Frame.Navigate(Type, Object)"/> に渡されたパラメーター値。
        /// </param>
        /// <param name="pageState">前のセッションでこのページによって保存された状態の
        /// ディクショナリ。ページに初めてアクセスするとき、状態は null になります。</param>
        protected override async void LoadState(Object navigationParameter, Dictionary <String, Object> pageState)
        {
            if (pageState != null)
            {
                if (CanvasItemManager.Current.Items.Count == 0)
                {
                    await CanvasItemManager.Current.LoadAllItemsAsync();
                }

                if ((pageState[PageStateKeyHasNewTraces] as bool?).GetValueOrDefault())
                {
                    var msg = new Windows.UI.Popups.MessageDialog(App.CurrentApp.MyResources["MessageCancelItemBecauseTerminated"]);
                    await msg.ShowAsync();
                }

                var item = CanvasItemManager.Current.GetItemByInternalName(pageState[PageStateKeyItemInternalName] as string);
                if (item == null)
                {
                    if (CanvasItemManager.Current.Items.Count != 0)
                    {
                        this.Frame.GoBack();
                        return;
                    }
                    else
                    {
                        item = new CanvasItem();
                    }
                }
                this.MainCanvas.Item = item;

                if (GetPageStateValue(pageState, PageStateKeyEditMode, false))
                {
                    this.MainCanvas.IsEditing = true;
                }

                if (GetPageStateValue(pageState, PageStateKeyEditToolPanelIsPinned, false))
                {
                    this.editToolPanel_PinButton.IsChecked = true;
                    this.TopAppBar.IsOpen = true;
                }
            }
            else
            {
                var nav = new CanvasPageNavigation();
                if (!nav.Deserialize(navigationParameter as string))
                {
                    this.Frame.GoBack();
                    return;
                }

                this.MainCanvas.Item = nav.Item != null ? nav.Item : new CanvasItem();
                if (nav.Reason == CanvasPageNavigationReason.Play)
                {
                    this.MainCanvas.IsEditing = false;
                    Play();
                }
                else
                {
                    this.MainCanvas.IsEditing = true;
                }
            }
        }
Exemple #9
0
 /// <summary>
 ///  手描き入力アイテムを追加する.
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 private void AddItemCore(CanvasItem item)
 {
     this.itemsDataContainer.Values[item.InternalName] = item.DisplayName;
     this.itemsCore.Add(item);
 }