private void ReportError_FormClosing(object sender, FormClosingEventArgs e) { if (_telemetry != null) { if (!string.IsNullOrEmpty(_exceptionMessage)) { _telemetry.Write(_operation, "Exception", _exceptionMessage); } if (!string.IsNullOrEmpty(_callStack)) { _telemetry.Write(_operation, "Exception", _callStack); } if (DialogResult == DialogResult.OK) { if (!string.IsNullOrEmpty(UserEmailAddress.Text)) { _telemetry.Write(_operation, "Exception(Data)", UserEmailAddress.Text); } if (!string.IsNullOrEmpty(UserComments.Text)) { _telemetry.Write(_operation, "Exception(Data)", UserComments.Text); } } } }
private void WriteTelemetry(string source, string level, string message) { if (_telemetry != null) { _telemetry.Write(source, level, message); } }
/// <summary> /// Create an OpenXml Word Document from the CML /// </summary> /// <param name="cml">Input Chemistry</param> /// <param name="guid">Bookmark to create</param> /// <param name="options"></param> /// <param name="telemetry"></param> /// <param name="topLeft"></param> /// <returns></returns> public static string CreateFromCml(string cml, string guid, OoXmlV4Options options, IChem4WordTelemetry telemetry, Point topLeft) { string module = $"{_product}.{_class}.{MethodBase.GetCurrentMethod().Name}()"; CMLConverter cc = new CMLConverter(); Model model = cc.Import(cml); if (model.AllErrors.Count > 0 || model.AllWarnings.Count > 0) { if (model.AllErrors.Count > 0) { telemetry.Write(module, "Exception(Data)", string.Join(Environment.NewLine, model.AllErrors)); } if (model.AllWarnings.Count > 0) { telemetry.Write(module, "Exception(Data)", string.Join(Environment.NewLine, model.AllWarnings)); } } string fileName = string.Empty; bool canRender = model.TotalAtomsCount > 0 && (model.TotalBondsCount == 0 || model.MeanBondLength > Core.Helpers.Constants.BondLengthTolerance / 2); if (canRender) { fileName = Path.Combine(Path.GetTempPath(), $"Chem4Word-V3-{guid}.docx"); string bookmarkName = Core.Helpers.Constants.OoXmlBookmarkPrefix + guid; // Create a Wordprocessing document. using (WordprocessingDocument package = WordprocessingDocument.Create(fileName, WordprocessingDocumentType.Document)) { // Add a new main document part. MainDocumentPart mdp = package.AddMainDocumentPart(); mdp.Document = new Document(new Body()); Body docbody = package.MainDocumentPart.Document.Body; // This will be live AddPictureFromModel(docbody, model, bookmarkName, options, telemetry, topLeft); // Save changes to the main document part. package.MainDocumentPart.Document.Save(); } } return(fileName); }
private void OnReleasesPageLinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { string module = $"{_product}.{_class}.{MethodBase.GetCurrentMethod().Name}()"; _telemetry.Write(module, "Action", "Triggered"); try { Process.Start("https://github.com/Chem4Word/Version3/releases/latest"); DialogResult = DialogResult.Cancel; } catch (Exception ex) { new ReportError(_telemetry, Globals.Chem4WordV3.WordTopLeft, module, ex).ShowDialog(); } }
private void ReportError_FormClosing(object sender, FormClosingEventArgs e) { string answer = richTextBox1.Text; if (!string.IsNullOrEmpty(_exceptionMessage)) { _telemetry.Write(_operation, "Exception", _exceptionMessage); } if (!string.IsNullOrEmpty(_callStack)) { _telemetry.Write(_operation, "Exception", _callStack); } if (DialogResult == DialogResult.OK) { if (!string.IsNullOrEmpty(answer)) { _telemetry.Write(_operation, "Exception(Data)", answer); } } }
public OoXmlRenderer(Model.Model model, Options options, IChem4WordTelemetry telemetry, Point topLeft) { string module = $"{_product}.{_class}.{MethodBase.GetCurrentMethod().Name}()"; _options = options; _telemetry = telemetry; _topLeft = topLeft; _telemetry.Write(module, "Verbose", "Called"); LoadFont(); _chemistryModel = model; DetermineInitialExtents(); }
public AutomaticUpdate(IChem4WordTelemetry telemetry) { string module = $"{_product}.{_class}.{MethodBase.GetCurrentMethod().Name}()"; try { _telemetry = telemetry; InitializeComponent(); _telemetry.Write(module, "AutomaticUpdate", "Shown"); } catch (Exception ex) { new ReportError(Globals.Chem4WordV3.Telemetry, Globals.Chem4WordV3.WordTopLeft, module, ex).ShowDialog(); } }
public Run GenerateRun() { string module = $"{_product}.{_class}.{MethodBase.GetCurrentMethod().Name}()"; _telemetry.Write(module, "Verbose", "Called"); //start off progress monitoring Progress pb = new Progress(); pb.TopLeft = _topLeft; //lists of objects for drawing _atomLabelCharacters = new List <AtomLabelCharacter>(); _bondLines = new List <BondLine>(); Stopwatch swr = new Stopwatch(); Stopwatch sw = new Stopwatch(); //Create a run Run run = new Run(); sw.Start(); swr.Start(); //set the median bond length _medianBondLength = GeometryTool.GetMedianBondLength2D(_chemistryModel.AllBonds); int moleculeNo = 0; foreach (Molecule mol in _chemistryModel.Molecules) { moleculeNo++; // Step 1- gather the atom information together Debug.WriteLine($"{module} Starting Step 1"); //_telemetry.Write(module, "Verbose", $"Starting Step 1 for molecule {moleculeNo}"); ProcessAtoms(mol, pb, moleculeNo, _pt); Debug.WriteLine("Elapsed time " + sw.ElapsedMilliseconds.ToString("##,##0") + "ms"); //_telemetry.Write(module, "Timing", $"Step 1 for molecule {moleculeNo} took " + sw.ElapsedMilliseconds.ToString("#,##0", CultureInfo.InvariantCulture) + "ms"); sw.Reset(); sw.Start(); // Step 2- gather the bond information together Debug.WriteLine($"{module} Starting Step 2"); //_telemetry.Write(module, "Verbose", $"Starting Step 2 for molecule {moleculeNo}"); ProcessBonds(mol, pb, moleculeNo); Debug.WriteLine("Elapsed time " + sw.ElapsedMilliseconds.ToString("##,##0") + "ms"); //_telemetry.Write(module, "Timing", $"Step 2 for molecule {moleculeNo} took " + sw.ElapsedMilliseconds.ToString("#,##0", CultureInfo.InvariantCulture) + "ms"); sw.Reset(); sw.Start(); if (_options.ShowRingCentres) { // Save Rings for later foreach (Ring ring in mol.Rings) { _rings.Add(ring.UniqueID, ring); } } } Debug.WriteLine($"{module} Starting Step 3"); //_telemetry.Write(module, "Verbose", "Starting Step 3"); IncreaseCanvasSize(); Debug.WriteLine("Elapsed time " + sw.ElapsedMilliseconds.ToString("##,##0") + "ms"); //_telemetry.Write(module, "Timing", "Step 3 took " + sw.ElapsedMilliseconds.ToString("#,##0", CultureInfo.InvariantCulture) + "ms"); sw.Reset(); sw.Start(); if (_options.ClipLines) { Debug.WriteLine($"{module} Starting Step 4"); //_telemetry.Write(module, "Verbose", "Starting Step 4"); #region Step 4 - Shrink bond lines ShrinkBondLinesPass1(pb); ShrinkBondLinesPass2(pb); #endregion Step 4 - Shrink bond lines Debug.WriteLine("Elapsed time " + sw.ElapsedMilliseconds.ToString("##,##0") + "ms"); //_telemetry.Write(module, "Timing", "Step 4 took " + sw.ElapsedMilliseconds.ToString("#,##0", CultureInfo.InvariantCulture) + "ms"); sw.Reset(); sw.Start(); } Debug.WriteLine($"{module} Starting Step 5"); //_telemetry.Write(module, "Verbose", "Starting Step 5"); #region Step 5 - Create main OoXml drawing objects Drawing drawing1 = new Drawing(); A.Graphic graphic1 = CreateGraphic(); A.GraphicData graphicData1 = CreateGraphicData(); Wpg.WordprocessingGroup wordprocessingGroup1 = new Wpg.WordprocessingGroup(); // Create Inline Drawing using canvas extents Wp.Inline inline1 = CreateInline(graphicData1, wordprocessingGroup1); #endregion Step 5 - Create main OoXml drawing objects Debug.WriteLine("Elapsed time " + sw.ElapsedMilliseconds.ToString("##,##0") + "ms"); //_telemetry.Write(module, "Timing", "Step 5 took " + sw.ElapsedMilliseconds.ToString("#,##0", CultureInfo.InvariantCulture) + "ms"); sw.Reset(); sw.Start(); #region Step 5a - Diagnostics if (_options.ShowMoleculeBoundingBoxes) { DrawBox(wordprocessingGroup1, _modelExtents, "00ff00", 1); foreach (Molecule mol in _chemistryModel.Molecules) { DrawBox(wordprocessingGroup1, mol.BoundingBox, "0000ff", 1); DrawBox(wordprocessingGroup1, MoleculeExtents(mol), "ff0000", 1); } DrawBox(wordprocessingGroup1, _canvasExtents, "000000", 1); } if (_options.ShowRingCentres) { ShowRingCentres(wordprocessingGroup1); } if (_options.ShowAtomPositions) { ShowAtomCentres(wordprocessingGroup1); } if (_options.ShowHulls) { ShowConvexHulls(wordprocessingGroup1); } #endregion Step 5a - Diagnostics Debug.WriteLine($"{module} Starting Step 6"); //_telemetry.Write(module, "Verbose", "Starting Step 6"); #region Step 6 - Create and append OoXml objects for all Bond Lines AppendBondOoxml(pb, wordprocessingGroup1); #endregion Step 6 - Create and append OoXml objects for all Bond Lines Debug.WriteLine("Elapsed time " + sw.ElapsedMilliseconds.ToString("##,##0") + "ms"); //_telemetry.Write(module, "Timing", "Step 6 took " + sw.ElapsedMilliseconds.ToString("#,##0", CultureInfo.InvariantCulture) + "ms"); sw.Reset(); sw.Start(); Debug.WriteLine($"{module} Starting Step 7"); //_telemetry.Write(module, "Verbose", "Starting Step 7"); #region Step 7 - Create and append OoXml objects for Atom Labels AppendAtomLabelOoxml(pb, wordprocessingGroup1); #endregion Step 7 - Create and append OoXml objects for Atom Labels Debug.WriteLine("Elapsed time " + sw.ElapsedMilliseconds.ToString("##,##0") + "ms"); //_telemetry.Write(module, "Timing", "Step 7 took " + sw.ElapsedMilliseconds.ToString("#,##0", CultureInfo.InvariantCulture) + "ms"); sw.Reset(); sw.Start(); Debug.WriteLine($"{module} Starting Step 8"); //_telemetry.Write(module, "Verbose", "Starting Step 8"); #region Step 8 - Append OoXml drawing objects to OoXml run object AppendAllOoXml(graphicData1, wordprocessingGroup1, graphic1, inline1, drawing1, run); #endregion Step 8 - Append OoXml drawing objects to OoXml run object Debug.WriteLine("Elapsed time " + sw.ElapsedMilliseconds.ToString("##,##0") + "ms"); //_telemetry.Write(module, "Timing", "Step 8 took " + sw.ElapsedMilliseconds.ToString("#,##0", CultureInfo.InvariantCulture) + "ms"); sw.Reset(); sw.Start(); double abl = _chemistryModel.MeanBondLength; Debug.WriteLine("Elapsed time for GenerateRun " + swr.ElapsedMilliseconds.ToString("#,##0", CultureInfo.InvariantCulture) + "ms"); _telemetry.Write(module, "Timing", $"Rendering {_chemistryModel.Molecules.Count} molecules with {_chemistryModel.AllAtoms.Count} atoms and {_chemistryModel.AllBonds.Count} bonds took {swr.ElapsedMilliseconds.ToString("##,##0")} ms; Average Bond Length: {abl.ToString("#0.00")}"); ShutDownProgress(pb); return(run); }