Beispiel #1
0
 static void EndAllStepMonitorInner()
 {
     using (ThreadLockScope.Scope(LockKey))
     {
         if (MonitorItem.MonitorStack.FixValue == MonitorItem.MonitorStack.Current)
         {
             MonitorItem.MonitorStack.FixValue.Coll();
             return;
         }
         MonitorItem.MonitorStack.Current.Coll();
         MonitorItem pre = MonitorItem.MonitorStack.Current;
         MonitorItem.MonitorStack.Current.EndMessage();
         ShowMinitor(MonitorItem.MonitorStack.Current.Title, 2);
         MonitorItem.MonitorStack.Pop();
         while (MonitorItem.MonitorStack.StackCount > 0)
         {
             MonitorItem.MonitorStack.Current.Coll(pre);
             pre = MonitorItem.MonitorStack.Current;
             MonitorItem.MonitorStack.Current.EndMessage();
             ShowMinitor(MonitorItem.MonitorStack.Current.Title, 2);
             MonitorItem.MonitorStack.Pop();
         }
         if (pre != null)
         {
             MonitorItem.MonitorStack.FixValue.Coll(pre);
         }
     }
 }
 private static byte[] TwoToThePowerOf(int n)
 {
     using (ThreadLockScope.Scope(powersOfTwo))
     {
         if (n >= powersOfTwo.Count)
         {
             for (int i = powersOfTwo.Count; i <= n; i++)
             {
                 List <byte> list = new List <byte>(powersOfTwo[i - 1]);
                 byte        num2 = 0;
                 for (int j = 0; j < list.Count; j++)
                 {
                     byte num4 = (byte)((list[j] << 1) + num2);
                     list[j] = (byte)(num4 % 10);
                     num2    = (byte)(num4 / 10);
                 }
                 if (num2 > 0)
                 {
                     list.Add(num2);
                 }
                 powersOfTwo.Add(list.ToArray());
             }
         }
         return(powersOfTwo[n]);
     }
 }
Beispiel #3
0
 /// <summary>
 /// 刷新资源检测
 /// </summary>
 public static void EndStepMonitor()
 {
     if (!LogMonitor)
     {
         return;
     }
     using (ThreadLockScope.Scope(LockKey))
     {
         if (MonitorItem.MonitorStack == null || MonitorItem.MonitorStack.Current == null)
         {
             return;
         }
         MonitorItem.MonitorStack.Current.Coll();
         if (MonitorItem.MonitorStack.StackCount == 0)
         {
             EndMonitorInner();
             return;
         }
         MonitorItem.MonitorStack.Current.EndMessage();
         ShowMinitor(MonitorItem.MonitorStack.Current.Title, 2);
         MonitorItem pre = MonitorItem.MonitorStack.Current;
         MonitorItem.MonitorStack.Pop();
         MonitorItem.MonitorStack.Current.Coll(pre);
         MonitorItem.MonitorStack.Current.Flush();
     }
 }
Beispiel #4
0
 /// <summary>
 /// 移除
 /// </summary>
 /// <param name="value"></param>
 public void Remove(T value)
 {
     using (ThreadLockScope.Scope(this))
     {
         _value?.Remove(value);
     }
 }
Beispiel #5
0
        /// <summary>
        ///   记录日志
        /// </summary>
        /// <param name="name"> 原始的消息 </param>
        /// <param name="msg"> 处理后的消息 </param>
        /// <param name="type"> 日志类型 </param>
        /// <param name="typeName"> 类型名称 </param>
        private static void RecordInner(string name, string msg, LogType type, string typeName = null)
        {
            Guid id = GetRequestId();

            if (type == LogType.None)
            {
                type = LogType.Trace;
            }
            ulong idx;

            using (ThreadLockScope.Scope(lockTooken))
            {
                idx = _id++;
            }
            Push(new RecordInfo
            {
                gID      = id,
                Index    = idx,
                Name     = name,
                Type     = type,
                Message  = msg,
                ThreadID = Thread.CurrentThread.ManagedThreadId,
                TypeName = typeName ?? TypeToString(type)
            });
        }
