public HouseholdTraitPresenter([NotNull] ApplicationPresenter applicationPresenter, [NotNull] HouseholdTraitView view,
                                       [NotNull] HouseholdTrait householdTrait)
            : base(view, "ThisHouseholdTrait.HeaderString", householdTrait, applicationPresenter)
        {
            _hht = householdTrait;
            _selectedAddCategory     = CategoryOrDevice[0];
            _autoSelectedAddCategory = CategoryOrDevice[0];
            if (_hht.Locations.Count > 0)
            {
                SelectedAffLocation = _hht.Locations[0];
            }

            RefreshRelevantAffordancesForAdding();

            if (_relevantAffordances.Count > 0)
            {
                SelectedAffordance = _relevantAffordances[0];
            }

            SelectedHouseholdTrait = Sim.HouseholdTraits[0];
            RefreshUses();
            RefreshClassifications();
            foreach (TimeType type in Enum.GetValues(typeof(TimeType)))
            {
                TimeTypes.Add(type);
            }
        }
Пример #2
0
        // based on : http://stackoverflow.com/questions/5438363/timespan-pretty-time-format-in-c-sharp
        public static string Humanize(this TimeSpan span, 
			IDictionary<TimeTypes, string> mappings = null,
			bool pluralize = false,
			string spaceBetweenValueAndUnits = " ",
			string spaceBetweenTypes = " ",
			TimeTypes minUnit = TimeTypes.MilliSecond
		)
        {
            if (mappings == null)
                mappings = TimeMappings;

            if (span == TimeSpan.Zero)
                return string.Format ("0 {0}{1}", mappings.ContainsKey (TimeTypes.Minute) ? mappings[TimeTypes.Minute] : "", pluralize ? "s" : string.Empty);

            const string format = "{0}{1}{2}";

            var list = new List<string> ();

            if (span.Days > 0    && (int)minUnit <= (int)TimeTypes.Day)
                list.Add (string.Format(format, span.Days, spaceBetweenValueAndUnits, mappings.ContainsKey (TimeTypes.Day) ? mappings[TimeTypes.Day] : "", pluralize && span.Days > 1 ? "s" : String.Empty));

            if (span.Hours > 0   && (int)minUnit <= (int)TimeTypes.Hour)
                list.Add (string.Format(format, span.Hours, spaceBetweenValueAndUnits, mappings.ContainsKey (TimeTypes.Hour) ? mappings[TimeTypes.Hour] : "", pluralize && span.Hours > 1 ? "s" : String.Empty));

            if (span.Minutes > 0 && (int)minUnit <= (int)TimeTypes.Minute)
                list.Add (string.Format(format, span.Minutes, spaceBetweenValueAndUnits, mappings.ContainsKey (TimeTypes.Minute) ? mappings[TimeTypes.Minute] : "", pluralize && span.Minutes > 1 ? "s" : String.Empty));

            if (span.Seconds > 0 && (int)minUnit <= (int)TimeTypes.Second)
                list.Add (string.Format(format, span.Seconds, spaceBetweenValueAndUnits, mappings.ContainsKey (TimeTypes.Second) ? mappings[TimeTypes.Second] : "", pluralize && span.Seconds > 1 ? "s" : String.Empty));

            if (span.Milliseconds > 0 && (int)minUnit <= (int)TimeTypes.MilliSecond)
                list.Add (string.Format(format, span.Milliseconds, spaceBetweenValueAndUnits, mappings.ContainsKey (TimeTypes.MilliSecond) ? mappings[TimeTypes.MilliSecond] : "", pluralize && span.Milliseconds > 1 ? "s" : String.Empty));

            return string.Join (spaceBetweenTypes, list);
        }
Пример #3
0
 static String GetStringFor(TimeTypes timeType, int time)
 {
     if (time > 1)
     {
         return(time + " " + timeType.ToString() + "s");
     }
     else
     {
         return(time + " " + timeType.ToString());
     }
 }
