Example #1
0
        public static ExecuteResult Until(Func <bool> method)
        {
            var timer = new System.Diagnostics.Stopwatch();

            timer.Start();
            var sleepTime = 100;
            var result    = new ExecuteResult();

            do
            {
                try
                {
                    if (method.Invoke())
                    {
                        return(result);
                    }
                }
                catch (Exception exception)
                {
                    Thread.Sleep(sleepTime);
                    sleepTime            = sleepTime + sleepTime; // increase waits between retry attempts
                    result.LastException = exception;
                    ConsoleD.WriteError(exception.ToString());
                }
            }while (timer.ElapsedMilliseconds <= DefaultTimeout);

            return(result);
        }
        public void UpdateIfEmpty(bool async = true)
        {
            Action updateAction = () =>
            {
                bool dataExists = this.DataManager.DataExists;
                ConsoleD.WriteLine("Database has seed data {0}.", dataExists);
                if (!dataExists)
                {
                    ConsoleD.WriteLine("Loading seed data");
                    var seedDataFile = this.FileManager.ResourcePath + "/Images/SeedData.xml";
                    // Note can't use Path.Combine as resource path point to your file app i.e. notes.app
                    string xml = System.IO.File.ReadAllText(seedDataFile);
                    this.Update(xml);
                }
            };

            if (async)
            {
                new Thread(updateAction.Invoke).Start();
            }
            else
            {
                updateAction.Invoke();
            }
        }
Example #3
0
        protected void OnWillRotate(NSNotification notification)
        {
            if (!this.IsViewLoaded)
            {
                return;
            }
            if (notification == null)
            {
                return;
            }

            var o1 = notification.UserInfo.ValueForKey(new NSString("UIApplicationStatusBarOrientationUserInfoKey"));
            int o2 = Convert.ToInt32(o1.ToString());
            UIInterfaceOrientation toOrientation = (UIInterfaceOrientation)o2;
            var notModal      = !(this.TabBarController.ModalViewController == null);
            var isSelectedTab = (this.TabBarController.SelectedViewController == this);

            //ConsoleD.WriteLine ("toOrientation:"+toOrientation);
            //ConsoleD.WriteLine ("isSelectedTab:"+isSelectedTab);

            var duration = UIApplication.SharedApplication.StatusBarOrientationAnimationDuration;

            if (!isSelectedTab || !notModal)
            {
                base.WillRotate(toOrientation, duration);

                UIViewController master = this.ViewControllers[0];
                var theDelegate         = this.Delegate;

                //YOU_DONT_FEEL_QUEAZY_ABOUT_THIS_BECAUSE_IT_PASSES_THE_APP_STORE
                UIBarButtonItem button = base.ValueForKey(new NSString("_barButtonItem")) as UIBarButtonItem;


                if (toOrientation == UIInterfaceOrientation.Portrait ||
                    toOrientation == UIInterfaceOrientation.PortraitUpsideDown)
                {
                    if (theDelegate != null && theDelegate.RespondsToSelector(new Selector("splitViewController:willHideViewController:withBarButtonItem:forPopoverController:")))
                    {
                        try {
                            UIPopoverController popover = base.ValueForKey(new NSString("_hiddenPopoverController")) as UIPopoverController;
                            theDelegate.WillHideViewController(this, master, button, popover);
                        } catch (Exception e) {
                            ConsoleD.WriteLine("There was a nasty error while notifyng splitviewcontrollers of a portrait orientation change: " + e.Message);
                        }
                    }
                }
                else
                {
                    if (theDelegate != null && theDelegate.RespondsToSelector(new Selector("splitViewController:willShowViewController:invalidatingBarButtonItem:")))
                    {
                        try {
                            theDelegate.WillShowViewController(this, master, button);
                        } catch (Exception e) {
                            ConsoleD.WriteLine("There was a nasty error while notifyng splitviewcontrollers of a landscape orientation change: " + e.Message);
                        }
                    }
                }
            }
        }
Example #4
0
		public override void WillShowViewController (UISplitViewController svc, UIViewController aViewController, UIBarButtonItem button)
		{
			SessionSpeakersMasterDetail dvc = svc.ViewControllers[1] as SessionSpeakersMasterDetail;
			
			if (dvc != null) {
				dvc.RemoveNavBarButton ();
				dvc.Popover = null;
			} else ConsoleD.WriteLine ("SessionSplitViewController dvc == null (show)");
		}
