Ejemplo n.º 1
0
        /// <summary>
        /// エクスポート
        /// </summary>
        public void Export(ExportSettingModel model)
        {
            bool   fail      = false;
            string ext       = "";
            string filter    = "";
            string exportstr = "";

            try
            {
                switch (model.Kind)
                {
                case ExportKind.Text:
                    exportstr = NodeConverterUtility.ToText(new QuartetEditorDescription(this.Content.Tree), model);
                    ext       = "txt";
                    filter    = "テキストファイル(*.txt)|*.txt|全てのファイル(*.*)|*.*";
                    break;

                case ExportKind.HTML:
                    exportstr = NodeConverterUtility.ToHTML(new QuartetEditorDescription(this.Content.Tree), Path.GetFileNameWithoutExtension(this.FilePath));
                    ext       = "html";
                    filter    = "HTMLファイル(*.html)|*.html|全てのファイル(*.*)|*.*";
                    break;

                case ExportKind.TreeText:
                    var header = ConfigManager.Current.Config.TreeTextCharacters;
                    exportstr = NodeConverterUtility.ToTreeText(new QuartetEditorDescription(this.Content.Tree), header.First());
                    ext       = "txt";
                    filter    = "テキストファイル(*.txt)|*.txt|全てのファイル(*.*)|*.*";
                    break;

                default:
                    throw new NotImplementedException();
                }

                // 保存する
                this._ExportSavePathRequest.OnNext(new Tuple <string, string, Action <string> >(filter, ext, (path) =>
                {
                    if (!string.IsNullOrWhiteSpace(path))
                    {
                        fail = !FileUtility.SaveText(path, exportstr, Encoding.UTF8);
                    }
                    return;
                }));
            }
            catch (Exception)
            {
                fail = true;
            }

            if (fail)
            {
                this._ShowErrorMessageRequest.OnNext("エクスポートに失敗しました…");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// ファイルを保存する
        /// </summary>
        private bool Save(string path, FileType type)
        {
            try
            {
                bool   overwrite      = File.Exists(path);
                bool   result         = false;
                string overwiteSuffix = Path.GetRandomFileName().Substring(0, 5);
                if (overwrite)
                {
                    File.Move(path, path + "." + overwiteSuffix);
                }

                switch (type)
                {
                case FileType.QEDocument:
                {
                    var data = new QuartetEditorDescription(this.Content.Tree);
                    result = FileUtility.SaveJsonObject(path, data);
                }
                break;

                case FileType.TreeText:
                {
                    var header = ConfigManager.Current.Config.TreeTextCharacters;
                    var data   = NodeConverterUtility.ToTreeText(new QuartetEditorDescription(this.Content.Tree), header.First());
                    result = FileUtility.SaveText(path, data, Encoding.UTF8);
                }
                break;

                default:
                    throw new NotImplementedException();
                }

                if (result && overwrite)
                {
                    File.Delete(path + "." + overwiteSuffix);
                }
                return(result);
            }
            catch
            {
            }
            return(false);
        }