Пример #4
0
        private ValidationResult ValidateTimeOfTheDay(string timeString)
        {
            bool isTimeTypeValid = Enum.IsDefined(typeof(TimeTypes), timeString.ToUpper());

            if (isTimeTypeValid && Enum.TryParse(typeof(TimeTypes), timeString, true, out object timeTypeEnumObj))
            {
                _chosenTimeType = (TimeTypes)timeTypeEnumObj;
                return(ValidationResult.VALID_RESULT);
            }
            else
            {
                return(new ValidationResult(false, TYPE_SLOT, String.Format("We cannot set time for {0} at this time. Please try again later.", timeString)));
            }
        }
Пример #5
0
        // based on : http://stackoverflow.com/questions/5438363/timespan-pretty-time-format-in-c-sharp
        public static string Humanize(this TimeSpan span,
                                      IDictionary <TimeTypes, string> mappings = null,
                                      bool pluralize = false,
                                      string spaceBetweenValueAndUnits = " ",
                                      string spaceBetweenTypes         = " ",
                                      TimeTypes minUnit = TimeTypes.MilliSecond
                                      )
        {
            if (mappings == null)
            {
                mappings = TimeMappings;
            }

            if (span == TimeSpan.Zero)
            {
                return(string.Format("0 {0}{1}", mappings.ContainsKey(TimeTypes.Minute) ? mappings[TimeTypes.Minute] : "", pluralize ? "s" : string.Empty));
            }

            const string format = "{0}{1}{2}";

            var list = new List <string> ();

            if (span.Days > 0 && (int)minUnit <= (int)TimeTypes.Day)
            {
                list.Add(string.Format(format, span.Days, spaceBetweenValueAndUnits, mappings.ContainsKey(TimeTypes.Day) ? mappings[TimeTypes.Day] : "", pluralize && span.Days > 1 ? "s" : String.Empty));
            }

            if (span.Hours > 0 && (int)minUnit <= (int)TimeTypes.Hour)
            {
                list.Add(string.Format(format, span.Hours, spaceBetweenValueAndUnits, mappings.ContainsKey(TimeTypes.Hour) ? mappings[TimeTypes.Hour] : "", pluralize && span.Hours > 1 ? "s" : String.Empty));
            }

            if (span.Minutes > 0 && (int)minUnit <= (int)TimeTypes.Minute)
            {
                list.Add(string.Format(format, span.Minutes, spaceBetweenValueAndUnits, mappings.ContainsKey(TimeTypes.Minute) ? mappings[TimeTypes.Minute] : "", pluralize && span.Minutes > 1 ? "s" : String.Empty));
            }

            if (span.Seconds > 0 && (int)minUnit <= (int)TimeTypes.Second)
            {
                list.Add(string.Format(format, span.Seconds, spaceBetweenValueAndUnits, mappings.ContainsKey(TimeTypes.Second) ? mappings[TimeTypes.Second] : "", pluralize && span.Seconds > 1 ? "s" : String.Empty));
            }

            if (span.Milliseconds > 0 && (int)minUnit <= (int)TimeTypes.MilliSecond)
            {
                list.Add(string.Format(format, span.Milliseconds, spaceBetweenValueAndUnits, mappings.ContainsKey(TimeTypes.MilliSecond) ? mappings[TimeTypes.MilliSecond] : "", pluralize && span.Milliseconds > 1 ? "s" : String.Empty));
            }

            return(string.Join(spaceBetweenTypes, list));
        }
        private void SetPropertyEditorsEditable(TimeTypes value)
        {
            var dv = View as DetailView;

            if (dv != null)
            {
                var fromYear  = dv.FindItem("TimeFrom.Year") as PropertyEditor;
                var fromMonth = dv.FindItem("TimeFrom.Month") as PropertyEditor;
                var toYear    = dv.FindItem("TimeTo.Year") as PropertyEditor;
                var toMonth   = dv.FindItem("TimeTo.Month") as PropertyEditor;
                if (fromYear != null && fromMonth != null && toYear != null && toMonth != null)
                {
                    switch (value)
                    {
                    case TimeTypes.FromLimit:
                        fromYear.AllowEdit.SetItemValue("AutoEnableDisableFromYear", true);
                        fromMonth.AllowEdit.SetItemValue("AutoEnableDisableFromMonth", true);
                        toYear.AllowEdit.SetItemValue("AutoEnableDisableToYear", false);
                        toMonth.AllowEdit.SetItemValue("AutoEnableDisableToMonth", false);
                        break;

                    case TimeTypes.ToLimit:
                        fromYear.AllowEdit.SetItemValue("AutoEnableDisableFromYear", false);
                        fromMonth.AllowEdit.SetItemValue("AutoEnableDisableFromMonth", false);
                        toYear.AllowEdit.SetItemValue("AutoEnableDisableToYear", true);
                        toMonth.AllowEdit.SetItemValue("AutoEnableDisableToMonth", true);
                        break;

                    case TimeTypes.Range:
                        fromYear.AllowEdit.SetItemValue("AutoEnableDisableFromYear", true);
                        fromMonth.AllowEdit.SetItemValue("AutoEnableDisableFromMonth", true);
                        toYear.AllowEdit.SetItemValue("AutoEnableDisableToYear", true);
                        toMonth.AllowEdit.SetItemValue("AutoEnableDisableToMonth", true);
                        break;

                    case TimeTypes.All:
                        fromYear.AllowEdit.SetItemValue("AutoEnableDisableFromYear", false);
                        fromMonth.AllowEdit.SetItemValue("AutoEnableDisableFromMonth", false);
                        toYear.AllowEdit.SetItemValue("AutoEnableDisableToYear", false);
                        toMonth.AllowEdit.SetItemValue("AutoEnableDisableToMonth", false);
                        break;

                    default:
                        break;
                    }
                }
            }
        }
