public static UserContext Login(string userName, string password, bool needToLog) { try { if (!string.IsNullOrWhiteSpace(SecurityManager.CurrentUserToken)) { SecurityManager.Logoff(SecurityManager.CurrentUserToken); } UserContext userContext = SecurityManager.SecurityProvider.Login(userName, password); if (userContext == null) { SecurityManager.SaveActivityLogForLoginFailedAction(userName, "نام کاربری یا رمز عبور نادرست"); } else { if (needToLog) { SecurityManager.SaveActivityLogForLoginAction(userName); } SecurityManager.CurrentUserToken = userContext.Token; SecurityManager.CurrentUserContext = userContext; } return(userContext); } catch (Exception ex) { EventLogHelper.Write(ExceptionManager.GetExceptionMessageWithDebugInfo(ex), EventLogEntryType.Error); throw; } }
/// <summary> /// 运行 /// </summary> public void Run() { if (running) { return; } try { if (nextRunTime < DateTime.Now) { nextRunTime = DateTime.Now.AddHours(runTimeInterval); this.configuration.Observers[this.Name].NextRunTime = nextRunTime; ServicesConfigurationView.Instance.Save(); running = true; } } catch (Exception ex) { // 发生异常是, 记录异常信息 并把运行标识为false. EventLogHelper.Write(string.Format("{0}服务发生异常信息\r\n{1}", this.Name, ex.ToString())); running = false; } }
public void Add(string key, object value) { try { if (value == null) { return; } if (this.Contains(key)) { object obj = this.GetData(key); obj = value; } else { this.cm.Insert(key, value, (CacheDependency)null, DateTime.MaxValue, System.Web.Caching.Cache.NoSlidingExpiration, CacheItemPriority.High, (CacheItemRemovedCallback)((cacheKey, expensiveObject, reason) => { if (!key.Contains("_EntityValidator__") && !key.Contains("_OperationKeys__")) { return; } EventLogHelper.Write(string.Format("{0}Cache: Key:{1}", (object)reason.ToString(), (object)key), EventLogEntryType.Warning); })); } } catch (Exception ex) { ExceptionManager.SaveException((Exception) new OMFException(string.Format("InsertCacheException: Key:{0}, message:{1}", (object)key, (object)ex.Message), ex)); } }
/// <summary></summary> public TaskWaitingItemServiceObserver(string name, string args) { this.m_Name = name; EventLogHelper.Write(string.Format("{0} 监听服务初始化。", this.Name)); this.Start(); }
/// <summary></summary> public SyncAccountStatusServiceObserver(string name, string args) { this.m_Name = name; EventLogHelper.Write(string.Format("{0} 监听服务初始化。", this.Name)); Start(); }
/// <summary></summary> public CleanUpExpiredRelationshipServiceObserver(string name, string args) { this.m_Name = name; EventLogHelper.Write(string.Format("{0} 监听服务初始化。", this.Name)); Start(); }
/// <summary>运行</summary> public void Run() { if (running) { return; } try { running = true; // 开始时间 TimeSpan beginTimeSpan = new TimeSpan(DateTime.Now.Ticks); // 发送待办 ServiceTrace.Instance.WriteLine("正在检测是否有任务需要发送。"); // 接收待办信息 IMessageObject message = queue.Receive(); if (message != null) { // 发送待办 ServiceTrace.Instance.WriteLine("正在发送任务信息。"); int count = 0; while (message != null) { if (message is TaskWorkInfo) { TasksContext.Instance.TaskService.Save((TaskWorkInfo)message); count++; } message = queue.Receive(); } // 成功发送待办 ServiceTrace.Instance.WriteLine("已成功发送【" + count + "】条任务信息。"); } this.nextRunTime = DateTime.Now.AddSeconds(this.interval); running = false; } catch (Exception ex) { // 发生异常是, 记录异常信息 并把运行标识为false. ServiceTrace.Instance.WriteLine(ex.ToString()); EventLogHelper.Write(string.Format("{0} 监听器发生异常信息\r\n{1}。", this.Name, ex)); running = false; } }
/// <summary>运行</summary> public void Run() { if (running) { return; } try { running = true; // 开始时间 TimeSpan beginTimeSpan = new TimeSpan(DateTime.Now.Ticks); // 发送待办 ServiceTrace.Instance.WriteLine("正在检测是否有定时任务需要发送。"); // 接收定时待办信息 IList <TaskWaitingItemInfo> list = TasksContext.Instance.TaskWaitingService.FindAllUnsentItems(1000); if (list.Count == 0) { ServiceTrace.Instance.WriteLine("没有需要发送的定时任务。"); } else { // 发送待办 ServiceTrace.Instance.WriteLine("正在发送定时任务信息。"); int count = 0; foreach (TaskWaitingItemInfo item in list) { TasksContext.Instance.TaskWaitingService.MoveToWorkItem(item); count++; } // 成功发送定时待办 ServiceTrace.Instance.WriteLine("已成功发送【" + count + "】条定时任务信息。"); } this.nextRunTime = DateTime.Now.AddSeconds(this.interval); running = false; } catch (Exception ex) { // 发生异常是, 记录异常信息 并把运行标识为false. ServiceTrace.Instance.WriteLine(ex.ToString()); EventLogHelper.Write(string.Format("{0} 监听器发生异常信息\r\n{1}。", this.Name, ex)); running = false; } }
static OMFFrameworkWebSection() { try { OMFFrameworkWebSection.current = ConfigurationManager.GetSection("OMF.Framework.Web") as OMFFrameworkWebSection; } catch (Exception ex) { EventLogHelper.Write(ExceptionManager.GetExceptionMessageWithDebugInfo((Exception) new OMFException("OMF.Framework.Web configuration exception", ex)), EventLogEntryType.Error); } }
/// <summary>运行</summary> public void Run() { if (running) { return; } try { running = true; // 开始时间 TimeSpan beginTimeSpan = new TimeSpan(DateTime.Now.Ticks); ServiceTrace.Instance.WriteLine("正在清理帐号与组织的过期关系信息。"); // MembershipManagement.Instance.OrganizationService.ClearupAllRelation(); ServiceTrace.Instance.WriteLine("正在清理人员与角色的过期关系信息。"); // MembershipManagement.Instance.RoleService.ClearupAllRelation(); ServiceTrace.Instance.WriteLine("正在清理人员与群组的过期关系信息。"); // MembershipManagement.Instance.GroupService.ClearupAllRelation(); ServiceTrace.Instance.WriteLine("已成功清理人员的全部过期关系信息。"); // 结束时间 TimeSpan endTimeSpan = new TimeSpan(DateTime.Now.Ticks); ServiceTrace.Instance.WriteLine(string.Format("共耗时{0}秒。", beginTimeSpan.Subtract(endTimeSpan).Duration().TotalSeconds)); // 3.设置下一次运行的时间(每隔一天) this.nextRunTime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " " + this.nextRunTime.ToString("HH:mm:00")).AddDays(1); running = false; } catch (Exception ex) { // 发生异常是, 记录异常信息 并把运行标识为false. ServiceTrace.Instance.WriteLine(ex.ToString()); EventLogHelper.Write(string.Format("{0} 监听器发生异常信息\r\n{1}。", this.Name, ex)); running = false; } }
/// <summary>运行</summary> public void Run() { if (running) { return; } try { running = true; // 开始时间 TimeSpan beginTimeSpan = new TimeSpan(DateTime.Now.Ticks); ServiceTrace.Instance.WriteLine("正在设置帐号状态。"); // 1.从组织架构获取项目信息 // IList<ProjectInfo> list = ProjectsContext.Instance.ProjectService.TryFetchNewProjectsFromMemebership(); //// 2.根据组织架构同步项目信息 //foreach (ProjectInfo item in list) //{ // ProjectsContext.Instance.ProjectService.SyncProjectFromMemebership(item.Id); //} ServiceTrace.Instance.WriteLine("已成功同步组织架构中的项目信息。"); // 结束时间 TimeSpan endTimeSpan = new TimeSpan(DateTime.Now.Ticks); ServiceTrace.Instance.WriteLine(string.Format("共耗时{0}秒。", beginTimeSpan.Subtract(endTimeSpan).Duration().TotalSeconds)); // 3.设置下一次运行的时间(每隔一天) this.nextRunTime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " " + this.nextRunTime.ToString("HH:mm:00")).AddDays(1); running = false; } catch (Exception ex) { // 发生异常是, 记录异常信息 并把运行标识为false. ServiceTrace.Instance.WriteLine(ex.ToString()); EventLogHelper.Write(string.Format("{0} 监听器发生异常信息\r\n{1}。", this.Name, ex)); running = false; } }
public void Close() { EventLogHelper.Write(string.Format("{0}服务被停止。", this.ServiceName)); foreach (Process backgroundProcess in backgroundProcesses) { if (!backgroundProcess.HasExited) { backgroundProcess.Close(); } } backgroundProcesses.Clear(); if (server != null) { server.Stop(); } }
private static void Save(ExceptionData exData) { try { foreach (IExceptionLogger exceptionLogger in ConfigurationController.ExceptionLoggers) { try { using (new TransactionScope(TransactionScopeOption.Suppress)) exceptionLogger.LogException(exData); } catch (Exception ex) { EventLogHelper.Write(ExceptionManager.GetExceptionMessageWithDebugInfo((Exception) new OMFException(string.Format("{0} exception", (object)exceptionLogger.GetType().FullName), ex)), EventLogEntryType.Error); } } } catch (Exception ex) { throw new LogManagementException("[ExceptionServiceLoggerName] failed and throw an exception", ex); } }
public void Start() { EventLogHelper.Write(string.Format("{0}服务正在启动。", this.Name)); server = new HttpServer(port, virtualPath, physicalPath, ConfigurationManager.AppSettings["staticFileFilters"], ConfigurationManager.AppSettings["directoryBrowse"] ); string processes = ConfigurationManager.AppSettings["processes"]; if (!string.IsNullOrEmpty(processes)) { string[] fileNames = processes.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string fileName in fileNames) { Console.WriteLine("正在启动后台程序:" + fileName); Process backgroundProcess = Process.Start(new ProcessStartInfo() { FileName = fileName, WindowStyle = ProcessWindowStyle.Hidden }); backgroundProcesses.Add(backgroundProcess); } } server.Start(); // 输出配置信息 KernelContext.Log.Info(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")); Console.WriteLine("Http server starting success."); Console.WriteLine("Url \t\t: http://localhost:{0}{1}", port, virtualPath); Console.WriteLine("Physical path \t: {0}", physicalPath); }
private static async Task SaveAsync(ExceptionData exData) { try { foreach (IExceptionLogger exceptionLogger in ConfigurationController.ExceptionLoggers) { IExceptionLogger exLogger = exceptionLogger; try { using (new TransactionScope(TransactionScopeOption.Suppress)) { if (exLogger is IExceptionLoggerAsync) { await((IExceptionLoggerAsync)exLogger).LogExceptionAsync(exData); } else { exLogger.LogException(exData); } } } catch (Exception ex) { OMFException dwdEx = new OMFException(string.Format("{0} exception: {1}", (object)exLogger.GetType().FullName, (object)ex.Message), exData.Exception); string message = ExceptionManager.GetExceptionMessageWithDebugInfo((Exception)dwdEx); EventLogHelper.Write(message, EventLogEntryType.Error); continue; } exLogger = (IExceptionLogger)null; } } catch (Exception ex) { throw new LogManagementException("[ExceptionServiceLoggerName] failed and throw an exception", ex); } }