Example #5
0
		public override void WillHideViewController (UISplitViewController svc, UIViewController aViewController, UIBarButtonItem barButtonItem, UIPopoverController pc)
		{
			SessionSpeakersMasterDetail dvc = svc.ViewControllers[1] as SessionSpeakersMasterDetail;
			
			if (dvc != null) {
				dvc.AddNavBarButton (barButtonItem);
				dvc.Popover = pc;
			} else ConsoleD.WriteLine ("SessionSplitViewController dvc == null (hide)");
		}
Example #6
0
        public void UpdatedImage(Uri uri)
        {
            ConsoleD.WriteLine("UPDATED:" + uri.AbsoluteUri);
            var img = ImageLoader.DefaultRequestImage(uri, this);

            if (img != null)
            {
                image.Image = RemoveSharpEdges(img);
            }
        }
        public void UpdatedImage(Uri uri)
        {
            ConsoleD.WriteLine("UPDATED:" + uri.AbsoluteUri);
            var img = ImageLoader.DefaultRequestImage(uri, this);

            if (img != null)
            {
                image.Image = MWC.iOS.UI.CustomElements.TweetCell.RemoveSharpEdges(img);
            }
        }
Example #8
0
 void HandleUpdateFinished(object sender, EventArgs e)
 {
     ConsoleD.WriteLine("Updates finished, going to populate table.");
     InvokeOnMainThread(() => {
         PopulateTable();
         if (loadingOverlay != null)
         {
             loadingOverlay.Hide();
         }
     });
 }
Example #9
0
		/// <summary>
		/// On 'view will appear', if we were showing a particular day last time,
		/// we're going to revert to the entire schedule this time
		/// </summary>
		public override void ViewWillAppear (bool animated)
		{
			base.ViewWillAppear (animated);
			ConsoleD.WriteLine ("viewappear showingDay = " + showingDay);
			if (!showingDay) {
				var sl = ViewControllers[0] as SessionsScreen;
				sl.ShowAll();
				sessionsList = sl;
			}
			showingDay = false;
		}
        void Initialize(string message, RectangleF bounds)
        {
            ConsoleD.WriteLine("UILoadingView.Initialize " + bounds);
            SetUpLoadingMessageLabel(message);
            SetUpActivityIndicator();
            SetUpOverlayBackground(bounds);

            AutoresizingMask = UIViewAutoresizing.FlexibleDimensions;

            AddSubview(overlayBackground);
            AddSubview(activityIndicator);
            AddSubview(loadingMessageLabel);

            initialized = true;
        }
Example #11
0
        /// <summary>
        /// Deserializes the specified XML.
        /// </summary>
        /// <param name="xml">The XML.</param>
        /// <returns>An instance of <see cref="PatientFile"/> represented by the passed in <paramref name="xml"/>.</returns>
        public PatientFile Deserialize(string xml)
        {
            PatientFile patientFile = null;

            try
            {
                patientFile = xml.Deserialize <PatientFile>();
            }
            catch (Exception ex)
            {
                ConsoleD.WriteError("Error occured deserializing patient file data.", ex);
            }

            return(patientFile);
        }
Example #12
0
        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);
            if (Root == null || Root.Count == 0)
            {
                StartLoadingScreen("Loading...");

                NSTimer.CreateScheduledTimer(TimeSpan.FromMilliseconds(1), delegate {
                    LoadData();
                });
            }
            else
            {
                ConsoleD.WriteLine("Dialog data already populated");
            }
        }
        public static T Deserialize <T>(this string xml) where T : new()
        {
            T result = default(T);

            try
            {
                var serializer   = new XmlSerializer(typeof(T));
                var stringReader = new StringReader(xml);
                result = (T)serializer.Deserialize(stringReader);
            }
            catch (Exception ex)
            {
                ConsoleD.WriteError("Deserializing type {0}.", ex, typeof(T).FullName);
            }

            return(result);
        }
 void HandleUpdateStarted(object sender, EventArgs e)
 {
     ConsoleD.WriteLine("Updates starting, need to create overlay.");
     InvokeOnMainThread(() => {
         if (loadingOverlay == null)
         {
             loadingOverlay = new MWC.iOS.UI.Controls.LoadingOverlay(TableView.Frame);
             // because DialogViewController is a UITableViewController,
             // we need to step OVER the UITableView, otherwise the loadingOverlay
             // sits *in* the scrolling area of the table
             if (View.Superview != null)                       //TODO: see when this is null
             {
                 View.Superview.Add(loadingOverlay);
                 View.Superview.BringSubviewToFront(loadingOverlay);
             }
         }
     });
 }
