Esempio n. 1
0
        private void ReturnCommand(MessageBody messageBody)
        {
            var task = TinctTask.GetObjectBySerializeString(messageBody.Datas);

            TinctTaskRepository.Current.UpdateRunningTask(task);
            TinctTaskRepository.Current.UpdateWaittingTask(task);
        }
Esempio n. 2
0
        public void ExuteTask(string datas, string loggerName, string loggerFileName)
        {
            var logger = TinctLoggerManger.GetLogger(loggerName, loggerFileName);
            var task   = TinctTask.GetObjectBySerializeString(datas);

            if (logger != null)
            {
                logger.LogMessage(task.ToJsonSerializeString());
            }
            AssemblyExcuteEnvironment.Current.AppDomainDicts.TryGetValue(task.ClassName + "\\" + task.MethodName, out AppDomain runTimeActionDomain);
            if (runTimeActionDomain == null)
            {
                runTimeActionDomain = AppDomain.CreateDomain(task.ClassName + "\\" + task.MethodName, AppDomain.CurrentDomain.Evidence, AppDomain.CurrentDomain.SetupInformation);
                AssemblyExcuteEnvironment.Current.AppDomainDicts.TryAdd(runTimeActionDomain.FriendlyName, runTimeActionDomain);
            }
            try
            {
                dynamic controler = runTimeActionDomain.CreateInstanceFrom(task.DllName + ".dll", task.NamespaceName + "." + task.ClassName).Unwrap();

                MethodInfo method         = controler.GetType().GetMethod(task.MethodName);
                int        parametercount = method.GetParameters().Count();
                if (parametercount == 0)
                {
                    method.Invoke(controler, null);
                }
                else
                {
                    method.Invoke(controler, new object[] { task.Datas });
                }

                task.Status = TinctTaskStatus.Completed;
            }
            catch (AppDomainUnloadedException e)
            {
                Console.WriteLine(e);
                //log
                task.Status = TinctTaskStatus.Exception;

                task.Exption         = e;
                task.HasException    = true;
                task.ExceptionString = e.ToString();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                //log
                task.Status          = TinctTaskStatus.Exception;
                task.Exption         = e;
                task.HasException    = true;
                task.ExceptionString = e.ToString();
            }

            AssemblyExcuteEnvironment.Current.UnloadDomain(runTimeActionDomain.FriendlyName);
            task.EndTime = DateTimeExtension.GetTimeStamp();
            if (logger != null)
            {
                logger.LogMessage(task.ToJsonSerializeString());
            }
            TinctMessage message = new TinctMessage();

            message.MessageHeader = new MessageHeader()
            {
                CommandType = CommandType.Return
            };
            MessageBody body = new MessageBody();

            body.Datas          = task.ToJsonSerializeString();
            message.MessageBody = body;

            TinctSlaveNode.Current.SendMessage(TinctNodeCongratulations.MasterName, message);
        }