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)); }
public override object execute(IInfoContext info, FunctionContext context) { new System.Threading.ManualResetEvent(false).WaitOne(1000); var z = context.getObject <List <string> >(0); return(z); }
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)); }
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)); }
public virtual ILogger registerLogger(IInfoContext infoctx, string applicationType, string className, LogLevel logLevel) { if (isLoadable(infoctx, applicationType)) { return(registerLogger(className, logLevel, infoctx)); } return(null); }
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)); }
public override object execute(IInfoContext info, FunctionContext context) { MainCorePcl mainAdapter = (MainCorePcl)info; log("This counter is "+mainAdapter.Counter()); return mainAdapter.Counter(); }
public override object execute(IInfoContext info, FunctionContext context) { MainCorePcl mainAdapter = (MainCorePcl)info; log("This counter is " + mainAdapter.Counter()); return(mainAdapter.Counter()); }
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); }
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); }
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); }
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); }
/// <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); }
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); } }
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); }
/// <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()); }
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")); }
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"); }
/// <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)); } }
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)); }
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)); }
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")); }
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")); }
/* * 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); } }
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)); }
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 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; } })); }
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; })); }
/// <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);
public override object execute(IInfoContext info, FunctionContext context) { return Android.OS.Build.VERSION.Release; }
public override object execute(IInfoContext info, FunctionContext context) { return UIDevice.CurrentDevice.SystemVersion; }
/// <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(); }