Example #1
0
 /// <summary>
 /// Extends Insert action with the ability to set insertion point through some marker.
 /// Given string is inserted AFTER first marker in the target string.
 /// <para>N.B.: Default Insert().After() is equivalent of Insert().After().From(The.Beginning)</para>
 /// </summary>
 /// <param name="marker">Marker value for insertion point.</param>
 public static InsertStringAfter After(this InsertString source, string marker)
 {
     return(new InsertStringAfter(source, marker));
 }
Example #2
0
 /// <summary>
 /// Extends Insert action with the ability to set insertion point through the marker.
 /// Given string is inserted BEFORE first marker in the target string.
 /// <para>N.B.: Default Insert().Before() is equivalent of Insert().Before().From(The.Beginning)</para>
 /// </summary>
 /// <param name="marker">Marker value for insertion point.</param>
 public static InsertStringBefore Before(this InsertString source, string marker)
 {
     return(new InsertStringBefore(source, marker));
 }
Example #3
0
 /// <summary>
 /// Extends Insert action with the ability to set insertion point through occurrence of the marker.
 /// Given string is inserted right BEFORE the marker.
 /// </summary>
 /// <param name="occurrence">Marker occurrence value for insertion point.</param>
 /// <param name="of">Marker value for insertion point.</param>
 public static InsertStringBeforeOccurrence Before(this InsertString source, int occurrence, string of)
 {
     return(new InsertStringBeforeOccurrence(source, occurrence, of));
 }
Example #4
0
 /// <summary>
 /// Extends Insert action with the ability to change position of insertion.
 /// <para>N.B.: Default Insert().At() is equivalent of Insert().At().From(The.Beginning)</para>
 /// </summary>
 /// <param name="source">Target string for insertion.</param>
 /// <param name="position">Position in string for insertion.</param>
 public static InsertStringAt At(this InsertString source, int position)
 {
     return(new InsertStringAt(source, position));
 }
Example #5
0
 /// <summary>
 /// Extends Insert action with the ability to change place of insertion.
 /// </summary>
 /// <param name="source">Target string for insertion.</param>
 /// <param name="position">
 /// Position in source string for insertion. Beginning or End value can be used.
 /// </param>
 /// <exception cref="System.ArgumentOutOfRangeException">Thrown when StartOf or EndOf position value is used.</exception>
 public static InsertStringTo To(this InsertString source, The position)
 {
     return(new InsertStringTo(source, position));
 }
Example #6
0
 /// <summary>
 /// Extends Insert action with the ability to set insertion point through occurrence of the marker.
 /// Given string is inserted right AFTER the marker.
 /// </summary>
 /// <param name="occurrence">Marker occurrence value for insertion point.</param>
 /// <param name="of">Marker value for insertion point.</param>
 public static InsertStringAfterOccurrence After(this InsertString source, int occurrence, string of)
 {
     return(new InsertStringAfterOccurrence(source, occurrence, of));
 }
