示例#1
0
        private void SendSelectionMethodToTheServer(ClientSideMethods selectedMethod)
        {
            List <byte> sendingArray = new List <byte>();

            if (!selectedMethod.MethodName.Contains('$'))
            {
                selectedMethod.MethodName = selectedMethod.MethodName + '$';
            }
            sendingArray.AddRange(ASCIIEncoding.Default.GetBytes(selectedMethod.MethodName));
            for (int i = 0; i < selectedMethod.MethodsParameters.Count; i++)
            {
                if ((Enums.ParameterType)selectedMethod.MethodsParameters[i] == Enums.ParameterType.String)
                {
                    byte[] stringVariable = ASCIIEncoding.Default.GetBytes(selectedMethod.MethodsParameterValues[i].ToString());
                    sendingArray.Add(Convert.ToByte(stringVariable.Length));
                    sendingArray.AddRange(stringVariable);
                }
                else
                {
                    byte valueLength = Convert.ToByte(selectedMethod.MethodsParameterValues[i]);
                    sendingArray.Add(1);
                    sendingArray.Add(valueLength);
                }
            }
            data = new byte[1024];
            data = sendingArray.ToArray();
            clientSocket.Send(data);
        }
示例#2
0
        private void CreateMethodsWithServerInformations(List <List <byte> > allMethods)
        {
            //sunucudan gelen bilgilerle metot gövdesini yeniden oluşturma.
            List <ClientSideMethods>   clientSideAllMethods = new List <ClientSideMethods>();
            ClientCreateMethodsProcess createMethodsProcess = new ClientCreateMethodsProcess();

            foreach (List <byte> item in allMethods)
            {
                clientSideAllMethods.Add(createMethodsProcess.Start(item));
            }


            //sunucudan alınan byte array metot bilgileriyle metotlar oluşturuldu. şimdi client ekranına basılacak.
            Console.WriteLine("---Server's available methods---");
            Console.WriteLine("\n");
            foreach (var method in clientSideAllMethods)
            {
                Console.WriteLine("Method Name: " + method.MethodName);
                Console.WriteLine("Return Type: " + method.MethodReturnType);
                Console.WriteLine("Parameters Count: " + method.MethodsParameters.Count.ToString());
                if (method.MethodsParameters.Count > 0)
                {
                    for (int i = 0; i < method.MethodsParameters.Count; i++)
                    {
                        Console.WriteLine(string.Format("{0}. Parameter (byte): ", i + 1));
                    }
                }
                Console.WriteLine("\n");
            }
            while (true)
            {
                Console.Write("Select a method (write method name): ");
                selectionMethodName = Console.ReadLine();
                selectionMethodName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(selectionMethodName);
                foreach (var item in clientSideAllMethods)
                {
                    item.MethodsParameterValues.Clear();
                }
                ClientSideMethods selectedMethod = clientSideAllMethods.Where(x => x.MethodName.Contains(selectionMethodName)).FirstOrDefault();
                if (selectedMethod.MethodsParameters.Count > 0)
                {
                    for (int i = 0; i < selectedMethod.MethodsParameters.Count; i++)
                    {
                        Console.Write(string.Format("{0}. Parameter ({1}): ", i + 1, selectedMethod.MethodsParameters[i]));
                        var paramater = Console.ReadLine();
                        selectedMethod.MethodsParameterValues.Add(paramater);
                    }
                }

                SendSelectionMethodToTheServer(selectedMethod);
            }
        }
示例#3
0
        public ClientSideMethods Start(List <byte> method)
        {
            List <Enums.ParameterType> parameters = new List <Enums.ParameterType>();

            this.method = method;
            Enums.ReturnType methodReturnType = (Enums.ReturnType)Enum.Parse(typeof(Enums.ReturnType), method[0].ToString());
            parametersCount = Convert.ToInt32(method[1]);
            for (int i = 0; i < parametersCount; i++)
            {
                parameters.Add((Enums.ParameterType)Enum.Parse(typeof(Enums.ParameterType), method[1 + i + 1].ToString()));
            }
            methodName = ASCIIEncoding.Default.GetString(method.ToArray(), (parametersCount + 2), method.Count - (parametersCount + 2));

            ClientSideMethods clientMethod = new ClientSideMethods();

            clientMethod.MethodName        = methodName;
            clientMethod.MethodReturnType  = methodReturnType;
            clientMethod.MethodsParameters = parameters;
            return(clientMethod);
        }