protected async override Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            IInvoker   invoker    = JavaScope.GetJavaInvoker(context);
            var        methodName = MethodName.Get(context) ?? throw new ArgumentNullException(Resources.MethodName);
            JavaObject javaObject = TargetObject.Get(context);
            string     className  = TargetType.Get(context);

            if (javaObject == null && string.IsNullOrWhiteSpace(className))
            {
                throw new InvalidOperationException(Resources.InvokationObjectException);
            }

            List <object> parameters = GetParameters(context);
            var           types      = GetParameterTypes(context, parameters);
            JavaObject    instance   = null;

            try
            {
                instance = await invoker.InvokeMethod(methodName, className, javaObject, parameters, types, cancellationToken);
            }
            catch (Exception e)
            {
                Trace.TraceError($"The method could not be invoked: {e}");
                throw new InvalidOperationException(Resources.InvokeMethodException, e);
            }

            return(asyncCodeActivityContext =>
            {
                Result.Set(asyncCodeActivityContext, instance);
            });
        }
Exemple #2
0
        /// <summary>
        /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run.
        /// </summary>
        /// <param name="context">The NativeActivityContext for the currently running activity.</param>
        /// <returns>A populated instance of Sytem.Management.Automation.PowerShell</returns>
        /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks>
        protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context)
        {
            System.Management.Automation.PowerShell invoker       = global::System.Management.Automation.PowerShell.Create();
            System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName);

            // Initialize the arguments
            // Specified ClassName cannot be WhiteSpace or NULL
            //
            if (ClassName.Expression != null && !string.IsNullOrWhiteSpace(ClassName.Get(context)))
            {
                targetCommand.AddParameter("ClassName", ClassName.Get(context));
            }

            if (Namespace.Expression != null)
            {
                targetCommand.AddParameter("Namespace", Namespace.Get(context));
            }

            if (OperationTimeoutSec.Expression != null)
            {
                targetCommand.AddParameter("OperationTimeoutSec", OperationTimeoutSec.Get(context));
            }

            if (MethodName.Expression != null)
            {
                targetCommand.AddParameter("MethodName", MethodName.Get(context));
            }

            if (PropertyName.Expression != null)
            {
                targetCommand.AddParameter("PropertyName", PropertyName.Get(context));
            }

            if (QualifierName.Expression != null)
            {
                targetCommand.AddParameter("QualifierName", QualifierName.Get(context));
            }


            return(new ActivityImplementationContext()
            {
                PowerShellInstance = invoker
            });
        }
Exemple #3
0
        /// <summary>
        /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run.
        /// </summary>
        /// <param name="context">The NativeActivityContext for the currently running activity.</param>
        /// <returns>A populated instance of System.Management.Automation.PowerShell</returns>
        /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks>
        protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context)
        {
            System.Management.Automation.PowerShell invoker       = global::System.Management.Automation.PowerShell.Create();
            System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName);

            // Initialize the arguments

            if (ClassName.Expression != null)
            {
                targetCommand.AddParameter("ClassName", ClassName.Get(context));
            }

            if (CimClass.Expression != null)
            {
                targetCommand.AddParameter("CimClass", CimClass.Get(context));
            }

            if (Query.Expression != null)
            {
                targetCommand.AddParameter("Query", Query.Get(context));
            }

            if (QueryDialect.Expression != null)
            {
                targetCommand.AddParameter("QueryDialect", QueryDialect.Get(context));
            }

            if (InputObject.Expression != null)
            {
                targetCommand.AddParameter("InputObject", InputObject.Get(context));
            }

            if (Arguments.Expression != null)
            {
                targetCommand.AddParameter("Arguments", Arguments.Get(context));
            }

            if (MethodName.Expression != null)
            {
                targetCommand.AddParameter("MethodName", MethodName.Get(context));
            }

            if (Namespace.Expression != null)
            {
                targetCommand.AddParameter("Namespace", Namespace.Get(context));
            }

            if (OperationTimeoutSec.Expression != null)
            {
                targetCommand.AddParameter("OperationTimeoutSec", OperationTimeoutSec.Get(context));
            }

            if (ResourceUri != null)
            {
                targetCommand.AddParameter("ResourceUri", ResourceUri.Get(context));
            }

            return(new ActivityImplementationContext()
            {
                PowerShellInstance = invoker
            });
        }
Exemple #4
0
 public ObservableCollection <Author> GetAllAuthors()
 {
     _log.Debug(MethodName.Get());
     return(new ObservableCollection <Author>(_ctx.Authors.ToList()));
 }
Exemple #5
0
 public AuthorCore(ILog log, Ctx ctx)
 {
     _log = log;
     _ctx = ctx;
     _log.Debug(MethodName.Get());
 }
Exemple #6
0
 public ObservableCollection <Book> GetAllBooksFromRepository()
 {
     _log.Debug(MethodName.Get());
     return(new ObservableCollection <Book>(_ctx.Books.ToList()));
 }
Exemple #7
0
 public BookCore(ILog log, Ctx ctx)
 {
     _ctx = ctx;
     _log = log;
     _log.Debug(MethodName.Get());
 }