/// <summary>
        /// Получить параметры по имени параметров
        /// </summary>
        public static StructureValueForClient GetParamatersForClientReady(List <string> ListNameOfValue) // Для запроса по нажатию, получает уже готовый результат
        {
            StructureValueForClient StructureReturn   = new StructureValueForClient();
            PropertyInfo            propertyStructure = typeof(ValueForClient).GetProperty("ReadyStructure");                        // Получил структуру
            StructureValueForClient Structure         = (StructureValueForClient)propertyStructure.GetValue(propertyStructure.Name); // Получил значение структуры

            foreach (string name in ListNameOfValue)
            {
                PropertyInfo property = Structure.GetType().GetProperty(name);

                if (property != null)
                {
                    property.SetValue(StructureReturn, property.GetValue(Structure));
                }

                string UpdateTime_Module_         = "updateTime_Module_";
                var    updateTime_Module_property = Structure.GetType().GetField(UpdateTime_Module_ + name);

                if (updateTime_Module_property != null)
                {
                    updateTime_Module_property.SetValue(StructureReturn, updateTime_Module_property.GetValue(Structure));
                }
            }

            return(StructureReturn);
        }
Пример #2
0
        public static Tuple <StructureValueForClient, string> GetParamatersForClientReady(List <string> ListNameOfValue) // Для запроса по нажатию, получает уже готовый результат
        {
            StructureValueForClient           ReturnStruct = default;
            ProgressOfUpdateAtStructAttribute Progress     = (ProgressOfUpdateAtStructAttribute)ParentMethods.GetStandart().Clone_Full();

            Progress.NonSerializedConfig.IsInTask = false;
            Progress.NonSerializedConfig.Method   = new Action(() =>
            {
                DateTime Start = DateTime.Now;

                try
                {
                    ReturnStruct = AutoRefresh_ServerPart.GetParamatersForClientReady(ListNameOfValue);
                }
                catch (Exception ex)
                {
                    try
                    {
                        ReturnStruct = AutoRefresh_ServerPart.GetParamatersForClientReady(ListNameOfValue);
                    }
                    catch (Exception exx)
                    {
                    }
                }

                TimeSpan TimeSpend = DateTime.Now - Start;
                ReturnStruct.TimeServerOnGetProperties   = TimeSpend;
                ReturnStruct.TimeServerWhenGetProperties = DateTime.Now.TimeOfDay;
            });
            Progress.Start();

            return(new Tuple <StructureValueForClient, string>(ReturnStruct, Progress.ExceptionMessage));
        }
        /// <summary>
        /// Модуль автообновления данных клиента. Серверная часть
        /// </summary>
        public static StructureValueForClient CheckAutoRefresh(StructureValueForClient StructureValueForClient)
        {
            Dictionary <string, DateTime> CheckProperties_With_TimeLastUpdate        = StructureValueForClient.CheckProperties_With_TimeLastUpdate;
            Dictionary <string, DateTime> Return_CheckProperties_With_TimeLastUpdate = new Dictionary <string, DateTime>();

            foreach (var name in CheckProperties_With_TimeLastUpdate)
            {
                DateTime     valueNameOfTimeUpdated    = default(DateTime);
                PropertyInfo propertiNameOfTimeUpdated = default(PropertyInfo);
                propertiNameOfTimeUpdated = default(PropertyInfo);
                string NameOfTimeUpdated = "UpdateTime_Module_" + name.Key;
                propertiNameOfTimeUpdated = ValueForClient.ReadyStructure.GetType().GetProperty(NameOfTimeUpdated);
                valueNameOfTimeUpdated    = propertiNameOfTimeUpdated is null ? default(DateTime) : (DateTime)propertiNameOfTimeUpdated.GetValue(ValueForClient.ReadyStructure);

                if (valueNameOfTimeUpdated < name.Value)
                {
                    valueNameOfTimeUpdated = propertiNameOfTimeUpdated is null ? new DateTime() : (DateTime)propertiNameOfTimeUpdated.GetValue(ValueForClient.ReadyStructure);
                }

                Return_CheckProperties_With_TimeLastUpdate.Add(name.Key, valueNameOfTimeUpdated);
            }

            return(new StructureValueForClient()
            {
                CheckProperties_With_TimeLastUpdate = Return_CheckProperties_With_TimeLastUpdate
            });                                                                                                                        // Return name of modules
        }
