コード例 #1
0
        private void CheckPdeLinkSource(Word.Document wDoc, PdeContent pdeContent)
        {
            if (wDoc == null)
            {
                return;
            }
            foreach (PdeContentItem item in pdeContent.Items)
            {
                bool isUse = IsUseInField(wDoc, item); // check Field

                if (!isUse)
                {
                    isUse = IsUseInInlineShape(wDoc, item); // check Chart
                }
                if (!isUse)                                 // check Tag
                {
                    if (item.ExportData != null && item.ExportData.Items != null)
                    {
                        foreach (DomainExportItem expDomain in item.ExportData.Items)
                        {
                            if (expDomain.Items != null && expDomain.Items.Exists(c => c.IsUsed))
                            {
                                isUse = true;
                                break;
                            }
                        }
                    }
                }

                item.Status = isUse ? Core.Constants.ContextManager.UsingStatus : Core.Constants.ContextManager.NotUsingStatus;
            }
        }
コード例 #2
0
        /// <summary>
        /// check the usage of pde content and update status
        /// </summary>
        /// <param name="pdeContent"></param>
        public void CheckPdeContent(Word.Document wDoc, PdeContent pdeContent)
        {
            if (pdeContent == null || pdeContent.Items == null || pdeContent.Items.Count == 0)
            {
                return;
            }

            CheckPdeLinkSource(wDoc, pdeContent);
        }
コード例 #3
0
ファイル: ImportPdeControl.cs プロジェクト: leonchen09/poc
        public ImportPdeControl(Word.Document wDoc, PdeContent pdeContent, bool isAdd)
        {
            InitializeComponent();

            _wDoc      = wDoc;
            PdeContent = pdeContent;
            BindPdeContent();

            btnAdd.Enabled    = isAdd;
            btnUpdate.Enabled = !isAdd;
            btnDelete.Enabled = !isAdd;
        }
コード例 #4
0
        public void AddExportXSD(PdeContent pdeContent)
        {
            if (pdeContent == null || pdeContent.Items == null)
            {
                return;
            }

            foreach (PdeContentItem item in pdeContent.Items)
            {
                AddExportXSD(item);
            }
        }
コード例 #5
0
ファイル: ThisAddIn.cs プロジェクト: leonchen09/poc
        private void unZipExcelFile(string tempFolder, Dictionary <string, string> oldFileNames, Dictionary <string, string> newFileNames)
        {
            string[] customeXmlFiles = Directory.GetFileSystemEntries(tempFolder + "\\customXml\\", "*.xml");
            Regex    custXmlRegex    = new Regex(@"item\d*.xml");//we need item*.xml only, do not need imemProps*.xml.

            foreach (string custXmlFile in customeXmlFiles)
            {
                if (custXmlRegex.IsMatch(custXmlFile))
                {
                    StreamReader sr      = new StreamReader(custXmlFile);
                    string       content = sr.ReadToEnd();
                    sr.Close();
                    sr = null;
                    XmlObject custXml = ObjectSerializeHelper.Deserialize <XmlObject>(content);
                    if (custXml.ContentType == ContentType.ImportedPde)
                    {
                        PdeContent pdeImported      = ObjectSerializeHelper.Deserialize <PdeContent>(custXml.Content);
                        string     importedFileName = pdeImported.FullFileName;
                        string     oldFileName      = null;
                        string     newFileName      = null;
                        //get new excel file name which has been updated into the document.
                        Dictionary <string, string> .Enumerator em = oldFileNames.GetEnumerator();
                        while (em.MoveNext())
                        {
                            oldFileName = null;
                            newFileName = null;
                            oldFileName = em.Current.Value;
                            if (pdeImported.FullFileName.Equals(oldFileName))
                            {
                                newFileNames.TryGetValue(em.Current.Key, out newFileName);
                                break;
                            }
                        }
                        FileHelper.ExcelFromBase64(pdeImported.FileContent, newFileName);

                        //replace file name with new name.
                        //content = content.Replace(oldFileName, newFileName);
                        //StreamWriter sw = new StreamWriter(custXmlFile);
                        //sw.Write(content);
                        //sw.Close();
                        //sw = null;
                        pdeImported.FullFileName = newFileName;
                        custXml.Content          = ObjectSerializeHelper.SerializeToString <PdeContent>(pdeImported);
                        content = ObjectSerializeHelper.SerializeToString <XmlObject>(custXml);
                        XmlDocument xmlDoc = new XmlDocument();
                        xmlDoc.LoadXml(content);
                        xmlDoc.Save(custXmlFile);
                    }
                }
            }
        }
