Esempio n. 1
0
        public bool SaveExportInfo(Workbook workbook)
        {
            //clear old export item information xml
            foreach (CustomXMLPart curXmlPart in workbook.CustomXMLParts)
            {
                if (curXmlPart.BuiltIn)
                {
                    continue;
                }
                XmlObject customObject = ObjectSerializeHelper.Deserialize <XmlObject>(curXmlPart.XML);
                if (customObject.ContentType == ContentType.PdeExportItem)
                {
                    curXmlPart.Delete();
                    break;
                }
            }
            //add new information
            CustomXMLPart xmlPart      = workbook.CustomXMLParts.Add();
            string        xmlContent   = ObjectSerializeHelper.SerializeToString <PdeExports>(new PdeExports(exportItems));
            XmlObject     excelContent = new XmlObject(xmlContent, ContentType.PdeExportItem);

            xmlPart.LoadXML(ObjectSerializeHelper.SerializeToString <XmlObject>(excelContent));

            return(true);
        }
Esempio n. 2
0
        public string GetInternalBookmarkString()
        {
            try
            {
                string          srvKey = string.Empty;
                ServicesProfile srvPro = Wkl.MainCtrl.ServiceCtrl.CreateProfile(out srvKey);
                GetInternalBookmark(srvKey);
                InternalBookmark internalBm = srvPro.Ibm;
                Wkl.MainCtrl.ServiceCtrl.RemoveDataObject(srvKey);

                return(ObjectSerializeHelper.SerializeToString <InternalBookmark>(internalBm));
            }
            catch (BaseException srvExp)
            {
                Services.ServiceException newSrvExp = new Services.ServiceException(ErrorCode.ipe_LoadInternalBookmarkError);
                newSrvExp.Errors.Add(srvExp);

                throw newSrvExp;
            }
            catch (Exception ex)
            {
                ServiceException srvExp = new ServiceException(ErrorCode.ipe_LoadInternalBookmarkError,
                                                               MessageUtils.Expand(Properties.Resources.ipe_LoadInternalBookmarkError, ex.Message), ex.StackTrace);

                throw srvExp;
            }
        }
Esempio n. 3
0
 public void TestXml(int i)
 {
     if (i == 1)
     {
         ObjTest t = new ObjTest();
         t.age      = 10;
         t.name     = "张三";
         t.birthday = DateTime.Now;
         t.sex      = false;
         string       xmlContent = ObjectSerializeHelper.SerializeToString <ObjTest>(t);
         FileStream   fout       = new FileStream("e:\\1.xml", FileMode.Create);
         StreamWriter sw         = new StreamWriter(fout);
         sw.Write(xmlContent);
         sw.Close();
         fout.Close();
     }
     else
     {
         StreamReader objReader  = new StreamReader("e:\\1.xml");
         string       sLine      = "";
         string       xmlcontent = "";
         while (sLine != null)
         {
             sLine = objReader.ReadLine();
             if (sLine != null && !sLine.Equals(""))
             {
                 xmlcontent += sLine;
             }
         }
         objReader.Close();
         MapNode mn = ObjectSerializeHelper.Deserialize <MapNode>(xmlcontent);
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Save internal bookmark object into document
        /// </summary>
        public void SaveInternalBookmark()
        {
            // 1. Get xml content
            // 2. Save custom xml part
            // 3. Save custom xml part id
            try
            {
                string content = string.Empty;
                string id      = string.Empty;

                if (CurrentTemplateInfo.InternalBookmark != null)
                {
                    content = ObjectSerializeHelper.SerializeToString <InternalBookmark>(CurrentTemplateInfo.InternalBookmark);
                }
                else
                {
                    content = ObjectSerializeHelper.SerializeToString <InternalBookmark>(new Pdw.Core.InternalBookmark());
                }

                XmlObject xmlObject = new XmlObject(content, ContentType.InternalBookmark);
                content = ObjectSerializeHelper.SerializeToString <XmlObject>(xmlObject);
                id      = GetCustomPartId();
                id      = AddCustomXmlPart(content, id);
                AddCustomProperty(Pdw.Core.ProntoMarkup.InternalBMCustomXmlPartId, id);
            }
            catch (Exception ex)
            {
                ManagerException mgrExp = new ManagerException(ErrorCode.ipe_SaveInternalBookmarkError,
                                                               MessageUtils.Expand(Properties.Resources.ipe_SaveInternalBookmarkError, ex.Message), ex.StackTrace);

                throw mgrExp;
            }
        }
Esempio n. 5
0
        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);
                    }
                }
            }
        }
