Exemplo n.º 1
0
 public void Initialize(TimedTask timer)
 {
     if (_discordClient == null)
     {
         return;
     }
     ConnectAsync();
     StartChatNotifier();
 }
Exemplo n.º 2
0
 public void Initialize(TimedTask timer)
 {
     UserManager.OnUserLoggedIn.Add(u =>
     {
         if (!u.Skillset.HasSkill(typeof(JDElectricalSkill)))
         {
             u.Skillset.LearnSkill(typeof(JDElectricalSkill));
         }
     });
 }
Exemplo n.º 3
0
        /// <param name="q"></param>
        /// <param name="cp">第几页</param>
        /// <param name="c">页大小</param>
        /// <param name="navc"></param>
        /// <returns></returns>
        //[System.Web.Http.HttpGet]
        //[ValidateInput(false)]
        //[System.Web.Http.Route("GetSGData")]
        private Object GetSGData(string q, string domain = null, string cp = null, string c = null, string navc = null)
        {
            try
            {
                List <FuncElapsed>     listElaps = new List <FuncElapsed>();
                CBase.Log.TimeWatchLog tlogTotal = new CBase.Log.TimeWatchLog();
                CBase.Log.TimeWatchLog tlog_temp = new CBase.Log.TimeWatchLog();

                if (string.IsNullOrEmpty(q))
                {
                    return(null);
                }

                int recStart = 0;
                int recCount = 0;

                InitPageParam(cp, c, out recStart, out recCount);

                //调用句群接口,返回内容
                QueryContainer <CMAnswer> qcAnswer = null;

                ClientInfo cinfo = new ClientInfo()
                {
                    UserName = CommonHelper.GetUserName(),
                    IP       = CommonHelper.GetClientIP()
                };
                tlog_temp.Start();
                cinfo.Type = ContentLogType.句群超时;
                qcAnswer   = TimedTask.CallActionWithTimeoutSync(timeout, () => new Answer(domain).Get(q, recStart, recCount, domain), q, cinfo);
                listElaps.Add(new FuncElapsed("SenGroup", tlog_temp.Debug()));

                tlog_temp.Start();
                cinfo.Type = ContentLogType.问题排序超时;
                QueryDataContainer SortData = DataSort.SortSenGroup(qcAnswer, cinfo);
                listElaps.Add(new FuncElapsed("SortSG", tlog_temp.Debug()));

                AnswerResultSG result = new Models.AnswerResultSG()
                {
                    SortData = SortData
                };
                result.timeSpan = tlogTotal.Debug();
                SortData.ElapsedList.AddRange(listElaps);

                if (SortData.MetaList.Count == 0)
                {
                    return(new { result = false, msg = "未找到查询结果!" });
                }
                return(new { result = true, SortData.MetaList });
            }
            catch (System.Exception ex)
            {
                CBase.Log.Logger.Error(ex);
                return(new { result = false, msg = ex.ToString() });
            }
        }
        public void Run_Enforces_SingleActiveTask()
        {
            _timerFuncCount = 0;
            var timedTask = new TimedTask("MyTask", TimerFunc);
            var timer     = new Timer(timedTask.Run, null, 10, 100);

            System.Threading.Thread.Sleep(1000);
            Assert.Equal(1, _timerFuncCount);

            timer.Dispose();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Adds a block to the world, offers various parameters to describe spawnbehaviour
        /// <para/>Will never spawn on the surface.
        /// <para/>Currently only supports the placement of single blocks, veins are still WIP and not included yet
        /// </summary>
        /// <param name="block">The block that should be spawned</param>
        /// <param name="abundancyInPPM">How many blocks should be generated in average (per million)</param>
        /// <param name="minHeight">The minimum height where the block should spawn</param>
        /// <param name="maxHeight">The maximum height where the block should spawn</param>
        /// <param name="spawnOnlyIn">Newly spawned block should only replace the blocks given here</param>
        /// <param name="forcespawn">If true makes sure that a block is placed per iteration unless Block placement fails 200 consecutive times
        /// <para/> If false only tries to set the amount of blocks, so if only ~50% of positions are valid, it only spawns ~50% of blocks </param>
        public static void GenerateMineral(Type block, float abundancyInPPM, int minHeight = 0, int maxHeight = 100, Type[] spawnOnlyIn = null, bool forcespawn = true) // maybe switch from chunks to area, as chunks are 3d in Eco
        {
            string blockname = block.ToString();                                                                                                                        //(Activator.CreateInstance(block) as Block).ToString();

            blockname = blockname.Split('.').Last();
            int amountofveins = (int)Math.Round(World.ChunksCount * abundancyInPPM / 1000f, 0);
            int i             = 0;
            int x             = 0;
            //Console.WriteLine("Should spawn " + amountofveins + " Blocks");
            Vector2i XZvector;
            Vector3i position;
            Block    tmpBlock;

            using (TimedTask task = new TimedTask("Spawning " + blockname + "s (" + amountofveins + ")"))
            {
                while (i <= amountofveins)
                {
                    XZvector = World.RandomMapPos().XZ;
                    position = XZvector.X_Z((int)random.Range(minHeight, Math.Min(maxHeight, World.GetTopPos(XZvector).Y - 2)));

                    if (spawnOnlyIn != null)
                    {
                        tmpBlock = World.GetBlock(position);
                        //Console.WriteLine("Found " + tmpBlock.GetType() + " need " + spawnOnlyIn[0]);
                        if (!spawnOnlyIn.Contains(tmpBlock.GetType()))
                        {
                            if (forcespawn)
                            {
                                x++;
                                if (x >= 200)
                                {
                                    Console.WriteLine("There was a problem with while spawning custom minerals... aborting...(200 consecutive failed placement attempts)");
                                    ChatManager.ServerMessageToAllAlreadyLocalized("There was a problem while spawning custom minerals... aborting...(200 consecutive failed placement attempts)", true);
                                    break;
                                }
                                continue;
                            }
                            else
                            {
                                i++;
                            }
                            continue;
                        }
                    }
                    //Console.WriteLine("Spawned " + blockname + " (" + i + "/" + amountofveins + ")" + " at " + position.x + "/" + position.y + "/" + position.z + "           ");
                    task.LoadPercentage = i / amountofveins;
                    World.SetBlock(block, position);
                    i++;
                    x = 0;
                }
            }
        }
Exemplo n.º 6
0
        public void Run_CallsRunOnTask_WhenCalled()
        {
            // Arrange
            var task = Substitute.For <ITask>();
            var sut  = new TimedTask(123,
                                     task);

            // Act
            sut.Run();

            // Assert
            task.Received().Run(123);
        }
Exemplo n.º 7
0
        public void Initialize(TimedTask timer)
        {
            ModsUtil.ReadInstalledMod();
            TransportPipeEventListener listener = new TransportPipeEventListener();

            EventManager.RegisterListener(listener);
            UserManager.OnUserLoggedIn.Add(u =>
            {
                if (!u.Skillset.HasSkill(typeof(AutomationSkill)))
                {
                    u.Skillset.LearnSkill(typeof(AutomationSkill));
                }
            });
        }
Exemplo n.º 8
0
    public static void Init(object ticks)
    {
        timeLine = new TimeLine();
        timeLine.Init(System.Convert.ToDouble(ticks));

        Logger.DEBUG("ticks offset: ", timeLine.OffsetTicks());

        timedTask = new TimedTask();
        timedTask.Init();

        timeRecorder = new TimeRecorder();

        Inited = true;
    }
Exemplo n.º 9
0
 public void Retrieve(string fname, string path)
 {
     if (retrieving)
     {
         throw new Exception("An operation is already in processing.");
     }
     retrieving = true;
     this.fname = fname;
     fstr       = File.Create(path);
     StartListening();
     rttask = new TimedTask(500, () => SendFileReq());
     SendFileReq();
     rttask.Start();
 }
Exemplo n.º 10
0
 public void Initialize(TimedTask timer)
 {
     try
     {
         new Thread(() => { collector.collect(); })
         {
             Name = "Collector"
         }.Start();
     }
     catch (Exception ex)
     {
         Logger.Error(ex.Message);
     }
 }
Exemplo n.º 11
0
        public ActionResult TimedEdit(long id = 0)
        {
            var m = _timedTaskService.SingleById(id);

            if (m == null)
            {
                m                = new TimedTask();
                m.Enable         = true;
                m.Method         = "GET";
                m.TimeoutSeconds = 15;
            }
            ViewBag.m = m;
            return(View());
        }
        internal IDisposable Schedule(Action action, TimeSpan delay)
        {
            if (Volatile.Read(ref shutdown))
            {
                return(EmptyDisposable.Instance);
            }
            long due = SchedulerHelper.NowUTC() + (long)delay.TotalMilliseconds;
            long id  = Interlocked.Increment(ref index);

            var tt = new TimedTask(action, due, id, queue);

            if (Offer(tt))
            {
                return(tt);
            }
            return(EmptyDisposable.Instance);
        }
Exemplo n.º 13
0
        //[System.Web.Http.HttpGet]
        //[ValidateInput(false)]
        //[System.Web.Http.Route("GetFAQData")]
        private async Task <Object> GetFAQData(string q, string domain = null)
        {
            try
            {
                List <FuncElapsed>     listElaps = new List <FuncElapsed>();
                CBase.Log.TimeWatchLog tlogTotal = new CBase.Log.TimeWatchLog();
                CBase.Log.TimeWatchLog tlog_temp = new CBase.Log.TimeWatchLog();
                if (string.IsNullOrEmpty(q))
                {
                    return(null);
                }
                QueryContainer <CMFAQ>                 faq      = null;
                QueryContainer <CMFAQ_NET>             faq_net  = null;
                List <Task <QueryContainer <CMFAQ> > > tFaqList = null;
                Task <QueryContainer <CMFAQ_NET> >     tFaq_net = null;

                //获取意图识别
                tlog_temp.Start();
                var tasks = new List <Task>();
                tFaqList = GetFAQTask(q, timeout, domain);
                tFaq_net = TimedTask.CallWithTimeoutAsync(timeout, () => new Faq_net(domain).Get(q, domain), q, null);
                tasks.AddRange(tFaqList);
                tasks.Add(tFaq_net);
                await Task.WhenAll(tasks.ToArray());

                faq     = GetFAQAll(tFaqList);
                faq_net = tFaq_net == null ? null : tFaq_net.Result;
                tlog_temp.Start();
                QueryDataContainer SortData = DataSort.SortKB(faq, faq_net, null, null);

                SortData.ElapsedList.AddRange(listElaps);
                if (SortData.MetaList.Count == 0)
                {
                    return(new { result = false, msg = "未找到查询结果!" });
                }
                return(new { result = true, SortData.MetaList });
            }
            catch (System.Exception ex)
            {
                CBase.Log.Logger.Error(ex);
                return(new { result = false, msg = ex.ToString() });
            }
        }
Exemplo n.º 14
0
        public void Initialize(TimedTask timer)
        {
            try
            {
                mongoClient = new MongoClient("MongoDBConnectionString");
                Console.WriteLine("DB Connected");
                EventManager.RegisterListener((object)new MessageListener());
                Console.WriteLine("[" + DateTime.Now.ToLongTimeString() + "]" + " Chat Listener aktiv", Console.ForegroundColor = ConsoleColor.Green);
            }
            catch (Exception e)
            {
                Console.WriteLine(DateTime.Now.ToShortTimeString() + e);
            }

            Console.WriteLine("Lade jetzt Message Reciver");
            new Thread((ThreadStart)(() =>
            {
                MessageReciever.RecieveMessages(mongoClient);
            })).Start();
        }
Exemplo n.º 15
0
        public void Initialize(TimedTask timer)
        {
            DiscordSocketClient blatherDiscord  = new DiscordSocketClient();
            DiscordSocketClient isabelleDiscord = new DiscordSocketClient();

            using (var services = ConfigureServices())
            {
                services.GetRequiredService <IdentityManager>().Initialize();
                services.GetRequiredService <CommandHandlingService>().InitializeAsync(isabelleDiscord).Wait();
                services.GetRequiredService <Blathers>().InitializeAsync(blatherDiscord).Wait();
                services.GetRequiredService <Isabelle>().InitializeAsync(isabelleDiscord).Wait();
                PublicModule.Initialize(services);
                EcoCommands.Initialize(services);

                var relay = new ChatRelay(services);
                ActionUtil.AddListener(relay);
            }

            Log.WriteLine(Localizer.Do($"Crossing is initialized!"));
            ChatManager.ServerMessageToAllLoc($"Crossing is initialized! Version 0.1", DefaultChatTags.General);
        }
Exemplo n.º 16
0
        private List <Task <bool> > GetFAQTaskExist(string q, int timeout, List <string> filterDomain)
        {
            Faq faq = new Faq();
            List <Task <bool> > taskList = new List <Task <bool> >();
            List <string>       dList    = faq.GetDomain();

            if (dList == null)
            {
                return(taskList);
            }

            foreach (var domain in dList)
            {
                if (filterDomain.Contains(domain))
                {
                    continue;
                }
                taskList.Add(TimedTask.CallWithTimeoutAsync(timeout, () => new Faq().IsExist(q, domain), null, null));
            }
            return(taskList);
        }
        internal IDisposable Schedule(Action action, TimeSpan initialDelay, TimeSpan period)
        {
            if (Volatile.Read(ref shutdown))
            {
                return(EmptyDisposable.Instance);
            }

            SequentialDisposable inner = new SequentialDisposable();
            SequentialDisposable outer = new SequentialDisposable(inner);

            long due = SchedulerHelper.NowUTC() + (long)initialDelay.TotalMilliseconds;
            long id  = Interlocked.Increment(ref index);

            long[] count = { 0 };

            Action recursive = null;

            recursive = () =>
            {
                action();
                var duePeriod = due + (long)(++count[0] * period.TotalMilliseconds);
                var idPeriod  = Interlocked.Increment(ref index);
                var periodTT  = new TimedTask(recursive, duePeriod, idPeriod, queue);
                if (Offer(periodTT))
                {
                    outer.Replace(periodTT);
                }
            };

            var tt = new TimedTask(recursive, due, id, queue);

            if (Offer(tt))
            {
                inner.Replace(tt);
                return(outer);
            }

            return(EmptyDisposable.Instance);
        }
 bool Offer(TimedTask tt)
 {
     lock (queue)
     {
         queue.Add(tt);
     }
     if (Volatile.Read(ref shutdown))
     {
         lock (queue)
         {
             queue.Clear();
         }
         return(false);
     }
     else
     {
         Monitor.Enter(this);
         Monitor.Pulse(this);
         Monitor.Exit(this);
     }
     return(true);
 }
Exemplo n.º 19
0
        public void Initialize(TimedTask timer)
        {
            SetupConfig();
            Logger.Initialize();
            Logger.Info("Plugin version is " + PluginVersion);

            if (!SetUpClient())
            {
                return;
            }

            ConnectAsync().Wait();

            // Triggered on a timer that starts when the Discord client connects.
            // It is likely that the client object has fetched all the relevant data, but there are not guarantees.
            OnDiscordMaybeReady += (obj, args) =>
            {
                InitializeIntegrations();
                UpdateIntegrations(TriggerType.Startup, null);
            };

            _ = EcoUser; // Create the Eco User on startup
        }
        public void Initialize(TimedTask timer)
        {
            DateTime dateNow = DateTime.Now;

            Log.Write(new LocString(string.Format("CitePerdue - Current date is: " + dateNow.ToString())));
            Console.WriteLine();

            WarnRestart("05:56:00", "3");
            WarnRestart("05:58:00", "1");
            SaveAndKick("05:59:00");

            WarnRestart("11:56:00", "3");
            WarnRestart("11:58:00", "1");
            SaveAndKick("11:59:00");

            WarnRestart("17:56:00", "3");
            WarnRestart("17:58:00", "1");
            SaveAndKick("17:59:00");

            WarnRestart("23:56:00", "3");
            WarnRestart("23:58:00", "1");
            SaveAndKick("23:59:00");
        }
Exemplo n.º 21
0
 public void Initialize(TimedTask timer)
 {
     //ColorCubeEventListener listener = new ColorCubeEventListener();
     //EventManager.RegisterListener(listener);
 }
Exemplo n.º 22
0
        public void Initialize(TimedTask timer)
        {
            BetterFarmingEventListener listener = new BetterFarmingEventListener();

            EventManager.RegisterListener(listener);
        }
Exemplo n.º 23
0
 public void Initialize(TimedTask timer)
 {
 }
Exemplo n.º 24
0
 public GBNSender(IPEndPoint cl, string path, string handle, short wsz) : base(cl, path, handle)
 {
     this.wsz = wsz;
     rttask   = new TimedTask(50, () => SendNext());
 }
Exemplo n.º 25
0
 public void Initialize(TimedTask timer)
 {
     WorldEditManager.UpdateBlueprintList();
 }
Exemplo n.º 26
0
 /// <summary>
 /// Delete,根据实体对象删除
 /// </summary>
 /// <returns>返回,成功:true,失败:false</returns>
 public bool Delete(TimedTask entity)
 {
     return(dal.Update(entity));
 }
Exemplo n.º 27
0
 /// <summary>
 /// 插入数据
 /// </summary>
 /// <returns>返回,成功:true,失败:false</returns>
 public int Insert(TimedTask entity)
 {
     return(dal.Insert(entity));
 }
Exemplo n.º 28
0
        //[System.Web.Http.HttpGet]
        //[ValidateInput(false)]
        //[System.Web.Http.Route("GetKBData")]
        private async Task <Object> GetKBData(string q, string domain = null)
        {
            try
            {
                List <FuncElapsed>     listElaps = new List <FuncElapsed>();
                CBase.Log.TimeWatchLog tlogTotal = new CBase.Log.TimeWatchLog();
                CBase.Log.TimeWatchLog tlog_temp = new CBase.Log.TimeWatchLog();
                if (string.IsNullOrEmpty(q))
                {
                    return(null);
                }
                //根据意图分析结果,提供准确答案与资源导航、问答对
                Dictionary <string, QueryContainer <CMKArea> >         navContent = null;
                Task <Dictionary <string, QueryContainer <CMKArea> > > tNavi      = null;
                ClientInfo cinfo = new ClientInfo()
                {
                    UserName = CommonHelper.GetUserName(),
                    IP       = CommonHelper.GetClientIP()
                };
                //获取意图识别
                tlog_temp.Start();
                Domain.Intent intent = new Answer(domain).GetIntent(q, domain);
                listElaps.Add(new FuncElapsed("GetIntent", tlog_temp.Debug()));

                //内容收集 意图是否识别收集用于数据分析 1未识别 2已识别
                ContentLogType collectType = ContentLogType.已识别;
                if (intent != null && intent.qt_parsed_rst == null)
                {
                    collectType = ContentLogType.未识别;
                }
                var client = new CollectorInterfaceClient();
                Task.Run <bool>(() =>
                {
                    return(client.SetConfused(new CollectorEntity()
                    {
                        Content = intent.RawInput,
                        Type = (int)collectType,
                        IP = cinfo.IP,
                        UserID = cinfo.UserName
                    }));
                });

                cinfo.Type = ContentLogType.知识库超时;
                tNavi      = TimedTask.CallWithTimeoutAsync(timeout, () => new KB(domain).Get(intent), q, cinfo);
                await Task.WhenAll(tNavi);

                navContent = tNavi == null ? null : tNavi.Result;
                tlog_temp.Start();
                cinfo.Type = ContentLogType.问题排序超时;
                QueryDataContainer SortData = DataSort.SortKB(null, null, navContent, cinfo);
                listElaps.Add(new FuncElapsed("SortKB", tlog_temp.Debug()));
                AnswerResultKB result = new Models.AnswerResultKB()
                {
                    intent   = intent,
                    SortData = SortData
                };
                result.timeSpan = tlogTotal.Debug();
                SortData.ElapsedList.AddRange(listElaps);
                if (SortData.MetaList.Count == 0)
                {
                    return(new { result = false, msg = "未找到查询结果!" });
                }
                for (int i = 0; i < SortData.MetaList.Count; i++)
                {
                    SortData.MetaList[i].QExp = null;
                }
                return(new { result = true, SortData.MetaList });
            }
            catch (System.Exception ex)
            {
                CBase.Log.Logger.Error(ex);
                return(new { result = false, msg = ex.ToString() });
            }
        }
Exemplo n.º 29
0
 public static TimedTask AddRunningCutscene(TimedTask timedTask)
 {
     RunningCutscenes.Add(timedTask);
     return(timedTask);
 }
Exemplo n.º 30
0
 public bool AddTimedTask(TimedTask timedTask)
 {
     return(_timedTasks.TryAdd(timedTask, true));
 }