Exemple #1
0
 public static void RemovedCallback(String k, Object v, CacheItemRemovedReason r)
 {
     try
     {
         EventLogEntry entry = v as EventLogEntry;
         if (entry != null && entry.AddTime != entry.LastUpdateTime.Value)
         {
             CommConfig config = CommConfig.GetConfig();
             CommonDataProvider.Instance().WriteEventLogEntry(entry);
         }
     }
     catch { }
 }
 /// <summary>
 ///从配置文件加载默认数据库访问提供者类
 /// </summary>
 private static void LoadDefaultProviders()
 {
     if (_defaultprovider == null)
     {
         lock (_lock)
         {
             if (_defaultprovider == null)
             {
                 CommConfig config       = CommConfig.GetConfig();
                 Provider   dataProvider = (Provider)config.Providers[GlobalKey.DEFAULT_PROVDIER_COMMON];
                 _defaultprovider = DataProvider.Instance(dataProvider) as CommonDataProvider;
             }
         }
     }
 }
Exemple #3
0
        public static void Write(EventLogEntry entry)
        {
            try
            {
                if (entry.ApplicationType != ApplicationType.NoSet && (entry.EventType == EventType.Information || entry.EventType == EventType.Debug))
                {
                    entry.Uniquekey = "";
                    CommConfig config = CommConfig.GetConfig();
                    CommonDataProvider.Instance().WriteEventLogEntry(entry);
                    return;
                }
                string key = string.Empty;
                if (entry.EventType == EventType.Warning)
                {
                    key = GlobalKey.EVENTLOG_KEY + "_" + string.Format("{0}-{1}-{2}-{3}-{4}", entry.ApplicationID, entry.EntryID, entry.EventID, (int)entry.EventType, entry.Message.GetHashCode());
                }
                else if (entry.EventType == EventType.Error && entry.Ex != null)
                {
                    key           = GlobalKey.EVENTLOG_KEY + "_" + string.Format("{0}-{1}-{2}-{3}-{4}-{5}", entry.ApplicationID, entry.EntryID, entry.EventID, (int)entry.EventType, entry.Ex.StackTrace.GetHashCode(), entry.Ex.Message.GetHashCode());
                    entry.Message = entry.Ex.Message + "-" + entry.Ex.StackTrace + "\r\n" + entry.Message;
                }
                else
                {
                    key = GlobalKey.EVENTLOG_KEY + "_" + string.Format("{0}-{1}", (int)entry.EventType, entry.Message.GetHashCode());
                }

                EventLogEntry oldentry = MangaCache.Get(key) as EventLogEntry;

                if (oldentry != null)
                {
                    oldentry.PCount++;
                    oldentry.LastUpdateTime = DateTime.Now;
                }
                else
                {
                    DateTime time = DateTime.Now;
                    entry.PCount         = 1;
                    entry.Uniquekey      = key;
                    entry.AddTime        = time;
                    entry.LastUpdateTime = time;
                    CommConfig config = CommConfig.GetConfig();
                    CommonDataProvider.Instance().WriteEventLogEntry(entry);
                    entry.PCount = 0;
                    MangaCache.Add(key, entry, 30, TimeSpan.Zero, System.Web.Caching.CacheItemPriority.AboveNormal, new CacheItemRemovedCallback(RemovedCallback));
                }
            }
            catch { }
        }
Exemple #4
0
        /// <summary>
        /// 加载具体实现类需要的参数
        /// </summary>
        /// <param name="dataProvider">数据提供信息类</param>
        /// <param name="connectionString">连接字符串名</param>
        /// <param name="databaseOwner">数据库所有者</param>
        private static void GetDataStoreParameters(Provider dataProvider, out string connectionString, out string databaseOwner)
        {
            databaseOwner = dataProvider.Attributes["databaseOwner"];
            CommConfig config = CommConfig.GetConfig();

            if (databaseOwner == null || databaseOwner.Trim().Length == 0)
            {
                databaseOwner = config.AppSetting[dataProvider.Attributes["databaseOwnerStringName"]];//数据库所有者
            }

            connectionString = dataProvider.Attributes["connectionString"];
            if (connectionString == null || connectionString.Trim().Length == 0)
            {
                connectionString = config.AppSetting[dataProvider.Attributes["connectionStringName"]];//数据库连接字符串名
            }
        }
