public HttpResponseMessage PostAlbum(Album album)
        {
            if (!this.ModelState.IsValid)
            {
                // Default Error Result
                //return Request.CreateErrorResponse(HttpStatusCode.Conflict, ModelState);

                // Customized error handling
                var error = new ApiMessageError(ModelState);
                return Request.CreateResponse<ApiMessageError>(HttpStatusCode.Conflict, error);
            }

            // update song id which isn't provided
            foreach (var song in album.Songs)
                song.AlbumId = album.Id;

            // see if album exists already
            var matchedAlbum = AlbumData.Current
                            .SingleOrDefault(alb => alb.Id == album.Id ||
                                             alb.AlbumName == album.AlbumName);
            if (matchedAlbum == null)
                AlbumData.Current.Add(album);
            else
                matchedAlbum = album;

            // return a string to show that the value got here
            var resp = Request.CreateResponse<string>(HttpStatusCode.OK,
                               album.AlbumName + " " + album.Entered.ToString());
            return resp;
        }
        public HttpResponseMessage PostAlbum(Album album)
        {
            if (!this.ModelState.IsValid)
            {
                // my custom error class
                var error = new ApiMessageError() { message = "Model is invalid" };
                foreach (var prop in ModelState.Values)
                {
                    if (prop.Errors.Any())
                        error.errors.Add(prop.Errors.First().ErrorMessage);
                }
                // Return the error object as a response with an error code
                return Request.CreateResponse<ApiMessageError>(HttpStatusCode.Conflict, error);
            }

            foreach (var song in album.Songs)
                song.AlbumId = album.Id;

            var matchedAlbum = AlbumData.Current
                            .SingleOrDefault(alb => alb.Id == album.Id ||
                                             alb.AlbumName == album.AlbumName);
            if (matchedAlbum == null)
                AlbumData.Current.Add(album);
            else
                matchedAlbum = album;

            // return a string to show that the value got here
            var resp = Request.CreateResponse(HttpStatusCode.OK, string.Empty);
            resp.Content = new StringContent(album.AlbumName + " " + album.Entered.ToString(),
                                                Encoding.UTF8, "text/plain");
            return resp;
        }
Exemplo n.º 3
0
        public HttpResponseMessage PostAlbum(Album album)
        {
            if (!this.ModelState.IsValid)
            {
                // Default Error Result
                //return Request.CreateErrorResponse(HttpStatusCode.Conflict, ModelState);

                // Customized error handling
                var error = new ApiMessageError(ModelState);
                return(Request.CreateResponse <ApiMessageError>(HttpStatusCode.Conflict, error));
            }

            // update song id which isn't provided
            foreach (var song in album.Songs)
            {
                song.AlbumId = album.Id;
            }

            // see if album exists already
            var matchedAlbum = AlbumData.Current
                               .SingleOrDefault(alb => alb.Id == album.Id ||
                                                alb.AlbumName == album.AlbumName);

            if (matchedAlbum == null)
            {
                AlbumData.Current.Add(album);
            }
            else
            {
                matchedAlbum = album;
            }

            // return a string to show that the value got here
            var resp = Request.CreateResponse <string>(HttpStatusCode.OK,
                                                       album.AlbumName + " " + album.Entered.ToString());

            return(resp);
        }
