public static IPattern SelectPattern(PatternOption pattern)
        {
            switch (pattern)
            {
            case PatternOption.First:
                return(new FirstPattern());

            case PatternOption.Second:
                return(new SecondPattern());

            case PatternOption.Third:
                return(new ThirdPattern());

            case PatternOption.Fourth:
                return(new FourthPattern());

            case PatternOption.Fifth:
                return(new FifthPattern());

            case PatternOption.Sixth:
                return(new SixthPattern());

            case PatternOption.Seventh:
                return(new SeventhPattern());

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Beispiel #2
0
 public static string ToLongString(this PatternOption opt)
 {
     if (opt == PatternOption.None)
     {
         return("");
     }
     if (stringBuilder == null)
     {
         stringBuilder = new StringBuilder();
     }
     else
     {
         stringBuilder.Length = 0;
     }
     foreach (PatternOption item in Enum.GetValues(typeof(PatternOption)))
     {
         if (opt.HasFlag(item) & item != PatternOption.None)
         {
             stringBuilder.Append(item.ToString());
             stringBuilder.Append(", ");
         }
     }
     stringBuilder.Length -= 2;
     return(stringBuilder.ToString());
 }
        static public void LogGen(Dictionary <Visualizers.Types, Appender> loggers,
                                  Visualizers.Types typelog,
                                  Dictionary <Rules, string> rules,
                                  KeyValuePair <Activity, ActivityCont> dicitem)
        {
            var item   = dicitem.Key;
            var action = "A";

            var logEvent = Visualizers.TypeLogEvent[typelog]
                           .GetConstructor(Type.EmptyTypes)
                           .Invoke(Type.EmptyTypes) as LogEvent;

            var po = new PatternOption();

            po.Post    = item;
            po.Type    = TypePattern.post;
            po.Pattern = rules[Rules.NotShare];

            po.SharePath = ReplacePattern(po);

            po.Type    = (TypePattern)Enum.Parse(typeof(TypePattern), item.Verb, true);
            po.Type    = TypePattern.post;
            po.Pattern = rules[Rules.Post];

            var sharafile = po.PostFileName;

            po.PostFileName   = ReplacePattern(po);
            logEvent.User     = typelog == Visualizers.Types.Code_swarm ? curWord : GetActor(item.Actor, typelog);
            logEvent.Date     = DateTime.Parse(item.Published);
            logEvent.Action   = typelog == Visualizers.Types.Logstalgia ? "post" : action;
            logEvent.FileName = po.PostFileName;
            if (logEvent is LogstalgiaEvent)
            {
                (logEvent as LogstalgiaEvent).Size = item.Object != null?item.Object.Content.Length.ToString() : "100";
            }
            if ((logEvent is GephiLogEvent))
            {
                (logEvent as GephiLogEvent).From = curWord;
            }

            loggers[typelog].Append(logEvent);
        }
        public static void LogGen(Dictionary<Visualizers.Types, Appender> loggers,
            Visualizers.Types typelog,
            Dictionary<Rules, string> rules,
            KeyValuePair<Activity, ActivityCont> dicitem)
        {
            var item = dicitem.Key;
            var action = "A";

            var logEvent = Visualizers.TypeLogEvent[typelog]
                .GetConstructor(Type.EmptyTypes)
                    .Invoke(Type.EmptyTypes) as LogEvent;

            var po = new PatternOption();

            po.Post = item;
            po.Type = TypePattern.post;
            po.Pattern = rules[Rules.NotShare];

            po.SharePath = ReplacePattern(po);

            po.Type = (TypePattern)Enum.Parse(typeof(TypePattern), item.Verb, true);
            po.Type = TypePattern.post;
            po.Pattern = rules[Rules.Post];

            var sharafile = po.PostFileName;

            po.PostFileName = ReplacePattern(po);
            logEvent.User = typelog == Visualizers.Types.Code_swarm ? curWord : GetActor(item.Actor, typelog);
            logEvent.Date = DateTime.Parse(item.Published);
            logEvent.Action = typelog == Visualizers.Types.Logstalgia ? "post" : action;
            logEvent.FileName = po.PostFileName;
            if (logEvent is LogstalgiaEvent)
                (logEvent as LogstalgiaEvent).Size = item.Object != null ? item.Object.Content.Length.ToString() : "100";
            if ((logEvent is GephiLogEvent)) {
                (logEvent as GephiLogEvent).From = curWord;
            }

            loggers[typelog].Append(logEvent);
        }
Beispiel #5
0
 public SimplePattern(string pattern, PatternOption options) : base(pattern, options)
 {
     if (string.IsNullOrEmpty(pattern))
     {
         throw new ArgumentException("Pattern string is null or empty", nameof(pattern));
     }
     if (pattern[0] == '*' && pattern[pattern.Length - 1] == '*')
     {
         if (pattern.Length < 3)
         {
             throw new ArgumentException("Invalid pattern string", nameof(pattern));
         }
         subString = pattern.Substring(1, pattern.Length - 2);
         contains  = true;
     }
     else if (pattern[0] == '*')
     {
         if (pattern.Length < 2)
         {
             throw new ArgumentException("Invalid pattern string", nameof(pattern));
         }
         subString = pattern.Substring(1);
         endsWith  = true;
     }
     else if (pattern[pattern.Length - 1] == '*')
     {
         if (pattern.Length < 2)
         {
             throw new ArgumentException("Invalid pattern string", nameof(pattern));
         }
         subString  = pattern.Substring(0, pattern.Length - 2);
         startsWith = true;
     }
     else
     {
         subString = pattern;
     }
 }
Beispiel #6
0
        protected static string ReplacePattern(PatternOption option)
        {
            if (option == null)
                return string.Empty;

            var result = option.Pattern;
            var prefix = string.Empty;
            var completed = false;

            PatternItem item = null;

            do {
                switch (option.Type) {
                    case TypePattern.share:
                    case TypePattern.checkin:
                    case TypePattern.post:
                        var post = option.Type == TypePattern.share ? option.Share : option.Post;

                        item = null;
                        if (post != null)
                            item = new PatternItem() {
                                Type = string.IsNullOrWhiteSpace(prefix) ? GetTypePatternName(option.Type) : "{type}",
                                Id = post.Id,
                                TimeSpan = DateString(post.Published, DateType.TimeSpan),
                                Date = DateString(post.Published, DateType.Date),
                                Time = DateString(post.Published, DateType.Time),
                                DateTime = DateString(post.Published, DateType.DateTime),
                                ActorName = post.Actor.DisplayName,
                                Actor = post.Actor.Id,
                                SharePath = !string.IsNullOrWhiteSpace(option.SharePath) ? option.SharePath : "{sharepath}",
                                PostFileName = !string.IsNullOrWhiteSpace(option.PostFileName) ? option.PostFileName : "{postfilename}",
                                Title = !string.IsNullOrWhiteSpace(post.Title) ? ForTitle(post.Title, 100) :
                                    (string.IsNullOrWhiteSpace(post.Object.Content) ? post.Id :
                                        ForTitle(Regex.Replace(post.Object.Content, "<.*?>", "", RegexOptions.IgnoreCase | RegexOptions.Multiline), 100))

                            };

                        if (!(completed = option.Type != TypePattern.share)) {
                            option.Type = TypePattern.post;
                        }
                        break;
                    case TypePattern.comment:
                        var comment = option.Comment;

                        item = null;
                        if (comment != null)
                            item = new PatternItem() {
                                Type = string.IsNullOrWhiteSpace(prefix) ? GetTypePatternName(option.Type) : "{type}",
                                Id = comment.Id,
                                TimeSpan = DateString(comment.Published, DateType.TimeSpan),
                                Date = DateString(comment.Published, DateType.Date),
                                Time = DateString(comment.Published, DateType.Time),
                                DateTime = DateString(comment.Published, DateType.DateTime),
                                ActorName = comment.Actor.DisplayName,
                                Actor = comment.Actor.Id,
                                SharePath = !string.IsNullOrWhiteSpace(option.SharePath) ? option.SharePath : "{sharepath}",
                                PostFileName = !string.IsNullOrWhiteSpace(option.PostFileName) ? option.PostFileName : "{postfilename}",
                                Title = comment.Object == null || string.IsNullOrWhiteSpace(comment.Object.Content) ?
                                comment.Id : ForTitle(Regex.Replace(comment.Object.Content, "<.*?>", "", RegexOptions.IgnoreCase | RegexOptions.Multiline), 100)
                            };
                        option.Type = TypePattern.post;
                        break;
                    case TypePattern.plus:
                    case TypePattern.reshare:
                        var person = option.Person;

                        item = null;
                        if (person != null) {
                            item = new PatternItem() {
                                Type = string.IsNullOrWhiteSpace(prefix) ? GetTypePatternName(option.Type) : "{type}",
                                Id = person.Id,
                                TimeSpan = DateString(DateTime.Now.ToString(), DateType.TimeSpan),
                                Date = DateString(DateTime.Now.ToString(), DateType.Date),
                                Time = DateString(DateTime.Now.ToString(), DateType.Time),
                                DateTime = DateString(DateTime.Now.ToString(), DateType.DateTime),
                                ActorName = person.DisplayName,
                                Actor = person.Id,
                                SharePath = !string.IsNullOrWhiteSpace(option.SharePath) ? option.SharePath : "{sharepath}",
                                PostFileName = !string.IsNullOrWhiteSpace(option.PostFileName) ? option.PostFileName : "{postfilename}",
                                Title = "{posttitle}"
                            };
                            post = option.Post;

                            if (post != null) {
                                item.TimeSpan = DateString(post.Published, DateType.TimeSpan);
                                item.Date = DateString(post.Published, DateType.Date);
                                item.Time = DateString(post.Published, DateType.Time);
                                item.DateTime = DateString(post.Published, DateType.DateTime);
                            }
                        }
                        option.Type = TypePattern.post;
                        break;
                }

                if (item != null && !string.IsNullOrWhiteSpace(result))
                    result = ApplyPattern(result, item, prefix, new string[] { "type", "sharepath", "postfilename" });

                if (!completed)
                    prefix = "post";
                else
                    break;
            } while (!completed);

            if (result == "{type}:{title}")
                result = "вот же хер";

            return ReplaceForLog(result.Replace("//", "/"));
        }
Beispiel #7
0
        public static void LogGen(Dictionary<Visualizers.Types, Appender> loggers, 
            Visualizers.Types typelog,
            Dictionary<Rules, string> rules,
            KeyValuePair<Activity, ActivityCont> dicitem)
        {
            var item = dicitem.Key;
            var action = "A";

            var logEvent = Visualizers.TypeLogEvent[typelog]
                .GetConstructor(Type.EmptyTypes)
                    .Invoke(Type.EmptyTypes) as LogEvent;

            var po = new PatternOption();

            var share = dicitem.Value.Share;
            if (share != null) {
                po.Post = item;
                po.Share = share;
                po.Pattern = rules[Rules.SharePath];
                po.Type = TypePattern.share;

                po.SharePath = ReplacePattern(po);

                po.Pattern = rules[Rules.ShareName];
                po.PostFileName = po.SharePath + ReplacePattern(po);
                po.PostFileName = po.PostFileName.Replace("//", "/");

                logEvent.User = GetActor(share.Actor, typelog);
                logEvent.Date = DateTime.Parse(share.Published);
                logEvent.Action = typelog == Visualizers.Types.Logstalgia ? "share" : action;
                logEvent.FileName = po.PostFileName;
                if (logEvent is LogstalgiaEvent)
                    (logEvent as LogstalgiaEvent).Size =
                        !string.IsNullOrWhiteSpace(share.Title) ?
                            share.Title.Length.ToString() :
                                string.IsNullOrWhiteSpace(item.Title) ?
                                    item.Title.Length.ToString() : "200";
                loggers[typelog].Append(logEvent);

                action = "M";
            }
            else {
                po.Post = item;
                po.Type = TypePattern.post;
                po.Pattern = rules[Rules.NotShare];

                po.SharePath = ReplacePattern(po);
            }

            po.Type = (TypePattern)Enum.Parse(typeof(TypePattern), item.Verb, true);
            if (po.Type == TypePattern.share && share == null)
                po.Type = TypePattern.post;
            po.Pattern = rules[Rules.Post];

            var sharafile = po.PostFileName;

            po.PostFileName = ReplacePattern(po);
            logEvent.User = GetActor(item.Actor, typelog);
            logEvent.Date = DateTime.Parse(item.Published);
            logEvent.Action = typelog == Visualizers.Types.Logstalgia ? "post" : action;
            logEvent.FileName = po.PostFileName;
            if (logEvent is LogstalgiaEvent)
                (logEvent as LogstalgiaEvent).Size = item.Object != null ? item.Object.Content.Length.ToString() : "100";
            if (share != null && (logEvent is GephiLogEvent)) {
                (logEvent as GephiLogEvent).From = sharafile;
            }

            loggers[typelog].Append(logEvent);

            if (item.Object != null) {

                if (item.Object.Replies.TotalItems > 0) {
                    try {
                        var listpl = dicitem.Value.Comments;

                        po.Pattern = rules[Rules.Comment];
                        po.Type = TypePattern.comment;

                        foreach (var pl in listpl) {
                            po.Comment = pl;
                            po.Type = TypePattern.comment;
                            var fnp = ReplacePattern(po);

                            logEvent.User = GetActor(pl.Actor, typelog);
                            logEvent.Date = DateTime.Parse(pl.Published);
                            logEvent.Action = typelog == Visualizers.Types.Logstalgia ? "comment" : "A";
                            logEvent.FileName = fnp;
                            if (logEvent is LogstalgiaEvent)
                                (logEvent as LogstalgiaEvent).Size = pl.Object != null ? pl.Object.Content.Length.ToString() : "1";
                            if (logEvent is GephiLogEvent)
                                (logEvent as GephiLogEvent).From = po.PostFileName;

                            loggers[typelog].Append(logEvent);
                        }
                    }
                    catch (Exception e) {
                        WriteLog(e, "Generator.LogGen");
                    }
                }

                long ticks = 0;

                if (item.Object.Plusoners.TotalItems > 0) {
                    try {
                        var listpl = dicitem.Value.Plusers;

                        po.Pattern = rules[Rules.Plus];

                        foreach (var pl in listpl) {
                            po.Person = pl;
                            po.Type = TypePattern.plus;
                            var fnp = ReplacePattern(po);

                            logEvent.User = GetActor(pl, typelog);
                            logEvent.Date = DateTime.Parse(item.Published).AddMinutes(ticks);
                            logEvent.Action = typelog == Visualizers.Types.Logstalgia ? "plus" : "A";
                            logEvent.FileName = fnp;
                            if (logEvent is LogstalgiaEvent)
                                (logEvent as LogstalgiaEvent).Size = "5";
                            if (logEvent is GephiLogEvent)
                                (logEvent as GephiLogEvent).From = po.PostFileName;

                            loggers[typelog].Append(logEvent);

                            ticks += 5;
                        }
                    }
                    catch (Exception e) {
                        WriteLog(e, "Generator.LogGen");
                    }
                }

                ticks = 0;

                if (item.Object.Resharers.TotalItems > 0) {
                    try {
                        var listpl = dicitem.Value.Sharers;

                        po.Pattern = rules[Rules.Plus];

                        foreach (var pl in listpl) {
                            po.Person = pl;
                            po.Type = TypePattern.reshare;
                            var fnp = ReplacePattern(po);

                            logEvent.User = GetActor(pl, typelog);
                            logEvent.Date = DateTime.Parse(item.Published).AddMinutes(ticks);
                            logEvent.Action = typelog == Visualizers.Types.Logstalgia ? "reshare" : "A";
                            logEvent.FileName = fnp;
                            if (logEvent is LogstalgiaEvent)
                                (logEvent as LogstalgiaEvent).Size = "5";
                            if (logEvent is GephiLogEvent)
                                (logEvent as GephiLogEvent).From = po.PostFileName;

                            loggers[typelog].Append(logEvent);

                            ticks += 5;
                        }
                    }
                    catch (Exception e) {
                        WriteLog(e, "Generator.LogGen");
                    }
                }
            }
        }
Beispiel #8
0
 public Pattern(string pattern, PatternOption options)
 {
     PatternString = pattern;
     Options       = options;
 }
Beispiel #9
0
        public static IEnumerable <Pattern> Parse(string patternFilePath)
        {
            var           result         = new List <Pattern>();
            PatternOption options        = PatternOption.None;
            PatternOption defaultOptions = PatternOption.File | PatternOption.MatchOnName | PatternOption.Simple;
            var           contents       = File.ReadAllLines(patternFilePath);

            foreach (string line in contents)
            {
                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }
                if (line.StartsWith("::", StringComparison.Ordinal))
                {
                    options = PatternOption.None;
                    string   optionString = line.Trim(new char[] { ' ', ':' });
                    string[] parts        = optionString.Split(' ');
                    foreach (string item in parts)
                    {
                        switch (item.ToUpper())
                        {
                        case "FILE":
                            options |= PatternOption.File;
                            break;

                        case "DIRECTORY":
                            options |= PatternOption.Directory;
                            break;

                        case "SIMPLE":
                            if (options.HasFlag(PatternOption.Regex))
                            {
                                throw new ArgumentException("REGEX and SIMPLE can not be combined.");
                            }
                            options |= PatternOption.Simple;
                            break;

                        case "REGEX":
                            if (options.HasFlag(PatternOption.Simple))
                            {
                                throw new ArgumentException("REGEX and SIMPLE can not be combined.");
                            }
                            options |= PatternOption.Regex;
                            break;

                        case "NAME":
                            options |= PatternOption.MatchOnName;
                            break;

                        case "PATH":
                            options |= PatternOption.MatchOnPath;
                            break;

                        default:
                            throw new ArgumentException($"Unknown pattern match option \"{item}\".");
                        }
                    }
                    if (!options.HasFlag(PatternOption.File) && !options.HasFlag(PatternOption.Directory))
                    {
                        throw new ArgumentException("FILE or DIRECTORY (or both) must be present i options.");
                    }
                    if (!options.HasFlag(PatternOption.Regex) && !options.HasFlag(PatternOption.Simple))
                    {
                        throw new ArgumentException("SIMPLE or REGEX must be present i options.");
                    }
                    if (!options.HasFlag(PatternOption.MatchOnName) && !options.HasFlag(PatternOption.MatchOnPath))
                    {
                        throw new ArgumentException("NAME or PATH (or both) must be present i options.");
                    }
                }
                else
                {
                    if (options == PatternOption.None)
                    {
                        options = defaultOptions;
                    }
                    string patternString = line.Trim();
                    if (options.HasFlag(PatternOption.Simple))
                    {
                        result.Add(new SimplePattern(patternString, options));
                    }
                    else
                    {
                        result.Add(new RegexPattern(patternString, options));
                    }
                }
            }
            return(result);
        }
Beispiel #10
0
 public RegexPattern(string pattern, PatternOption options) : base(pattern, options)
 {
     regex = new Regex(pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
 }
Beispiel #11
0
 public void ChangePattern(PatternOption pattern)
 {
     _pattern = PatternSelector.SelectPattern(pattern);
     IsRandom = false;
 }
Beispiel #12
0
        static public void LogGen(Dictionary <Visualizers.Types, Appender> loggers, Visualizers.Types typelog, Dictionary <Rules, string> rules, KeyValuePair <Activity, ActivityCont> dicitem)
        {
            var item = dicitem.Key;

            var action = "A";

            var po = new PatternOption();

            var share = dicitem.Value.Share;

            if (share != null)
            {
                po.Post    = item;
                po.Share   = share;
                po.Pattern = rules[Rules.SharePath];
                po.Type    = TypePattern.share;

                po.SharePath = ReplacePattern(po);

                po.Pattern      = rules[Rules.ShareName];
                po.PostFileName = po.SharePath + ReplacePattern(po);
                po.PostFileName = po.PostFileName.Replace("//", "/");

                loggers[typelog].Append(new LogEvent()
                {
                    User     = item.Object.Id,
                    Date     = DateTime.Parse(item.Published),
                    Action   = action,
                    FileName = po.PostFileName
                });

                action = "M";
            }
            else
            {
                po.Post    = item;
                po.Type    = TypePattern.post;
                po.Pattern = rules[Rules.NotShare];

                po.SharePath = ReplacePattern(po);
            }

            po.Type    = TypePattern.post;
            po.Pattern = rules[Rules.Post];

            po.PostFileName = ReplacePattern(po);

            loggers[typelog].Append(new LogEvent()
            {
                User     = item.Id,
                Date     = DateTime.Parse(item.Published),
                Action   = action,
                FileName = po.PostFileName
            });

            if (item.Object != null)
            {
                if (item.Object.Resharers.TotalItems > 0)
                {
                    try {
                        var listpl = dicitem.Value.Comments;
                        po.Pattern = rules[Rules.Comment];
                        po.Type    = TypePattern.comment;
                        foreach (var pl in listpl)
                        {
                            po.Comment = pl;
                            var fnp = ReplacePattern(po);

                            loggers[typelog].Append(new LogEvent()
                            {
                                User     = item.Id,
                                Date     = DateTime.Parse(item.Published),
                                Action   = "A",
                                FileName = fnp
                            });
                        }
                    }
                    catch (Exception e) {
                        WriteLog(e, "UDGenerator.LogGen");
                    }
                }

                long ticks = 0;

                if (item.Object.Plusoners.TotalItems > 0)
                {
                    try {
                        var listpl = dicitem.Value.Plusers;

                        po.Pattern = rules[Rules.Plus];
                        po.Type    = TypePattern.plus;

                        foreach (var pl in listpl)
                        {
                            po.Person = pl;
                            var fnp = ReplacePattern(po);

                            loggers[typelog].Append(new LogEvent()
                            {
                                User     = item.Id,
                                Date     = DateTime.Parse(item.Published).AddMinutes(ticks),
                                Action   = "A",
                                FileName = fnp
                            });

                            ticks += 5;
                        }
                    }
                    catch (Exception e) {
                        WriteLog(e, "UDGenerator.LogGen");
                    }
                }

                ticks = 0;

                if (item.Object.Resharers.TotalItems > 0)
                {
                    try {
                        var listpl = dicitem.Value.Sharers;

                        po.Pattern = rules[Rules.Plus];
                        po.Type    = TypePattern.reshare;

                        foreach (var pl in listpl)
                        {
                            po.Person = pl;
                            var fnp = ReplacePattern(po);

                            loggers[typelog].Append(new LogEvent()
                            {
                                User     = item.Id,
                                Date     = DateTime.Parse(item.Published).AddMinutes(ticks),
                                Action   = "A",
                                FileName = fnp
                            });

                            ticks += 5;
                        }
                    }
                    catch (Exception e) {
                        WriteLog(e, "UDGenerator.LogGen");
                    }
                }
            }
        }
Beispiel #13
0
        protected static string ReplacePattern(PatternOption option)
        {
            if (option == null)
            {
                return(string.Empty);
            }

            var result    = option.Pattern;
            var prefix    = string.Empty;
            var completed = false;

            PatternItem item = null;

            do
            {
                switch (option.Type)
                {
                case TypePattern.share:
                case TypePattern.checkin:
                case TypePattern.post:
                    var post = option.Type == TypePattern.share ? option.Share : option.Post;

                    item = null;
                    if (post != null)
                    {
                        item = new PatternItem()
                        {
                            Type         = string.IsNullOrWhiteSpace(prefix) ? GetTypePatternName(option.Type) : "{type}",
                            Id           = post.Id,
                            TimeSpan     = DateString(post.Published, DateType.TimeSpan),
                            Date         = DateString(post.Published, DateType.Date),
                            Time         = DateString(post.Published, DateType.Time),
                            DateTime     = DateString(post.Published, DateType.DateTime),
                            ActorName    = post.Actor.DisplayName,
                            Actor        = post.Actor.Id,
                            SharePath    = !string.IsNullOrWhiteSpace(option.SharePath) ? option.SharePath : "{sharepath}",
                            PostFileName = !string.IsNullOrWhiteSpace(option.PostFileName) ? option.PostFileName : "{postfilename}",
                            Title        = !string.IsNullOrWhiteSpace(post.Title) ? ForTitle(post.Title, 100) :
                                           (string.IsNullOrWhiteSpace(post.Object.Content) ? post.Id :
                                            ForTitle(Regex.Replace(post.Object.Content, "<.*?>", "", RegexOptions.IgnoreCase | RegexOptions.Multiline), 100))
                        }
                    }
                    ;

                    if (!(completed = option.Type != TypePattern.share))
                    {
                        option.Type = TypePattern.post;
                    }
                    break;

                case TypePattern.comment:
                    var comment = option.Comment;

                    item = null;
                    if (comment != null)
                    {
                        item = new PatternItem()
                        {
                            Type         = string.IsNullOrWhiteSpace(prefix) ? GetTypePatternName(option.Type) : "{type}",
                            Id           = comment.Id,
                            TimeSpan     = DateString(comment.Published, DateType.TimeSpan),
                            Date         = DateString(comment.Published, DateType.Date),
                            Time         = DateString(comment.Published, DateType.Time),
                            DateTime     = DateString(comment.Published, DateType.DateTime),
                            ActorName    = comment.Actor.DisplayName,
                            Actor        = comment.Actor.Id,
                            SharePath    = !string.IsNullOrWhiteSpace(option.SharePath) ? option.SharePath : "{sharepath}",
                            PostFileName = !string.IsNullOrWhiteSpace(option.PostFileName) ? option.PostFileName : "{postfilename}",
                            Title        = comment.Object == null || string.IsNullOrWhiteSpace(comment.Object.Content) ?
                                           comment.Id : ForTitle(Regex.Replace(comment.Object.Content, "<.*?>", "", RegexOptions.IgnoreCase | RegexOptions.Multiline), 100)
                        }
                    }
                    ;
                    option.Type = TypePattern.post;
                    break;

                case TypePattern.plus:
                case TypePattern.reshare:
                    var person = option.Person;

                    item = null;
                    if (person != null)
                    {
                        item = new PatternItem()
                        {
                            Type         = string.IsNullOrWhiteSpace(prefix) ? GetTypePatternName(option.Type) : "{type}",
                            Id           = person.Id,
                            TimeSpan     = DateString(DateTime.Now.ToString(), DateType.TimeSpan),
                            Date         = DateString(DateTime.Now.ToString(), DateType.Date),
                            Time         = DateString(DateTime.Now.ToString(), DateType.Time),
                            DateTime     = DateString(DateTime.Now.ToString(), DateType.DateTime),
                            ActorName    = person.DisplayName,
                            Actor        = person.Id,
                            SharePath    = !string.IsNullOrWhiteSpace(option.SharePath) ? option.SharePath : "{sharepath}",
                            PostFileName = !string.IsNullOrWhiteSpace(option.PostFileName) ? option.PostFileName : "{postfilename}",
                            Title        = "{posttitle}"
                        };
                        post = option.Post;

                        if (post != null)
                        {
                            item.TimeSpan = DateString(post.Published, DateType.TimeSpan);
                            item.Date     = DateString(post.Published, DateType.Date);
                            item.Time     = DateString(post.Published, DateType.Time);
                            item.DateTime = DateString(post.Published, DateType.DateTime);
                        }
                    }
                    option.Type = TypePattern.post;
                    break;
                }

                if (item != null && !string.IsNullOrWhiteSpace(result))
                {
                    result = ApplyPattern(result, item, prefix, new string[] { "type", "sharepath", "postfilename" });
                }

                if (!completed)
                {
                    prefix = "post";
                }
                else
                {
                    break;
                }
            } while (!completed);

            if (result == "{type}:{title}")
            {
                result = "вот же хер";
            }

            return(ReplaceForLog(result.Replace("//", "/")));
        }
Beispiel #14
0
        static public void LogGen(Dictionary <Visualizers.Types, Appender> loggers,
                                  Visualizers.Types typelog,
                                  Dictionary <Rules, string> rules,
                                  KeyValuePair <Activity, ActivityCont> dicitem)
        {
            var item   = dicitem.Key;
            var action = "A";

            var logEvent = Visualizers.TypeLogEvent[typelog]
                           .GetConstructor(Type.EmptyTypes)
                           .Invoke(Type.EmptyTypes) as LogEvent;

            var po = new PatternOption();

            var share = dicitem.Value.Share;

            if (share != null)
            {
                po.Post    = item;
                po.Share   = share;
                po.Pattern = rules[Rules.SharePath];
                po.Type    = TypePattern.share;

                po.SharePath = ReplacePattern(po);

                po.Pattern      = rules[Rules.ShareName];
                po.PostFileName = po.SharePath + ReplacePattern(po);
                po.PostFileName = po.PostFileName.Replace("//", "/");

                logEvent.User     = GetActor(share.Actor, typelog);
                logEvent.Date     = DateTime.Parse(share.Published);
                logEvent.Action   = typelog == Visualizers.Types.Logstalgia ? "share" : action;
                logEvent.FileName = po.PostFileName;
                if (logEvent is LogstalgiaEvent)
                {
                    (logEvent as LogstalgiaEvent).Size =
                        !string.IsNullOrWhiteSpace(share.Title) ?
                        share.Title.Length.ToString() :
                        string.IsNullOrWhiteSpace(item.Title) ?
                        item.Title.Length.ToString() : "200";
                }
                loggers[typelog].Append(logEvent);

                action = "M";
            }
            else
            {
                po.Post    = item;
                po.Type    = TypePattern.post;
                po.Pattern = rules[Rules.NotShare];

                po.SharePath = ReplacePattern(po);
            }

            po.Type = (TypePattern)Enum.Parse(typeof(TypePattern), item.Verb, true);
            if (po.Type == TypePattern.share && share == null)
            {
                po.Type = TypePattern.post;
            }
            po.Pattern = rules[Rules.Post];

            var sharafile = po.PostFileName;

            po.PostFileName   = ReplacePattern(po);
            logEvent.User     = GetActor(item.Actor, typelog);
            logEvent.Date     = DateTime.Parse(item.Published);
            logEvent.Action   = typelog == Visualizers.Types.Logstalgia ? "post" : action;
            logEvent.FileName = po.PostFileName;
            if (logEvent is LogstalgiaEvent)
            {
                (logEvent as LogstalgiaEvent).Size = item.Object != null?item.Object.Content.Length.ToString() : "100";
            }
            if (share != null && (logEvent is GephiLogEvent))
            {
                (logEvent as GephiLogEvent).From = sharafile;
            }

            loggers[typelog].Append(logEvent);

            if (item.Object != null)
            {
                if (item.Object.Replies.TotalItems > 0)
                {
                    try {
                        var listpl = dicitem.Value.Comments;

                        po.Pattern = rules[Rules.Comment];
                        po.Type    = TypePattern.comment;

                        foreach (var pl in listpl)
                        {
                            po.Comment = pl;
                            po.Type    = TypePattern.comment;
                            var fnp = ReplacePattern(po);

                            logEvent.User     = GetActor(pl.Actor, typelog);
                            logEvent.Date     = DateTime.Parse(pl.Published);
                            logEvent.Action   = typelog == Visualizers.Types.Logstalgia ? "comment" : "A";
                            logEvent.FileName = fnp;
                            if (logEvent is LogstalgiaEvent)
                            {
                                (logEvent as LogstalgiaEvent).Size = pl.Object != null?pl.Object.Content.Length.ToString() : "1";
                            }
                            if (logEvent is GephiLogEvent)
                            {
                                (logEvent as GephiLogEvent).From = po.PostFileName;
                            }

                            loggers[typelog].Append(logEvent);
                        }
                    }
                    catch (Exception e) {
                        WriteLog(e, "Generator.LogGen");
                    }
                }

                long ticks = 0;

                if (item.Object.Plusoners.TotalItems > 0)
                {
                    try {
                        var listpl = dicitem.Value.Plusers;

                        po.Pattern = rules[Rules.Plus];

                        foreach (var pl in listpl)
                        {
                            po.Person = pl;
                            po.Type   = TypePattern.plus;
                            var fnp = ReplacePattern(po);

                            logEvent.User     = GetActor(pl, typelog);
                            logEvent.Date     = DateTime.Parse(item.Published).AddMinutes(ticks);
                            logEvent.Action   = typelog == Visualizers.Types.Logstalgia ? "plus" : "A";
                            logEvent.FileName = fnp;
                            if (logEvent is LogstalgiaEvent)
                            {
                                (logEvent as LogstalgiaEvent).Size = "5";
                            }
                            if (logEvent is GephiLogEvent)
                            {
                                (logEvent as GephiLogEvent).From = po.PostFileName;
                            }

                            loggers[typelog].Append(logEvent);

                            ticks += 5;
                        }
                    }
                    catch (Exception e) {
                        WriteLog(e, "Generator.LogGen");
                    }
                }

                ticks = 0;

                if (item.Object.Resharers.TotalItems > 0)
                {
                    try {
                        var listpl = dicitem.Value.Sharers;

                        po.Pattern = rules[Rules.Plus];

                        foreach (var pl in listpl)
                        {
                            po.Person = pl;
                            po.Type   = TypePattern.reshare;
                            var fnp = ReplacePattern(po);

                            logEvent.User     = GetActor(pl, typelog);
                            logEvent.Date     = DateTime.Parse(item.Published).AddMinutes(ticks);
                            logEvent.Action   = typelog == Visualizers.Types.Logstalgia ? "reshare" : "A";
                            logEvent.FileName = fnp;
                            if (logEvent is LogstalgiaEvent)
                            {
                                (logEvent as LogstalgiaEvent).Size = "5";
                            }
                            if (logEvent is GephiLogEvent)
                            {
                                (logEvent as GephiLogEvent).From = po.PostFileName;
                            }

                            loggers[typelog].Append(logEvent);

                            ticks += 5;
                        }
                    }
                    catch (Exception e) {
                        WriteLog(e, "Generator.LogGen");
                    }
                }
            }
        }
Beispiel #15
0
        public static void LogGen(Dictionary<Visualizers.Types, Appender> loggers, Visualizers.Types typelog, Dictionary<Rules, string> rules, KeyValuePair<Activity, ActivityCont> dicitem)
        {
            var item = dicitem.Key;

            var action = "A";

            var po = new PatternOption();

            var share = dicitem.Value.Share;
            if (share != null) {
                po.Post = item;
                po.Share = share;
                po.Pattern = rules[Rules.SharePath];
                po.Type = TypePattern.share;

                po.SharePath = ReplacePattern(po);

                po.Pattern = rules[Rules.ShareName];
                po.PostFileName = po.SharePath + ReplacePattern(po);
                po.PostFileName = po.PostFileName.Replace("//", "/");

                loggers[typelog].Append(new LogEvent() {
                    User = item.Object.Id,
                    Date = DateTime.Parse(item.Published),
                    Action = action,
                    FileName = po.PostFileName
                });

                action = "M";
            }
            else {
                po.Post = item;
                po.Type = TypePattern.post;
                po.Pattern = rules[Rules.NotShare];

                po.SharePath = ReplacePattern(po);
            }

            po.Type = TypePattern.post;
            po.Pattern = rules[Rules.Post];

            po.PostFileName = ReplacePattern(po);

            loggers[typelog].Append(new LogEvent() {
                User = item.Id,
                Date = DateTime.Parse(item.Published),
                Action = action,
                FileName = po.PostFileName
            });

            if (item.Object != null) {

                if (item.Object.Resharers.TotalItems > 0) {
                    try {
                        var listpl = dicitem.Value.Comments;
                        po.Pattern = rules[Rules.Comment];
                        po.Type = TypePattern.comment;
                        foreach (var pl in listpl) {
                            po.Comment = pl;
                            var fnp = ReplacePattern(po);

                            loggers[typelog].Append(new LogEvent() {
                                User = item.Id,
                                Date = DateTime.Parse(item.Published),
                                Action = "A",
                                FileName = fnp
                            });
                        }
                    }
                    catch (Exception e) {
                        WriteLog(e, "UDGenerator.LogGen");
                    }
                }

                long ticks = 0;

                if (item.Object.Plusoners.TotalItems > 0) {
                    try {
                        var listpl = dicitem.Value.Plusers;

                        po.Pattern = rules[Rules.Plus];
                        po.Type = TypePattern.plus;

                        foreach (var pl in listpl) {
                            po.Person = pl;
                            var fnp = ReplacePattern(po);

                            loggers[typelog].Append(new LogEvent() {
                                User = item.Id,
                                Date = DateTime.Parse(item.Published).AddMinutes(ticks),
                                Action = "A",
                                FileName = fnp
                            });

                            ticks += 5;
                        }
                    }
                    catch (Exception e) {
                        WriteLog(e, "UDGenerator.LogGen");
                    }
                }

                ticks = 0;

                if (item.Object.Resharers.TotalItems > 0) {
                    try {
                        var listpl = dicitem.Value.Sharers;

                        po.Pattern = rules[Rules.Plus];
                        po.Type = TypePattern.reshare;

                        foreach (var pl in listpl) {
                            po.Person = pl;
                            var fnp = ReplacePattern(po);

                            loggers[typelog].Append(new LogEvent() {
                                User = item.Id,
                                Date = DateTime.Parse(item.Published).AddMinutes(ticks),
                                Action = "A",
                                FileName = fnp
                            });

                            ticks += 5;
                        }
                    }
                    catch (Exception e) {
                        WriteLog(e, "UDGenerator.LogGen");
                    }
                }
            }
        }