Example #1
0
        internal static string Replace(string text, string find, string replace)
        {
            UtilFramework.Assert(text.Contains(find));
            string result = text.Replace(find, replace);

            return(result);
        }
Example #2
0
        /// <summary>
        /// Returns type of for example Application.AppMain" or better "Application.AppMain, Application".
        /// </summary>
        public static Type TypeFromName(string typeName)
        {
            if (!typeFromNameListCache.ContainsKey(typeName))
            {
                Type type = Type.GetType(typeName);
                typeFromNameListCache.TryAdd(typeName, type);
            }

            Type result = typeFromNameListCache[typeName];

            UtilFramework.Assert(result != null, "TypeName unknown!");
            return(result);
        }
Example #3
0
 internal static void TimeStart(string name)
 {
     if (!StopwatchList.ContainsKey(name))
     {
         StopwatchList[name] = new Item {
             Stopwatch = new Stopwatch()
         };
     }
     UtilFramework.Assert(StopwatchList[name].IsStart == false);
     StopwatchList[name].Stopwatch.Start();
     StopwatchList[name].IsStart     = true;
     StopwatchList[name].StartCount += 1;
 }
Example #4
0
        /// <summary>
        /// Search 'find' in every line. If found replace line with 'replace'.
        /// </summary>
        /// <param name="text">Text file.</param>
        /// <param name="find">Text to find in line.</param>
        /// <param name="replace">Text to replace line with.</param>
        /// <returns>Returns modified text file.</returns>
        internal static string ReplaceLine(string text, string find, string replace)
        {
            bool          isFind = false;
            StringBuilder result = new StringBuilder();

            using (var reader = new StringReader(text))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    if (line.Contains(find))
                    {
                        isFind = true;
                        line   = replace;
                    }
                    result.AppendLine(line);
                }
            }
            UtilFramework.Assert(isFind, string.Format("Text not found! ({0})", find));
            return(result.ToString());
        }
Example #5
0
        /// <summary>
        /// Bind unused stopwatch to this request.
        /// </summary>
        internal static void RequestBind()
        {
            UtilFramework.Assert(requestId.Value == Guid.Empty);
            requestId.Value = Guid.NewGuid();

            var collection = CollectionCurrent;

            collection.RequestCount += 1;
            collection.LogText.Clear();

            // Average time is calculated based on max every 10 requests.
            if (CollectionCurrent.RequestCount > 10)
            {
                CollectionCurrent.RequestCount = 1;
                foreach (var item in CollectionCurrent.List)
                {
                    item.Value.Stopwatch.Reset();
                    item.Value.StartCount = 0;
                }
            }
        }
Example #6
0
 internal static void TimeStop(string name)
 {
     UtilFramework.Assert(StopwatchList[name].IsStart == true);
     StopwatchList[name].Stopwatch.Stop();
     StopwatchList[name].IsStart = false;
 }