Example #15
0
        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);

            if (BL.Managers.UpdateManager.IsUpdating)
            {
                if (loadingOverlay == null)
                {
                    var bounds = new CGRect(0, 0, 768, 1004);
                    if (InterfaceOrientation == UIInterfaceOrientation.LandscapeLeft ||
                        InterfaceOrientation == UIInterfaceOrientation.LandscapeRight)
                    {
                        bounds = new CGRect(0, 0, 1024, 748);
                    }

                    loadingOverlay = new MWC.iOS.UI.Controls.LoadingOverlay(bounds);
                    // because DialogViewController is a UITableViewController,
                    // we need to step OVER the UITableView, otherwise the loadingOverlay
                    // sits *in* the scrolling area of the table
                    View.Superview.Add(loadingOverlay);
                    View.Superview.BringSubviewToFront(loadingOverlay);
                }
                ConsoleD.WriteLine("Waiting for updates to finish before displaying table.");
            }
            else
            {
                loadingOverlay = null;
                if (AlwaysRefresh || Root == null || Root.Count == 0)
                {
                    ConsoleD.WriteLine("Not updating, populating table.");
                    PopulateTable();
                }
                else
                {
                    ConsoleD.WriteLine("Data already populated.");
                }
            }
        }
        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);

            if (this.PatientFileUpdateManager.UpdateInProgress)
            {
                if (this.loadingOverlay == null)
                {
                    var bounds = new RectangleF(0, 0, 768, 1004);
                    if (this.InterfaceOrientation == UIInterfaceOrientation.LandscapeLeft ||
                        this.InterfaceOrientation == UIInterfaceOrientation.LandscapeRight)
                    {
                        bounds = new RectangleF(0, 0, 1024, 748);
                    }

                    this.loadingOverlay = new LoadingOverlay(bounds);
                    // because DialogViewController is a UITableViewController,
                    // we need to step OVER the UITableView, otherwise the loadingOverlay
                    // sits *in* the scrolling area of the table
                    this.View.Superview.Add(this.loadingOverlay);
                    this.View.Superview.BringSubviewToFront(this.loadingOverlay);
                }
                ConsoleD.WriteLine("Waiting for updates to finish before displaying table.");
            }
            else
            {
                this.loadingOverlay = null;
                if (this.AlwaysRefresh || this.Root == null || this.Root.Count == 0)
                {
                    ConsoleD.WriteLine("Not updating, populating table.");
                    this.PopulateTable();
                }
                else
                {
                    ConsoleD.WriteLine("Data already populated.");
                }
            }
        }
        /// <summary>
        /// Updates the database using the specified xml, which is deserialize into a <see cref="PatientFile"/> instance, first.
        /// </summary>
        /// <param name="xml">The xml representing a <see cref="PatientFile"/> object.</param>
        public void Update(string xml)
        {
            ConsoleD.WriteLine("Updating database using xml");

            lock (globalSync)
            {
                this.UpdateInProgress = true;
                this.UpdateStarted(null, EventArgs.Empty);
                var finishedEventArgs = new UpdateFinishedEventArgs(UpdateType.SeedData, false);

                var patientFile = new PatientFileParser().Deserialize(xml);
                if (patientFile != null)
                {
                    if (this.SaveToDatabase(patientFile))
                    {
                        finishedEventArgs.Success = true;
                    }
                }

                this.UpdateFinished(null, finishedEventArgs);
                this.UpdateInProgress = false;
            }
        }
        private bool SaveToDatabase(PatientFile patientFile)
        {
            bool result = false;

            try
            {
                ConsoleD.WriteLine("Saving the patient file data to sqlite");

                if (patientFile.Patients.Count > 0)
                {
                    this.DataManager.DeletePatients();
                    this.DataManager.SavePatients(patientFile.Patients);
                }

                result = true;
            }
            catch (Exception ex)
            {
                ConsoleD.WriteError("Saving patient file data failed for the following reasons ", ex);
            }

            return(result);
        }
        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);

            if (BL.Managers.UpdateManager.IsUpdatingUserGroups)
            {
                if (loadingOverlay == null)
                {
                    loadingOverlay = new MWC.iOS.UI.Controls.LoadingOverlay(View.Frame);

                    // because DialogViewController is a UITableViewController,
                    // we need to step OVER the UITableView, otherwise the loadingOverlay
                    // sits *in* the scrolling area of the table
                    if (View.Superview != null)
                    {
                        // TODO: see when Superview is null
                        View.Superview.Add(loadingOverlay);
                        View.Superview.BringSubviewToFront(loadingOverlay);
                    }
                }
                ConsoleD.WriteLine("Waiting for updates to finish before displaying table.");
            }
            else
            {
                loadingOverlay = null;
                if (Root == null || Root.Count == 0)
                {
                    ConsoleD.WriteLine("Not updating, populating table.");
                    PopulateTable();
                }
                else
                {
                    ConsoleD.WriteLine("Exhibitors already populated");
                }
            }
        }
 /// <summary>
 /// When we receive a memory warning, clear the MT.D image cache
 /// </summary>
 /// <param name="application">
 /// The application.
 /// </param>
 public override void ReceiveMemoryWarning(UIApplication application)
 {
     ConsoleD.WriteLine("==== Received Memory Warning ====");
     ImageLoader.Purge();
 }
