Clear() public method

public Clear ( ) : StringBuilder
return StringBuilder
Example #1
0
 /// <summary>
 /// Разбить на слова.
 /// </summary>
 /// <param name="src">Исходная строка.</param>
 /// <returns>Разбитая на слова строка.</returns>
 public IEnumerable<string> Split(string src)
 {
     var sb = new StringBuilder();
     for (int i = 0; i < src.Length; i++)
     {
         var ch = src[i];
         if (ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n')
         {
             sb.Append(' ');
             yield return sb.ToString();
             sb.Clear();
         }
         else
         {
             sb.Append(ch);
             //if (ch == '.' || ch == ',' || ch == ':' || ch == '/' || ch == '\\' || ch == '#' || ch =='?' || ch == '!' || ch == '*' || ch == '-')
             if (char.IsPunctuation(ch) || ch == '.' || ch == ',' || ch == ':' || ch == '/' || ch == '\\' || ch == '#' || ch == '?' || ch == '!' || ch == '*' || ch == '-')
             {
                 yield return sb.ToString();
                 sb.Clear();
             }
         }
     }
     if (sb.Length > 0)
     {
         yield return sb.ToString();
     }
 }
        private IEnumerable<string> GetTokens() {
            var token = new StringBuilder();
            var lastCharacter = '\0';
            foreach (var character in _xPath) {
                if (IsQuote(lastCharacter)) {
                    token.Append(character);
                    if (character == lastCharacter) {
                        yield return token.ToString();
                        token.Clear();
                        lastCharacter = '\0';
                    }
                    continue;
                }

                if (IsQuote(character) || IsName(character) != IsName(lastCharacter)) {
                    if (token.Length > 0)
                        yield return TrimToken(token);
                    token.Clear();
                }
                token.Append(character);
                lastCharacter = character;
            }
            if (token.Length > 0)
                yield return TrimToken(token);
        }
Example #3
0
        static void Main(string[] args)
        {
            var text1 = File.ReadAllBytes(@"..\doc\pi.t");
              var text2 = File.ReadAllBytes(@"..\doc\e.t");

              var comparer = new Comparer();
              var k = 5;

              var result = comparer.Compare(text1, text2, k);

              var sb = new StringBuilder();
              sb.AppendLine(string.Format("Max length: {0}\n", result.MaxLength));
              using (var file = System.IO.File.AppendText(@"..\doc\pie.t"))
              {
            file.Write(sb.ToString());
            sb.Clear();
            foreach (var index in result.Indices)
            {
              sb.AppendLine(string.Format("Length: {0}, pi_index: {1}, e_index: {2}",
            index.Value,
            index.Key.Item1,
            index.Key.Item2));
              file.Write(sb.ToString());
              sb.Clear();
            }
              }
        }
        public void AppendIntTest()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
              StringBuilder stringBuilder = new StringBuilder();

              stringBuilder.AppendNumber(1234567890);
              Assert.AreEqual("1234567890", stringBuilder.ToString());

              stringBuilder.Clear();
              stringBuilder.AppendNumber(-1234567890);
              Assert.AreEqual("-1234567890", stringBuilder.ToString());

              stringBuilder.Clear();
              stringBuilder.AppendNumber(1234567890, AppendNumberOptions.None);
              Assert.AreEqual("1234567890", stringBuilder.ToString());

              stringBuilder.Clear();
              stringBuilder.AppendNumber(1234567890, AppendNumberOptions.PositiveSign);
              Assert.AreEqual("+1234567890", stringBuilder.ToString());

              stringBuilder.Clear();
              stringBuilder.AppendNumber(1234567890, AppendNumberOptions.NumberGroup);
              Assert.AreEqual("1,234,567,890", stringBuilder.ToString());

              stringBuilder.Clear();
              stringBuilder.AppendNumber(1234567890, AppendNumberOptions.PositiveSign | AppendNumberOptions.NumberGroup);
              Assert.AreEqual("+1,234,567,890", stringBuilder.ToString());
        }
        private static IEnumerable<string> SplitAndLower(string source)
        {
            var strings = new List<string>();
            var builder = new StringBuilder();

            foreach (var character in source)
            {
                if (IsSeparator(character))
                {
                    if (builder.Length > 0)
                    {
                        strings.Add(builder.ToString());
                    }

                    builder.Clear();
                    continue;
                }
                else if (char.IsUpper(character) && builder.Length > 0)
                {
                    strings.Add(builder.ToString());
                    builder.Clear();
                }

                builder.Append(char.ToLowerInvariant(character));
            }

            if (builder.Length > 0)
            {
                strings.Add(builder.ToString());
            }

            return strings;
        }
    public string ReverseWords(string s) {
        var sb = new StringBuilder();
        var wordList = new List<string>();
        foreach (var ch in s)
        {
            if (char.IsWhiteSpace(ch))
            {
                if (sb.Length > 0)
                {
                    wordList.Add(sb.ToString());
                    sb.Clear();
                }
            }
            else
            {
                sb.Append(ch);
            }
        }
        if (sb.Length > 0)
        {
            wordList.Add(sb.ToString());
            sb.Clear();
        }
        
        foreach (var word in ((IEnumerable<string>)wordList).Reverse())
        {
            if (sb.Length > 0)
            {
                sb.Append(' ');
            }
            sb.Append(word);
        }

        return sb.ToString();
    }