Esempio n. 6
0
        public bool SaveMapInfo(Workbook workbook)
        {
            //clear old map information xml
            foreach (CustomXMLPart curXmlPart in workbook.CustomXMLParts)
            {
                if (curXmlPart.BuiltIn)
                {
                    continue;
                }
                XmlObject customObject = ObjectSerializeHelper.Deserialize <XmlObject>(curXmlPart.XML);
                if (customObject.ContentType == ContentType.PdeMapInfo)
                {
                    curXmlPart.Delete();
                    break;
                }
            }
            //add new map information
            CustomXMLPart xmlPart      = workbook.CustomXMLParts.Add();
            string        xmlContent   = ObjectSerializeHelper.SerializeToString <MapInfo>(mapInfo);
            XmlObject     excelContent = new XmlObject(xmlContent, ContentType.PdeMapInfo);

            xmlPart.LoadXML(ObjectSerializeHelper.SerializeToString <XmlObject>(excelContent));

            //Generate new xsd file and import it.
            GenXsd genXsd = new GenXsd();

            prepareData(genXsd);
            XmlMap xmap = genXsd.ImportXsd(workbook);

            //add xpath for each mapped cell and table
            foreach (MapNode mn in mapInfo.Maps)
            {
                if (mn.type == MapType.SingleCell)
                {
                    Range c = workbook.Application.get_Range(mn.target);
                    c.XPath.SetValue(xmap, mn.xPath);
                }
                else
                {
                    string[]   target    = mn.target.Split('!');
                    Worksheet  worksheet = workbook.Sheets[target[0]];
                    ListObject lst       = worksheet.ListObjects[target[1]];
                    foreach (TabCol tc in mn.columns)
                    {
                        lst.ListColumns[tc.columnName].XPath.SetValue(xmap, tc.xPath);
                    }
                }
            }

            return(true);
        }
Esempio n. 7
0
        private void GetRenderArguments(ChecksumInfo checksum, out string renderArgument, out string jRenderArgument)
        {
            System.Text.StringBuilder renderArgBuilder  = new System.Text.StringBuilder();
            System.Text.StringBuilder jrenderArgBuilder = new System.Text.StringBuilder();

            foreach (ChecksumInfoItem item in checksum.ChecksumInfoItems)
            {
                string sysArg = ObjectSerializeHelper.SerializeToString <ProntoDoc.Framework.CoreObject.SystemParameter>(item.SystemParameter);
                string temp   = ObjectSerializeHelper.SerializeToString <RenderArgDomainSchema>(item.RenderArgument);
                temp = sysArg + Environment.NewLine + Environment.NewLine + Environment.NewLine + temp;
                renderArgBuilder.AppendLine(temp);

                temp = ObjectSerializeHelper.SerializeToString <JRenderArgDomainSchema>(item.JRenderArgument);
                jrenderArgBuilder.AppendLine(temp);
            }

            renderArgument  = renderArgBuilder.ToString();
            jRenderArgument = jrenderArgBuilder.ToString();
        }
Esempio n. 8
0
        private void button9_Click(object sender, EventArgs e)
        {
            List <string> strs = new List <string>();

            strs.Add("SS_SQLServer");
            strs.Add("輝百新(紹興)有限公司 (TEST)_GMS");
            //int index = strs.FindIndex(s => s == "zh中文测试_gms(test)");
            //index = strs.FindIndex(s => s == "a");

            string result = ObjectSerializeHelper.SerializeToString <List <string> >(strs);

            Console.WriteLine(result);

            List <string> strs1 = new List <string>();

            strs1.Add("SS_SQLServer");
            strs1.Add("company1");
            string result1 = ObjectSerializeHelper.SerializeToString <List <string> >(strs1);
        }
Esempio n. 9
0
        private void button12_Click(object sender, EventArgs e)
        {
            word.Application app      = createWord();
            String           wordFile = textBox10.Text;
            string           xsltFile = textBox9.Text;

            word.Document doc = app.Documents.Open(wordFile);

            StreamReader sr  = new StreamReader(xsltFile);
            string       xsl = sr.ReadToEnd();

            //delete old xsl file
            foreach (CustomXMLPart xmlPart in doc.CustomXMLParts)
            {
                if (xmlPart.BuiltIn)
                {
                    continue;
                }
                XmlObject customObject = ObjectSerializeHelper.Deserialize <XmlObject>(xmlPart.XML);
                if (customObject.ContentType == ContentType.PdwrXsl)
                {
                    xmlPart.Delete();
                    break;
                }
            }

            //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));

            sr.Close();
            doc.Save();
            enablePdw(app);
            app.Quit();
        }
