Inheritance: Core.GeneratorSetting
示例#1
0
        protected virtual void GenerateLogs(Dictionary <Activity, ActivityCont> data,
                                            GeneratorSetting setting, Dictionary <Visualizers.Types, Appender> loggers)
        {
            if (haveStater)
            {
                Stater.StateLabel = "Generation ...";
            }

            if (haveStater)
            {
                Stater.MaxPosition = data.Count * loggers.Count;
                Stater.SetState("Generate logs ...", 0);
            }

            foreach (var log in loggers.Keys)
            {
                var rules = setting.Rules[log];

                foreach (var dicitem in data)
                {
                    setting.Methods[log](loggers, log, rules, dicitem);

                    //LogGen(loggers, log.Key, rules, dicitem);

                    if (haveStater)
                    {
                        Stater.Inc();
                    }
                }
            }
        }
示例#2
0
        public GeneratorSetting Clone()
        {
            var item = new GeneratorSetting();

            var arr = this.GetType().GetProperties().ToArray();

            foreach (var prop in arr)
            {
                prop.SetValue(item, prop.GetValue(this, null), null);
            }

            return(item);
        }
示例#3
0
        private void Generate(string idProfile, StateControl sc, Visualizers.Types flags, Dictionary <Visualizers.Types, string> filenames)
        {
            var sett = new GeneratorSetting()
            {
                ProfileID    = /*"101113754039426612780"*/ idProfile,
                Rules        = rules,
                VisLogs      = (Visualizers.Types)flags,
                LogFiles     = filenames,
                MaxResults   = Convert.ToInt32(nudMaxRes.Value),
                MaxComments  = Convert.ToInt32(nudMaxComment.Value),
                MaxPluses    = Convert.ToInt32(nudMaxPlus.Value),
                MaxReshares  = Convert.ToInt32(nudMaxReshare.Value),
                Deep         = cbDeep.Checked ? Convert.ToInt32(nudDeep.Value) : 0,
                UseDateRange = cbDateRange.Checked,
                DateFrom     = Convert.ToDateTime(dtpFrom.Value.Date),
                DateTo       = Convert.ToDateTime(dtpTo.Value.AddDays(1).Date)
            };

            if (tcGooglePlus.SelectedTab == tpGPUsers)
            {
                sett.Methods = new Dictionary <Visualizers.Types, GeneratorLogsMeth> {
                    //UD
                    { Visualizers.Code_swarm, UDGenerator.LogGen },
                    { Visualizers.Gource, Generator.LogGen },
                    { Visualizers.Logstalgia, Generator.LogGen },
                    { Visualizers.Gephi, Generator.LogGen },
                };
                if (cbFGraph.Checked)
                {
                    new FollowersGenerator(apikey.Text, sc).Run(sett);
                }
                else
                {
                    (Program.OAuth2 != null ? new Generator(Program.OAuth2, sc) : new Generator(apikey.Text, sc)).Run(sett);
                }
            }
            else
            {
                sett.Methods = new Dictionary <Visualizers.Types, GeneratorLogsMeth> {
                    //UD
                    { Visualizers.Code_swarm, WordsSearchGenerator.LogGen },
                    { Visualizers.Gource, WordsSearchGenerator.LogGen },
                    { Visualizers.Logstalgia, WordsSearchGenerator.LogGen },
                    { Visualizers.Gephi, WordsSearchGenerator.LogGen },
                };
                (Program.OAuth2 != null ? new WordsSearchGenerator(Program.OAuth2, sc) : new WordsSearchGenerator(apikey.Text, sc)).Run(sett);
            }
        }
