示例#1
0
        protected static string HighlightMatch(Widget widget, string text, string toMatch)
        {
            var           lane   = StringMatcher.GetMatcher(toMatch, false).GetMatch(text);
            StringBuilder result = new StringBuilder();

            if (lane != null)
            {
                int lastPos = 0;
                for (int n = 0; n < lane.Length; n++)
                {
                    int pos = lane[n];
                    if (pos - lastPos > 0)
                    {
                        MarkupUtilities.AppendEscapedString(result, text.Substring(lastPos, pos - lastPos));
                    }
                    result.Append("<span foreground=\"");
                    var color = Mono.TextEditor.HslColor.GenerateHighlightColors(widget.Style.Base(StateType.Normal),
                                                                                 widget.Style.Text(StateType.Normal), 3)[2];
                    result.Append(color.ToPangoString());
                    result.Append("\">");
                    MarkupUtilities.AppendEscapedString(result, text[pos].ToString());
                    result.Append("</span>");
                    lastPos = pos + 1;
                }
                if (lastPos < text.Length)
                {
                    MarkupUtilities.AppendEscapedString(result, text.Substring(lastPos, text.Length - lastPos));
                }
            }
            else
            {
                MarkupUtilities.AppendEscapedString(result, text);
            }
            return(result.ToString());
        }
示例#2
0
        /// <summary>
        /// Add select bookmark
        /// </summary>
        /// <param name="name">Name of bookmark</param>
        /// <param name="value">Value of bookmark</param>
        private void AddSingleBookmark(InternalBookmarkItem bm)
        {
            string          key;
            ServicesProfile servicePro = Wkl.MainCtrl.ServiceCtrl.CreateProfile(out key);

            //Add a space before text.
            servicePro.ContentService.AddToSelection_Text       = " ";
            servicePro.ContentService.AddToSelection_IsSelected = false;
            AddTextToCurrentSelection(key);

            // add select text
            servicePro.ContentService.AddToSelection_Text       = MarkupUtilities.GenTextXslTag(bm.BizName, bm.Type, true);
            servicePro.ContentService.AddToSelection_IsSelected = true;
            AddTextToCurrentSelection(key);

            // add select bookmark
            servicePro.ContentService.AddBookmark_Name = MarkupUtilities.GenKeyForXslTag(bm.Key, bm.Type, true);
            AddBookmarkInCurrentSelection(key);

            // set cursor after bookmark
            servicePro.ContentService.MoveChars_Count  = 1;
            servicePro.ContentService.MoveChars_IsLeft = false;
            MoveChars(key);

            Wkl.MainCtrl.ServiceCtrl.RemoveDataObject(key);
        }
示例#3
0
        protected static string HighlightMatch(string text, string toMatch, bool selected)
        {
            var           lane   = StringMatcher.GetMatcher(toMatch, true).GetMatch(text);
            StringBuilder result = new StringBuilder();

            if (lane != null)
            {
                int lastPos = 0;
                for (int n = 0; n < lane.Length; n++)
                {
                    int pos = lane[n];
                    if (pos - lastPos > 0)
                    {
                        MarkupUtilities.AppendEscapedString(result, text.Substring(lastPos, pos - lastPos));
                    }
                    var matchColor = selected ? Styles.GlobalSearch.SelectedResultMatchTextColor : Styles.GlobalSearch.ResultMatchTextColor;
                    result.Append("<span foreground=\"" + Styles.ColorGetHex(matchColor) + "\" font_weight=\"bold\">");
                    MarkupUtilities.AppendEscapedString(result, text[pos].ToString());
                    result.Append("</span>");
                    lastPos = pos + 1;
                }
                if (lastPos < text.Length)
                {
                    MarkupUtilities.AppendEscapedString(result, text.Substring(lastPos, text.Length - lastPos));
                }
            }
            else
            {
                MarkupUtilities.AppendEscapedString(result, text);
            }
            return(result.ToString());
        }
示例#4
0
        protected static string HighlightMatch(string text, string toMatch, bool selected)
        {
            var           lane          = StringMatcher.GetMatcher(toMatch, true).GetMatch(text);
            var           matchHexColor = selected ? selectedResultMatchTextColor : resultMatchTextColor;
            StringBuilder result        = new StringBuilder(text.Length + matchHexColor.Length + 46);

            if (lane != null)
            {
                int lastPos = 0;
                for (int n = 0; n < lane.Length; n++)
                {
                    int pos = lane[n];
                    if (pos - lastPos > 0)
                    {
                        MarkupUtilities.AppendEscapedString(result, text, lastPos, pos - lastPos);
                    }
                    result.Append("<span foreground=\"");
                    result.Append(matchHexColor);
                    result.Append("\" font_weight=\"bold\">");
                    MarkupUtilities.AppendEscapedString(result, text, pos, 1);
                    result.Append("</span>");
                    lastPos = pos + 1;
                }
                if (lastPos < text.Length)
                {
                    MarkupUtilities.AppendEscapedString(result, text, lastPos, text.Length - lastPos);
                }
            }
            else
            {
                MarkupUtilities.AppendEscapedString(result, text, 0, text.Length);
            }
            return(result.ToString());
        }
