public SaveDocument Mutate(SaveDocument saveDocument) { if (saveDocument == null) { throw new ArgumentNullException(nameof(saveDocument)); } var nextObjetId = int.Parse (saveDocument.Sections.Single(s => s.Name == "Objects") .InnerPairs .Single(p => p.Key == "Size") .Value); saveDocument = ReplaceAreaWithCloneInSection("Cells", saveDocument); saveDocument = CloneObjects(saveDocument, nextObjetId); saveDocument = ReplaceAreaWithCloneInSection("Electricity", saveDocument); saveDocument = ReplaceAreaWithCloneInSection("Water", saveDocument); saveDocument = ReplaceAreaWithCloneInSection("Patrols", saveDocument); return(saveDocument); }
protected override FileInfo SaveAs(DirectoryInfo dir, SaveDocument format) { String basepath = dir.FullName + Separator; FileInfo fileToReturn = new FileInfo(basepath + this.FilePath.Name.Replace(this.FilePath.Extension, HtmlExtension)); switch (format) { case SaveDocument.HtmlIE: this.SaveAsHtml(fileToReturn); return(fileToReturn); case SaveDocument.HtmlAll: SaveAsHtmlAll(fileToReturn); return(fileToReturn); case SaveDocument.Office2003: fileToReturn = new FileInfo(basepath + this.FilePath.Name.Replace(this.FilePath.Extension, Office2003Extension)); this.SaveOffice2003(fileToReturn); return(fileToReturn); default: fileToReturn = new FileInfo(basepath + this.FilePath.Name.Replace(this.FilePath.Extension, DocumentDefaultExtension)); this.Save(fileToReturn); return(fileToReturn); } }
private SaveDocument CloneAreaInSection(string sectionName, SaveDocument saveDocument) { var section = saveDocument.Sections.Single (s => s.Name == sectionName); var offsetX = m_CloneToX - m_CloneFromX; var offsetY = m_CloneToY - m_CloneFromY; var newInnerSections = section.InnerSections .Select(GetContentsWithCoordinates) .Where(r => IsInArea(r, m_CloneFromX, m_CloneFromY)) .Select(r => new SaveSection($"{r.X + offsetX} {r.Y + offsetY}", r.InnerSections, WithoutExcluded(r.InnerPairs))); var allInnerSections = section.InnerSections.Concat(newInnerSections) .ToArray(); var newSection = new SaveSection (sectionName, allInnerSections, WithSizeCorrected(section.InnerPairs, allInnerSections.Length)); return(RepaceSection(newSection, saveDocument)); }
protected override FileInfo SaveAs(DirectoryInfo dir, SaveDocument format) { if (format == SaveDocument.HtmlAll || format == SaveDocument.HtmlIE) { return(this.SaveAsHtml(dir)); } else { throw new NotImplementedException(); } }
public void SaveAsTestOOXml2007() { PowerPoint2007OfficeDocument_Accessor target = new PowerPoint2007OfficeDocument_Accessor(Open(this.demoDoc)); DirectoryInfo dir = new DirectoryInfo("c:\\temp\\demoppt\\");; SaveDocument format = SaveDocument.OOXml2007; FileInfo expected = new FileInfo(dir.FullName + "\\demo.pptx"); FileInfo actual; actual = target.SaveAs(dir, format); Assert.AreEqual(expected.FullName.ToUpperInvariant(), actual.FullName.ToUpperInvariant()); Assert.IsTrue(actual.Exists); }
public void SaveAsTestHtmlIE() { Word2007OfficeDocument_Accessor target = new Word2007OfficeDocument_Accessor(Open(this.demoDoc)); DirectoryInfo dir = new DirectoryInfo(@"c:\temp\tempdemo\"); SaveDocument format = SaveDocument.HtmlIE; FileInfo expected = new FileInfo(dir.FullName + "\\demo.html");; FileInfo actual; actual = target.SaveAs(dir, format); Assert.AreEqual(expected.FullName.ToUpperInvariant(), actual.FullName.ToUpperInvariant()); Assert.IsTrue(actual.Exists); }
public void SaveAsTestOffice2003() { Excel2007OfficeDocument_Accessor target = new Excel2007OfficeDocument_Accessor(Open(this.demoDoc)); DirectoryInfo dir = new DirectoryInfo("c:\\temp\\exceltemp\\"); SaveDocument format = SaveDocument.Office2003; FileInfo expected = new FileInfo(dir.FullName + "\\demo.xls"); FileInfo actual; actual = target.SaveAs(dir, format); Assert.AreEqual(expected.FullName.ToUpperInvariant(), actual.FullName.ToUpperInvariant()); Assert.IsTrue(actual.Exists); }
private static SaveDocument RepaceSection(SaveSection newSection, SaveDocument saveDocument) { var sections = saveDocument.Sections.ToArray(); var sectionIndex = sections.Select((s, i) => new { s, Index = i }) .Single(r => r.s.Name == newSection.Name) .Index; sections[sectionIndex] = newSection; return(new SaveDocument(saveDocument.OuterPairs, sections)); }
public string Persist(SaveDocument saveDocument) { if (saveDocument == null) { throw new ArgumentNullException(nameof(saveDocument)); } ICollection <string> persistedParts = new LinkedList <string>(); PersistPairs(saveDocument.OuterPairs, persistedParts); PersistSections(saveDocument.Sections, persistedParts); return(string.Join(" ", persistedParts)); }
public SaveDocument Mutate(SaveDocument saveDocument) { var outerPairs = saveDocument.OuterPairs.ToDictionary (p => p.Key, p => p.Value); outerPairs["NumCellsX"] = (int.Parse(outerPairs["NumCellsX"]) + m_LengthX).ToString(); outerPairs["NumCellsY"] = (int.Parse(outerPairs["NumCellsY"]) + m_LengthY).ToString(); outerPairs["OriginW"] = (int.Parse(outerPairs["OriginW"]) + m_LengthX).ToString(); outerPairs["OriginH"] = (int.Parse(outerPairs["OriginH"]) + m_LengthY).ToString(); return(new SaveDocument (outerPairs.Select(p => new SavePair(p.Key, p.Value)), ShiftEverything(saveDocument.Sections))); }
private SaveDocument ReplaceAreaWithCloneInSection (string sectionName, SaveDocument saveDocument) { // This ended-up being a mess because I encountered parts of the // save file I hadn't spotted until the end, but I didn't feel // like refectoring, hence the work-around for other inner sections var section = saveDocument.Sections.Single (s => s.Name == sectionName); var regex = new Regex("\\d+ \\d+"); var groupedInnerSections = section.InnerSections .GroupBy(s => regex.IsMatch(s.Name), s => s) .ToDictionary(g => g.Key, g => g.ToArray()); if (!groupedInnerSections.ContainsKey(true)) { groupedInnerSections[true] = new SaveSection[] {}; } if (!groupedInnerSections.ContainsKey(false)) { groupedInnerSections[false] = new SaveSection[] {}; } section = new SaveSection (sectionName, groupedInnerSections[true], section.InnerPairs); saveDocument = RepaceSection(section, saveDocument); saveDocument = RemoveAreaInSection(sectionName, saveDocument); saveDocument = CloneAreaInSection(sectionName, saveDocument); section = saveDocument.Sections.Single(s => s.Name == sectionName); section = new SaveSection (sectionName, section.InnerSections.Concat(groupedInnerSections[false]), section.InnerPairs); return(RepaceSection(section, saveDocument)); }
private SaveDocument RemoveObjectsInCloneToArea (SaveDocument saveDocument) { var section = saveDocument.Sections.Single (s => s.Name == "Objects"); var newInnerSections = section.InnerSections .Select(GetObjectSectionWithCoordinates) .Where(r => !IsInArea(r, m_CloneToX, m_CloneToY)) .Select(r => r.Section) .ToArray(); var newSection = new SaveSection ("Objects", newInnerSections, WithSizeCorrected(section.InnerPairs, newInnerSections.Length)); return(RepaceSection(newSection, saveDocument)); }
protected override FileInfo SaveAs(DirectoryInfo dir, SaveDocument format) { if (format == SaveDocument.HtmlAll || format == SaveDocument.HtmlIE) { return(this.SaveAsHtml(dir)); } else if (format == SaveDocument.Office2003) { String nameDocFile = this.FilePath.Name.Replace(this.FilePath.Extension, Office2003Extension); FileInfo docFile = new FileInfo(dir.FullName + Separator + nameDocFile); this.SaveOffice2003(docFile); return(docFile); } else { String nameDocxFile = this.FilePath.Name.Replace(this.FilePath.Extension, DocumentDefaultExtension); FileInfo docXFile = new FileInfo(dir.FullName + Separator + nameDocxFile); this.Save(docXFile); return(docXFile); } }
private SaveDocument RemoveAreaInSection(string sectionName, SaveDocument saveDocument) { var section = saveDocument.Sections.Single (s => s.Name == sectionName); var newInnerSections = section.InnerSections .Select(GetContentsWithCoordinates) .Where(r => !IsInArea(r, m_CloneToX, m_CloneToY)) .Select(r => new SaveSection($"{r.X} {r.Y}", r.InnerSections, r.InnerPairs)) .ToArray(); var newSection = new SaveSection (sectionName, newInnerSections, WithSizeCorrected(section.InnerPairs, newInnerSections.Length)); return(RepaceSection(newSection, saveDocument)); }
protected override FileInfo SaveAs(DirectoryInfo dir, SaveDocument format) { switch (format) { case SaveDocument.HtmlAll: case SaveDocument.HtmlIE: return(this.SaveAsHtml(dir)); case SaveDocument.Office2003: String nameDocFile = this.FilePath.Name.Replace(this.FilePath.Extension, Office2003Extension); FileInfo docFile = new FileInfo(dir.FullName + Separator + nameDocFile); this.SaveOffice2003(docFile); return(docFile); default: String nameDocxFile = this.FilePath.Name.Replace(this.FilePath.Extension, DocumentDefaultExtension); FileInfo docXFile = new FileInfo(dir.FullName + Separator + nameDocxFile); this.Save(docXFile); return(docXFile); } }
public SaveDocument Mutate(SaveDocument saveDocument) { if (saveDocument == null) { throw new ArgumentNullException(nameof(saveDocument)); } var section = saveDocument.Sections.Single (s => s.Name == "Objects"); var newInnerSections = section.InnerSections .Where(s => !IsObjectOfType(s, m_ObjectType) && !IsObjectContainingType(s, m_ObjectType)) .ToArray(); var newSection = new SaveSection ("Objects", newInnerSections, WithSizeCorrected(section.InnerPairs, newInnerSections.Length)); return(RepaceSection(newSection, saveDocument)); }
private void Parser_OnCompleted(object obj) { Data_Proc(); string path = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\ElibraryList.doc"; SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Filter = "Text files(*.doc)|*.doc|All files(*.*)|*.*"; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { path = saveFileDialog1.FileName; } label3.Text = "Сохранение..."; var save = new SaveDocument(); save.InDoc(data, path); pictureBox1.Enabled = false; label3.Enabled = false; pictureBox1.Visible = false; label3.Visible = false; MessageBox.Show("Сохранено"); this.Close(); }
protected override FileInfo SaveAs(DirectoryInfo dir, SaveDocument format) { FileInfo docX = new FileInfo(presentation.FullName); FileInfo HTMLFile = new FileInfo(dir.FullName + Separator + this.FilePath.Name.Replace(docX.Extension, HtmlExtension)); switch (format) { case SaveDocument.HtmlIE: presentation.SaveAs(HTMLFile.FullName, PowerPoint.PpSaveAsFileType.ppSaveAsHTML, Office.MsoTriState.msoFalse); presentation.Close(); presentation = (PowerPoint.Presentation)application.Presentations.Open(docX.FullName, Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse, Office.MsoTriState.msoTrue); return(HTMLFile); case SaveDocument.HtmlAll: dir.Create(); presentation.SaveAs(HTMLFile.FullName, PowerPoint.PpSaveAsFileType.ppSaveAsHTMLDual, Office.MsoTriState.msoFalse); presentation.Close(); presentation = (PowerPoint.Presentation)application.Presentations.Open(docX.FullName, Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse, Office.MsoTriState.msoTrue); return(HTMLFile); default: throw new NotImplementedException(); } }
/// <summary> /// Save the document in a specific format /// </summary> /// <param name="dir">Directory to save</param> /// <param name="format">Format to use</param> /// <returns></returns> protected abstract FileInfo SaveAs(DirectoryInfo dir, SaveDocument format);
private SaveDocument CloneObjects(SaveDocument saveDocument, int nextObjectId) { var nextUniqueId = long.Parse (saveDocument.OuterPairs.Single(p => p.Key == "ObjectId.next") .Value); var section = saveDocument.Sections.Single (s => s.Name == "Objects"); var offsetX = m_CloneToX - m_CloneFromX; var offsetY = m_CloneToY - m_CloneFromY; var newInnerSections = section.InnerSections .Select(GetObjectSectionWithCoordinates) .Where(r => IsInArea(r, m_CloneFromX, m_CloneFromY)) .Where(r => !m_ExcludedObjectTypes.Contains(r.Section.InnerPairs.Single(p => p.Key == "Type").Value)) .Select(r => { var objectId = nextObjectId++; var newInnerPairs = r.Section.InnerPairs; // ReSharper disable once AccessToModifiedClosure Func <string, double> getPairValue = key => double.Parse(newInnerPairs.Single(p => p.Key == key).Value); // ReSharper disable SpecifyACultureInStringConversionExplicitly newInnerPairs = ReplacePairValue (newInnerPairs, "Pos.x", (getPairValue("Pos.x") + offsetX).ToString()); newInnerPairs = ReplacePairValue (newInnerPairs, "Pos.y", (getPairValue("Pos.y") + offsetY).ToString()); // ReSharper restore SpecifyACultureInStringConversionExplicitly newInnerPairs = ReplacePairValue (newInnerPairs, "Id.i", objectId.ToString()); newInnerPairs = ReplacePairValue (newInnerPairs, "Id.u", nextUniqueId++.ToString()); return(new SaveSection ($"[i {objectId}]", r.Section.InnerSections.Where(s => s.Name != "Connections"), WithoutExcluded(newInnerPairs))); }) .ToArray(); saveDocument = RemoveObjectsInCloneToArea(saveDocument); section = saveDocument.Sections.Single(s => s.Name == "Objects"); var newSection = new SaveSection ("Objects", section.InnerSections.Concat(newInnerSections).ToArray(), WithSizeCorrected(section.InnerPairs, nextObjectId)); saveDocument = RepaceSection(newSection, saveDocument); var outerPairs = ReplacePairValue(saveDocument.OuterPairs, "ObjectId.next", nextUniqueId.ToString()); return(new SaveDocument(outerPairs, saveDocument.Sections)); }
private static AttachmentInfo SaveAsAttachment(object doc, AttachmentInfo attachment, SaveDocument saveDocument) { string fileId = AttachmentManager.GetNewFileID(); string savePath = AttachmentInfo.FileIDToPath(fileId, AttachmentManager.AttachmentRootPath); Directory.CreateDirectory(savePath.Substring(0, savePath.LastIndexOf(@"\"))); saveDocument.Invoke(doc, savePath); attachment.FileID = fileId; if (String.IsNullOrEmpty(attachment.Name)) { attachment.Name = fileId + attachment.Ext; } //attachment.Name = fileName; //attachment.Ext = fileExt; //attachment.Size = fileSize; attachment.LastUpdate = DateTime.Now; attachment.OwnerAccount = YZAuthHelper.LoginUserAccount; FileInfo fileInfo = new FileInfo(savePath); attachment.Size = fileInfo.Length; using (IYZDbProvider provider = YZDbProviderManager.DefaultProvider) { using (IDbConnection cn = provider.OpenConnection()) { provider.Insert(cn, attachment); } } return(attachment); }
/// <summary> /// Updates existing save document /// </summary> /// <param name="save"></param> public void Update(SaveDocument save) { collection.ReplaceOne(Builders <SaveDocument> .Filter.Eq("id", save.Id), save); }