Exemplo n.º 4
0
        private static async Task <bool> MarkReadSingle(ObservableCollection <Items> UpdateList, Items ListItem, string ActionType, bool Silent)
        {
            try
            {
                bool   MarkStatus = false;
                string ItemId     = ListItem.item_id;

                //Check if internet is available
                if (!NetworkInterface.GetIsNetworkAvailable() || ApiMessageError.StartsWith("(Off)"))
                {
                    if (!Silent)
                    {
                        await EventProgressDisableUI("Off marking item as " + ActionType.ToLower() + "...", true);
                    }
                    Debug.WriteLine("Off marking item as " + ActionType.ToLower() + "...");

                    await AddOfflineSync(ItemId, ActionType);

                    MarkStatus = true;
                }
                else
                {
                    if (!Silent)
                    {
                        await EventProgressDisableUI("Marking item as " + ActionType.ToLower() + "...", true);
                    }
                    Debug.WriteLine("Marking item as " + ActionType.ToLower() + "...");

                    string[][] RequestHeader = new string[][] { new[] { "Authorization", "GoogleLogin auth=" + AppVariables.ApplicationSettings["ConnectApiAuth"].ToString() } };

                    HttpStringContent PostContent;
                    if (ActionType == "Read")
                    {
                        PostContent = new HttpStringContent("i=" + ItemId + "&a=user/-/state/com.google/read", Windows.Storage.Streams.UnicodeEncoding.Utf8, "application/x-www-form-urlencoded");
                    }
                    else
                    {
                        PostContent = new HttpStringContent("i=" + ItemId + "&r=user/-/state/com.google/read", Windows.Storage.Streams.UnicodeEncoding.Utf8, "application/x-www-form-urlencoded");
                    }

                    HttpResponseMessage PostHttp = await AVDownloader.SendPostRequestAsync(7500, "News Scroll", RequestHeader, new Uri(ApiConnectionUrl + "edit-tag"), PostContent);

                    if (PostHttp != null && (PostHttp.Content.ToString() == "OK" || PostHttp.Content.ToString().Contains("<error>Not found</error>")))
                    {
                        MarkStatus = true;
                    }
                }

                if (MarkStatus)
                {
                    //Wait for busy database
                    await ApiUpdate.WaitForBusyDatabase();

                    //Mark item in database and list
                    TableItems TableEditItems = await SQLConnection.Table <TableItems>().Where(x => x.item_id == ItemId).FirstOrDefaultAsync();

                    if (TableEditItems != null)
                    {
                        if (ActionType == "Read")
                        {
                            TableEditItems.item_read_status = true;
                            ListItem.item_read_status       = Visibility.Visible; //Updates itemviewer
                            if (App.vApplicationFrame.SourcePageType.ToString().EndsWith("NewsPage") && NewsPage.vCurrentLoadingFeedFolder.feed_id != "1" && (bool)AppVariables.ApplicationSettings["HideReadMarkedItem"])
                            {
                                UpdateList.Remove(ListItem);
                            }
                        }
                        else
                        {
                            TableEditItems.item_read_status = false;
                            ListItem.item_read_status       = Visibility.Collapsed; //Updates itemviewer
                            if (App.vApplicationFrame.SourcePageType.ToString().EndsWith("NewsPage") && NewsPage.vCurrentLoadingFeedFolder.feed_id == "1" && (bool)AppVariables.ApplicationSettings["HideReadMarkedItem"])
                            {
                                UpdateList.Remove(ListItem);
                            }
                        }
                    }

                    //Update the items in database
                    await SQLConnection.UpdateAsync(TableEditItems);
                }
                else
                {
                    await AVMessageBox.Popup("Failed to mark item " + ActionType.ToLower(), "Please check your internet connection and try again.", "Ok", "", "", "", "", false);
                    await EventProgressEnableUI();
                }

                return(MarkStatus);
            }
            catch
            {
                Debug.WriteLine("Failed to un/read item.");
                return(false);
            }
        }
Exemplo n.º 5
0
        //Mark all items as read
        public static async Task <bool> MarkReadAll(ObservableCollection <Items> UpdateList, bool Confirm)
        {
            try
            {
                //Check if user is logged in
                if (!CheckLogin())
                {
                    await AVMessageBox.Popup("Not logged in", "Marking all items read can only be done when you are logged in.", "Ok", "", "", "", "", false);

                    return(false);
                }

                if (Confirm)
                {
                    Int32 MsgBoxResult = await AVMessageBox.Popup("Mark all items read", "Do you want to mark all items for every feed as read?", "Mark all items read", "", "", "", "", true);

                    if (MsgBoxResult == 0)
                    {
                        return(false);
                    }
                }

                bool MarkStatus = false;

                //Check if internet is available
                if (!NetworkInterface.GetIsNetworkAvailable() || ApiMessageError.StartsWith("(Off)"))
                {
                    await EventProgressDisableUI("Off marking all items as read...", true);

                    Debug.WriteLine("Off marking all items as read...");

                    //Wait for busy database
                    await ApiUpdate.WaitForBusyDatabase();

                    List <String> UnreadItemList = (await SQLConnection.Table <TableItems>().Where(x => !x.item_read_status).ToListAsync()).Select(x => x.item_id).ToList();
                    await AddOfflineSync(UnreadItemList, "Read");

                    MarkStatus = true;
                }
                else
                {
                    await EventProgressDisableUI("Marking all items as read...", true);

                    Debug.WriteLine("Marking all items as read...");

                    //Date time variables
                    Int64 UnixTimeTicks = 0;
                    if (AppVariables.ApplicationSettings["LastItemsUpdate"].ToString() != "Never")
                    {
                        UnixTimeTicks = (Convert.ToDateTime(AppVariables.ApplicationSettings["LastItemsUpdate"], AppVariables.CultureInfoEnglish).Ticks - DateTime.Parse("01/01/1970 00:00:00").Ticks) / 10; //Nanoseconds
                    }

                    //Mark all items as read on api server
                    string[][]        RequestHeader = new string[][] { new[] { "Authorization", "GoogleLogin auth=" + AppVariables.ApplicationSettings["ConnectApiAuth"].ToString() } };
                    HttpStringContent PostContent   = new HttpStringContent("s=user/-/state/com.google/reading-list&ts=" + UnixTimeTicks, Windows.Storage.Streams.UnicodeEncoding.Utf8, "application/x-www-form-urlencoded");

                    HttpResponseMessage PostHttp = await AVDownloader.SendPostRequestAsync(7500, "News Scroll", RequestHeader, new Uri(ApiConnectionUrl + "mark-all-as-read"), PostContent);

                    if (PostHttp != null && (PostHttp.Content.ToString() == "OK" || PostHttp.Content.ToString().Contains("<error>Not found</error>")))
                    {
                        MarkStatus = true;
                    }
                }

                if (MarkStatus)
                {
                    Debug.WriteLine("Marked all items as read on the server or offline sync list.");

                    //Wait for busy database
                    await ApiUpdate.WaitForBusyDatabase();

                    //Update items in database
                    await SQLConnection.ExecuteAsync("UPDATE TableItems SET item_read_status = ('1') WHERE item_read_status = ('0')");

                    //Update current items list
                    List <Items> ListItems = UpdateList.Where(x => x.item_read_status == Visibility.Collapsed).ToList();
                    foreach (Items NewsItem in ListItems)
                    {
                        if ((bool)AppVariables.ApplicationSettings["HideReadMarkedItem"])
                        {
                            UpdateList.Remove(NewsItem);
                        }
                        else
                        {
                            NewsItem.item_read_status = Visibility.Visible;
                        }
                    }

                    await EventProgressEnableUI();
                }
                else
                {
                    await AVMessageBox.Popup("Failed to mark all items read", "Please check your internet connection and try again.", "Ok", "", "", "", "", false);
                    await EventProgressEnableUI();
                }

                return(MarkStatus);
            }
            catch
            {
                await AVMessageBox.Popup("Failed to mark all items read", "Please check your internet connection and try again.", "Ok", "", "", "", "", false);
                await EventProgressEnableUI();

                return(false);
            }
        }
