Example #1
0
        /// <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>
        /// <returns></returns>
        public static string CreateFromCml(string cml, string guid, Options options, IChem4WordTelemetry telemetry, Point topLeft)
        {
            CMLConverter cc = new CMLConverter();

            Model.Model m = cc.Import(cml);

            string fileName = Path.Combine(Path.GetTempPath(), $"Chem4Word-V3-{guid}.docx");

            bool canRender = m.AllAtoms.Count > 0 && (m.MeanBondLength > Constants.BondLengthTolerance / 2 || m.AllBonds.Count == 0);

            if (canRender)
            {
                string bookmarkName = "C4W_" + 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 is for test
                    //AddParagraph(docbody, "Hello World", bookmarkName);
                    // This will be live
                    AddPictureFromModel(docbody, m, bookmarkName, options, telemetry, topLeft);

                    // Save changes to the main document part.
                    package.MainDocumentPart.Document.Save();
                }
            }

            return(fileName);
        }
Example #2
0
 public AtomLabelPositioner(List <AtomLabelCharacter> atomLabelCharacters, Dictionary <string, List <Point> > convexHulls, Dictionary <char, TtfCharacter> characterset, PeriodicTable atomDefinitions, IChem4WordTelemetry telemetry)
 {
     _AtomLabelCharacters = atomLabelCharacters;
     _TtfCharacterSet     = characterset;
     _convexhHulls        = convexHulls;
     _telemetry           = telemetry;
 }
 public AtomLabelPositioner(double meanBondLength, List <AtomLabelCharacter> atomLabelCharacters, Dictionary <string, List <Point> > convexHulls, Dictionary <char, TtfCharacter> characterset, IChem4WordTelemetry telemetry)
 {
     _AtomLabelCharacters = atomLabelCharacters;
     _TtfCharacterSet     = characterset;
     _convexhHulls        = convexHulls;
     _telemetry           = telemetry;
     _meanBondLength      = meanBondLength;
 }
Example #4
0
        public ChemicalServices(IChem4WordTelemetry telemetry)
        {
            Telemetry = telemetry;

            // http://byterot.blogspot.com/2016/07/singleton-httpclient-dns.html
            var sp = ServicePointManager.FindServicePoint(new Uri(Constants.Chem4WordWebServiceUri));

            sp.ConnectionLeaseTimeout = 60 * 1000; // 1 minute
        }
 public SettingsHost(AcmeOptions options, IChem4WordTelemetry telemetry, Point topLeft) : this()
 {
     if (!DesignerProperties.GetIsInDesignMode(this))
     {
         UcSettings.AcmeOptions    = options;
         UcSettings.Telemetry      = telemetry;
         UcSettings.OnButtonClick += UcSettingsOnOnButtonClick;
         _topLeft = topLeft;
     }
 }
Example #6
0
        public ChemicalServices(IChem4WordTelemetry telemetry)
        {
            Telemetry = telemetry;

            // http://byterot.blogspot.com/2016/07/singleton-httpclient-dns.html
            string uri = Globals.Chem4WordV3.SystemOptions.Chem4WordWebServiceUri;

            if (!Uri.IsWellFormedUriString(uri, UriKind.Absolute))
            {
                uri = Constants.DefaultChem4WordWebServiceUri;
            }
            var sp = ServicePointManager.FindServicePoint(new Uri(uri));

            sp.ConnectionLeaseTimeout = 60 * 1000; // 1 minute
        }
Example #7
0
        /// <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, Options options, IChem4WordTelemetry telemetry, Point topLeft)
        {
            string module = $"{_product}.{_class}.{MethodBase.GetCurrentMethod().Name}()";

            CMLConverter cc = new CMLConverter();

            Model.Model m = cc.Import(cml);
            if (m.AllErrors.Count > 0 || m.AllWarnings.Count > 0)
            {
                if (m.AllErrors.Count > 0)
                {
                    telemetry.Write(module, "Exception(Data)", string.Join(Environment.NewLine, m.AllErrors));
                }

                if (m.AllWarnings.Count > 0)
                {
                    telemetry.Write(module, "Exception(Data)", string.Join(Environment.NewLine, m.AllWarnings));
                }
            }

            string fileName = Path.Combine(Path.GetTempPath(), $"Chem4Word-V3-{guid}.docx");

            bool canRender = m.AllAtoms.Count > 0 && (m.MeanBondLength > Constants.BondLengthTolerance / 2 || m.AllBonds.Count == 0);

            if (canRender)
            {
                string bookmarkName = 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 is for test
                    //AddParagraph(docbody, "Hello World", bookmarkName);
                    // This will be live
                    AddPictureFromModel(docbody, m, bookmarkName, options, telemetry, topLeft);

                    // Save changes to the main document part.
                    package.MainDocumentPart.Document.Save();
                }
            }

            return(fileName);
        }
Example #8
0
        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();
        }
Example #9
0
        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();
            }
        }
