Example #1
0
 public static void Push()
 {
     if (Settings.SyncOn && Reachability.IsDefaultNetworkAvailable())
     {
         StartPush();
     }
 }
Example #2
0
        private static void PullStart()
        {
            if (cancelled)
            {
                SetReceive(true);

                CheckReceiveDone();
            }
            else
            {
                if (Reachability.IsDefaultNetworkAvailable())
                {
                    SaveMyStuff.GetMyBooksEvent += HandleGetMyBooksEvent;
                    SaveMyStuff.GetMyBooks();
                }
                else
                {
                    if (currentSyncType == SyncType.PUSH_AND_PULL)
                    {
                        if (SyncDoneEvent != null)
                        {
                            SyncDoneEvent();
                        }
                    }
                }
            }
        }
Example #3
0
        public static void Show(UIView view, CloudSync.SyncType syncType)
        {
            if (Reachability.IsDefaultNetworkAvailable())
            {
                LoadingView.CancelEvent += HandleCancelEvent;
                LoadingView.Show("Syncing", "Please wait while" + '\n' + "eBriefing is syncing." + '\n' + "This may take a few minutes...");

                // Pull sync
                if (syncType == CloudSync.SyncType.PULL)
                {
                    CloudSync.ReceiveDoneEvent += HandleReceiveDoneEvent;

                    CloudSync.Pull();
                }

                // Push and Pull sync
                else if (syncType == CloudSync.SyncType.PUSH_AND_PULL)
                {
                    PushNPullInProgress      = true;
                    CloudSync.SyncDoneEvent += HandleSyncDoneEvent;

                    CloudSync.PushAndPull();
                }
            }
            else
            {
                StartTimer();
            }
        }
Example #4
0
 public static void PullMyStuffs(Book book)
 {
     if (Settings.SyncOn && Reachability.IsDefaultNetworkAvailable())
     {
         PullMyStuffsWork(book);
     }
 }
        public void CancelDownload(Book book)
        {
            try
            {
                if (BookUpdater.CurrentBook.ID == book.ID)
                {
                    book.Cancelled = true;

                    BookUpdater.CancelDownloadOperations();

                    // If internet connection is available, remove the current book and start download next one
                    if (Reachability.IsDefaultNetworkAvailable())
                    {
                        GetBookViewAndUpdateCollectionView(book.ID);
                    }
                    else
                    {
                        // Cancel current downloads if it's in progress
                        CancelAllDownloads();
                    }
                }
                else
                {
                    BookUpdater.RemoveBookFromDevice(book);
                    BookUpdater.Dequeue(book.ID);
                }

                RefreshTable();
            }
            catch (Exception ex)
            {
                Logger.WriteLineDebugging("BookshelfViewController - CancelDownload: {0}", ex.ToString());
            }
        }
Example #6
0
        private static void SendMyAnnotations(List <Book> bookList)
        {
            if (cancelled)
            {
                SetSent(true);

                CheckSentDone();
            }
            else
            {
                if (Reachability.IsDefaultNetworkAvailable())
                {
                    SaveMyStuff.SetMyAnnotationEvent += HandleSetMyAnnotationEvent;

                    foreach (Book book in bookList)
                    {
                        List <Annotation> annotationList = BooksOnDeviceAccessor.GetAllAnnotations(book.ID);
                        if (annotationList != null && annotationList.Count > 0)
                        {
                            for (Int32 i = 0; i < annotationList.Count; i++)
                            {
                                bool lastItem = false;
                                if (i == annotationList.Count - 1)
                                {
                                    lastItem = true;
                                }

                                if (annotationList[i].Removed)
                                {
                                    SaveMyStuff.RemoveMyAnnotation(annotationList[i], lastItem);
                                }
                                else
                                {
                                    SaveMyStuff.SetMyAnnotation(annotationList[i], lastItem);
                                }
                            }
                        }
                        else
                        {
                            sentAnnotations = true;
                        }
                    }

                    // Remove annotation that are marked as removed
                    foreach (Book book in bookList)
                    {
                        List <Annotation> annotationList = BooksOnDeviceAccessor.GetRemovedAnnotations(book.ID);
                        if (annotationList != null && annotationList.Count > 0)
                        {
                            foreach (Annotation annotation in annotationList)
                            {
                                BooksOnDeviceAccessor.RemoveAnnotation(annotation.BookID, annotation.PageID);
                            }
                        }
                    }
                }
            }
        }
