示例#1
0
        protected void InitializeWsDocument(string path)
        {
            using (new WsActivationContext())
            {
                try
                {
                    _wsDocument = new tagWSDOCUMENT
                    {
                        bstrLocalFile = path
                    };
                    _docProvider = new DocProviderClass();
                    _docProvider.Resolve(ref _wsDocument);
                    _wsDocument = _docProvider.GetDocument(_wsDocument.bstrDocumentID, (int)wsGetDocFlags.DF_INFO_ONLY);
                    _wsDocument.lConversation = 1;

                    GetVersionInformation();

                    ModifiedTime = _wsDocument.dModifiedTime;
                    DocumentId = _wsDocument.bstrDocumentID;
                    Description = _wsDocument.bstrDescription;

                }
                catch (Exception e)
                {
                    Logger.LogError(e);
                }
            }
        }
        public static ComparisonDocument SelectDocument(string documentName = null)
        {
            var docProvider = new DocProviderClass();

            if (!string.IsNullOrEmpty(documentName))
            {
                var wsDocument = docProvider.GetDocument(documentName, (int)wsGetDocFlags.DF_INFO_ONLY);
                return new ComparisonDocument(wsDocument);
            }
            else
            {
                System.Reflection.Assembly asm = System.Reflection.Assembly.LoadFrom("Workshare.Utilities.dll");
                object[] parameters = new object[1];
                parameters[0] = GetForegroundWindow();
                using ((IDisposable)Activator.CreateInstance(asm.GetType("Workshare.Utilities.DisableWindow"), parameters))
                {
                    var result = docProvider.SelectDocumentEx(Process.GetCurrentProcess().MainWindowHandle.ToInt32(),
                        "Documents (*.docx;*.doc;*.pdf;*.rtf;*.txt)|*.docx; *.doc; *.pdf; *.rtf; *.txt|All files (*.*)|*.*||",
                        "");

                    if (!string.IsNullOrEmpty(result))
                    {
                        var wsDocument = docProvider.GetDocument(result, (int)wsGetDocFlags.DF_INFO_ONLY);
                        return new ComparisonDocument(wsDocument);
                    }
                }
            }
            return null;
        }
 private string GetFullNameFromDms(string dmsDocumentId)
 {
     var docProvider = new DocProviderClass();       
     try
     {
         var doc = docProvider.GetDocument(dmsDocumentId, 0); // we don't want to lock file here so just pass 0 as flag.  
         if (dmsDocumentId.StartsWith("file://"))
         {
             var newPath = Path.Combine(Path.GetDirectoryName(doc.bstrLocalFile), string.Format("{0}.{1}", doc.bstrDescription, doc.bstrExtension));
             File.Move(doc.bstrLocalFile, newPath);
             return newPath;    
         }
         return doc.bstrLocalFile;
     }
     finally
     {
         Marshal.ReleaseComObject(docProvider);
         docProvider = null;
     }
 }
示例#4
0
        private void SaveAsNew()
        {
            try
            {
                var pdfDocument = _activeDocument.WsDocument;
                pdfDocument.bstrLocalFile = _options.Destination;
                pdfDocument.bstrDescription = Path.GetFileName(_options.Destination);
  
                var docProvider = new DocProviderClass();
                docProvider.Resolve(ref pdfDocument);
                int iFormatIndex = 1;
                var hr = docProvider.GetSaveInfoEx(_options.ParentWindow.Handle.ToInt32(), "PDF Documents (*.pdf)|*.pdf||",
                    (int)(wsGetSaveInfoFlags.DF_NEW_DOCUMENT | wsGetSaveInfoFlags.DF_NO_WORKSHARE_SAVEAS_UI), (int)MessageBranding.WsProtect, ref iFormatIndex, ref pdfDocument);

                if (hr == 0)
                {
					pdfDocument.bstrLocalFile = _options.Destination; // need to reset for the save (GetSaveInfoEx clears the field)
                    docProvider.SaveDocument(ref pdfDocument, 0);
                    docProvider.CloseDocument(ref pdfDocument, (int)wsCloseDocFlags.DF_UNLOCK_ONLY);
					_options.DocumentID = pdfDocument.bstrDocumentID;
                }

                _activeDocument.AddActivityToDmsHistory(DmsActivityType.Print);
            }
            catch (COMException e)
            {
                const int cancelledOperation = -2146303990;

                if (e.ErrorCode == cancelledOperation)
                    return;

                Logger.LogError(e);
            }
            catch (Exception e)
            {
                Logger.LogError(e);
            }
        }
