Ejemplo n.º 1
0
        public void GameStart()
        {
            try
            {
                MsgSender.PushMsg(GroupNum, 0, "对决即将开始,请双方做好准备!", BindAi);
                Thread.Sleep(2000);
                InitChessBoard();

                for (var i = 0; i < 6; i++)
                {
                    ProceedTurn();
                    Thread.Sleep(1000);

                    var temp = SelfQQNum;
                    SelfQQNum = AimQQNum;
                    AimQQNum  = temp;
                }

                MsgSender.PushMsg(GroupNum, 0, "对决结束!", BindAi);
            }
            catch (Exception ex)
            {
                RuntimeLogger.Log(ex);
                MsgSender.PushMsg(GroupNum, 0, "系统异常,游戏结束!", BindAi);
            }

            ChessSvc.GameOver(this);
        }
Ejemplo n.º 2
0
        public static void SetMaxCount(string key, int count)
        {
            mutex.WaitOne();

            try
            {
                using var db = new SqliteContext(dataSource);
                var record = db.SqliteFixedSet.FirstOrDefault(p => p.Key == key);
                if (record == null)
                {
                    record = new SqliteFixedSet()
                    {
                        Key = key, MaxCount = count, Value = "[]"
                    };

                    db.SqliteFixedSet.Add(record);
                }
                else
                {
                    record.MaxCount = count;
                }

                db.SaveChanges();
            }
            catch (Exception e)
            {
                RuntimeLogger.Log(e);
            }
            finally
            {
                mutex.ReleaseMutex();
            }
        }
Ejemplo n.º 3
0
        public SearchEngine(SearchEngineConfig config)
        {
            mConfig      = config;
            mQueryParser = new SimpleQueryParser(new QueryParserConfig
            {
                TextSegmenter = config.TextSegmenter,
            });

            mRetriever = new InexactTopKRetriever(new RetrieverConfig
            {
                PostingListStore   = config.PostingListStore,
                UrlFileStore       = config.UrlFileStore,
                InvertedIndexStore = config.InvertedIndexStore,
            }, ResultSize);

            var rankerConfig = new RankerConfig
            {
                PostingListStore   = config.PostingListStore,
                UrlFileStore       = config.UrlFileStore,
                InvertedIndexStore = config.InvertedIndexStore,
            };

            mRanker    = new IntegratedRanker(rankerConfig);
            mProRanker = new QueryTermProximityRanker(rankerConfig);

            mLogger = new RuntimeLogger(Path.Combine(config.LogDirectory, "SearchEngine.Log"), true);
        }
Ejemplo n.º 4
0
    public ExampleRuntime(RuntimeMod mod)
    {
        _mod          = mod;
        _mod.OnStart += (s, a) => Start();

        _log = mod.Log;
        _log.LogInfo("Hello from ExampleRuntime.");
    }
