protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            if (this.MeasurementInitialised)
            {
                return;
            }

            // Parse out the URI and send to the ViewModel
            string s = String.Empty;

            NavigationContext.QueryString.TryGetValue("ProfileId", out s);
            int profileId = int.Parse(s);

            NavigationContext.QueryString.TryGetValue("MeasurementId", out s);
            MeasurementId mId = (MeasurementId)Enum.Parse(typeof(MeasurementId), s, true);

            App.VM.LoadEditMeasurementData(profileId, mId);

            // Load values into the page from ViewModel
            this.LoadMeasurementIntoPage();

            // Take a snapshot to determine if changes have been made later
            this.TakeSnapshotOfForm();

            if (App.VM.EditMeasurementsPageAction == EditMeasurementPageActions.New)
            {
                (this.ApplicationBar.MenuItems[0] as ApplicationBarMenuItem).IsEnabled = false;
            }

            this.MeasurementInitialised = true;
        }
 // Call OnNavigatingTo to make sure that you have all the necessary state
 public void LoadEditMeasurementData(int profileId, MeasurementId mId)
 {
     // Load up the profile
     if (this.SelectedProfile == null ||
         this.SelectedProfile.Id != profileId)
     {
         this.SelectedProfile = this.Profiles.Where(p => p.Id == profileId).First();
     }
     // Determine if it is a new measurement or an edit
     this.EditMeasurementsPageAction = (this.SelectedProfile.Measurements.Select(m => m.MeasurementId).Contains(mId)) ?
                                       EditMeasurementPageActions.Edit : EditMeasurementPageActions.New;
     // Load up the selected measurement if necessary
     if (this.SelectedMeasurement == null ||
         this.SelectedMeasurement.Profile == null ||
         this.SelectedMeasurement.Profile.Id != profileId ||  // Execution should not get here if the attached profile is null
         this.SelectedMeasurement.MeasurementId != mId)
     {
         if (this.EditMeasurementsPageAction == EditMeasurementPageActions.New)
         {
             MeasurementTemplate st = this.MeasurementTemplates.Where(t => t.Id == mId).First();
             this.SelectedMeasurement = new Measurement()
             {
                 Name            = st.Name,
                 MeasurementType = st.MeasurementType,
                 MeasurementId   = st.Id,
             };
         }
         else
         {
             this.SelectedMeasurement = this.SelectedProfile.Measurements.Where(m => m.MeasurementId == mId).First();
         }
     }
 }
        public Measurement GetEmptyMeasurementFromTemplate(MeasurementId mId)
        {
            MeasurementTemplate mt = Model.Static.MeasurementTemplates.Where(m => m.Id == mId).First();

            return(new Measurement()
            {
                MeasurementId = mId,
                Name = mt.Name,
                Value = null,
                MeasurementType = mt.MeasurementType,
            });
        }
Exemplo n.º 4
0
        public override int GetHashCode()
        {
            var hashCode = -510074534;

            hashCode = hashCode * -1521134295 + MeasurementId.GetHashCode();
            hashCode = hashCode * -1521134295 + StationId.GetHashCode();
            hashCode = hashCode * -1521134295 + MeasurementTypeId.GetHashCode();
            hashCode = hashCode * -1521134295 + UnitId.GetHashCode();
            hashCode = hashCode * -1521134295 + Value.GetHashCode();
            hashCode = hashCode * -1521134295 + TimesStamp.GetHashCode();
            return(hashCode);
        }
Exemplo n.º 5
0
        public double GetMeasurementOrNull(MeasurementId id)
        {
            double d;

            if (this.Measurements.TryGetValue(id, out d))
            {
                return(d);
            }
            else
            {
                return(-1);
            }
        }
Exemplo n.º 6
0
 public EventInfo(EventProvider eventProvider,
                  EventDescriptor eventDescriptor,
                  ComponentId componentId,
                  CategoryId categoryId,
                  MeasurementId measurementId,
                  ulong size)
 {
     EventProvider   = eventProvider;
     EventDescriptor = eventDescriptor;
     ComponentId     = componentId;
     CategoryId      = categoryId;
     MeasurementId   = measurementId;
     Size            = size;
 }
Exemplo n.º 7
0
 private void Start(ComponentId component, CategoryId category, MeasurementId measurementId, ulong size)
 {
     this.component     = component;
     this.category      = category;
     this.measurementId = measurementId;
     if (!memReportingSwitch.TraceInfo)  // the default
     {
         this.timer.Start();
         etwProvider.WriteEvent(ref beginEvent, (uint)component, (uint)category, (uint)measurementId, (ulong)0, size, (double)0);
     }
     else
     {
         EventInfo eventInfo = new EventInfo(etwProvider, beginEvent, component, category, measurementId, size);
         Trace.WriteLine(eventInfo);
     }
 }