Exemplo n.º 6
0
        //Mark items till as read
        public static async Task <bool> MarkReadTill(ObservableCollection <Items> UpdateList, Items EndItem, bool Confirm, bool Silent, bool EnableUI)
        {
            try
            {
                if (Confirm)
                {
                    Int32 MsgBoxResult = await AVMessageBox.Popup("Mark items read till item", "Do you want to mark all items for the selected feed till this item as read?", "Mark read till item", "", "", "", "", true);

                    if (MsgBoxResult == 0)
                    {
                        return(false);
                    }
                }

                bool   MarkStatus = false;
                string EndItemId  = EndItem.item_id;

                //Check the selected items
                List <Items> TableEditItems = UpdateList.Where(x => x.item_id == EndItemId || x.item_read_status == Visibility.Collapsed).ToList();

                //Check if internet is available
                if (!NetworkInterface.GetIsNetworkAvailable() || ApiMessageError.StartsWith("(Off)"))
                {
                    if (!Silent)
                    {
                        await EventProgressDisableUI("Off marking read till item...", true);
                    }
                    Debug.WriteLine("Off marking read till item...");

                    //Add items to string list
                    List <String> ReadItemIds = new List <String>();
                    foreach (Items NewsItem in TableEditItems)
                    {
                        string NewsItemId = NewsItem.item_id;
                        ReadItemIds.Add(NewsItemId);

                        //Check if the end item has been reached
                        if (EndItemId == NewsItemId)
                        {
                            Debug.WriteLine("Added all news items to the string list.");
                            break;
                        }
                    }

                    await AddOfflineSync(ReadItemIds, "Read");

                    MarkStatus = true;
                }
                else
                {
                    if (!Silent)
                    {
                        await EventProgressDisableUI("Marking read till item...", true);
                    }
                    Debug.WriteLine("Marking read till item...");

                    //Add items to post string
                    string PostStringItemIds = String.Empty;
                    foreach (Items NewsItem in TableEditItems)
                    {
                        string NewsItemId = NewsItem.item_id;
                        PostStringItemIds += "&i=" + NewsItemId;

                        //Check if the end item has been reached
                        if (EndItemId == NewsItemId)
                        {
                            Debug.WriteLine("Added all news items to the post string.");
                            break;
                        }
                    }

                    string[][]        RequestHeader = new string[][] { new[] { "Authorization", "GoogleLogin auth=" + AppVariables.ApplicationSettings["ConnectApiAuth"].ToString() } };
                    HttpStringContent PostContent   = new HttpStringContent("a=user/-/state/com.google/read" + PostStringItemIds, Windows.Storage.Streams.UnicodeEncoding.Utf8, "application/x-www-form-urlencoded");

                    HttpResponseMessage PostHttp = await AVDownloader.SendPostRequestAsync(10000, "News Scroll", RequestHeader, new Uri(ApiConnectionUrl + "edit-tag"), PostContent);

                    if (PostHttp != null && (PostHttp.Content.ToString() == "OK" || PostHttp.Content.ToString().Contains("<error>Not found</error>")))
                    {
                        MarkStatus = true;
                    }
                }

                if (MarkStatus)
                {
                    Debug.WriteLine("Marked items till this item as read on the server or offline sync list.");

                    //Add items to post string
                    string SqlStringItemIds = String.Empty;
                    foreach (Items NewsItem in TableEditItems)
                    {
                        string NewsItemId = NewsItem.item_id;
                        SqlStringItemIds += "'" + NewsItemId + "',";

                        //Check if the end item has been reached
                        if (EndItemId == NewsItemId)
                        {
                            Debug.WriteLine("Added all news items to the sql string.");
                            break;
                        }
                    }

                    //Wait for busy database
                    await ApiUpdate.WaitForBusyDatabase();

                    SqlStringItemIds = AVFunctions.StringRemoveEnd(SqlStringItemIds, ",");
                    await SQLConnection.ExecuteAsync("UPDATE TableItems SET item_read_status = ('1') WHERE item_id IN (" + SqlStringItemIds + ") AND item_read_status = ('0')");

                    //Update current items list
                    foreach (Items NewsItem in UpdateList.ToList())
                    {
                        //Mark the item as read or remove it from list
                        if ((bool)AppVariables.ApplicationSettings["HideReadMarkedItem"])
                        {
                            UpdateList.Remove(NewsItem);
                        }
                        else
                        {
                            NewsItem.item_read_status = Visibility.Visible;
                        }

                        //Check if the end item has been reached
                        if (EndItemId == NewsItem.item_id)
                        {
                            Debug.WriteLine("Marked items till this item as read in the list and database.");
                            break;
                        }
                    }

                    if (EnableUI)
                    {
                        await EventProgressEnableUI();
                    }
                }
                else
                {
                    await AVMessageBox.Popup("Failed to mark items read", "Please check your internet connection and try again.", "Ok", "", "", "", "", false);
                    await EventProgressEnableUI();
                }

                return(MarkStatus);
            }
            catch
            {
                await AVMessageBox.Popup("Failed to mark items read", "Please check your internet connection and try again.", "Ok", "", "", "", "", false);
                await EventProgressEnableUI();

                return(false);
            }
        }
