Ejemplo n.º 1
0
 private DocumentContent LoadDocumentContent(DocumentFile documentFile)
 {
     Trace.WriteLine(">> Load document content: " + documentFile.FileName);
     using (var stream = new FileStream(documentFile.FileName, FileMode.Open, FileAccess.Read))
     {
         using (var reader = new StreamReader(stream, Encoding.UTF8))
         {
             var documentContent = new DocumentContent()
             {
                 Code = reader.ReadToEnd()
             };
             documentFile.ResetModified();
             return(documentContent);
         }
     }
 }
Ejemplo n.º 2
0
        private void NewCore(DocumentType documentType, string code = null)
        {
            int startCaretPosition = 0;

            if (string.IsNullOrEmpty(code))
            {
                code = documentType == DocumentType.CSharp ? TemplateCode.InitialCSharpCode : TemplateCode.InitialVisualBasicCode;
                startCaretPosition = documentType == DocumentType.CSharp ? TemplateCode.StartCaretPositionCSharp : TemplateCode.StartCaretPositionVisualBasic;
            }
            string fileName = "Script" + (documentCounter + 1) + (documentType == DocumentType.CSharp ? ".cs" : ".vb");
            var    document = new DocumentFile(documentType, fileName, code, startCaretPosition);

            document.ResetModified();
            fileService.AddDocument(document);
            ActiveDocumentFile = document;
            documentCounter++;
        }
Ejemplo n.º 3
0
 private void SaveCore(DocumentFile document, string fileName)
 {
     try
     {
         using (var stream = new FileStream(fileName, FileMode.Create, FileAccess.Write))
         {
             using (var writer = new StreamWriter(stream, Encoding.UTF8))
             {
                 writer.Write(document.Content.Code);
             }
         }
         document.FileName = fileName;
         document.ResetModified();
     }
     catch (Exception e)
     {
         Trace.TraceError(e.ToString());
         messageService.ShowError(shellService.ShellView, string.Format(CultureInfo.CurrentCulture, Resources.SaveFileError, fileName));
     }
 }