示例#5
0
        private void HighlightNotMatchFields(DomainMatch domainMatch)
        {
            try
            {
                foreach (DomainMatchItem matchItem in domainMatch.DomainMatchItems.Values)
                {
                    foreach (string wBmValue in matchItem.NotMatchBizs)
                    {
                        foreach (Bookmark wBm in Wkl.MainCtrl.CommonCtrl.CommonProfile.ActiveDoc.Bookmarks)
                        {
                            if (MarkupUtilities.GetRangeText(wBm.Range) == wBmValue)
                            {
                                wBm.Range.HighlightColorIndex = ProntoMarkup.BackgroundHighLight;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ManagerException mgrExp = new ManagerException(ErrorCode.ipe_HighlightBookmarkError,
                                                               MessageUtils.Expand(Properties.Resources.ipe_HighlightBookmarkError, ex.Message), ex.StackTrace);

                throw mgrExp;
            }
        }
示例#6
0
        protected static string HighlightMatch(Widget widget, string text, string toMatch)
        {
            var           lane   = StringMatcher.GetMatcher(toMatch, true).GetMatch(text);
            StringBuilder result = new StringBuilder();

            if (lane != null)
            {
                int lastPos = 0;
                for (int n = 0; n < lane.Length; n++)
                {
                    int pos = lane[n];
                    if (pos - lastPos > 0)
                    {
                        MarkupUtilities.AppendEscapedString(result, text.Substring(lastPos, pos - lastPos));
                    }
                    result.Append("<span foreground=\"#4d4d4d\" font_weight=\"bold\">");
                    MarkupUtilities.AppendEscapedString(result, text[pos].ToString());
                    result.Append("</span>");
                    lastPos = pos + 1;
                }
                if (lastPos < text.Length)
                {
                    MarkupUtilities.AppendEscapedString(result, text.Substring(lastPos, text.Length - lastPos));
                }
            }
            else
            {
                MarkupUtilities.AppendEscapedString(result, text);
            }
            return(result.ToString());
        }
示例#7
0
        /// <summary>
        /// Remove all word bookmark that not exist on internal bookmark collection
        /// </summary>
        /// <param name="iBms"></param>
        public void ValidateBookmarkCollection(string key)
        {
            // 1. Get all word bookmark
            // 2. If bookmark in word not exist in internal bookmark
            // 2.1. markup this to return
            // 2.2. if isUpdate = true, we delete its
            try
            {
                ContentServiceProfile contentProfile = Wkl.MainCtrl.ServiceCtrl.GetProfile(key).ContentService;
                InternalBookmark      iBms           = Wkl.MainCtrl.CommonCtrl.GetTemplateInfo(
                    contentProfile.ValidateBookmark_ITemplateName).InternalBookmark;

                GetBookmarkCollection(key);

                List <string> deletedList        = new List <string>();
                Dictionary <string, string> wBms = contentProfile.GetBookmarks_OListBM;

                foreach (string bmKey in wBms.Keys)
                {
                    InternalBookmarkItem item = iBms.GetInternalBookmarkItem(bmKey);

                    if (item == null || item.BizName != wBms[bmKey]) // compare key and value
                    {
                        if (MarkupUtilities.IsProntoDocCommentBookmark(bmKey) ||
                            MarkupUtilities.IsPdeTagBookmark(bmKey))
                        {
                            continue;
                        }

                        deletedList.Add(wBms[bmKey]);
                        contentProfile.HighlightBookmarkName = bmKey;
                        HighlightBookmark(key);

                        if (contentProfile.ValidateBookmark_IIsUpdate)
                        {
                            contentProfile.DeletedBookmarkName = bmKey;
                            contentProfile.DeleteWholeBookmark = false;
                            DeleteBookmark(key);
                        }
                    }
                }

                contentProfile.ValidateBookmark_ORemovedList = deletedList;
            }
            catch (BaseException srvExp)
            {
                Services.ServiceException newSrvExp = new Services.ServiceException(ErrorCode.ipe_ValidateWordBookmarkError);
                newSrvExp.Errors.Add(srvExp);

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

                throw srvExp;
            }
        }
示例#8
0
        /// <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);
            }
        }
示例#9
0
        private string ImportPdeTag(Word.Document wDoc, string key, string value)
        {
            if (wDoc == null || string.IsNullOrWhiteSpace(key) || string.IsNullOrWhiteSpace(value))
            {
                return(string.Empty);
            }

            // add a space before text.
            wDoc.Application.Selection.TypeText(" ");

            // add select text
            string bmValue = MarkupUtilities.GenTextXslTag(value, XsltType.Select, true);

            wDoc.Application.Selection.TypeText(bmValue);
            wDoc.Application.Selection.MoveLeft(Word.WdUnits.wdCharacter, bmValue.Length, Word.WdMovementType.wdExtend);

            // add select bookmark
            string bmName = Core.MarkupConstant.MarkupPdeTag + key;

            Word.Bookmark oldBm = null;
            foreach (Word.Bookmark bookmark in wDoc.Bookmarks)
            {
                if (string.Equals(bmName, bookmark.Name, StringComparison.OrdinalIgnoreCase))
                {
                    oldBm = bookmark;
                    break;
                }
            }
            if (oldBm != null)
            {
                oldBm.Delete();
            }
            Word.Range range = wDoc.Application.Selection.Range;
            wDoc.Bookmarks.Add(bmName, range);
            wDoc.Bookmarks.DefaultSorting = Word.WdBookmarkSortBy.wdSortByLocation;
            wDoc.Bookmarks.ShowHidden     = false;

            // set cursor after bookmark
            wDoc.Application.Selection.MoveRight(Word.WdUnits.wdCharacter, 1);

            // markup ProntoDoc;
            WKL.DataController.MainController.MainCtrl.CommonCtrl.CommonProfile.CurrentTemplateInfo.IsProntoDoc = true;
            if (!System.IO.File.Exists(wDoc.FullName))
            {
                wDoc.Application.Options.SaveInterval = 0;
            }

            return(bmName);
        }
示例#10
0
        /// <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);
        }
示例#11
0
        private string GetPdeDataType(string key, InternalBookmark ibm)
        {
            if (ibm == null || string.IsNullOrWhiteSpace(key))
            {
                return(string.Empty);
            }

            InternalBookmarkItem ibmItem = ibm.GetInternalBookmarkItem(key);

            if (ibmItem == null)
            {
                return(string.Empty);
            }

            return(MarkupUtilities.SqlDbType2XsdDataType(ibmItem.DataType));
        }
示例#12
0
        /// <summary>
        /// Check this section has bookmark or no
        /// </summary>
        /// <param name="Sel">Section</param>
        /// <returns></returns>
        public string HasBookmark(Selection Sel)
        {
            string bmName = string.Empty;

            if (Sel != null)
            {
                if (Sel.Bookmarks != null)
                {
                    int count = Sel.Bookmarks.Count;
                    if (count > 0)
                    {
                        string selText = Sel.Range.Text;
                        foreach (Bookmark bm in Sel.Bookmarks)
                        {
                            string bmValue = bm.Range.Text;

                            if (string.IsNullOrEmpty(selText))
                            {
                                if (!MarkupUtilities.IsProntoDocCommentBookmark(bm.Name))
                                {
                                    bm.Range.Select();
                                    bmName = count == 1 ? bm.Name : string.Empty;
                                }
                                continue;
                            }

                            if (!selText.Contains(bmValue) && !MarkupUtilities.IsProntoDocCommentBookmark(bm.Name))
                            {
                                if (bm.End > Sel.End) // bookmark is end of selection
                                {
                                    Sel.End = bm.End;
                                }

                                if (Sel.Start > bm.Start) // bookmark is start of selection
                                {
                                    Sel.Start = bm.Start;
                                }
                                bmName = count == 1 ? bm.Name : string.Empty;
                            }
                        }
                    }
                }
            }

            return(bmName);
        }
示例#13
0
        /// <summary>
        /// get all internal bookmark item (include USC) from document
        /// </summary>
        /// <param name="ibmDomain"></param>
        /// <returns></returns>
        private List <InternalBookmarkItem> GetInternalBookmarkItemCollection(InternalBookmarkDomain ibmDomain)
        {
            List <InternalBookmarkItem> items = new List <InternalBookmarkItem>();

            // internal bookmark item
            foreach (InternalBookmarkItem item in ibmDomain.InternalBookmarkItems)
            {
                InternalBookmarkItem newItem = null;
                if (item.Key.EndsWith(ProntoMarkup.KeySelect))
                {
                    newItem = new InternalBookmarkItem(MarkupUtilities.RemoveChars(item.BizName, 1, 2), item.UniqueName, item.DataType, XsltType.Select);
                }
                else if (item.Key.EndsWith(ProntoMarkup.KeyStartIf) && item.ItemType == DSIconType.Condition.ToString())
                {
                    newItem = new InternalBookmarkItem(MarkupUtilities.RemoveChars(item.BizName, 1, 1), item.UniqueName, item.DataType, XsltType.If);
                }

                if (newItem != null)
                {
                    if (string.IsNullOrEmpty(newItem.UniqueName)) // ngocbv: make sure unique name not is null in case UDF
                    {
                        newItem.UniqueName = item.TechName;
                    }
                    newItem.Key      = newItem.BizName; // ngocbv: keep key for highlight
                    newItem.TechName = item.TechName;
                    items.Add(newItem);
                }
            }

            // usc
            foreach (USCItem usc in ibmDomain.USCItems)
            {
                foreach (USCItem item in usc.Fields)
                {
                    InternalBookmarkItem newItem = new InternalBookmarkItem(item.BusinessName, item.UniqueName, item.DataType, XsltType.If);
                    newItem.Key = usc.BusinessName; // ngocbv: keep key for highlight
                    items.Add(newItem);
                }
            }

            return(items);
        }
示例#14
0
        /// <summary>
        /// validate word bookmark (if exist in word but not exit in internal => highlight and markup to return)
        /// </summary>
        /// <param name="iBms"></param>
        /// <returns></returns>
        private List <string> ValidateWordBookmark(WdColorIndex color)
        {
            List <string> deletedList = new List <string>();

            foreach (Bookmark wBm in _doc.Bookmarks)
            {
                InternalBookmarkItem item = iBm.GetInternalBookmarkItem(wBm.Name);

                // 1. check null (can not find ibm)
                if (item == null)
                {
                    // todo: ngocbv_rem => confirm to remove export item
                    //if (!MarkupUtilities.IsProntoDocCommentBookmark(wBm.Name))
                    //{
                    //    deletedList.Add(wBm.Name);
                    //    HighLightBookmark(wBm.Name, color);
                    //}
                    continue;
                }

                // 2. get real biz name
                string bizName = item.IsImage() ? MarkupUtilities.GetBizNameOfBookmarkImage(wBm.Name, _doc.InlineShapes) : wBm.Range.Text;

                if (item.BizName != bizName) // compare key and value
                {
                    deletedList.Add(wBm.Name);
                    HighLightBookmark(wBm.Name, color);
                }
                else if (item != null && item.Type == XsltType.Select) // check match with domain (only check for field)
                {
                    DomainInfo domainInfo = Wkl.MainCtrl.CommonCtrl.GetDomainInfo(item.DomainName);

                    if (domainInfo != null && !domainInfo.Fields.ContainsKey(MarkupUtilities.GetOriginalBizName(wBm.Name, item.BizName)))
                    {
                        deletedList.Add(wBm.Name);
                        HighLightBookmark(wBm.Name, color);
                    }
                }
            }

            return(deletedList);
        }
示例#15
0
        private string ImportPdeChart(Word.Document wDoc, string chartName, string chartContent)
        {
            string chartPath = AssetManager.FileAdapter.GenRandomFilePath(ChartExtension);
            string bmValue   = MarkupUtilities.GenTextXslTag(chartName, XsltType.Select, true);
            string bmName    = BaseMarkupUtilities.XmlEncode(chartName);

            // create temporary image
            bmName = string.Format("{0}{1}{2}", MarkupConstant.MarkupPdeTag, bmName, MarkupConstant.MarkupPdeChart);
            ProntoDoc.Framework.Utils.FileHelper.FileFromBase64(chartContent, chartPath);

            // delete old bm
            Word.Bookmark oldBm = null;
            foreach (Word.Bookmark bookmark in wDoc.Bookmarks)
            {
                if (string.Equals(bmName, bookmark.Name, StringComparison.OrdinalIgnoreCase))
                {
                    oldBm = bookmark;
                    break;
                }
            }
            if (oldBm != null)
            {
                oldBm.Delete();
            }

            // add image into word
            wDoc.Application.Selection.TypeText(" ");
            Word.InlineShape inlineShape = wDoc.Application.Selection.InlineShapes.AddPicture(chartPath, false, true);
            inlineShape.AlternativeText = MarkupUtilities.CreateAlternativeText(bmName, bmValue);

            // add bookmark
            wDoc.Application.Selection.MoveLeft(Word.WdUnits.wdCharacter, 1);
            wDoc.Application.Selection.MoveRight(Word.WdUnits.wdCharacter, 1, Word.WdMovementType.wdExtend);
            wDoc.Bookmarks.Add(bmName, wDoc.Application.Selection.Range);
            wDoc.Application.Selection.MoveRight(Word.WdUnits.wdCharacter);

            // delete temporary file
            System.IO.File.Delete(chartPath);

            return(bmName);
        }
示例#16
0
        /// <summary>
        /// Get bookmark collection in word
        /// </summary>
        /// <returns>Dictionary with key is bookmark name and value is bookmark text</returns>
        public void GetBookmarkCollection(string key)
        {
            try
            {
                ContentServiceProfile contentProfile = Wkl.MainCtrl.ServiceCtrl.GetProfile(key).ContentService;

                Dictionary <string, string> bookmarks = new Dictionary <string, string>();

                Bookmarks bms = Wkl.MainCtrl.CommonCtrl.CommonProfile.Bookmarks;

                foreach (Bookmark bookmark in bms)
                {
                    if (bookmark.Name.Contains(ProntoMarkup.KeyImage))
                    {
                        bookmarks.Add(bookmark.Name, MarkupUtilities.GetBizNameOfBookmarkImage(bookmark.Name,
                                                                                               Wkl.MainCtrl.CommonCtrl.CommonProfile.ActiveDoc.InlineShapes));
                    }
                    else
                    {
                        bookmarks.Add(bookmark.Name, MarkupUtilities.GetRangeText(bookmark.Range));
                    }
                }

                contentProfile.GetBookmarks_OListBM = bookmarks;
            }
            catch (BaseException srvExp)
            {
                Services.ServiceException newSrvExp = new Services.ServiceException(ErrorCode.ipe_GetWordBookmarksError);
                newSrvExp.Errors.Add(srvExp);

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

                throw srvExp;
            }
        }
示例#17
0
        /// <summary>
        /// Add foreach bookmark
        /// </summary>
        /// <param name="name">Name of bookmark</param>
        /// <param name="value">Value of bookmark</param>
        private void AddDoubleBookmark(InternalBookmarkItem bm)
        {
            //1. Get FontColor of BM
            //2. Generate tag
            //3. Add start tag (text) to document
            //4. Add start tag to BM
            //5. Move cursor to after
            //6. Add end tag (text) to document
            //7. Add end tag to BM
            //8. Move cursor to between two tags
            //9. Set color

            string          key;
            ServicesProfile servicePro = Wkl.MainCtrl.ServiceCtrl.CreateProfile(out key);

            WdColor fontColor  = GetFontColor(bm.Type);
            WdColor textColor  = WdColor.wdColorBlack;
            int     textLength = 0;

            if (Globals.ThisAddIn.Application.Selection.Range.Start != Globals.ThisAddIn.Application.Selection.Range.End)
            {
                textLength = Globals.ThisAddIn.Application.Selection.Range.Text.Length;
                textColor  = Globals.ThisAddIn.Application.Selection.Range.Font.Color;
                servicePro.ContentService.MoveChars_Count  = 1;
                servicePro.ContentService.MoveChars_IsLeft = true;
                MoveChars(key);
            }

            //2.Generate tag
            string startTag = MarkupUtilities.GenTextXslTag(bm.BizName, bm.Type, true);

            //Add a space before text
            servicePro.ContentService.AddToSelection_Text       = " ";
            servicePro.ContentService.AddToSelection_IsSelected = false;
            AddTextToCurrentSelection(key);

            //3. add start foreach text
            servicePro.ContentService.AddToSelection_Text       = startTag.Trim();
            servicePro.ContentService.AddToSelection_IsSelected = true;
            AddTextToCurrentSelection(key);

            //4. add start foreach bookmark
            servicePro.ContentService.AddBookmark_Name = MarkupUtilities.GenKeyForXslTag(bm.Key, bm.Type, true);
            AddBookmarkInCurrentSelection(key);
            servicePro.ContentService.AddBookmark_BookmarkReturn.Range.Font.Color = fontColor;
            //if (bm.Type == XsltType.If) // todo: ngocbv add highlight color for condition tag
            //    servicePro.ContentService.AddBookmark_BookmarkReturn.Range.HighlightColorIndex = ProntoMarkup.IfColorBackground;

            //5. add space
            servicePro.ContentService.MoveChars_Count  = (textLength > 0 ? textLength + 1 : 1);
            servicePro.ContentService.MoveChars_IsLeft = false;
            MoveChars(key);

            servicePro.ContentService.AddToSelection_Text       = " ";
            servicePro.ContentService.AddToSelection_IsSelected = false;
            AddTextToCurrentSelection(key);

            Globals.ThisAddIn.Application.Selection.Font.Color = textColor;

            //6. add end foreach text
            servicePro.ContentService.AddToSelection_Text       = MarkupUtilities.GenTextXslTag(bm.BizName, bm.Type, false);
            servicePro.ContentService.AddToSelection_IsSelected = true;
            AddTextToCurrentSelection(key);

            //7. add end foreach bookmarl
            servicePro.ContentService.AddBookmark_Name = MarkupUtilities.GenKeyForXslTag(bm.Key, bm.Type, false);
            AddBookmarkInCurrentSelection(key);
            servicePro.ContentService.AddBookmark_BookmarkReturn.Range.Font.Color = fontColor;
            //if (bm.Type == XsltType.If) // todo: ngocbv add highlight color for condition tag
            //    servicePro.ContentService.AddBookmark_BookmarkReturn.Range.HighlightColorIndex = ProntoMarkup.IfColorBackground;

            //8.set cursor before end tag
            servicePro.ContentService.MoveChars_Count  = 2;
            servicePro.ContentService.MoveChars_IsLeft = true;

            MoveChars(key);

            //9. reset color
            Globals.ThisAddIn.Application.Selection.Font.Color = textColor;

            Wkl.MainCtrl.ServiceCtrl.RemoveDataObject(key);
        }
示例#18
0
        //public bool DeleteAllBookmark(string value)
        //{
        //    try
        //    {
        //        foreach (Bookmark bookmark in Wkl.MainCtrl.CommonCtrl.CommonProfile.Bookmarks)
        //            if (MarkupUtilities.GetRangeText(bookmark.Range).Equals(value))
        //                DeleteBookmark(bookmark);
        //        return true;
        //    }
        //    catch (System.Exception ex)
        //    {
        //        ManagerException mgrExp = new ManagerException(ErrorCode.ipe_DeleteBookmarkError,
        //            MessageUtils.Expand(Properties.Resources.ipe_DeleteBookmarkError, ex.Message), ex.StackTrace);

        //        throw mgrExp;
        //    }
        //}

        private void DeleteBookmark(Bookmark bookmark, bool isDeleteWhole)
        {
            if (bookmark != null)
            {
                // 1. remove order by if bookmark is data tag
                string name = bookmark.Name;
                string text = MarkupUtilities.GetRangeText(bookmark.Range);
                if (name.EndsWith(ProntoMarkup.KeySelect))
                {
                    System.Collections.Generic.List <Bookmark>  bms        = GetBookmarksOrderByPosition();
                    System.Collections.Generic.Stack <Bookmark> foreachBms = new System.Collections.Generic.Stack <Bookmark>();
                    bool isExist = false;
                    foreach (Bookmark bm in bms)
                    {
                        if (bm.Name.EndsWith(ProntoMarkup.KeyStartForeach))
                        {
                            foreachBms.Push(bm);
                        }
                        if (bm.Name.EndsWith(ProntoMarkup.KeyEndForeach))
                        {
                            foreachBms.Pop();
                        }
                        if (bm.Name == name)
                        {
                            isExist = true;
                            break;
                        }
                    }
                    if (isExist && foreachBms.Count > 0)
                    {
                        Bookmark foreachBm = foreachBms.Pop();
                        string   oldText   = MarkupUtilities.GetRangeText(foreachBm.Range);
                        string   newText   = oldText.Replace(text +
                                                             Constants.OrderBy.Concat +
                                                             Constants.OrderBy.AscMark +
                                                             Constants.OrderBy.Delimiter, "");
                        newText = newText.Replace(text +
                                                  Constants.OrderBy.Concat +
                                                  Constants.OrderBy.DescMark +
                                                  Constants.OrderBy.Delimiter, "");
                        newText = newText.Replace(Constants.OrderBy.Delimiter + text +
                                                  Constants.OrderBy.Concat +
                                                  Constants.OrderBy.AscMark, "");
                        newText = newText.Replace(Constants.OrderBy.Delimiter + text +
                                                  Constants.OrderBy.Concat +
                                                  Constants.OrderBy.DescMark, "");
                        if (oldText != newText)
                        {
                            UpdateBookmarkText(foreachBm, newText);
                        }
                    }
                }

                // 2. remove bookmark
                if (isDeleteWhole)
                {
                    bookmark.Range.Text = "";
                }
                else
                {
                    bookmark.Delete();
                }
            }
        }
示例#19
0
        /// <summary>
        /// Highlight all word bookmark that not exist on data domain
        /// </summary>
        /// <param name="iBms"></param>
        public void ValidateBookmarkCollectionWithDomain(string key)
        {
            try
            {
                bool          isHighlight = false;
                List <string> unMatched   = new List <string>();

                //Get Bookmark Collection then put to WKL
                GetBookmarkCollection(key);

                ContentServiceProfile       contentProfile = Wkl.MainCtrl.ServiceCtrl.GetProfile(key).ContentService;
                Dictionary <string, string> wBm            = contentProfile.GetBookmarks_OListBM;

                //Get Internal Bookmark
                TemplateInfo templateInfo = Wkl.MainCtrl.CommonCtrl.GetTemplateInfo(
                    contentProfile.ValidateBookmark_ITemplateName);
                InternalBookmark interBm = templateInfo.InternalBookmark;

                //Get Domain Data
                foreach (string domainName in templateInfo.DomainNames)
                {
                    DomainInfo domainInfo = Wkl.MainCtrl.CommonCtrl.GetDomainInfo(domainName);
                    if (domainInfo != null)
                    {
                        InternalBookmarkDomain ibmDomain = interBm.GetInternalBookmarkDomain(domainName);
                        foreach (InternalBookmarkItem item in ibmDomain.InternalBookmarkItems)
                        {
                            if (!MarkupUtilities.IsExistOnDomain(item, domainInfo.Fields, true))
                            {
                                if (wBm.ContainsKey(item.Key) && wBm[item.Key] == item.BizName)
                                {
                                    contentProfile.HighlightBookmarkName = item.Key;
                                    unMatched.Add(item.BizName);
                                    HighlightBookmark(key);
                                    isHighlight = true;
                                }
                            }
                        }
                    }
                    else
                    {
                        isHighlight = true;
                    }
                }

                contentProfile.UnMatchedFields = unMatched;
                contentProfile.Result          = !isHighlight;
            }
            catch (BaseException srvExp)
            {
                Services.ServiceException newSrvExp = new Services.ServiceException(ErrorCode.ipe_ValidateWordBookmarkWithDomainError);
                newSrvExp.Errors.Add(srvExp);

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

                throw srvExp;
            }
        }
示例#20
0
        /// <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;
            }
        }
