Ejemplo n.º 1
0
        public TmxMallSegmenter(Segment sourceSegment)
        {
            TmxMallSegmentElementVisitor tmxMallSegmentElementVisitor = new TmxMallSegmentElementVisitor();

            this._tags      = new List <SegmentElement>();
            this._plaintags = new List <string>();
            foreach (SegmentElement current in sourceSegment.Elements)
            {
                SegmentElement item = current.Duplicate();
                current.AcceptSegmentElementVisitor(tmxMallSegmentElementVisitor);
                string plainText = tmxMallSegmentElementVisitor.PlainText;
                bool   flag      = !string.IsNullOrEmpty(plainText);
                if (flag)
                {
                    bool flag2 = plainText.IndexOf("<g") >= 0;
                    if (flag2)
                    {
                        this._tags.Add(item);
                        this._plaintags.Add(plainText);
                    }
                    else
                    {
                        bool flag3 = plainText.IndexOf("/g>") >= 0;
                        if (flag3)
                        {
                            this._tags.Add(item);
                            this._plaintags.Add(plainText);
                        }
                    }
                    tmxMallSegmentElementVisitor.Reset(false);
                }
            }
        }
        /// <summary>
        /// Microsoft always adds closing tags, but we don't keep track of our tags that way..so the segments always have garbage text at the end with the closing tag markup...this method removes them
        /// </summary>
        /// <param name="segment"></param>
        /// <returns></returns>
        public Segment RemoveTrailingClosingTags(Segment segment)
        {
            #region RemoveTrailingClosingTags
            SegmentElement element = segment.Elements[segment.Elements.Count - 1]; //get last element
            string         str     = element.ToString();

            int             tagsCount = segment.GetTagCount();
            string          pattern   = @"\</tg[0-9]*\>"; //we want to find "</tg" + {any number} + ">"
            Regex           rgx       = new Regex(pattern);
            System.Type     elType    = element.GetType();
            MatchCollection matches   = rgx.Matches(str);
            if (elType.ToString().Equals("Sdl.LanguagePlatform.Core.Text") && matches.Count > 0) //if a text element containing matches
            {
                foreach (Match myMatch in matches)
                {
                    str = str.Replace(myMatch.Value, ""); //puts our separator around tagtexts
                }

                segment.Elements.Remove(element);
                segment.Add(str.TrimStart());
            }
            #endregion

            return(segment);
        }
        public void AddTuExtended(string tmPath)
        {
            #region "OpenExtended"
            FileBasedTranslationMemory tm = new FileBasedTranslationMemory(tmPath);
            TranslationUnit            tu = new TranslationUnit();
            #endregion

            #region "SegmentsExtended"
            tu.SourceSegment = new Segment(tm.LanguageDirection.SourceLanguage);
            tu.TargetSegment = new Segment(tm.LanguageDirection.TargetLanguage);
            #endregion

            #region "elements"
            SegmentElement srcElement = this.GetSourceElement();
            SegmentElement trgElement = this.GetTargetElement();
            tu.SourceSegment.Add(srcElement);
            tu.TargetSegment.Add(trgElement);
            #endregion

            #region "AddTuExtended"
            tm.LanguageDirection.AddTranslationUnit(tu, this.GetImportSettings());
            tm.Save();
            MessageBox.Show("TU has been added successfully.");
            #endregion
        }
Ejemplo n.º 4
0
        public void GetSegmentDefinition(string name, string version, out ArrayList elements, out string segDesc)
        {
            LoadXmlFile();
            elements = new ArrayList();
            segDesc  = string.Empty;
            var hl7Version = _hl7Versions.HL7Version.Where(v => v.Version.Equals(version)).SingleOrDefault();

            if (null != hl7Version)
            {
                var segment = hl7Version.Segments.Where(s => s.Name.Equals(name)).SingleOrDefault();
                segDesc = segment.Description;
                var sortedFields = segment.Fields.Field.OrderBy(f => f.Order);
                foreach (var field in sortedFields)
                {
                    var element = new SegmentElement()
                    {
                        field       = field.Order,
                        type        = field.Type,
                        opt         = field.Required ? "R" : "O",
                        repetitions = field.Repeations,
                        length      = field.Length,
                        table       = string.IsNullOrEmpty(field.Table) ? 0 : Convert.ToInt32(field.Table),
                        desc        = field.Description
                    };
                    elements.Add(element);
                }
            }
        }