Exemplo n.º 7
0
        private static async Task <bool> MarkReadSingle(ObservableCollection <Items> UpdateList, Items ListItem, string ActionType, bool Silent)
        {
            try
            {
                bool   MarkStatus = false;
                string ItemId     = ListItem.item_id;

                //Check if internet is available
                if (Connectivity.NetworkAccess != NetworkAccess.Internet || ApiMessageError.StartsWith("(Off)"))
                {
                    if (!Silent)
                    {
                        EventProgressDisableUI("Off marking item as " + ActionType.ToLower() + "...", true);
                    }
                    Debug.WriteLine("Off marking item as " + ActionType.ToLower() + "...");

                    await AddOfflineSync(ItemId, ActionType);

                    MarkStatus = true;
                }
                else
                {
                    if (!Silent)
                    {
                        EventProgressDisableUI("Marking item as " + ActionType.ToLower() + "...", true);
                    }
                    Debug.WriteLine("Marking item as " + ActionType.ToLower() + "...");

                    string[][] RequestHeader = new string[][] { new[] { "Authorization", "GoogleLogin auth=" + AppSettingLoad("ConnectApiAuth").ToString() } };

                    StringContent PostContent;
                    if (ActionType == "Read")
                    {
                        PostContent = new StringContent("i=" + ItemId + "&a=user/-/state/com.google/read", Encoding.UTF8, "application/x-www-form-urlencoded");
                    }
                    else
                    {
                        PostContent = new StringContent("i=" + ItemId + "&r=user/-/state/com.google/read", Encoding.UTF8, "application/x-www-form-urlencoded");
                    }
                    Uri PostUri = new Uri(ApiConnectionUrl + "edit-tag");

                    string PostHttp = await AVDownloader.SendPostRequestAsync(7500, "News Scroll", RequestHeader, PostUri, PostContent);

                    if (PostHttp != null && (PostHttp == "OK" || PostHttp.Contains("<error>Not found</error>")))
                    {
                        MarkStatus = true;
                    }
                }

                if (MarkStatus)
                {
                    //Get the current page name
                    string currentPage = App.Current.MainPage.ToString();

                    //Mark item in database and list
                    TableItems TableEditItems = await vSQLConnection.Table <TableItems>().Where(x => x.item_id == ItemId).FirstOrDefaultAsync();

                    if (TableEditItems != null)
                    {
                        if (ActionType == "Read")
                        {
                            TableEditItems.item_read_status = true;
                            ListItem.item_read_status       = true;
                            ListItem.item_read_icon         = ImageSource.FromResource("NewsScroll.Assets.iconRead-Dark.png");
                        }
                        else
                        {
                            TableEditItems.item_read_status = false;
                            ListItem.item_read_status       = false;
                            ListItem.item_read_icon         = null;
                        }
                    }

                    //Update the items in database
                    await vSQLConnection.UpdateAsync(TableEditItems);
                }
                else
                {
                    List <string> messageAnswers = new List <string>();
                    messageAnswers.Add("Ok");

                    await MessagePopup.Popup("Failed to mark item " + ActionType.ToLower(), "Please check your internet connection and try again.", messageAnswers);

                    EventProgressEnableUI();
                }

                return(MarkStatus);
            }
            catch
            {
                Debug.WriteLine("Failed to un/read item.");
                return(false);
            }
        }