示例#21
0
        /// <summary>
        /// Add a bookmark into current document
        /// </summary>
        /// <param name="name">Name of bookmark</param>
        /// <param name="value">Value of bookmark</param>
        /// <param name="xsltType">XsltType (Select, Foreach or If)</param>
        /// <returns></returns>
        public bool AddBookmark(string key)
        {
            try
            {
                ServicesProfile      serviceProfile = Wkl.MainCtrl.ServiceCtrl.GetProfile(key);
                InternalBookmarkItem bm             = serviceProfile.ContentService.AddBookmark_IBookmark;
                Wkl.MainCtrl.CommonCtrl.CommonProfile.CurrentTemplateInfo.IsAdding = true;

                serviceProfile.ContentService.MarkProntDoc = true;
                switch (bm.Type)
                {
                case XsltType.Foreach:
                    AddDoubleBookmark(bm);
                    MarkProntoDoc(key);
                    break;

                case XsltType.If:
                    AddDoubleBookmark(bm);
                    MarkProntoDoc(key);
                    break;

                case XsltType.Select:
                    if (bm.IsImage())
                    {
                        serviceProfile.WbmKey          = bm.Key + ProntoMarkup.KeyImage;
                        serviceProfile.WbmValue        = MarkupUtilities.GenTextXslTag(bm.BizName, bm.Type, true);
                        serviceProfile.AlternativeText = MarkupUtilities.CreateAlternativeText(serviceProfile.WbmKey,
                                                                                               serviceProfile.WbmValue);
                        AddBookmarkImageEvent(key);
                    }
                    else
                    {
                        AddSingleBookmark(bm);
                    }
                    MarkProntoDoc(key);
                    break;

                case XsltType.Comment:
                    AddCommentBookmark(bm);
                    break;

                default:
                    break;
                }

                Wkl.MainCtrl.CommonCtrl.CommonProfile.CurrentTemplateInfo.IsAdding = false;
                return(true);
            }
            catch (BaseException srvExp)
            {
                Services.ServiceException newSrvExp = new Services.ServiceException(ErrorCode.ipe_AddBookmarkError);
                newSrvExp.Errors.Add(srvExp);

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

                throw srvExp;
            }
        }
