Exemple #1
0
        public void Start()
        {
            if (TaskRepository == null)
            {
                throw new Exception("Do not find TaskRepository!");
            }


            new Task(() =>
            {
                while (true)
                {
                    var currenttask = TaskRepository.DequeueTinctTask();
                    var runnodes    = TaskRepository.GetTaskRuntimeNodeNames(currenttask);
                    var node        = GetRunningNode(TinctMasterNode.Current.SlaveNodes, runnodes);

                    if (string.IsNullOrEmpty(node))
                    {
                        TaskRepository.AddWaittingTask(currenttask);
                        continue;
                    }

                    currenttask.TargetNodeName = node;
                    currenttask.StartTime      = DateTimeExtension.GetTimeStamp();
                    currenttask.Status         = TinctTaskStatus.Running;
                    var message = BuildTaskMessage(currenttask, CommandType.Run);

                    TinctMasterNode.Current.SendMessage(node, message);
                    TaskRepository.AddRunningTask(currenttask);
                }
            }).Start();
        }
Exemple #2
0
        public bool SendMessage(string machineName, TinctMessage message)
        {
            PackageMessage pmsg = new PackageMessage();

            pmsg.SourceName      = NodeInfo.NodeName;
            pmsg.DestinationName = machineName;
            pmsg.SendTimeStamp   = DateTimeExtension.GetTimeStamp();
            pmsg.Message         = message;
            return(SendMessage(machineName, masterPort, pmsg));
        }
Exemple #3
0
        public static List <NodeInfo> GetCurrentNodes()
        {
            List <NodeInfo> nodes = new List <NodeInfo>();

            nodes.Add(new NodeInfo()
            {
                LastUpdateTime = DateTimeExtension.GetTimeStamp(), NodeName = "test",
                Status         = NodeStatus.Running
            });
            return(nodes);
            //  return TinctMasterNode.Current.SlaveNodes.ToArray().ToList();
        }
Exemple #4
0
        public void ClearAllTinctTasks()
        {
            queueTasks = new ConcurrentQueue <TinctTask>();

            lock (syncruntimetasks)
            {
                foreach (var item in currentRuntimeTasks)
                {
                    item.Status  = TinctTaskStatus.Faulted;
                    item.EndTime = DateTimeExtension.GetTimeStamp();
                    logger.LogMessage(item.ToJsonSerializeString());
                }

                currentRuntimeTasks.Clear();
            }
            lock (syncWaittingtasks)
            {
                queueWaittingTasks.Clear();
            }
        }
Exemple #5
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);
        }
Exemple #6
0
        private void EnQueueMessage()
        {
            while (true)
            {
                Console.WriteLine("Waiting for a connection... ");
                TcpClient acceptClient = listener.AcceptTcpClient();
                new Task(() =>
                {
                    Console.WriteLine("Connected!");
                    NetworkStream stream = acceptClient.GetStream();

                    List <byte> lists = new List <byte>();

                    int readStep = 0;
                    while (true)
                    {
                        Byte[] bytes = new Byte[8192 * 10];
                        try
                        {
                            readStep = stream.Read(bytes, 0, bytes.Length);
                            lists.AddRange(bytes);

                            if (readStep < bytes.Length)
                            {
                                long receviceTime = DateTimeExtension.GetTimeStamp();
                                var data          = System.Text.Encoding.Unicode.GetString(lists.ToArray(), 0, lists.Count);
                                var message       = PackageMessage.GetObjectBySerializeString(data);
                                if (message != null)
                                {
                                    message.ReceviceTimeStamp = receviceTime;
                                    MessageQueues.Enqueue(message);
                                }
                                else
                                {
                                    ///Filter some message
                                }
                                if (MessageQueues.Count == 1)
                                {
                                    eventqueue.Set();
                                    eventqueue.Reset();
                                }
                                lists.Clear();
                            }
                        }
                        catch (IOException e)
                        {
                            Console.WriteLine(e.Message);


                            var remoteName = GetRemoteName(acceptClient);
                            if (dicTcpAcceptClients.Count > 0)
                            {
                                var m1 = dicTcpSendClients.Where(m => m.Key.Contains(remoteName)).First();
                                m1.Value.Close();
                                dicTcpSendClients.TryRemove(m1.Key, out TcpClient clienttcp);
                                clienttcp = null;
                            }
                            stream.Close();
                            acceptClient.Close();
                            return;
                        }
                    }
                    ;
                }).Start();
            }
        }