/// <summary> /// Поток обновления данных /// </summary> /// <param name="state"></param> private void RefreshDataProcessing(object state) { if (UserSession.IsAuthenticated && !IsRunning) { Thread th = new Thread(() => { try { IsRunning = true; DatabaseParameterValuesClass Param = new DatabaseParameterValuesClass(); Param.CreateParameterValue("Token", UserSession.Login.Token); Param.CreateParameterValue("UserId", UserSession.Login.ID); Param.CreateParameterValue("FirstName"); Param.CreateParameterValue("LastName"); Param.CreateParameterValue("MidleName"); Param.CreateParameterValue("Job"); Param.CreateParameterValue("Active"); Param.CreateParameterValue("State"); Param.CreateParameterValue("ErrorText"); UserSession.Project.Database.Execute("UserInformation", ref Param); if (Param.ParameterByName("State").AsString == "ok") { DatabaseParameterValuesClass Params = new DatabaseParameterValuesClass(); Params.CreateParameterValue("Token", UserSession.Login.Token); DatabaseTableClass ReadTable = new DatabaseTableClass { Table = (System.Data.DataTable)UserSession.Project.Database.Execute("UserPermissions", ref Params) }; Permissions.Clear(); foreach (System.Data.DataRow row in ReadTable.Table.Rows) { Permissions.Add(new ServerLib.JTypes.Server.ResponseUserPermissionClass { ObjectName = ReadTable.AsString(row, "OBJECT"), Operation = (ServerLib.JTypes.Enums.ObjectOperations)ReadTable.AsInt32(row, "OPERATION") }); } string OldMessage = JsonConvert.SerializeObject(this); FirstName = Param.ParameterByName("FirstName").AsString; LastName = Param.ParameterByName("LastName").AsString; MidleName = Param.ParameterByName("MidleName").AsString; JobName = Param.ParameterByName("Job").AsString; Active = Param.ParameterByName("Active").AsInt32 == 1 ? ServerLib.JTypes.Enums.UserActive.activated : ServerLib.JTypes.Enums.UserActive.blocked; State = ServerLib.JTypes.Enums.ResponseState.ok; if (JsonConvert.SerializeObject(this) != OldMessage) { UserSession.OutputQueueAddObject(this); } } } catch (Exception ex) { UserSession.Project.Log.Error(string.Format("UserInformation.RefreshDataProcessing {0}", ex.Message)); } finally { IsRunning = false; } }); th.Start(); } RefreshDataTimer.Change(5000, Timeout.Infinite); }
/// <summary> /// Обновление данных /// </summary> public override void RefreshData() { ServerLib.JTypes.Server.ResponseUsersClass OutputList = new ServerLib.JTypes.Server.ResponseUsersClass(); DatabaseParameterValuesClass Params = new DatabaseParameterValuesClass(); Params.CreateParameterValue("Token", UserSession.Login.Token); DatabaseTableClass ReadTable = new DatabaseTableClass { Table = (System.Data.DataTable)UserSession.Project.Database.Execute("Users", ref Params) }; foreach (System.Data.DataRow row in ReadTable.Table.Rows) { ServerLib.JTypes.Server.ResponseUserClass Item = new ServerLib.JTypes.Server.ResponseUserClass { ID = ReadTable.AsInt64(row, "ID"), Login = ReadTable.AsString(row, "LOGIN"), FirstName = ReadTable.AsString(row, "FIRST_NAME"), LastName = ReadTable.AsString(row, "LAST_NAME"), MidleName = ReadTable.AsString(row, "MIDLE_NAME"), JobID = ReadTable.AsInt64(row, "POSITION_ID"), JobName = ReadTable.AsString(row, "POSITION"), Active = (UserActive)ReadTable.AsInt32(row, "ACTIVE") }; if (ReadCollection.TryGetValue(Item.ID, out ServerLib.JTypes.Server.ResponseUserClass ExistItem)) { if (ExistItem.Hash != Item.Hash) { Item.Command = ItemCommands.edit; ReadCollection.TryUpdate(Item.ID, Item, ExistItem); OutputList.Items.Add(Item); } } else { Item.Command = ItemCommands.add; ReadCollection.TryAdd(Item.ID, Item); OutputList.Items.Add(Item); } } foreach (System.Collections.Generic.KeyValuePair <long, ServerLib.JTypes.Server.ResponseUserClass> Item in ReadCollection) { bool IsExist = false; foreach (System.Data.DataRow row in ReadTable.Table.Rows) { if (Item.Value.ID == ReadTable.AsInt64(row, "ID")) { IsExist = true; break; } } if (!IsExist) { Item.Value.Command = ItemCommands.delete; OutputList.Items.Add(Item.Value); ReadCollection.TryRemove(Item.Value.ID, out ServerLib.JTypes.Server.ResponseUserClass DeletingUser); } } if (OutputList.Items.Count > 0) { UserSession.OutputQueueAddObject(OutputList); } }