Skip to content

Commit

Permalink
Merged PR 33: 3.0.7 Beta 7 - merge Beta6-Bug-Fixes to master
Browse files Browse the repository at this point in the history
* Change updater to remove passive switch as this is sometimes failing to update.
* Record ChEBI and PubChem Id being inserted, to allow better diagnostics.
* Change release version to "3.0.7 Beta 7".
* Add extra data about machine using WMI.
* Inform user of posative status after manual update check.
* Add CultureInfo.InvariantCulture to Telemetry timings.
* Change Updater to remove /passive as it has stopped working.
* Give Chem4Word-Updater a random name when copying it to run, just in case it gets run twice.
* Record  download time and speed of Update and Setup

Related work items: #274
  • Loading branch information
MikeWilliams-UK committed Nov 18, 2017
2 parents c4fc1ec + df82b63 commit 35f98db
Show file tree
Hide file tree
Showing 70 changed files with 1,249 additions and 728 deletions.
12 changes: 6 additions & 6 deletions src/Chem4Word.V3/Chem4WordV3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1422,19 +1422,19 @@ private void OnContentControlAfterAdd(Word.ContentControl NewContentControl, boo
{
Debug.WriteLine($"{module}");

if (!InUndoRedo && !string.IsNullOrEmpty(NewContentControl.Tag))
if (!InUndoRedo && !string.IsNullOrEmpty(NewContentControl?.Tag))
{
Debug.WriteLine(" Looking for " + NewContentControl.Tag);
Debug.WriteLine(" Looking for " + NewContentControl?.Tag);

Word.Document doc = NewContentControl.Application.ActiveDocument;
Word.Application app = Globals.Chem4WordV3.Application;
CustomXMLPart cxml = CustomXmlPartHelper.GetCustomXmlPart(NewContentControl.Tag, app.ActiveDocument);
CustomXMLPart cxml = CustomXmlPartHelper.GetCustomXmlPart(NewContentControl?.Tag, app.ActiveDocument);
if (cxml == null)
{
if (doc.Application.Documents.Count > 1)
{
Word.Application app1 = Globals.Chem4WordV3.Application;
cxml = CustomXmlPartHelper.FindCustomXmlPart(NewContentControl.Tag, app1.ActiveDocument);
cxml = CustomXmlPartHelper.FindCustomXmlPart(NewContentControl?.Tag, app1.ActiveDocument);
if (cxml != null)
{
// Generate new molecule Guid and apply it
Expand Down Expand Up @@ -1468,9 +1468,9 @@ private void OnContentControlBeforeDelete(Word.ContentControl contentControl, bo
try
{
Debug.WriteLine($"{module.Replace("()", $"({contentControl.Application.ActiveDocument.Name})")}");
//Debug.WriteLine("CC ID: " + contentControl.ID + " Tag: " + contentControl.Tag + " Title: " + contentControl.Title);
//Debug.WriteLine("CC ID: " + contentControl.ID + " Tag: " + contentControl?.Tag + " Title: " + contentControl.Title);
//WordInterop.Document doc = contentControl.Application.ActiveApp;
//CustomXMLPart cxml = GetCustomXmlPart(contentControl.Tag);
//CustomXMLPart cxml = GetCustomXmlPart(contentControl?.Tag);
//if (cxml != null)
//{
// cxml.Delete();
Expand Down
62 changes: 27 additions & 35 deletions src/Chem4Word.V3/Data/Chem4Word-Versions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,29 @@
<ChangeLog>
<Id>f3c4f4db-2fff-46db-b14a-feb8e09f7742</Id>
<Version>
<Number>3.0.5 Beta 6</Number>
<Number>3.0.7 Beta 7</Number>
<IsBeta>true</IsBeta>
<Released>01-Nov-2017</Released>
<Released>18-Nov-2017</Released>
<Changes>
<Change>Add extra menus to Help, to open manual, WebSite, YouTube and Manual Update Check</Change>
<Change>Prevent structures with half bonds being sent to ChemSpider</Change>
<Change>Handle error when TaskPane has already been closed</Change>
<Change>Handle error when Ribbon is null</Change>
<Change>Handle error when Library can't be copied</Change>
<Change>Make Chem4WordSetup.exe single instance</Change>
<Change>Allow Chem4Word-Versions.xml and updates to be deployed to multiple domains</Change>
<Change>Ensure Chem4WordUpdater.exe copy was successful before trying to run it</Change>
<Change>Revised Office version detection</Change>
<Change>Change updater to remove passive switch as this is sometimes failing to update. Please download Chem4Word-Setup.exe from https://github.com/Chem4Word/Version3/releases if you encounter any dificulties updating.</Change>
<Change>Add option to Render Carbon Atoms.</Change>
</Changes>
<Url>https://www.chem4word.co.uk/files3/Chem4Word-Setup.3.0.7.Beta.7.msi</Url>
</Version>
<Version>
<Number>3.0.6 Beta 6</Number>
<IsBeta>true</IsBeta>
<Released>05-Nov-2017</Released>
<Changes>
<Change>Add extra menus to Help, to open manual, WebSite, YouTube and Manual Update Check.</Change>
<Change>Prevent structures with half bonds being sent to ChemSpide.r</Change>
<Change>Handle error when TaskPane has already been closed.</Change>
<Change>Handle error when Ribbon is null.</Change>
<Change>Handle error when Library can't be copied.</Change>
<Change>Make Chem4WordSetup.exe single instance.</Change>
<Change>Allow Chem4Word-Versions.xml and updates to be deployed to multiple domains.</Change>
<Change>Ensure Chem4WordUpdater.exe copy was successful before trying to run it.</Change>
<Change>Revised Office version detection.</Change>
</Changes>
<Url>https://www.chem4word.co.uk/files3/Chem4Word-Setup.3.0.6.Beta.6.msi</Url>
</Version>
Expand All @@ -24,7 +34,7 @@
<IsBeta>true</IsBeta>
<Released>18-Oct-2017</Released>
<Changes>
<Change>Fix glitch with detection of Office 365 (2016) installation</Change>
<Change>Fix glitch with detection of Office 365 (2016) installation.</Change>
</Changes>
<Url>https://www.chem4word.co.uk/files3/Chem4Word-Setup.3.0.5.Beta.5.msi</Url>
</Version>
Expand All @@ -33,8 +43,8 @@
<IsBeta>true</IsBeta>
<Released>15-Oct-2017</Released>
<Changes>
<Change>Prevent legacy chemistry being erased when saving document, if user chose not to upgrade</Change>
<Change>Prevent error if user tries to insert V3000 molfile</Change>
<Change>If user chooses not to upgrade, prevent legacy chemistry being erased when saving a document.</Change>
<Change>Handle error caused if user tries to insert a V3000 molfile.</Change>
</Changes>
<Url>https://www.chem4word.co.uk/files3/Chem4Word-Setup.3.0.4.Beta.4.msi</Url>
</Version>
Expand All @@ -43,28 +53,10 @@
<IsBeta>true</IsBeta>
<Released>04-Oct-2017</Released>
<Changes>
<Change>Fix some null poniter exceptions caused by legacy (V2) data</Change>
<Change>Add telemetry to ChemDoodle Web Editor to monitor start up time</Change>
<Change>Fix ChEBI Search</Change>
<Change>Fix some null pointer exceptions, caused by legacy (V2) data.</Change>
<Change>Add telemetry to ChemDoodle Web Editor to monitor start up time.</Change>
<Change>Fix ChEBI Search.</Change>
</Changes>
<Url>https://www.chem4word.co.uk/files3/Chem4Word-Setup.3.0.3.Beta.3.msi</Url>
</Version>
<Version>
<Number>3.0.2 Beta 2</Number>
<IsBeta>true</IsBeta>
<Released>18-Jun-2017</Released>
<Changes>
<Change>Installer testing - Do Not Use</Change>
</Changes>
<Url>https://www.chem4word.co.uk/files3/Chem4Word-Setup.3.0.2.Beta.2.msi</Url>
</Version>
<Version>
<Number>3.0.1 Beta 1</Number>
<IsBeta>true</IsBeta>
<Released>08-Jun-2017</Released>
<Changes>
<Change>Installer testing - Do Not Use</Change>
</Changes>
<Url>https://www.chem4word.co.uk/files3/Chem4Word-Setup.3.0.1.Beta.1.msi</Url>
</Version>
</ChangeLog>
4 changes: 2 additions & 2 deletions src/Chem4Word.V3/Data/This-Version.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Version>
<Number>3.0.6 Beta 6</Number>
<Number>3.0.7 Beta 7</Number>
<IsBeta>true</IsBeta>
<Released>05-Nov-2017</Released>
<Released>18-Nov-2017</Released>
</Version>
24 changes: 0 additions & 24 deletions src/Chem4Word.V3/Data/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,30 +47,6 @@ <h1>Chemistry for Word Add-In V3</h1>
<a href="/files3/Chem4Word-Setup.3.0.3.Beta.3.msi">Chem4Word.Setup.3.0.3 Beta 3</a>
</td>
</tr>
<tr>
<td>
Version 3.0.2 - Beta 2
</td>
<td>
<a href="/files3/Chem4Word-Setup.3.0.2.Beta.2.msi">Chem4Word.Setup.3.0.2 Beta 2</a>
</td>
</tr>
<tr>
<td>
Version 3.0.1 - Beta 1
</td>
<td>
<a href="/files3/Chem4Word-Setup.3.0.1.Beta.1.msi">Chem4Word.Setup.3.0.1 Beta 1</a>
</td>
</tr>
<tr>
<td>
Version 3.0.0 - Alpha
</td>
<td>
<a href="/files3/Chem4Word-Setup.3.0.0.Alpha.msi">Chem4Word.Setup.3.0.0 Alpha</a>
</td>
</tr>
<tr>
<td>
Version History
Expand Down
99 changes: 66 additions & 33 deletions src/Chem4Word.V3/Helpers/ConfigWatcher.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Chem4Word.View;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Chem4Word.Helpers
{
public class ConfigWatcher
{
// Files to watch for
private const string _filter = "*.json";
private const string _attributeShowHydrogens = "ShowHydrogens";
private const string _attributeColouredAtoms = "ColouredAtoms";

// Config settings to watch
private Config[] _watchedConfigs = {
new Config { Name = "ShowHydrogens", Type = "bool" },
new Config { Name = "ShowCarbons", Type = "bool" },
new Config { Name = "ColouredAtoms", Type = "bool" }};

private FileSystemWatcher _watcher;
private string _watchedPath;
Expand All @@ -27,9 +28,11 @@ public ConfigWatcher(string watchedPath)
_watchedPath = watchedPath;

_watcher = new FileSystemWatcher();

_watcher.Path = _watchedPath;
_watcher.NotifyFilter = NotifyFilters.LastWrite;
_watcher.Filter = _filter;
_watcher.NotifyFilter = NotifyFilters.LastWrite;

_watcher.Changed += OnChanged;
_watcher.EnableRaisingEvents = true;
}
Expand All @@ -39,63 +42,84 @@ private void OnChanged(object source, FileSystemEventArgs e)
if (_handleEvents)
{
_handleEvents = false;
JToken tokenShowHydrogens = null;
JToken tokenColouredAtoms = null;
_watcher.EnableRaisingEvents = false;

Dictionary<string, Config> sourceConfigs = new Dictionary<string, Config>();

string thisFile = e.FullPath;
Debug.WriteLine($"Trigger file is {thisFile}");
Thread.Sleep(250);

using (StreamReader sr = File.OpenText(e.FullPath))
{
using (JsonTextReader reader = new JsonTextReader(sr))
{
JObject jObject = (JObject)JToken.ReadFrom(reader);
tokenShowHydrogens = jObject[_attributeShowHydrogens];
tokenColouredAtoms = jObject[_attributeColouredAtoms];
foreach (var config in _watchedConfigs)
{
JToken t = jObject[config.Name];
if (t != null)
{
sourceConfigs.Add(config.Name, new Config { Type = config.Type, Value = t.Value<string>() });
}
}
}
}

if (tokenShowHydrogens != null && tokenColouredAtoms != null)
if (sourceConfigs.Any())
{
bool showHydrogens = tokenShowHydrogens.Value<bool>();
bool colouredAtoms = tokenColouredAtoms.Value<bool>();

string[] files = Directory.GetFiles(_watchedPath, _filter);
foreach (var file in files)
{
if (!file.Equals(thisFile))
{
JToken tokenShowHydrogensOther = null;
JToken tokenColouredAtomsOther = null;
JObject jObject = null;

List<JToken> targetTokens = new List<JToken>();
using (StreamReader sr = File.OpenText(file))
{
using (JsonTextReader reader = new JsonTextReader(sr))
{
jObject = (JObject)JToken.ReadFrom(reader);
tokenShowHydrogensOther = jObject[_attributeShowHydrogens];
tokenColouredAtomsOther = jObject[_attributeColouredAtoms];
foreach (var config in _watchedConfigs)
{
JToken t = jObject[config.Name];
if (t != null)
{
targetTokens.Add(t);
}
}
}
}

if (tokenShowHydrogensOther != null && tokenColouredAtomsOther != null)
if (targetTokens.Any())
{
bool showHydrogensOther = tokenShowHydrogensOther.Value<bool>();
bool colouredAtomsOther = tokenColouredAtomsOther.Value<bool>();

bool write = false;
if (colouredAtomsOther != colouredAtoms)
{
jObject[_attributeColouredAtoms] = colouredAtoms;
write = true;
}
if (showHydrogensOther != showHydrogens)

foreach (var target in targetTokens)
{
jObject[_attributeShowHydrogens] = showHydrogens;
write = true;
foreach (var kvp in sourceConfigs)
{
if (target.Path.Equals(kvp.Key))
{
if (!target.Value<string>().Equals(kvp.Value.Value))
{
Debug.WriteLine($"Changing setting {kvp.Key} to {kvp.Value.Value}");
switch (kvp.Value.Type)
{
case "bool":
jObject[kvp.Key] = bool.Parse(kvp.Value.Value);
write = true;
break;
}
}
}
}
}

if (write)
{
Debug.WriteLine($"Writing file {file}");
string json = JsonConvert.SerializeObject(jObject, Formatting.Indented);
File.WriteAllText(file, json);
}
Expand All @@ -104,8 +128,17 @@ private void OnChanged(object source, FileSystemEventArgs e)
}
}

_watcher.EnableRaisingEvents = true;
_handleEvents = true;
}
}

}

public class Config
{
public string Type { get; set; }
public string Name { get; set; }
public string Value { get; set; }
}
}
4 changes: 2 additions & 2 deletions src/Chem4Word.V3/Helpers/CustomXMLPartHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public static void RemoveOrphanedXmlParts(Word.Document doc)
{
if (cc.Title != null && cc.Title.Equals(Constants.ContentControlTitle))
{
string guid = GuidFromTag(cc.Tag);
string guid = GuidFromTag(cc?.Tag);

if (!string.IsNullOrEmpty(guid))
{
Expand Down Expand Up @@ -149,7 +149,7 @@ public static void Diagnostics(Word.Document doc, string when)
counter++;
Debug.WriteLine("ContentControl: " + ccc.ID);
Debug.WriteLine(" Range.Start: " + ccc.Range.Start);
Debug.WriteLine(" Tag: " + ccc.Tag);
Debug.WriteLine(" Tag: " + ccc?.Tag);
}
}

Expand Down
Loading

0 comments on commit 35f98db

Please sign in to comment.