public static Tuple <List <dynamic>, string> CommonLayer(List <dynamic> SetItems, List <dynamic> ReturnItems, string MethodName, out ConnectionBackInformation ConnectionBackInformation)
        {
            string                    messageFromServer1 = "";
            List <dynamic>            messageFromServer  = new List <dynamic>();
            ConnectionBackInformation ConnectionBackInformation_Local = default;

            {
                if (string.IsNullOrEmpty(MethodName))
                {
                    throw new NullReferenceException(nameof(MethodName) + " is null or empty");
                }
                else
                {
                    if (ImportDesignForm.IPAddress is null)
                    {
                        throw new NullReferenceException(nameof(ImportDesignForm.IPAddress) + " is null");
                    }

                    if (ImportDesignForm.Port == default)
                    {
                        throw new NullReferenceException(nameof(ImportDesignForm.Port) + " == default");
                    }

                    List <dynamic> returnParametersAndMessageFromSocket = ConnectToServer.CommonLayerConnection(ImportDesignForm.IPAddress, ImportDesignForm.Port, SetItems, ReturnItems, MethodName, out ConnectionBackInformation_Local);

                    messageFromServer = returnParametersAndMessageFromSocket;

                    if (messageFromServer.Count > 1)
                    {
                        messageFromServer1 = messageFromServer[messageFromServer.Count - 1];
                    }
                }
            }

            ConnectionBackInformation = ConnectionBackInformation_Local;

            return(new Tuple <List <dynamic>, string>(messageFromServer, messageFromServer1));
        }
        public static Tuple <T, string, string> GetUser <T>(string Login, string Password, out ConnectionBackInformation ConnectionBackInformation)
        {
            string         MethodName = MethodBase.GetCurrentMethod().Name;
            List <dynamic> SetItems   = new List <dynamic>()
            {
                Login, Password
            };
            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));
            }
        }
        public static Tuple <StructureValueForClient, string, string> GetParamatersForClientReady(List <string> ListNameOfValue, out ConnectionBackInformation ConnectionBackInformation)
        {
            string         MethodName = MethodBase.GetCurrentMethod().Name;
            List <dynamic> SetItems   = new List <dynamic>()
            {
                ListNameOfValue
            };
            List <dynamic> ReturnItems = new List <dynamic>()
            {
                Converter.CreateInstance <StructureValueForClient>(), Converter.CreateInstance <string>()
            };
            Tuple <List <dynamic>, string, string> tuple = Common <StructureValueForClient>(SetItems, ReturnItems, MethodName, out ConnectionBackInformation);

            if (tuple.Item1.Count == 0)
            {
                return(new Tuple <StructureValueForClient, string, string>(null, tuple.Item2, tuple.Item3));
            }
            else
            {
                return(new Tuple <StructureValueForClient, string, string>(tuple.Item1[0], tuple.Item2, tuple.Item3));
            }
        }
        public static Tuple <List <dynamic>, string, string> Common <T>(List <dynamic> SetItems, List <dynamic> ReturnItems, string MethodName, out ConnectionBackInformation ConnectionBackInformation)
        {
            Tuple <List <dynamic>, string, string> tuple = default;

            ConnectionBackInformation = default;

            {
                var r = CommonLayer(SetItems, ReturnItems, MethodName, out ConnectionBackInformation);
                tuple = new Tuple <List <dynamic>, string, string>(r.Item1, r.Item2, null);
            }

            return(tuple);
        }
        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);
                                }
                            }
                    }
                }
            }
        }
        /// <summary>
        /// Проверка времени на обновленные данные с сервера
        /// </summary>
        /// <param name="NameOfModuleToUpdate">Название модуля для обновления</param>
        /// <param name="timeLastUpdate">Время последнего обновления</param>
        /// <param name="InNetWorkProtocol">Задействован сетевой протокол. На случай, есль взаимодействие внутри сервера</param>
        /// <param name="IPAddress">IPAddress сервера</param>
        /// <param name="Thisport">Порт</param>
        /// <param name="Parent">Родительский объект прогресс-аспекта</param>
        /// <returns>Возвращает логическое значение, можно ли отправлять запрос на обновление</returns>

        public static bool CheckAutoRefresh(string NameOfModuleToUpdate, DateTime timeLastUpdate, bool InNetWorkProtocol, IPAddress IPAddress, int Thisport, out ConnectionBackInformation ConnectionBackInformation)
        {
            bool Returned = false;

            ConnectionBackInformation = default;

            {
                if (!string.IsNullOrEmpty(NameOfModuleToUpdate))
                {
                    lock (CheckProperties_With_TimeLastUpdate) // lock на добавление и изменение
                        if (CheckProperties_With_TimeLastUpdate.ContainsKey(NameOfModuleToUpdate))
                        {
                            if (CheckProperties_With_TimeLastUpdate[NameOfModuleToUpdate] != timeLastUpdate)
                            {
                                CheckProperties_With_TimeLastUpdate[NameOfModuleToUpdate] = timeLastUpdate;
                            }
                        }
                        else
                        {
                            CheckProperties_With_TimeLastUpdate.Add(NameOfModuleToUpdate, new DateTime());
                        }

                    lock (ListNameModuleOnServer)
                        if (ListNameModuleOnServer.ContainsKey(NameOfModuleToUpdate))
                        {
                            lock (CheckProperties_With_TimeLastUpdate)  // lock на взятие значения
                                if (ListNameModuleOnServer[NameOfModuleToUpdate] > CheckProperties_With_TimeLastUpdate[NameOfModuleToUpdate])
                                {
                                    Returned = true;

                                    return(Returned);
                                }
                        }

                    if (!Helper.IsLocked(CheckAutoRefresh_OnServer_lockObject))
                    {
                        lock (CheckAutoRefresh_OnServer_lockObject)
                        {
                            TimeSpan StartLoad = DateTime.Now.TimeOfDay;
                            CheckAutoRefresh(InNetWorkProtocol, IPAddress, Thisport, out ConnectionBackInformation);
                            TimeSpan TimeOnLoad = DateTime.Now.TimeOfDay - StartLoad;

                            if (ConnectionBackInformation.Recieve_GetResponse & TimeOnLoad > TimeSpan.FromSeconds(20))
                            {
                            }
                        }
                    }
                }
            }
            return(Returned);
        }
