Exemple #1
0
        public static void WriteAsync(string Container, string DocumentType, string DocumentID, string Contents)
        {
            //BackgroundTask.Start(0, () =>
            //{

//				FoodJournal.Model.Data.FoodJournalBackup.Log("Write",Container,DocumentType + "." + DocumentID);

            try
            {
                ThreadSync.WaitOne();     // Wait till we have a sync signal, and clear the signal

                SessionLog.StartPerformance("Write");
                WriteDocument(Container, DocumentType, DocumentID, Contents);
            }
            catch (Exception ex) { LittleWatson.ReportException(ex); }
            finally
            {
                SessionLog.EndPerformance("Write");
                ThreadSync.Set();     // Set the signal for the next thread to go if it comes to it
            }

            SyncQueue.Post(Container, DocumentType, DocumentID, Contents);

            //});
        }
Exemple #2
0
        public static void LoadItems(bool Wait, String Xml)
        {
            SessionLog.StartPerformance("LoadItems");

            try {
                if (Loading)
                {
                    if (Wait)
                    {
                        while (Loading)
                        {
                            Thread.Sleep(100);
                        }
                    }
                    else
                    {
                        return;
                    }
                }

                //FoodJournalBackup.Log("Load Items",null,null);

                Loading = true;

                if (Xml == null)
                {
                    Xml = LocalDB.Read("Items", "Items", "All");
                }

                if (Xml != null)
                {
                    Serializer s = Serializer.FromXML(Xml);

                    foreach (var i in s.Select("Item"))
                    {
                        FoodItem item = new FoodItem(i.Key, false);
                        item.LastAmountDB = i.Read("LastAmount");

                        item.NutritionDB    = i.Read("Nutrition");
                        item.ServingSizesDB = i.Read("ServingSizes");
                        item.SourceID       = i.Read("SourceID");

                        Cache.MergeItem(item);
                    }
                }

                Cache.AllItemsLoaded = true;
            } catch (Exception ex) {
                LittleWatson.ReportException(ex);
            } finally {
                Loading = false;

                SessionLog.EndPerformance("LoadItems");
            }
        }
Exemple #3
0
        public static void StartSave()
        {
            SessionLog.StartPerformance("Save");

            lock (SaveQueue) {
                if (Saving)
                {
                    return;
                }
                Saving = true;
            }

            // save after 0 seconds
            BackgroundTask.Start(0, () => {
                try {
                    List <DateTime> queue = new List <DateTime> ();
                    lock (SaveQueue) {
                        queue.AddRange(SaveQueue);
                        SaveQueue.Clear();
                    }

                    foreach (var dt in queue)
                    {
                        SaveDay(dt);
                    }

                    if (queue.Count > 0)
                    {
                        SaveRecent();
                    }

                    if (!Cache.AllItemsLoaded)
                    {
                        LoadItems(true, null);
                    }

                    SaveItems();
                } finally {
                    lock (SaveQueue) {
                        Saving = false;
                    }

                    SessionLog.EndPerformance("Save");

                    if (SaveQueue.Count > 0)
                    {
                        StartSave();
                    }
                }
            }
                                 );
        }
Exemple #4
0
        // Threadsafe reading of entire document contents
        public static string Read(string Container, string DocumentType, string DocumentID)
        {
            try
            {
                ThreadSync.WaitOne(); // Wait till we have a sync signal, and clear the signal

                SessionLog.StartPerformance("Read");
                return(ReadDocument(Container, DocumentType, DocumentID));
            }
            catch (Exception ex) { LittleWatson.ReportException(ex); }
            finally
            {
                SessionLog.EndPerformance("Read");
                ThreadSync.Set(); // Set the signal for the next thread to go if it comes to it
            }

            return(null);
        }
Exemple #5
0
        public static void LoadDay(DateTime date)
        {
            SessionLog.StartPerformance("LoadDay");

            try {
                string Container  = date.ToStorageStringMonth();
                string DocumentID = date.ToStorageStringDate();
                string Xml        = LocalDB.Read(Container, "Day", DocumentID);

                LoadDay(date, Xml);

                //FoodJournalBackup.Log("Load Day",date.ToStorageStringFull(),null);
                //FoodJournalBackup.VerifyDate(date);
            } catch (Exception ex) {
                LittleWatson.ReportException(ex);
            }

            SessionLog.EndPerformance("LoadDay");
        }
Exemple #6
0
        public static void Push(object Message)
        {
            try {
                SessionLog.StartPerformance("Push");

                Truncate();

                var msg = new MessageQueueRow();
                msg.MessageType       = Message.GetType().Name;
                msg.IsClientIncomming = false;
                msg.Created           = DateTime.Now;
                msg.Message           = Serialize(Message);

                MessageQueueDB.Insert(msg);

                StartPump();
            } catch (Exception ex) {
                ReportQueueException(ex);
            }
        }
