コード例 #1
0
        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;
        }
コード例 #2
0
        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;
        }
コード例 #3
0
        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);
                }
            }
        }
コード例 #4
0
        public override void RemoveMetadata(TempFileForActions tempFile, CleanActionPropertySet cleanProperties)
        {
            CMetadataElements elementsToClean = GetMetaDataElementsToClean(cleanProperties);
            CExcludedMetadataElements excludedElements = GetMetaDataElementsToExclude(cleanProperties);
            
            CMetadataElements reviewersOnlyElements = new CMetadataElements();
            reviewersOnlyElements.SelectNoElements();
            reviewersOnlyElements["Reviewers"].Enabled = elementsToClean["Reviewers"].Enabled;

            int lDttm = 0;
            bool bExcludeSaveDate = FieldIsExcluded(excludedElements, "savedate");

            if (elementsToClean["DocumentStatistics"].Enabled && !bExcludeSaveDate)   // if zeroed, do not re-zero
            {
                lDttm = -1; // don't bother with dttm Revision
            }

            // We clean reviews on the binary level first to get ride of them correctly.

            if (!(bool) cleanProperties[CleanOption.SkipDomCleaning].Value)
            {
                lDttm = ExecuteStrategy3(tempFile.TempFile, lDttm, reviewersOnlyElements, excludedElements, "Metawall.WordBinaryStripper");
                DoDomRemoval(tempFile.TempFile, cleanProperties);
            }

            // Clean all binary metadata again, the DOM clean would have inserted some metadata.
            ExecuteStrategy3(tempFile.TempFile, lDttm, elementsToClean, excludedElements, "Metawall.WordBinaryStripper");
        }
コード例 #5
0
        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);
                }
            }
        }
コード例 #6
0
        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;
        }