Ejemplo n.º 5
0
        public void RootTouchbarToXmlAsStringNotNull()
        {
            //Arrange
            var space   = new SpecialElement(SpecialElement.Space.Small);
            var segRoot = new SegmentedControl("4")
            {
                Seperated = true
            };
            var seg1 = new SegmentElement("seg1", "a,b,c", "Segment BT 1");

            segRoot.ChildElements.Add(seg1);

            var scroll = new ScrollViewControl("X");

            scroll.ChildElements.Add(new ButtonElement("s1", "1,2,3", "Scroll BT1", CustomIcons.GoToIcon));
            scroll.ChildElements.Add(new ButtonElement("s2", "ctrl+f", "Scroll BT2")
            {
                Width = 80, BackgroundColor = "ff0000"
            });
            scroll.ChildElements.Add(new ButtonElement("s3", "ctrl+f", "Scroll BT3")
            {
                Width = 120
            });
            scroll.ChildElements.Add(new ButtonElement("s4", "ctrl+f", "Scroll BT4")
            {
                Width = 80
            });

            var pop = new PopoverControl("Y", "Pop Items", CustomIcons.SurroundIcon);

            pop.ChildElements.Add(new ButtonElement("p2", "ctrl+f", "Pop BT1")
            {
                Width = 80
            });
            pop.PressAndHoldChildElements.Add(new ButtonElement("p1", "1,2,3", "PopHold BT1", CustomIcons.FormatDocIcon));
            var button3 = new ButtonElement("p3", "alt+f1", "PopHold BT2");

            pop.PressAndHoldChildElements.Add(button3);

            var root = new RootTouchbar();

            root.Elements.Add(new ButtonElement("r1", "1,2,3", "Button1", SystemStandardIcons.Play));
            root.Elements.Add(space);
            root.Elements.Add(new ButtonElement("r2", "ctrl+f", "Button2")
            {
                Width = 80
            });
            root.Elements.Add(segRoot);
            root.Elements.Add(scroll);
            root.Elements.Add(pop);

            //Act
            var doc = root.ToXmlAsString();

            //Assert
            Assert.IsNotNull(doc);

            Debug.Write(doc);
        }
Ejemplo n.º 6
0
        private void AddField(ArrayList elements, int field, string type, string optional, int repetitions, int length, int table, string description)
        {
            var element = new SegmentElement()
            {
                field = field, type = type, opt = optional, repetitions = repetitions, length = length, table = table, desc = description
            };

            elements.Add(element);
        }
Ejemplo n.º 7
0
        public void SegmentParser_GetTag_StandaloneTag()
        {
            string value = "<ut Type=\"start\" RightEdge=\"angle\"/>";

            SegmentElement actual = SegmentParser.GetTag(value);

            Assert.AreEqual(TagType.Standalone, (actual as Tag).Type);
            Assert.AreEqual(@"ut", (actual as Tag).TagID);
            Assert.IsNotNull((actual as Tag).Anchor);
        }
        public static SegmentElement ConvertToSegmentElement(this ElementViewModel node)
        {
            var button = new SegmentElement(node.Id, node.KeyCode, node.Title, node.Bitmap != null ? node.EncodedIcon : null)
            {
                ScaleImage2X = node.ScaleImage2X,
                Width        = node.Width
            };

            if (node.TextColor.HasValue)
            {
                button.TextColor = node.TextColor.Value.ConvertColorToHex();
            }
            if (node.BackgroundColor.HasValue)
            {
                button.BackgroundColor = node.BackgroundColor.Value.ConvertColorToHex();
            }

            return(button);
        }
        private SegmentElement GetTargetElement()
        {
            SegmentElement element = null;

            return(element);
        }
        private SegmentElement GetSourceElement()
        {
            SegmentElement element = null;

            return(element);
        }