Exemple #5
0
        public static void JobWrite(string message, int eventID, int appid, EventType etype)
        {
            EventLogEntry entry = new EventLogEntry();

            entry.Message       = message;
            entry.Category      = "Job";
            entry.EventID       = eventID;
            entry.EventType     = etype;
            entry.EventDate     = DateTime.Now;
            entry.ApplicationID = appid;
            if (appid > 0)
            {
                entry.ApplicationType = ApplicationType.Tools;
            }
            else
            {
                entry.ApplicationType = ApplicationType.NoSet;
            }
            entry.EntryID = 0;
            if (string.IsNullOrEmpty(entry.MachineName))
            {
                entry.MachineName = Environment.MachineName;
            }
            if (!string.IsNullOrEmpty(entry.Message))
            {
                entry.Message = WebHelper.HtmlEncode(entry.Message);
            }
            CommConfig config = CommConfig.GetConfig();

            if (!string.IsNullOrEmpty(config.AppSetting["ApplicationName"]))
            {
                entry.ApplicationName = config.AppSetting["ApplicationName"];
            }
            if (!string.IsNullOrEmpty(config.AppSetting["ApplicationID"]))
            {
                entry.ApplicationID = DataConvert.SafeInt(config.AppSetting["ApplicationID"]);
            }
            Write(entry);
        }
        /// <summary>
        /// 从配置文件加载数据库访问提供者类
        /// </summary>
        /// <param name="providerName">提供者名</param>
        /// <returns>漫画提供者</returns>
        public static CommonDataProvider Instance(string providerName)
        {
            string             cachekey = GlobalKey.PROVIDER + "_" + providerName;
            CommonDataProvider objType  = MangaCache.GetLocal(cachekey) as CommonDataProvider;//从缓存读取

            if (objType == null)
            {
                CommConfig config       = CommConfig.GetConfig();
                Provider   dataProvider = (Provider)config.Providers[providerName];
                objType = DataProvider.Instance(dataProvider) as CommonDataProvider;
                string      path    = null;
                HttpContext context = HttpContext.Current;
                if (context != null)
                {
                    path = context.Server.MapPath("~/config/common.config");
                }
                else
                {
                    path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"config\common.config");
                }
                MangaCache.MaxLocalWithFile(cachekey, objType, path);
            }
            return(objType);
        }
Exemple #7
0
        /// <summary>
        /// 查找并开始执行任务,已经存在的任务停止
        /// </summary>
        public void Start()
        {
            if (jobList.Count != 0)
            {
                return;
            }
            CommConfig config = CommConfig.GetConfig();

            if (!config.IsDisableBackgroundThreads)
            {
                XmlNode node = config.GetConfigSection("common/jobs");
                if (node == null)
                {
                    return;
                }
                bool         isSingleThread        = true;//是否单线程运行
                XmlAttribute singleThreadAttribute = node.Attributes["singleThread"];
                if (singleThreadAttribute != null && !string.IsNullOrEmpty(singleThreadAttribute.Value) && string.Compare(singleThreadAttribute.Value, "false", true) == 0)
                {
                    isSingleThread = false;
                }
                else
                {
                    isSingleThread = true;
                    XmlAttribute millisecond = node.Attributes["millisecond"];
                    if (millisecond != null && !string.IsNullOrEmpty(millisecond.Value))
                    {
                        try
                        {
                            Interval = Int32.Parse(millisecond.Value);
                        }
                        catch
                        {
                            Interval = -1;
                        }
                    }
                    XmlAttribute seconds = node.Attributes["seconds"];
                    if (Interval < 0 && seconds != null && !string.IsNullOrEmpty(seconds.Value))
                    {
                        try
                        {
                            Interval = Int32.Parse(seconds.Value) * 1000;
                        }
                        catch
                        {
                            Interval = -1;
                        }
                    }
                    XmlAttribute minutes = node.Attributes["minutes"];
                    if (Interval < 0 && minutes != null && !string.IsNullOrEmpty(minutes.Value))
                    {
                        try
                        {
                            Interval = Int32.Parse(minutes.Value) * 60000;
                        }
                        catch
                        {
                            Interval = 15 * 60000;
                        }
                    }
                    if (Interval == -1)
                    {
                        Interval = 15 * 60000;
                    }
                }

                //创建任务
                foreach (XmlNode jnode in node.ChildNodes)
                {
                    if (jnode.NodeType != XmlNodeType.Comment)
                    {
                        XmlAttribute typeAttribute = jnode.Attributes["type"];
                        XmlAttribute nameAttribute = jnode.Attributes["name"];

                        Type type = Type.GetType(typeAttribute.Value);
                        if (type != null)
                        {
                            if (!jobList.Contains(nameAttribute.Value))
                            {
                                Job j = new Job(type, jnode);
                                jobList[nameAttribute.Value] = j;
                                if (!isSingleThread || !j.SingleThreaded)//多个线程运行任务
                                {
                                    j.PostJob += new EventHandler(PostJob);
                                    j.InitializeTimer();
                                }
                            }
                        }
                    }
                }
                if (isSingleThread)
                {
                    //如果是单线程运行则创建单个定时器运行任务
                    singleTimer = new Timer(new TimerCallback(call_back), null, Interval, Interval);
                }
            }
        }