Exemplo n.º 8
0
        //Mark all items as read
        public static async Task <bool> MarkReadAll(ObservableCollection <Items> UpdateList, bool Confirm)
        {
            try
            {
                //Check if user is logged in
                if (!CheckLogin())
                {
                    List <string> messageAnswers = new List <string>();
                    messageAnswers.Add("Ok");

                    await MessagePopup.Popup("Not logged in", "Marking all items read can only be done when you are logged in.", messageAnswers);

                    return(false);
                }

                if (Confirm)
                {
                    List <string> messageAnswers = new List <string>();
                    messageAnswers.Add("Mark all items read");
                    messageAnswers.Add("Cancel");

                    string messageResult = await MessagePopup.Popup("Mark all items read", "Do you want to mark all items for every feed as read?", messageAnswers);

                    if (messageResult == "Cancel")
                    {
                        return(false);
                    }
                }

                bool MarkStatus = false;

                //Check if internet is available
                if (Connectivity.NetworkAccess != NetworkAccess.Internet || ApiMessageError.StartsWith("(Off)"))
                {
                    EventProgressDisableUI("Off marking all items as read...", true);
                    Debug.WriteLine("Off marking all items as read...");

                    List <string> UnreadItemList = (await vSQLConnection.Table <TableItems>().Where(x => !x.item_read_status).ToListAsync()).Select(x => x.item_id).ToList();
                    await AddOfflineSync(UnreadItemList, "Read");

                    MarkStatus = true;
                }
                else
                {
                    EventProgressDisableUI("Marking all items as read...", true);
                    Debug.WriteLine("Marking all items as read...");

                    //Date time variables
                    long UnixTimeTicks = 0;
                    if (AppSettingLoad("LastItemsUpdate").ToString() != "Never")
                    {
                        UnixTimeTicks = (Convert.ToDateTime(AppSettingLoad("LastItemsUpdate"), AppVariables.CultureInfoEnglish).Ticks - DateTime.Parse("01/01/1970 00:00:00").Ticks) / 10; //Nanoseconds
                    }

                    //Mark all items as read on api server
                    string[][]    RequestHeader = new string[][] { new[] { "Authorization", "GoogleLogin auth=" + AppSettingLoad("ConnectApiAuth").ToString() } };
                    StringContent PostContent   = new StringContent("s=user/-/state/com.google/reading-list&ts=" + UnixTimeTicks, Encoding.UTF8, "application/x-www-form-urlencoded");
                    Uri           PostUri       = new Uri(ApiConnectionUrl + "mark-all-as-read");

                    string PostHttp = await AVDownloader.SendPostRequestAsync(7500, "News Scroll", RequestHeader, PostUri, PostContent);

                    if (PostHttp != null && (PostHttp == "OK" || PostHttp.Contains("<error>Not found</error>")))
                    {
                        MarkStatus = true;
                    }
                }

                if (MarkStatus)
                {
                    Debug.WriteLine("Marked all items as read on the server or offline sync list.");

                    //Update items in database
                    await vSQLConnection.ExecuteAsync("UPDATE TableItems SET item_read_status = ('1') WHERE item_read_status = ('0')");

                    //Update current items list
                    List <Items> ListItems = UpdateList.Where(x => x.item_read_status == false).ToList();
                    foreach (Items NewsItem in ListItems)
                    {
                        //Mark the item as read
                        NewsItem.item_read_status = true;
                        NewsItem.item_read_icon   = ImageSource.FromResource("NewsScroll.Assets.iconRead-Dark.png");
                    }

                    EventProgressEnableUI();
                }
                else
                {
                    List <string> messageAnswers = new List <string>();
                    messageAnswers.Add("Ok");

                    await MessagePopup.Popup("Failed to mark all items read", "Please check your internet connection and try again.", messageAnswers);

                    EventProgressEnableUI();
                }

                return(MarkStatus);
            }
            catch
            {
                List <string> messageAnswers = new List <string>();
                messageAnswers.Add("Ok");

                await MessagePopup.Popup("Failed to mark all items read", "Please check your internet connection and try again.", messageAnswers);

                EventProgressEnableUI();
                return(false);
            }
        }
