示例#1
0
 private string ShortenURL(string originalURL)
 {
     try
     {
         string str = string.Empty;
         if (CoreServices.Instance.CurrentURLShorteningService(this.TwitterAccountID) != null)
         {
             str = CoreServices.Instance.CurrentURLShorteningService(this.TwitterAccountID).ShortenURL(this.TwitterAccountID, originalURL);
             if (string.IsNullOrEmpty(str) || string.IsNullOrWhiteSpace(str))
                 str = originalURL;
         }
         return str;
     }
     catch (Exception ex)
     {
         Application.Current.Dispatcher.BeginInvoke((Action)(() =>
         {
             string local_0 = string.Format("We received the following error trying to shorten the url. {0}", (object)ex.Message);
             SimpleErrorPrompt local_1 = new SimpleErrorPrompt()
             {
                 DataContext = (object)new
                 {
                     ErrorHeading = "url shortening failed",
                     ErrorText = local_0
                 }
             };
             Messenger.Default.Send<PromptMessage>(new PromptMessage()
             {
                 IsModal = false,
                 PromptView = (FrameworkElement)local_1,
                 IsCentered = false
             }, (object)ViewModelMessages.ShowSlidePrompt);
         }), DispatcherPriority.ContextIdle, new object[0]);
         return originalURL;
     }
 }