Beispiel #6
0
        /// <summary>
        ///   记录日志
        /// </summary>
        private void RecordTraceInner(string msg, string type = "trace")
        {
#if SILVERLIGHT
            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (!store.DirectoryExists("Log"))
                {
                    store.CreateDirectory("Log");
                }
                string ph = Path.Combine(LogPath, DateTime.Today.ToString("yyyy-MM-dd") + ".trace.log");
                using (IsolatedStorageFileStream rootFile = store.OpenFile(ph, FileMode.Append))
                {
                    StreamWriter writer = new StreamWriter(rootFile);
                    writer.Write(msg);
                    writer.Write("\n");
                    writer.Flush();
                    rootFile.Close();
                }
            }
#else
            if (!Directory.Exists(LogPath))
            {
                Directory.CreateDirectory(LogPath);
            }
            string ph = Path.Combine(LogPath, $"{DateTime.Today:yyyy-MM-dd}.{DateTime.Now.Hour / 2}.{type.Trim('.')}.log");

            using (ThreadLockScope.Scope(this))
            {
                File.AppendAllText(ph, msg + "\n", Encoding.UTF8);
            }
#endif
        }
Beispiel #7
0
        /// <summary>
        ///   构造
        /// </summary>
        /// <param name="al"> 对象 </param>
        /// <param name="name"> 对象锁的名字 </param>
        /// <param name="elimination"> 排斥的名称,即如果有这些名称的锁定将不能再次锁定 </param>
        /// <returns> 锁定范围,如果之前已锁定则为空 </returns>
        /// <remarks>
        ///   名称是大小写敏感的
        /// </remarks>
        public static AtomLockScope CreateLock(IAtomLock al, string name, params string[] elimination)
        {
            if (al.AtomLockNames == null)
            {
                al.AtomLockNames = new List <string>();
            }
            else if (al.AtomLockNames.Contains(name))
            {
                return(null);
            }
            else if (elimination != null && elimination.Length > 0)
            {
                if (elimination.Any(e => al.AtomLockNames.Contains(e)))
                {
                    return(null);
                }
            }

            using (ThreadLockScope.Scope(al))
            {
                al.AtomLockNames.Add(name);
            }
            return(new AtomLockScope
            {
                AtomLock = al,
                LockName = name
            });
        }