Exemplo n.º 8
0
 public void Create(MeasurementId measurementId, string type, string unit)
 {
     if (State.Created)
     {
         throw new InvalidOperationException($"{nameof(Measurement)}-{measurementId} already created");
     }
     if (string.IsNullOrEmpty(type))
     {
         throw new ArgumentNullException("Measurement type cannot be null");
     }
     if (string.IsNullOrEmpty(unit))
     {
         throw new ArgumentNullException("Measurement unit cannot be null");
     }
     Apply(new MeasurementCreated(measurementId, type, unit, DateTime.Now));
 }
Exemplo n.º 9
0
        public static void UseTwoMeasurements(IEventStore eventStore)
        {
            if (MeasurementViewModels.Any())
            {
                return;
            }
            var measurementId = new MeasurementId(Guid.NewGuid());
            var type          = "Stomach";
            var unit          = "cm";
            var createEvent_1 = new MeasurementCreated(measurementId, type, unit, DateTime.Now.AddDays(-3));
            var viewModel_1   = new MeasurementViewModel
            {
                Id     = measurementId.Guid,
                Type   = type,
                Unit   = unit,
                Values = new Dictionary <DateTime, double>
                {
                    { DateTime.Now.AddDays(-3), 104.5 },
                    { DateTime.Now.AddDays(-1), 104 },
                }
            };
            var measurementId_2 = new MeasurementId(Guid.NewGuid());
            var type_2          = "High jump";
            var unit_2          = "meter";
            var createEvent_2   = new MeasurementCreated(measurementId_2, type_2, unit, DateTime.Now.AddDays(-4));
            var viewModel_2     = new MeasurementViewModel
            {
                Id     = measurementId_2.Guid,
                Type   = type_2,
                Unit   = unit_2,
                Values = new Dictionary <DateTime, double>
                {
                    { DateTime.Now.AddDays(-4), 0.34 },
                    { DateTime.Now.AddHours(-2), 0.357 }
                }
            };

            eventStore.Add(measurementId, new List <IEvent> {
                createEvent_1
            });
            eventStore.Add(measurementId_2, new List <IEvent> {
                createEvent_2
            });
            MeasurementViewModels.Add(viewModel_1);
            MeasurementViewModels.Add(viewModel_2);
        }
Exemplo n.º 10
0
 internal PerformanceBlock(ComponentId component, CategoryId category, MeasurementId measurementId, ulong size)
 {
     Start(component, category, measurementId, size);
 }
Exemplo n.º 11
0
 public MeasurementUnitChanged(MeasurementId id, string unit, DateTime eventDateTime) : base(eventDateTime)
 {
     Id   = id;
     Unit = unit;
 }
Exemplo n.º 12
0
        async Task When(CreateMeasurement cmd)
        {
            var measurementId = new MeasurementId(cmd.Id);

            await Update(measurementId, m => m.Create(measurementId, cmd.Type, cmd.Unit));
        }
 public string GetHelpText(MeasurementId measurementId, GenderId gender)
 {
     return(App.VM.HelpData.HelpText[measurementId]);
 }
        public BitmapImage GetHelpImg(MeasurementId measurementId, GenderId gender)
        {
            string fn = (gender == GenderId.Male) ? App.VM.HelpData.HelpImgMale[measurementId] : App.VM.HelpData.HelpImgFemale[measurementId];

            return(new BitmapImage(new Uri(AppConstants.HELP_IMAGE_DIRECTORY + fn, UriKind.Relative)));
        }
