コード例 #1
0
        void ProcessThreads(YamsterGroup group, DateTime?olderThanCutoff, Action <YamsterThread> action)
        {
            // Id         LastUpdate              # Msgs  Message
            // 187041710  2014-05-23 01:16:04 AM  1       has created the Test Group group.
            Utils.Log("Id         LastUpdate              # Msgs  Message");
            Utils.Log("---------- ----------------------- ------- ----------------------------------");

            foreach (YamsterThread thread in group.Threads.OrderBy(x => x.LastUpdate))
            {
                if (olderThanCutoff != null)
                {
                    if (thread.LastUpdate > olderThanCutoff.Value)
                    {
                        continue;
                    }
                }

                Utils.Log("{0,-10} {1:yyyy-MM-dd hh:mm:ss tt}  {2,-7} {3}",
                          thread.ThreadId,
                          thread.LastUpdate,
                          thread.Messages.Count,
                          Utilities.TruncateWithEllipsis(
                              thread.ThreadStarterMessage.GetPreviewText(), 34));

                action(thread);
            }
        }
コード例 #2
0
ファイル: MessageComposer.cs プロジェクト: octogonz/yamster
 public void StartNewThread(YamsterGroup group)
 {
     if (group == null)
     {
         throw new ArgumentNullException("group");
     }
     this.ComposerMode          = MessageComposerMode.NewThread;
     this.GroupContext          = group;
     this.ThreadContext         = null;
     this.MessageBeingRepliedTo = null;
     UpdateUI();
 }
コード例 #3
0
        public override void Run()
        {
            var appContext = AppContext.Default;

            YamsterGroup group = appContext.YamsterCache.GetGroupById(GroupId);

            Utils.Log("Yammer Network: {0}", appContext.YamsterCache.CurrentNetworkUrl);
            Utils.Log("Login user: {0}", appContext.YamsterCache.CurrentUserAlias);
            Utils.Log("Group to delete: \"{0}\"", group.GroupName);

            DateTime?olderThanCutoff = null;

            if (this.OlderThanDays > 0)
            {
                olderThanCutoff = DateTime.Now.Date.AddDays(-OlderThanDays);
                Utils.Log("Only deleting threads older than {0:yyyy-MM-dd}", olderThanCutoff.Value);
                Utils.Log("");
            }
            Utils.Log("");

            if (WhatIf)
            {
                Utils.Log("Messages that would be deleted:");
                Utils.Log("");

                ProcessThreads(group, olderThanCutoff, (thread) => { });

                Utils.Log("");
                Utils.Log("No messages were actually deleted because -WhatIf was specified.");
            }
            else
            {
                Console.Write(
                    @"THIS COMMAND WILL *PERMANENTLY* DELETE MESSAGES FROM YOUR YAMMER NETWORK!

Yamster cannot guarantee that this command will work as expected.  In no event
shall the authors or copyright holders be liable for any accidental data loss
or other damages that may result.  Proceed at your own risk!

If you accept the risks involved with bulk deleting, and have read the Yamster
license agreement and accept those terms, then type ""I AGREE"": ");

                string reply = Console.ReadLine();
                Utils.Log("");

                if (reply.ToUpper().Trim().TrimEnd('.') != "I AGREE")
                {
                    Utils.Log("ERROR: Aborting because you did not agree to the terms.");
                    return;
                }

                Utils.Log("Connecting to Yammer...");
                Utils.VerifyLogin(appContext);

                int threadCount         = 0;
                int deletedMessageCount = 0;

                YamsterMessage lastMessageAttempted = null;

                try
                {
                    ProcessThreads(group, olderThanCutoff,
                                   (thread) => {
                        ++threadCount;

                        int messageNumber = 1;
                        foreach (YamsterMessage message in thread.Messages.Reverse())
                        {
                            if (ShouldSkipMessage(message))
                            {
                                Console.Write(" S");
                            }
                            else
                            {
                                // NOTE: Apparently Yammer doesn't impose rate limits for deletes
#if false
                                bool wroteDot = false;
                                while (!AppContext.Default.YamsterApi.IsSafeToRequest(increasedPriority: false))
                                {
                                    if (!wroteDot)
                                    {
                                        Console.Write(" ");
                                    }
                                    Console.Write(".");
                                    wroteDot = true;
                                    Thread.Sleep(2000);
                                }
#endif
                                try
                                {
                                    lastMessageAttempted = message;
                                    message.DeleteFromServer();
                                    Console.Write(" " + messageNumber);
                                    ++deletedMessageCount;
                                }
                                catch (ServerObjectNotFoundException)
                                {
                                    Console.Write(" E");
                                }
                                catch (Exception ex)
                                {
                                    if (!this.IgnoreErrors)
                                    {
                                        throw;
                                    }
                                    ShowMessageDeletionError(ex, lastMessageAttempted);
                                }
                            }

                            ++messageNumber;
                        }
                        Console.WriteLine();
                    }
                                   );
                }
                catch (Exception ex)
                {
                    ShowMessageDeletionError(ex, lastMessageAttempted);
                }

                Utils.Log("");
                Utils.Log("Deleted {0} messages from {1} threads", deletedMessageCount, threadCount);
            }
        }