Exemple #1
0
        public static IPEndPoint CreateIPEndPoint(string endPoint)
        {
            string[] ep = endPoint.Split(':');
            if (ep.Length < 2)
            {
                NetworkController.ShowException(new FormatException("Invalid endpoint format"));
            }
            IPAddress ip;

            if (ep.Length > 2)
            {
                if (!IPAddress.TryParse(string.Join(":", ep, 0, ep.Length - 1), out ip))
                {
                    NetworkController.ShowException(new FormatException("Invalid ip-adress"));
                }
            }
            else
            {
                if (!IPAddress.TryParse(ep[0], out ip))
                {
                    NetworkController.ShowException(new FormatException("Invalid ip-adress"));
                }
            }
            int port;

            if (!int.TryParse(ep[ep.Length - 1], NumberStyles.None, NumberFormatInfo.CurrentInfo, out port))
            {
                NetworkController.ShowException(new FormatException("Invalid port"));
            }
            return(new IPEndPoint(ip, port));
        }
Exemple #2
0
        private void pushCustomType(IMarshalable obj, DataStorage ds)
        {
            IMarshalable imObj = obj as IMarshalable;

            if (imObj == null)
            {
                NetworkController.ShowException(new Exception("invalid rpc parameter"));
            }

            ds.Push(obj.GetType().FullName, imObj);
        }
Exemple #3
0
        private string getUniqueClassString(Object c)
        {
            int hash = c.GetHashCode();
            int num;

            if (!hashToNum.TryGetValue(hash, out num))
            {
                NetworkController.ShowException(new Exception("object not invoked"));
                return(null);
            }
            return(c.ToString() + "#" + num.ToString());
        }
Exemple #4
0
 private bool pushBasicType(object obj, DataStorage ds)
 {
     try
     {
         ds.Push(obj);
     }
     catch (Exception e)
     {
         NetworkController.ShowException(e);
         return(false);
     }
     return(true);
 }
Exemple #5
0
        public static Dictionary <string, IMarshalable> GetMethodParamsObjects(MethodInfo methodInfo)
        {
            Dictionary <string, IMarshalable> result = new Dictionary <string, IMarshalable>();

            ParameterInfo[] args = methodInfo.GetParameters();
            foreach (ParameterInfo par in args)
            {
                if (NetView.IsValidBasicType(par.ParameterType))
                {
                    continue;
                }

                var constructor = par.ParameterType.GetConstructor(
                    BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,
                    null, Type.EmptyTypes, null);
                if (constructor == null)
                {
                    NetworkController.ShowException(new Exception("method's parameter " + par.ParameterType.FullName + " should have a parameterless constructor"));
                    return(null);
                }
                if (par.ParameterType.FullName == "System.Object[]")
                {
                    NetworkController.ShowException(new Exception("invalid parameter type " + par.ParameterType.FullName));
                    return(null);
                }


                var    obj     = Activator.CreateInstance(par.ParameterType);
                string objName = obj.ToString();



                if (!(obj is IMarshalable))
                {
                    NetworkController.ShowException(new Exception("argument " + objName + " not implement IMarshalable"));
                    return(null);
                }

                if (result.ContainsKey(objName))
                {
                    continue;
                }

                result.Add(objName, obj as IMarshalable);
            }
            return(result);
        }
Exemple #6
0
        public static object CheckNonBasicType(Type type)
        {
            if (NetView.IsValidBasicType(type))
            {
                return(null);
            }

            var constructor = type.GetConstructor(
                BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,
                null, Type.EmptyTypes, null);

            if (constructor == null)
            {
                if (FormatterServices.GetUninitializedObject(type) == null)
                {
                    NetworkController.ShowException(new Exception("method's parameter " + type.FullName + " should have a parameterless constructor"));
                    return(null);
                }
            }
            if (type.FullName == "System.Object[]")
            {
                NetworkController.ShowException(new Exception("invalid parameter type " + type.FullName));
                return(null);
            }


            var    obj     = Activator.CreateInstance(type);
            string objName = obj.ToString();



            if (!(obj is IMarshalable))
            {
                NetworkController.ShowException(new Exception("argument " + objName + " not implement IMarshalable"));
                return(null);
            }

            if (type.GetMethod("GetHashCode").DeclaringType != type)
            {
                NetworkController.ShowException(new Exception("argument " + objName + " not override GetHashCode"));
                return(null);
            }

            return(obj);
        }
Exemple #7
0
        private object[] parseRequest(DataStorage ds)
        {
            Dictionary <int, object> result = new Dictionary <int, object>();
            int i = 0;

            while (!ds.Empty)
            {
                string key       = ds.ReadString();
                object resObject = parseObject(key, ds);
                if (resObject == null)
                {
                    NetworkController.ShowException(new Exception("invalid rpc parameter"));
                }

                result.Add(i, resObject);
                i++;
            }
            object[] resultSlice = new object[i];
            foreach (KeyValuePair <int, object> res in result)
            {
                resultSlice[res.Key] = res.Value;
            }
            return(resultSlice);
        }