Пример #7
0
    public static String FormatDictionary(Dictionary <TimeTypes, int> times)
    {
        //clear out all times that are 0
        times.ToList().Where(pair => pair.Value == 0).ToList().ForEach(pair => times.Remove(pair.Key));

        String toReturn = "";

        //format the string for return
        if (times.Keys.Count == 0)
        {
            toReturn = "now";
        }
        else if (times.Keys.Count == 1)
        {
            foreach (TimeTypes timeType in times.Keys)
            {
                int time = times[timeType];
                toReturn = GetStringFor(timeType, time);
            }
        }
        else
        {
            TimeTypes[] timeTypes = new TimeTypes[times.Keys.Count];
            times.Keys.CopyTo(timeTypes, 0);
            foreach (TimeTypes timeType in timeTypes)
            {
                int time = times[timeType];
                toReturn += GetStringFor(timeType, time) + "";
                // its last do nothing
                if (timeType == timeTypes[timeTypes.Length - 1])
                {
                    toReturn += "";
                }
                else if (timeType == timeTypes[timeTypes.Length - 2])
                {
                    toReturn += " and ";
                }
                else
                {
                    toReturn += ", ";
                }
            }
        }
        return(toReturn);
    }
Пример #8
0
        public static TemporalBase GetNewTemporal(TimeTypes timeType)
        {
            TemporalBase tb;
            switch (timeType)
            {
                case TimeTypes.Point:
                    tb = new TemporalPoint();
                    break;
                case TimeTypes.Interval:
                    tb = new TemporalInterval();
                    break;
                case TimeTypes.Length:
                    tb = new TemporalLength();
                    break;
                default:
                    throw new ArgumentOutOfRangeException("timeType");
            }

            return tb;
        }
Пример #9
0
        public usrSupplementsCycleDosageEditor()
        {
            InitializeComponent();

            foreach (DosageType dosageType in Enum.GetValues(typeof(DosageType)))
            {
                DosageTypes.Add(new ListItem <DosageType>(EnumLocalizer.Default.Translate(dosageType), dosageType));
            }
            foreach (DosageUnit dosageUnit in Enum.GetValues(typeof(DosageUnit)))
            {
                DosageUnits.Add(new ListItem <DosageUnit>(EnumLocalizer.Default.Translate(dosageUnit), dosageUnit));
            }
            foreach (SupplementCycleDayRepetitions repetition in Enum.GetValues(typeof(SupplementCycleDayRepetitions)))
            {
                Repetitions.Add(new ListItem <SupplementCycleDayRepetitions>(EnumLocalizer.Default.Translate(repetition), repetition));
            }
            foreach (TimeType timeType in Enum.GetValues(typeof(TimeType)))
            {
                TimeTypes.Add(new ListItem <TimeType>(EnumLocalizer.Default.Translate(timeType), timeType));
            }
        }