Exemplo n.º 8
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);
                    }));
                }
            }
        }
Exemplo n.º 9
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);
                    }
Exemplo n.º 10
0
        private static ManualResetEvent connectDone = new ManualResetEvent(false);   // ManualResetEvent instances signal completion.
        /// <summary>
        /// Запуск подключения к серверу
        /// </summary>
        /// <param name="IPAddress">IPAddress сервера</param>
        /// <param name="Port">Порт</param>
        /// <param name="dataToSerialize">Структура на сериализацию</param>
        /// <param name="Parent">Родительский объект прогресс-аспекта</param>
        /// <returns></returns>

        public static DataToSerialize StartClient(IPAddress IPAddress, int Port, DataToSerialize dataToSerialize, out ConnectionBackInformation ConnectionBackInformation) // Для отправки DataSet
        {
            DataToSerialize ReturnDataSet = default;

            {
                TimeSpan SerializeBefore_Start = DateTime.Now.TimeOfDay;
                DataToBinary.Convert(dataToSerialize, out byte[] Bytes_ToSend, out string Exception); // Сериализация
                dataToSerialize = null;
                TimeSpan SerializeToSend = DateTime.Now.TimeOfDay - SerializeBefore_Start;

                if (!string.IsNullOrEmpty(Exception))
                {
                }

                byte[] Bytes_FromRecieve = StartClient(IPAddress, Port, Bytes_ToSend, out ConnectionBackInformation);

                ConnectionBackInformation.Send_Serialize = SerializeToSend;

                ConnectionBackInformation.Send_Bytes = Bytes_ToSend is null ? default : Bytes_ToSend.Length;
                                                       Bytes_ToSend = null;

                                                       ConnectionBackInformation.Recieve_Bytes = Bytes_FromRecieve is null ? default : Bytes_FromRecieve.Length;

                                                                                                 if (!(Bytes_FromRecieve is null))
                                                                                                 {
                                                                                                     TimeSpan SerializeAfter_Start = DateTime.Now.TimeOfDay;
                                                                                                     DataToBinary.Convert(Bytes_FromRecieve, out ReturnDataSet, out string Ex); // Десериализация
                                                                                                     ConnectionBackInformation.Recieve_Deserialize = DateTime.Now.TimeOfDay - SerializeAfter_Start;

                                                                                                     if (!string.IsNullOrEmpty(Ex))
                                                                                                     {
                                                                                                     }

                                                                                                     Bytes_FromRecieve = null;
                                                                                                 }