private bool ExecuteUsingOptimisingAddin(object document, CMetadataElements elementsToClean, CExcludedMetadataElements excludedElements) { if (null == document) return false; Word.Document wordDocument = null; Word._Application application = null; Office.COMAddIns comAddins = null; Office.COMAddIn officeAddin = null; try { wordDocument = document as Word.Document; if (null == wordDocument) return false; application = wordDocument.Application; if (null == application) return false; comAddins = application.COMAddIns; if (null == comAddins) return false; object addinIndex = "WPWordOptimisingAddin.Interceptor"; officeAddin = comAddins.Item(ref addinIndex); if (null == officeAddin) return false; officeAddin.Object.GetType().InvokeMember("ExecuteStrategy2", System.Reflection.BindingFlags.InvokeMethod, null, officeAddin.Object, new object[] { document, elementsToClean, excludedElements, m_domStripperProgId }, System.Globalization.CultureInfo.InvariantCulture); } catch (System.Exception e) { Logger.LogError("Word Optimising Addin is not registered or is disabled. Exception details trace follow:"); Logger.LogError(e); return false; } finally { if (null != officeAddin) System.Runtime.InteropServices.Marshal.ReleaseComObject(officeAddin); if (null != comAddins) System.Runtime.InteropServices.Marshal.ReleaseComObject(comAddins); if (null != application) System.Runtime.InteropServices.Marshal.ReleaseComObject(application); } return true; }
private bool ExecuteUsingOptimisingAddin(object document, CMetadataElements elementsToClean, CExcludedMetadataElements excludedElements) { if (null == document) return false; Word.Document wordDocument = null; Word._Application application = null; Office.COMAddIns comAddins = null; Office.COMAddIn officeAddin = null; try { wordDocument = document as Word.Document; if (null == wordDocument) return false; application = wordDocument.Application; if (null == application) return false; comAddins = application.COMAddIns; if (null == comAddins) return false; object addinIndex = "WPWordOptimisingAddin.Interceptor"; officeAddin = comAddins.Item(ref addinIndex); if (null == officeAddin) return false; Interceptor IOptAddin = officeAddin.Object as Interceptor; IOptAddin.ExecuteStrategy2(document, elementsToClean, excludedElements, m_domStripperProgId); } catch (System.Exception e) { Logger.LogError("Word Optimising Addin is not registered or is disabled. Exception details trace follow:"); Logger.LogError(e); return false; } finally { if (null != officeAddin) System.Runtime.InteropServices.Marshal.ReleaseComObject(officeAddin); if (null != comAddins) System.Runtime.InteropServices.Marshal.ReleaseComObject(comAddins); if (null != application) System.Runtime.InteropServices.Marshal.ReleaseComObject(application); } return true; }
protected void ExecuteStrategy2(object document, CMetadataElements elementsToClean, CExcludedMetadataElements excludedElements, string progId) { using (new WsActivationContext()) { IMWStrategy2 strategy = (IMWStrategy2)CreateComObject(progId); if (strategy == null) { return; } try { strategy.Execute2(document, elementsToClean, excludedElements); } finally { Marshal.ReleaseComObject(strategy); } } }
private bool FieldIsExcluded(CExcludedMetadataElements excludedElements, string sField) { for (int i = 1; i <= excludedElements.Count; i++) { if (excludedElements[i].Name.ToString() == "ExcludeFieldCodes") { string sNames = excludedElements[i].Value.ToString().ToLower(System.Globalization.CultureInfo.InvariantCulture); if (sNames.Contains(sField)) { return true; } } } return false; }
protected void ExecuteMetwallBinaryStrategy(object document, CMetadataElements elementsToClean, CExcludedMetadataElements excludedElements, string progId) { using (new WsActivationContext()) { IMWStrategy2 strategy = (IMWStrategy2)CreateComObject(progId); if (null == strategy) return; try { strategy.Execute2(document, elementsToClean, excludedElements); } finally { System.Runtime.InteropServices.Marshal.ReleaseComObject(strategy); } } }
protected int ExecuteStrategy3(object document, int lDttm, CMetadataElements elementsToClean, CExcludedMetadataElements excludedElements, string progId) { using (new WsActivationContext()) { IMWStrategy3 strategy = (IMWStrategy3)CreateComObject(progId); if (strategy == null) { return 0; } try { strategy.Execute3(document, ref lDttm, elementsToClean, excludedElements); } finally { Marshal.ReleaseComObject(strategy); } } return lDttm; }