Пример #10
0
 public AutoTimeConverter(TimeTypes type)
 {
     Type = type;
 }
Пример #11
0
        public static void AdvancedConcepts()
        {
            ScalarTypes scalarType       = Helper.FillObject <ScalarTypes>();
            var         scalarTypeEncode = Helper.Encode(scalarType);
            var         scalarTypeDecode = Helper.Decode(scalarTypeEncode, ScalarTypes.Parser);

            Assert.IsTrue(Helper.CompareObjects(scalarType, scalarTypeDecode));

            ComplexTypes complexType = Helper.FillObject <ComplexTypes>();

            complexType.Maps.Add(1, "Suresh");
            complexType.Numbers.Add(10);
            complexType.Details = Any.Pack(Helper.FillObject <Person>());
            var complexTypeEncode = Helper.Encode(complexType);
            var complexTypeDecode = Helper.Decode(complexTypeEncode, ComplexTypes.Parser);

            Assert.IsTrue(Helper.CompareObjects(complexType, complexTypeDecode));

            if (complexTypeDecode.Details.Is(Person.Descriptor))
            {
                complexTypeDecode.Details.TryUnpack(out Person person);
            }
            var oneOfCase = complexTypeDecode.OneofCase;    //returns the name of the field that is set

            NullableTypes nullableType       = Helper.FillObject <NullableTypes>();
            var           nullableTypeEncode = Helper.Encode(nullableType);
            var           nullableTypeDecode = Helper.Decode(nullableTypeEncode, NullableTypes.Parser);

            Assert.IsTrue(Helper.CompareObjects(nullableType, nullableTypeDecode));

            TimeTypes timeType       = Helper.FillObject <TimeTypes>();
            var       timeTypeEncode = Helper.Encode(timeType);
            var       timeTypeDecode = Helper.Decode(timeTypeEncode, TimeTypes.Parser);

            Assert.IsTrue(Helper.CompareObjects(timeType, timeTypeDecode));


            //Write a collections
            List <ScalarTypes> sts = new List <ScalarTypes>();

            sts.Add(Helper.FillObject <ScalarTypes>());
            sts.Add(Helper.FillObject <ScalarTypes>());

            MemoryStream ipStream = new MemoryStream();

            foreach (var st in sts)
            {
                st.WriteDelimitedTo(ipStream);
            }

            using (var file = File.Create("data.bin"))
                file.Write(ipStream.ToArray());
            ipStream.Close();

            List <ScalarTypes> stsDecoded = new List <ScalarTypes>();

            using (var stream = File.OpenRead("data.bin"))
            {
                while (stream.Position < stream.Length)
                {
                    var sto = ScalarTypes.Parser.ParseDelimitedFrom(stream);
                    stsDecoded.Add(sto);
                }
            }
            Assert.IsTrue(Helper.CompareObjects(sts, stsDecoded));
        }
Пример #12
0
 void hide()
 {
     Config.pauseUpdate = true; TimeTypes.Refresh((c) => c.type = TimeType.None); Config.pauseUpdate = false; Config.UpdateConfig();
 }
Пример #13
0
 void show()
 {
     Config.pauseUpdate = true; TimeTypes.Refresh((c) => c.type = TimeType.Normal); Config.pauseUpdate = false; Config.UpdateConfig();
 }
Пример #14
0
 void reset()
 {
     Config.pauseUpdate = true; Config.loadConfig(); TimeTypes.Refresh(); OutTimes.Refresh(); Config.pauseUpdate = false; Config.UpdateConfig();
 }