예제 #1
0
        public static void UpdateRelativeTime(this ITwitterItem item)
        {
            string relativeTime;
            var    span    = new TimeSpan(DateTime.Now.Ticks - item.CreatedAt.Ticks);
            var    seconds = Math.Max(span.TotalSeconds, 0);

            span = TimeSpan.FromSeconds(seconds);
            if (seconds < 60)
            {
                relativeTime = string.Format("{0} second{1} ago", span.Seconds, span.Seconds <= 1 ? "" : "s");
            }
            else if (seconds < (60 * 60))
            {
                relativeTime = string.Format("{0} minute{1} ago", span.Minutes, span.Minutes == 1 ? "" : "s");
            }
            else if (seconds < (24 * 60 * 60))
            {
                relativeTime = string.Format("{0} hour{1} ago", span.Hours, span.Hours == 1 ? "" : "s");
            }
            else
            {
                // 1 日以上前の場合は日付表示にする
                relativeTime = item.CreatedAt.ToString("g");
            }
            item.RelativeTime = relativeTime;
        }
예제 #2
0
 public bool Equals(ITwitterItem other)
 {
     if (other == null)
     {
         return(false);
     }
     else if (!(other is DirectMessage))
     {
         return(false);
     }
     return(this.Id == other.Id);
 }
예제 #3
0
 public static bool CheckEach(this List<Filter> filters, ITwitterItem item)
 {
     Stack<Tuple<bool, int>> results = new Stack<Tuple<bool, int>>();
     for (int i = 0; i < filters.Count - 1; i++)
     {
         if (results.Count == 0 || results.Peek().Item2 < filters[i].Level)
         {
             results.Push(Tuple.Create(filters[i].Process(item), filters[i].Level));
         }
         else if (results.Peek().Item2 == filters[i].Level)
         {
             var t = results.Pop();
             if (filters[i].AndCombine)
             {
                 results.Push(Tuple.Create(t.Item1 && filters[i].Process(item), filters[i].Level));
             }
             else
             {
                 results.Push(Tuple.Create(t.Item1 || filters[i].Process(item), filters[i].Level));
             }
         }
         else
         {
             bool r = filters[i].Process(item);
             if (filters[i].AndCombine)
             {
                 do
                 {
                     r = r && results.Pop().Item1;
                 } while (results.Count == 0 || results.Peek().Item2 >= filters[i].Level);
             }
             else
             {
                 do
                 {
                     r = r || results.Pop().Item1;
                 } while (results.Count == 0 || results.Peek().Item2 >= filters[i].Level);
             }
             results.Push(Tuple.Create(r, filters[i].Level));
         }
     }
     if (filters.Last().AndCombine)
     {
         results.Push(Tuple.Create(filters.Last().Process(item), filters.Last().Level));
         return results.All(t => t.Item1);
     }
     else
     {
         results.Push(Tuple.Create(filters.Last().Process(item), filters.Last().Level));
         return results.Any(t => t.Item1);
     }
     //return false;
 }
예제 #4
0
 public bool Delete(ITwitterItem item)
 {
     for (int i = 0; i < RetryCount; i++)
     {
         if (item.IsMessage ? DeleteMessage(item.Id) : DeleteStatus(item.Id))
         {
             return(true);
         }
         Thread.Sleep(1000);
     }
     return(false);
 }
예제 #5
0
 public void Remove(ITwitterItem removeItem)
 {
     lock (_thisLock)
     {
         if (removeItem == null)
         {
             return;
         }
         if (Items.Remove(removeItem))
         {
             if (removeItem.IsNewest)
             {
                 UnreadCount--;
             }
             //View.Refresh();
         }
     }
 }
예제 #6
0
        public bool Process(ITwitterItem item)
        {
            switch (Type)
            {
            case FilterType.Text:
                return(item.Text.IndexOf(Pattern, StringComparison.OrdinalIgnoreCase) != -1);

            case FilterType.RegexText:
                return(Regex.IsMatch(item.Text, Pattern, RegexOptions.IgnoreCase));

            case FilterType.Name:
                return(string.Compare(item.Sender.ScreenName, Pattern, true) == 0);

            case FilterType.RegexName:
                return(Regex.IsMatch(item.Sender.ScreenName, Pattern, RegexOptions.IgnoreCase));

            case FilterType.Source:
            {
                var status = item as Status;

                if (status != null)
                {
                    return(string.Compare(status.Source, Pattern, true) == 0);
                }
            }
            break;

            case FilterType.RegexSource:
            {
                var status = item as Status;

                if (status != null)
                {
                    return(Regex.IsMatch(status.Source, Pattern, RegexOptions.IgnoreCase));
                }
            }
            break;
            }
            return(false);
        }
예제 #7
0
 public bool Equals(ITwitterItem other)
 {
     if (other == null)
     {
         return(false);
     }
     else if (!(other is Status))
     {
         return(false);
     }
     if (((Status)other).IsReTweeted && IsReTweeted)
     {
         return(ReTweetedStatus.Id == ((Status)other).ReTweetedStatus.Id);
     }
     else if (((Status)other).IsReTweeted)
     {
         return(((Status)other).ReTweetedStatus.Id == this.Id);
     }
     else if (IsReTweeted)
     {
         return(ReTweetedStatus.Id == other.Id);
     }
     return(this.Id == other.Id);
 }
예제 #8
0
 public bool Equals(ITwitterItem other)
 {
     if (other == null)
     {
         return false;
     }
     else if (!(other is Status))
     {
         return false;
     }
     if (((Status)other).IsReTweeted && IsReTweeted)
     {
         return (ReTweetedStatus.ID == ((Status)other).ReTweetedStatus.ID);
     }
     else if (((Status)other).IsReTweeted)
     {
         return (((Status)other).ReTweetedStatus.ID == this.ID);
     }
     else if (IsReTweeted)
     {
         return (ReTweetedStatus.ID == other.ID);
     }
     return (this.ID == other.ID);
 }
예제 #9
0
 public UpdateEventArgs(ITwitterItem item)
 {
     Item = item;
 }
예제 #10
0
 private bool IsFilterMatch(ITwitterItem item)
 {
     return(Filters.Count == 0 || Filters.Any(filter => filter.Process(item)));
 }
예제 #11
0
 public bool Equals(ITwitterItem other)
 {
     if (other == null)
     {
         return false;
     }
     else if (!(other is DirectMessage))
     {
         return false;
     }
     return (this.ID == other.ID);
 }
예제 #12
0
 public UpdateEventArgs(ITwitterItem item)
 {
     Item = item;
 }
예제 #13
0
 public bool Delete(ITwitterItem item)
 {
     for (int i = 0; i < RetryCount; i++)
     {
         if (item.IsMessage ? DeleteMessage(item.ID) : DeleteStatus(item.ID))
         {
             return true;
         }
         System.Threading.Thread.Sleep(1000);
     }
     return false;
 }