コード例 #1
0
        public bool Execute()
        {
            bool successful = true;
            var  tasks      = container.ResolveAll <BootstrapperTask>().OrderBy(t => t.Order).ToList();

            foreach (var task in tasks)
            {
                LocalLoggingService.Debug("AdhesiveFramework.Bootstrapper 开始执行 '{0}' ({1})", task.GetType().FullName, task.Description);
                try
                {
                    if (task.Execute() == TaskContinuation.Break)
                    {
                        LocalLoggingService.Warning("AdhesiveFramework.Bootstrapper 执行中断 '{0}' ({1})", task.GetType().FullName, task.Description);
                        successful = false;
                        break;
                    }
                }
                catch (Exception ex)
                {
                    LocalLoggingService.Error("AdhesiveFramework.Bootstrapper 执行出错 '{0}',异常信息:{1}", task.GetType().FullName, ex.ToString());
                }
            }
            ;
            return(successful);
        }
コード例 #2
0
        public static T GetConfig <T>(string fileName, T defVal)
        {
            object instance     = null;
            string fileFullName = GetConfigFileFullName(fileName);

            if (ConfigCache.TryGetValue(fileFullName, out instance))
            {
                return((T)instance);
            }
            lock (Locker)
            {
                if (ConfigCache.TryGetValue(fileFullName, out instance))
                {
                    return((T)instance);
                }
                if (!File.Exists(fileFullName))
                {
                    TryCreateConfig(fileName, defVal);
                    return(defVal);
                }
                XmlDocument doc = new XmlDocument();
                try
                {
                    doc.Load(fileFullName);
                }
                catch (Exception ex)
                {
                    string errMsg = string.Format("加载配置文件 {0} 失败!异常信息:{1}", fileFullName, ex);
                    LocalLoggingService.Error(errMsg);
                    return(defVal);
                }
                ConfigFileWatcher configFileWatcher = null;
                if (!ConfigFileWatcherCache.TryGetValue(fileFullName, out configFileWatcher))
                {
                    ConfigFileWatcherCache.Add(fileFullName, new ConfigFileWatcher(fileFullName, OnConfigChanged));
                }
                XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
                using (StringReader sr = new StringReader(doc.OuterXml))
                {
                    try
                    {
                        instance = (T)xmlSerializer.Deserialize(sr);
                        ConfigCache.Add(fileFullName, instance);
                        return((T)instance);
                    }
                    catch (Exception ex)
                    {
                        LocalLoggingService.Debug("反序列化异常,类型名称:{0},异常信息:{1}", typeof(T).Name, ex.ToString());
                        return(defVal);
                    }
                }
            }
        }
コード例 #3
0
 protected override void InternalDispose()
 {
     container.ResolveAll <BootstrapperTask>().OrderByDescending(t => t.Order).Each(task =>
     {
         try
         {
             LocalLoggingService.Debug("AdhesiveFramework.Bootstrapper 开始清理 '{0}' ({1})", task.GetType().FullName, task.Description);
             task.Dispose();
         }
         catch (Exception ex)
         {
             LocalLoggingService.Error("AdhesiveFramework.Bootstrapper 清理出错 '{0}',异常信息:{1}", task.GetType().FullName, ex.ToString());
         }
     });
 }