コード例 #6
0
ファイル: IntegrationManager.cs プロジェクト: leonchen09/poc
        private PdeContent GetPdeContent()
        {
            string pdeContentId = GetPropertyValue(PdwInfo.PdeContentXmlPartId);

            if (pdeContentId == null)
            {
                return(null);
            }

            string     pdeContentData = GetCustomXmlPartContent(pdeContentId);
            XmlObject  xmlObject      = ObjectSerializeHelper.Deserialize <XmlObject>(pdeContentData);
            PdeContent pdeContent     = ObjectSerializeHelper.Deserialize <PdeContent>(xmlObject.Content);

            return(pdeContent);
        }
コード例 #7
0
        /// <summary>
        /// only acept save when the document has word bookmark (has data tag) and internal bookmark
        /// </summary>
        /// <returns></returns>
        private bool HasDataTag()
        {
            bool hasWbm = false;

            if (_doc != null && _doc.Bookmarks != null && _doc.Bookmarks.Count > 0)
            {
                hasWbm = true;
            }
            if (!hasWbm)
            {
                return(false);
            }

            // check pdw tags
            if (iBm != null && iBm.InternalBookmarkDomains != null)
            {
                foreach (InternalBookmarkDomain ibmDomain in iBm.InternalBookmarkDomains)
                {
                    if (ibmDomain.InternalBookmarkItems.Count > 0)
                    {
                        return(true);
                    }
                }
            }

            // check pde tags
            PdeContent pdeContent = PdeContent;

            if (pdeContent != null && pdeContent.Items != null)
            {
                foreach (PdeContentItem pdeContentItem in pdeContent.Items)
                {
                    if (pdeContentItem.ExportData != null && pdeContentItem.ExportData.Items != null)
                    {
                        foreach (DomainExportItem expDomain in pdeContentItem.ExportData.Items)
                        {
                            if (expDomain.Items != null && expDomain.Items.Exists(c => c.IsUsed))
                            {
                                return(true);
                            }
                        }
                    }
                }
            }

            return(false);
        }
コード例 #8
0
ファイル: ContextManager.cs プロジェクト: leonchen09/poc
        /// <summary>
        /// Oen pdwr file
        /// </summary>
        /// <param name="Doc"></param>
        public void OpenPdwr(Document Doc, ref List <string> tempFiles)
        {
            // get pdwr info
            string mgrKey = string.Empty;
            string srvKey = string.Empty;

            ServicesProfile srvPro = Wkl.MainCtrl.ServiceCtrl.CreateProfile(out srvKey);

            mainManager.MainService.PropertyService.GetPdwrInfos(srvKey);
            PdwrInfo pdwrInfo = srvPro.IntegrationService.PdwrInfo;

            // translate pdwr
            // if (!string.IsNullOrEmpty(pdwrInfo.XmlString) && !string.IsNullOrEmpty(pdwrInfo.XsltString))
            if (!string.IsNullOrEmpty(pdwrInfo.XmlString))
            {
                string folderPath = AssetManager.FileAdapter.TemporaryFolderPath;
                string fileName   = System.Guid.NewGuid().ToString();

                string xmlFilePath = string.Format("{0}\\{1}{2}", folderPath, fileName, FileExtension.Xml); // mwxml
                string xslFilePath = string.Format("{0}\\{1}{2}", folderPath, fileName, FileExtension.Xsl);

                FileHelper.CreateFile(xmlFilePath, pdwrInfo.XmlString);
                tempFiles.Add(xmlFilePath);
                if (!string.IsNullOrWhiteSpace(pdwrInfo.XsltString)) // support old file
                {
                    FileHelper.CreateFile(xslFilePath, pdwrInfo.XsltString);
                    tempFiles.Add(xslFilePath);
                }

                Document newDoc = null;
                if (!string.IsNullOrWhiteSpace(pdwrInfo.XsltString)) // support old file
                {
                    newDoc = Wkl.MainCtrl.CommonCtrl.CommonProfile.App.Documents.Open(
                        FileName: xmlFilePath,
                        Format: WdOpenFormat.wdOpenFormatXML,
                        XMLTransform: xslFilePath);
                }
                else
                {
                    newDoc = Wkl.MainCtrl.CommonCtrl.CommonProfile.App.Documents.Open(
                        FileName: xmlFilePath, Format: WdOpenFormat.wdOpenFormatXML);
                }
                Wkl.MainCtrl.CommonCtrl.CommonProfile.App.ScreenUpdating = true;
                newDoc.ActiveWindow.View.Type = WdViewType.wdPrintView;

                // update pde
                if (!string.IsNullOrWhiteSpace(pdwrInfo.PdeContent))
                {
                    PdeContent    pdeContent = ObjectSerializeHelper.Deserialize <PdeContent>(pdwrInfo.PdeContent);
                    List <string> excelFiles = mainManager.MainService.PropertyService.RenderPdeInPdw(newDoc, pdeContent);
                    tempFiles.AddRange(excelFiles);
                }
                newDoc.Save();

                #region process RenderSetting
                if (!string.IsNullOrEmpty(pdwrInfo.SettingString))
                {
                    RenderSettings renderSetting = ObjectSerializeHelper.Deserialize <RenderSettings>(pdwrInfo.SettingString);
                    if (renderSetting != null)
                    {
                        switch (renderSetting.Channel)
                        {
                            #region Media = Display
                        case RenderSettings.ChannelType.Display:
                            switch (renderSetting.Media)
                            {
                            case RenderSettings.MediaType.Pdf:
                                newDoc.ExportAsFixedFormat(Path.ChangeExtension(xmlFilePath, FileExtension.PdfNoDot),
                                                           WdExportFormat.wdExportFormatPDF, true);
                                ((_Document)newDoc).Close();
                                break;

                            case RenderSettings.MediaType.Xps:
                                newDoc.ExportAsFixedFormat(Path.ChangeExtension(xmlFilePath, FileExtension.XpsNoDot),
                                                           WdExportFormat.wdExportFormatXPS, true);
                                ((_Document)newDoc).Close();
                                break;

                            default:
                                break;
                            }
                            break;

                            #endregion
                            #region Media = Email, Media = Attachment
                        case RenderSettings.ChannelType.Email:
                        case RenderSettings.ChannelType.Attachment:
                            MailHelper.SendEmail(newDoc, renderSetting, ref tempFiles);
                            break;

                            #endregion
                            #region Media = Fax
                        case RenderSettings.ChannelType.Fax:
                            Wkl.MainCtrl.CommonCtrl.CommonProfile.App.CommandBars.ExecuteMso(
                                Constants.SendInternetFax);
                            break;

                            #endregion
                        default:
                            break;
                        }
                    }
                }

                #endregion
            }
        }