Exemple #7
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SessionLog.StartPerformance("Navigate");

            if (bundle == null)
            {
                bundle = Intent.Extras;
            }

            if (bundle == null)
            {
                bundle = new Bundle();
            }

            SetContentView(Resource.Layout.activity_main);
            Navigate.navigationContext = this;
            ResourceData.ResourceDatabase2.assetManager = Assets;

            if (Navigate.selectedPeriod == Period.none)
            {
                Navigate.selectedDate   = DateTime.Now.Date;
                Navigate.selectedPeriod = DateTime.Now.Period();
            }

            drawerLayout   = this.FindViewById <Android.Support.V4.Widget.DrawerLayout>(Resource.Id.drawer_layout);
            navigationView = this.FindViewById <NavigationView>(Resource.Id.navigation);

            var toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);

            SetSupportActionBar(toolbar);
            var actionBar = this.SupportActionBar;

            actionBar.SetTitle(Resource.String.Today);
            actionBar.SetDisplayHomeAsUpEnabled(true);
            setupDrawerContent();
            SupportActionBar.SetTitle(Resource.String.Today);
            SupportFragmentManager.BeginTransaction()
            .Replace(Resource.Id.cab_stub, new TodayViewFragment(Navigate.selectedDate, AppResources.Today, Navigate.selectedPeriod))
            .Commit();
#if SCREENSHOT
            Navigate.selectedPeriod   = Period.Breakfast;
            Navigate.screenshotScreen = this;
            Fragment fragment = null;
            var      screen   = Intent.GetStringExtra("Screen");
            if (screen != null)
            {
                screen = screen.ToLower();
                if (screen == "today")
                {
                    fragment = new TodayViewFragment(Navigate.selectedDate, AppResources.Today, Navigate.selectedPeriod);
                }
                else if (screen == "journal")
                {
                    fragment = new JournalViewFragment();
                }
                else if (screen == "report")
                {
                    fragment = new ReportFragment();
                }
                else if (screen == "goal")
                {
                    fragment = new GoalViewFragment();
                }
                if (fragment != null)
                {
                    SupportFragmentManager.BeginTransaction()
                    .Replace(Resource.Id.cab_stub, fragment)
                    .Commit();
                }
            }
#endif
        }
Exemple #8
0
        private void setupDrawerContent()
        {
            navigationView.NavigationItemSelected += (object sender, NavigationView.NavigationItemSelectedEventArgs e) =>
            {
                SessionLog.StartPerformance("Navigate");
                var menuItem = e.MenuItem;
                menuItem.SetChecked(true);
                switch (menuItem.ItemId)
                {
                case Resource.Id.navigation_item_1:
                    SupportFragmentManager.BeginTransaction()
                    .Replace(Resource.Id.cab_stub, new TodayViewFragment())
                    .AddToBackStack(null)
                    .Commit();
                    SupportActionBar.SetTitle(Resource.String.Today);
                    break;

                case Resource.Id.navigation_item_2:

                    SupportFragmentManager.BeginTransaction()
                    .Replace(Resource.Id.cab_stub, new JournalViewFragment())
                    .AddToBackStack("JournalViewFragment")
                    .Commit();
                    //GrabAdIntertitials();
                    SupportActionBar.SetTitle(Resource.String.OpenJournal);
                    break;

                case Resource.Id.navigation_item_3:
                    SupportFragmentManager.BeginTransaction()
                    .Replace(Resource.Id.cab_stub, new ReportFragment())
                    .AddToBackStack("ReportViewFragment")
                    .Commit();
                    //GrabAdIntertitials();
                    SupportActionBar.SetTitle(Resource.String.Report);
                    break;

                case Resource.Id.navigation_item_4:
                    SupportFragmentManager.BeginTransaction()
                    .Replace(Resource.Id.cab_stub, new GoalViewFragment())
                    .AddToBackStack("GoalViewFragment")
                    .Commit();
                    SupportActionBar.SetTitle(Resource.String.Goals);
                    break;

                case Resource.Id.navigation_item_5:
                    Navigate.ToSettingsPage();
                    break;

                case Resource.Id.navigation_item_6:
                    Navigate.ToFeedback();
                    break;

                default:
                    break;
                }
                menuItem.SetChecked(true);
                drawerLayout.CloseDrawers();
            };

            drawerToggle = new ActionBarDrawerToggleAnonymousInnerClassHelper(this, drawerLayout, Resource.String.drawer_open, Resource.String.drawer_close);
            drawerLayout.SetDrawerListener(drawerToggle);
        }