/// <summary> /// Save a document /// </summary> /// <param name="Doc"></param> /// <param name="SaveAsUI"></param> /// <param name="Cancel"></param> public void SaveDocument(Document Doc, ref bool SaveAsUI, ref bool Cancel) { TemplateInfo tempInfo = Wkl.MainCtrl.CommonCtrl.GetTemplateInfo(Doc.FullName); if (tempInfo == null) { return; } if (!tempInfo.IsSaving) { string mgrKey = string.Empty; string filePath = Doc.FullName; bool isAutoSaving = tempInfo.IsAutoSave; ManagerProfile mgrPro = Wkl.MainCtrl.ManagerCtrl.CreateProfile(out mgrKey); mgrPro.TemplateType = MarkupUtilities.GetTemplateType(filePath); ContextValidator validator = new ContextValidator(Doc); validator.ValidateBeforeSave(mgrKey); tempInfo.IsAutoSave = true; Cancel = true; SaveAsUI = false; if (!mgrPro.IsCorrect) // not AutoSave then we need to validate, check file path and prevent save event of word object { if (!isAutoSaving) { tempInfo.IsSaving = false; if (mgrPro.WbmKeys.Count == 0) { ShowPopupMessage(MessageUtils.Expand(Properties.Resources.ipe_NotIsProntoDoc, Properties.Resources.ipe_ValidateMessage)); } else { mgrPro.WDoc = Doc; Hcl.SaveMessageDialog saveNotify = new Hcl.SaveMessageDialog(mgrKey); saveNotify.Show(); } } UpdateStatus(MessageUtils.Expand(Properties.Resources.ipm_NotIsProntoDoc, Properties.Resources.ipe_NotSaveMessage)); } else { if (!isAutoSaving && !File.Exists(filePath)) { filePath = GetNewFileName(); } Save(Doc, filePath); SaveUserData(); } Wkl.MainCtrl.ManagerCtrl.RemoveDataObject(mgrKey); } }
/// <summary> /// Save document as pronto template /// </summary> /// <param name="Doc"></param> /// <param name="filePath"></param> /// <param name="isToFinal">true: Actually Save to file. false: save to temp file to get xsl,...</param> public PdwInfo SaveAsTemplate(Document Doc, string filePath, bool isToFinal = true) { TemplateInfo tempInfo = Wkl.MainCtrl.CommonCtrl.GetTemplateInfo(Doc.FullName); if (tempInfo == null) { return(null); } string mgrKey = string.Empty; ManagerProfile mgrPro = Wkl.MainCtrl.ManagerCtrl.CreateProfile(out mgrKey); mgrPro.TemplateType = MarkupUtilities.GetTemplateType(filePath); ContextValidator validator = new ContextValidator(Doc); validator.ValidateBeforeSave(mgrKey); PdwInfo pdwInfo = null; if (!mgrPro.IsCorrect) { tempInfo.IsSaving = false; if (mgrPro.WbmKeys.Count == 0) { ShowPopupMessage(MessageUtils.Expand(Properties.Resources.ipe_NotIsProntoDoc, Properties.Resources.ipe_ValidateMessage)); } else { mgrPro.WDoc = Doc; Hcl.SaveMessageDialog saveNotify = new Hcl.SaveMessageDialog(mgrKey); saveNotify.Show(); } } else { pdwInfo = Save(Doc, filePath, isToFinal: isToFinal); if (isToFinal) { SaveUserData(); } } Wkl.MainCtrl.ManagerCtrl.RemoveDataObject(mgrKey); return(pdwInfo); }
/// <summary> /// Save document information /// </summary> /// <param name="Doc"></param> /// <param name="filePath"></param> /// <param name="isReconstruct"></param> private PdwInfo Save(Document Doc, string filePath, bool isReconstruct = false, bool isToFinal = true) { try { TemplateInfo tempInfo = Wkl.MainCtrl.CommonCtrl.GetTemplateInfo(Doc.FullName); if (tempInfo == null) { return(null); } PdwInfo pdwInfo = null; tempInfo.IsSaving = true; // markup the document is saving if (!string.IsNullOrEmpty(filePath)) { // put where clause into internal bookmark foreach (string domainName in tempInfo.DomainNames) { DomainInfo domainInfo = Wkl.MainCtrl.CommonCtrl.GetDomainInfo(domainName); InternalBookmarkDomain ibmDomain = tempInfo.InternalBookmark.GetInternalBookmarkDomain(domainName); if (ibmDomain != null) { ibmDomain.WhereClause = domainInfo.DSDomainData.WhereClause.Clause; } } // save pdwinfo (checksum, oslq, xslt) pdwInfo = SavePdwInfo(filePath, Doc, isReconstruct); // save internal bookmark mainManager.MainService.PropertyService.SaveInterBookmark(); // save the document if (isToFinal) { TemplateType type = MarkupUtilities.GetTemplateType(filePath); if (type == TemplateType.Pdm) { mainManager.MainService.PdmService.Save(); } else { // Doc.SaveAs(filePath); Doc.Save(); } } tempInfo = Wkl.MainCtrl.CommonCtrl.GetTemplateInfo(Doc.FullName); if (tempInfo != null) { tempInfo.IsProntoDoc = true; // markup the document is pronto doc // set autosave option if (!isReconstruct && Wkl.MainCtrl.CommonCtrl.CommonProfile.App.Options.SaveInterval != ProntoMarkup.SaveInterval) { Wkl.MainCtrl.CommonCtrl.CommonProfile.App.Options.SaveInterval = ProntoMarkup.SaveInterval; } if (isToFinal) { UpdateStatus(MessageUtils.Expand(Properties.Resources.ipm_SaveSuccessful, filePath)); // update status } } } if (tempInfo != null) { tempInfo.IsSaving = false; // markup the document is saved } return(pdwInfo); } catch (BaseException baseExp) { ManagerException mgrExp = new ManagerException(ErrorCode.ipe_SaveDocumentError); mgrExp.Errors.Add(baseExp); throw mgrExp; } catch (Exception ex) { ManagerException mgrExp = new ManagerException(ErrorCode.ipe_SaveDocumentError, MessageUtils.Expand(Properties.Resources.ipe_SaveDocumentError, ex.Message), ex.StackTrace); throw mgrExp; } }
/// <summary> /// open document /// </summary> /// <param name="Doc"></param> public void OpenDocument(Document Doc) { //1.Check File structure //If true // 1.1 Update Status // 1.2 Create TemplateInfo object in WKL // 1.3 Validate with Domain string key; ServicesProfile servicePro = Wkl.MainCtrl.ServiceCtrl.CreateProfile(out key); servicePro.IntegrationService.CheckCorrectContent_IFilePath = Doc.FullName; mainManager.MainService.PropertyService.IsCorrectFileStructure(key); if ((bool)servicePro.IntegrationService.Result) { UpdateStatus(MessageUtils.Expand(Properties.Resources.ipm_CheckingMessage, Doc.FullName)); // Create TemplateInfo to WKL. Key is full name of doc TemplateInfo templateInfo = Wkl.MainCtrl.CommonCtrl.CreateTemplateInfo(Doc.FullName); templateInfo.IsProntoDoc = true; // check struct List <string> message = new List <string>(); bool isMatchWithDomain = true; bool isMatchWithDataSegment = true; bool isCorrectChecksum = true; // Validate Internal BM with any Domain servicePro.IntegrationService.TemplateFileName = Doc.FullName; mainManager.MainService.PropertyService.IsInternalBMMatchWithDomain(key); isMatchWithDomain = (bool)servicePro.IntegrationService.Result; string popupMessage = Properties.Resources.ipm_WrongMessages; // Validate Word structure IsCorrectWordStruct(key, Doc, ref message); // Compare Internal BM and Word BM. IsMatchBetweenInternalAndWord(ref message, false, Doc.FullName); // show reconstruct button if (message.Count > 0) { templateInfo.IsReconstruct = true; } else { templateInfo.IsReconstruct = false; } if (!isMatchWithDomain) { if (servicePro.IntegrationService.CheckMatchWithDomain_OListMatch != null && servicePro.IntegrationService.CheckMatchWithDomain_OListMatch.Count > 0) { //Show dialog to user select a domain. Hcl.ChooseDomain chooseDomain = new Hcl.ChooseDomain(servicePro.IntegrationService.CheckMatchWithDomain_OListMatch); chooseDomain.ShowDialog(); List <DomainMatch> domainMatches = chooseDomain.DomainMatches; chooseDomain.Dispose(); mainManager.RibbonManager.UpdateUI(EventType.ShowPanel); if (!domainMatches.Exists(d => !string.IsNullOrWhiteSpace(d.NewDomainName))) { if (templateInfo.RightPanel != null) { (templateInfo.RightPanel.Control as Hcl.ProntoDocMarkup).UpdateExceptionList(message, false, string.Empty); } } else { foreach (DomainMatch domainMatch in domainMatches) { if (string.IsNullOrWhiteSpace(domainMatch.NewDomainName)) { continue; } if (domainMatch.NewDomainName.Equals(domainMatch.DomainName)) { HighlightNotMatchFields(domainMatch); //Highlight unmatch Fields continue; } templateInfo.DomainNames.Add(domainMatch.NewDomainName); HighlightNotMatchFields(domainMatch); //Highlight unmatch Fields isMatchWithDataSegment = IsMatchWithDataSegment(Doc.FullName, ref message); if (templateInfo.RightPanel != null) { (templateInfo.RightPanel.Control as Hcl.ProntoDocMarkup).UpdateExceptionList(message, isMatchWithDataSegment, domainMatch.NewDomainName); } } if (templateInfo.IsReconstruct) { if (message.Count > 0) // has error when check construct { popupMessage += Properties.Resources.ipm_WrongBookmarkMessages; } if (!isMatchWithDomain || !isMatchWithDataSegment) { popupMessage += Properties.Resources.ipm_WrongDomainMessages; } mainManager.MainService.BookmarkService.ProtectDocument(); } else { mainManager.MainService.BookmarkService.UnProtectDocument(); Wkl.MainCtrl.CommonCtrl.CommonProfile.App.Options.SaveInterval = ProntoMarkup.SaveInterval; } } } else { HighlightAllBookmark(templateInfo.InternalBookmark); if (templateInfo.RightPanel != null) { (templateInfo.RightPanel.Control as Hcl.ProntoDocMarkup).UpdateExceptionList(message, false, string.Empty); } } } else { //HACK:FORM CONTROLS - Restore TemplateType templateType = MarkupUtilities.GetTemplateType(Doc.FullName); if (templateType == TemplateType.Pdm) { mainManager.MainService.PdmService.Restore(key); } mainManager.RibbonManager.UpdateUI(EventType.ShowPanel); } // decorate treeview if (templateInfo.RightPanel != null) { (templateInfo.RightPanel.Control as Hcl.ProntoDocMarkup).DecorateTreeView(); } // Validate CheckSum isCorrectChecksum = IsCorrectChecksum(); if (!isCorrectChecksum) { popupMessage += Properties.Resources.ipm_WrongChecksumMessage; } if (popupMessage != Properties.Resources.ipm_WrongMessages) { ShowPopupMessage(string.Format(popupMessage, "\n")); } UpdateStatus(MessageUtils.Expand(Properties.Resources.ipm_FinishLoading, Doc.FullName)); } Wkl.MainCtrl.ServiceCtrl.RemoveDataObject(key); }
public void IsCorrectFileStructure(string key) { try { IntegrationServiceProfile integrationPro = Wkl.MainCtrl.ServiceCtrl.GetProfile(key).IntegrationService; string filePath = integrationPro.CheckCorrectContent_IFilePath; bool hasOsql = true; bool hasXslt = true; bool hasChks = true; bool hasInternalBookmark = false; bool passPdmControlChecking = true; string srvKey = string.Empty; ServicesProfile srvPro = null; bool isPdm = MarkupUtilities.GetTemplateType(filePath) == TemplateType.Pdm; if (Path.GetExtension(filePath).ToLower() == FileExtension.ProntoDocumenentWord || isPdm) { hasOsql = false; hasXslt = false; hasChks = false; srvKey = string.Empty; srvPro = Wkl.MainCtrl.ServiceCtrl.CreateProfile(out srvKey); if (isPdm) { passPdmControlChecking = false; srvPro.TemplateType = TemplateType.Pdm; } GetPdwInformation(srvKey); Wkl.MainCtrl.ServiceCtrl.RemoveDataObject(srvKey); List <XmlObject> xmlObjects = srvPro.XmlObjects; foreach (XmlObject xmlObject in xmlObjects) { if (xmlObject == null) { continue; } switch (xmlObject.ContentType) { case ContentType.Osql: hasOsql = true; break; case ContentType.Xslt: hasXslt = true; break; case ContentType.Checksum: hasChks = true; break; case ContentType.FormControls: passPdmControlChecking = true; break; default: break; } } } srvKey = string.Empty; srvPro = Wkl.MainCtrl.ServiceCtrl.CreateProfile(out srvKey); GetInternalBookmark(srvKey); Wkl.MainCtrl.ServiceCtrl.RemoveDataObject(srvKey); hasInternalBookmark = srvPro.Ibm == null ? false : !srvPro.Ibm.IsNull(); if (hasOsql && hasXslt && hasChks && hasInternalBookmark && passPdmControlChecking) { integrationPro.Result = true; } else { integrationPro.Result = false; } } catch (BaseException srvExp) { Services.ServiceException newSrvExp = new Services.ServiceException(ErrorCode.ipe_ValidateStructError); newSrvExp.Errors.Add(srvExp); throw newSrvExp; } catch (Exception ex) { ServiceException srvExp = new ServiceException(ErrorCode.ipe_ValidateStructError, MessageUtils.Expand(Properties.Resources.ipe_ValidateStructError, ex.Message), ex.StackTrace); throw srvExp; } }