コード例 #9
0
ファイル: ContextManager.cs プロジェクト: leonchen09/poc
 public void CheckPdeContent(Document wDoc, PdeContent pdeContent)
 {
     mainManager.MainService.PropertyService.CheckPdeContent(wDoc, pdeContent);
 }
コード例 #10
0
        private System.Collections.Generic.Dictionary <string, string> RenderPdeContent(PdeContent pdeContent, string folder,
                                                                                        ref System.Collections.Generic.List <string> tempFiles)
        {
            System.Collections.Generic.Dictionary <string, string> dicLinks = new System.Collections.Generic.Dictionary <string, string>();
            foreach (PdeContentItem item in pdeContent.Items)
            {
                string key = item.FilePath.Trim().ToLower();
                if (dicLinks.ContainsKey(key))
                {
                    continue;
                }

                string newFile = string.Format("{0}_{1}.xlsx", item.STN, Guid.NewGuid());
                newFile = System.IO.Path.Combine(folder, newFile);

                ProntoDoc.Framework.Utils.FileHelper.ExcelFromBase64(item.FileContent, newFile);
                dicLinks.Add(key, newFile);
                tempFiles.Add(newFile);
            }

            return(dicLinks);
        }
コード例 #11
0
        public System.Collections.Generic.List <string> RenderPdeInPdw(Word.Document wDoc, PdeContent pdeContent)
        {
            // validate
            System.Collections.Generic.List <string> tempFiles = new System.Collections.Generic.List <string>();
            if (pdeContent == null || pdeContent.Items == null || pdeContent.Items.Count == 0)
            {
                return(tempFiles);
            }

            // extract and create excel files with new names
            string folder = System.IO.Path.GetDirectoryName(wDoc.FullName);

            System.Collections.Generic.Dictionary <string, string> dicLinks = RenderPdeContent(pdeContent, folder, ref tempFiles);

            // change link in Field with new name
            UpdateTableLink(wDoc, dicLinks);

            // change link in InlineShape(Chart) with new name
            UpdateChartLink(wDoc, dicLinks);

            // return list of temporaty files
            return(tempFiles);
        }
