Exemple #1
0
        public void ToString_formatting_with_complex_names()
        {
            MethodName id = MethodName.Parse("System.String::System.IConvertible.ToUInt32(), mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");

            Assert.Equal("System.IConvertible.ToUInt32", id.ToString("N"));
            Assert.Equal("String::System.IConvertible.ToUInt32()", id.ToString("C"));
            Assert.Equal("System.String::System.IConvertible.ToUInt32()", id.ToString("G"));
            Assert.Equal("System.String::System.IConvertible.ToUInt32()", id.ToString("F"));
            Assert.Equal("System.String::System.IConvertible.ToUInt32(), mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", id.ToString("U"));
        }
Exemple #2
0
 void CallMethod(MethodName name)
 {
     if (_hasMethod[(int)name])
     {
         CellLuaManager.ClassCallMethod(LuaClassName, name.ToString(), gameObject);
     }
 }
Exemple #3
0
        /// <summary>
        /// Create object
        /// </summary>
        /// <param name="dynamicObject"></param>
        /// <param name="call"></param>
        /// <param name="types"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public static ResultModel <T> Invoke <T>(this DynamicObject dynamicObject, MethodName call, IEnumerable <Type> types = null, IEnumerable <dynamic> parameters = null)
        {
            var result = new ResultModel <T>();

            try
            {
                var method = dynamicObject.Service.GetType().GetMethod(call.ToString())
                             ?.MakeGenericMethod(types?.ToArray() ?? new[] { typeof(object) });

                if (method == null)
                {
                    throw new Exception("Method not supported!");
                }
                var task = (Task)method.Invoke(dynamicObject.Service, parameters?.ToArray());
                Task.WaitAll(task);
                var res = ((dynamic)task).Result;
                result.IsSuccess = res.IsSuccess;
                result.Errors    = res.Errors;
                result.Result    = res.Result;

                return(result);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                result.Errors.Add(new ErrorModel(nameof(Exception), e.Message));
                return(result);
            }
        }
Exemple #4
0
                public string ToString(SignatureStyle style)
                {
                    string methodName = method.ToString(style);

                    if (isConstructor)
                    {
                        if (isStatic)
                        {
                            methodName = ".cctor";
                        }
                        else
                        {
                            methodName = ".ctor";
                        }
                    }

                    string result = declaringType.ToString(style) + "." + methodName;

                    if (style == SignatureStyle.Formal)
                    {
                        result += "(";
                        if (parameters != null)
                        {
                            result += parameters.ToString(style);
                        }
                        result += ")";
                    }
                    return(result);
                }
Exemple #5
0
        public JObject RequestServer(MethodName methodName, List <object> parameters)
        {
            HttpWebRequest rawRequest = GetRawRequest();

            //  basic info required by qt
            JObject jObject = new JObject
            {
                new JProperty("jsonrpc", "1.0"),
                new JProperty("id", "1"),
                new JProperty("method", methodName.ToString())
            };

            //  adds provided parameters
            JArray props = new JArray();

            if (parameters != null && parameters.Any())
            {
                foreach (object parameter in parameters)
                {
                    props.Add(parameter);
                }
            }

            StreamReader streamReader = null;

            jObject.Add(new JProperty("params", props));

            // serialize json for the request
            try
            {
                String s         = JsonConvert.SerializeObject(jObject);
                byte[] byteArray = Encoding.UTF8.GetBytes(s);
                rawRequest.ContentLength = byteArray.Length;
                Stream dataStream = rawRequest.GetRequestStream();
                dataStream.Write(byteArray, 0, byteArray.Length);
                dataStream.Close();

                WebResponse webResponse = rawRequest.GetResponse();
                streamReader = new StreamReader(webResponse.GetResponseStream(), true);
                return((JObject)JsonConvert.DeserializeObject(streamReader.ReadToEnd()));
            }
            catch (WebException webException)
            {
                if (webException.Status == WebExceptionStatus.ConnectFailure)
                {
                    throw new Exception("Could not connect to Gamerscoind, please check that Gamerscoind is up and running and that you configuration (" + _primaryserverIp + ", " + _primaryusername + ", " + _primarypassword + ") is correct");
                }
                return(null);
            }
            finally
            {
                if (streamReader != null)
                {
                    streamReader.Close();
                }
            }
        }