Example #21
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            toolbar = new UINavigationBar(new RectangleF(0, 0, View.Frame.Width, toolbarHeight));
            toolbar.SetItems(new UINavigationItem[] {
                new UINavigationItem("Map")
            }, false);
            toolbar.AutoresizingMask = UIViewAutoresizing.FlexibleWidth;
            toolbar.TintColor        = AppDelegate.ColorNavBarTint;

            Title            = Constants.MapPinSubtitle;  // "Fira de Barcelona";
            TabBarItem.Title = "Map";

            // create our location and zoom for los angeles
            CLLocationCoordinate2D coords = new CLLocationCoordinate2D(Constants.MapPinLatitude, Constants.MapPinLongitude);
            MKCoordinateSpan       span   = new MKCoordinateSpan(MilesToLatitudeDegrees(3), MilesToLongitudeDegrees(3, coords.Latitude));

            mapView = new MKMapView(new RectangleF(0, toolbarHeight, View.Frame.Width, UIScreen.MainScreen.ApplicationFrame.Height - toolbarHeight));
            mapView.ShowsUserLocation = true;
            mapView.Frame             = new RectangleF(0, 0, View.Frame.Width, View.Frame.Height);
            mapView.AutoresizingMask  = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
            // set the coords and zoom on the map
            mapView.Region = new MKCoordinateRegion(coords, span);

            segmentedControl = new UISegmentedControl();
            segmentedControl.InsertSegment("Map", 0, false);
            segmentedControl.InsertSegment("Satellite", 1, false);
            segmentedControl.InsertSegment("Hybrid", 2, false);
            segmentedControl.SelectedSegment = 0;
            segmentedControl.ControlStyle    = UISegmentedControlStyle.Bar;
            segmentedControl.TintColor       = UIColor.DarkGray;
            if (AppDelegate.IsPhone)
            {
                var topOfSegement = View.Frame.Height - 120;
                segmentedControl.Frame = new RectangleF(20, topOfSegement, 282, 30);
                //segmentedControl.Frame = new RectangleF(20, 340, 282, 30);
            }
            else
            {
                // IsPad
                var left = (View.Frame.Width / 2) - (282 / 2);
                segmentedControl.Frame            = new RectangleF(left, View.Frame.Height - 70, 282, 30);
                segmentedControl.AutoresizingMask = UIViewAutoresizing.FlexibleMargins;
            }
            segmentedControl.ValueChanged += delegate {
                if (segmentedControl.SelectedSegment == 0)
                {
                    mapView.MapType = MonoTouch.MapKit.MKMapType.Standard;
                }
                else if (segmentedControl.SelectedSegment == 1)
                {
                    mapView.MapType = MonoTouch.MapKit.MKMapType.Satellite;
                }
                else if (segmentedControl.SelectedSegment == 2)
                {
                    mapView.MapType = MonoTouch.MapKit.MKMapType.Hybrid;
                }
            };

            try {
                // add a basic annotation, got a bug report about these lines of code
                mapView.AddAnnotation(
                    new BasicMapAnnotation(coords, Constants.MapPinTitle, Constants.MapPinSubtitle)
                    );
            } catch (Exception mapex) {
                ConsoleD.WriteLine("Not sure if happens " + mapex.Message);
            }

            View.AddSubview(mapView);
            View.AddSubview(toolbar);
            View.AddSubview(segmentedControl);
        }
