Beispiel #1
0
        /// <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);
        }
Beispiel #2
0
        /// <summary>
        /// Обновление данных
        /// </summary>
        public override void RefreshData()
        {
            ServerLib.JTypes.Server.ResponseObjectsClass OutputList = new ServerLib.JTypes.Server.ResponseObjectsClass();
            DatabaseParameterValuesClass Params = new DatabaseParameterValuesClass();

            Params.CreateParameterValue("Token", UserSession.Login.Token);
            DatabaseTableClass ReadTable = new DatabaseTableClass
            {
                Table = (System.Data.DataTable)UserSession.Project.Database.Execute("Objects", ref Params)
            };

            foreach (System.Data.DataRow row in ReadTable.Table.Rows)
            {
                ServerLib.JTypes.Server.ResponseObjectClass Item = new ServerLib.JTypes.Server.ResponseObjectClass
                {
                    ID              = ReadTable.AsInt64(row, "ID"),
                    Name            = ReadTable.AsString(row, "NAME"),
                    Description     = ReadTable.AsString(row, "DESCRIPTION"),
                    OperationRead   = ReadTable.AsInt64(row, "OPERATION_READ") == 1,
                    OperationAdd    = ReadTable.AsInt64(row, "OPERATION_ADD") == 1,
                    OperationEdit   = ReadTable.AsInt64(row, "OPERATION_EDIT") == 1,
                    OperationDelete = ReadTable.AsInt64(row, "OPERATION_DELETE") == 1
                };

                if (ReadCollection.TryGetValue(Item.ID, out ServerLib.JTypes.Server.ResponseObjectClass 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.ResponseObjectClass> Item in ReadCollection)
            {
                bool IsExist = false;

                foreach (System.Data.DataRow row in ReadTable.Table.Rows)
                {
                    if (Item.Key == 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.ResponseObjectClass DeletingItem);
                }
            }

            if (OutputList.Items.Count > 0)
            {
                UserSession.OutputQueueAddObject(OutputList);
            }
        }
Beispiel #3
0
        /// <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);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Обновление данных
        /// </summary>
        public override void RefreshData()
        {
            ServerLib.JTypes.Server.ResponseJobsClass OutputList = new ServerLib.JTypes.Server.ResponseJobsClass();
            DatabaseParameterValuesClass Params = new DatabaseParameterValuesClass();

            Params.CreateParameterValue("Token", UserSession.Login.Token);
            DatabaseTableClass ReadTable = new DatabaseTableClass
            {
                Table = (System.Data.DataTable)UserSession.Project.Database.Execute("Jobs", ref Params)
            };

            foreach (System.Data.DataRow row in ReadTable.Table.Rows)
            {
                ServerLib.JTypes.Server.ResponseJobClass Item = new ServerLib.JTypes.Server.ResponseJobClass
                {
                    ID   = ReadTable.AsInt64(row, "ID"),
                    Name = ReadTable.AsString(row, "JOB_NAME")
                };

                if (JobsCollection.TryGetValue(Item.ID, out ServerLib.JTypes.Server.ResponseJobClass ExistItem))
                {
                    if (ExistItem.Hash != Item.Hash)
                    {
                        Item.Command = ItemCommands.edit;
                        JobsCollection.TryUpdate(Item.ID, Item, ExistItem);
                        OutputList.Jobs.Add(Item);
                    }
                }
                else
                {
                    Item.Command = ItemCommands.add;
                    JobsCollection.TryAdd(Item.ID, Item);
                    OutputList.Jobs.Add(Item);
                }
            }

            foreach (System.Collections.Generic.KeyValuePair <long, ServerLib.JTypes.Server.ResponseJobClass> Item in JobsCollection)
            {
                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.Jobs.Add(Item.Value);
                    JobsCollection.TryRemove(Item.Value.ID, out ServerLib.JTypes.Server.ResponseJobClass DeletingItem);
                }
            }

            if (OutputList.Jobs.Count > 0)
            {
                UserSession.OutputQueueAddObject(OutputList);
            }
        }