Exemple #6
0
        public void ToString_formatting()
        {
            MethodName id = MethodName.Parse("System.IComparer.CompareTo(x:System.Object, y:System.Object), mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");

            Assert.Equal("CompareTo", id.ToString("N"));
            Assert.Equal("IComparer.CompareTo(Object, Object)", id.ToString("C"));
            Assert.Equal("System.IComparer.CompareTo(System.Object x, System.Object y)", id.ToString("G"));
            Assert.Equal("System.IComparer.CompareTo(System.Object x, System.Object y)", id.ToString("F"));
            Assert.Equal("System.IComparer.CompareTo(System.Object x, System.Object y), mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", id.ToString("U"));

            // TODO Roundtrip assembly names on parameter types...

            // C -- compact form (minimal qualification in names)
            // G -- general form
            // N -- the plain name
            // F -- the full name
            // U -- the roundtrippable name
        }
        public JObject RequestServer(MethodName methodName, List<object> parameters)
        {
            HttpWebRequest rawRequest = GetRawRequest();

            //  basic info required by qt
            JObject jObject = new JObject
                {
                    new JProperty("jsonrpc", "1.0"),
                    new JProperty("id", "1"),
                    new JProperty("method", methodName.ToString())
                };

            //  adds provided parameters
            JArray props = new JArray();

            if (parameters != null && parameters.Any())
            {
                foreach (object parameter in parameters)
                {
                    props.Add(parameter);

                }
            }

            StreamReader streamReader = null;
            jObject.Add(new JProperty("params", props));

            // serialize json for the request
            try
            {
                String s = JsonConvert.SerializeObject(jObject);
                byte[] byteArray = Encoding.UTF8.GetBytes(s);
                rawRequest.ContentLength = byteArray.Length;
                Stream dataStream = rawRequest.GetRequestStream();
                dataStream.Write(byteArray, 0, byteArray.Length);
                dataStream.Close();

                WebResponse webResponse = rawRequest.GetResponse();
                streamReader = new StreamReader(webResponse.GetResponseStream(), true);
                return (JObject)JsonConvert.DeserializeObject(streamReader.ReadToEnd());
            }
            catch (WebException webException)
            {
                if (webException.Status == WebExceptionStatus.ConnectFailure)
                {
                    throw new Exception("Could not connect to Gamerscoind, please check that Gamerscoind is up and running and that you configuration (" + _secondaryserverIp + ", " + _secondaryusername + ", " + _secondarypassword +") is correct");
                }
                return null;
            }
            finally
            {
                if (streamReader != null)
                {
                    streamReader.Close();
                }
            }
        }
Exemple #8
0
        public JObject RequestServer(MethodName methodName, List <object> parameters)
        {
            var rawRequest = GetRawRequest();

            // basic required info to qt
            JObject joe = new JObject();

            joe.Add(new JProperty("jsonrpc", "1.0"));
            joe.Add(new JProperty("id", "1"));
            joe.Add(new JProperty("method", methodName.ToString()));

            // adds provided paramters

            JArray props = new JArray();

            if (parameters != null && parameters.Any())
            {
                foreach (var parameter in parameters)
                {
                    props.Add(parameter);
                }
            }
            StreamReader streamReader = null;

            joe.Add(new JProperty("params", props));

            // serialize json for the request

            try
            {
                string s         = JsonConvert.SerializeObject(joe);
                byte[] byteArray = Encoding.UTF8.GetBytes(s);
                rawRequest.ContentLength = byteArray.Length;
                Stream dataStream = rawRequest.GetRequestStream();
                dataStream.Write(byteArray, 0, byteArray.Length);
                dataStream.Close();


                WebResponse webResponse = rawRequest.GetResponse();

                streamReader = new StreamReader(webResponse.GetResponseStream(), true);

                return((JObject)JsonConvert.DeserializeObject(streamReader.ReadToEnd()));
            }
            finally
            {
                if (streamReader != null)
                {
                    streamReader.Close();
                }
            }
            return(null);
        }
        public JObject BuildRequestJObject(MethodName methodName, List <object> parameters)
        {
            JObject joe = new JObject();

            joe.Add(new JProperty("jsonrpc", "1.0"));
            joe.Add(new JProperty("id", "1"));
            joe.Add(new JProperty("method", methodName.ToString()));

            // adds provided paramters
            joe.Add(new JProperty("params", parameters));

            return(joe);
        }