Ejemplo n.º 11
0
        public void GetSegmentDefinition(string name, string version, out ArrayList elements, out string segDesc)
        {
            SegmentElement se;

            elements = new ArrayList();
            segDesc  = null;
            OleDbConnection conn = NormativeDatabase.Instance.Connection;
            StringBuilder   sql  = new StringBuilder();

            sql.Append("SELECT HL7SegmentDataElements.seg_code, HL7SegmentDataElements.seq_no, ");
            sql.Append("HL7SegmentDataElements.repetitional, HL7SegmentDataElements.repetitions, ");
            sql.Append("HL7DataElements.description, HL7DataElements.length_old, HL7DataElements.table_id, ");
            sql.Append("HL7SegmentDataElements.req_opt, HL7Segments.description, HL7DataElements.data_structure ");
            sql.Append(
                "FROM HL7Versions RIGHT JOIN (HL7Segments INNER JOIN (HL7DataElements INNER JOIN HL7SegmentDataElements ");
            sql.Append("ON (HL7DataElements.version_id = HL7SegmentDataElements.version_id) ");
            sql.Append("AND (HL7DataElements.data_item = HL7SegmentDataElements.data_item)) ");
            sql.Append("ON (HL7Segments.version_id = HL7SegmentDataElements.version_id) ");
            sql.Append("AND (HL7Segments.seg_code = HL7SegmentDataElements.seg_code)) ");
            sql.Append("ON (HL7Versions.version_id = HL7Segments.version_id) ");
            sql.Append("WHERE HL7SegmentDataElements.seg_code = '");
            sql.Append(name);
            sql.Append("' and HL7Versions.hl7_version = '");
            sql.Append(version);
            sql.Append("' ORDER BY HL7SegmentDataElements.seg_code, HL7SegmentDataElements.seq_no;");
            OleDbCommand stmt = SupportClass.TransactionManager.manager.CreateStatement(conn);
            OleDbCommand temp_OleDbCommand;

            temp_OleDbCommand             = stmt;
            temp_OleDbCommand.CommandText = sql.ToString();
            OleDbDataReader rs = temp_OleDbCommand.ExecuteReader();

            while (rs.Read())
            {
                if (segDesc == null)
                {
                    segDesc = Convert.ToString(rs[9 - 1]);
                }
                se       = new SegmentElement();
                se.field = Convert.ToInt32(rs.GetValue(2 - 1));
                se.rep   = Convert.ToString(rs[3 - 1]);
                if (rs.IsDBNull(4 - 1))
                {
                    se.repetitions = 0;
                }
                else
                {
                    se.repetitions = Convert.ToInt32(rs.GetValue(4 - 1));
                }

                if (se.repetitions == 0)
                {
                    if (se.rep == null || !se.rep.ToUpper().Equals("Y".ToUpper()))
                    {
                        se.repetitions = 1;
                    }
                }
                se.desc = Convert.ToString(rs[5 - 1]);
                if (!rs.IsDBNull(6 - 1))
                {
                    se.length = DetermineLength(rs);
                }

                se.table = Convert.ToInt32(rs.GetValue(7 - 1));
                se.opt   = Convert.ToString(rs[8 - 1]);
                se.type  = Convert.ToString(rs[10 - 1]);
                //shorten CE_x to CE
                if (se.type.StartsWith("CE"))
                {
                    se.type = "CE";
                }

                elements.Add(se);

                /*System.out.println("Segment: " + name + " Field: " + se.field + " Rep: " + se.rep +
                 *              " Repetitions: " + se.repetitions + " Desc: " + se.desc + " Length: " + se.length +
                 *              " Table: " + se.table + " Segment Desc: " + segDesc);*/
            }
            rs.Close();
            stmt.Dispose();
            NormativeDatabase.Instance.returnConnection(conn);
        }