Exemplo n.º 9
0
        //Mark items till as read
        public static async Task <bool> MarkReadTill(ObservableCollection <Items> UpdateList, Items EndItem, bool Confirm, bool Silent, bool EnableUI)
        {
            try
            {
                if (Confirm)
                {
                    List <string> messageAnswers = new List <string>();
                    messageAnswers.Add("Mark read till item");
                    messageAnswers.Add("Cancel");

                    string messageResult = await MessagePopup.Popup("Mark items read till item", "Do you want to mark all items for the selected feed till this item as read?", messageAnswers);

                    if (messageResult == "Cancel")
                    {
                        return(false);
                    }
                }

                bool   MarkStatus = false;
                string EndItemId  = EndItem.item_id;

                //Check the selected items
                List <Items> TableEditItems = UpdateList.Where(x => x.item_id == EndItemId || x.item_read_status == false).ToList();

                //Check if internet is available
                if (Connectivity.NetworkAccess != NetworkAccess.Internet || ApiMessageError.StartsWith("(Off)"))
                {
                    if (!Silent)
                    {
                        EventProgressDisableUI("Off marking read till item...", true);
                    }
                    Debug.WriteLine("Off marking read till item...");

                    //Add items to string list
                    List <string> ReadItemIds = new List <string>();
                    foreach (Items NewsItem in TableEditItems)
                    {
                        string NewsItemId = NewsItem.item_id;
                        ReadItemIds.Add(NewsItemId);

                        //Check if the end item has been reached
                        if (EndItemId == NewsItemId)
                        {
                            Debug.WriteLine("Added all news items to the string list.");
                            break;
                        }
                    }

                    await AddOfflineSync(ReadItemIds, "Read");

                    MarkStatus = true;
                }
                else
                {
                    if (!Silent)
                    {
                        EventProgressDisableUI("Marking read till item...", true);
                    }
                    Debug.WriteLine("Marking read till item...");

                    //Add items to post string
                    string PostStringItemIds = string.Empty;
                    foreach (Items NewsItem in TableEditItems)
                    {
                        string NewsItemId = NewsItem.item_id;
                        PostStringItemIds += "&i=" + NewsItemId;

                        //Check if the end item has been reached
                        if (EndItemId == NewsItemId)
                        {
                            Debug.WriteLine("Added all news items to the post string.");
                            break;
                        }
                    }

                    string[][]    RequestHeader = new string[][] { new[] { "Authorization", "GoogleLogin auth=" + AppSettingLoad("ConnectApiAuth").ToString() } };
                    StringContent PostContent   = new StringContent("a=user/-/state/com.google/read" + PostStringItemIds, Encoding.UTF8, "application/x-www-form-urlencoded");
                    Uri           PostUri       = new Uri(ApiConnectionUrl + "edit-tag");

                    string PostHttp = await AVDownloader.SendPostRequestAsync(10000, "News Scroll", RequestHeader, PostUri, PostContent);

                    if (PostHttp != null && (PostHttp == "OK" || PostHttp.Contains("<error>Not found</error>")))
                    {
                        MarkStatus = true;
                    }
                }

                if (MarkStatus)
                {
                    Debug.WriteLine("Marked items till this item as read on the server or offline sync list.");

                    //Add items to post string
                    string SqlStringItemIds = string.Empty;
                    foreach (Items NewsItem in TableEditItems)
                    {
                        string NewsItemId = NewsItem.item_id;
                        SqlStringItemIds += "'" + NewsItemId + "',";

                        //Check if the end item has been reached
                        if (EndItemId == NewsItemId)
                        {
                            Debug.WriteLine("Added all news items to the sql string.");
                            break;
                        }
                    }

                    SqlStringItemIds = AVFunctions.StringRemoveEnd(SqlStringItemIds, ",");
                    await vSQLConnection.ExecuteAsync("UPDATE TableItems SET item_read_status = ('1') WHERE item_id IN (" + SqlStringItemIds + ") AND item_read_status = ('0')");

                    //Update current items list
                    foreach (Items NewsItem in UpdateList.ToList())
                    {
                        //Mark the item as read
                        NewsItem.item_read_status = true;
                        NewsItem.item_read_icon   = ImageSource.FromResource("NewsScroll.Assets.iconRead-Dark.png");

                        //Check if the end item has been reached
                        if (EndItemId == NewsItem.item_id)
                        {
                            Debug.WriteLine("Marked items till this item as read in the list and database.");
                            break;
                        }
                    }

                    if (EnableUI)
                    {
                        EventProgressEnableUI();
                    }
                }
                else
                {
                    List <string> messageAnswers = new List <string>();
                    messageAnswers.Add("Ok");

                    await MessagePopup.Popup("Failed to mark items read", "Please check your internet connection and try again.", messageAnswers);

                    EventProgressEnableUI();
                }

                return(MarkStatus);
            }
            catch
            {
                List <string> messageAnswers = new List <string>();
                messageAnswers.Add("Ok");

                await MessagePopup.Popup("Failed to mark items read", "Please check your internet connection and try again.", messageAnswers);

                EventProgressEnableUI();
                return(false);
            }
        }