Example #7
0
        private static void SendMyNotes(List <Book> bookList)
        {
            if (cancelled)
            {
                SetSent(true);

                CheckSentDone();
            }
            else
            {
                if (Reachability.IsDefaultNetworkAvailable())
                {
                    SaveMyStuff.SetMyNoteEvent += HandleSetMyNoteEvent;

                    foreach (Book book in bookList)
                    {
                        List <Note> noteList = BooksOnDeviceAccessor.GetAllNotes(book.ID);
                        if (noteList != null && noteList.Count > 0)
                        {
                            for (Int32 i = 0; i < noteList.Count; i++)
                            {
                                bool lastItem = false;
                                if (i == noteList.Count - 1)
                                {
                                    lastItem = true;
                                }

                                if (noteList[i].Removed)
                                {
                                    SaveMyStuff.RemoveMyNote(noteList[i], lastItem);
                                }
                                else
                                {
                                    SaveMyStuff.SetMyNote(noteList[i], lastItem);
                                }
                            }
                        }
                        else
                        {
                            sentNotes = true;
                        }
                    }

                    // Remove notes that are marked as removed
                    foreach (Book book in bookList)
                    {
                        List <Note> noteList = BooksOnDeviceAccessor.GetRemovedNotes(book.ID);
                        if (noteList != null && noteList.Count > 0)
                        {
                            foreach (Note note in noteList)
                            {
                                BooksOnDeviceAccessor.RemoveNote(note.BookID, note.PageID);
                            }
                        }
                    }
                }
            }
        }
        async private void Connect()
        {
            if (!Reachability.IsDefaultNetworkAvailable())
            {
                AlertView.Show(StringRef.connectionFailure, StringRef.connectionRequired, StringRef.ok);
            }
            else
            {
                try
                {
                    bool notCompatible             = false;
                    WebExceptionStatus errorStatus = WebExceptionStatus.ConnectFailure;
                    cts = new CancellationTokenSource();

                    Settings.WriteUseFormsAuth(false);

                    LoadingView.Show("Connecting", "Please wait while we're connecting to Demo Library...");
                    await eBriefingService.Run(() => StartAuthenticate(out errorStatus, out notCompatible), cts.Token);

                    LoadingView.Hide();
                    cts.Token.ThrowIfCancellationRequested();

                    if (errorStatus == WebExceptionStatus.Success)
                    {
                        Settings.Authenticated      = true;
                        Settings.AvailableCheckTime = DateTime.MinValue;
                        Settings.WriteSyncOn(false);

                        CancelAllDownloads();

                        // Success
                        Dismiss(false);
                    }
                    else
                    {
                        Settings.Authenticated = false;

                        if (notCompatible)
                        {
                            AlertView.Show(StringRef.alert, StringRef.notCompatible, StringRef.ok);
                        }
                        else
                        {
                            WebExceptionAlertView.ShowAlert(errorStatus);
                        }
                    }
                }
                catch (OperationCanceledException)
                {
                    KeychainAccessor.ClearCredential();
                }
            }
        }
Example #9
0
 async void HandleSyncButtonTouchEvent()
 {
     HidePopover();
     if (Reachability.IsDefaultNetworkAvailable())
     {
         await OpenSyncView();
     }
     else
     {
         AlertView.Show(StringRef.connectionFailure, StringRef.connectionRequired, StringRef.ok);
     }
 }
Example #10
0
        public static void GetMyStuff(String bookID)
        {
            if (Settings.SyncOn)
            {
                if (Reachability.IsDefaultNetworkAvailable())
                {
                    SaveMyStuff.GetMyBookmarksEvent   += HandleGetMyBookmarksEvent;
                    SaveMyStuff.GetMyNotesEvent       += HandleGetMyNotesEvent;
                    SaveMyStuff.GetMyAnnotationsEvent += HandleGetMyAnnotationsEvent;

                    SaveMyStuff.GetMyBookmarks(bookID, true);
                    SaveMyStuff.GetMyNotes(bookID, true);
                    SaveMyStuff.GetMyAnnotations(bookID, true);
                }
            }
        }
