protected internal virtual void WriteXmlCore(XmlWriter writer)
 {
     if (ExtractionMode != default(ExtractionMode))
     {
         writer.WriteAttributeString("mode", ExtractionMode.ToString().ToCamelCase());
     }
 }
 public QNameValueExtractor(
     IMessageContextProperty property,
     string xpathExpression,
     ExtractionMode contextExtractionMode = ExtractionMode.Write,
     QNameValueExtractionMode qNameValueExtractionMode = QNameValueExtractionMode.Default)
     : this(property?.QName ?? throw new ArgumentNullException(nameof(property)), xpathExpression, contextExtractionMode, qNameValueExtractionMode)
 {
 }
예제 #3
0
 public QNameValueExtractor(
     IMessageContextProperty property,
     string xpathExpression,
     ExtractionMode contextExtractionMode = ExtractionMode.Write,
     QNameValueExtractionMode qNameValueExtractionMode = QNameValueExtractionMode.Default)
     : this(property.QName, xpathExpression, contextExtractionMode, qNameValueExtractionMode)
 {
 }
 public QNameValueExtractor(
     XmlQualifiedName propertyName,
     string xpathExpression,
     ExtractionMode contextExtractionMode = ExtractionMode.Write,
     QNameValueExtractionMode qNameValueExtractionMode = QNameValueExtractionMode.Default)
     : base(propertyName, xpathExpression, contextExtractionMode)
 {
     QNameValueExtractionMode = qNameValueExtractionMode;
 }
 protected internal virtual void WriteXmlCore(XmlWriter writer)
 {
     if (writer == null)
     {
         throw new ArgumentNullException(nameof(writer));
     }
     if (ExtractionMode != default)
     {
         writer.WriteAttributeString("mode", ExtractionMode.ToString().ToCamelCase());
     }
 }
 public PropertyExtractor(XmlQualifiedName propertyName, ExtractionMode extractionMode)
 {
     if (GetType() == typeof(PropertyExtractor) && !(extractionMode == ExtractionMode.Clear || extractionMode == ExtractionMode.Ignore))
     {
         throw new ArgumentException(
                   "Invalid ExtractionMode, only Clear and Ignore are supported for PropertyExtractor without a Value or an XPath.",
                   nameof(extractionMode));
     }
     PropertyName   = propertyName ?? throw new ArgumentNullException(nameof(propertyName));
     ExtractionMode = extractionMode;
 }
        private void QueueExctractionWorkerThread(object state)
        {
            object[]       args           = state as object[];
            string         installPath    = (string)args[0];
            string         sourceCulture  = (string)args[1];
            string         targetCulture  = (string)args[2] ?? ResourceTool.DEFAULT_CULTURE;
            ExtractionMode mode           = (ExtractionMode)args[3];
            string         exportFilePath = (string)args[4];
            string         languageDbPath = (string)args[5];

            try
            {
                this.DisableForm();

                ITranslator translator;
                switch (mode)
                {
                case ExtractionMode.DatabaseTranslation:
                    translator = new LegacyLanguageDbTranslator();
                    ((LegacyLanguageDbTranslator)translator).ReadDatabase(languageDbPath);
                    break;

                case ExtractionMode.Double:
                    translator = new ExpandedStringTranslator();
                    break;

                case ExtractionMode.Reverse:
                    translator = new ReverseStringTranslator();
                    break;

                case ExtractionMode.WebTranslation:
                    translator = new WebServiceTranslator();
                    break;

                default:
                    translator = new NormalizedStringTranslator();
                    break;
                }
                ResourceTool.ExportLanguage(installPath, sourceCulture, targetCulture, translator, exportFilePath, new AppendLogCallback(this.AppendToLog));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Export Failed", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            finally
            {
                this.EnableForm();
            }
        }
 public ConstantExtractor(XmlQualifiedName propertyName, string value, ExtractionMode extractionMode = ExtractionMode.Write)
     : base(propertyName, extractionMode)
 {
     if (value.IsNullOrEmpty())
     {
         throw new ArgumentNullException(nameof(value));
     }
     if (extractionMode == ExtractionMode.Demote)
     {
         throw new ArgumentException(
                   $"{nameof(Annotation.ExtractionMode)} '{ExtractionMode.Demote}' is not supported by {nameof(ConstantExtractor)}.",
                   nameof(extractionMode));
     }
     Value = value;
 }
예제 #9
0
        private void QueueExctractionWorkerThread(object state)
        {
            object[]       args           = state as object[];
            string         installPath    = (string)args[0];
            string         sourceCulture  = (string)args[1];
            string         targetCulture  = (string)args[2] ?? ResourceTool.DEFAULT_CULTURE;
            ExtractionMode mode           = (ExtractionMode)args[3];
            string         exportFilePath = (string)args[4];
            string         languageDbPath = (string)args[5];

            try
            {
                ITranslator translator;
                switch (mode)
                {
                case ExtractionMode.DatabaseTranslation:
                    translator = new LegacyLanguageDbTranslator();
                    ((LegacyLanguageDbTranslator)translator).ReadDatabase(languageDbPath);
                    break;

                case ExtractionMode.Double:
                    translator = new ExpandedStringTranslator();
                    break;

                case ExtractionMode.Reverse:
                    translator = new ReverseStringTranslator();
                    break;

                case ExtractionMode.WebTranslation:
                    translator = new WebServiceTranslator();
                    break;

                default:
                    translator = new NormalizedStringTranslator();
                    break;
                }
                ResourceTool.ExportLanguage(installPath, sourceCulture, targetCulture, translator, exportFilePath, new AppendLogCallback(this.AppendToLog));
                AppendToLog(string.Empty);
                MsgBox.ShowInformation(SharedStrings.LANGUAGE_READY);
            }
            catch (Exception ex)
            {
                MsgBox.ShowException(ex);
            }
        }
예제 #10
0
        private void btnNew_Click(object sender, EventArgs e)
        {
            SaveFileDialog exportSaveFileDialog = new SaveFileDialog();

            exportSaveFileDialog.Filter = "Microsoft Access File | *.mdb";
            if (exportSaveFileDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            string exportFilePath = exportSaveFileDialog.FileName;

            string sourceCulture;

            if (lbxLanguages.SelectedItem != null)
            {
                sourceCulture = ((DropDownListItem)lbxLanguages.SelectedItem).Key;
            }
            else
            {
                sourceCulture = ((DropDownListItem)lbxLanguages.Items[0]).Key;
            }

            string targetCulture = null;

            ExtractionMode mode = ExtractionMode.None;

            string installPath = Path.GetDirectoryName(Application.ExecutablePath);

            string languageDbPath = string.Empty;

            System.Threading.WaitCallback callback = new System.Threading.WaitCallback(this.QueueExctractionWorkerThread);

            object[] args = new object[6];
            args[0] = installPath;
            args[1] = sourceCulture;
            args[2] = targetCulture;
            args[3] = mode;
            args[4] = exportFilePath;
            args[5] = languageDbPath;

            System.Threading.ThreadPool.QueueUserWorkItem(callback, (object)args);
        }
 public ConstantExtractor(XmlQualifiedName propertyName, string value, ExtractionMode extractionMode = ExtractionMode.Write)
     : base(propertyName, extractionMode)
 {
     if (value.IsNullOrEmpty())
     {
         throw new ArgumentNullException("value");
     }
     if (extractionMode == ExtractionMode.Demote)
     {
         throw new ArgumentException(
                   string.Format(
                       "{0} '{1}' is not supported by {2}.",
                       typeof(ExtractionMode).Name,
                       ExtractionMode.Demote,
                       typeof(ConstantExtractor).Name),
                   "extractionMode");
     }
     Value = value;
 }
        private void ExportSelectedLanguage()
        {
            if (exportSaveFileDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            string exportFilePath = exportSaveFileDialog.FileName;

            string sourceCulture = ((DropDownListItem)this.lstInstalledLanguages.SelectedItem).Key;

            string targetCulture = null;

            if (rbCreateAutoTranslate.Checked)
            {
                targetCulture = (this.ddlCultures.SelectedItem as DropDownListItem).Key.ToString();
            }


            ExtractionMode mode =
                this.rbCreateAutoTranslate.Checked ? ExtractionMode.WebTranslation
                : this.rbCreateReverse.Checked ? ExtractionMode.Reverse
                : this.rbCreateCopy.Checked ? ExtractionMode.Copy
                : this.rbCreateLegacyEpiDatabase.Checked ? ExtractionMode.DatabaseTranslation
                : this.rbCreateExpansion.Checked ? ExtractionMode.Double
                : mode = ExtractionMode.None;

            string installPath = this.folderBrowserDialog.SelectedPath;

            string languageDbPath = this.txtLanguageDatabase.Text;

            System.Threading.WaitCallback callback = new System.Threading.WaitCallback(this.QueueExctractionWorkerThread);

            object[] args = new object[6];
            args[0] = installPath;
            args[1] = sourceCulture;
            args[2] = targetCulture;
            args[3] = mode;
            args[4] = exportFilePath;
            args[5] = languageDbPath;

            System.Threading.ThreadPool.QueueUserWorkItem(callback, (object)args);
        }
예제 #13
0
 public XPathExtractor(IMessageContextProperty property, string xpathExpression, ExtractionMode extractionMode = ExtractionMode.Write)
     : this(property.QName, xpathExpression, extractionMode)
 {
 }
 public XPathExtractor(XmlQualifiedName propertyName, string xpathExpression, ExtractionMode extractionMode = ExtractionMode.Write)
     : base(propertyName, extractionMode)
 {
     XPathExpression = new XPathExpression(xpathExpression);
 }
 public XPathExtractor(IMessageContextProperty property, string xpathExpression, ExtractionMode extractionMode = ExtractionMode.Write)
     : this(property?.QName ?? throw new ArgumentNullException(nameof(property)), xpathExpression, extractionMode)
 {
 }
예제 #16
0
        /// <summary>
        /// Extracts individual Guidelines from document based on given style
        /// </summary>
        public static List <Guideline> GetGuideLinesInDocument(string chapterWordFilePath, int chapterNumber, string guidelineTitleStyle, ExtractionMode extractionMode)
        {
            OpenDocument(chapterWordFilePath);

            //object guideLineStyle = GetDocumentGuideLineStyle(); //chapters are inconsistent with styling and fonts

            List <Guideline> guidelines = new List <Guideline>();

            Word.Range rng = _WordApp.ActiveDocument.Content;

            rng.Find.ClearFormatting();
            rng.Find.Text = "Guidelines";
            rng.Find.set_Style(guidelineTitleStyle);

            rng.Find.Execute();

            bool foundAGuidelineTable = false;

            while (rng.Find.Found)
            {
                // the range of rng will just be the word "Guidelines" which is in a table. So the rngTables
                //will just be one Table which is the table that the Guideline is in.
                foreach (Word.Table guidelineTable in rng.Tables)
                {
                    GetGuidelinesInTable(ref guidelines, chapterNumber, guidelineTable, extractionMode);
                    // GetGuidelineFromTable(ref guidelines, guidelineTable);
                }
                foundAGuidelineTable = true;
                rng.Find.Execute();
            }

            if (!foundAGuidelineTable)// no guidelines found
            {
                LogErrors(chapterNumber, guidelineTitleStyle);
                return(guidelines);
            }

            _WordApp.Documents.Close(SaveChanges: Word.WdSaveOptions.wdPromptToSaveChanges);
            return(guidelines);
        }
예제 #17
0
        /// <summary>
        /// Bookmarks each individal guideline in the Guideline table. e.g. Ch1_123asd8ad
        /// </summary>
        private static void ParseIndividualGuidelinesInTable(Range tableRange, ref List <Guideline> guidelines, int chapterNumber, ExtractionMode extractionMode)
        {
            string guidAsString;

            string          tableText = tableRange.Text;
            MatchCollection guidelineMatches;

            if (!string.IsNullOrEmpty(tableText))
            {
                guidelineMatches = Regex.Matches(tableText, @"(([^\\](?<!\r))*(?=(\r)))"); //text followed by carriage return -> get each individual guideline (i.e. each  DO..., DONT... etc) in the the table
            }
            else
            {
                return;
            }

            object start = tableRange.Start;
            object end   = tableRange.End;

            Word.Range individualGuidelineRange;

            foreach (Match guidelineMatch in guidelineMatches)
            {
                if (guidelineMatch.Value.StartsWith("Guideline") || string.IsNullOrWhiteSpace(guidelineMatch.Value))
                {
                    continue;                                                                                                 //skip the first line and whitespace matches
                }
                individualGuidelineRange = _ChapterWordDoc.Range(start, end);
                string searchText = PrepareFindText(guidelineMatch.Value);

                individualGuidelineRange.Find.Text = searchText;
                individualGuidelineRange.Find.Execute();


                if (individualGuidelineRange.Find.Found)
                {
                    guidAsString = Guid.NewGuid().ToString("N");
                    string bookmarkKey   = "NA";
                    string guidelineText = GetXmlCompatibleText(individualGuidelineRange.Text);

                    Guideline guideline;
                    switch (extractionMode)
                    {
                    case ExtractionMode.BookmarkAllGuidelines:
                        bookmarkKey = (_ChapterWordDoc.Bookmarks.Add(($"Ch{chapterNumber.ToString().PadLeft(2, '0')}_{guidAsString}").Substring(0, 12), individualGuidelineRange).Name);
                        guideline   = new Guideline()
                        {
                            Key = bookmarkKey, Text = guidelineText
                        };
                        GuidelinesFormatter.Guidelines.Add(guideline);
                        break;

                    case ExtractionMode.NoBookmarking:
                        bookmarkKey = "NA";
                        guideline   = new Guideline()
                        {
                            Key = bookmarkKey, Text = guidelineText
                        };
                        GuidelinesFormatter.Guidelines.Add(guideline);
                        break;

                    case ExtractionMode.BookmarkOnlyNewGuidelinesAndCheckForChangesOfPreviouslyBookmarkedGuidelines:
                        //check if text is already bookmarked and if text has changed.
                        GuidelineStatus guidelineStatus = checkBookmarkStatus(individualGuidelineRange.Text, individualGuidelineRange, ref bookmarkKey);
                        if (guidelineStatus == GuidelineStatus.NotPreviouslyBookmarkedNewGuideline)
                        {
                            bookmarkKey = (_ChapterWordDoc.Bookmarks.Add(($"Ch{chapterNumber.ToString().PadLeft(2, '0')}_{guidAsString}").Substring(0, 12), individualGuidelineRange).Name);
                            guideline   = new Guideline()
                            {
                                Key = bookmarkKey, Text = guidelineText
                            };
                            GuidelinesFormatter.Guidelines.Add(guideline);
                        }
                        else if (guidelineStatus == GuidelineStatus.BookmarkedAndChanged)
                        {
                            Guideline existingGuideLine;
                            Guideline guidelineWithChangedText = new Guideline()
                            {
                                Key = bookmarkKey
                            };
                            if (GuidelinesFormatter.Guidelines.TryGetValue(guidelineWithChangedText, out existingGuideLine))
                            {
                                GuidelinesFormatter.Guidelines.Remove(guidelineWithChangedText);     //remove old
                                guideline = new Guideline()
                                {
                                    Key = bookmarkKey, Text = guidelineText, Comments = existingGuideLine.Comments, Section = existingGuideLine.Section, Severity = existingGuideLine.Severity, Subsection = existingGuideLine.Subsection
                                };                                                                                                                                                                                                                                        //update new
                                GuidelinesFormatter.Guidelines.Add(guideline);
                            }
                        }

                        break;
                    }

                    //guidelines.Add((bookmark, individualGuidelineRange.Text));

                    //GuidelinesFormatter.Guidelines.Add(guideline);

                    //guidelines.Add(guideline);
                }
            }
        }
예제 #18
0
        /* public static void GetGuidelineFromTable(ref List<string> guidelineTable, Word.Table table)
         * {
         *
         *   for (int row = 1; row <= table.Rows.Count; row++)
         *   {
         *       var cell = table.Cell(row, 1);
         *       var text = cell.Range.Text;
         *       if (text.Contains("Guidelines"))
         *       {
         *           guidelineTable.Add(text);
         *       }
         *       // text now contains the content of the cell.
         *   }
         *
         * }*/


        public static void GetGuidelinesInTable(ref List <Guideline> guidelines, int chapterNumber, Word.Table table, ExtractionMode extractionMode)
        {
            Word.Range individualGuidelineRange;
            for (int row = 1; row <= table.Rows.Count; row++)
            {
                var cell = table.Cell(row, 1);
                var text = cell.Range.Text;
                if (text.Contains("Guidelines"))
                {
                    individualGuidelineRange = cell.Range;

                    ParseIndividualGuidelinesInTable(cell.Range, ref guidelines, chapterNumber, extractionMode);
                }
            }
        }
 public ConstantExtractor(IMessageContextProperty property, string value, ExtractionMode extractionMode = ExtractionMode.Write)
     : this(property.QName, value, extractionMode)
 {
 }
 public ConstantExtractor(IMessageContextProperty property, string value, ExtractionMode extractionMode = ExtractionMode.Write)
     : this(property?.QName ?? throw new ArgumentNullException(nameof(property)), value, extractionMode)
 {
 }