Пример #4
0
        public static Tuple <StructureValueForClient, string> CheckAutoRefresh(StructureValueForClient StructureValueForClient)
        {
            StructureValueForClient           Text     = default;
            ProgressOfUpdateAtStructAttribute Progress = (ProgressOfUpdateAtStructAttribute)ParentMethods.GetStandart().Clone_Full();

            Progress.NonSerializedConfig.IsInTask = false;
            Progress.NonSerializedConfig.Method   = new Action(() =>
            {
                Text = AutoRefresh_ServerPart.CheckAutoRefresh(StructureValueForClient);
            });
            Progress.Start();

            return(new Tuple <StructureValueForClient, string>(Text, Progress.ExceptionMessage));
        }
        public static void Convert(DataSet dataset, StructureValueForClient structure, out byte[] bytes, out string ExceptionMessage)
        {
            byte[] local = default;
            string ExceptionMessage_Local = null;

            {
                Convert(new DataToSerialize()
                {
                    dataset = dataset, ReadyStructure = structure
                }, out local, out ExceptionMessage_Local);
            }
            bytes            = local;
            ExceptionMessage = ExceptionMessage_Local;
            bytes            = local;
        }
Пример #6
0
        public static bool Process(out StructureValueForClient StructureValueForClient, out TimeSpan TimeOnLoad, out ConnectionBackInformation ConnectionBackInformationLoad) // Process
        {
            StructureValueForClient = null;
            TimeOnLoad = default;
            ConnectionBackInformationLoad = null;

            if (ListNameOfValue is null ? false : ListNameOfValue.Count > 0)
            {
                TimeSpan StartLoad = DateTime.Now.TimeOfDay;
                Tuple <StructureValueForClient, string, string> tuple = MethodsCall.GetParamatersForClientReady(ListNameOfValue, out ConnectionBackInformationLoad);
                TimeOnLoad = DateTime.Now.TimeOfDay - StartLoad;
                Console.WriteLine("GetParamatersForClientReady, time on it: " + TimeOnLoad);

                if (ConnectionBackInformationLoad.Recieve_GetResponse)
                {
                    var Time = TimeOnLoad - ConnectionBackInformationLoad.Recieve_TimeSpend - ConnectionBackInformationLoad.Send_TimeSpend;

                    if (TimeOnLoad > TimeSpan.FromSeconds(20))
                    {
                    }

                    if (Time > TimeSpan.FromSeconds(2))
                    {
                    }
                }
                else
                {
                }

                if (!(tuple.Item1 is null))
                {
                    TimeSpan TimeServerWhenGetProperties = DateTime.Now.TimeOfDay - tuple.Item1.TimeServerWhenGetProperties;
                    TimeSpan TimeOnSentFromServer        = TimeOnLoad - TimeServerWhenGetProperties;
                }

                if (tuple.Item3 == "<Not connected>")
                {
                    Console.WriteLine("Result: <Not connected>");
                }
                else if (!(tuple.Item1 is null))
                {
                    StructureValueForClient = tuple.Item1;

                    if (!(StructureValueForClient is null))
                    {
                        return(true);
                    }
        public static Tuple <T, string, string> SetToServer <T>(StructureValueForClient result, out ConnectionBackInformation ConnectionBackInformation)
        {
            string         MethodName = MethodBase.GetCurrentMethod().Name;
            List <dynamic> SetItems   = new List <dynamic>()
            {
                result
            };
            List <dynamic> ReturnItems = new List <dynamic>()
            {
                Converter.CreateInstance <T>(), Converter.CreateInstance <string>()
            };
            Tuple <List <dynamic>, string, string> tuple = Common <T>(SetItems, ReturnItems, MethodName, out ConnectionBackInformation);

            if (tuple.Item1.Count == 0)
            {
                return(new Tuple <T, string, string>(Converter.CreateInstance <T>(), tuple.Item2, tuple.Item3));
            }
            else
            {
                return(new Tuple <T, string, string>(tuple.Item1[0], tuple.Item2, tuple.Item3));
            }
        }
        /// <summary>
        /// Запрос информации о обновленных данных
        /// </summary>
        /// <param name="InNetWorkProtocol">Задействован сетевой протокол. На случай, есль взаимодействие внутри сервера</param>
        /// <param name="IPAddress">IPAddress сервера</param>
        /// <param name="Thisport">Порт</param>
        /// <param name="Parent">Родительский объект прогресс-аспекта</param>

        public static void CheckAutoRefresh(bool InNetWorkProtocol, IPAddress IPAddress, int Thisport, out ConnectionBackInformation ConnectionBackInformation) // Метод на постоянный апдейт
        {
            ConnectionBackInformation = default;

            {
                Dictionary <string, DateTime> CheckProperties_With_TimeLastUpdate_Copy = default;

                lock (CheckProperties_With_TimeLastUpdate)  // lock на взятие коллекции
                    CheckProperties_With_TimeLastUpdate_Copy = CheckProperties_With_TimeLastUpdate.ToDictionary(x => x.Key, y => y.Value);

                if (CheckProperties_With_TimeLastUpdate_Copy.Count != 0)
                {
                    StructureValueForClient StructureValueForClient = new StructureValueForClient()
                    {
                        CheckProperties_With_TimeLastUpdate = CheckProperties_With_TimeLastUpdate_Copy
                    };
                    Dictionary <string, DateTime> dictFromServer = new Dictionary <string, DateTime>();

                    if (InNetWorkProtocol)
                    {
                        List <dynamic> SetItems = new List <dynamic>()
                        {
                            StructureValueForClient
                        };
                        List <dynamic> ReturnItems = new List <dynamic>()
                        {
                            Converter.CreateInstance <StructureValueForClient>(), Converter.CreateInstance <string>()
                        };

                        TimeSpan       StartLoad = DateTime.Now.TimeOfDay;
                        List <dynamic> returnParametersAndMessageFromSocket = ConnectToServer.CommonLayerConnection(IPAddress, Thisport, SetItems, ReturnItems, nameof(CheckAutoRefresh), out ConnectionBackInformation);
                        TimeSpan       TimeOnLoad = DateTime.Now.TimeOfDay - StartLoad;

                        if (TimeOnLoad > TimeSpan.FromSeconds(20))
                        {
                        }
                        else if (TimeOnLoad > TimeSpan.FromSeconds(10))
                        {
                        }
                        else if (TimeOnLoad > TimeSpan.FromSeconds(5))
                        {
                        }
                        else if (TimeOnLoad > TimeSpan.FromSeconds(3))
                        {
                        }

                        try
                        {
                            if (returnParametersAndMessageFromSocket.Count > 0)
                            {
                                dictFromServer = ((StructureValueForClient)returnParametersAndMessageFromSocket[0]).CheckProperties_With_TimeLastUpdate;
                            }
                            else
                            {
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                    else
                    {
                        StructureValueForClient       Struct = Server.AutoRefresh_ServerPart.CheckAutoRefresh(StructureValueForClient);
                        Dictionary <string, DateTime> returnParametersAndMessageFromSocket = Struct.CheckProperties_With_TimeLastUpdate;
                        string messageFromSocket = default;
                        dictFromServer = returnParametersAndMessageFromSocket;
                    }

                    if (dictFromServer is null ? false : dictFromServer.Count > 0)
                    {
                        lock (ListNameModuleOnServer)
                            foreach (var s in dictFromServer)
                            {
                                if (ListNameModuleOnServer.ContainsKey(s.Key))
                                {
                                    if (ListNameModuleOnServer[s.Key] != s.Value)
                                    {
                                        ListNameModuleOnServer[s.Key] = s.Value;
                                    }
                                }
                                else
                                {
                                    ListNameModuleOnServer.Add(s.Key, s.Value);
                                }
                            }
                    }
                }
            }
        }
        public bool SetToServer(object sender, EventArgs e, StructureValueForClient StructureValueForClient, out string Exception) // Event
        {
            DateTime Start           = DateTime.Now;
            bool     Done            = false;
            string   Exception_Local = null;

            Thread Thread = new Thread(() =>
            {
                try
                {
                    if (sender is null)
                    {
                        sender = new object();
                    }

                    lock (sender)
                    {
                        if (Thread.CurrentThread.Name is null)
                        {
                            Thread.CurrentThread.Name = nameof(SetToServer);
                        }

                        if (StructureValueForClient != null)
                        {
                            if (TaskManagerForm.StatusStrip.InvokeRequired)
                            {
                                TaskManagerForm.StatusStrip.Invoke(new Action(() =>
                                {
                                    TaskManagerForm.toolStripStatusLabelExport.BackColor = Color.Yellow;
                                    TaskManagerForm.toolStripStatusLabelExport.Text      = string.Format("Export: {0}", "Started");
                                }));
                            }
                            else
                            {
                                TaskManagerForm.toolStripStatusLabelExport.BackColor = Color.Yellow;
                                TaskManagerForm.toolStripStatusLabelExport.Text      = string.Format("Export: {0}", "Started");
                            }

                            DateTime Started = DateTime.Now;
                            Tuple <string, string, string> tuple1 = MethodsCall.SetToServer <string>(StructureValueForClient, out ConnectionBackInformation ConnectionBackInformation);
                            TimeSpan Time = DateTime.Now - Started;

                            if (tuple1 is null ? true : (!string.IsNullOrEmpty(tuple1.Item1) || !string.IsNullOrEmpty(tuple1.Item2) || !string.IsNullOrEmpty(tuple1.Item3)))
                            {
                                Started = DateTime.Now;
                                tuple1  = MethodsCall.SetToServer <string>(StructureValueForClient, out ConnectionBackInformation);
                                Time    = DateTime.Now - Started;
                            }

                            if (tuple1 is null ? false : !string.IsNullOrEmpty(tuple1.Item1))
                            {
                                Done            = false;
                                Exception_Local = tuple1.Item1;
                            }
                            else if (tuple1 is null ? false : !string.IsNullOrEmpty(tuple1.Item2))
                            {
                                Done            = false;
                                Exception_Local = tuple1.Item2;
                            }
                            else if (tuple1 is null ? false : !string.IsNullOrEmpty(tuple1.Item3))
                            {
                                Done            = false;
                                Exception_Local = tuple1.Item3;
                            }
 private static StructureValueForClient CommonConvert(StructureValueForClient Item, DataTable dataTable)
 {
     return(new StructureValueForClient());
 }
 private static DataTable CommonConvert(StructureValueForClient item)
 {
     return(new DataTable());
 }
 public static StructureValueForClient ConvertFrom(StructureValueForClient DefaultItem, DataTable dataTable) // DefaultItem - пустой экземпляр для динамической передачи типа/структуры данных
 {
     return(CommonConvert(DefaultItem, dataTable));
 }
Пример #13
0
        private void OnUpdate(bool Update, TimeSpan TimeFromServer, StructureValueForClient StructureValueForClient_Setted, ConnectionBackInformation ConnectionBackInformationLoad)
        {
            DateTime LastTimeUpdate = DateTime.Now;

            if (Update)
            {
                Updated = false;

                if (true) //Load
                {
                    #region Pages load
                    #region HR
                    DateTime HRStart = DateTime.Now;

                    if (tabControlMain.TabPages.Contains(tabPageHR))
                    {
                        if (StructureValueForClient_Setted.UpdateTime_Module_HR > default(DateTime))
                        {
                            if (this.StructureValueForClient is null ? true :
                                StructureValueForClient_Setted.UpdateTime_Module_HR >
                                this.StructureValueForClient.UpdateTime_Module_HR)
                            {
                                Updated = true;
                                CommonDll.Structs.F_HR.HR HR = (CommonDll.Structs.F_HR.HR)StructureValueForClient_Setted.HR.Clone();

                                if (this.InvokeRequired)
                                {
                                    this.Invoke(new Action(() =>
                                    {
                                        hR_Page1.Set(LastTimeUpdate, StructureValueForClient_Setted.UpdateTime_Module_HR, HR);
                                    }));
                                }

                                HR = null;
                            }
                        }
                    }

                    if (!(StructureValueForClient_Setted.HR is null) & !(LoadDialog is null))
                    {
                        LoadDialog.Set(nameof(StructureValueForClient_Setted.HR), DateTime.Now - HRStart);
                    }
                    #endregion

                    #region отладка сервера
                    DateTime ProgressOfUpdateStart = DateTime.Now;

                    if (this.InvokeRequired)
                    {
                        this.Invoke(new Action(() =>
                                               viewServerProcess1.LastTimeUpdate = LastTimeUpdate));
                    }
                    else
                    {
                        viewServerProcess1.LastTimeUpdate = LastTimeUpdate;
                    }

                    if (tabControlMain.TabPages.Contains(tabPage_ServerProcess))
                    {
                        if (StructureValueForClient_Setted.UpdateTime_Module_ProgressOfUpdate > default(DateTime))
                        {
                            if (this.StructureValueForClient is null ? true :
                                StructureValueForClient_Setted.UpdateTime_Module_ProgressOfUpdate >
                                this.StructureValueForClient.UpdateTime_Module_ProgressOfUpdate)
                            {
                                if (viewServerProcess1.LastTimeOnServer == default(DateTime))
                                {
                                    Updated = true;
                                    List <ProgressOfUpdateAtStructAttribute> List_ProgressOfUpdateAtStructAttribute = StructureValueForClient_Setted.ProgressOfUpdate.List_ProgressOfUpdateAtStructAttribute.Select(x => (ProgressOfUpdateAtStructAttribute)x.Clone()).ToList();

                                    if (this.InvokeRequired)
                                    {
                                        this.Invoke(new Action(() =>
                                        {
                                            viewServerProcess1.LastTimeOnServer = StructureValueForClient_Setted.UpdateTime_Module_ProgressOfUpdate;
                                            viewServerProcess1.Set(List_ProgressOfUpdateAtStructAttribute);
                                        }));
                                    }

                                    List_ProgressOfUpdateAtStructAttribute = null;
                                }
                            }
                        }
                    }

                    if (!(StructureValueForClient_Setted.ProgressOfUpdate is null) & !(LoadDialog is null))
                    {
                        LoadDialog.Set(nameof(StructureValueForClient_Setted.ProgressOfUpdate), DateTime.Now - ProgressOfUpdateStart);
                    }
                    #endregion
                    #endregion
                }

                Dictionary <string, MainParentClass> props = Helper.GetProperties <MainParentClass, StructureValueForClient>(StructureValueForClient_Setted);

                foreach (var From in props) // Обнулить не задействованные структуры.
                {
                    string Name = From.Key;
                    var    ReadyStructure_Type = StructureValueForClient_Setted.GetType();

                    if (!(ReadyStructure_Type is null))
                    {
                        var To_Property = ReadyStructure_Type.GetProperty(Name);

                        if (!(To_Property is null))
                        {
                            To_Property.SetValue(StructureValueForClient_Setted, null);
                        }
                    }
                }

                this.StructureValueForClient   = StructureValueForClient_Setted;
                StructureValueForClient_Setted = null;
                TimeSpan TimeLoadOnClient = DateTime.Now - LastTimeUpdate;

                if (Updated)
                {
                    Updated = false;
                }
                else
                {
                }

                TimeFromServer   = new TimeSpan(TimeFromServer.Hours, TimeFromServer.Minutes, TimeFromServer.Seconds);
                TimeLoadOnClient = new TimeSpan(TimeLoadOnClient.Hours, TimeLoadOnClient.Minutes, TimeLoadOnClient.Seconds);

                if (StatusStripGlobal.InvokeRequired)
                {
                    StatusStripGlobal.Invoke(new Action(() =>
                    {
                        ToolStripStatusLabel.BackColor = Color.Transparent;
                        ToolStripStatusLabel.Text      = string.Format("Load from server: {0}, on client: {1}", TimeFromServer, TimeLoadOnClient);
                    }));
                }
            }
            else
            {
                if (StatusStripGlobal.InvokeRequired)
                {
                    StatusStripGlobal.Invoke(new Action(() =>
                    {
                        ToolStripStatusLabel.BackColor = Color.Orange;
                        ToolStripStatusLabel.Text      = string.Format("Load from server: {0}, on client: {1}", "Failed", "at " + LastTimeUpdate);
                    }));
                }
            }
        }
Пример #14
0
        public static Tuple <string, string> SetToServer(StructureValueForClient Obj)
        {
            string Text = ParentMethods.SetToServer(Obj, Program.Progress);

            return(new Tuple <string, string>(null, Text));
        }