示例#22
0
        /// <summary>
        /// Get bookmark collection in word
        /// </summary>
        /// <returns>Dictionary with key is bookmark name and value is bookmark text</returns>
        public void GetDistinctBookmarks(string key)
        {
            //1.Get All Bookmarks
            //2.Do not add EndIf, EndForEach bookmark
            //3.If a bookmark is existed in List, increase number entry
            //4.Else insert to list.
            try
            {
                ContentServiceProfile contentProfile = Wkl.MainCtrl.ServiceCtrl.GetProfile(key).ContentService;
                List <BookmarkItem>   listBookmarks  = new List <BookmarkItem>();
                Bookmarks             bms            = Wkl.MainCtrl.CommonCtrl.CommonProfile.Bookmarks;

                for (int j = 1; j <= bms.Count; j++)
                {
                    Bookmark bookmark = bms[j];

                    //2.Do not add EndIf, EndForEach bookmark
                    if (!MarkupUtilities.GetRangeText(bookmark.Range).Contains(Constants.BookMarkControl.EndIfTag))
                    {
                        BookmarkItem item = new BookmarkItem(bookmark.Name, string.Empty, string.Empty, bookmark);
                        if (bookmark.Name.Contains("Image"))
                        {
                            GetInternalBookmark(key);
                            InternalBookmark internalBM = Wkl.MainCtrl.ServiceCtrl.GetProfile(key).Ibm;
                            foreach (InternalBookmarkDomain ibmDomain in internalBM.InternalBookmarkDomains)
                            {
                                foreach (InternalBookmarkItem internalItem in ibmDomain.InternalBookmarkItems)
                                {
                                    if (internalItem.Key.CompareTo(bookmark.Name) == 0)
                                    {
                                        item.Value       = internalItem.BizName;
                                        item.DisplayName = SplitValue(internalItem.BizName);
                                    }
                                }
                            }
                        }
                        else
                        {
                            item.Value       = MarkupUtilities.GetRangeText(bookmark.Range);
                            item.DisplayName = SplitValue(item.Value);
                        }

                        if (listBookmarks.Count == 0)
                        {
                            listBookmarks.Add(item);
                        }
                        else
                        {
                            int  n       = -1;
                            bool existed = false;
                            for (int i = 0; i < listBookmarks.Count; i++)
                            {
                                n += 1;
                                if (listBookmarks[i].Value.Equals(item.Value))
                                {
                                    existed = true;
                                    break;
                                }
                            }

                            //3.
                            if (existed)
                            {
                                listBookmarks[n].NumberEntry += 1;
                                listBookmarks[n].Items.Add(bookmark);
                            }
                            else//4.
                            {
                                listBookmarks.Add(item);
                            }
                        }
                    }
                }
                contentProfile.GetDistinctBM_OListBM = listBookmarks;
            }
            catch (BaseException srvExp)
            {
                Services.ServiceException newSrvExp = new Services.ServiceException(ErrorCode.ipe_GetDistinctBookmarkError);
                newSrvExp.Errors.Add(srvExp);

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

                throw srvExp;
            }
        }