示例#5
0
        private void SaveAsRelated()
        {
            try
            {
                var pdfDocument = _activeDocument.WsDocument;
                pdfDocument.bstrLocalFile = _options.Destination;
                pdfDocument.bstrDescription = Path.GetFileNameWithoutExtension(_options.Destination);
                pdfDocument.bstrExtension = Path.GetExtension(_options.Destination);
                    
                var docProvider = new DocProviderClass();
                docProvider.RelateDocument(ref pdfDocument, _activeDocument.DocumentId);
				_options.DocumentID = pdfDocument.bstrDocumentID;
                _activeDocument.AddActivityToDmsHistory(DmsActivityType.Print);
            }
            catch (COMException e)
            {
                const int cancelledOperation = -2146303990;

                if (e.ErrorCode == cancelledOperation)
                    return;

                Logger.LogError(e);
            }
            catch (Exception e)
            {
                Logger.LogError(e);
            }
        }
示例#6
0
        private void SaveLocal()
        {
            try
            {
                var wsDocument = new tagWSDOCUMENT
                {
                    bstrLocalFile = _options.Destination,
                    bstrDescription = Path.GetFileName(_options.Destination)
                };
                    
                var docProvider = new DocProviderClass();
                docProvider.Resolve(ref wsDocument);
                int iFormatIndex = 1;
                docProvider.GetLFSSaveInfo(_options.ParentWindow.Handle.ToInt32(), "PDF Documents (*.pdf)|*.pdf||",
                    (int)(wsGetSaveInfoFlags.DF_NEW_DOCUMENT | wsGetSaveInfoFlags.DF_NO_WORKSHARE_SAVEAS_UI), ref iFormatIndex, ref wsDocument);

                wsDocument.bstrLocalFile = _options.Destination;
                docProvider.SaveDocument(ref wsDocument, 0);
                docProvider.CloseDocument(ref wsDocument, (int)wsCloseDocFlags.DF_UNLOCK_ONLY);
				_options.LocalFile = wsDocument.bstrLocalFile; // for open once if necc
				_activeDocument.AddActivityToDmsHistory(DmsActivityType.Print);
            }
            catch (COMException e)
            {
                const int cancelledOperation = -2146303990;

                if (e.ErrorCode == cancelledOperation)
                    return;

                Logger.LogError(e);
            }
            catch (Exception e)
            {
                Logger.LogError(e);
            }
        }
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            if (!this.Dispatcher.CheckAccess())
            {
                this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.SystemIdle, TimeSpan.FromSeconds(1),
                   new System.Action(delegate()
                   {
                       btnSave_Click(sender, e);
                   }
                ));
            }
            else
            {
                try
                {
                    Button b = sender as Button;
                    if (b == null)
                        return;

                    AttachedComparison comp = b.DataContext as AttachedComparison;
                    if (comp == null)
                        return;

                    tagWSDOCUMENT doc = new tagWSDOCUMENT();
                    doc.bstrDescription = Path.ChangeExtension(comp.Title, "rtf");
                    doc.bstrExtension = "rtf";
                    doc.bstrLocalFile = comp.RedlineRtfPath;
                    int formatIndex = 1;

                    DocProviderClass docProv = new DocProviderClass();
                    if (docProv != null)
                    {
						HwndSource source = HwndSource.FromVisual(this) as HwndSource;
						int hWnd = source == null ? 0 : (int) source.Handle;
                        Int32 retVal = docProv.GetSaveInfoEx(hWnd, "Rich text documents (*.rtf)|*.rtf||", (int)wsGetSaveInfoFlags.DF_NEW_DOCUMENT, 1, ref formatIndex, ref doc);

                        if (retVal == 0) // 0 == S_OK
                        {
                            doc.bstrLocalFile = comp.RedlineRtfPath;
                            const int DF_UNLOCK_ONLY = 1;
                            docProv.SaveDocument(ref doc, 0);
                            docProv.CloseDocument(ref doc, DF_UNLOCK_ONLY);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.LogError(ex);
                    Forms.MessageBox.Show(ex.Message);
                }
            }
        }
        public static void CloseDocumentProviders()
		{
			// setting it to null makes sure the Object is collected by the GC
			m_docprov = null;
		}