Beispiel #8
0
        /// <summary>
        ///   记录日志
        /// </summary>
        /// <param name="id"> 标识 </param>
        /// <param name="msg"> 消息 </param>
        /// <param name="type"> 日志类型 </param>
        /// <param name="user"> 当前操作者 </param>
        /// <param name="name"> 标识的文件后缀(如.error,则文件名可能为 20160602.error.log) </param>
        private void RecordLog(Guid id, string msg, string type, string user = null, string name = null)
        {
#if SILVERLIGHT
            XElement      xmlTree1 = new XElement("LogItem", new XElement("Date", DateTime.Now), new XElement("Type", type), new XElement("User", user), new XElement("Infomation", msg));
            StringBuilder sb       = new StringBuilder();
            StringWriter  sw       = new StringWriter(sb);
            xmlTree1.Save(sw);
            string info = sb.ToString();
            try
            {
                using (var store = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    if (!store.DirectoryExists("Log"))
                    {
                        store.CreateDirectory("Log");
                    }
                    string ph = Path.Combine("Log", DateTime.Today.ToString("yyyy-MM-dd") + ".log");
                    using (IsolatedStorageFileStream rootFile = store.OpenFile(ph, FileMode.Append))
                    {
                        StreamWriter writer = new StreamWriter(rootFile);
                        writer.Write(info.ToString());
                        writer.Flush();
                        rootFile.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                SytemDebug.WriteLine("日志记录时发生异常:\r\n{0}\r\n{1}", info, ex);
            }
#else
            string log = type == "DataBase"
                ? $@"
/*Date:{ DateTime.Now.ToString(CultureInfo.InvariantCulture)}*/
{msg}"
                : $@"
Date:{DateTime.Now.ToString(CultureInfo.InvariantCulture)}
Type:{type}
User:{user}
{msg}";
            try
            {
                if (!Directory.Exists(LogPath))
                {
                    Directory.CreateDirectory(LogPath);
                }
                string ph = Path.Combine(LogPath, $"{DateTime.Today:yyyyMMdd}.{name}.log");

                using (ThreadLockScope.Scope(this))
                {
                    File.AppendAllText(ph, log, Encoding.UTF8);
                }
            }
            catch (Exception ex)
            {
                LogRecorder.SystemTrace("日志记录:TextRecorder.RecordLog4", ex);
            }
#endif
        }
Beispiel #9
0
 /// <summary>
 /// 刷新资源检测
 /// </summary>
 static void BeginStepMonitorInner(string title)
 {
     using (ThreadLockScope.Scope(LockKey))
     {
         MonitorItem.MonitorStack.Push(new MonitorItem(title));
         ShowMinitor(title, 1);
     }
 }
Beispiel #10
0
 static void ShowMinitor(string msg)
 {
     SystemTrace(msg);
     using (ThreadLockScope.Scope(LockKey))
     {
         MonitorItem.MonitorTexter?.AppendLine(msg);
     }
 }
Beispiel #11
0
 /// <summary>
 /// 清栈
 /// </summary>
 public void Clear()
 {
     using (ThreadLockScope.Scope(this))
     {
         _value  = new List <T>();
         Current = FixValue;
     }
 }
Beispiel #12
0
 /// <summary>
 ///  当前再入栈
 /// </summary>
 /// <remarks>目的是和其它人做相同次数的入栈和出栈</remarks>
 public void PushCurrent()
 {
     using (ThreadLockScope.Scope(this))
     {
         IsEmpty = false;
         _value.Add(Current);
     }
 }
Beispiel #13
0
 /// <summary>
 /// 清栈
 /// </summary>
 public void Clear()
 {
     using (ThreadLockScope.Scope(this))
     {
         stackValues  = new List <T>();
         this.Current = this.FixValue;
     }
 }
Beispiel #14
0
 /// <summary>
 ///  当前再入栈
 /// </summary>
 /// <remarks>目的是和其它人做相同次数的入栈和出栈</remarks>
 public void PushCurrent()
 {
     using (ThreadLockScope.Scope(this))
     {
         this.IsEmpty = false;
         this.stackValues.Add(this.Current);
     }
 }
Beispiel #15
0
 /// <summary>
 ///   入栈
 /// </summary>
 /// <param name="value"> </param>
 public void Push(T value)
 {
     using (ThreadLockScope.Scope(this))
     {
         IsEmpty = false;
         _value.Add(value);
         Current = value;
     }
 }
Beispiel #16
0
 /// <summary>
 ///   入栈
 /// </summary>
 /// <param name="value"> </param>
 public void Push(T value)
 {
     using (ThreadLockScope.Scope(this))
     {
         this.IsEmpty = false;
         this.stackValues.Add(value);
         this.Current = value;
     }
 }
Beispiel #17
0
 /// <summary>
 ///   入栈
 /// </summary>
 /// <param name="value"> </param>
 public void Push(TraceStep value)
 {
     value.Start = DateTime.Now;
     using (ThreadLockScope.Scope(this))
     {
         Current.Children.Add(value);
         _value.Push(Current = value);
     }
 }
Beispiel #18
0
 /// <summary>
 ///  空入栈
 /// </summary>
 public void PushNull()
 {
     using (ThreadLockScope.Scope(this))
     {
         IsEmpty = false;
         _value.Add(default(T));
         Current = default(T);
     }
 }
Beispiel #19
0
 /// <summary>
 ///  空入栈
 /// </summary>
 public void PushNull()
 {
     using (ThreadLockScope.Scope(this))
     {
         this.IsEmpty = false;
         this.stackValues.Add(default(T));
         this.Current = default(T);
     }
 }
Beispiel #20
0
 /// <summary>
 /// 移除
 /// </summary>
 /// <param name="value"></param>
 public void Remove(T value)
 {
     using (ThreadLockScope.Scope(this))
     {
         if (_value != null)
         {
             _value.Remove(value);
         }
     }
 }
Beispiel #21
0
 /// <summary>
 /// 直接操作Stack后的更新
 /// </summary>
 public void Refresh()
 {
     using (ThreadLockScope.Scope(this))
     {
         IsEmpty = _value.Count == 0;
         Current = IsEmpty
             ? FixValue
             : _value[_value.Count - 1];
     }
 }
Beispiel #22
0
 /// <summary>
 /// 直接操作Stack后的更新
 /// </summary>
 public void Refresh()
 {
     using (ThreadLockScope.Scope(this))
     {
         this.IsEmpty = this.stackValues.Count == 0;
         this.Current = this.IsEmpty
             ? this.FixValue
             : this.stackValues[this.stackValues.Count - 1];
     }
 }
Beispiel #23
0
 /// <summary>
 /// 移除
 /// </summary>
 /// <param name="value"></param>
 public void Remove(T value)
 {
     using (ThreadLockScope.Scope(this))
     {
         if (this.stackValues != null)
         {
             this.stackValues.Remove(value);
         }
     }
 }
Beispiel #24
0
 /// <summary>
 ///   入队列
 /// </summary>
 /// <param name="info"> </param>
 private static void Push(RecordInfo info)
 {
     if (Thread.CurrentPrincipal != null)
     {
         info.User = Thread.CurrentPrincipal.Identity.Name;
     }
     using (ThreadLockScope.Scope(recordInfos))
     {
         recordInfos.Add(info);
     }
 }
Beispiel #25
0
 /// <summary>
 ///   配置固定值(只第一次调用有效果)
 /// </summary>
 /// <param name="value"> </param>
 public void SetFix(T value)
 {
     using (ThreadLockScope.Scope(this))
     {
         if (Equals(value, default(T)) || this.FixStackBottom)
         {
             return;
         }
         this.FixStackBottom = true;
         this.FixValue       = this.Current = value;
     }
 }
Beispiel #26
0
 /// <summary>
 ///   配置固定值(只第一次调用有效果)
 /// </summary>
 /// <param name="value"> </param>
 public void SetFix(T value)
 {
     using (ThreadLockScope.Scope(this))
     {
         if (FixStackBottom)
         {
             return;
         }
         FixStackBottom = true;
         FixValue       = Current = value;
     }
 }
Beispiel #27
0
 /// <summary>
 ///   出栈
 /// </summary>
 public TraceStep Pop()
 {
     using (ThreadLockScope.Scope(this))
     {
         if (_value.Count == 0)
         {
             return(FixValue);
         }
         Current.End = DateTime.Now;
         _value.Pop();
         return(Current = _value.Count == 0 ? FixValue : _value.Peek());
     }
 }
Beispiel #28
0
 /// <summary>
 ///   入栈
 /// </summary>
 /// <param name="value"> </param>
 public void Push(T value)
 {
     using (ThreadLockScope.Scope(this))
     {
         if (Equals(value, default(T)))
         {
             return;
         }
         IsEmpty = false;
         _value.Add(value);
         Current = value;
     }
 }
Beispiel #29
0
 /// <summary>
 ///   入栈
 /// </summary>
 /// <param name="value"> </param>
 public void Push(T value)
 {
     using (ThreadLockScope.Scope(this))
     {
         if (Equals(value, default(T)))
         {
             return;
         }
         this.IsEmpty = false;
         this.stackValues.Add(value);
         this.Current = value;
     }
 }
Beispiel #30
0
 /// <summary>
 ///   出栈
 /// </summary>
 public void Pop()
 {
     using (ThreadLockScope.Scope(this))
     {
         if (this.stackValues.Count == 0)
         {
             return;
         }
         this.stackValues.RemoveAt(this.stackValues.Count - 1);
         this.IsEmpty = this.stackValues.Count == 0;
         this.Current = this.IsEmpty
             ? this.FixValue
             : this.stackValues[this.stackValues.Count - 1];
     }
 }