コード例 #1
0
ファイル: NianObserver.cs プロジェクト: hxdnshx/STKProject
        protected override void Run()
        {
            if (IsFirstRun && _isDeferedLogin)
            {
                waitToken.WaitHandle.WaitOne(1000);
                Login();
            }
            if (IsFirstRun && !IsTest)
            {
                waitToken.WaitHandle.WaitOne(new Random().Next(0, 100000));
            }

            var value = DiffDetected;

            if (_isFirstRun)
            {
                DiffDetected = null;
            }
            using (var transaction = context.Database.BeginTransaction())
            {
                foreach (var uid in TargetUID.Split(',').Select(str => int.Parse(str)))
                {
                    try
                    {
                        var data = context.UserInfo.SingleOrDefault(r => r.UserId == uid);
                        if (data == null)
                        {
                            data        = new User();
                            data.UserId = uid;
                            context.UserInfo.Add(data);
                        }

                        currentTime = DateTime.Now;
                        //Status Data Compare
                        var userData = api.GetUserData(TargetUID.ToString());
                        var result   = userData["user"] as JObject;
                        uName = result["name"].Value <string>();
                        foreach (var obj in result)
                        {
                            var val = obj.Value as JValue;
                            if (val != null)
                            {
                                var targetValue = obj.Value.Value <string>();
                                var sourceValue = "";
                                if (data.Status.ContainsKey(obj.Key))
                                {
                                    sourceValue = data.Status[obj.Key];
                                }
                                if (sourceValue != targetValue)
                                {
                                    data.Status[obj.Key] = targetValue;
                                    DiffDetected?.Invoke(
                                        "http://nian.so/#!/user/" + TargetUID,
                                        uName + "修改了" + obj.Key,
                                        uName + "修改了" + obj.Key + ",从" + sourceValue + "变为" + targetValue,
                                        "Nian." + TargetUID + ".UserInfo." + obj.Key);
                                }
                            }
                        }

                        Console.WriteLine("wwww" + data);
                        GetDreamList(uid, context);

                        currentPeroid++;
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                        Console.WriteLine("Module" + Alias + " Throw an Exception");
                    }
                }
            }

            context.SaveChanges();

            if (_isFirstRun)
            {
                _isFirstRun  = false;
                DiffDetected = value;
            }
            Console.WriteLine(Alias + ":Data Fetched");
        }
コード例 #2
0
        protected override void Run()
        {
            if (IsFirstRun && _isDeferedLogin)
            {
                waitToken.WaitHandle.WaitOne(1000);
                Login();
            }
            if (IsFirstRun && !IsTest)
            {
                waitToken.WaitHandle.WaitOne(new Random().Next(0, 100000));
            }
            var col   = db.GetCollection <NianData>();
            var value = DiffDetected;

            if (_isFirstRun)
            {
                DiffDetected = null;
            }
            var trans = db.BeginTrans();

            try {
                currentTime = DateTime.Now;
                //Status Data Compare
                var userData = api.GetUserData(TargetUID.ToString());
                var result   = userData["user"] as JObject;
                uName = result["name"].Value <string>();
                foreach (var obj in result)
                {
                    var val = obj.Value as JValue;
                    if (val != null)
                    {
                        var targetValue = obj.Value.Value <string>();
                        var sourceValue = "";
                        if (data.ListItems.ContainsKey(obj.Key))
                        {
                            sourceValue = data.ListItems[obj.Key];
                        }
                        if (sourceValue != targetValue)
                        {
                            data.ListItems[obj.Key] = targetValue;
                            DiffDetected?.Invoke(
                                "http://nian.so/#!/user/" + TargetUID,
                                uName + "修改了" + obj.Key,
                                uName + "修改了" + obj.Key + ",从" + sourceValue + "变为" + targetValue,
                                "Nian." + TargetUID + ".UserInfo." + obj.Key);
                        }
                    }
                }
                Console.WriteLine("wwww" + data);
                GetDreamList(TargetUID, data);
                col.Update(data);

                currentPeroid++;
            }
            catch (Exception e) {
                Console.WriteLine(e);
                Console.WriteLine("Module" + Alias + " Throw an Exception");
            }
            finally {
                trans.Commit();
            }
            if (_isFirstRun)
            {
                _isFirstRun  = false;
                DiffDetected = value;
            }
            Console.WriteLine(Alias + ":Data Fetched");
        }