示例#4
0
        protected virtual void doGenerate(GeneratorSetting setting, string pid, int depth = 0)
        {
            if (string.IsNullOrWhiteSpace(pid) || setting == null)
            {
                return;
            }

            var acts = Service.Activities.List(pid, setting.Collection);

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

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

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

            users[pid] = true;

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

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

                acts.MaxResults = nextResults;
                acts.PageToken  = nextPage;

                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 (item.Object != null)
                            {
                                if (item.Verb == "share" &&
                                    !string.IsNullOrWhiteSpace(item.Object.Id))
                                {
                                    try {
                                        ditem.Share = Service.Activities.Get(item.Object.Id).Fetch();
                                    }
                                    catch (Exception e) {
                                        WriteLog(e, this);
                                    }
                                }

                                if (item.Object.Replies.TotalItems > 0)
                                {
                                    var plser = Service.Comments.List(item.Id);
                                    plser.MaxResults = setting.MaxComments;
                                    try {
                                        var listpl = plser.Fetch();

                                        ditem.Comments = listpl.Items;
                                    }
                                    catch (Exception e) {
                                        WriteLog(e, this);
                                    }
                                }

                                if (item.Object.Plusoners.TotalItems > 0)
                                {
                                    var plser = Service.People.ListByActivity(item.Id, PeopleResource.Collection.Plusoners);
                                    plser.MaxResults = setting.MaxPluses;

                                    try {
                                        var listpl = plser.Fetch();

                                        ditem.Plusers = listpl.Items;
                                    }
                                    catch (Exception e) {
                                        WriteLog(e, this);
                                    }
                                }

                                if (item.Object.Resharers.TotalItems > 0)
                                {
                                    var plser = Service.People.ListByActivity(item.Id, PeopleResource.Collection.Resharers);
                                    plser.MaxResults = setting.MaxReshares;

                                    try {
                                        var listpl = plser.Fetch();

                                        ditem.Sharers = listpl.Items;
                                    }
                                    catch (Exception e) {
                                        WriteLog(e, this);
                                    }
                                }
                            }

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

                        GenerateLogs(dicdate, setting, loggers);

                        if (depth > 0)
                        {
                            foreach (var ditem in dicdate)
                            {
                                try {
                                    var share = ditem.Value.Share;
                                    if (share != null)
                                    {
                                        if (share.Actor != null &&
                                            !string.IsNullOrWhiteSpace(share.Actor.Id) &&
                                            !users.ContainsKey(share.Actor.Id))
                                        {
                                            users[share.Actor.Id] = true;
                                            doGenerate(setting, share.Actor.Id, depth - 1);
                                        }
                                    }
                                }
                                catch (Exception e) {
                                    WriteLog(e, this);
                                }


                                try {
                                    var coms = ditem.Value.Comments;

                                    if (coms != null)
                                    {
                                        foreach (var sitem in coms)
                                        {
                                            if (!users.ContainsKey(sitem.Actor.Id))
                                            {
                                                users[sitem.Actor.Id] = true;
                                                doGenerate(setting, sitem.Actor.Id, depth - 1);
                                            }
                                            if (haveStater)
                                            {
                                                Stater.Inc();
                                            }
                                        }
                                    }
                                }
                                catch (Exception e) {
                                    WriteLog(e, this);
                                }

                                try {
                                    var pluses = ditem.Value.Plusers;
                                    if (pluses != null)
                                    {
                                        foreach (var sitem in pluses)
                                        {
                                            if (!users.ContainsKey(sitem.Id))
                                            {
                                                users[sitem.Id] = true;
                                                doGenerate(setting, sitem.Id, depth - 1);
                                            }
                                            if (haveStater)
                                            {
                                                Stater.Inc();
                                            }
                                        }
                                    }
                                }
                                catch (Exception e) {
                                    WriteLog(e, this);
                                }

                                try {
                                    var shares = ditem.Value.Sharers;
                                    if (shares != null)
                                    {
                                        foreach (var sitem in shares)
                                        {
                                            if (!users.ContainsKey(sitem.Id))
                                            {
                                                users[sitem.Id] = true;
                                                doGenerate(setting, sitem.Id, depth - 1);
                                            }
                                            if (haveStater)
                                            {
                                                Stater.Inc();
                                            }
                                        }
                                    }
                                }
                                catch (Exception e) {
                                    WriteLog(e, this);
                                }
                            }

                            if (haveStater)
                            {
                                Stater.Inc();
                            }
                        }
                    }
                    else
                    {
                        WriteLog(feed.Error.ToString(), this);
                    }
                }
                catch (Exception e) {
                    WriteLog(e, this);
                    e.ShowError();
                    step = 0;
                }
            }
        }
示例#5
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;
                }
            }
        }
示例#6
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;
                    }
                }
            }
        }
示例#7
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);
                }
            }
        }