Esempio n. 10
0
        public string GenChecksum(string osqlString, List <ChecksumInfoItem> checksumItems, TemplateType templateType,
                                  string dscColor, bool hasDsc, string filePath)
        {
            // 1. prepare service
            MainService mainService = new MainService();

            Integrity.Validator validatorService = new Integrity.Validator();

            // 2. Plugin Id
            string pluginId = Wkl.MainCtrl.CommonCtrl.CommonProfile.PluginInfo.Id + " | " + Wkl.MainCtrl.CommonCtrl.CommonProfile.PluginInfo.Version;

            // 3. Plugin Name
            string pluginName = Wkl.MainCtrl.CommonCtrl.CommonProfile.PluginInfo.Name;

            // 4. User name
            string userName = validatorService.GetCurrentUserName();

            // 5. Checksum content
            string strInternalBm = mainService.PropertyService.GetInternalBookmarkString();
            string strChecksum   = validatorService.GenCheckSum(pluginId, pluginName, userName, strInternalBm, osqlString);

            // 6. make checksum object
            ChecksumInfo objChecksum = new ChecksumInfo(pluginId, pluginName, userName, strChecksum);

            // 7. add other information
            objChecksum.ChecksumInfoItems = checksumItems;

            // 8. template type
            objChecksum.TemplateType = templateType;

            // 9. add computer name
            objChecksum.ComputerName = validatorService.GetComputerName();

            objChecksum.DocumentSpecificColor = dscColor;
            objChecksum.HasDocumentSpecific   = hasDsc;
            objChecksum.FilePath = filePath;

            return(ObjectSerializeHelper.SerializeToString <ChecksumInfo>(objChecksum));
        }
Esempio n. 11
0
        private void button1_Click(object sender, EventArgs e)
        {
            Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
            app.Visible = true;
            Workbook      workbook = app.Workbooks.Open(textBox1.Text);
            CustomXMLPart xmlPart  = workbook.CustomXMLParts.Add();

            //读取xml文件
            XmlDocument data = new XmlDocument();

            data.Load(textBox8.Text);
            XmlObject excelContent = new XmlObject(data.OuterXml, ContentType.PderXml);

            xmlPart.LoadXML(ObjectSerializeHelper.SerializeToString <XmlObject>(excelContent));

            //string id = xmlPart.Id;
            //textBox1.Text = id;
            workbook.SaveAs(textBox1.Text + "r");
            workbook.Close();
            app.Quit();
            MessageBox.Show("pder ok.");
        }
Esempio n. 12
0
        public void SavePdwInfo(string key)
        {
            try
            {
                ManagerProfile mgrPro     = Wkl.MainCtrl.ManagerCtrl.GetProfile(key);
                XmlObject      osql       = new XmlObject(mgrPro.PdwInfo.OsqlString, ContentType.Osql);
                XmlObject      xslt       = new XmlObject(mgrPro.PdwInfo.XsltString, ContentType.Xslt);
                XmlObject      chks       = new XmlObject(mgrPro.PdwInfo.ChecksumString, ContentType.Checksum);
                XmlObject      pdeContent = new XmlObject(mgrPro.PdwInfo.PdeContent, ContentType.PdeContent);

                LogUtils.CreateFile("input.xsl", mgrPro.PdwInfo.XsltString);
                LogUtils.CreateFile("input.osql.xml", mgrPro.PdwInfo.OsqlString);

                string osqlId       = GetPropertyValue(PdwInfo.OsqlCustomXmlPartId);
                string xsltId       = GetPropertyValue(PdwInfo.XsltCustomXmlPartId);
                string chksId       = GetPropertyValue(PdwInfo.ChksCustomXmlPartId);
                string pdeContentId = GetPropertyValue(PdwInfo.PdeContentXmlPartId);

                osqlId       = AddCustomXmlPart(ObjectSerializeHelper.SerializeToString <XmlObject>(osql), osqlId);
                xsltId       = AddCustomXmlPart(ObjectSerializeHelper.SerializeToString <XmlObject>(xslt), xsltId);
                chksId       = AddCustomXmlPart(ObjectSerializeHelper.SerializeToString <XmlObject>(chks), chksId);
                pdeContentId = AddCustomXmlPart(ObjectSerializeHelper.SerializeToString <XmlObject>(pdeContent), pdeContentId);

                AddCustomProperty(PdwInfo.OsqlCustomXmlPartId, osqlId);
                AddCustomProperty(PdwInfo.XsltCustomXmlPartId, xsltId);
                AddCustomProperty(PdwInfo.ChksCustomXmlPartId, chksId);
                AddCustomProperty(PdwInfo.PdeContentXmlPartId, pdeContentId);
            }
            catch (Exception ex)
            {
                ManagerException mgrExp = new ManagerException(ErrorCode.ipe_SavePdwInfoError,
                                                               MessageUtils.Expand(Properties.Resources.ipe_SavePdwInfoError, ex.Message), ex.StackTrace);

                throw mgrExp;
            }
        }
