public void InternalInvoke(string applicationName) { if (applicationName == IbnConst.ProductName) { UserLight prevUser, curUser; prevUser = Security.SetCurrentUser("alert", out curUser); try { //DateTime from = DateTime.UtcNow.AddHours(-1); //DateTime to = DateTime.UtcNow; ArrayList items = new ArrayList(); using (IDataReader reader = DbSchedule2.FillScheduleProcessHandlerTempItems()) { // ValueId, DateTypeName, ObjectTypeId, ObjectId, Dt, HookId, HandlerId, Params, DateValue, Lag while (reader.Read()) { items.Add(new ProcessHandlerTempItems( (int)reader["ValueId"], (int)reader["HandlerId"], (string)reader["Params"], (int)reader["HookId"], reader["ObjectId"] == DBNull.Value ? null : (int?)reader["ObjectId"], reader["ObjectUid"] == DBNull.Value ? null : (Guid?)reader["ObjectUid"], (DateTime)reader["Dt"], (DateTime)reader["DateValue"], (int)reader["Lag"])); } } foreach (ProcessHandlerTempItems item in items) { try { Schedule.ProcessHandler(item.HandlerId, item.Params, item.HookId, item.ObjectId, item.ObjectUid, item.DateValue); DbSchedule2.AddProcessedDateType(item.Id, item.HookId, item.DateValue, item.Lag); //DbSchedule2.DeleteDateTypeValue(item.Id); } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex); Log.WriteError(ex.ToString()); } } } finally { Security.SetCurrentUser(prevUser); } } }
public static void UpdateDateTypeValue(int dateTypeId, int?objectId, Guid?objectUid, DateTime dateValue) { // OR: Если дата в прошлом - она нам не нужна [4/18/2006] if (dateValue < DateTime.UtcNow) { DbSchedule2.DeleteDateTypeValue(dateTypeId, objectId, objectUid); } else { DbSchedule2.UpdateDateTypeValue(dateTypeId, objectId, objectUid, dateValue); } }
public static SubscriptionTypes GetSubscriptionType(DateTypes dateType, int UserId, int ObjectId) { SubscriptionTypes SubscriptionType = SubscriptionTypes.UNDEFINED; using (IDataReader reader = DbSchedule2.GetReminderSubscriptionPersonalForObject((int)dateType, UserId, ObjectId)) { if (reader.Read()) { SubscriptionType = (SubscriptionTypes)((int)reader["SubscriptionType"]); } } return(SubscriptionType); }
public static void UpdateReminderSubscriptionPersonalForObject(DateTypes dateType, int ObjectId, int Lag, bool IsActive) { bool WasActive = false; int HookId = -1; int OldLag = -1; using (IDataReader reader = DbSchedule2.GetReminderSubscriptionPersonalForObject((int)dateType, Security.CurrentUser.UserID, ObjectId)) { /// SubscriptionId, DateTypeId, UserId, ObjectId, Lag, IsActive, HookId, SubscriptionType if (reader.Read()) { if ((int)reader["SubscriptionType"] == (int)SubscriptionTypes.PersonalForObject) { WasActive = (bool)reader["IsActive"]; if (reader["HookId"] != DBNull.Value) { HookId = (int)reader["HookId"]; } OldLag = (int)reader["Lag"]; } } } int SubscriptionId = DbSchedule2.AddReminderSubscriptionPersonalForObject((int)dateType, Security.CurrentUser.UserID, ObjectId, Lag, IsActive); if (IsActive && !WasActive) // Activation { HookId = DbSchedule2.AddHook((int)dateType, ObjectId, Lag, (int)DateTypeHandlers.SendReminder, ((int)SubscriptionTypes.PersonalForObject).ToString()); DbSchedule2.UpdateReminderSubscriptionHookId(SubscriptionId, HookId); } else if (IsActive && WasActive && Lag != OldLag) // Lag changed { DbSchedule2.UpdateHook(HookId, Lag); } else if (!IsActive && WasActive) // Deactivation { DbSchedule2.UpdateReminderSubscriptionHookId(SubscriptionId, -1); DbSchedule2.DeleteHook(HookId); } }
private static void UpdateReminderSubscriptionGlobal(DateTypes dateType, int Lag, bool IsActive) { bool WasActive = false; int HookId = -1; int OldLag = -1; using (IDataReader reader = DbSchedule2.GetReminderSubscriptionGlobal((int)dateType)) { if (reader.Read()) { WasActive = (bool)reader["IsActive"]; if (reader["HookId"] != DBNull.Value) { HookId = (int)reader["HookId"]; } OldLag = (int)reader["Lag"]; } } int SubscriptionId = DbSchedule2.AddReminderSubscriptionGlobal((int)dateType, Lag, IsActive); if (IsActive && !WasActive) // Activation { HookId = DbSchedule2.AddHook((int)dateType, -1, Lag, (int)DateTypeHandlers.SendReminder, ((int)SubscriptionTypes.Global).ToString()); DbSchedule2.UpdateReminderSubscriptionHookId(SubscriptionId, HookId); } else if (IsActive && WasActive && Lag != OldLag) // Lag changed { DbSchedule2.UpdateHook(HookId, Lag); } else if (!IsActive && WasActive) // Deactivation { DbSchedule2.UpdateReminderSubscriptionHookId(SubscriptionId, -1); DbSchedule2.DeleteHook(HookId); } }
public static int AddDateTypeValue(int DateTypeId, int ObjectId, DateTime DateValue) { // OR: Данный метод используется только для Batch Alerts [4/18/2006] return(DbSchedule2.AddDateTypeValue(DateTypeId, ObjectId, DateValue)); }
public static void ProcessHandler(int handlerId, string argument, int hookId, int?objectId, Guid?objectUid, DateTime dateValue) { ObjectTypes objectType = ObjectTypes.UNDEFINED; DateTypes dateType = DateTypes.Undefined; if (handlerId == (int)DateTypeHandlers.SendReminder) { // Напоминать только о тех датах, которые еще не наступили. if (dateValue >= DateTime.UtcNow) { bool sendReminder = false; int userId = -1; using (IDataReader reader = DbSchedule2.GetReminderSubscriptionByHookId(hookId)) { if (reader.Read()) { sendReminder = true; if (reader["UserId"] != DBNull.Value) { userId = (int)reader["UserId"]; // O.R. [2010-04-01]: Don't process inactive user if (User.GetUserActivity(userId) != User.UserActivity.Active) { sendReminder = false; } } objectType = (ObjectTypes)reader["ObjectTypeId"]; dateType = (DateTypes)reader["DateTypeId"]; } } // Не напоминать о досрочно запущенных или досрочно завершённых объектах [2007-02-16] if (sendReminder) { sendReminder = ConfirmNotification(objectType, dateType, objectId, objectUid); } if (sendReminder) { SubscriptionTypes subscriptionType = (SubscriptionTypes)int.Parse(argument, CultureInfo.InvariantCulture); switch (subscriptionType) { case SubscriptionTypes.Global: ProcessGlobalSubscription(hookId, dateType, objectType, objectId, objectUid); break; case SubscriptionTypes.Personal: ProcessPersonalSubscription(hookId, dateType, userId, objectType, objectId, objectUid); break; case SubscriptionTypes.PersonalForObject: ProcessPersonalSubscriptionForObject(hookId, dateType, userId, objectType, objectId, objectUid); break; } } } } else if (handlerId == (int)DateTypeHandlers.RaiseSystemEvent) { bool raiseEvent = false; using (IDataReader reader = DbSchedule2.GetHook(hookId)) { if (reader.Read()) { raiseEvent = true; objectType = (ObjectTypes)reader["ObjectTypeId"]; dateType = (DateTypes)reader["DateTypeId"]; } } if (raiseEvent) { // Не уведомлять о досрочно запущенных или досрочно завершённых объектах [2008-07-29] raiseEvent = ConfirmNotification(objectType, dateType, objectId, objectUid); if (raiseEvent) { SystemEventTypes EventType = (SystemEventTypes)int.Parse(argument); if (objectId.HasValue) { SystemEvents.AddSystemEvents(EventType, objectId.Value); } else if (objectUid.HasValue) { SystemEvents.AddSystemEvents(EventType, objectUid.Value); } } if (objectType == ObjectTypes.Task) { Task.RecalculateAllStates(Task.GetProject(objectId.Value)); } else if (objectType == ObjectTypes.ToDo) { ToDo.RecalculateState(objectId.Value); } else if (objectType == ObjectTypes.CalendarEntry) { CalendarEntry.RecalculateState(objectId.Value); } } } else if (handlerId == (int)DateTypeHandlers.BatchAlert) { if (objectId.HasValue) { Alerts2.SendBatch(objectId.Value, dateValue); } } else if (handlerId == (int)DateTypeHandlers.LdapSync) { if (objectId.HasValue) { Ldap.Synchronize(objectId.Value, dateValue); } } }
public static void DeleteReminderSubscriptionPersonalForObject(DateTypes DateType, int ObjectId) { DbSchedule2.DeleteReminderSubscriptionPersonalForObject((int)DateType, Security.CurrentUser.UserID, ObjectId); }
public static void DeleteReminderSubscriptionPersonal(DateTypes DateType) { DbSchedule2.DeleteReminderSubscriptionPersonal((int)DateType, Security.CurrentUser.UserID); }
/// <summary> /// Reader returns fields: /// SubscriptionId, DateTypeId, UserId, ObjectId, Lag, IsActive, HookId, SubscriptionType /// </summary> /// <returns></returns> public static IDataReader GetReminderSubscriptionPersonalForObject(DateTypes DateType, int ObjectId) { return(DbSchedule2.GetReminderSubscriptionPersonalForObject((int)DateType, Security.CurrentUser.UserID, ObjectId)); }
/// <summary> /// Reader returns fields: /// SubscriptionId, DateTypeId, UserId, ObjectId, ObjectUid, Lag, IsActive, HookId, SubscriptionType /// </summary> /// <returns></returns> public static IDataReader GetReminderSubscriptionPersonal(DateTypes DateType) { return(DbSchedule2.GetReminderSubscriptionPersonal((int)DateType, Security.CurrentUser.UserID)); }
/// <summary> /// Reader returns fields: /// SubscriptionId, DateTypeId, UserId, ObjectId, ObjectUid, Lag, IsActive, HookId /// </summary> /// <returns></returns> public static IDataReader GetReminderSubscriptionGlobal(DateTypes DateType) { return(DbSchedule2.GetReminderSubscriptionGlobal((int)DateType)); }
public static void DeleteDateTypeValue(int dateTypeId, int?objectId, Guid?objectUid) { DbSchedule2.DeleteDateTypeValue(dateTypeId, objectId, objectUid); }
internal static void UpdateTimeline(int eventId, DateTime startDate, DateTime finishDate, bool checkAccess) { if (checkAccess) { VerifyCanUpdate(eventId); } int TimeZoneId = Security.CurrentUser.TimeZoneId; startDate = DBCommon.GetUTCDate(TimeZoneId, startDate); finishDate = DBCommon.GetUTCDate(TimeZoneId, finishDate); int projectId = -1; bool hasRecurrence = false; using (IDataReader reader = CalendarEntry.GetEvent(eventId, false)) { if (reader.Read()) { if (reader["ProjectId"] != DBNull.Value) { projectId = (int)reader["ProjectId"]; } hasRecurrence = ((int)reader["HasRecurrence"] == 1); } } // O.R. [2009-12-18] Dates for recurrent events should be chnaged in recurrence editing. if (hasRecurrence) { return; } TimeSpan ts = finishDate.Subtract(startDate); int taskTime = (int)ts.TotalMinutes; using (DbTransaction tran = DbTransaction.Begin()) { int retVal = DbCalendarEntry2.UpdateTimeline(eventId, startDate, finishDate, taskTime); if (retVal > 0) { SystemEvents.AddSystemEvents(SystemEventTypes.CalendarEntry_Updated_Timeline, eventId); if (!hasRecurrence) { if (retVal == 1 || retVal == 3) { Schedule.UpdateDateTypeValue(DateTypes.CalendarEntry_StartDate, eventId, startDate); } if (retVal == 2 || retVal == 3) { Schedule.UpdateDateTypeValue(DateTypes.CalendarEntry_FinishDate, eventId, finishDate); } } else { // O.R.[2009-09-29]: Recalculate events dates for scheduling Schedule.DeleteDateTypeValue(DateTypes.CalendarEntry_StartDate, eventId); Schedule.DeleteDateTypeValue(DateTypes.CalendarEntry_FinishDate, eventId); int ReminderInterval; Hashtable ret = CalendarEntry.GetEventInstances(eventId, out ReminderInterval); foreach (DateTime dtStart in ret.Keys) { DateTime dtEnd = (DateTime)ret[dtStart]; if (dtStart > DateTime.UtcNow && dtEnd > DateTime.UtcNow) { DbSchedule2.AddNewDateTypeValue((int)DateTypes.CalendarEntry_StartDate, eventId, dtStart); DbSchedule2.AddNewDateTypeValue((int)DateTypes.CalendarEntry_FinishDate, eventId, dtEnd); } } } // O.R: Recalculating project TaskTime if (projectId > 0) { TimeTracking.RecalculateProjectTaskTime(projectId); } } CalendarEntry.RecalculateState(eventId); tran.Commit(); } }