Ejemplo n.º 5
0
        /// <inheritdoc />
        protected override int RunImpl(string[] args)
        {
            if (!ParseArguments(args))
            {
                ShowHelp();
                return(1);
            }

            if (Arguments.Help)
            {
                ShowHelp();
                return(0);
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            UnhandledErrorPolicy();

            var runtimeSetup = new RuntimeSetup
            {
                RuntimePath = Path.GetDirectoryName(AssemblyUtils.GetFriendlyAssemblyLocation(
                                                        typeof(IcarusProgram).Assembly))
            };

            var runtimeLogger = new RuntimeLogger();

            GenericCollectionUtils.ForEach(Arguments.PluginDirectories, runtimeSetup.AddPluginDirectory);

            using (RuntimeBootstrap.Initialize(runtimeSetup, runtimeLogger))
            {
                // wire up services & components
                var scanner = new DefaultConventionScanner(RuntimeAccessor.Registry);
                scanner.Scan("Gallio.Icarus", Assembly.GetExecutingAssembly());

                LoadPackages();

                var optionsController = RuntimeAccessor.ServiceLocator.Resolve <IOptionsController>();

                // create & initialize a test runner whenever the test runner factory is changed
                optionsController.TestRunnerFactory.PropertyChanged += (s, e) =>
                                                                       ConfigureTestRunnerFactory(optionsController.TestRunnerFactory);

                ConfigureTestRunnerFactory(optionsController.TestRunnerFactory);

                var runtimeLogController = RuntimeAccessor.ServiceLocator.Resolve <IRuntimeLogController>();
                runtimeLogController.SetLogger(runtimeLogger);

                var applicationController = RuntimeAccessor.ServiceLocator.Resolve <IApplicationController>();
                applicationController.Arguments = Arguments;

                ErrorDialogUnhandledExceptionHandler.RunApplicationWithHandler(new Main(applicationController));

                UnloadPackages();
            }

            return(ResultCode.Success);
        }
Ejemplo n.º 6
0
        public static void Log(Exception ex)
        {
            var error = ex.Message + "\r\n" + ex.StackTrace;

            AIAnalyzer.AddError(error);
            Global.MsgPublish(error);
            RuntimeLogger.Log(ex);

            MsgSender.PushMsg(0, Global.DeveloperNumber, error, Global.DefaultConfig.MainAi);
        }
 private void InitializeComponent()
 {
     lock (_initLock) {
         if (!_initialized)
         {
             RuntimeLogger.SetUp("eSpace Address_CS", true);
             this.AcquireRequestState += Application_AcquireRequestState;
             SessionInfo.SessionStart += RunOnSessionStart;
         }
         _initialized = true;
     }
 }
Ejemplo n.º 8
0
 public static List <long> GetAllEnabledPersons()
 {
     try
     {
         using var db = new ExCacherContent(dataSource);
         return(db.CounterEnableRecord.Select(p => p.QQNum).ToList());
     }
     catch (Exception e)
     {
         RuntimeLogger.Log(e);
         return(new List <long>());
     }
 }
Ejemplo n.º 9
0
 public static long Get(long QQNum)
 {
     try
     {
         using var db = new ExCacherContent(dataSource);
         var record = db.PersonMsgCountRecord.FirstOrDefault(p => p.QQNum == QQNum);
         return(record?.Count ?? 0);
     }
     catch (Exception e)
     {
         RuntimeLogger.Log(e);
         return(0);
     }
 }
Ejemplo n.º 10
0
 public Crawler(CrawlerConfig config,
                IUrlFrontier urlFrontier,
                IFetcher fetcher,
                ISimilarContentManager similarContentManager,
                List <IUrlFilter> urlFilters)
 {
     mConfig               = config;
     Status                = CrawlerStatus.STOPPED;
     mUrlFrontier          = urlFrontier;
     mFetcher              = fetcher;
     mSimilarContentJudger = similarContentManager;
     mUrlFilters           = urlFilters;
     mLogger               = new RuntimeLogger(Path.Combine(config.LogDirectory, "Crawler.Log"), true);
     mErrorLogger          = new RuntimeLogger(Path.Combine(config.LogDirectory, "Crawler Error.Log"), false);
 }
Ejemplo n.º 11
0
        public static void CleanAll()
        {
            try
            {
                using var db = new ExCacherContent(dataSource);
                var records = db.PersonMsgCountRecord.ToArray();
                db.PersonMsgCountRecord.RemoveRange(records);

                db.SaveChanges();
            }
            catch (Exception e)
            {
                RuntimeLogger.Log(e);
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        public GetExecutor(RuntimeLogger r, Introspector i, Type c, String key)
        {
            rlog    = r;
            args[0] = key;

            // NOTE: changed from get to get to get_Item - assumption is that get would be converted to an indexer in .Net
            // to keep some resembalance to the Java version, look for "Get" and "get" methods as well (both cases for .Net style and java)
            method = i.getMethod(c, "get_Item", args);
            if (method == null)
            {
                method = i.getMethod(c, "Get", args);
                if (method == null)
                {
                    method = i.getMethod(c, "get", args);
                }
            }
        }
Ejemplo n.º 13
0
        public static void PersonDisable(long QQNum)
        {
            try
            {
                using var db = new ExCacherContent(dataSource);
                var record = db.CounterEnableRecord.FirstOrDefault(p => p.QQNum == QQNum);
                if (record == null)
                {
                    return;
                }

                db.CounterEnableRecord.Remove(record);
                db.SaveChanges();
            }
            catch (Exception e)
            {
                RuntimeLogger.Log(e);
            }
        }
Ejemplo n.º 14
0
        public void StartGame()
        {
            try
            {
                BeforeGameStart();

                for (var i = 0; i < 12 && !JudgeWinner(); i++)
                {
                    DoSend();
                    SendMessage($"{SelfPet.Name}的回合开始!");
                    BeforeTurnStartTrigger();
                    if (JudgeWinner())
                    {
                        break;
                    }

                    ProcessTurn();
                    if (JudgeWinner())
                    {
                        break;
                    }

                    AfterTurnEndTrigger();
                    if (JudgeWinner())
                    {
                        break;
                    }

                    SwitchPet();
                }

                DoSend();
                ShowResult();
                DoSend();
            }
            catch (Exception e)
            {
                RuntimeLogger.Log(e);
                SendMessage("系统异常,对决中止!");
                DoSend();
            }
        }
Ejemplo n.º 15
0
        public static void Cache <T>(string key, T data)
        {
            mutex.WaitOne();

            try
            {
                using (var db = new SqliteContext(dataSource))
                {
                    var record = db.SqliteFixedSet.FirstOrDefault(p => p.Key == key);
                    if (record == null)
                    {
                        record = new SqliteFixedSet()
                        {
                            Key   = key,
                            Value = JsonConvert.SerializeObject(new List <T>()
                            {
                                data
                            }),
                            MaxCount = 10
                        };

                        db.SqliteFixedSet.Add(record);
                    }
                    else
                    {
                        var list = JsonConvert.DeserializeObject <List <T> >(record.Value);
                        list         = list.Prepend(data).Take(record.MaxCount).ToList();
                        record.Value = JsonConvert.SerializeObject(list);
                    }

                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
                RuntimeLogger.Log(e);
            }
            finally
            {
                mutex.ReleaseMutex();
            }
        }
Ejemplo n.º 16
0
        public static void Cache(long QQNum, long count = 1)
        {
            try
            {
                using var db = new ExCacherContent(dataSource);
                var record = db.PersonMsgCountRecord.FirstOrDefault(p => p.QQNum == QQNum);
                if (record == null)
                {
                    record = new PersonMsgCountRecord()
                    {
                        QQNum = QQNum, Count = count
                    };
                    db.PersonMsgCountRecord.Add(record);
                }
                else
                {
                    var todayStr = DateTime.Now.ToString("yyyyMMdd");
                    if (string.IsNullOrEmpty(record.LastDate) || record.LastDate != todayStr)
                    {
                        record.LastDate   = todayStr;
                        record.TodayCount = 0;
                    }

                    record.TodayCount ??= 0;

                    if (record.TodayCount >= DialyLimit)
                    {
                        return;
                    }

                    count              = Math.Min(count, DialyLimit - record.TodayCount ?? 0);
                    record.TodayCount += count;
                    record.Count      += count;
                }

                db.SaveChanges();
            }
            catch (Exception e)
            {
                RuntimeLogger.Log(e);
            }
        }
Ejemplo n.º 17
0
        private void MessageInvoke(string bindAi, QQEventModel model)
        {
            Console.WriteLine($"{bindAi}:{JsonConvert.SerializeObject(model)}");

            try
            {
                if (!string.IsNullOrEmpty(model.Id) && WaitingDic.TryRemove(model.Id, out var waiting))
                {
                    WaitingCallBack(waiting, model);
                    return;
                }

                var resolver = MessageResolvers.FirstOrDefault(p => p.MsgEvent == model.Event);
                resolver?.Resolver(bindAi, model);
            }
            catch (Exception e)
            {
                RuntimeLogger.Log(e);
            }
        }
Ejemplo n.º 18
0
        public void StartReceive <T>(Action <T> CallBack)
        {
            var consumer = new EventingBasicConsumer(channel);

            channel.BasicConsume(ReceiveQueue, true, consumer);
            consumer.Received += (model, ea) =>
            {
                try
                {
                    var body        = ea.Body;
                    var message     = Encoding.UTF8.GetString(body.ToArray());
                    var information = JsonConvert.DeserializeObject <T>(message);

                    CallBack(information);
                }
                catch (Exception e)
                {
                    RuntimeLogger.Log(e);
                }
            };
        }
Ejemplo n.º 19
0
        /// <summary>
        /// 下载并保存文件
        /// </summary>
        /// <param name="url"></param>
        /// <param name="savePath"></param>
        /// <returns></returns>
        public static bool DownloadImage(string url, string savePath)
        {
            try
            {
                var req = (HttpWebRequest)WebRequest.Create(url);
                req.ServicePoint.Expect100Continue = false;
                req.Method       = "GET";
                req.KeepAlive    = true;
                req.ContentType  = "image/*";
                using var rsp    = (HttpWebResponse)req.GetResponse();
                using var stream = rsp.GetResponseStream();
                Image.FromStream(stream).Save(savePath);

                return(true);
            }
            catch (Exception e)
            {
                RuntimeLogger.Log(e);
                return(false);
            }
        }
Ejemplo n.º 20
0
        public void CallBack(WaitingModel model, QQEventModel eventModel)
        {
            try
            {
                dynamic result    = eventModel.Result["result"];
                var     buddy     = result["buddy"];
                var     info_list = buddy["info_list"];

                var info = new MsgInformation()
                {
                    Information = InformationType.CommandBack,
                    RelationId  = model.RelationId,
                    Msg         = JsonConvert.SerializeObject(info_list[0])
                };
                WSMgr.PublishInformation(info);
            }
            catch (Exception e)
            {
                RuntimeLogger.Log(e);
            }
        }
Ejemplo n.º 21
0
        public static void PersonEnable(long QQNum)
        {
            try
            {
                using var db = new ExCacherContent(dataSource);
                if (db.CounterEnableRecord.Any(p => p.QQNum == QQNum))
                {
                    return;
                }

                db.CounterEnableRecord.Add(new CounterEnableRecord()
                {
                    QQNum = QQNum
                });
                db.SaveChanges();
            }
            catch (Exception e)
            {
                RuntimeLogger.Log(e);
            }
        }
Ejemplo n.º 22
0
        public static void Consume(long QQNum, long count = 1)
        {
            try
            {
                using var db = new ExCacherContent(dataSource);
                var record = db.PersonMsgCountRecord.FirstOrDefault(p => p.QQNum == QQNum);
                if (record == null)
                {
                    return;
                }
                else
                {
                    record.Count = count > record.Count ? 0 : record.Count - count;
                }

                db.SaveChanges();
            }
            catch (Exception e)
            {
                RuntimeLogger.Log(e);
            }
        }
Ejemplo n.º 23
0
        public void GameStart()
        {
            MsgSender.PushMsg(GroupNum, 0, $"冒险开始!当前副本是 {CaveModel.Name} !", BindAi);
            Thread.Sleep(1000);

            try
            {
                while (Winner == null)
                {
                    ProcessTurn();
                    AlterTurn();
                    Thread.Sleep(2000);
                }

                Settlement();
            }
            catch (Exception ex)
            {
                MsgSender.PushMsg(GroupNum, 0, "游戏异常,对决结束!", BindAi);
                RuntimeLogger.Log(ex);
            }
        }
Ejemplo n.º 24
0
        public static List <T> Get <T>(string key)
        {
            mutex.WaitOne();

            try
            {
                using (var db = new SqliteContext(dataSource))
                {
                    var record = db.SqliteFixedSet.FirstOrDefault(p => p.Key == key);
                    return(record == null ? new List <T>() : JsonConvert.DeserializeObject <List <T> >(record.Value));
                }
            }
            catch (Exception e)
            {
                RuntimeLogger.Log(e);
                return(new List <T>());
            }
            finally
            {
                mutex.ReleaseMutex();
            }
        }
Ejemplo n.º 25
0
 public void Write()
 {
     RuntimeLogger.Log(this);
 }
Ejemplo n.º 26
0
 public SimpleSimilarContentManager(CrawlerConfig config)
 {
     mLogger = new RuntimeLogger(Path.Combine(config.LogDirectory, "Crawler.Log"), true);
     mConfig = config;
 }
 /// <summary>  Recieves our RuntimeServices object
 /// </summary>
 public Introspector(RuntimeLogger r)
 {
     this.rlog = r;
 }
Ejemplo n.º 28
0
 private void Write()
 {
     RuntimeLogger.Log(this);
 }
Ejemplo n.º 29
0
 public static void Log(string log)
 {
     Global.MsgPublish(log);
     RuntimeLogger.Log(log);
 }
        static void initSiteSearch(string sitePath)
        {
            if (_SiteSearch == null)
            {
                lock (loc)
                    if (_SiteSearch == null)
                    {
                        SearchIndexer searchIndexer = Ingeniux.Search.SearchIndexer.Get(RuntimeLogger.GetLogger(sitePath));
                        _SiteSearch = new SiteSearch(searchIndexer.Logger);

                        System.Web.HttpContext.Current.Application["SiteSearch"] = _SiteSearch;

                        //start indexing service, use runtime logger
                        searchIndexer.Start(_SiteSearch);
                    }
            }
        }