Esempio n. 1
0
        protected void GenerateLogs(Dictionary <string, string> data, string user, Direction dir, GeneratorSetting setting, Dictionary <Core.Visualizers.Types, Logger.Appender> loggers)
        {
            if (data == null || loggers == null)
            {
                return;
            }

            if (haveStater)
            {
                Stater.MaxPosition = setting.MaxResults < 100 ? setting.MaxResults : 100;
            }

            var curPos = 0;
            var arr    = data.Values.ToArray();

            foreach (var key in loggers.Keys)
            {
                var logger   = loggers[key];
                var logEvent = Core.Visualizers.TypeLogEvent[key]
                               .GetConstructor(Type.EmptyTypes)
                               .Invoke(Type.EmptyTypes) as LogEvent;
                logEvent.Date   = DateTime.Now;
                logEvent.Action = "A";

                foreach (var item in arr)
                {
                    if (haveStater && curPos++ % 100 == 0)
                    {
                        Stater.SetState("Generate...", 0);
                    }

                    switch (dir)
                    {
                    case Direction.visible:
                        logEvent.User     = user;
                        logEvent.FileName = item;
                        break;

                    case Direction.incoming:
                        logEvent.User     = item;
                        logEvent.FileName = user;
                        break;
                    }
                    logger.Append(logEvent);
                    if (haveStater)
                    {
                        Stater.Inc();
                    }

                    if (curPos >= setting.MaxResults)
                    {
                        break;
                    }
                }
            }
        }
Esempio n. 2
0
        protected override void doGenerate(GeneratorSetting setting, string word, int depth)
        {
            if (string.IsNullOrWhiteSpace(word) || setting == null)
            {
                return;
            }

            curWord = word;

            var acts = Service.Activities.Search(word);

            if (setting.UseDateRange)
            {
                setting.MaxResults = 20;
            }

            var    step     = setting.MaxResults / (double)20;
            string nextPage = string.Empty;

            if (users == null)
            {
                users = new Dictionary <string, bool>();
            }

            users[word] = true;

            while (step != 0)
            {
                var nextResults = 20;
                if (step-- < 1)
                {
                    nextResults = (int)((step + 1) * 20);
                    step        = 0;
                }

                step = step == 0 && setting.UseDateRange ? 1 : step;

                acts.MaxResults = nextResults;
                acts.PageToken  = nextPage;
                acts.OrderBy    = Google.Apis.Plus.v1.ActivitiesResource.OrderBy.Recent;

                if (haveStater)
                {
                    Stater.MaxPosition = nextResults;
                    Stater.SetState("Load feeds ...");
                }

                Dictionary <Activity, ActivityCont> dicdate = null;

                try {
                    var feed = acts.Fetch();

                    if (dicdate == null)
                    {
                        dicdate = new Dictionary <Activity, ActivityCont>();
                    }
                    dicdate.Clear();

                    nextPage = null;
                    if (feed.Error == null)
                    {
                        nextPage = feed.NextPageToken;
                        if (string.IsNullOrWhiteSpace(nextPage))
                        {
                            step            = 0;
                            Stater.Position = Stater.MaxPosition;
                        }

                        if (haveStater)
                        {
                            Stater.MaxPosition = feed.Items.Count;
                            Stater.SetState("Parsing ...");
                        }

                        foreach (var item in feed.Items)
                        {
                            if (setting.UseDateRange && !InRange(setting.DateFrom, setting.DateTo, item.Published))
                            {
                                if (IsOutLeft(setting.DateFrom, item.Published))
                                {
                                    step = 0;
                                    break;
                                }
                                continue;
                            }

                            var ditem = dicdate[item] = new ActivityCont();

                            if (haveStater)
                            {
                                Stater.Inc();
                            }
                        }

                        GenerateLogs(dicdate, setting, loggers);
                    }
                    else
                    {
                        WriteLog(feed.Error.ToString(), this);
                    }
                }
                catch (Exception e) {
                    WriteLog(e, this);
                    e.ShowError();
                    step = 0;
                }
            }
        }
Esempio n. 3
0
        private void DoGenerate(GeneratorSetting setting, string pid, WebClient webc, string user, int deep = 0)
        {
            var fileReq = new FileInfo(@"tempdata\" + pid);

            foreach (Direction dir in Enum.GetValues(typeof(Direction)))
            {
                try {
                    if (fileReq.Exists)
                    {
                        fileReq.Delete();
                    }

                    if (haveStater)
                    {
                        Stater.MaxPosition = 2;
                        Stater.SetState("Load data ...", 0);
                    }

                    var request = "https://plus.google.com/u/0/_/socialgraph/lookup/" + dir.ToString() + "/?o=%5Bnull%2Cnull%2C%22" + pid + "%22%5D&rt=j&n=" + setting.MaxResults.ToString();

                    busy = true;
                    webc.DownloadFile(new Uri(request), fileReq.FullName);

                    if (!errorLoad)
                    {
                        try {
                            fileReq.Refresh();
                            if (fileReq.Exists && fileReq.Length > 0)
                            {
                                var work = "";
                                using (var rd = fileReq.OpenText()) {
                                    work = rd.ReadToEnd().Replace("\n", "");
                                }
                                fileReq.Delete();

                                var users = new Dictionary <string, string>();

                                Regex.Replace(work, @".*?\[\[,," + "\\\"" + @"(\d{21})" + "\\\"" + ".*?\\\"(.+?\\\").*?",
                                              new MatchEvaluator(delegate(Match m) {
                                    if (m.Success)
                                    {
                                        if (m.Groups.Count > 1)
                                        {
                                            if (!users.ContainsKey(m.Groups[1].Value))
                                            {
                                                users[m.Groups[1].Value] = m.Groups[2].Value.Replace("\"", "");
                                            }
                                        }
                                    }
                                    return("");
                                }));

                                GenerateLogs(users, user, dir, setting, loggers);

                                if (deep > 0)
                                {
                                    var i = 0;
                                    foreach (var item in users)
                                    {
                                        if (!completeUser.Keys.Contains(item.Key) && i++ <= setting.MaxResults)
                                        {
                                            completeUser[item.Key] = true;
                                        }
                                        else
                                        {
                                            continue;
                                        }
                                        DoGenerate(setting, item.Key, webc, item.Value, deep - 1);
                                    }
                                }
                            }
                        }
                        catch (Exception e) {
                            WriteLog(e, this);
                        }
                    }
                }
                catch (Exception e) {
                    WriteLog(new Exception(dir == Direction.visible ?
                                           "Perhaps the " + user + " hide users, that in him's circles." :
                                           "Perhaps the " + user + " has hidden users who have it in circles", e), this);
                }
            }
        }