Example #10
0
        public static void SaveAcmeSettings(Options options, IChem4WordTelemetry telemetry, Point topLeft)
        {
            string module = $"{_product}.{_class}.{MethodBase.GetCurrentMethod().Name}()";

            try
            {
                if (!string.IsNullOrEmpty(options.SettingsFile))
                {
                    string temp = JsonConvert.SerializeObject(options, Formatting.Indented);
                    File.WriteAllText(options.SettingsFile, temp);

                    // Clear the Dirty flag
                    options.Dirty = false;
                }
            }
            catch (Exception ex)
            {
                new ReportError(telemetry, topLeft, module, ex).ShowDialog();
            }
        }
Example #11
0
        public static Options LoadAcmeSettings(string settingsFile, IChem4WordTelemetry telemetry, Point topLeft)
        {
            Options result = new Options();

            string module = $"{_product}.{_class}.{MethodBase.GetCurrentMethod().Name}()";

            try
            {
                if (!string.IsNullOrEmpty(settingsFile))
                {
                    if (File.Exists(settingsFile))
                    {
                        string json = File.ReadAllText(settingsFile);
                        result = JsonConvert.DeserializeObject <Options>(json);
                        string temp = JsonConvert.SerializeObject(result, Formatting.Indented);
                        if (!json.Equals(temp))
                        {
                            File.WriteAllText(settingsFile, temp);
                        }
                    }
                    else
                    {
                        result.RestoreDefaults();
                        string json = JsonConvert.SerializeObject(result, Formatting.Indented);
                        File.WriteAllText(settingsFile, json);
                    }

                    result.SettingsFile = settingsFile;
                    // Clear the Dirty flag
                    result.Dirty = false;
                }
            }
            catch (Exception ex)
            {
                new ReportError(telemetry, topLeft, module, ex).ShowDialog();
            }

            return(result);
        }
Example #12
0
        public ReportError(IChem4WordTelemetry telemetry, System.Windows.Point topLeft, string operation, Exception ex)
        {
            InitializeComponent();

            try
            {
                TopLeft    = topLeft;
                _telemetry = telemetry;

                _operation        = operation;
                _callStack        = ex.ToString();
                _exceptionMessage = ex.Message;
                if (ex.InnerException != null)
                {
                    _exceptionMessage += Environment.NewLine + ex.InnerException.Message;
                }
            }
            catch (Exception)
            {
                // Do Nothing
            }
        }
Example #13
0
        public UndoHandler(EditViewModel vm, IChem4WordTelemetry telemetry)
        {
            _editViewModel = vm;
            _telemetry     = telemetry;

            //set up the buffer record
            _startBracket = new UndoRecord
            {
                Description = "#start#",
                Level       = 0,
                UndoAction  = null,
                RedoAction  = null
            };
            _endBracket = new UndoRecord
            {
                Description = "#end#",
                Level       = 0,
                UndoAction  = null,
                RedoAction  = null
            };

            Initialize();
        }
 public AtomLabelPositioner(List <AtomLabelCharacter> atomLabelCharacters, Dictionary <char, TtfCharacter> characterset, PeriodicTable atomDefinitions, IChem4WordTelemetry telemetry)
 {
     m_AtomLabelCharacters = atomLabelCharacters;
     m_TtfCharacterSet     = characterset;
     _telemetry            = telemetry;
 }
Example #15
0
 public Pubchem(IChem4WordTelemetry telemetry)
 {
     Telemetry = telemetry;
 }
Example #16
0
        /// <summary>
        /// Creates the DrawingML objects and adds them to the document
        /// </summary>
        /// <param name="docbody"></param>
        /// <param name="model"></param>
        /// <param name="bookmarkName"></param>
        /// <param name="options"></param>
        /// <param name="telemetry"></param>
        /// <param name="topLeft"></param>
        private static void AddPictureFromModel(Body docbody, Model.Model model, string bookmarkName, Options options, IChem4WordTelemetry telemetry, Point topLeft)
        {
            Paragraph paragraph1 = new Paragraph();

            if (!string.IsNullOrEmpty(bookmarkName))
            {
                BookmarkStart bookmarkstart = new BookmarkStart();
                bookmarkstart.Name = bookmarkName;
                bookmarkstart.Id   = "1";
                paragraph1.Append(bookmarkstart);
            }

            // This is where the work gets done ...
            OoXmlRenderer pic = new OoXmlRenderer(model, options, telemetry, topLeft);

            paragraph1.Append(pic.GenerateRun());

            if (!string.IsNullOrEmpty(bookmarkName))
            {
                BookmarkEnd bookmarkend = new BookmarkEnd();
                bookmarkend.Id = "1";
                paragraph1.Append(bookmarkend);
            }

            docbody.Append(paragraph1);
        }
Example #17
0
 public Chemspider(IChem4WordTelemetry telemetry)
 {
     Telemetry = telemetry;
 }
Example #18
0
        public static void ShowAcmeSettings(EditorCanvas currentEditor, string settingsFile, IChem4WordTelemetry telemetry, Point topLeft)
        {
            var mode = Application.Current.ShutdownMode;

            Application.Current.ShutdownMode = ShutdownMode.OnExplicitShutdown;
            var options = FileUtils.LoadAcmeSettings(settingsFile, telemetry, topLeft);
            var pe      = new SettingsHost(options, telemetry, topLeft);

            ShowDialog(pe, currentEditor);
            Application.Current.ShutdownMode = mode;
        }