Exemple #10
0
        /// <summary> Builds request j object. </summary>
        /// <remarks> superreeen, 09.11.2013. </remarks>
        /// <exception cref="ObjectDisposedException"> Thrown when a supplied object has been disposed. </exception>
        /// <param name="methodName"> Name of the method. </param>
        /// <param name="args"> A variable-length parameters list containing arguments. </param>
        /// <returns> A JObject. </returns>
        private static JObject BuildRequestJObject(MethodName methodName, params object[] args)
        {
            JObject jObject = new JObject();

            jObject.Add(new JProperty("jsonrpc", "1.0"));
            jObject.Add(new JProperty("id", "1"));
            jObject.Add(new JProperty("method", methodName.ToString().ToLower()));

            // adds provided paramters
            jObject.Add(new JProperty("params", args));

            return(jObject);
        }
        public void Format_use_simple_parameter_type_names()
        {
            MethodName m = MethodName.FromMethodInfo(typeof(string).GetTypeInfo().GetMethod("CopyTo"));

            MetadataNameFormat format = new MetadataNameFormat();

            format.DefaultFormatString[SymbolType.Parameter] = "Cv";

            string expected = "System.String.CopyTo(Int32, Char[], Int32, Int32)";

            Assert.Equal(expected, format.Format(m));
            Assert.Equal(expected, m.ToString(null, format));
        }
        public void Format_use_simple_parameter_type_names_generic()
        {
            MethodName m = MethodName.FromMethodInfo(
                typeof(string).GetTypeInfo().GetMethods().Single(t => t.Name == "Concat" && t.IsGenericMethod));

            MetadataNameFormat format = new MetadataNameFormat();

            format.DefaultFormatString[SymbolType.Parameter] = "Cv";
            format.IncludeTypeParameters  = true;
            format.IncludeTypeConstraints = false;
            format.IncludeVariance        = false;

            string expected = "System.String.Concat<T>(IEnumerable<T>)";

            Assert.Equal(expected, format.Format(m));
            Assert.Equal(expected, m.ToString(null, format));
        }
        public void Format_use_generic_parameter_positions_array()
        {
            MethodName m = MethodName.FromMethodInfo(
                typeof(Array).GetTypeInfo().GetMethods().Single(t => t.Name == "TrueForAll" && t.IsGenericMethod));

            MetadataNameFormat format = new MetadataNameFormat();

            format.DefaultFormatString[SymbolType.Parameter] = "Cv";
            format.IncludeTypeParameters        = true;
            format.IncludeTypeConstraints       = false;
            format.IncludeVariance              = false;
            format.UseGenericParameterPositions = true;

            string expected = "System.Array.TrueForAll``1(``0[], Predicate<``0>)";

            Assert.Equal(expected, format.Format(m));
            Assert.Equal(expected, m.ToString(null, format));
        }
 private ViewTest GetViewTest(MethodName methodName)
 {
     var method = GetType().GetMethod(methodName.ToString());
     return new ViewTest(method);
 }
Exemple #15
0
        public override async Task <bool> Evaluate(RulesEngineService rulesEngine)
        {
            MethodMapping methodMapping = rulesEngine.MetaModel.GetMethod(ScriptEntityType.Action, MethodName.ToString());
            var           @class        = methodMapping.Class;

            // Create the object instance
            object @object = rulesEngine.Instantiate(@class);

            // Manually inject the rules Engine context into the object instance
            @class.GetProperty(nameof(ScriptClass.Context)).SetValue(@object, rulesEngine.Context);

            // Generate the method meta-data
            var method = @class.GetMethod(methodMapping.Method.Name);

            List <object> methodParameters = new List <object>();

            method.GetParameters().ToList().ForEach(reflectionParameter =>
            {
                var parameter = Parameters[reflectionParameter.Name];

                if (parameter == null)
                {
                    throw new ApplicationException($"Missing {nameof(Parameter)} {reflectionParameter.Name}");
                }

                methodParameters.Add(parameter.Value);
            });

            // Invoke the method - possibly asynchronously
            bool status = await methodMapping.Method.InvokeAsync(@object, methodParameters.ToArray());

            return(status);
        }
Exemple #16
0
 public Item(string controlName, MethodName methodName, string arg)
 {
     this.controlName = controlName;
     this.methodName  = methodName.ToString();
     this.arg         = arg;
 }
Exemple #17
0
        public void parse_parameter_out_ref_parameter()
        {
            string        text = "M:System.UriParser.Resolve(System.Uri,System.Uri,System.UriFormatException@)";
            CodeReference c    = CodeReference.Parse(text);

            Assert.True(c.IsValid);
            Assert.Equal(CodeReferenceType.Valid, c.ReferenceType);

            MethodName name = (MethodName)c.MetadataName;

            Assert.Equal("Resolve", name.Name);
            Assert.Equal("System.UriParser.Resolve(System.Uri, System.Uri, System.UriFormatException&)", name.ToString());
            Assert.Equal(text, c.ToString());
        }