示例#1
0
        private void AssertLastCityChar(int length)
        {
            var cutLength = Truncator.FindCutLength(citiesUmlauts, length);

            // special case: length 0 means nothing should come back
            if (length == 0)
            {
                Assert.AreEqual(0, cutLength, "on 0 should be 0");
                return;
            }

            var foundChar = citiesUmlauts[cutLength - 1];
            var expected  = citiesUtf8[length - 1];

            // if it's one of the special characters, the real value will be a ; ending the entity
            if (entityPositions.Contains(length))
            {
                expected = ';';
            }
            Assert.AreEqual(expected, foundChar, $"tried on index {length}");
        }
示例#2
0
 /// <summary>
 /// Cut off a text at the best possible place with a max-length.
 /// This will count html-entities like &amp; &nbsp; or umlauts as 1 character,
 /// and will try to cut off between words if possible.
 /// </summary>
 /// <param name="value">String to cut off. Can contain umlauts and html-entities, but should not contain html-tags as there are not treated properly.</param>
 /// <param name="length">length to cut off at</param>
 /// <returns></returns>
 public static string Crop(string value, int length)
 {
     return(Truncator.SafeTruncate(value, length));
 }
示例#3
0
 /// <summary>
 /// Cut off a text at the best possible place with a max-length.
 /// This will count html-entities like &amp;, &amp;nbsp; or umlauts as 1 character,
 /// and will try to cut off between words if possible.
 /// So it will backtrack to the previous space.
 /// </summary>
 /// <param name="value">String to cut off. Can contain umlauts and html-entities, but should not contain html-tags as there are not treated properly.</param>
 /// <param name="length">length to cut off at</param>
 /// <returns></returns>
 public static string Crop(this string value, int length) => Truncator.SafeTruncate(value, length);
 public IQueueDeclarationBuilder WithName(string queueName)
 {
     Truncator.Truncate(ref queueName);
     Declaration.Name = queueName;
     return(this);
 }
示例#5
0
        public static List <IBusinessObject> ReadXml(string xml, out string notes, out string notesTable, out string notesField)
        {
            List <IBusinessObject> list        = new List <IBusinessObject>();
            StringBuilder          notesBuffer = new StringBuilder();

            XmlReader reader = XmlNodeReader.Create(new StringReader(xml));

            string          currentElementName = null;
            IBusinessObject currentBO          = null;
            bool            currentBOHasData   = false;
            bool            recordNotes        = false;

            // we have to handle Status, PathTest, QOL_Therapy as special cases, since they have fieldnames = tablenames
            bool insideSpecialTable = false;

            notesTable = null;
            notesField = null;

            Truncator truncator = null;

            while (reader.Read())
            {
                // state machine: every tag hit either forks or saves
                switch (reader.NodeType)
                {
                case XmlNodeType.EndElement:
                    if (insideSpecialTable && reader.Name == currentBO.TableName)
                    {
                        insideSpecialTable = false;
                    }
                    break;

                case XmlNodeType.Element:
                    currentElementName = reader.Name;
                    //if ((!insideSpecialTable && BOFactory.CanBuild(currentElementName)) || currentElementName == "NoTable")
                    if ((!insideSpecialTable && BusinessObjectFactory.CanBuildBusinessObject(currentElementName)) || currentElementName == "NoTable")
                    {
                        if (currentBOHasData)
                        {
                            list.Add(currentBO);

                            if (truncator != null)
                            {
                                truncator.Finish();
                            }
                        }

                        if (currentElementName == "NoTable")
                        {
                            notesTable  = reader.GetAttribute("PutDataInTable");
                            notesField  = reader.GetAttribute("PutDataInField");
                            currentBO   = null;
                            recordNotes = true;
                        }
                        else
                        {
                            //currentBO = BOFactory.GetBO(currentElementName);
                            currentBO   = BusinessObjectFactory.BuildBusinessObject(currentElementName);
                            recordNotes = false;
                            //if (currentBO.HasColumn(currentBO.Tablename))
                            if (currentBO.HasField(currentBO.TableName))
                            {
                                insideSpecialTable = true;
                            }

                            truncator = new Truncator(currentBO);
                        }

                        currentBOHasData = false;
                    }
                    break;

                case XmlNodeType.Text:
                    if (reader.Value != null && reader.Value != "")
                    {
                        // if (recordNotes) // OR !currentBO.HasField(currentElementName)
                        if (recordNotes || !currentBO.HasField(currentElementName))
                        {
                            notesBuffer.Append(" | ");
                            notesBuffer.Append(currentElementName);
                            notesBuffer.Append(" :: ");
                            notesBuffer.Append(reader.Value);
                        }
                        else
                        {
                            currentBO[currentElementName] = truncator.HandleValue(currentElementName, reader.Value);
                            currentBOHasData = true;
                        }
                    }
                    break;
                }
            }

            // finishing up
            if (currentBOHasData)
            {
                list.Add(currentBO);

                if (truncator != null)
                {
                    truncator.Finish();
                }
            }

            reader.Close();

            if (notesBuffer.Length > 0)
            {
                notes = "OTHER EFORM DATA: " + notesBuffer.ToString();
            }
            else
            {
                notes = null;
            }

            return(list);
        }
示例#6
0
 public IExchangeDeclarationBuilder WithName(string exchangeName)
 {
     Truncator.Truncate(ref exchangeName);
     Declaration.Name = exchangeName;
     return(this);
 }