public int addGroupInfo(ClientInfoModel client, GroupInfoModel addGroup)
        {
            int value = -1;
            StandardResultModel resultInfo = null;

            if (!client.admin)
            {
                return value;
            }

            mRequest = RequestController.creatAddGroupRequest(client, addGroup);

            if (mRequest == null)
            {
                return value;
            }

            resultInfo = mConnection.startConnection(mRequest);
            mConnection.closeConnection();

            if (resultInfo == null)
            {
                return value;
            }

            GroupInfoModel resultGroup = JsonConvert.DeserializeObject<GroupInfoModel>(resultInfo.result.ToString());

            if (resultInfo.successful && resultInfo.type == ResultType.addGroup)
            {
                value = resultGroup.ID;
            }

            mRequest = null;
            return value;
        }
 public static StandardRequestModel creatDelPackageRequest(ClientInfoModel client, PackageInfoModel delPackage)
 {
     StandardRequestModel request = null;
     if (client == null)
     {
         return request;
     }
     request = new StandardRequestModel();
     request.Client = client;
     request.request = RequestTyp.delDatabaseSoftwarePackage;
     request.requestData = delPackage;
     return request;
 }
 public static StandardRequestModel creatAddClientRequest(ClientInfoModel client, ClientInfoModel addClient)
 {
     StandardRequestModel request = null;
     if (client == null)
     {
         return request;
     }
     request = new StandardRequestModel();
     request.Client = client;
     request.request = RequestTyp.addDatabaseClient;
     request.requestData = addClient;
     return request;
 }
 public static StandardRequestModel creatDelGroupRequest(ClientInfoModel client, GroupInfoModel delGroup)
 {
     StandardRequestModel request = null;
     if (client == null)
     {
         return request;
     }
     request = new StandardRequestModel();
     request.Client = client;
     request.request = RequestTyp.delDatabaseGroup;
     request.requestData = delGroup;
     return request;
 }
        public StandardResultModel startConnection(StandardRequestModel request)
        {
            StandardResultModel result = null;
            string strRequest = null, strResult = null;

            try
            {
                ServerConnection = new TcpClient(IpAddress, 5555);
            }
            catch (Exception)
            {
                return result;
            }

            if (!ServerConnection.Connected)
            {
                return result;
            }

            connectionStream = ServerConnection.GetStream();

            if (request == null)
            {
                return result;
            }

            try
            {
                strRequest = JsonConvert.SerializeObject(request);
                sendStringStream(strRequest);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            strResult = readStream();

            if (strRequest == "")
            {
                return result;
            }

            result = JsonConvert.DeserializeObject<StandardResultModel>(strResult);

            return result;
        }
        public bool sendUpdateRequest(ClientInfoModel client, string savePath)
        {
            bool value = false;
            StandardResultModel resultInfo = null;

            if (client.admin)
            {
                return value;
            }

            mRequest = RequestController.creatUpdateRequest(client);

            if (mRequest == null)
            {
                return value;
            }

            resultInfo = mConnection.startConnection(mRequest);

            if (resultInfo == null)
            {
                return value;
            }

            if (resultInfo.successful && resultInfo.type == ResultType.sendPackage)
            {
                value = mConnection.readFile(savePath);
            }

            mConnection.closeConnection();

            mRequest = null;
            return value;
        }
        public bool sendFile(ClientInfoModel client, GroupInfoModel group, PackageInfoModel package, string filePath)
        {
            bool value = false;
            StandardResultModel resultInfo = null;

            if (!client.admin)
            {
                return value;
            }

            mRequest = RequestController.creatSendSoftwarePackageRequest(client, group, package);

            if (mRequest == null)
            {
                return false;
            }

            resultInfo = mConnection.startConnection(mRequest);

            if (resultInfo == null)
            {
                return false;
            }

            if (resultInfo.successful && resultInfo.type == ResultType.readPackage)
            {
                value = mConnection.sendFile(filePath);
            }

            mConnection.closeConnection();

            return false;
        }
        public List<PackageInfoModel> getGroupPackages(ClientInfoModel client, GroupInfoModel group)
        {
            List<PackageInfoModel> packageInfo = null;
            StandardResultModel resultInfo = null;

            if (!client.admin)
            {
                return packageInfo;
            }

            mRequest = RequestController.creatGetGrupePackages(client,group);

            if (mRequest == null)
            {
                return packageInfo;
            }

            resultInfo = mConnection.startConnection(mRequest);
            mConnection.closeConnection();

            if (resultInfo == null)
            {
                return packageInfo;
            }

            if (resultInfo.successful && resultInfo.type == ResultType.GrupePackages)
            {
                packageInfo = new List<PackageInfoModel>();
                JArray array = (JArray)resultInfo.result;
                if (array != null)
                {
                    packageInfo = JsonConvert.DeserializeObject<List<PackageInfoModel>>(array.ToString());
                }
            }

            mRequest = null;
            return packageInfo;
        }
        public List<GroupInfoModel> getDatabaseGroups(ClientInfoModel client)
        {
            List<GroupInfoModel> groupInfo = null;
            StandardResultModel resultInfo = null;

            if (!client.admin)
            {
                return groupInfo;
            }
            mRequest = RequestController.creatGetGroupsRequest(client);

            if (mRequest == null)
            {
                return groupInfo;
            }

            try
            {
                resultInfo = mConnection.startConnection(mRequest);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            mConnection.closeConnection();

            if (resultInfo == null)
            {
                return null;
            }

            if (resultInfo.successful && resultInfo.type == ResultType.GroupInfo)
            {
                groupInfo = new List<GroupInfoModel>();
                 JArray array =(JArray)resultInfo.result;
                 groupInfo = JsonConvert.DeserializeObject<List<GroupInfoModel>>(array.ToString());
            }

            mRequest = null;
            return groupInfo;
        }
        public List<ClientInfoModel> getDatabaseClients(ClientInfoModel client)
        {
            List<ClientInfoModel> clientInfo = null;
            StandardResultModel resultInfo = null;

            if (!client.admin)
            {
                return clientInfo;
            }

            mRequest = RequestController.creatGetClientsRequest(client);

            if (mRequest == null)
            {
                return clientInfo;
            }

            resultInfo = mConnection.startConnection(mRequest);
            mConnection.closeConnection();

            if (resultInfo == null)
            {
                return clientInfo;
            }

            if (resultInfo.successful && resultInfo.type == ResultType.ClientInfo)
            {
                clientInfo = new List<ClientInfoModel>();
                JArray array = (JArray)resultInfo.result;
                clientInfo = JsonConvert.DeserializeObject<List<ClientInfoModel>>(array.ToString());
            }

            mRequest = null;
            return clientInfo;
        }
        public bool delPackageInfo(ClientInfoModel client, PackageInfoModel delPackage)
        {
            bool value = false;
            StandardResultModel resultInfo = null;

            if (!client.admin)
            {
                return value;
            }

            mRequest = RequestController.creatDelPackageRequest(client, delPackage);

            if (mRequest == null)
            {
                return value;
            }

            resultInfo = mConnection.startConnection(mRequest);
            mConnection.closeConnection();

            if (resultInfo == null)
            {
                return value;
            }

            if (resultInfo.successful && resultInfo.type == ResultType.delDatabaseSoftwarePackage)
            {
                value = true;
            }

            mRequest = null;
            return value;
        }
        public static StandardRequestModel creatGetClientPackages(ClientInfoModel client, ClientInfoModel clientInfo)
        {
            StandardRequestModel request = null;

            if (client == null || clientInfo == null)
            {
                return request;
            }

            request = new StandardRequestModel();
            request.Client = client;
            request.request = RequestTyp.getClientPackages;
            request.requestData = clientInfo;

            return request;
        }
 public static StandardRequestModel creatUpdateRequest(ClientInfoModel client)
 {
     StandardRequestModel request = null;
     if (client == null)
     {
         return request;
     }
     request = new StandardRequestModel();
     request.Client = client;
     request.request = RequestTyp.upDateRequest;
     request.requestData = null;
     return request;
 }
        public static StandardRequestModel creatSendSoftwarePackageRequest(ClientInfoModel client, GroupInfoModel group, PackageInfoModel package)
        {
            StandardRequestModel request = null;
            if (client == null)
            {
                return request;
            }

            string info = group.Name + "," + package.Name;
            request = new StandardRequestModel();
            request.Client = client;
            request.request = RequestTyp.sendSoftwarePackage;
            request.requestData = info;
            return request;
        }
 public static StandardRequestModel creatGetPackagesRequest(ClientInfoModel client)
 {
     StandardRequestModel request = null;
     if (client == null)
     {
         return request;
     }
     request = new StandardRequestModel();
     request.Client = client;
     request.request = RequestTyp.getDatabaseSoftwarePackages;
     request.requestData = null;
     return request;
 }
 public static StandardRequestModel creatGetGrupePackages(ClientInfoModel client, GroupInfoModel group)
 {
     StandardRequestModel request = null;
     if (client == null)
     {
         return request;
     }
     request = new StandardRequestModel();
     request.Client = client;
     request.request = RequestTyp.getGrupePackages;
     request.requestData = group;
     return request;
 }