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; } } }
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)); } }
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++; }