public override Task <List <string> > executeAsync(IInfoContext info, FunctionContext context)
        {
            new System.Threading.ManualResetEvent(false).WaitOne(1000);
            var z = context.getObject <List <string> >(0);

            return(Task.FromResult(z));
        }
Exemplo n.º 2
0
        public override object execute(IInfoContext info, FunctionContext context)
        {
            new System.Threading.ManualResetEvent(false).WaitOne(1000);
            var z = context.getObject <List <string> >(0);

            return(z);
        }
Exemplo n.º 3
0
        public static PID?GetNamed(this IInfoContext context, string name)
        {
            var system  = context.System;
            var process = system.ProcessRegistry.GetLocal(name);

            return(process == system.DeadLetter ? null : new PID(system.Address, name));
        }
Exemplo n.º 4
0
 public bool isLoadable(IInfoContext infoctx, string applicationType)
 {
     if (applicationType.CompareTo("default") == 0 || applicationType.CompareTo(infoctx.TypeApplication) == 0 || (applicationType.EndsWith("*") && infoctx.TypeApplication.StartsWith(applicationType.Substring(0, applicationType.Length - 1))))
     {
         return(true);
     }
     return(false);
 }
        public override async Task <T> executeGenericAsync <T>(IInfoContext info, FunctionContext context)
        {
            await Task.Delay(1000);

            var z = context.getObject <T>(0);

            return(await Task.FromResult(z));
        }
Exemplo n.º 6
0
 public virtual ILogger registerLogger(IInfoContext infoctx, string applicationType, string className, LogLevel logLevel)
 {
     if (isLoadable(infoctx, applicationType))
     {
         return(registerLogger(className, logLevel, infoctx));
     }
     return(null);
 }
Exemplo n.º 7
0
 public virtual T registerAsSingleton <T>(IInfoContext infoctx, string applicationType, string className, params object[] args)
 {
     if (isLoadable(infoctx, applicationType))
     {
         return((T)FunctionCaller.registerAsSingleton <T>(className, args));
     }
     return(default(T));
 }
Exemplo n.º 8
0
        public override object execute(IInfoContext info, FunctionContext context)
        {
            MainCorePcl mainAdapter = (MainCorePcl)info;

            log("This counter is "+mainAdapter.Counter());

            return mainAdapter.Counter();
        }
Exemplo n.º 9
0
        public override object execute(IInfoContext info, FunctionContext context)
        {
            MainCorePcl mainAdapter = (MainCorePcl)info;

            log("This counter is " + mainAdapter.Counter());

            return(mainAdapter.Counter());
        }
Exemplo n.º 10
0
 public virtual ILogger registerLogger <T>(IInfoContext infoctx, string applicationType, LogLevel logLevel)
 {
     if (isLoadable(infoctx, applicationType))
     {
         Type clazz = typeof(T);
         return(registerLogger(clazz, logLevel, infoctx));
     }
     return(null);
 }
Exemplo n.º 11
0
 public virtual AbstractListener addListener <T>(IInfoContext infoctx, string applicationType, string listenerName) where T : AbstractListener, new()
 {
     if (isLoadable(infoctx, applicationType))
     {
         Type clazz = typeof(T);
         return(addListener(clazz, applicationType, listenerName));
     }
     return(null);
 }
Exemplo n.º 12
0
 protected virtual EnterpriseFunction addFunction <T>(IInfoContext infoctx, string applicationType, string functionName) where T : EnterpriseFunction, new()
 {
     if (isLoadable(infoctx, applicationType))
     {
         Type clazz = typeof(T);
         return(addFunction(clazz, applicationType, functionName));
     }
     return(null);
 }
Exemplo n.º 13
0
 public virtual AbstractListener addListener(IInfoContext infoctx, string applicationType, string className, string listenerName)
 {
     if (isLoadable(infoctx, applicationType))
     {
         Type clazz = GetType(className);
         return(addListener(clazz, applicationType, listenerName));
     }
     return(null);
 }