コード例 #12
0
ファイル: IntegrationService.cs プロジェクト: leonchen09/poc
 public List <string> RenderPdeInPdw(Document wDoc, PdeContent pdeContent)
 {
     return(PdeService.RenderPdeInPdw(wDoc, pdeContent));
 }
コード例 #13
0
ファイル: IntegrationService.cs プロジェクト: leonchen09/poc
 public void CheckPdeContent(Document wDoc, PdeContent pdeContent)
 {
     PdeService.CheckPdeContent(wDoc, pdeContent);
 }
コード例 #14
0
ファイル: Form1.cs プロジェクト: leonchen09/poc
        private void button8_Click(object sender, EventArgs e)
        {
            word.Application app = new word.Application();
            app.Visible = true;

            Thread.Sleep(2000);

            //disable the pdw plugin
            COMAddIn  pdwAddin = null;
            COMAddIns addins   = app.COMAddIns;

            foreach (COMAddIn addin in addins)
            {
                if (addin.Description.Equals("Pdw"))
                {
                    addin.Connect = false;
                    pdwAddin      = addin;
                    break;
                }
            }
            Thread.Sleep(1000);
            string tempFile = textBox_pdw.Text;
            string wordFile = tempFile.Split('.')[0] + ".docx";

            File.Copy(tempFile, wordFile, true);
            word.Document doc = app.Documents.Open(wordFile);
            //change properties of document
            //foreach (DocumentProperty docPro in doc.CustomDocumentProperties)
            //{
            //    if (docPro.Name.StartsWith("Pronto_ImportedExcelFileName"))
            //    {
            //        docPro.Value = textBox_pdwpder.Text;
            //    }
            //}
            //remove pde template and add pder file.
            PdeContent pdeImported = null;
            string     xsl         = null;

            foreach (CustomXMLPart xmlPart in doc.CustomXMLParts)
            {
                if (xmlPart.BuiltIn)
                {
                    continue;
                }
                XmlObject customObject = ObjectSerializeHelper.Deserialize <XmlObject>(xmlPart.XML);
                if (customObject.ContentType == ContentType.ImportedPde)
                {
                    pdeImported = ObjectSerializeHelper.Deserialize <PdeContent>(customObject.Content);
                }
                else if (customObject.ContentType == ContentType.Xslt)
                {
                    xsl = customObject.Content;
                }
                xmlPart.Delete();
            }
            //add pder file
            CustomXMLPart xmlPart_pder = doc.CustomXMLParts.Add();

            pdeImported.FileContent = FileHelper.ExcelToBase64(textBox_pdwpder.Text);
            //pdeImported.FullFileName = textBox_pdwpder.Text;
            XmlObject pderObj = new XmlObject();

            pderObj.ContentType = ContentType.ImportedPde;
            pderObj.Content     = ObjectSerializeHelper.SerializeToString <PdeContent>(pdeImported);
            xmlPart_pder.LoadXML(ObjectSerializeHelper.SerializeToString <XmlObject>(pderObj));
            //add xml data file
            XmlDocument dataXml = new XmlDocument();

            dataXml.Load(textBox_pdwd.Text);
            XmlObject     pdwrXml     = new XmlObject(dataXml.InnerXml, ContentType.PdwrXml);
            CustomXMLPart xmlPart_xml = doc.CustomXMLParts.Add();

            xmlPart_xml.LoadXML(ObjectSerializeHelper.SerializeToString <XmlObject>(pdwrXml));
            //add xsl file
            XmlObject xslObj = new XmlObject();

            xslObj.ContentType = ContentType.PdwrXsl;
            xslObj.Content     = xsl;
            CustomXMLPart xmlpart_xsl = doc.CustomXMLParts.Add();

            xmlpart_xsl.LoadXML(ObjectSerializeHelper.SerializeToString <XmlObject>(xslObj));
            //add pdwr setting
            XmlObject settObj = new XmlObject();

            settObj.ContentType = ContentType.PdwrSettings;
            settObj.Content     = "<?xml version=\"1.0\" encoding=\"utf-16\"?><RenderSettings xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><Media>Docx</Media><Channel>Display</Channel></RenderSettings>";
            CustomXMLPart xmlpart_sett = doc.CustomXMLParts.Add();

            xmlpart_sett.LoadXML(ObjectSerializeHelper.SerializeToString <XmlObject>(settObj));

            doc.Save();
            doc.Close();
            pdwAddin.Connect = true;
            app.Quit();
            File.Copy(wordFile, wordFile.Split('.')[0] + ".pdwr", true);
            MessageBox.Show("Create pdwr file success.");
        }