Esempio n. 13
0
        /// <summary>
        /// new: gen pdw file with word xml document (save docx as xml file for gen xslt)
        /// </summary>
        /// <param name="fullDocName"></param>
        /// <param name="isFull"></param>
        /// <returns></returns>
        public void GetPdwInfo(string key)
        {
            ServicesProfile         srvPro            = Wkl.MainCtrl.ServiceCtrl.GetProfile(key);
            List <ChecksumInfoItem> checksumInfoItems = new List <ChecksumInfoItem>();

            srvPro.PdwInfo = new PdwInfo();
            TemplateInfo template = Wkl.MainCtrl.CommonCtrl.GetTemplateInfo(srvPro.FullDocName);

            if (srvPro.IsFullDoc)
            {
                #region gen osql
                GenOsqlHelper genOsqlHelper = new GenOsqlHelper();
                try
                {
                    srvPro.DomainInfos = new List <DomainInfo>();
                    int domainCount = template.DomainNames.Count;
                    int domainIndex = 0;
                    while (domainIndex < domainCount)
                    {
                        string domainName = template.DomainNames[domainIndex];
                        InternalBookmarkDomain ibmDomain = template.InternalBookmark.GetInternalBookmarkDomain(domainName);
                        if (ibmDomain != null && ibmDomain.InternalBookmarkItems != null &&
                            ibmDomain.InternalBookmarkItems.Count > 0)
                        {
                            srvPro.DomainInfos.Add(Wkl.MainCtrl.CommonCtrl.GetDomainInfo(domainName));
                            domainIndex++;
                        }
                        else
                        {
                            template.RemoveDomainAt(domainIndex);
                            domainCount--;
                        }
                    }
                    genOsqlHelper.GenOsql(srvPro.DomainInfos, template.InternalBookmark);
                    srvPro.PdwInfo.OsqlString = genOsqlHelper.OsqlString;
                    checksumInfoItems         = genOsqlHelper.ChecksumInfoItems;
                }
                catch (BaseException srvExp)
                {
                    Services.ServiceException newSrvExp = new Services.ServiceException(ErrorCode.ipe_GenOsqlError);
                    newSrvExp.Errors.Add(srvExp);
                    LogUtils.Log("GenOsql_ServiceException", srvExp);
                    throw newSrvExp;
                }
                catch (Exception ex)
                {
                    ServiceException srvExp = new ServiceException(
                        ErrorCode.ipe_GenOsqlError,
                        MessageUtils.Expand(Properties.Resources.ipe_GenOsqlError, ex.Message), ex.StackTrace);
                    LogUtils.Log("GenOsql_SystemException", ex);
                    throw srvExp;
                }
                #endregion

                #region gen xsl
                GenXsltHelper genXsltHelper = new GenXsltHelper();
                try
                {
                    srvPro.Ibm = genOsqlHelper.Ibm;
                    genXsltHelper.GenXsl2007(key);
                    srvPro.PdwInfo.XsltString = srvPro.XsltString;
                }
                catch (BaseException srvExp)
                {
                    Services.ServiceException newSrvExp = new Services.ServiceException(ErrorCode.ipe_GenXsltError);
                    newSrvExp.Errors.Add(srvExp);

                    throw newSrvExp;
                }
                catch (Exception ex)
                {
                    ServiceException srvExp = new ServiceException(
                        ErrorCode.ipe_GenXsltError,
                        MessageUtils.Expand(Properties.Resources.ipe_GenXsltError, ex.Message), ex.StackTrace);
                    throw srvExp;
                }
                #endregion

                // update RelationOn into InternalBookmark
                UpdateRelationOns(key);

                // pde content
                Integration.PdeService pdeService = new Integration.PdeService();
                pdeService.AddExportXSD(template.PdeContent);
                foreach (PdeContentItem item in template.PdeContent.Items)
                {
                    if (System.IO.File.Exists(item.FilePath))
                    {
                        try
                        {
                            string pdeFileContent = FileHelper.ExcelToBase64(item.FilePath);
                            item.FileContent = pdeFileContent;
                        }
                        catch { }
                    }
                }
                srvPro.PdwInfo.PdeContent = ObjectSerializeHelper.SerializeToString <PdeContent>(template.PdeContent);
            }

            // get checksum
            GetCheckSum(srvPro, checksumInfoItems, template.InternalBookmark.DocumentSpecificColor, template.InternalBookmark.HasDocumentSpecific);
        }
Esempio n. 14
0
        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.");
        }