예제 #1
0
        /// <summary>
        /// 保存文件
        /// </summary>
        /// <param name="newFileName">使用新文件名</param>
        /// <param name="args">事件参数</param>
        /// <returns>操作是否成功</returns>
        public virtual bool SaveDocument(bool newFileName, WriterCommandEventArgs args)
        {
            string      fileName = args.Document.FileName;
            IFileSystem fs       = args.Host.FileSystems.Docuemnt;

            if (args.Parameter is string)
            {
                if (newFileName == false)
                {
                    fileName = (string)args.Parameter;
                }
            }
            else if (args.Parameter is System.IO.Stream)
            {
                System.IO.Stream stream2 = (System.IO.Stream)args.Parameter;
                args.Document.Save(stream2, FileFormat.XML);
                return(true);
            }
            else if (args.Parameter is System.IO.TextWriter)
            {
                System.IO.TextWriter writer = (System.IO.TextWriter)args.Parameter;
                args.Document.Save(writer, FileFormat.XML);
                return(true);
            }
            if (args.ShowUI)
            {
                if (fileName == null || fileName.Trim().Length == 0 || newFileName)
                {
                    fileName = fs.BrowseSave(args.Host.Services, fileName);
                    if (string.IsNullOrEmpty(fileName))
                    {
                        return(false);
                    }
                }
            }//if

            if (fileName == null || fileName.Trim().Length == 0)
            {
                return(false);
            }

            VFileInfo  info   = fs.GetFileInfo(args.Host.Services, fileName);
            FileFormat format = WriterUtils.ParseFileFormat(info.Format);

            System.IO.Stream stream = fs.Save(args.Host.Services, fileName);
            if (stream != null)
            {
                using (stream)
                {
                    args.Document.Save(stream, format);
                }
                return(true);
            }
            else
            {
                // 未能打开文件,保存失败。
                return(false);
            }
        }
예제 #2
0
        int VFSProvider.GetFileInformation(string filename, out VFileInfo info)
        {
            info = new VFileInfo ();
            if (filename == ROOT) {
                info.Attributes = FileAttributes.Directory;
                info.Length = 0;
            } else {
                info.Attributes = FileAttributes.Normal;
                info.Length = mockLen;
            }
            info.LastAccessTime = DateTime.Now;
            info.LastWriteTime = DateTime.Now;
            info.CreationTime = DateTime.Now;

            return VFSConstants.SUCCESS;
        }
예제 #3
0
 /// <summary>
 /// 更新内容
 /// </summary>
 public void UpdateImageContent()
 {
     if (string.IsNullOrEmpty(this.Source) == false)
     {
         DCSoft.CSharpWriter.Data.IFileSystem fs = this.OwnerDocument.AppHost.FileSystems.Default;
         VFileInfo info = fs.GetFileInfo(this.OwnerDocument.AppHost.Services, this.Source);
         if (info.Exists)
         {
             System.IO.Stream stream = fs.Open(this.OwnerDocument.AppHost.Services, this.Source);
             if (stream != null)
             {
                 using (stream)
                 {
                     XImageValue img = new XImageValue(stream);
                     this.Image = img;
                 }
             }
         }
     }
 }
