Exemple #1
0
 /// <summary>
 /// Client informs server for the action result
 /// </summary>
 /// <param name="result"></param>
 public void SetActionResultResponse(ActionScriptResult result)
 {
     try
     {
         result.GetResultMessage();
     }
     catch (Exception ex)
     {
         log.ErrorFormat("'SetActionResultResponse' Method failed with error: '{0}'", ex.GetExceptionMessage());
     }
 }
Exemple #2
0
        /// <summary>
        /// Register on server events
        /// </summary>
        private void RegisterOnServerEvents()
        {
            hub.On <byte[], string>("SetActionScriptAssemblyData", (assembly, typeName) =>
            {
                ActionScriptManager.SetActionScriptAssemblyData(assembly, typeName);

                if (ClientManager.ActionScriptSettings.RunImmediately)
                {
                    log.Info("Requesting server preconfigured actions...");
                    ///Request action script commands
                    this.CallServerMethod("RequestActionScriptCommands");
                }
            });

            hub.On <string, object[]> ("invokeAction", (method, parameters) =>
            {
                ActionScriptResult result = ActionScriptManager.InvokeAction(method, parameters);

                ///Informs the server about the result
                this.CallServerMethod("SetActionResultResponse", result);
            });
        }
Exemple #3
0
        /// <summary>
        /// Invoking action from action script instance
        /// </summary>
        /// <param name="method"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public static ActionScriptResult InvokeAction(string method, object[] parameters = null)
        {
            ActionScriptResult actionScriptResult = new ActionScriptResult();

            try
            {
                log.InfoFormat("Invoking Action '{0}'....", method);

                actionScriptResult.Action = method;

                if (string.IsNullOrEmpty(method))
                {
                    throw new Exception("Method name is not defined!");
                }

                if (instance == null)
                {
                    throw new Exception(string.Format("Action Script Instance is not defined!"));
                }

                if (type == null)
                {
                    throw new Exception(string.Format("Namespace is not defined!"));
                }

                var methodInfo = type.GetMethod(method);

                if (methodInfo == null)
                {
                    throw new Exception(string.Format("Method '{0}' doesn't exist!", method));
                }

                ParameterInfo[] parameterDefinition = methodInfo.GetParameters();
                if (parameterDefinition.Count() > 0)
                {
                    if (parameterDefinition.Count() != parameters.Count())
                    {
                        throw new Exception("The number of parameters doesn't match!");
                    }

                    for (int i = 0; i < parameterDefinition.Count(); i++)
                    {
                        ParameterInfo info  = parameterDefinition[i];
                        string        _type = string.Empty;
                        try
                        {
                            _type = string.Format("System.{0}", info.ParameterType.Name);
                        }
                        catch (Exception ex)
                        {
                            throw new Exception(string.Format("Failed to get parameter type for: '{0}'!", info.ParameterType.Name));
                        }
                        try
                        {
                            parameters[i] = Convert.ChangeType(parameters[i], Type.GetType(_type));
                        }
                        catch (Exception ex)
                        {
                            throw new Exception(string.Format("Invalid cast parameter: '{0}' to type: '{1}'", parameters[i], _type));
                        }
                    }
                }

                methodInfo.Invoke(instance, parameters);
                actionScriptResult.Result = Result.Success;
            }
            catch (Exception ex)
            {
                actionScriptResult.Result     = Result.Failed;
                actionScriptResult.FailReason = ex.GetExceptionMessage();
            }

            actionScriptResult.GetResultMessage();

            return(actionScriptResult);
        }