Example #11
0
        private static void SendMyBookmarks(List <Book> bookList)
        {
            if (cancelled)
            {
                SetSent(true);

                CheckSentDone();
            }
            else
            {
                if (Reachability.IsDefaultNetworkAvailable())
                {
                    SaveMyStuff.SetMyBookmarksEvent += HandleSetMyBookmarksEvent;

                    foreach (Book book in bookList)
                    {
                        List <Bookmark> bookmarkList = BooksOnDeviceAccessor.GetAllBookmarks(book.ID);
                        if (bookmarkList != null && bookmarkList.Count > 0)
                        {
                            SaveMyStuff.SetMyBookmarks(bookmarkList);
                        }
                        else
                        {
                            sentBookmarks = true;
                        }
                    }

                    // Remove bookmarks that are marked as removed
                    foreach (Book book in bookList)
                    {
                        List <Bookmark> bookmarkList = BooksOnDeviceAccessor.GetRemovedBookmarks(book.ID);
                        if (bookmarkList != null && bookmarkList.Count > 0)
                        {
                            foreach (Bookmark bookmark in bookmarkList)
                            {
                                BooksOnDeviceAccessor.RemoveBookmark(bookmark.BookID, bookmark.PageID);
                            }
                        }
                    }
                }
            }
        }
