Ejemplo n.º 1
0
        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();
        }
        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();
        }
Ejemplo n.º 3
0
 public void Invoke_NullFunction()
 {
     using (var context = AppDomainContext.Create())
     {
         RemoteAction.Invoke(context.Domain, null);
     }
 }
 public void Invoke_InstanceTwoTypes_NullFunction()
 {
     Assert.Throws(typeof(ArgumentNullException), () =>
     {
         var action = new RemoteAction<int, int>();
         action.Invoke(1, 2, null);
     });
 }
Ejemplo n.º 5
0
 /// <summary>
 ///     停止所有执行任务,并清空执行状态表
 /// </summary>
 public void StopAllTask()
 {
     foreach (var context in AppDomainContextDic.Values)
     {
         RemoteAction.Invoke(context.Domain, () => { SchedulerContainer.GetContainerInstance().StopSchedule(); });
     }
     _taskRunLogRespository.ClearTaskRunLog(); // 清空执行状态表
 }
Ejemplo n.º 6
0
        /// <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
        }
Ejemplo n.º 7
0
        /// <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);
        }
Ejemplo n.º 8
0
        /// <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);
        }
Ejemplo n.º 9
0
        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);
            }
        }
Ejemplo n.º 10
0
        protected override void OnClick()
        {
            base.OnClick();
            if (!NotificationAction.HasRemoteInputs)
            {
                NotificationAction.Invoke();
            }
            else
            {
                NotificationAction?.Parent?.ReplyHandler?.GetReplyFromUser().ContinueWith(task =>
                {
                    if (!task.IsCompleted || string.IsNullOrEmpty(task.Result))
                    {
                        return;
                    }

                    NotificationAction.Reply(task.Result);
                });
            }
        }
        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_InstanceNoTypes_NullFunction()
 {
     var action = new RemoteAction();
     action.Invoke(null);
 }
Ejemplo n.º 14
0
        public void Invoke_InstanceFourTypes_NullFunction()
        {
            var action = new RemoteAction <int, int, int, int>();

            action.Invoke(1, 2, 3, 4, null);
        }
Ejemplo n.º 15
0
        public void Invoke_InstanceOneType_NullFunction()
        {
            var action = new RemoteAction <int>();

            action.Invoke(1, null);
        }
Ejemplo n.º 16
0
        public void Invoke_InstanceNoTypes_NullFunction()
        {
            var action = new RemoteAction();

            action.Invoke(null);
        }
 public void Invoke_InstanceOneType_NullFunction()
 {
     var action = new RemoteAction<int>();
     action.Invoke(1, null);
 }
 public void Invoke_InstanceTwoTypes_NullFunction()
 {
     var action = new RemoteAction<int, int>();
     action.Invoke(1, 2, null);
 }
Ejemplo n.º 19
0
 public void Invoke_NullDomain()
 {
     RemoteAction.Invoke(null, () => { });
 }