示例#23
0
        public void btnHighlightBookmark_Click(Office.IRibbonControl control)
        {
            try
            {
                TemplateInfo templateInfo = Wkl.MainCtrl.CommonCtrl.CommonProfile.CurrentTemplateInfo;
                if (templateInfo != null && templateInfo.InternalBookmark != null &&
                    templateInfo.DomainNames != null &&
                    templateInfo.DomainNames.Count > 0)
                {
                    DomainSelector domainSelector = new DomainSelector();
                    domainSelector.ShowDialog();
                    Dictionary <string, string> selectedDomains = domainSelector.DataTagColor;
                    bool   isHighlight = domainSelector.IsHighlight;
                    string colorNameDS = domainSelector.DocumentSpecificConditionColor;
                    DefineColors.DefineColor colorDS = DefineColors.GetColor(colorNameDS, false);
                    foreach (KeyValuePair <string, string> selectedDomain in selectedDomains)
                    {
                        InternalBookmarkDomain ibmDomain = templateInfo.InternalBookmark.GetInternalBookmarkDomain(selectedDomain.Key);
                        if (ibmDomain != null && ibmDomain.InternalBookmarkItems != null)
                        {
                            string colorNameDT = selectedDomain.Value;
                            DefineColors.DefineColor colorDT = DefineColors.GetColor(colorNameDT, false);

                            foreach (InternalBookmarkItem ibmItem in ibmDomain.InternalBookmarkItems)
                            {
                                string key = string.Empty;
                                Pdw.WKL.Profiler.Manager.ManagerProfile profile = Wkl.MainCtrl.ManagerCtrl.CreateProfile(out key);
                                profile.HighlightBookmarkName = ibmItem.Key;
                                Managers.DataIntegration.DataIntegrationManager bmMgr = new Managers.DataIntegration.DataIntegrationManager();
                                bool isDocumentSpecific = MarkupUtilities.IsProntoDocDocumentSpecificBookmark(ibmItem.Key);
                                if (isDocumentSpecific)
                                {
                                    if (colorDS != null)
                                    {
                                        profile.WdColorIndex = colorDS.Color;
                                    }
                                }
                                else
                                {
                                    if (colorDT != null)
                                    {
                                        profile.WdColorIndex = colorDT.Color;
                                    }
                                }

                                if (isHighlight)
                                {
                                    bmMgr.HighLightBookmark(key);
                                }
                                else
                                {
                                    bmMgr.UnHighLightBookmark(key);
                                }
                            }
                            ibmDomain.Color = isHighlight ? colorNameDT : string.Empty;
                            templateInfo.InternalBookmark.DocumentSpecificColor = isHighlight ? colorNameDS : string.Empty;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogUtils.Log("chkHighlightBookmark_Click", ex);
            }
        }
示例#24
0
        /// <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);
        }
示例#25
0
        private string GetPdeXslPath(string bizName, List <string> selectedTables)
        {
            string        xslPath      = string.Empty;
            List <string> path         = selectedTables;
            List <string> parentPath   = new List <string>();
            bool          isForeachTag = false;

            if (!string.IsNullOrWhiteSpace(bizName)) // data tag
            {
                if (_foreach.Count > 0)
                {
                    string colKey = _foreach[_foreach.Count - 1].Path[0];
                    parentPath = GetPdeSelectedTables(colKey, false);
                }
            }
            else // for-each
            {
                if (_foreach.Count > 0)
                {
                    string colKey = _foreach[_foreach.Count - 1].Path[0];
                    path = selectedTables = GetPdeSelectedTables(colKey, false);

                    if (_foreach.Count > 1) // has foreach parent
                    {
                        colKey     = _foreach[_foreach.Count - 2].Path[0];
                        parentPath = GetPdeSelectedTables(colKey, false);
                    }
                }
            }

            // build virtual path
            for (int i = 0; i < parentPath.Count - path.Count; i++)
            {
                if (MarkupUtilities.IsExistOnList(selectedTables, parentPath[i]))
                {
                    xslPath = "../" + xslPath;
                }
            }

            // build path
            for (int i = parentPath.Count; i < path.Count; i++)
            {
                if (MarkupUtilities.IsExistOnList(selectedTables, path[i]))
                {
                    xslPath = xslPath + path[i] + "/";
                }
            }

            if (xslPath.EndsWith("/"))
            {
                xslPath = xslPath.Remove(xslPath.Length - 1);
            }

            if (string.IsNullOrEmpty(xslPath) && path.Count > 0)
            {
                xslPath = "../" + MarkupUtilities.XmlEncode(path[path.Count - 1]);
            }

            // process add section (put virutal path at the root table)
            if (_isAddSection)
            {
                if ((_foreach.Count == 1 && isForeachTag) ||           // root for-each tag (add virtual path in the first)
                    (_foreach.Count == 0 && selectedTables.Count > 0)) // root select (remove the first path)
                {
                    string sectionPath = GetSectionPath();
                    int    index       = IndexOfSecondChar(xslPath, '/', false); // second because the first is DomainName
                    if (index > 0)
                    {
                        xslPath = xslPath.Substring(index + 1);
                        if (string.IsNullOrEmpty(xslPath) && selectedTables.Count > 0) // using for for-each of root after for-each multi section
                        {
                            xslPath = "../../" + sectionPath;
                        }
                    }
                    else
                    {
                        if (selectedTables.Count > 0 && xslPath == sectionPath) // in case user tag for-each root node
                        {
                            xslPath = "../../" + sectionPath;
                        }
                    }
                }
            }

            return(xslPath);
        }
示例#26
0
        private string GetPdwXslPath(string bizName, bool isIf, List <string> selectedTables,
                                     Relations relations, XmlNode startNode = null)
        {
            string        xslPath      = string.Empty;
            List <string> path         = new List <string>();
            List <string> parentPath   = new List <string>();
            bool          isForeachTag = false;

            if (relations.MapInfos.ContainsKey(bizName))
            {
                string tableName = relations.MapInfos[bizName].TableName;
                if (tableName.StartsWith("[") && tableName.EndsWith("]"))
                {
                    tableName = tableName.Substring(1, tableName.Length - 2);
                }
                path    = GetPath(selectedTables, tableName);
                bizName = "@" + MarkupUtilities.XmlEncode(bizName);
                if (isIf)
                {
                    bizName = bizName + "= 1";
                }
                if (_foreach.Count > 0) // has foreach parent
                {
                    parentPath = _foreach[_foreach.Count - 1].Path;
                }
            }
            else
            {
                if (bizName == ProntoDoc.Framework.CoreObject.FrameworkConstants.PdwWatermark)
                {
                    xslPath = GetSectionPath() + "/";
                    bizName = "@" + Pdw.Core.MarkupUtilities.XmlEncode(bizName);
                }
                else
                {
                    if (_foreach.Count > 0)
                    {
                        isForeachTag = true;
                        path         = _foreach[_foreach.Count - 1].Path;
                        if (_foreach.Count > 1) // has foreach parent
                        {
                            parentPath = _foreach[_foreach.Count - 2].Path;
                        }
                    }
                }
            }

            // build virtual path
            for (int i = 0; i < parentPath.Count - path.Count; i++)
            {
                if (MarkupUtilities.IsExistOnList(selectedTables, parentPath[i]))
                {
                    xslPath = "../" + xslPath;
                }
            }

            // build path
            for (int i = parentPath.Count; i < path.Count; i++)
            {
                if (MarkupUtilities.IsExistOnList(selectedTables, path[i]))
                {
                    xslPath = xslPath + MarkupUtilities.XmlEncode(path[i]) + "/"; // ngocbv: add encode
                }
            }
            xslPath = xslPath + bizName;
            if (xslPath.EndsWith("/"))
            {
                xslPath = xslPath.Remove(xslPath.Length - 1);
            }

            if (string.IsNullOrEmpty(xslPath) && path.Count > 0)
            {
                xslPath = "../" + MarkupUtilities.XmlEncode(path[path.Count - 1]);
            }

            // process add section (put virutal path at the root table)
            if (_isAddSection)
            {
                if ((_foreach.Count == 1 && isForeachTag) ||           // root for-each tag (add virtual path in the first)
                    (_foreach.Count == 0 && selectedTables.Count > 0)) // root select (remove the first path)
                {
                    string sectionPath = GetSectionPath();
                    int    index       = IndexOfSecondChar(xslPath, '/', false); // second because the first is DomainName
                    if (index > 0)
                    {
                        xslPath = xslPath.Substring(index + 1);
                        if (string.IsNullOrEmpty(xslPath) && selectedTables.Count > 0) // using for for-each of root after for-each multi section
                        {
                            xslPath = "../../" + sectionPath;
                        }
                    }
                    else
                    {
                        if (selectedTables.Count > 0 && xslPath == sectionPath) // in case user tag for-each root node
                        {
                            xslPath = "../../" + sectionPath;
                        }
                    }
                }
            }

            // process when tag in header or footer
            if (startNode != null)
            {
                if (selectedTables.Count > 0)
                {
                    bool isInFooterOrHeader = IsInFooterOrHeader(startNode);
                    if (isInFooterOrHeader)
                    {
                        string sectionPath = GetSectionPath();
                        if (!xslPath.StartsWith(sectionPath))
                        {
                            xslPath = sectionPath + "/" + xslPath;
                        }
                    }
                }
            }

            return(xslPath);
        }
示例#27
0
        /// <summary>
        /// Add internal bookmark item
        /// </summary>
        /// <param name="bm"></param>
        public void AddInternalBookmark(string key)
        {
            try
            {
                ServicesProfile           serviceProfile = Wkl.MainCtrl.ServiceCtrl.GetProfile(key);
                IntegrationServiceProfile integrationPro = serviceProfile.IntegrationService;
                InternalBookmarkItem      ibmItem        = integrationPro.AddInternalBM_IBookmark;
                if (string.IsNullOrWhiteSpace(ibmItem.DomainName))
                {
                    ibmItem.DomainName = Wkl.MainCtrl.CommonCtrl.CommonProfile.CurrentTemplateInfo.SelectedDomainName;
                }
                switch (ibmItem.Type)
                {
                case XsltType.Foreach:
                case XsltType.If:
                    InternalBookmarkItem start = ibmItem.Clone();
                    InternalBookmarkItem end   = ibmItem.Clone();

                    start.BizName = MarkupUtilities.GenTextXslTag(ibmItem.BizName, ibmItem.Type, true);
                    start.Key     = MarkupUtilities.GenKeyForXslTag(ibmItem.Key, ibmItem.Type, true);

                    serviceProfile.IbmItem = start;
                    AddInternalBookmarkItem(key);

                    end.BizName            = MarkupUtilities.GenTextXslTag(ibmItem.BizName, ibmItem.Type, false);
                    end.Key                = MarkupUtilities.GenKeyForXslTag(ibmItem.Key, ibmItem.Type, false);
                    serviceProfile.IbmItem = end;
                    AddInternalBookmarkItem(key);
                    break;

                case XsltType.Select:
                    InternalBookmarkItem select = ibmItem.Clone();
                    select.BizName = MarkupUtilities.GenTextXslTag(select.BizName, select.Type, true);
                    select.Key     = ibmItem.IsImage() ? select.Key + ProntoMarkup.KeyImage
                            : MarkupUtilities.GenKeyForXslTag(select.Key, select.Type, true);

                    serviceProfile.IbmItem = select;
                    AddInternalBookmarkItem(key);
                    break;

                case XsltType.Comment:
                    InternalBookmarkItem comment = ibmItem.Clone();
                    comment.BizName = MarkupUtilities.GenTextXslTag(comment.BizName, comment.Type, true);
                    comment.Key     = ibmItem.IsImage() ? comment.Key + ProntoMarkup.KeyImage
                            : MarkupUtilities.GenKeyForXslTag(comment.Key, comment.Type, true);

                    serviceProfile.IbmItem = comment;
                    AddInternalBookmarkItem(key);
                    break;

                default:
                    break;
                }
            }
            catch (BaseException srvExp)
            {
                Services.ServiceException newSrvExp = new Services.ServiceException(ErrorCode.ipe_AddIbmItemError);
                newSrvExp.Errors.Add(srvExp);

                throw newSrvExp;
            }
            catch (Exception ex)
            {
                ServiceException srvExp = new ServiceException(ErrorCode.ipe_AddIbmItemError,
                                                               MessageUtils.Expand(Properties.Resources.ipe_AddIbmItemError, ex.Message), ex.StackTrace);
                throw srvExp;
            }
        }
示例#28
0
        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;
            }
        }
