Exemple #1
0
 internal void RaiseCommandCompletedEvent(string requestId, int result, IntPtr bundleHandle)
 {
     if (bundleHandle != IntPtr.Zero)
     {
         CommandCompleted?.Invoke(this, new CommandCompletedEventArgs(requestId, result, new Bundle(new SafeBundleHandle(bundleHandle, true))));
     }
     else
     {
         CommandCompleted?.Invoke(this, new CommandCompletedEventArgs(requestId, result));
     }
 }
 private static void RegisterCommandCompletedEvent()
 {
     _commandCompletedCallback = (clientName, requestId, result, bundleHandle, _) =>
     {
         if (bundleHandle != IntPtr.Zero)
         {
             CommandCompleted?.Invoke(null, new CommandCompletedEventArgs(requestId, result, new Bundle(new SafeBundleHandle(bundleHandle, true))));
         }
         else
         {
             CommandCompleted?.Invoke(null, new CommandCompletedEventArgs(requestId, result));
         }
     };
     Native.SetEventReceivedCb(Handle, _commandCompletedCallback).
     ThrowIfError("Failed to init RegisterEventCompletedEvent.");
 }
 public Result OnCommandCompleted(Result res)
 {
     CommandCompleted?.Invoke(this, res);
     return(res);
 }
Exemple #4
0
 void OnCommandCompleted()
 {
     Runtime.RunInMainThread(() => {
         CommandCompleted?.Invoke(this, EventArgs.Empty);
     }).WaitAndGetResult();
 }
Exemple #5
0
        private void ExecuteCommand(ConstructorInfo constructorInfo, CommandLineObjectPicker picker)
        {
            List <object> parameterValues = new List <object>();
            bool          complainAboutExtraParameters = true;

            int idx = 0;

            //for each parameter on the constructor we want to invoke
            foreach (var parameterInfo in constructorInfo.GetParameters())
            {
                var required = new RequiredArgument(parameterInfo);

                var argDelegate = GetDelegate(required);

                //if it is an easy one to automatically fill e.g. IBasicActivateItems
                if (argDelegate != null && argDelegate.IsAuto)
                {
                    parameterValues.Add(argDelegate.Run(required));
                }
                else
                //if the constructor argument is a picker, use the one passed in
                if (parameterInfo.ParameterType == typeof(CommandLineObjectPicker))
                {
                    if (picker == null)
                    {
                        throw new ArgumentException($"Type {constructorInfo.DeclaringType} contained a constructor which took an {parameterInfo.ParameterType} but no picker was passed");
                    }

                    parameterValues.Add(picker);

                    //the parameters are expected to be consumed by the target constructors so it's not really a problem if there are extra
                    complainAboutExtraParameters = false;
                    continue;
                }
                else
                //if we have argument values specified
                if (picker != null)
                {
                    //and the specified value matches the expected parameter type
                    if (picker.HasArgumentOfType(idx, parameterInfo.ParameterType))
                    {
                        //consume a value
                        parameterValues.Add(picker[idx].GetValueForParameterOfType(parameterInfo.ParameterType));
                        idx++;
                        continue;
                    }

                    throw new Exception($"Expected parameter at index {idx} to be a {parameterInfo.ParameterType} (for parameter '{parameterInfo.Name}') but it was {(idx >= picker.Length ? "Missing":picker[idx].RawValue)}");
                }
                else
                {
                    parameterValues.Add(GetValueForParameterOfType(parameterInfo));
                }
            }

            if (picker != null && idx < picker.Length && complainAboutExtraParameters)
            {
                throw new Exception("Unrecognised extra parameter " + picker[idx].RawValue);
            }

            var instance = (IAtomicCommand)constructorInfo.Invoke(parameterValues.ToArray());

            if (instance.IsImpossible)
            {
                CommandImpossible?.Invoke(this, new CommandEventArgs(instance));
                return;
            }

            instance.Execute();
            CommandCompleted?.Invoke(this, new CommandEventArgs(instance));
        }
 void OnCommandCompleted(object sender, EventArgs e)
 {
     CommandCompleted?.Invoke(this, e);
 }