Example #22
0
 public SessionDetailsScreen(int sessionID)
     : base(UserInterfaceIdiomIsPhone ? "SessionDetailsScreen_iPhone" : "SessionDetailsScreen_iPad", null)
 {
     ConsoleD.WriteLine("Creating Session Details Screen, Session ID: " + sessionID.ToString());
     sessionId = sessionID;
 }
Example #23
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            BL.Managers.UpdateManager.UpdateFinished += HandleUpdateFinished;

            SessionTable.SeparatorColor = UIColor.Black;
            SessionTable.SeparatorStyle = UITableViewCellSeparatorStyle.SingleLine;

            if (AppDelegate.IsPhone)
            {
                MwcLogoImageView.Image = UIImage.FromBundle("/Images/Home");
                MwcLogoImageView.Frame = new RectangleF(0, 0, 320, 480);
            }
            else
            {
                // IsPad
                MwcLogoImageView.Image = UIImage.FromBundle("/Images/Home-Portrait~ipad");

                // style the separators to be black
                SessionTable.SeparatorColor   = UIColor.Black;
                SessionTable.SeparatorStyle   = UITableViewCellSeparatorStyle.SingleLine;
                UpNextTable.SeparatorColor    = UIColor.Black;
                UpNextTable.SeparatorStyle    = UITableViewCellSeparatorStyle.SingleLine;
                FavoritesTable.SeparatorColor = UIColor.Black;
                FavoritesTable.SeparatorStyle = UITableViewCellSeparatorStyle.SingleLine;

                // the extra 'clear' Views for background are a bit of a hack
                // and not needed on the phone!
                // http://forums.macrumors.com/showthread.php?t=901706
                var clearView1 = new UIView();
                clearView1.Frame             = new RectangleF(0, 470, 320, 200);
                clearView1.BackgroundColor   = UIColor.Clear;
                SessionTable.BackgroundColor = UIColor.Clear;
                SessionTable.BackgroundView  = clearView1;

                var clearView2 = new UIView();
                clearView2.Frame            = new RectangleF(0, 470 + 210, 320, 320);
                clearView2.BackgroundColor  = UIColor.Clear;
                UpNextTable.BackgroundColor = UIColor.Clear;
                UpNextTable.BackgroundView  = clearView2;

                var clearView3 = new UIView();
                clearView3.Frame               = new RectangleF(768 - 320, 470, 320, 420);
                clearView3.BackgroundColor     = UIColor.Clear;
                FavoritesTable.BackgroundColor = UIColor.Clear;
                FavoritesTable.BackgroundView  = clearView3;
            }

            //TODO: Craig, i want to look at encapsulating this at the BL layer,
            // i don't know if that's a feasible approach, but i think this is
            // generally a good pattern.
            //
            // if we're in the process of updating, populate the table when it's done
            // alas, if we keep it in the app layer, it gives us an opportunity to
            // show a spinner over the table with an "updating" message.
            if (BL.Managers.UpdateManager.IsUpdating)
            {
                if (AppDelegate.IsPhone)
                {
                    loadingOverlay = new MWC.iOS.UI.Controls.LoadingOverlay(SessionTable.Frame);
                }
                else                    // IsPad (rotates!)
                {
                    var overlayFrame = View.Frame;
                    overlayFrame.Y                  = 330;
                    overlayFrame.Height             = 768 - 330;
                    loadingOverlay                  = new MWC.iOS.UI.Controls.LoadingOverlay(overlayFrame);
                    loadingOverlay.AutoresizingMask = UIViewAutoresizing.FlexibleDimensions;
                }
                View.AddSubview(loadingOverlay);

                ConsoleD.WriteLine("UpdateManager.IsUpdating ~ wait for them to finish");
            }
            else
            {
                PopulateTable();
            }
        }