Пример #1
0
        public static StatusData ConvertFrom(StatusInfo statusInfo)
        {
            var data = new StatusData();
            data.CreatedAt = statusInfo.CreatedAt;
            data.ID = statusInfo.ID;
            data.Text = statusInfo.Text;
            data.Source = statusInfo.Source;
            data.Favorited = statusInfo.Favorited;
            data.Truncated = statusInfo.Truncated;
            data.ReplyTo = statusInfo.ReplyTo;
            data.ReplyToUserId = statusInfo.ReplyToUserId;
            data.ReplyToUserScreenName = statusInfo.ReplyToUserScreenName;
            data.ThumbnailPic = statusInfo.ThumbnailPic;
            data.MiddlePic = statusInfo.MiddlePic;
            data.OriginalPic = statusInfo.OriginalPic;
            data.Mid = statusInfo.Mid;
            if(null != statusInfo.User)
                data.User = ConvertFrom(statusInfo.User);
            data.Geo = statusInfo.Geo;

            if(null != statusInfo.RetweetedStatus)
                data.RetweetedStatus = ConvertFrom(statusInfo.RetweetedStatus);

            return data;
        }
Пример #2
0
        public static void ShowImage(StatusData statusData, bool isShowForwardedPic)
        {
            var mainWin = Application.Current.MainWindow;
            var imgViewer = ImageViewer.Instance;

            if (!IsShowing)
            {
                imgViewer.Owner = mainWin;
                imgViewer.RequiredLocationX = mainWin.Left + mainWin.ActualWidth + 2;
                imgViewer.RequiredLocationY = mainWin.Top + 2;

                mainWin.LocationChanged += imgViewer.HandleMainWinLocationChanged;
            }

            var picToShow = string.Empty;

            if (isShowForwardedPic)
                picToShow = statusData.RetweetedStatus.OriginalPic;
            else
                picToShow = statusData.OriginalPic;

            if (!ImageHelper.ExistsImage(picToShow))
                imgViewer.imgLoader.Source = picToShow;
            else
                imgViewer.imgLoader.Source = ImageHelper.GetImage(picToShow);

            if (!ImagesViewed.Contains(imgViewer.imgLoader.Source))
                ImagesViewed.Add(imgViewer.imgLoader.Source);

            ImageViewer.Instance.Show();
            ImageViewer.Instance.Activate();

            IsShowing = true;
        }
Пример #3
0
        public PostWindow(MainViewModel viewModel, StatusData targetStatus, PosterMode mode)
        {
            InitializeComponent();

            this.targetStatusContainer.DataContext = this.targetStatus = targetStatus;
            this.poster.ViewModel = this.viewModel = viewModel;
            this.poster.Mode = this.mode = mode;

            this.Loaded += new RoutedEventHandler(HandlePostWindowLoaded);
        }
Пример #4
0
        public void RemoveFromFavourite(StatusData statusData, FrameworkElement target)
        {
            var callback = new AsyncCallback<StatusInfo>(delegate(AsyncCallResult<StatusInfo> result)
            {
                if (result.Success)
                {
                    var statusInFav = result.Data;

                    this.syncContext.Send(new SendOrPostCallback(delegate(object state)
                    {
                        var exists = this.FavouriteStatuses.FirstOrDefault((item) => item.ID == statusInFav.ID);
                        if (null != exists)
                            this.FavouriteStatuses.Remove(exists);

                        // Traverse all statuses collection to set Favorited as false.
                        exists = this.MyHomeStatuses.FirstOrDefault((item) => item.ID == statusInFav.ID);
                        if (null != exists)
                            exists.Favorited = false;
                        exists = this.MyStatuses.FirstOrDefault((item) => item.ID == statusInFav.ID);
                        if (null != exists)
                            exists.Favorited = false;
                        exists = this.AtMeStatuses.FirstOrDefault((item) => item.ID == statusInFav.ID);
                        if (null != exists)
                            exists.Favorited = false;
                        exists = this.StatusSearchResult.FirstOrDefault((item) => item.ID == statusInFav.ID);
                        if (null != exists)
                            exists.Favorited = false;
                    }), null);

                    ShowMessage("Status removed to favourite.");
                }
                else
                    ShowMessage("Status failed to remov from favourite due to: {0}.", result.Exception.Message);

                SetItemState(target, true);
            });

            target.IsEnabled = false;
            ShowMessage("Removing status from favourite.");
            AMicroblog.DeleteFromFavoriteAsync(callback, statusData.ID);
        }
Пример #5
0
        public void AddToFavourite(StatusData statusData, FrameworkElement target)
        {
            var callback = new AsyncCallback<StatusInfo>(delegate(AsyncCallResult<StatusInfo> result)
            {
                if (result.Success)
                {
                    var statusInFav = result.Data;

                    this.syncContext.Send(new SendOrPostCallback(delegate(object state)
                    {
                        var srvStatusData = DataConverter.ConvertFrom(statusInFav);
                        srvStatusData.Favorited = true;
                        var exists = this.FavouriteStatuses.FirstOrDefault((item) => item.ID == srvStatusData.ID);
                        if (null == exists)
                            this.FavouriteStatuses.Insert(0, srvStatusData); // TODO: Sorting

                        // Traverse all statuses collection to set Favorited as true.
                        exists = this.MyHomeStatuses.FirstOrDefault((item) => item.ID == srvStatusData.ID);
                        if (null != exists)
                            exists.Favorited = true;
                        exists = this.MyStatuses.FirstOrDefault((item) => item.ID == srvStatusData.ID);
                        if (null != exists)
                            exists.Favorited = true;
                        exists = this.AtMeStatuses.FirstOrDefault((item) => item.ID == srvStatusData.ID);
                        if (null != exists)
                            exists.Favorited = true;
                        exists = this.StatusSearchResult.FirstOrDefault((item) => item.ID == srvStatusData.ID);
                        if (null != exists)
                            exists.Favorited = true;

                    }), null);

                    ShowMessage("Status added to favourite.");
                }
                else
                    ShowMessage("Status failed to add to favourite due to: {0}.", result.Exception.Message);

                SetItemState(target, true);
            });

            target.IsEnabled = false;
            ShowMessage("Adding status to favourite...");
            AMicroblog.AddToFavoriteAsync(callback, statusData.ID);
        }