Exemplo n.º 10
0
        public static async Task <int> PageApiUpdate()
        {
            try
            {
                //Reset load variables
                AppVariables.CurrentTotalItemsCount = 0;
                AppVariables.CurrentFeedsLoaded     = 0;
                AppVariables.CurrentItemsLoaded     = 0;
                AppVariables.BusyApplication        = true;
                Debug.WriteLine("Started updating api (News: " + OnlineUpdateNews + " Starred: " + OnlineUpdateStarred + " Feeds: " + OnlineUpdateFeeds + ")");

                //Check if offline mode is enabled
                if (!ApiMessageError.Contains("Off"))
                {
                    //Check update success
                    bool UpdateStatus = true;

                    //Check the login status
                    if ((OnlineUpdateNews || OnlineUpdateStarred || OnlineUpdateFeeds) && !AppVariables.LoadSearch && !CheckLogin())
                    {
                        UpdateStatus = await Login(false, false);

                        if (UpdateStatus)
                        {
                            ApiMessageError = string.Empty;
                        }
                        else
                        {
                            List <string> messageAnswers = new List <string>();
                            messageAnswers.Add("Retry to login");
                            messageAnswers.Add("Go to account settings");
                            messageAnswers.Add("Switch to offline mode");

                            string messageResult = await MessagePopup.Popup("Failed to login", "Would you like to retry to login to The Old Reader or do you want to switch to offline mode?\n\nMake sure that you have an internet connection and that your correct account settings are set before retrying.", messageAnswers);

                            if (messageResult == "Retry to login")
                            {
                                return(await PageApiUpdate());
                            }
                            else if (messageResult == "Go to account settings")
                            {
                                AppVariables.BusyApplication = false;
                                return(2);
                            }
                            else
                            {
                                ApiMessageError = "(Off) ";
                            }
                        }
                    }

                    //Download feeds from Api
                    if (UpdateStatus && AppVariables.LoadFeeds && OnlineUpdateFeeds && !ApiMessageError.Contains("Off"))
                    {
                        UpdateStatus = await Feeds(false, false);

                        if (UpdateStatus)
                        {
                            ApiMessageError   = string.Empty;
                            OnlineUpdateFeeds = false;
                        }
                        else
                        {
                            List <string> messageAnswers = new List <string>();
                            messageAnswers.Add("Retry downloading feeds");
                            messageAnswers.Add("Go to account settings");
                            messageAnswers.Add("Switch to offline mode");

                            string messageResult = await MessagePopup.Popup("Failed to load the feeds", "Would you like to retry loading the feeds or do you want to switch to offline mode?\n\nMake sure that you have an internet connection and that your correct account settings are set before retrying.", messageAnswers);

                            if (messageResult == "Retry downloading feeds")
                            {
                                return(await PageApiUpdate());
                            }
                            else if (messageResult == "Go to account settings")
                            {
                                AppVariables.BusyApplication = false;
                                return(2);
                            }
                            else
                            {
                                ApiMessageError   = "(Off) ";
                                OnlineUpdateFeeds = true;
                            }
                        }
                    }

                    //Download news items from Api
                    if (UpdateStatus && AppVariables.LoadNews && OnlineUpdateNews)
                    {
                        //Remove older news items
                        await ItemsRemoveOld(false, false);

                        //Sync offline changed items
                        await SyncOfflineChanges(false, false);

                        //Download news items from Api
                        if (!ApiMessageError.Contains("Off"))
                        {
                            if (UpdateStatus)
                            {
                                UpdateStatus = await AllNewsItems(true, false, false, false);
                            }
                            if (!UpdateStatus)
                            {
                                List <string> messageAnswers = new List <string>();
                                messageAnswers.Add("Retry downloading items");
                                messageAnswers.Add("Switch to offline mode");

                                string messageResult = await MessagePopup.Popup("Failed to load the items", "Would you like to retry loading the items or do you want to switch to offline mode?\n\nMake sure that you have an internet connection and that your correct account settings are set before retrying.", messageAnswers);

                                if (messageResult == "Retry downloading items")
                                {
                                    return(await PageApiUpdate());
                                }
                                else
                                {
                                    ApiMessageError  = "(Off) ";
                                    OnlineUpdateNews = true;
                                }
                            }
                        }

                        //Download read status from Api
                        if (!ApiMessageError.Contains("Off"))
                        {
                            if (UpdateStatus)
                            {
                                UpdateStatus = await ItemsRead(List_NewsItems, false, false);
                            }
                            if (!UpdateStatus)
                            {
                                List <string> messageAnswers = new List <string>();
                                messageAnswers.Add("Retry downloading read items");
                                messageAnswers.Add("Switch to offline mode");

                                string messageResult = await MessagePopup.Popup("Failed to load read items", "Would you like to retry loading read items or do you want to switch to offline mode?\n\nMake sure that you have an internet connection and that your correct account settings are set before retrying.", messageAnswers);

                                if (messageResult == "Retry downloading read items")
                                {
                                    return(await PageApiUpdate());
                                }
                                else
                                {
                                    ApiMessageError  = "(Off) ";
                                    OnlineUpdateNews = true;
                                }
                            }
                        }

                        //Check if news items updated
                        if (UpdateStatus && !ApiMessageError.Contains("Off"))
                        {
                            ApiMessageError  = string.Empty;
                            OnlineUpdateNews = false;
                        }
                    }

                    //Download starred items from Api
                    if (UpdateStatus && AppVariables.LoadStarred && OnlineUpdateStarred && !ApiMessageError.Contains("Off"))
                    {
                        UpdateStatus = await ItemsStarred(true, false, false);

                        if (UpdateStatus)
                        {
                            ApiMessageError     = string.Empty;
                            OnlineUpdateStarred = false;
                        }
                        else
                        {
                            List <string> messageAnswers = new List <string>();
                            messageAnswers.Add("Retry downloading starred items");
                            messageAnswers.Add("Switch to offline mode");

                            string messageResult = await MessagePopup.Popup("Failed to load starred items", "Would you like to retry loading starred items or do you want to switch to offline mode?\n\nMake sure that you have an internet connection and that your correct account settings are set before retrying.", messageAnswers);

                            if (messageResult == "Retry downloading starred items")
                            {
                                return(await PageApiUpdate());
                            }
                            else
                            {
                                ApiMessageError     = "(Off) ";
                                OnlineUpdateStarred = true;
                            }
                        }
                    }
                }

                Debug.WriteLine("Finished the update task.");
                AppVariables.BusyApplication = false;
                return(0);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed to start update task: " + ex.Message);
                AppVariables.BusyApplication = false;
                return(1);
            }
        }