Exemplo n.º 14
0
 /// <summary>
 /// Carica una funzione nel sistema.
 /// </summary>
 /// <param name="companyName">	il nome dell'azienda. </param>
 /// <param name="functionName">	il nome della funzione. </param>
 /// <param name="className">		la classe che imlementa la funzione. </param>
 /// <param name="properties">	eventuali propriet� della funzione.
 ///
 /// @return				la funzione creata.
 /// </param>
 /// <exception cref="Exception">	se si verifica un errore. </exception>
 protected virtual EnterpriseFunction addFunction(IInfoContext infoctx, string applicationType, string className, string functionName)
 {
     if (isLoadable(infoctx, applicationType))
     {
         Type clazz = GetType(className);
         return(addFunction(clazz, applicationType, functionName));
     }
     return(null);
 }
Exemplo n.º 15
0
 protected virtual ILogger registerLogger(Type clazz, LogLevel logLevel, IInfoContext infoctx)
 {
     lock (padlock)
     {
         this.loggerWorker = Activator.CreateInstance(clazz) as ILogger;
         this.loggerWorker.InitLog(infoctx);
         this.loggerWorker.SetLogLevel(logLevel);
         return(this.loggerWorker);
     }
 }
Exemplo n.º 16
0
        public override async Task <T> executeGenericAsync <T> (IInfoContext info, FunctionContext context)
        {
            if (!isAsyncMethod())
            {
                await Task.Yield();
            }
            var result = await executeAsync(info, context);

            return((T)(object)result);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Starts the Task, scheduling it for execution to the current TaskScheduler.
        /// </summary>
        /// <param name="functionName">	Function Name. </param>
        /// <param name="context">	Params that can be passed to the function using FunctionContext. </param>
        /// <param name="info">    Class that implements IInfoContext. </param>
        public virtual void CallSynchronizedTaskFunction(string functionName, IInfoContext info, FunctionContext context)
        {
            WorkerTask asyncWorker = new WorkerTask(this, info, functionName, context);

            asyncWorker.init();
            Task runner = new Task(asyncWorker.run);

            runner.Start();
            //return runner;
            //return Task.Run(() => asyncWorker.run());
        }
Exemplo n.º 18
0
 public override System.Threading.Tasks.Task <string> executeAsync(IInfoContext info, FunctionContext context)
 {
     log("Sono partito " + getName());
     new System.Threading.ManualResetEvent(false).WaitOne(1000);
     if (context != null && context.getParam(0) != null)
     {
         throw new SystemException("Fails");
     }
     new System.Threading.ManualResetEvent(false).WaitOne(1000);
     log("Sono finito " + getName());
     return(Task.FromResult("Hi"));
 }
Exemplo n.º 19
0
 public override object execute(IInfoContext info, FunctionContext context)
 {
     log("Start Regular function ");
     new System.Threading.ManualResetEvent(false).WaitOne(1000);
     if (context != null && context.getParam(0) != null)
     {
         throw new SystemException("Fails");
     }
     new System.Threading.ManualResetEvent(false).WaitOne(1000);
     log("Ended Regular function ");
     return("Hi");
 }
Exemplo n.º 20
0
        /// <summary>
        /// Call a Regular Function
        /// </summary>
        /// <typeparam name="T">Generic Type to return</typeparam>
        /// <param name="functionName">	Function Name. </param>
        /// <param name="context">	Params that can be passed to the function using FunctionContext. </param>
        /// <param name="info">    Class that implements IInfoContext. </param>
        /// <returns>Return a generic type result</returns>
        public virtual T CallFunction <T>(string functionName, IInfoContext info, FunctionContext context)
        {
            var result = CallFunction(functionName, info, context);

            if (result != null)
            {
                return((T)result);
            }
            else
            {
                return(default(T));
            }
        }
Exemplo n.º 21
0
        private static void Error(
            ILogger logger, IInfoContext context, object message, Exception exception)
        {
            if (!logger.IsEnabled(LogLevel.Error))
            {
                return;
            }

            logger.Log(
                LogLevel.Error, exception,
                "[{0}] failed while handling {1}: {2}",
                ActorName(context), TypeName(message), Explain(message));
        }
Exemplo n.º 22
0
 public WorkerTask(CallerCoreMobile main, IInfoContext info, string functionName, FunctionContext context)
 {
     this.main = main;
     this.info = info;
     this.functionName = functionName;
     this.Logger = main.getLogger();
     if (context != null)
         this.context = new FunctionContext(context);
     else
         this.context = null;
     asyncWorkerID++;
        // asyncWorkerID = worker.asyncWorkers++;
 }
        public override object execute(IInfoContext info, FunctionContext context)
        {
            var myparam = context.getIntParam("test").Value;

            log("Start Regular function " + getName() + " Param " + myparam);
            new System.Threading.ManualResetEvent(false).WaitOne(500);
            if (context.getIntParam("test").Value % 30 == 0)
            {
                throw new SystemException($"Error {myparam}");
            }
            log("Ended Regular function " + getName() + " Param " + myparam);
            return(myparam);
        }
        public override async System.Threading.Tasks.Task <int> executeAsync(IInfoContext info, FunctionContext context)
        {
            var myparam = context.getIntParam("test").Value;

            log("Sono partito " + getName() + " Param " + myparam);
            await Task.Delay(500);

            if (context.getIntParam("test").Value % 30 == 0)
            {
                throw new SystemException($"Error {myparam}");
            }
            log("Sono finito " + getName() + " Param " + myparam);
            return(await Task.FromResult(myparam));
        }
Exemplo n.º 25
0
        public override async System.Threading.Tasks.Task <string> executeAsync(IInfoContext info, FunctionContext context)
        {
            log("Sono partito " + getName());
            await Task.Delay(1000);

            if (context != null && context.getParam(0) != null)
            {
                throw new SystemException("Fails");
            }
            await Task.Delay(1000);

            log("Sono finito " + getName());
            return(await Task.FromResult("Hi"));
        }
Exemplo n.º 26
0
        public override System.Threading.Tasks.Task <T> executeGenericAsync <T>(IInfoContext info, FunctionContext context)
        {
            log("****** Num Param=" + ((context != null) ? $"{context.NumParam}" : "-1"));

            log("Start Task function");
            new System.Threading.ManualResetEvent(false).WaitOne(1000);
            if (context != null && context.getParam(0) != null)
            {
                throw new SystemException("Fails");
            }
            new System.Threading.ManualResetEvent(false).WaitOne(1000);
            log("Ended Task function ");


            return(Task.FromResult((T)(object)"Hi"));
        }
Exemplo n.º 27
0
        /*
         * public override Task<T> executeGenericAsync<T> (IInfoContext info, FunctionContext context)
         * {
         *
         *      var tcs = new TaskCompletionSource<T>();
         *      //.ContinueWith<T>( t => (T)(object)t.Result);
         *  executeAsync(info, context).ContinueWith( t => {
         *              if (t.IsFaulted)
         *              {
         *                      // faulted with exception
         *                      Exception ex = t.Exception;
         *                      while (ex is AggregateException && ex.InnerException != null)
         *                              ex = ex.InnerException;
         *                      tcs.TrySetException(ex);
         *              }
         *              else if (t.IsCanceled) tcs.TrySetCanceled();
         *              else tcs.TrySetResult((T)(object)t.Result);
         *
         *      }
         *      );
         *      return tcs.Task;
         *
         * }
         */

        /// <summary>
        /// Method to overrived. If not implemented exec the method async
        /// </summary>
        /// <param name="IInfoContext">Main Info Class</param>
        /// <param name="FunctionContext">Params</param>
        /// <returns>return an object</returns>
        public override object execute(IInfoContext info, FunctionContext context)
        {
            log(LogLevel.Debug, "Executing method execute by Async implementation");
            var task = Task.Run <T2>(() => executeGenericAsync <T2>(info, context));

            try {
                return((object)task.Result);
            }
            catch (AggregateException ae) {
                ae.Handle((x) =>
                {
                    throw x;
                });
                return(null);
            }
        }
Exemplo n.º 28
0
        private void Trace(
            ILogger logger, IInfoContext context, object message)
        {
            if (!logger.IsEnabled(LogLevel.Trace))
            {
                return;
            }
            if (SuppressTrace(context, message))
            {
                return;
            }

            logger.Log(
                LogLevel.Trace,
                "[{0}] received {1}: {2}",
                ActorName(context), TypeName(message), Explain(message));
        }
Exemplo n.º 29
0
 public WorkerTask(CallerCoreMobile main, IInfoContext info, string functionName, FunctionContext context)
 {
     this.main         = main;
     this.info         = info;
     this.functionName = functionName;
     this.Logger       = main.getLogger();
     if (context != null)
     {
         this.context = new FunctionContext(context);
     }
     else
     {
         this.context = null;
     }
     asyncWorkerID++;
     // asyncWorkerID = worker.asyncWorkers++;
 }
Exemplo n.º 30
0
        public override async Task <bool> executeAsync(IInfoContext info, FunctionContext context)
        {
            string host      = "google.com";
            int    msTimeout = 5000;
            int    port      = 80;

            return(await Task.Run(() =>
            {
                try
                {
                    log(LogLevel.Info, "Connect to internet....");
                    var clientDone = new ManualResetEvent(false);
                    var reachable = false;
                    var hostEntry = new DnsEndPoint(host, port);
                    using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
                    {
                        var socketEventArg = new SocketAsyncEventArgs {
                            RemoteEndPoint = hostEntry
                        };
                        socketEventArg.Completed += (s, e) =>
                        {
                            reachable = e.SocketError == SocketError.Success;

                            clientDone.Set();
                        };

                        clientDone.Reset();

                        socket.ConnectAsync(socketEventArg);

                        clientDone.WaitOne(msTimeout);

                        return reachable;
                    }
                }
                catch (Exception ex)
                {
                    log("Unable to reach: " + host + " Error: " + ex);
                    return false;
                }
            }));
        }
Exemplo n.º 31
0
        public override async Task <bool> executeAsync(IInfoContext info, FunctionContext context)
        {
            string host      = "google.com";
            int    msTimeout = 5000;

            return(await Task.Run <bool> (() => {
                bool reachable;
                try {
                    log(LogLevel.Info, "Connect to internet....");
                    reachable = InetAddress.GetByName(host).IsReachable(msTimeout);
                } catch (UnknownHostException ex) {
                    log("Unable to reach: " + host + " Error: " + ex);
                    reachable = false;
                } catch (Exception ex2) {
                    log("Unable to reach: " + host + " Error: " + ex2);
                    reachable = false;
                }
                return reachable;
            }));
        }
Exemplo n.º 32
0
        /// <summary>
        /// Carica le funzioni predefinite del sistema.
        /// </summary>
        /// <exception cref="Exception">	se si verifica un errore durante il caricamento. </exception>
        public virtual void loadFunctions(IInfoContext infoctx, List <FunctionProps> basefunc)
        {
            lock (this)
            {
                getLogger().Debug("EnterpriseCaller: loading enterprise functions...");
                int                functionsCounter = 0;
                int                handlersCounter  = 0;
                List <string>      functionlist     = new List <string>();
                EnterpriseFunction function;

                for (int i = 0; i < basefunc.Count; i++)
                {
                    try
                    {
                        FunctionProps fps           = basefunc[i];
                        string        companyName   = fps.appType;
                        string        functionName  = fps.functionName;
                        string        classFuncName = fps.className;
                        if ((companyName.CompareTo("default") == 0 || companyName.CompareTo(infoctx.TypeApplication) == 0) && !functionlist.Contains(functionName))
                        {
                            functionlist.Add(functionName);
                            function = addFunction(infoctx, companyName, classFuncName, functionName);
                            functionsCounter++;
                            if (function is MessageHandler)
                            {
                                handlersCounter++;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        getLogger().Error(e);
                    }
                    finally
                    {
                    }
                }
                CleanAssemblyCache();
                getLogger().Debug("Regular " + functionsCounter + " functions and " + handlersCounter + " handlers loaded");
            }
        }
 public abstract override object execute(IInfoContext info, FunctionContext context);
Exemplo n.º 34
0
 public override object execute(IInfoContext info, FunctionContext context)
 {
     return Android.OS.Build.VERSION.Release;
 }
Exemplo n.º 35
0
 public override object execute(IInfoContext info, FunctionContext context)
 {
     return UIDevice.CurrentDevice.SystemVersion;
 }
Exemplo n.º 36
0
		/// <summary>
		/// Init the function
		/// </summary>
		/// <seealso cref= CallerCore.MainCore.EnterpriseListener#init() </seealso>
        /// 
       
		public virtual void init(CallerCoreMobile main)
		{
			this.main = main;
            this.info = main.infoctx;
            this.Logger = main.getLogger();
		}