Example #7
0
        public void TestEagerlyLoadingMultipleLevels()
        {
            using (var context = new TestDB2015Entities())
            {
                var databaseLog = new StringBuilder();
                context.Database.Log = commandLine =>
                {
                    databaseLog.AppendLine(commandLine);
                    Trace.Write(commandLine);
                };

                Trace.WriteLine("a normal query");
                var product1IncludeTags = context.Users
                                                 .Include(x => x.Products)
                                                 .Include(x => x.Products.Select(y => y.Tags))
                                                 .FirstOrDefault();
                Assert.IsNotNull(product1IncludeTags);

                Trace.WriteLine("1st query using Include method.");
                databaseLog.Clear();
                var debugInfo1 = new EFCacheDebugInfo();
                var firstPoductIncludeTags = context.Users
                                                    .Include(x => x.Products)
                                                    .Include(x => x.Products.Select(y => y.Tags))
                                                    .Cacheable(debugInfo1)
                                                    .FirstOrDefault();
                Assert.IsNotNull(firstPoductIncludeTags);
                Assert.AreEqual(false, debugInfo1.IsCacheHit);
                var hash1 = debugInfo1.EFCacheKey.KeyHash;
                var cacheDependencies1 = debugInfo1.EFCacheKey.CacheDependencies;

                Trace.WriteLine("same cached query using Include method.");
                databaseLog.Clear();
                var debugInfo11 = new EFCacheDebugInfo();
                var firstPoductIncludeTags11 = context.Users
                                                    .Include(x => x.Products)
                                                    .Include(x => x.Products.Select(y => y.Tags))
                                                    .Cacheable(debugInfo11)
                                                    .FirstOrDefault();
                Assert.IsNotNull(firstPoductIncludeTags11);
                Assert.AreEqual(true, debugInfo11.IsCacheHit);

                Trace.WriteLine(
                    @"2nd query looks the same, but it doesn't have the Include method, so it shouldn't produce the same queryKeyHash.
                 This was the problem with just parsing the LINQ expression, without considering the produced SQL.");
                databaseLog.Clear();
                var debugInfo2 = new EFCacheDebugInfo();
                var firstPoduct = context.Users.Cacheable(debugInfo2)
                                               .FirstOrDefault();
                Assert.IsNotNull(firstPoduct);
                Assert.AreEqual(false, debugInfo2.IsCacheHit);
                var hash2 = debugInfo2.EFCacheKey.KeyHash;
                var cacheDependencies2 = debugInfo2.EFCacheKey.CacheDependencies;

                Assert.AreNotEqual(hash1, hash2);
                Assert.AreNotEqual(cacheDependencies1, cacheDependencies2);
            }
        }
        internal static IEnumerable<string> Split(string expression)
        {
            List<string> result = new List<string>();

            StringBuilder resultItemBuilder = new StringBuilder();
            List<char> charArray = expression.ToList();
            for (int i = 0; i < charArray.Count; i++)
            {
                string oneCharString = charArray[i].ToString(CultureInfo.InvariantCulture);
                string twoCharString = oneCharString;
                // 读取两个字符,判断是不是特殊双字符的操作符.etc: >=, <=, &&, ||
                if (i < charArray.Count - 1)
                {
                    twoCharString += charArray[i + 1].ToString(CultureInfo.InvariantCulture);
                }

                if (OperatorMethod.IsOperator(twoCharString) &&
                    twoCharString.Length == 2)
                {
                    if (resultItemBuilder.Length > 0)
                    {
                        result.Add(resultItemBuilder.ToString());
                        resultItemBuilder.Clear();
                    }

                    result.Add(twoCharString);
                    i++;
                }
                else if (OperatorMethod.IsOperator(oneCharString))
                {
                    if (resultItemBuilder.Length > 0)
                    {
                        result.Add(resultItemBuilder.ToString());
                        resultItemBuilder.Clear();
                    }

                    result.Add(oneCharString);
                }
                else
                {
                    resultItemBuilder.Append(oneCharString);
                }
            }

            if (resultItemBuilder.Length > 0)
            {
                result.Add(resultItemBuilder.ToString());
                resultItemBuilder.Clear();
            }

            return result;
        }
Example #9
0
        public SelectModel GetContractOutStockSelect(int pageIndex, int pageSize, string orderStr, string stockName, DateTime beginDate, DateTime endDate, string stockIds = "")
        {
            NFMT.Common.SelectModel select = new NFMT.Common.SelectModel();

            select.PageIndex = pageIndex;
            select.PageSize = pageSize;
            if (string.IsNullOrEmpty(orderStr))
                select.OrderStr = "sto.StockId desc";
            else
                select.OrderStr = orderStr;

            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append("sto.StockId,sn.RefNo,sto.AssetId,ass.AssetName,sto.BrandId,bra.BrandName,sto.Format,sto.OriginPlace,sto.CurNetAmount,sto.DeliverPlaceId");
            sb.Append(",dp.DPName,sto.StockDate,sto.UintId,mu.MUName,sto.CustomsType,ct.DetailName as CustomsTypeName,sto.CardNo,sto.StockStatus,ss.StatusName");
            sb.Append(",se.ExclusiveAmount, ISNULL(sto.CurNetAmount,0) - ISNULL(se.ExclusiveAmount,0) as NetAmount, ISNULL(sto.CurNetAmount,0) - ISNULL(se.ExclusiveAmount,0) as OutAmount,sto.Bundles,sto.Bundles as OutBundles");
            select.ColumnName = sb.ToString();

            int readyStatus = (int)Common.StatusEnum.已生效;

            sb.Clear();
            sb.Append(" dbo.St_Stock sto ");
            sb.Append("  inner join dbo.St_StockName sn on sto.StockNameId = sn.StockNameId ");

            sb.Append(" left join NFMT_Basic.dbo.Asset ass on sto.AssetId = ass.AssetId ");
            sb.Append(" left join NFMT_Basic.dbo.Brand bra on sto.BrandId = bra.BrandId ");
            sb.Append(" left join NFMT_Basic.dbo.DeliverPlace dp on sto.DeliverPlaceId = dp.DPId ");
            sb.Append(" left join NFMT_Basic.dbo.MeasureUnit mu on sto.UintId= mu.MUId ");
            sb.Append(" left join NFMT_Basic.dbo.BDStyleDetail ct on ct.StyleDetailId = sto.CustomsType ");
            sb.Append("  left join NFMT_Basic.dbo.BDStatusDetail ss on ss.DetailId = sto.StockStatus ");

            sb.AppendFormat("  left join (select Sum(ExclusiveAmount) as ExclusiveAmount,StockId from dbo.St_StockExclusive where ExclusiveStatus = {0} group by StockId ) as se on se.StockId = sto.StockId ", readyStatus);
            select.TableName = sb.ToString();

            sb.Clear();
            sb.AppendFormat(" sto.StockStatus in ({0},{1},{2}) ", (int)StockStatusEnum.预入库存, (int)StockStatusEnum.在库正常, (int)StockStatusEnum.新拆库存);
            sb.Append(" and ISNULL(sto.CurNetAmount,0) - ISNULL(se.ExclusiveAmount,0) >0 ");

            if (!string.IsNullOrEmpty(stockName))
                sb.AppendFormat(" and sn.RefNo like '%{0}%' ", stockName);
            if (beginDate > Common.DefaultValue.DefaultTime && endDate > beginDate)
                sb.AppendFormat(" and sto.StockDate between '{0}' and '{1}' ", beginDate.ToString(), endDate.AddDays(1).ToString());

            if (!string.IsNullOrEmpty(stockIds))
                sb.AppendFormat(" and sto.StockId in ({0})", stockIds);

            select.WhereStr = sb.ToString();

            return select;
        }
Example #10
0
        /// <summary>
        /// Iterator that builds tokens from the inputted document, and returns them as they are built.
        /// </summary>
        /// <param name="document">The document to tokenize</param>
        /// <returns>Returns lowercase tokens, one at a time as soon as they are read</returns>
        public IEnumerable<string> Tokenize(string document)
        {
            StringBuilder token = new StringBuilder();
            foreach(char character in document)
            {
                if (ignoreList.Contains(character))
                {
                    if (token.Length > 0)
                    {
                        string result = token.ToString().ToLower();
                        token.Clear();
                        if (this.isValidTerm(result))    // dont return stop words
                        {
                            yield return result;
                        }

                    }
                }
                else
                {
                    token.Append(character);
                }
            }

            if (token.Length > 0)
            {
                yield return token.ToString().ToLower();
            }
        }
Example #11
0
        public CipherDecoder(string secretCode, string cipher)
        {
            cipherItems = new List<CipherItem>();

            StringBuilder currentCipher = new StringBuilder();
            char lastChar = '\0';
            foreach (char ch in cipher)
            {
                if (ch >= 'A' && ch <= 'Z')
                {
                    if (currentCipher.Length > 0)
                    {
                        cipherItems.Add(new CipherItem(lastChar, currentCipher.ToString()));
                        currentCipher.Clear();
                    }
                    lastChar = ch;
                }
                else
                {
                    currentCipher.Append(ch);
                }
            }
            if (currentCipher.Length > 0)
            {
                cipherItems.Add(new CipherItem(lastChar, currentCipher.ToString()));
            }

            this.secretCode = secretCode;
        }
Example #12
0
        public string CountAndSay(int n)
        {
            var result = "1";
            char currentCh;
            int i, j, startNum;
            var builder = new StringBuilder();

            for (i = 1; i < n; i++)
            {
                currentCh = result[0];
                startNum = 0;
                for (j = 1; j < result.Length; j++)
                {
                    if (currentCh != result[j])
                    {
                        builder.Append(j - startNum);
                        builder.Append(currentCh);
                        currentCh = result[j];
                        startNum = j;
                    }
                }
                builder.Append(j - startNum);
                builder.Append(currentCh);

                result = builder.ToString();
                builder.Clear();
            }

            return result;
        }
Example #13
0
        public static EditProblemViewModel GetEditProblemViewModel(Problem problem)
        {
            var epvm = new EditProblemViewModel();
            epvm.Author = problem.Author.UserName;
            epvm.Name = problem.Name;
            epvm.Text = problem.Text;
            epvm.SelectedCategoryId = problem.CategoryId;
            epvm.IsBlocked = problem.IsBlocked;

            var sb = new StringBuilder();
            foreach (var tag in problem.Tags)
            {
                sb.Append(tag.Name);
                sb.Append(',');
            }

            epvm.TagsString = sb.ToString();

            sb.Clear();

            foreach (var ans in problem.CorrectAnswers)
            {
                sb.Append(ans.Text);
                sb.Append(';');
            }

            sb.Remove(sb.Length - 1, 1);
            epvm.Answers = sb.ToString();

            return epvm;
        }
Example #14
0
        /// <summary>
        /// Execute any update statements required to clear data, followed by delete statements for all tables.
        /// </summary>
        /// <param name="updateCommands">Update commands to execute</param>
        /// <param name="tables">Tables to delete from</param>
        /// <param name="timeout">Maximum time for a statement</param>
        /// <param name="deleteBatch">Batch delete statements into groups, saves times on databases with large numbers of tables.</param>
        public void Zap(IEnumerable<string> updateCommands, IEnumerable<string> tables, int timeout = 30, int deleteBatch = 1)
        {
            foreach (var item in updateCommands)
            {
                dao.ExecuteNonQuery(item, timeout);
            }

            var sb = new StringBuilder();
            var count = 0;
            foreach (var item in tables)
            {
                sb.AppendLine(string.Format("DELETE FROM {0};", item));
                count++;
                if (count % deleteBatch != 0)
                {
                    continue;
                }

                dao.ExecuteNonQuery(sb.ToString(), timeout);
                sb.Clear();
            }

            var lastCmd = sb.ToString();
            if (!string.IsNullOrEmpty(lastCmd))
            {
                dao.ExecuteNonQuery(lastCmd, timeout);
            }
        }
        public List<OperationElement> GetOperationElements(string expression)
        {
            if (string.IsNullOrEmpty(expression))
                throw new EmptyStringException();
            var operationElements = new List<OperationElement>();
            var builder = new StringBuilder();

            foreach (char character in expression)
            {
                if (char.IsDigit(character))
                {
                    builder.Append(character);
                }
                else if (IsOperator(character))
                {
                    if (builder.Length != 0)
                    {
                        operationElements.Add(new OperationElement(OperationElementType.Number, builder.ToString()));
                        builder.Clear();
                    }
                    operationElements.Add(new OperationElement(OperationElementType.Operator, character.ToString()));
                }
                else
                {
                    throw new IncorrectOperationStringException(expression);
                }
            }

            if (builder.Length != 0)
                operationElements.Add(new OperationElement(OperationElementType.Number, builder.ToString()));
            return operationElements;
        }
 public IList<string> FullJustify(string[] words, int maxWidth) {
     var result = new List<string>();
     var buffer = new List<string>();
     var sb = new StringBuilder();
     var len = 0;
     
     for (var i = 0; i < words.Length; ++i)
     {
         var newLen = words[i].Length + (len == 0 ? 0 : len + 1);
         if (newLen <= maxWidth)
         {
             buffer.Add(words[i]);
             len = newLen;
         }
         else
         {
             if (buffer.Count == 1)
             {
                 sb.Append(buffer[0]);
                 sb.Append(' ', maxWidth - buffer[0].Length);
             }
             else
             {
                 var spaceCount = maxWidth - len + buffer.Count - 1;
                 for (var j = 0; j < buffer.Count - 1; ++j)
                 {
                     sb.Append(buffer[j]);
                     var spaceToAdd = (spaceCount - 1) / (buffer.Count - j - 1) + 1;
                     sb.Append(' ', spaceToAdd);
                     spaceCount -= spaceToAdd;
                 }
                 sb.Append(buffer.Last());
             }
             result.Add(sb.ToString());
             buffer.Clear();
             buffer.Add(words[i]);
             sb.Clear();
             len = words[i].Length;
         }
     }
     
     if (buffer.Count > 0)
     {
         for (var j = 0; j < buffer.Count; ++j)
         {
             if (sb.Length > 0)
             {
                 sb.Append(' ');
             }
             sb.Append(buffer[j]);
         }
         if (sb.Length < maxWidth)
         {
             sb.Append(' ', maxWidth - sb.Length);
         }
         result.Add(sb.ToString());
     }
     
     return result;
 }
        public List<LogEntry> ParseFile(Stream file, string filename, List<LogEntry> existingEntries)
        {
            // TODO: error checking
            System.IO.StreamReader sr = new StreamReader(file);
            StringBuilder sb = new StringBuilder();

            List<LogEntry> entries = existingEntries??new List<LogEntry>();

            while (!sr.EndOfStream)
            {
                string line = sr.ReadLine();
                if (LogEntry.LogTimeStamp.IsMatch(line))
                {
                    if (sb.Length > 0)
                    {
                        // found a full log entry in sb, parse it and clear it out
                        LogEntry entry = null;
                        if (LogEntry.TryParse(sb.ToString(), filename, out entry))
                        {
                            // got one!
                            entries.Add(entry);
                        }
                        else
                        {
                            // what do I do with this error?
                        }
                        sb.Clear();
                    }
                }
                sb.AppendLine(line);

            }
            return entries;
        }
Example #18
0
        public IEnumerable<string> tokenize(Stream stream)
        {
            StreamReader reader = new StreamReader(stream);
            StringBuilder token = new StringBuilder();
            while (!reader.EndOfStream)
            {
                char character = (char)reader.Read();
                if (ignoreList.Contains(character))
                {
                    if (token.Length > 0)
                    {
                        string result = token.ToString().ToLower();
                        token.Clear();
                        yield return result;
                    }
                }
                else
                {
                    token.Append(character);
                }
            }

            if (token.Length > 0)
            {
                yield return token.ToString().ToLower();
            }
        }
Example #19
0
        private string FindIndependentTree(List<CatalogEntity> catalogList, int parent, int offset)
        {
            string Ret = "";

            StringBuilder sb = new StringBuilder();

            for (int i = offset, count = catalogList.Count; i < count; i++)
            {
                if(catalogList[i].Parent == parent)
                {
                    // Resolve the sub-tree of this ordered catalog beginning with sepcial offset in the list
                    string child = FindIndependentTree(catalogList, i, i + 1);
                    // Give the bookmark of this catalog
                    string bookmarks = GetBookmarks(catalogList[i].BookmarkList);

                    sb.Clear();

                    if (child != null && child.Length > 0)
                    {
                        sb.AppendLine(child);
                    }

                    if(bookmarks != null)
                    {
                        sb.AppendLine(bookmarks);
                    }

                    Ret += bookmarkWrapper.CatalogWrapper(catalogList[i].Catalog.Name, sb.ToString());
                }
            }

            return Ret;
        }
Example #20
0
        private void btnDraw_Click(object sender, RoutedEventArgs e) {

            int[][] tempTable;

            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            try {
                Console.WriteLine("kutsutaan drawia loton arvolla: " + selectedLotto);
                tempTable = lottoOlio.draw(Int32.Parse(drawsBox.Text), selectedLotto);
            }
            catch (Exception) {
                MessageBox.Show("Draws luukussa oltava numero.");
                throw;
            }

            Console.WriteLine("tempTable pituus on: " + tempTable.Length);

            for (int j = 0; j < tempTable.Length; j++) {
                sb.Clear();
                Console.WriteLine("Kierros: " + j);
                Console.WriteLine("tempTable indeksi " + j + " pituus on: " + tempTable[j].Length);
                for (int i = 0; i < tempTable[j].Length; i++) {
                    Console.WriteLine(" -Kierros: " + i);
                    sb.Append(Convert.ToString(tempTable[j][i])).Append(", ");
                }
                drawsArea.Items.Add(sb.ToString()); 
            }
        }
        public override bool Execute()
        {
            HashSet<string> directoriesToRestore = new HashSet<string>();

            foreach (string rootDirectory in RootDirectories)
            {
                AddDirectoriesToRestore(rootDirectory, rootDirectory, directoriesToRestore);
            }

            List<string> resultBuilder = new List<string>();
            StringBuilder sb = new StringBuilder(directoryListLength);

            foreach (string directoryPath in directoriesToRestore)
            {
                sb.Append('"');
                sb.Append(directoryPath);
                sb.Append("\" ");

                if (sb.Length >= directoryListLength)
                {
                    resultBuilder.Add(sb.ToString());
                    sb.Clear();
                }
            }

            if (sb.Length > 0)
            {
                resultBuilder.Add(sb.ToString());
            }

            DirectoriesToRestore = resultBuilder.ToArray();

            return true;
        }
        protected virtual void OnSuccessfulResponse(DocumentResponse response, HttpResponseMessage httpResponse)
        {
            using (var content = httpResponse.Content.ReadAsStream())
            {
                if (ContentShouldHaveIdAndRev(httpResponse.RequestMessage))
                    PopulateDocumentHeaderFromResponseStream(response, content);
                else
                {
                    PopulateMissingIdFromRequestUri(response, httpResponse);
                    PopulateMissingRevFromRequestHeaders(response, httpResponse);
                }

                content.Position = 0;

                var sb = new StringBuilder();
                using (var reader = new StreamReader(content, MyCouchRuntime.DefaultEncoding))
                {
                    while (!reader.EndOfStream)
                    {
                        sb.Append(reader.ReadLine());
                    }
                }
                response.Content = sb.ToString();
                sb.Clear();
            }
        }
        public override string ToString()
        {
            var sb = new StringBuilder();
            sb.Clear();
            sb.Append('[');

            sb.Append(this.Name);
            bool flag = true;
            foreach (var phone in this.Phones)
            {
                if (flag)
                {
                    sb.Append(": ");
                    flag = false;
                }
                else
                {
                    sb.Append(", ");
                }

                sb.Append(phone);
            }

            sb.Append(']');
            return sb.ToString();
        }
Example #24
0
        public IEnumerable<string> Wrap(string input)
        {
            var builder = new StringBuilder();
            int pos = 0;
            var result = new List<string>();
            foreach (var chr in input)
            {
                if (!(chr == ' ' && pos == 0))
                {
                    builder.Append(chr);
                    ++pos;
                    if (pos == rowLength)
                    {
                        result.Add(builder.ToString());
                        builder.Clear();
                        pos = 0;
                    }
                }
            }

            if(builder.Length > 0)
                result.Add(builder.ToString());

            return result.AsReadOnly();
        }
Example #25
0
 public void DoWorkflow(Table replaceClass, ref List<string> fileName)
 {
   StringBuilder stringBuilder1 = new StringBuilder();
   foreach (Column column in replaceClass.Columns)
   {
     if (Common.IsWorkFlow(column.Comment))
     {
       StringBuilder stringBuilder2 = new StringBuilder();
       string oldValue = "<Compile Include=@Properties\\AssemblyInfo.cs@ />".Replace('@', '"');
       string str1 = column.Comment.Replace('【', '[').Replace('】', ']').Replace(',', ',');
       string[] strArray = str1.Substring(str1.IndexOf('[') + 1, str1.IndexOf(']') - str1.IndexOf('[') - 1).Split(',');
       string newValue1 = str1.Substring(0, str1.ToUpper().IndexOf("WORKFLOW"));
       for (int index = 0; index < strArray.Length; ++index)
       {
         string newValue2 = replaceClass.Code + column.Code + index.ToString();
         string content = Common.Read(BaseClass.m_DempDirectory + "/CodeActivity1.cs").Replace("DAL", replaceClass.NameSpace + "DAL").Replace("WFActivitys", replaceClass.NameSpace + "WFActivitys").Replace("CodeActivity1", newValue2).Replace(this.m_ReplaceClassCode, replaceClass.Code).Replace(this.m_ReplaceClassName, replaceClass.Name).Replace(this.m_ReplaceAttribute, strArray[index]).Replace("^State^", column.Code).Replace(this.m_Id, Common.GetFirstPrimaryKeyCode(replaceClass)).Replace("WF", newValue1);
         Common.Write(BaseClass.m_RootDirectory + "/WFActivitys/" + newValue2 + ".cs", content);
         string str2 = "    <Compile Include=@Framework@ />\r\n            ".Replace('@', '"');
         stringBuilder2.Append(str2.Replace("Framework", newValue2 + ".cs"));
       }
       stringBuilder2.Append(oldValue);
       string path = BaseClass.m_RootDirectory + "/WFActivitys/WFActivitys.csproj";
       Common.Write(path, Common.Read(path).Replace(oldValue, stringBuilder2.ToString()).Replace("<RootNamespace>WFActivitys</RootNamespace>", "<RootNamespace>" + replaceClass.NameSpace + "WFActivitys</RootNamespace>"));
       stringBuilder2.Clear();
     }
   }
 }
        public static void extract_all_resources_to_relative_directory(IFileSystem fileSystem, IAssembly assembly, string directoryPath, IList<string> relativeDirectories, string resourcesToInclude, bool overwriteExisting = false, bool logOutput = false)
        {
            var resourceString = new StringBuilder();
            foreach (var resourceName in assembly.GetManifestResourceNames())
            {
                if (!resourceName.StartsWith(resourcesToInclude))
                {
                    continue;
                }
                resourceString.Clear();
                resourceString.Append(resourceName);

                //var fileExtensionLocation = resourceName.LastIndexOf('.');
                //resourceString.Remove(fileExtensionLocation, resourceString.Length - fileExtensionLocation);
                resourceString.Replace(resourcesToInclude + ".", "");
                foreach (var directory in relativeDirectories)
                {
                    resourceString.Replace("{0}".format_with(directory), "{0}{1}".format_with(directory, fileSystem.get_path_directory_separator_char()));
                }

                // replacing \. with \
                resourceString.Replace("{0}.".format_with(fileSystem.get_path_directory_separator_char()), "{0}".format_with(fileSystem.get_path_directory_separator_char()));

                var fileLocation = resourceString.ToString();
                //var fileLocation = fileSystem.combine_paths("", resourceString.ToString().Split('.')) + resourceName.Substring(fileExtensionLocation);

                var filePath = fileSystem.combine_paths(directoryPath, fileLocation);
                if (logOutput) "chocolatey".Log().Debug("Unpacking {0} to '{1}'".format_with(fileLocation,filePath));
                extract_binary_file_from_assembly(fileSystem, assembly, resourceName, filePath, overwriteExisting);
            }
        }
        public IEnumerable<string> GetEdgesCsv(IEnumerable<OnergeDetay> onergeDetays)
        {
            // SOURCE_NODE_TYPE, SOURCE_NODE_NAME, EDGE_TYPE, TARGET_NODE_TYPE, TARGET_NODE_NAME, WEIGHT
            var quote = "\"";

            var nodes = new HashSet<string>();
            int batchCount = 1;

            var ret = new StringBuilder();

            foreach (var detay in onergeDetays)
            {
                if (nodes.Count + 3 >= batchCount * 500)
                {
                    yield return ret.ToString();

                    batchCount++;
                    ret.Clear();
                }

                ret.AppendFormat("{0}, {1}, {2}, {3}, {4}, {5}\n", "Milletvekili", detay.OnergeninSahibi, "UYE", "Parti", detay.Parti, 1);
                ret.AppendFormat("{0}, {1}, {2}, {3}, {4}, {5}\n", "Milletvekili", detay.OnergeninSahibi, "SAHIP", "Soru Önergesi", detay.EsasNumarasi, 1);
                ret.AppendFormat("{0}, {1}, {2}, {3}, {4}, {5}\n", "Soru Önergesi", quote + detay.EsasNumarasi + quote, "MUHATAP", "Bakan", quote + detay.OnergeninMuhatabi + quote, 1);

                nodes.Add(detay.OnergeninSahibi);
                nodes.Add(detay.Parti);
                nodes.Add(detay.EsasNumarasi);
                nodes.Add(detay.OnergeninMuhatabi);
            }

            yield return ret.ToString();
        }
        public void ParseFile(string fileName)
        {
            using (StreamReader stream = File.OpenText(fileName))
            {
                var sb = new StringBuilder();

                while (!stream.EndOfStream)
                {
                    string line = stream.ReadLine();

                    if (line != Separator)
                    {
                        sb.AppendLine(line);
                    }
                    else
                    {
                        var highlight = new Highlight(sb.ToString());
                        highlight.Parse();
                        _highlights.Add(highlight);

                        sb.Clear();
                    }
                }
            }
        }
Example #29
0
        public static IEnumerable<LogEntry> ParseLogLines(IEnumerable<string> lines)
        {
            var multilineMessage = new StringBuilder();

            LogEntry currentEntry = null;
            foreach (string line in lines)
            {
                LogEntry nextEntry = LogEntry.Parse(line);
                if (nextEntry != null)
                {
                    if (currentEntry != null)
                    {
                        if (multilineMessage.Length > 0)
                        {
                            currentEntry.Message = multilineMessage.ToString();
                            multilineMessage.Clear();
                        }

                        yield return currentEntry;
                    }
                    currentEntry = nextEntry;
                }
                else
                {
                    if (currentEntry != null)
                    {
                        if (multilineMessage.Length == 0)
                        {
                            multilineMessage.Append(currentEntry.Message);
                        }

                        multilineMessage.AppendLine(line);
                    }
                }
            }

            if (currentEntry != null)
            {
                if (multilineMessage.Length > 0)
                {
                    currentEntry.Message = multilineMessage.ToString();
                    multilineMessage.Clear();
                }

                yield return currentEntry;
            }
        }
Example #30
0
 /// <summary>
 ///     Fired by the item destroyer event prefab after items are destroyed.
 /// </summary>
 /// <returns>
 ///     The <see cref="string" />.
 /// </returns>
 protected override string OnPreDestroyItems()
 {
     var _floodPrompt = new StringBuilder();
     _floodPrompt.Clear();
     _floodPrompt.AppendLine("Severe hail storm");
     _floodPrompt.Append("results in");
     return _floodPrompt.ToString();
 }