Exemplo n.º 11
0
        private static async Task <bool> MarkStarSingle(Items ListItem, bool RemoveFromList, string ActionType, bool Silent)
        {
            try
            {
                bool   MarkStatus = false;
                string ItemId     = ListItem.item_id;

                //Check if internet is available
                if (!AppVariables.InternetAccess || ApiMessageError.StartsWith("(Off)"))
                {
                    if (!Silent)
                    {
                        await EventProgressDisableUI("Off " + ActionType.ToLower() + "ring the item...", true);
                    }
                    System.Diagnostics.Debug.WriteLine("Off " + ActionType.ToLower() + "ring the item...");

                    await AddOfflineSync(ItemId, ActionType);

                    MarkStatus = true;
                }
                else
                {
                    if (!Silent)
                    {
                        await EventProgressDisableUI(ActionType + "ring the item...", true);
                    }
                    System.Diagnostics.Debug.WriteLine(ActionType + "ring the item...");

                    string[][] RequestHeader = new string[][] { new[] { "Authorization", "GoogleLogin auth=" + AppVariables.ApplicationSettings["ConnectApiAuth"].ToString() } };

                    StringContent PostContent;
                    if (ActionType == "Star")
                    {
                        PostContent = new StringContent("i=" + ItemId + "&a=user/-/state/com.google/starred", Encoding.UTF8, "application/x-www-form-urlencoded");
                    }
                    else
                    {
                        PostContent = new StringContent("i=" + ItemId + "&r=user/-/state/com.google/starred", Encoding.UTF8, "application/x-www-form-urlencoded");
                    }

                    string PostHttp = await AVDownloader.SendPostRequestAsync(7500, "News Scroll", RequestHeader, new Uri(ApiConnectionUrl + "edit-tag"), PostContent);

                    if (PostHttp == "OK" || PostHttp.Contains("<error>Not found</error>"))
                    {
                        MarkStatus = true;
                    }
                }

                if (MarkStatus)
                {
                    //Mark item in database and list
                    TableItems TableEditItems = await SQLConnection.Table <TableItems>().Where(x => x.item_id == ItemId).FirstOrDefaultAsync();

                    if (TableEditItems != null)
                    {
                        if (ActionType == "Star")
                        {
                            TableEditItems.item_star_status = true;
                            ListItem.item_star_status       = Visibility.Visible;
                        }
                        else
                        {
                            TableEditItems.item_star_status = false;
                            ListItem.item_star_status       = Visibility.Collapsed;
                            if (RemoveFromList)
                            {
                                List_StarredItems.Remove(ListItem);
                            }
                        }
                    }

                    //Update the items in database
                    await SQLConnection.UpdateAsync(TableEditItems);
                }
                else
                {
                    await new MessagePopup().OpenPopup("Failed to " + ActionType.ToLower() + " item", "Please check your internet connection and try again.", "Ok", "", "", "", "", false);
                    await EventProgressEnableUI();
                }

                return(MarkStatus);
            }
            catch
            {
                System.Diagnostics.Debug.WriteLine("Failed to un/star item.");
                return(false);
            }
        }