示例#29
0
        /// <summary>
        /// add a comment
        /// </summary>
        /// <pparam name="bm"></pparam>
        private void AddCommentBookmark(InternalBookmarkItem bm)
        {
            string          key;
            ServicesProfile servicePro = Wkl.MainCtrl.ServiceCtrl.CreateProfile(out key);

            // add a space before comment
            servicePro.ContentService.AddToSelection_Text       = " ";
            servicePro.ContentService.AddToSelection_IsSelected = false;
            AddTextToCurrentSelection(key);

            // change font color to Red
            servicePro.ContentService.WdColorIndex = WdColorIndex.wdRed;
            SetFontForCurrentSelection(key);

            // add select text
            string commentText = MarkupUtilities.GenTextXslTag(bm.BizName, bm.Type, true);

            servicePro.ContentService.AddToSelection_Text       = commentText;
            servicePro.ContentService.AddToSelection_IsSelected = false;
            AddTextToCurrentSelection(key);

            // change font color to normal
            servicePro.ContentService.WdColorIndex = WdColorIndex.wdBlack;
            SetFontForCurrentSelection(key);

            // add a space after comment
            servicePro.ContentService.AddToSelection_Text       = " ";
            servicePro.ContentService.AddToSelection_IsSelected = false;
            AddTextToCurrentSelection(key);

            // move left a character to back to comment
            servicePro.ContentService.MoveChars_Count    = 1;
            servicePro.ContentService.MoveChars_IsLeft   = true;
            servicePro.ContentService.MoveChars_IsExtend = false;
            MoveChars(key);

            // select comment
            servicePro.ContentService.MoveChars_Count    = commentText.Length;
            servicePro.ContentService.MoveChars_IsLeft   = true;
            servicePro.ContentService.MoveChars_IsExtend = true;
            MoveChars(key);

            // add select bookmark
            servicePro.ContentService.AddBookmark_Name = MarkupUtilities.GenKeyForXslTag(bm.Key, bm.Type, true);
            AddBookmarkInCurrentSelection(key);

            // move to end of comment
            servicePro.ContentService.MoveChars_Count    = 1;
            servicePro.ContentService.MoveChars_IsLeft   = false;
            servicePro.ContentService.MoveChars_IsExtend = false;
            MoveChars(key);

            // move to comment text position
            servicePro.ContentService.MoveChars_Count    = ProntoMarkup.ValueCommentTextPosition;
            servicePro.ContentService.MoveChars_IsLeft   = true;
            servicePro.ContentService.MoveChars_IsExtend = false;
            MoveChars(key);

            // change font color to normal
            servicePro.ContentService.WdColorIndex = WdColorIndex.wdBlack;
            SetFontForCurrentSelection(key);

            Wkl.MainCtrl.ServiceCtrl.RemoveDataObject(key);
        }