public void Invoke_NullDomain() { Assert.Throws(typeof(ArgumentNullException), () => { RemoteAction.Invoke(null, () => { }); }); }
public void Invoke_MarshalObjectByRef_FourArg() { using (var context = AppDomainContext.Create()) { var actual = new Test(); RemoteAction.Invoke( context.Domain, actual, (short)11, new Double?(12.0), new Composite() { Value = 13 }, (test, value2, value3, value4) => { test.Value1 = 10; test.Value2 = value2; test.Value3 = value3; test.Value4 = value4; }); Assert.NotNull(actual); Assert.Equal(10, actual.Value1); Assert.Equal(11, actual.Value2); Assert.Equal(12.0, actual.Value3); Assert.NotNull(actual.Value4); Assert.Equal(13, actual.Value4.Value); } }
static void Main(string[] args) { using (var context1 = AppDomainContext.Create()) using (var context2 = AppDomainContext.Create()) { var task1 = Task.Factory.StartNew( () => { RemoteAction.Invoke( context1.Domain, () => { var appName = AppDomain.CurrentDomain.SetupInformation.ApplicationName; Console.WriteLine("Hello from app domain " + appName); }); }); var task2 = Task.Factory.StartNew( () => { RemoteAction.Invoke( context2.Domain, () => { var appName = AppDomain.CurrentDomain.SetupInformation.ApplicationName; Console.WriteLine("Hello from app domain " + appName); }); }); // Be sure to wait, else the domains will dispose Task.WaitAll(task1, task2); } Console.ReadKey(); }
public void Invoke_MarshalObjectByRef_NoArguments() { using (var context = AppDomainContext.Create()) { RemoteAction.Invoke(context.Domain, () => { }); } }
public void Invoke_NullFunction() { using (var context = AppDomainContext.Create()) { RemoteAction.Invoke(context.Domain, null); } }
static void Main(string[] args) { using (var context1 = AppDomainContext.Create()) using (var context2 = AppDomainContext.Create()) using (var context3 = AppDomainContext.Create()) { var pizzaInContext1 = Remote <Pizza> .CreateProxy(context1.Domain, "Hawaiian"); // manipulate object from current app domain pizzaInContext1.RemoteObject.AddTopping(new Topping("Cheese")); // manipulate object from context 2 RemoteAction.Invoke( context2.Domain, pizzaInContext1.RemoteObject, new Topping("Pineapple"), (pizza, topping) => { pizza.AddTopping(topping); }); // manipulate object, adding info from context 3 RemoteAction.Invoke( context3.Domain, pizzaInContext1.RemoteObject, (pizza) => { pizza.AddTopping(new Topping("Ham")); }); Console.WriteLine(pizzaInContext1.RemoteObject.ToString()); } Console.ReadKey(); }
public void Invoke_InstanceNoTypes_NullFunction() { Assert.Throws(typeof(ArgumentNullException), () => { var action = new RemoteAction(); action.Invoke(null); }); }
public void Invoke_InstanceFourTypes_NullFunction() { Assert.Throws(typeof(ArgumentNullException), () => { var action = new RemoteAction <int, int, int, int>(); action.Invoke(1, 2, 3, 4, null); }); }
/// <summary> /// 停止所有执行任务,并清空执行状态表 /// </summary> public void StopAllTask() { foreach (var context in AppDomainContextDic.Values) { RemoteAction.Invoke(context.Domain, () => { SchedulerContainer.GetContainerInstance().StopSchedule(); }); } _taskRunLogRespository.ClearTaskRunLog(); // 清空执行状态表 }
public void Invoke_InstanceTwoTypes_NullFunction() { Assert.Throws(typeof(ArgumentNullException), () => { var action = new RemoteAction<int, int>(); action.Invoke(1, 2, null); }); }
/// <summary> /// Constructs an event arguments /// </summary> /// <param name="host">Hostname or IP address</param> /// <param name="port">IP Port</param> /// <param name="protocol">Protocol</param> public RemoteReportedEventArgs(string host, int port, ProtoType protocol) { Host = host; Port = port; Protocol = protocol; // Default action is accept. Action = new RemoteAcceptAction(); }
public void Invoke_NullFunction() { Assert.Throws(typeof(ArgumentNullException), () => { using (var context = AppDomainContext.Create()) { RemoteAction.Invoke(context.Domain, null); } }); }
/// <summary> /// 开始所有执行的任务,并且结合配置执行状态表数据 /// </summary> public void StartAllScheduler() { GetUseableJobconfigs(); //读取任务配置 foreach (var configs in ConfigDic.Values) { foreach (var config in configs) { var runlog = new TaskRunLog { Pcip = Computer.IpAddress, Pcmac = Computer.MacAddress, Pcname = Computer.ComputerName, Taskid = config.Taskid, Taskname = config.Taskname, Taskremark = config.TaskRemark, Taskserverid = _runnerConfig.TaskServerId, Taskstatus = 0, Tasknextruntime = DateTime.Now, Tasklastruntime = DateTime.Now }; _taskRunLogRespository.SaveTaskRunLog(runlog); } } #region 根据模块创建新的appdomain,并开始任务 foreach (var config in ConfigDic) { var setup = new AppDomainSetup { ApplicationName = $"JobLoader_{config.Key}", ApplicationBase = FileHelper.GetRootPath(), PrivateBinPath = "ZilLionTask", CachePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "JobCachePath"), ShadowCopyFiles = "true" }; setup.ShadowCopyDirectories = string.Concat(setup.ApplicationBase, ";", setup.PrivateBinPath); var remoteDomain = AppDomain.CreateDomain($"{config.Key}Domain_{Guid.NewGuid():N}", null, setup); var context = AppDomainContext.Wrap(remoteDomain); if (!AppDomainContextDic.ContainsKey(config.Key)) { AppDomainContextDic.Add(config.Key, context); } RemoteAction.Invoke(context.Domain, config.Key, config.Value, _runnerConfig, (k, v, runnerconfig) => { var container = SchedulerContainer.GetContainerInstance(); container.InitScheduler(k, v, runnerconfig); container.StartScheduler(); }); } #endregion }
private async Task <HttpResponseMessage> SendWithRetriesAsync(RemoteAction action, string jsonString, CancellationToken cancellationToken) { var exceptions = new List <Exception>(); var start = DateTime.Now; for (var attempt = 0; attempt < MaxRetries; attempt++) { try { using StringContent content = new(jsonString, Encoding.UTF8, "application/json"); // Any transport layer errors will throw an exception here. var response = await _client.SendAsync(HttpMethod.Post, GetUriEndPoint(action), content, cancellationToken).ConfigureAwait(false); var totalTime = DateTime.Now - start; if (exceptions.Any()) { Logger.LogDebug($"Received a response for {action} in {totalTime.TotalSeconds:0.##s} after {attempt} failed attempts: {new AggregateException(exceptions)}."); } else { if (action != RemoteAction.GetStatus) { Logger.LogDebug($"Received a response for {action} in {totalTime.TotalSeconds:0.##s}."); } } return(response); } catch (HttpRequestException e) { exceptions.Add(e); } catch (Exception e) { if (exceptions.Any()) { exceptions.Add(e); throw new AggregateException(exceptions); } else { throw; } } // Wait before the next try. await Task.Delay(250, cancellationToken).ConfigureAwait(false); } throw new AggregateException(exceptions); }
private async Task <string> SendAsync <TRequest>(RemoteAction action, TRequest request, CancellationToken cancellationToken) where TRequest : class { using var content = Serialize(request); using var response = await _client.SendAsync(HttpMethod.Post, GetUriEndPoint (action), content, cancellationToken).ConfigureAwait(false); if (!response.IsSuccessStatusCode) { await response.ThrowRequestExceptionFromContentAsync(cancellationToken).ConfigureAwait(false); } return(await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false)); }
private async Task <string> SendWithRetriesAsync <TRequest>(RemoteAction action, TRequest request, CancellationToken cancellationToken) where TRequest : class { using var response = await SendWithRetriesAsync(action, Serialize (request), cancellationToken).ConfigureAwait(false); if (!response.IsSuccessStatusCode) { await response.ThrowRequestExceptionFromContentAsync(cancellationToken).ConfigureAwait(false); } return(await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false)); }
public void OnMessageReceived(string text) { ServerWebSocketService swss = WebSocketSettings.WsServer; try { RemoteAction remote = JsonConvert.DeserializeObject <RemoteAction>(text); if (remote.action == null) { JsonSerializerSettings settings = new JsonSerializerSettings(); settings.MissingMemberHandling = MissingMemberHandling.Error; RemoteResponse response = JsonConvert.DeserializeObject <RemoteResponse>(text, settings); // response ereignis } else { if (AssignRemoteAction(remote.action.Value, remote.value)) { if (swss != null) { RemoteResponse rr = new RemoteResponse(); if (remote.action.Value == RemoteClasses.Action.Information) { string deviceName = Settings.DeviceName; rr.status = 100; rr.message = String.IsNullOrEmpty(deviceName) ? Environment.MachineName : deviceName; swss.SendMessage(JsonConvert.SerializeObject(rr)); } else { rr.status = 200; rr.message = "ok"; swss.SendMessage(JsonConvert.SerializeObject(rr)); } } } } } catch (JsonSerializationException ex) { Debug.WriteLine(ex.ToString()); } catch (JsonReaderException jre) { Debug.WriteLine("Received invalid json: " + text); RemoteResponse rr = new RemoteResponse(); rr.status = 406; rr.message = "Invalid JSON-Object"; swss.SendMessage(JsonConvert.SerializeObject(rr)); } }
/// <summary> /// 根据ID立即执行 /// </summary> /// <param name="config"></param> public void RunOnceTaskById(TaskConfig config) { if (!AppDomainContextDic.ContainsKey(config.TaskModule)) { return; } var context = AppDomainContextDic[config.TaskModule]; RemoteAction.Invoke(context.Domain, config.Taskid, taskid => { SchedulerContainer.GetContainerInstance().RunOnceTask(taskid); }); var runlog = _taskRunLogRespository.GetTaskRunLogById(config.Taskid); runlog.Tasklastruntime = DateTime.Now; _taskRunLogRespository.SaveTaskRunLog(runlog); }
/// <summary> /// 删除指定id任务 /// </summary> /// <param name="config"></param> public void DeleteById(TaskConfig config) { if (!AppDomainContextDic.ContainsKey(config.TaskModule)) { return; } var context = AppDomainContextDic[config.TaskModule]; RemoteAction.Invoke(context.Domain, config.Taskid, taskid => { SchedulerContainer.GetContainerInstance().DeleteJob(taskid); }); config.IsDeleted = 1; _taskConfigRespository.SaveData(config); var runlog = _taskRunLogRespository.GetTaskRunLogById(config.Taskid); _taskRunLogRespository.RemoveTaskRunLog(runlog); }
public void Invoke_MarshalObjectByRef_OneArg() { using (var context = AppDomainContext.Create()) { var actual = new Test(); RemoteAction.Invoke( context.Domain, actual, (test) => { test.Value1 = 10; }); Assert.NotNull(actual); Assert.Equal(10, actual.Value1); } }
void Start() { Academy.Instance.Dispose(); brainServerClient = new UnityBrainServerClient(brainServerIp, brainServerPort); List <GameObject> agents = GetComponent <GameArena>().m_Agents; foreach (var agent in agents) { var script = agent.GetComponent <RemoteAIRobotAgent>(); var agentID = script.m_ArucoMarkerID; var remoteAction = new RemoteAction() { remoteAgent = script, action = 0 }; m_RemoteAgents.Add(agentID, remoteAction); } }
public void Invoke_MarshalObjectByRef_TwoArg() { using (var context = AppDomainContext.Create()) { var actual = new Test(); RemoteAction.Invoke( context.Domain, actual, (short)11, (test, value2) => { test.Value1 = 10; test.Value2 = value2; }); Assert.IsNotNull(actual); Assert.AreEqual(10, actual.Value1); Assert.AreEqual(11, actual.Value2); } }
public void IActionBuilderTest() { string name = "My Remote Action"; string path1 = "docker://mypath"; string path2 = "actions/checkout@v2"; IRemoteActionBuilder b = new RemoteActionBuilderImpl(_stepsBuilder, _pipelineBuilder); b.SetName(name) .Execute(path1) .Execute(path2) // Should override .Build(); RemoteAction actual = (RemoteAction)b.Collect(); RemoteAction expected = new RemoteAction(name, path2); Assert.AreEqual(expected.Name, actual.Name); Assert.AreEqual(expected.Path, actual.Path); }
public void DotNetHooks() { _server.LogDebug("Hooks.DotNetHooks IN"); IList <AppDomain> appDomains = Utility.GetAppDomains(); _server.LogDebug("Hooks.DotNetHooks appDomains " + appDomains.Count); foreach (AppDomain appDomain in appDomains) { _server.LogDebug("Hooks.DotNetHooks appDomain.FriendlyName " + appDomain.FriendlyName); } AppDomain remotePlayDomain = appDomains[0]; try { var domainContext = AppDomainContext.Wrap(remotePlayDomain); try { RemoteAction.Invoke( domainContext.Domain, () => { PatcherRemoteplayToolbar.server = EasyHook.RemoteHooking.IpcConnectClient <InjectionInterface>("dotnethooks"); PatcherRemoteplayToolbar.DoPatching(); }); } catch (Exception e) { _server.LogError(e, "Error when executing remote AppDomain code"); } } catch (Exception e) { _server.LogError(e, "Error Hooks.100"); } _server.LogDebug("Hooks.DotNetHooks OUT"); }
public async Task <RunSummary> CreateRemoteInstanceAndRunAsync <TRunner>(object[] runnerRemoteArgs, MethodInfo runAsyncMethod) { var remoteTaskCompletionSource = new RemoteTaskCompletionSource <SerializableRunSummary>(); RemoteAction.Invoke( _appDomainContext.Domain, CallerAppDomainId, runnerRemoteArgs, remoteTaskCompletionSource, runAsyncMethod, async(callerAppDomainId, args, taskCompletionSource, methodInfo) => { try { if (callerAppDomainId == AppDomain.CurrentDomain.Id) { throw new InvalidOperationException("The action is running in the initial app domain instead of being run in the new app domain."); } var runner = ObjectFactory.CreateInstance <TRunner>(args); var runSummary = await(Task <RunSummary>) methodInfo.Invoke(runner, null); taskCompletionSource.SetResult(new SerializableRunSummary(runSummary)); } catch (OperationCanceledException) { taskCompletionSource.SetCanceled(); } catch (Exception e) { taskCompletionSource.SetException(e); } }); var serializableRunSummary = await remoteTaskCompletionSource.Task; return(serializableRunSummary.Deserialize()); }
public void Invoke_InstanceOneType_NullFunction() { var action = new RemoteAction<int>(); action.Invoke(1, null); }
public void Invoke_InstanceNoTypes_NullFunction() { var action = new RemoteAction(); action.Invoke(null); }
public void RunRemoteAction <T>(T arg, Action <T> action) { RemoteAction.Invoke <T>(_context.Domain, arg, action); }
public async Task RunRemoteActionAsync <T>(T arg, Action <T> action) { await Task.Factory.StartNew(() => RemoteAction.Invoke <T>(_context.Domain, arg, action) ); }
public async Task RunRemoteActionAsync(Action action) { await Task.Factory.StartNew(() => RemoteAction.Invoke(_context.Domain, action) ); }
public void RunRemoteAction(Action action) { RemoteAction.Invoke(_context.Domain, action); }
public async Task RunRemoteActionAsync <T1, T2, T3, T4>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, Action <T1, T2, T3, T4> action) { await Task.Factory.StartNew(() => RemoteAction.Invoke <T1, T2, T3, T4>(_context.Domain, arg1, arg2, arg3, arg4, action) ); }
public void RunRemoteAction <T1, T2, T3, T4>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, Action <T1, T2, T3, T4> action) { RemoteAction.Invoke <T1, T2, T3, T4>(_context.Domain, arg1, arg2, arg3, arg4, action); }
public void Invoke_InstanceTwoTypes_NullFunction() { var action = new RemoteAction<int, int>(); action.Invoke(1, 2, null); }