void HandleSchedules(GXAmiSchedule schedule, GXEventsItem e) { ulong mask = (ulong)((int)e.Target << 16 | (int)e.Action); //Find is anyone interested from this data collector event. foreach (GXSession it in Sessions) { foreach (GXEvent e1 in it.NotifyClients) { if (e1.UserID != 0 && (mask & e1.Mask) != 0) { //Notify only super admin or if user has access to this data collector. if (e1.SuperAdmin)//TODO: || GXDeviceGroupService.CanUserAccessDeviceGroup(Db, e1.UserID, group.Id)) { e1.Rows.Add(e); it.Received.Set(); } } /* TODO: * //Notify DC that Schedule is added. * else if (e.Action == Actions.Edit && e.Target == ActionTargets.Trace && * e1.DataCollectorGuid == schedule.datac) * { * e1.Rows.Add(e); * it.Received.Set(); * } * */ } } }
void HandleDataCollectors(IDbConnection Db, Guid guid, GXEventsItem e) { ulong mask = (ulong)((int)e.Target << 16 | (int)e.Action); //Find is anyone interested from this data collector event. lock (Db) { foreach (GXSession it in Sessions) { foreach (GXEvent e1 in it.NotifyClients) { if (e1.UserID != 0 && (mask & e1.Mask) != 0) { //Notify only super admin or if user has access to this data collector. if (e1.SuperAdmin)//TODO: || GXDeviceGroupService.CanUserAccessDeviceGroup(Db, e1.UserID, group.Id)) { e1.Rows.Add(e); it.Received.Set(); } } //Notify DC that trace state is change. else if (e.Action == Actions.Edit && e.Target == ActionTargets.Trace && e1.DataCollectorGuid == guid) { e1.Rows.Add(e); it.Received.Set(); } } } } }
void HandleDevice(IDbConnection Db, ulong deviceId, GXEventsItem e) { ulong mask = (ulong)((int)e.Target << 16 | (int)e.Action); //Find is anyone interested from this device event. lock (Db) { foreach (GXSession it in Sessions) { foreach (GXEvent e1 in it.NotifyClients) { if (e1.UserID != 0 && (mask & e1.Mask) != 0) { //Notify only super admin and if user has access to this device. if (e1.SuperAdmin || GXDeviceService.CanUserAccessDevice(Db, e1.UserID, deviceId)) { e1.Rows.Add(e); it.Received.Set(); } } else if (e1.DataCollectorGuid != Guid.Empty && GXDataCollectorService.CanDataCollectorsAccessDevice(Db, deviceId, e1.DataCollectorGuid)) { e1.Rows.Add(e); it.Received.Set(); } } } } }
/// <summary> /// Notify from new device profile. /// </summary> /// <param name="Db"></param> /// <param name="template"></param> /// <param name="e"></param> void HandleDeviceProfiles(GXAmiDeviceProfile template, GXEventsItem e) { ulong mask = (ulong)((int)e.Target << 16 | (int)e.Action); //Find is anyone interested from this device template event. foreach (GXSession it in Sessions) { foreach (GXEvent e1 in it.NotifyClients) { if (e1.UserID != 0 && (mask & e1.Mask) != 0) { //Notify only super admin from new templates. if (e1.SuperAdmin) { e1.Rows.Add(e); it.Received.Set(); } } } } }
void HandleUser(GXAmiUser user, GXEventsItem e) { ulong mask = (ulong)((int)e.Target << 16 | (int)e.Action); //Find is anyone interested from this user event. foreach (GXSession it in Sessions) { foreach (GXEvent e1 in it.NotifyClients) { if (e1.UserID != 0 && (mask & e1.Mask) != 0) { //Notify only super admin and user from the task. if (e1.SuperAdmin || e1.UserID == user.Id) { e1.Rows.Add(e); it.Received.Set(); } } } } }
void HandleTableValuesUpdated(IDbConnection Db, GXAmiDataRow[] value, GXEventsItem e) { ulong mask = (ulong)((int)e.Target << 16 | (int)e.Action); //Find is anyone interested from this user event. foreach (GXSession it in Sessions) { foreach (GXEvent e1 in it.NotifyClients) { if (e1.UserID != 0 && (mask & e1.Mask) != 0) { //Notify only super admin device owners if (e1.SuperAdmin)//TODO: || e1.UserID == user.Id) { e1.Rows.Add(e); it.Received.Set(); } } } } }
void HandleDeviceErrors(IDbConnection Db, GXAmiDeviceError error, GXEventsItem e) { ulong mask = (ulong)((int)e.Target << 16 | (int)e.Action); //Find is anyone interested from this data collector event. lock (Db) { foreach (GXSession it in Sessions) { foreach (GXEvent e1 in it.NotifyClients) { if (e1.UserID != 0 && (mask & e1.Mask) != 0) { //Notify only super admin or if user has access to this data collector. if (e1.SuperAdmin || GXDeviceService.CanUserAccessDevice(Db, e1.UserID, error.TargetDeviceID.Value)) { e1.Rows.Add(e); it.Received.Set(); } } } } } }
void HandleDeviceGroup(IDbConnection Db, GXAmiDeviceGroup group, GXEventsItem e) { ulong mask = (ulong)((int)e.Target << 16 | (int)e.Action); //Find is anyone interested from this device group event. lock (Db) { foreach (GXSession it in Sessions) { foreach (GXEvent e1 in it.NotifyClients) { if (e1.UserID != 0 && (mask & e1.Mask) != 0) { //Notify only super admin and if user has access to this device group. if (e1.SuperAdmin || GXDeviceGroupService.CanUserAccessDeviceGroup(Db, e1.UserID, group.Id)) { e1.Rows.Add(e); it.Received.Set(); } } } } } }
/// <summary> /// Notify from new device tasks. /// </summary> /// <param name="Db"></param> /// <param name="task"></param> /// <param name="e"></param> void HandleTasks(IDbConnection Db, GXAmiTask task, GXEventsItem e) { ulong mask = (ulong)((int)e.Target << 16 | (int)e.Action); lock (Db) { if (task.State == TaskState.Pending) { GXAmiTaskLog it = new GXAmiTaskLog(task); Db.Insert <GXAmiTaskLog>(it); it.Id = (ulong)Db.GetLastInsertId(); if (it.Data != null) { foreach (string value in GXTaskService.SplitByLength(it.Data, 255)) { GXAmiTaskLogData d = new GXAmiTaskLogData(); d.TaskId = it.Id; d.Data = value; Db.Insert(d); } } } //DC is claimed the task. else if (task.State == TaskState.Processing) { GXAmiTaskLog it = Db.GetById <GXAmiTaskLog>(task.Id); it.ClaimTime = task.ClaimTime; Db.UpdateOnly(it, p => p.ClaimTime, q => q.Id == task.Id); } else //Task is finished (succeeded or failed) { GXAmiTaskLog it = Db.GetById <GXAmiTaskLog>(task.Id); it.FinishTime = DateTime.Now.ToUniversalTime(); Db.UpdateOnly(it, p => p.FinishTime, q => q.Id == task.Id); } } foreach (GXSession it in Sessions) { foreach (GXEvent e1 in it.NotifyClients) { if ((mask & e1.Mask) != 0) { //Do not notify task sender. if (task.State == TaskState.Pending && e1.Instance == task.Instance) { continue; } //Do not notify sender DC. if (task.State == TaskState.Processing && e1.DataCollectorGuid == task.DataCollectorGuid) { continue; } //Do not notify other DCs for task success or fail. if ((task.State == TaskState.Succeeded || task.State == TaskState.Failed || task.State == TaskState.Timeout) && e1.DataCollectorGuid != Guid.Empty && e1.DataCollectorGuid != task.DataCollectorGuid) { continue; } //Notify only super admin, user and DC from the task. if (e1.SuperAdmin || (e1.UserID != 0 && e1.UserID == task.UserID) || e1.DataCollectorGuid == task.DataCollectorGuid || //If device is read notify DCs that owns the device. IsDeviceConnectedToDC(Db, task, e1.DataCollectorGuid)) { if (e1.DataCollectorGuid != Guid.Empty) { System.Diagnostics.Debug.WriteLine("Server notifies: " + task.TaskType.ToString() + " " + task.State.ToString() + " DC: " + e1.DataCollectorGuid.ToString()); } e1.Rows.Add(e); it.Received.Set(); } } } } }