コード例 #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
ファイル: Program.cs プロジェクト: hxdnshx/STKProject
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            if (args.Length != 2)
            {
                return;
            }
            if (!File.Exists(args[0]))
            {
                return;
            }
            LiteDatabase db      = new LiteDatabase(args[0]);
            var          oldData = db.GetCollection <Stalker.NianData>().FindOne(Query.All());
            var          newData = new STK.NianContext(args[1]);

            newData.Database.EnsureCreated();
            {
                //UserInfo
                var status = new STK.UserStatus();
                status.Status.AddRange(oldData.ListItems);
                status.UserId = Convert.ToInt32(oldData.ListItems["uid"]);
                newData.UserInfo.Add(status);
            }

            {
                //Dreams Steps Comments
                foreach (var oldDataDream in oldData.Dreams)
                {
                    var newDataDream = new STK.Dream();
                    newDataDream.DreamId = Convert.ToInt32(oldDataDream.Status["id"]);
                    newDataDream.Status.AddRange(oldDataDream.Status);
                    if (newDataDream.Steps == null)
                    {
                        newDataDream.Steps = new List <STK.Step>();
                    }
                    newDataDream.Steps.AddRange(oldDataDream.Steps.Select(steps =>
                    {
                        var newStep    = new STK.Step();
                        newStep.StepId = Convert.ToInt32(steps.Status["sid"]);
                        newStep.Images.AddRange(steps.Images);
                        newStep.IsRemoved = steps.IsRemoved;
                        newStep.Status.AddRange(steps.Status);
                        newStep.Comments = new List <STK.Comment>(steps.Comments.Select(comment =>
                        {
                            STK.Comment newComment = new STK.Comment();
                            newComment.CommentId   = Convert.ToInt32(comment.Status["id"]);
                            newComment.Status.AddRange(comment.Status);
                            return(newComment);
                        }));
                        return(newStep);
                    }));
                    newData.Dreams.Add(newDataDream);
                }
            }

            newData.SaveChanges();
            foreach (var steps in newData.Steps)
            {
                Console.WriteLine(steps.StepId);
            }
        }