Exemplo n.º 15
0
        public static void ReadFileIntoDb(ConversionsDataContext db, ConversionId conversionId)
        {
            Uri uri = new Uri(AppConstants.CSV_DATA_DIRECTORY + conversionId.ToString() + ".txt", UriKind.Relative);
            var res = System.Windows.Application.GetResourceStream(uri);

            System.IO.StreamReader fh = new System.IO.StreamReader(res.Stream);

            int           lineNum = 0;
            List <string> headers = new List <string>();

            Pocketailor.Model.ConversionData cd = null;

            while (!fh.EndOfStream)
            {
                lineNum++;
                string line = fh.ReadLine();
                // Read headers
                if (lineNum == 1)
                {
                    headers = line.Split(AppConstants.CSV_DELIMITERS).ToList <string>();
                    continue;
                }
                // Skip commented lines
                if (line.StartsWith("#"))
                {
                    continue;
                }
                // Skip empty lines
                if (line.Trim() == String.Empty)
                {
                    continue;
                }
                var els = line.Split(AppConstants.CSV_DELIMITERS).ToList <string>();
                // We make the assumption that data for a particular brand, gender, region, conversion are contiguous,
                // so when any one of these change, we change the object
                CsvLine csvLine = new CsvLine();
                csvLine.Conversion = conversionId;
                for (int i = 0; i < els.Count; i++)
                {
                    els[i] = els[i].Trim();
                    switch (headers[i].ToLower())
                    {
                    //case "conversion":
                    //    csvLine.Conversion = (ConversionId)Enum.Parse(typeof(ConversionId), els[i], true);
                    //    continue;
                    case "brand":
                        csvLine.Brand = (BrandId)Enum.Parse(typeof(BrandId), els[i], true);
                        continue;

                    case "region":
                        csvLine.Region = els[i];
                        continue;

                    case "gender":
                        csvLine.Gender = (GenderId)Enum.Parse(typeof(GenderId), els[i], true);
                        continue;

                    case "sizeid":
                        csvLine.SizeId = Int32.Parse(els[i]);
                        continue;

                    case "size":
                        csvLine.Size = els[i];
                        continue;

                    // Assume all remaining properties are numbers
                    default:
                        double d;
                        if (els[i] == String.Empty)
                        {
                            d = -1;
                        }
                        else
                        {
                            d = Double.Parse(els[i]);
                        }
                        MeasurementId mId = (MeasurementId)Enum.Parse(typeof(MeasurementId), headers[i], true);
                        csvLine.Measurements.Add(mId, d);
                        break;
                    }
                }
                // Take into account the first line
                if (cd == null)
                {
                    cd            = new Pocketailor.Model.ConversionData();
                    cd.Region     = csvLine.Region;
                    cd.Brand      = csvLine.Brand;
                    cd.Conversion = csvLine.Conversion;
                    cd.Gender     = csvLine.Gender;
                }
                // See if need to write a new object to the database i.e. the dataset has changed
                if (csvLine.Region != cd.Region ||
                    csvLine.Brand != cd.Brand ||
                    csvLine.Conversion != cd.Conversion ||
                    csvLine.Gender != cd.Gender)
                {
                    // Write to DB
                    cd.JsonifyData();
                    db.ConversionData.InsertOnSubmit(cd);
                    db.SubmitChanges();
                    // Create next database object
                    cd            = new Pocketailor.Model.ConversionData();
                    cd.Region     = csvLine.Region;
                    cd.Brand      = csvLine.Brand;
                    cd.Conversion = csvLine.Conversion;
                    cd.Gender     = csvLine.Gender;
                }
                // Add the measurements for this line ...
                foreach (MeasurementId mId in csvLine.Measurements.Keys)
                {
                    if (!cd.Measurements.Keys.Contains(mId))
                    {
                        cd.Measurements.Add(mId, new List <double>());
                    }
                    cd.Measurements[mId].Add(csvLine.Measurements[mId]);
                }
                cd.Sizes.Add(csvLine.Size);
                cd.SizeIds.Add(csvLine.SizeId);

                // Write to db is obj count too high
                //if ((objNum % AppConstants.DB_OBJECT_BUFFER_BEFORE_WRITE) == 0)
                //{
                //    db.SubmitChanges();
                //}
            }
            // Write any remaining object to the DB
            if (cd != null)
            {
                cd.JsonifyData();
                db.ConversionData.InsertOnSubmit(cd);
                db.SubmitChanges();
            }
        }
Exemplo n.º 16
0
 public MeasurementTypeChanged(MeasurementId id, string type, DateTime eventDateTime) : base(eventDateTime)
 {
     Id   = id;
     Type = type;
 }
Exemplo n.º 17
0
 public MeasurementCreated(MeasurementId id, string type, string unit, DateTime eventDateTime) : base(eventDateTime)
 {
     Id   = id;
     Type = type;
     Unit = unit;
 }
Exemplo n.º 18
0
 public static void Mark(ComponentId component, CategoryId category, MeasurementId measurementId, ulong size = 0, double rate = 0)
 {
     etwProvider.WriteEvent(ref markEvent, (uint)component, (uint)category, (uint)measurementId, (ulong)0, size, rate);
 }
Exemplo n.º 19
0
        /// <summary>
        /// Create a new PerformanceBlock object
        /// </summary>
        /// <param name="component">The component containing the event</param>
        /// <param name="category">The category of what is being measured</param>
        /// <param name="measurementId">The specific measurement being taken</param>
        /// <param name="size">An optional size indicating the size of the work being performed</param>
        /// <returns></returns>
        public static PerformanceBlock Create(ComponentId component, CategoryId category, MeasurementId measurementId, ulong size = 0)
        {
            PerformanceBlock free = System.Threading.Interlocked.Exchange <PerformanceBlock>(ref cache, null);

            if (free != null)
            {
                free.Start(component, category, measurementId, size);
                return(free);
            }
            return(new PerformanceBlock(component, category, measurementId, size));
        }