예제 #4
0
        private void InnerFileOpen(object sender, WriterCommandEventArgs args)
        {
            if (args.Mode == WriterCommandEventMode.QueryState)
            {
                args.Enabled = args.Document != null && args.EditorControl != null;
            }
            if (args.Mode == WriterCommandEventMode.Invoke)
            {
                IFileSystem fs = args.Host.FileSystems.Docuemnt;
                args.Result = false;
                if (args.Document.Modified)
                {
                    if (QuerySave(args) == false)
                    {
                        return;
                    }
                }


                if (args.Parameter is System.IO.Stream)
                {
                    // 用户参数为一个文件流对象,则以XML的格式从这个流中加载数据
                    System.IO.Stream stream = (System.IO.Stream)args.Parameter;
                    args.EditorControl.LoadDocument(stream, FileFormat.XML);
                    args.Document.FileName = null;
                    args.Result            = true;
                    args.Document.OnSelectionChanged();
                    args.Document.OnDocumentContentChanged();
                    return;
                }

                string fileName = null;
                if (args.Parameter is string)
                {
                    // 用户指定文件名了
                    fileName = (string)args.Parameter;
                    if (fileName.StartsWith("rawxml:"))
                    {
                        // 认为是原生态的XML字符串
                        fileName = fileName.Substring("rawxml:".Length);
                        System.IO.StringReader myStr = new System.IO.StringReader(fileName);
                        args.EditorControl.LoadDocument(myStr, FileFormat.XML);
                        args.Document.FileName = null;
                        args.Result            = true;
                        args.Document.OnSelectionChanged();
                        args.Document.OnDocumentContentChanged();
                        return;
                    }
                }
                if (args.ShowUI)
                {
                    fileName = fs.BrowseOpen(args.Host.Services, fileName);
                    if (string.IsNullOrEmpty(fileName))
                    {
                        // 用户取消操作
                        return;
                    }
                }
                VFileInfo info = fs.GetFileInfo(args.Host.Services, fileName);
                if (info.Exists)
                {
                    FileFormat       format = WriterUtils.ParseFileFormat(info.Format);
                    System.IO.Stream stream = fs.Open(args.Host.Services, fileName);
                    if (args.Host.Debuger != null)
                    {
                        args.Host.Debuger.DebugLoadingFile(fileName);
                    }
                    if (stream != null)
                    {
                        int length = 0;
                        using (stream)
                        {
                            //args.Document.FileName = fileName;
                            args.EditorControl.Document.BaseUrl = System.IO.Path.GetDirectoryName(fileName) + "\\";
                            args.Document.FileName = fileName;
                            args.EditorControl.LoadDocument(stream, format);
                            args.Document.FileName = fileName;
                            length = (int)stream.Length;
                        }
                        if (args.Host.Debuger != null)
                        {
                            args.Host.Debuger.DebugLoadFileComplete(length);
                        }
                        args.Document.OnSelectionChanged();
                        args.Document.OnDocumentContentChanged();
                        args.Document.FileName = fileName;
                        args.Result            = true;
                        args.RefreshLevel      = UIStateRefreshLevel.All;
                    }
                    else
                    {
                        args.Result       = false;
                        args.RefreshLevel = UIStateRefreshLevel.None;
                        return;
                    }
                }
                else
                {
                    if (args.ShowUI)
                    {
                        MessageBox.Show(
                            args.EditorControl,
                            string.Format(WriterStrings.FileNotExist_FileName, fileName),
                            WriterStrings.SystemAlert,
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Information);
                    }
                    args.Result = false;
                }
            }
        }
예제 #5
0
        protected void InsertFileContent(object sender, WriterCommandEventArgs args)
        {
            if (args.Mode == WriterCommandEventMode.QueryState)
            {
                args.Enabled = args.DocumentControler != null &&
                               args.Document != null &&
                               args.DocumentControler.CanInsertElementAtCurrentPosition(
                    typeof(DomElement));
            }
            else if (args.Mode == WriterCommandEventMode.Invoke)
            {
                args.Result = false;
                DomDocument document = null;
                string      fileName = null;
                if (args.Parameter is string)
                {
                    fileName = (string)args.Parameter;
                }
                else if (args.Parameter is DomDocument)
                {
                    document = (DomDocument)args.Parameter;
                }
                if (document == null)
                {
                    IFileSystem fs = args.Host.FileSystems.Docuemnt;
                    if (fs != null)
                    {
                        if (args.ShowUI)
                        {
                            // 浏览文件
                            fileName = fs.BrowseOpen(args.Host.Services, fileName);
                        }
                        if (string.IsNullOrEmpty(fileName))
                        {
                            return;
                        }
                        VFileInfo info = fs.GetFileInfo(args.Host.Services, fileName);
                        if (info.Exists == false)
                        {
                            // 文件不存在
                            return;
                        }
                        //打开文件
                        if (args.Host.Debuger != null)
                        {
                            args.Host.Debuger.DebugLoadingFile(fileName);
                        }
                        System.IO.Stream stream = fs.Open(args.Host.Services, fileName);
                        if (stream != null)
                        {
                            FileFormat format = WriterUtils.ParseFileFormat(info.Format);
                            using (stream)
                            {
                                // 读取文件,加载文档对象
                                document         = new DomDocument();
                                document.Options = args.Document.Options;

                                document.ServerObject = args.Document.ServerObject;
                                document.Load(stream, format);
                                if (args.Host.Debuger != null)
                                {
                                    args.Host.Debuger.DebugLoadFileComplete((int)stream.Length);
                                }
                            }
                        }
                    }
                }
                if (document != null &&
                    document.Body != null &&
                    document.Body.Elements.Count > 0)
                {
                    // 导入文档内容
                    DomElementList list = document.Body.Elements;
                    args.Document.ImportElements(list);
                    args.DocumentControler.InsertElements(list);
                    args.Result = list;
                }
            }
        }