示例#2
0
        private async void PostTweet()
        {
            Messenger.Default.Send<GenericMessage<object>>(new GenericMessage<object>((object)false), (object)ViewModelMessages.EnableReplyOptions);
            this.sendingTweetInProgress = true;
            this.PostTweetEnabled = false;
            this.TweetEntryEnabled = false;
            this.ImageUploadButtonIsEnabled = false;
            this.PostTweetProgressVisibility = Visibility.Visible;
            bool error = false;
            int numberOfStatus = 0;
            if ((this.CharCount <= SettingsData.Instance.TweetCharLimit || Enumerable.Count<ITweetService>(Enumerable.Where<ITweetService>((IEnumerable<ITweetService>)CoreServices.Instance.TweetServices, (Func<ITweetService, bool>)(x => x.OverrideTweetCharLimit))) > 0) && this.CharCount > 0)
            {
                try
                {
                    this.TweetTextCounter();
                    if (this.CurrentlySelectedImage != null && !this.TwitterImageServiceIsEnabled)
                    {
                        this.uploadImageCountDownEvent = new CountdownEvent(1);
                        this.ProcessImageUpload(this.CurrentlySelectedImage.FilePath, (Action<string>)(s =>
                        {
                            TwitViewModel temp_978 = this;
                            string temp_982 = temp_978.ActualTweetText + " " + s;
                            temp_978.ActualTweetText = temp_982;
                            this.TweetTextCounter();
                        }));
                        await Task.Run((Action)(() => this.uploadImageCountDownEvent.Wait()));
                    }
                    if (this.imageUploadsFailed)
                    {
                        await System.Windows.Application.Current.Dispatcher.BeginInvoke((Action)(() =>
                        {
                            SimpleErrorPrompt local_0 = new SimpleErrorPrompt()
                            {
                                DataContext = (object)new
                                {
                                    ErrorHeading = "image upload failed",
                                    ErrorText = "Image failed to upload, please try again."
                                }
                            };
                            Messenger.Default.Send<PromptMessage>(new PromptMessage()
                            {
                                IsModal = true,
                                PromptView = (FrameworkElement)local_0,
                                IsCentered = false
                            }, (object)ViewModelMessages.ShowSlidePrompt);
                        }), new object[0]);
                        error = true;
                        this.sendingTweetInProgress = false;
                        this.PostTweetEnabled = true;
                        this.TweetEntryEnabled = true;
                        this.ImageUploadButtonIsEnabled = true;
                        this.PostTweetProgressVisibility = Visibility.Collapsed;
                        return;
                    }
                    else if (this.CharCount > SettingsData.Instance.TweetCharLimit && Enumerable.Count<ITweetService>(Enumerable.Where<ITweetService>((IEnumerable<ITweetService>)CoreServices.Instance.TweetServices, (Func<ITweetService, bool>)(x => x.OverrideTweetCharLimit))) == 0)
                    {
                        await System.Windows.Application.Current.Dispatcher.BeginInvoke((Action)(() => Messenger.Default.Send<DialogMessage>(new DialogMessage(string.Empty, (Action<MessageBoxResult>)(o => { })), (object)DialogType.TweetLength)), new object[0]);
                        error = true;
                        return;
                    }
                    else
                    {
                        TwitterResponse<Status> updateResponse = (TwitterResponse<Status>)null;
                        TwitterResponse<TwitterDirectMessage> directMessageResponse = (TwitterResponse<TwitterDirectMessage>)null;
                        Match dmMatch = (Match)null;
                        string userName = string.Empty;
                        string tweetpoststring = this.ActualTweetText;
                        if (this.newTweetType == TwitViewModel.NewTweetType.DirectMessage)
                        {
                            dmMatch = TwitViewModel.DM_EXPRESSION.Match(tweetpoststring);
                            userName = dmMatch.Groups[1].Value;
                            tweetpoststring = tweetpoststring.Replace(dmMatch.Groups[0].Value, "").Trim();
                        }
                        else
                        {
                            foreach (ITweetService tweetService in CoreServices.Instance.TweetServices)
                            {
                                if (tweetService.WantsPreCreation)
                                {
                                    PreTweetCreationResponse creationResponse = tweetService.PreTweetCreation(tweetpoststring, this.CharCount, this.ReplyToID.ToString(), this.UserName, this.newTweetType == TwitViewModel.NewTweetType.DirectMessage, App.AppState.Accounts[this.TwitterAccountID].TwitterAccountName);
                                    if (string.IsNullOrEmpty(creationResponse.Error) && !string.IsNullOrEmpty(creationResponse.TweetContent))
                                        tweetpoststring = creationResponse.TweetContent;
                                }
                            }
                        }
                        if (this.newTweetType == TwitViewModel.NewTweetType.DirectMessage)
                        {
                            if (dmMatch.Success && userName.Length > 0)
                            {
                                directMessageResponse = await DirectMessages.SendAsync(App.AppState.Accounts[this.TwitterAccountID].Tokens, userName, tweetpoststring, (OptionalProperties)null);
                                if (directMessageResponse != null && directMessageResponse.Result == RequestResult.Success)
                                {
                                    TwitterDirectMessage responseObject = directMessageResponse.ResponseObject;
                                    this.lastTweet = new UndoTweetState()
                                    {
                                        Id = responseObject.Id,
                                        LastTweetText = this.ActualTweetText,
                                        TweetType = TwitViewModel.NewTweetType.DirectMessage,
                                        UserName = this.UserName
                                    };
                                    this.CurrentTweetDocument = (FlowDocument)null;
                                    if (responseObject != null)
                                    {
                                        numberOfStatus = responseObject.Sender.NumberOfStatuses;
                                        App.AppState.Accounts[this.TwitterAccountID].Settings.TwitterUserImage = responseObject.Sender.ProfileImageSecureLocation;
                                    }
                                }
                                else
                                {
                                    this.StatusType = -2;
                                    this.StatusText = Enumerable.First<TwitterError>(directMessageResponse.Errors).Message;
                                }
                                this.StatusLabelVisibility = Visibility.Visible;
                            }
                        }
                        else
                        {
                            switch (this.newTweetType)
                            {
                                case TwitViewModel.NewTweetType.Reply:
                                    StatusUpdateOptions statusUpdateOptons = MetroTwitTwitterizer.StatusUpdateOptions;
                                    statusUpdateOptons.InReplyToStatusId = this.ReplyToID;
                                    if (this.CurrentlySelectedImage != null && this.TwitterImageServiceIsEnabled)
                                    {
                                        updateResponse = await Tweets.UpdateWithMediaAsync(App.AppState.Accounts[this.TwitterAccountID].Tokens, tweetpoststring, this.BufferFromImage(this.CurrentlySelectedImage.Image), statusUpdateOptons);
                                        this.DecrementPostTweetCounter();
                                        break;
                                    }
                                    else
                                    {
                                        updateResponse = await Tweets.UpdateAsync(App.AppState.Accounts[this.TwitterAccountID].Tokens, tweetpoststring, statusUpdateOptons);
                                        break;
                                    }
                                case TwitViewModel.NewTweetType.Retweet:
                                    if (this.CurrentlySelectedImage != null && this.TwitterImageServiceIsEnabled)
                                    {
                                        updateResponse = await Tweets.UpdateWithMediaAsync(App.AppState.Accounts[this.TwitterAccountID].Tokens, tweetpoststring, this.BufferFromImage(this.CurrentlySelectedImage.Image), MetroTwitTwitterizer.StatusUpdateOptions);
                                        this.DecrementPostTweetCounter();
                                        break;
                                    }
                                    else
                                    {
                                        updateResponse = await Tweets.UpdateAsync(App.AppState.Accounts[this.TwitterAccountID].Tokens, tweetpoststring, MetroTwitTwitterizer.StatusUpdateOptions);
                                        break;
                                    }
                                default:
                                    if (this.CurrentlySelectedImage != null && this.TwitterImageServiceIsEnabled)
                                    {
                                        updateResponse = await Tweets.UpdateWithMediaAsync(App.AppState.Accounts[this.TwitterAccountID].Tokens, tweetpoststring, this.BufferFromImage(this.CurrentlySelectedImage.Image), MetroTwitTwitterizer.StatusUpdateOptions);
                                        this.DecrementPostTweetCounter();
                                        break;
                                    }
                                    else
                                    {
                                        updateResponse = await Tweets.UpdateAsync(App.AppState.Accounts[this.TwitterAccountID].Tokens, tweetpoststring, MetroTwitTwitterizer.StatusUpdateOptions);
                                        break;
                                    }
                            }
                            if (updateResponse != null && updateResponse.Result == RequestResult.Success)
                            {
                                Status responseObject = updateResponse.ResponseObject;
                                this.lastTweet = new UndoTweetState()
                                {
                                    Id = responseObject.Id,
                                    LastTweetText = this.ActualTweetText,
                                    TweetType = this.newTweetType,
                                    UserName = this.UserName,
                                    ReplyToID = this.ReplyToID
                                };
                                this.CurrentTweetDocument = (FlowDocument)null;
                                if (responseObject != null)
                                {
                                    numberOfStatus = responseObject.User.NumberOfStatuses;
                                    App.AppState.Accounts[this.TwitterAccountID].Settings.TwitterUserImage = responseObject.User.ProfileImageSecureLocation;
                                    foreach (ITweetService tweetService in CoreServices.Instance.TweetServices)
                                    {
                                        if (tweetService.WantsPostCreation)
                                            tweetService.PostTweetCreation(responseObject.Text, this.CharCount, responseObject.InReplyToStatusId.ToString(), responseObject.InReplyToScreenName, false, App.AppState.Accounts[this.TwitterAccountID].TwitterAccountName, responseObject.Id);
                                    }

                                }
                            }
                            else
                            {
                                this.StatusType = -2;
                                this.StatusText = Enumerable.First<TwitterError>(updateResponse.Errors).Message;
                                if (this.StatusText == "Status is a duplicate.")
                                    this.StatusText = "Tweet error: tweet is a duplicate of a last tweet posted.";
                                this.StatusLabelVisibility = Visibility.Visible;
                            }
                        }
                    }
                }
                catch
                {
                    error = true;
                }
            }
            else
                error = true;
            if (!this.imageUploadsFailed && !error)
            {
                base.RaisePropertyChanged("SingleImageTypeEnabled");
                this.CurrentlySelectedImage = (SingleImageUploadRequest)null;
                this.EnableTweetArea();
                if (numberOfStatus > 0)
                {
                    this.PostTweetEnabled = false;
                    this.ResetNewTweet(true);
                    if (App.AppState.Accounts[this.TwitterAccountID].TwitterUserTweetCount != numberOfStatus.ToString() + " tweets")
                    {
                        App.AppState.Accounts[this.TwitterAccountID].TwitterUserTweetCount = numberOfStatus.ToString() + " tweets";
                        Messenger.Default.Send<GenericMessage<object>>(new GenericMessage<object>((object)null), (object)this.MultiAccountifyToken((System.Enum)ViewModelMessages.ProfileUpdated));
                    }
                }
            }
            else
                this.EnableTweetArea();
        }
 internal void StreamStopped(StopReasons stopreason)
 {
     this.Stopped = true;
       this.StopReason = new StopReasons?(stopreason);
       if (App.AppState.Accounts[this.TwitterAccountID].IsSignedIn && stopreason == StopReasons.Unauthorised)
       {
     System.Windows.Application.Current.Dispatcher.Invoke((Action) (() =>
     {
       SimpleErrorPrompt local_0 = new SimpleErrorPrompt()
       {
     DataContext = (object) new
     {
       ErrorHeading = "service halted",
       ErrorText = "The Twitter streaming connection could not start.\r\nPlease ensure your computer time and timezone are accurate before restarting MetroTwit."
     }
       };
       Messenger.Default.Send<PromptMessage>(new PromptMessage()
       {
     IsModal = false,
     PromptView = (FrameworkElement) local_0,
     IsCentered = false
       }, (object) ViewModelMessages.ShowSlidePrompt);
     }));
     this.retrycount = new int?(0);
       }
       else
       {
     StopReasons? nullable1 = this.StopReason;
     if ((nullable1.GetValueOrDefault() != StopReasons.WebConnectionFailed ? 0 : (nullable1.HasValue ? 1 : 0)) != 0 && !this.retrycount.HasValue)
     {
       this.retrycount = new int?(0);
       this.Stream.StartUserStream(new InitUserStreamCallback(this.FriendsReceived), new StreamStoppedCallback(this.StreamStopped), new StatusCreatedCallback(this.StatusReceived), new StatusDeletedCallback(this.StatusDeleted), new DirectMessageCreatedCallback(this.DirectMessageReceived), new DirectMessageDeletedCallback(this.DirectMessageDeleted), new EventCallback(this.EventReceived), (RawJsonCallback) null);
     }
     else
     {
       if (stopreason == StopReasons.StoppedByRequest)
     return;
       if (this.retrytimer == null)
       {
     this.retrytimer = new Timer();
     this.retrytimer.Elapsed += new ElapsedEventHandler(this.retrytimer_Elapsed);
     this.retrytimer.AutoReset = false;
       }
       if (!this.retrycount.HasValue)
     this.retrycount = new int?(0);
       TwitterStreaming twitterStreaming = this;
       int? nullable2 = twitterStreaming.retrycount;
       int? nullable3 = nullable2.HasValue ? new int?(nullable2.GetValueOrDefault() + 1) : new int?();
       twitterStreaming.retrycount = nullable3;
       this.retrytimer.Interval = (double) this.retrycount.Value * TimeSpan.FromSeconds(30.0).TotalMilliseconds;
       if (this.retrytimer.Interval < (stopreason == StopReasons.RateLimited ? TimeSpan.FromMinutes(15.0).TotalMilliseconds : TimeSpan.FromMinutes(5.0).TotalMilliseconds))
     this.retrytimer.Start();
       else
     System.Windows.Application.Current.Dispatcher.Invoke((Action) (() =>
     {
       SimpleErrorPrompt local_0 = new SimpleErrorPrompt()
       {
         DataContext = (object) new
         {
           ErrorHeading = "service disrupted",
           ErrorText = "The Twitter streaming connection has been lost. We've tried reconnecting without success.\r\nTwitter restricts the number of streaming connections you can have at any one time, so please check if you have other Twitter applications running."
         }
       };
       Messenger.Default.Send<PromptMessage>(new PromptMessage()
       {
         IsModal = false,
         PromptView = (FrameworkElement) local_0,
         IsCentered = false
       }, (object) ViewModelMessages.ShowSlidePrompt);
     }));
     }
       }
 }