Example #7
0
        private void Update(EvaluationContext context)
        {
            var maxLength     = MaxLength.GetValue(context);
            var stringBuilder = InputBuffer.GetValue(context);
            var lastIndex     = _index;

            if (maxLength <= 0)
            {
                Result.Value = String.Empty;
                return;
            }

            if (!InputBuffer.IsConnected || stringBuilder == null)
            {
                stringBuilder = _fallbackBuffer;
            }

            if (ClearTrigger.GetValue(context))
            {
                stringBuilder.Clear();
                _index = 0;
            }

            //var mode = (Modes)WriteMode.GetValue(context);

            try
            {
                if (Insert.GetValue(context))
                {
                    if (TriggerRandomPos.GetValue(context))
                    {
                        _index = (int)_random.NextLong(0, stringBuilder.Length);
                    }

                    var separator = Separator.GetValue(context);;
                    if (!string.IsNullOrEmpty(separator))
                    {
                        separator = separator.Replace("\\n", "\n");
                    }

                    var str           = InsertString.GetValue(context);
                    var insertString  = str + separator;
                    var insertLength  = insertString.Length;
                    var currentLength = stringBuilder.Length;
                    var lineWrap      = (WrapLinesModes)WrapLines.GetValue(context);
                    var mode          = (Modes)WriteMode.GetValue(context);

                    if (_index > maxLength)
                    {
                        _index = 0;
                    }

                    var pos = _index;
                    if (pos + insertLength > maxLength)
                    {
                        insertLength = maxLength - pos;
                    }

                    if (mode != Modes.Insert && pos < currentLength - insertLength)
                    {
                        stringBuilder.Remove(pos, insertLength);
                    }

                    if (pos > currentLength)
                    {
                        var fillString = FillCharacter.GetValue(context);
                        var fillChar   = string.IsNullOrEmpty(fillString) ?  '_' : fillString[0];
                        stringBuilder.Append(new string(fillChar, pos - currentLength));
                    }

                    stringBuilder.Insert(pos, insertString);

                    InsertLineWraps(lineWrap, stringBuilder, pos, insertLength, WrapLineColumn.GetValue(context).Clamp(1, 1000));
                    switch (mode)
                    {
                    case Modes.Insert:
                    {
                        _index += insertLength;
                        break;
                    }

                    case Modes.Overwrite:
                    {
                        _index += insertLength;
                        _index %= maxLength;
                        break;
                    }

                    case Modes.OverwriteAtFixedOffset:
                        _index += FillOffset.GetValue(context);
                        if (_index > maxLength)
                        {
                            _index = _index % maxLength;
                        }
                        else if (_index < 0)
                        {
                            _index += maxLength - insertLength;
                        }

                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }


                    //InsertLineWraps(lineWrap, stringBuilder);

                    if (stringBuilder.Length > maxLength)
                    {
                        stringBuilder.Length = maxLength;
                    }
                }
            }
            catch (Exception e)
            {
                Log.Warning($"Failed to manipulate string at index {_index} " + e.Message);
            }

            //

            Builder.Value = stringBuilder;
            Result.Value  = stringBuilder.ToString();
        }
Example #8
0
        static void ExtractDataToTXT(string FileName)
        {
            string line;
            int    counter   = 0;
            bool   FoundData = false;
            string InsertString;
            string InsertIntoString = string.Empty;
            string ParsedLine       = string.Empty;
            string DataLine         = string.Empty;
            // Read the file and display it line by line.
            StreamReader file = new System.IO.StreamReader(FileName);

            using (SqlConnection conn = new SqlConnection(SQLConnectionString))
            {
                conn.Open();
                while ((line = file.ReadLine()) != null)
                {
                    if (line.IndexOf("VALUES (") > -1)
                    {
                        FoundData        = true;
                        InsertIntoString = line.Substring(0, line.IndexOf("VALUES (") + 7).Replace("`", "");
                        line             = line.Substring(line.IndexOf("VALUES (") + 7);
                    }

                    if ((FoundData) && (line.IndexOf(",") > -1))
                    {
                        InsertString = line.Replace("`", "");
                        InsertString = InsertString.Replace("\\'", "''");
                        while (InsertString.Length > 0)
                        {
                            // Break into a smaller batch of 500 items
                            int currIndexLoc = 0;
                            for (int rowCounter = 0; rowCounter < 500; rowCounter++)
                            {
                                counter++;
                                currIndexLoc = InsertString.IndexOf("),(", currIndexLoc + 1);
                            }

                            if (counter == 1963500)
                            {
                                Console.Write("aa");
                            }

                            string query = InsertIntoString;
                            if (currIndexLoc > -1)
                            {
                                query       += InsertString.Substring(0, currIndexLoc + 1);
                                InsertString = InsertString.Substring(currIndexLoc + 2);
                            }
                            else
                            {
                                query       += InsertString;
                                InsertString = string.Empty;
                            }
                            try
                            {
                                SqlCommand cmd = new SqlCommand(query, conn);
                                cmd.ExecuteNonQuery();
                                Console.WriteLine(counter);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.Message);
                            }
                        }
                    }
                }
            }
            file.Close();
        }