Example #12
0
        public static bool Download(String url, UIViewController controller, bool forceDownload = false)
        {
            bool exist = false;

            if (!String.IsNullOrEmpty(url) && url.Contains("http"))
            {
                try
                {
                    String localPath = DownloadedFilesCache.BuildCachedFilePath(url);
                    if (File.Exists(localPath) && !forceDownload)
                    {
                        exist = true;
                    }
                    else
                    {
                        if (Reachability.IsDefaultNetworkAvailable())
                        {
                            BackgroundWorker downloadWorker = new BackgroundWorker();
                            downloadWorker.DoWork += delegate
                            {
                                ASIHTTPRequest request = new ASIHTTPRequest(NSUrl.FromString(url));
                                request.Username                = Settings.UserID;
                                request.Password                = KeychainAccessor.Password;
                                request.Domain                  = Settings.Domain;
                                request.Delegate                = controller;
                                request.DidFinishSelector       = new Selector("requestFinish:");
                                request.DownloadDestinationPath = DownloadedFilesCache.BuildCachedFilePath(url);
                                request.StartAsynchronous();
                            };
                            downloadWorker.RunWorkerAsync();
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.WriteLineDebugging("FileDownloader - Download: {0}", ex.ToString());
                }
            }

            return(exist);
        }
        async public void LoadBooks()
        {
            TimeSpan diff = DateTime.UtcNow.Subtract(Settings.AvailableCheckTime);

            if (TimeSettings.LibraryRefreshRequired(diff))
            {
                if (Reachability.IsDefaultNetworkAvailable())
                {
                    LoadingView.Show("Loading", "Please wait while we're checking Available Books...", false);

                    List <Book> bookList = await eBriefingService.Run(() => eBriefingService.StartDownloadBooks());

                    if (bookList != null)
                    {
                        Settings.AvailableCheckTime = DateTime.UtcNow;

                        // Save in the cache
                        BooksOnServerAccessor.SaveBooks(bookList);

                        // Load books
                        RetrieveBooks();

                        // Update available badge
                        UpdateAvailableBadge();
                    }
                    else
                    {
                        LoadingView.Hide();
                    }
                }
                else
                {
                    UpdateStatusLabel(StringRef.connectionRequired);
                }
            }
            else
            {
                RetrieveBooks();
            }
        }
        public void RetrieveBooks()
        {
            if (!Reachability.IsDefaultNetworkAvailable())
            {
                UpdateStatusLabel(StringRef.connectionRequired);
            }
            else
            {
                List <Book> bookList = BooksOnServerAccessor.GetBooks();
                if (bookList == null)
                {
                    UpdateStatusLabel("There are no available books.");

                    Failed2RetrieveBooks();
                }
                else
                {
                    // Load collectionView
                    LoadCollectionView();
                }
            }
        }
Example #15
0
        async private void StartAuthentication()
        {
            if (Reachability.IsDefaultNetworkAvailable())
            {
                if (!String.IsNullOrEmpty(URL.ServerURL))
                {
                    bool verified = await eBriefingService.Run(() => CheckCredential());

                    if (verified)
                    {
                        Dismiss();
                    }
                    else
                    {
                        ShowErrorView();
                    }
                }
            }
            else
            {
                ShowErrorView();
            }
        }
Example #16
0
        private static void PushStart()
        {
            if (Reachability.IsDefaultNetworkAvailable())
            {
                // SEND
                List <Book> bookList = BooksOnDeviceAccessor.GetAllBooks();
                if (bookList != null && bookList.Count > 0)
                {
                    SendMyBooks(bookList);

                    SendMyBookmarks(bookList);

                    SendMyNotes(bookList);

                    SendMyAnnotations(bookList);
                }
                else
                {
                    sentBooks = sentBookmarks = sentNotes = sentAnnotations = true;

                    CheckSentDone();
                }
            }
        }
Example #17
0
        private static void SendMyBooks(List <Book> bookList)
        {
            if (cancelled)
            {
                SetSent(true);

                CheckSentDone();
            }
            else
            {
                if (Reachability.IsDefaultNetworkAvailable())
                {
                    SaveMyStuff.SetMyBooksEvent += HandleSetMyBooksEvent;
                    SaveMyStuff.SetMyBooks(bookList);

                    // Remove books that are marked as removed
                    List <Book> removeList = BooksOnDeviceAccessor.GetRemovedBooks();
                    if (removeList != null && removeList.Count > 0)
                    {
                        BookRemover.RemoveBooks(removeList);
                    }
                }
            }
        }
            public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
            {
                UITableViewCell cell = tableView.DequeueReusableCell("PopoverSettingIdentifier");

                try
                {
                    if (cell == null)
                    {
                        cell = new UITableViewCell(UITableViewCellStyle.Default, "PopoverSettingIdentifier");
                    }

                    cell.Accessory      = UITableViewCellAccessory.None;
                    cell.SelectionStyle = UITableViewCellSelectionStyle.Default;

                    if (indexPath.Section == 0 && indexPath.Row == 1)
                    {
                        cell.SelectionStyle = UITableViewCellSelectionStyle.None;

                        cell.TextLabel.Text  = "Content Sync";
                        cell.ImageView.Image = UIImage.FromBundle("Assets/Icons/sync.png");

                        if (syncSwitch == null)
                        {
                            syncSwitch               = new UISwitch();
                            syncSwitch.Frame         = new CGRect(tableView.Frame.Size.Width - 20 - syncSwitch.Frame.Width, 22f - (syncSwitch.Frame.Height / 2f), syncSwitch.Frame.Width, syncSwitch.Frame.Height);
                            syncSwitch.ValueChanged += (object sender, EventArgs e) =>
                            {
                                Settings.WriteSyncOn(syncSwitch.On);

                                if (Settings.SyncOn)
                                {
                                    if (parent.SyncOnEvent != null)
                                    {
                                        parent.SyncOnEvent();
                                    }
                                }
                                else
                                {
                                    if (parent.SyncOffEvent != null)
                                    {
                                        parent.SyncOffEvent();
                                    }
                                }
                            };

                            // Disable syncing for Demo server
                            syncSwitch.SetState(Settings.SyncOn, false);

                            if (Reachability.IsDefaultNetworkAvailable() && !URL.ServerURL.Contains(StringRef.DemoURL))
                            {
                                syncSwitch.Enabled = true;
                            }
                            else
                            {
                                syncSwitch.Enabled = false;
                            }
                        }
                        cell.ContentView.AddSubview(syncSwitch);
                    }
                    else
                    {
                        if (indexPath.Section == 0)
                        {
                            cell.TextLabel.Text  = "Library Setting";
                            cell.ImageView.Image = UIImage.FromBundle("Assets/Icons/server.png");
                        }
                        else
                        {
                            if (indexPath.Row == 0)
                            {
                                cell.TextLabel.Text  = "About eBriefing";
                                cell.ImageView.Image = UIImage.FromBundle("Assets/Icons/about.png");
                            }
                            else if (indexPath.Row == 1)
                            {
                                cell.TextLabel.Text  = "Tutorial";
                                cell.ImageView.Image = UIImage.FromBundle("Assets/Icons/tutorial.png");
                            }
//                            else if (indexPath.Row == 2)
//                            {
//                                cell.TextLabel.Text = "Privacy Policy";
//                                cell.ImageView.Image = UIImage.FromBundle("Assets/Icons/privacy.png");
//                            }
                            else if (indexPath.Row == 2)
                            {
                                cell.TextLabel.Text  = "Give Feedback";
                                cell.ImageView.Image = UIImage.FromBundle("Assets/Icons/feedback.png");
                            }
                            else
                            {
                                cell.TextLabel.Text  = "Rate This App";
                                cell.ImageView.Image = UIImage.FromBundle("Assets/Icons/rate.png");
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.WriteLineDebugging("PopoverSettingDataSource - GetCell: {0}", ex.ToString());
                }

                return(cell);
            }