public void VerifyFormOfTimeOfDayParameterType()
        {
            var timeOfDayParameterType = new TimeOfDayParameterType();
            var format = NumberFormat.Format(timeOfDayParameterType);

            Assert.AreEqual("hh:mm:ss", format);
        }
        public void VerifThatConvertDoubleToDateTimeObjectConvertsAsExpected()
        {
            var      timeOfDayParameterType = new TimeOfDayParameterType(Guid.NewGuid(), null, null);
            DateTime expectedDate;

            var stringValue         = "-";
            var stringValueAsObject = (object)stringValue;

            ParameterSheetUtilities.ConvertDoubleToDateTimeObject(ref stringValueAsObject, timeOfDayParameterType);
            Assert.AreEqual("-", stringValueAsObject);

            var timeDoubleValue         = 0.11111111111111111111111111111d;
            var timeDoubleValueAsObject = (object)timeDoubleValue;

            ParameterSheetUtilities.ConvertDoubleToDateTimeObject(ref timeDoubleValueAsObject, timeOfDayParameterType);
            expectedDate = new DateTime(1, 1, 1, 2, 40, 0);
            Assert.AreEqual(expectedDate, timeDoubleValueAsObject);

            var dateParameterType       = new DateParameterType(Guid.NewGuid(), null, null);
            var dateDoubleValue         = 0.11111111111111111111111111111d;
            var dateDoubleValueAsObject = (object)dateDoubleValue;

            ParameterSheetUtilities.ConvertDoubleToDateTimeObject(ref dateDoubleValueAsObject, dateParameterType);
            expectedDate = new DateTime(1899, 12, 30, 2, 40, 0);
            Assert.AreEqual(expectedDate, dateDoubleValueAsObject);
        }
Exemplo n.º 3
0
        public void SetUp()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            this.uri   = new Uri("http://www.rheagroup.com");
            this.cache = new ConcurrentDictionary <CDP4Common.Types.CacheKey, Lazy <Thing> >();

            this.ratioScale = new RatioScale(Guid.NewGuid(), this.cache, this.uri);

            var valuedefLow = new EnumerationValueDefinition(Guid.NewGuid(), this.cache, this.uri);

            valuedefLow.ShortName = "low";
            var valuedefMedium = new EnumerationValueDefinition(Guid.NewGuid(), this.cache, this.uri);

            valuedefMedium.ShortName = "medium";

            this.booleanParameterType  = new BooleanParameterType(Guid.NewGuid(), this.cache, this.uri);
            this.dateParameterType     = new DateParameterType(Guid.NewGuid(), this.cache, this.uri);
            this.dateTimeParameterType = new DateTimeParameterType(Guid.NewGuid(), this.cache, this.uri);

            this.enumerationParameterType      = new EnumerationParameterType(Guid.NewGuid(), this.cache, this.uri);
            this.enumerationParameterType.Name = "test";
            this.enumerationParameterType.ValueDefinition.Add(valuedefLow);
            this.enumerationParameterType.ValueDefinition.Add(valuedefMedium);

            this.simpleQuantityKind = new SimpleQuantityKind(Guid.NewGuid(), this.cache, this.uri);
            this.simpleQuantityKind.PossibleScale.Add(this.ratioScale);
            this.simpleQuantityKind.DefaultScale = this.ratioScale;

            this.textParameterType      = new TextParameterType(Guid.NewGuid(), this.cache, this.uri);
            this.timeOfDayParameterType = new TimeOfDayParameterType(Guid.NewGuid(), this.cache, this.uri);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Validates the <param name="value"></param> to check whether it is a valid time of day.
        /// </summary>
        /// <param name="parameterType">
        /// A <see cref="TimeOfDayParameterType"/>
        /// </param>
        /// <param name="value">
        /// the time of day value
        /// </param>
        /// <returns>
        /// a <see cref="ValidationResult"/> that carries the <see cref="ValidationResultKind"/> and an optional message.
        /// </returns>
        public static ValidationResult Validate(this TimeOfDayParameterType parameterType, string value)
        {
            ValidationResult result;

            if (value == DefaultValue)
            {
                result.ResultKind = ValidationResultKind.Valid;
                result.Message    = string.Empty;
                return(result);
            }

            //// when DateTimeStyles.NoCurrentDateDefault is specified an no date part is specified, the date is assumed to be 1-1-1. If the
            //// date of the dateTime variable is not 1-1-1 the user provided an invalid date. The loophole here is that when a user provides a
            //// value that includes 1-1-1, it will be validated as being valid.

            DateTime dateTime;
            var      isDateTime = DateTime.TryParse(value, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind | DateTimeStyles.NoCurrentDateDefault, out dateTime);

            if (isDateTime && dateTime.Year == 1 && dateTime.Month == 1 && dateTime.Day == 1)
            {
                result.ResultKind = ValidationResultKind.Valid;
                result.Message    = string.Empty;
                return(result);
            }
            else
            {
                result.ResultKind = ValidationResultKind.Invalid;
                result.Message    = string.Format("{0} is not a valid Time of Day, for valid Time Of Day formats see http://www.w3.org/TR/xmlschema-2/#time.", value);
                return(result);
            }
        }
Exemplo n.º 5
0
        public void Setup()
        {
            RxApp.MainThreadScheduler = Scheduler.CurrentThread;
            this.serviceLocator       = new Mock <IServiceLocator>();
            this.navigation           = new Mock <IThingDialogNavigationService>();
            ServiceLocator.SetLocatorProvider(() => this.serviceLocator.Object);
            this.serviceLocator.Setup(x => x.GetInstance <IThingDialogNavigationService>()).Returns(this.navigation.Object);
            this.permissionService = new Mock <IPermissionService>();
            this.permissionService.Setup(x => x.CanWrite(It.IsAny <Thing>())).Returns(true);
            this.session = new Mock <ISession>();
            var person = new Person(Guid.NewGuid(), null, null)
            {
                Container = this.siteDir
            };

            this.session.Setup(x => x.ActivePerson).Returns(person);

            this.siteDir = new SiteDirectory(Guid.NewGuid(), null, null);
            this.siteDir.Person.Add(person);
            var rdl = new SiteReferenceDataLibrary(Guid.NewGuid(), null, null)
            {
                Name = "testRDL", ShortName = "test"
            };

            this.timeOfDayParameterType = new TimeOfDayParameterType(Guid.NewGuid(), null, null)
            {
                Name = "booleanParameterType", ShortName = "cat"
            };
            var cat = new Category(Guid.NewGuid(), null, null)
            {
                Name = "category1", ShortName = "cat1"
            };

            rdl.DefinedCategory.Add(cat);
            this.siteDir.SiteReferenceDataLibrary.Add(rdl);

            var transactionContext = TransactionContextResolver.ResolveContext(this.siteDir);

            this.transaction = new ThingTransaction(transactionContext, null);

            this.session.Setup(x => x.RetrieveSiteDirectory()).Returns(this.siteDir);
            this.session.Setup(x => x.PermissionService).Returns(this.permissionService.Object);
            this.session.Setup(x => x.OpenReferenceDataLibraries).Returns(new HashSet <ReferenceDataLibrary>(this.siteDir.SiteReferenceDataLibrary));

            var dal = new Mock <IDal>();

            this.session.Setup(x => x.DalVersion).Returns(new Version(1, 1, 0));
            this.session.Setup(x => x.Dal).Returns(dal.Object);
            dal.Setup(x => x.MetaDataProvider).Returns(new MetaDataProvider());
        }
        /// <summary>
        /// Serialize the <see cref="TimeOfDayParameterType"/>
        /// </summary>
        /// <param name="timeOfDayParameterType">The <see cref="TimeOfDayParameterType"/> to serialize</param>
        /// <returns>The <see cref="JObject"/></returns>
        private JObject Serialize(TimeOfDayParameterType timeOfDayParameterType)
        {
            var jsonObject = new JObject();

            jsonObject.Add("alias", this.PropertySerializerMap["alias"](timeOfDayParameterType.Alias.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("category", this.PropertySerializerMap["category"](timeOfDayParameterType.Category.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), timeOfDayParameterType.ClassKind)));
            jsonObject.Add("definition", this.PropertySerializerMap["definition"](timeOfDayParameterType.Definition.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](timeOfDayParameterType.ExcludedDomain.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](timeOfDayParameterType.ExcludedPerson.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](timeOfDayParameterType.HyperLink.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("iid", this.PropertySerializerMap["iid"](timeOfDayParameterType.Iid));
            jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](timeOfDayParameterType.IsDeprecated));
            jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](timeOfDayParameterType.ModifiedOn));
            jsonObject.Add("name", this.PropertySerializerMap["name"](timeOfDayParameterType.Name));
            jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](timeOfDayParameterType.RevisionNumber));
            jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](timeOfDayParameterType.ShortName));
            jsonObject.Add("symbol", this.PropertySerializerMap["symbol"](timeOfDayParameterType.Symbol));
            jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](timeOfDayParameterType.ThingPreference));
            return(jsonObject);
        }
        /// <summary>
        /// Persist the DTO composition to the ORM layer.
        /// </summary>
        /// <param name="transaction">
        /// The transaction object.
        /// </param>
        /// <param name="partition">
        /// The database partition (schema) where the requested resource will be stored.
        /// </param>
        /// <param name="timeOfDayParameterType">
        /// The timeOfDayParameterType instance to persist.
        /// </param>
        /// <returns>
        /// True if the persistence was successful.
        /// </returns>
        private bool CreateContainment(NpgsqlTransaction transaction, string partition, TimeOfDayParameterType timeOfDayParameterType)
        {
            var results = new List <bool>();

            foreach (var alias in this.ResolveFromRequestCache(timeOfDayParameterType.Alias))
            {
                results.Add(this.AliasService.CreateConcept(transaction, partition, alias, timeOfDayParameterType));
            }

            foreach (var definition in this.ResolveFromRequestCache(timeOfDayParameterType.Definition))
            {
                results.Add(this.DefinitionService.CreateConcept(transaction, partition, definition, timeOfDayParameterType));
            }

            foreach (var hyperLink in this.ResolveFromRequestCache(timeOfDayParameterType.HyperLink))
            {
                results.Add(this.HyperLinkService.CreateConcept(transaction, partition, hyperLink, timeOfDayParameterType));
            }

            return(results.All(x => x));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Validates the <param name="value"></param> to check whether it is a valid time of day.
        /// </summary>
        /// <param name="parameterType">
        /// A <see cref="TimeOfDayParameterType"/>
        /// </param>
        /// <param name="value">
        /// The string value that is to be validated.
        /// </param>
        /// <returns>
        /// a <see cref="ValidationResult"/> that carries the <see cref="ValidationResultKind"/> and an optional message.
        /// </returns>
        public static ValidationResult Validate(this TimeOfDayParameterType parameterType, object value)
        {
            ValidationResult result;

            var stringValue = value as string;

            if (stringValue != null)
            {
                if (stringValue == DefaultValue)
                {
                    result.ResultKind = ValidationResultKind.Valid;
                    result.Message    = string.Empty;
                    return(result);
                }

                //// when DateTimeStyles.NoCurrentDateDefault is specified an no date part is specified, the date is assumed to be 1-1-1. If the
                //// date of the dateTime variable is not 1-1-1 the user provided an invalid date. The loophole here is that when a user provides a
                //// value that includes 1-1-1, it will be validated as being valid.

                DateTime dateTime;
                var      isDateTime = DateTime.TryParse(stringValue, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind | DateTimeStyles.NoCurrentDateDefault, out dateTime);

                if (isDateTime && dateTime.Year == 1 && dateTime.Month == 1 && dateTime.Day == 1)
                {
                    result.ResultKind = ValidationResultKind.Valid;
                    result.Message    = string.Empty;
                    return(result);
                }
            }

            try
            {
                var timeOfDayValue = Convert.ToDateTime(value);
                if (timeOfDayValue.Year == 1 && timeOfDayValue.Month == 1 && timeOfDayValue.Day == 1)
                {
                    result.ResultKind = ValidationResultKind.Valid;
                    result.Message    = string.Empty;
                    return(result);
                }
            }
            catch (Exception ex)
            {
                Logger.Trace(ex);
            }

            try
            {
                var timeOfDayValue = Convert.ToDateTime(value);
                if (timeOfDayValue.Year == 1 && timeOfDayValue.Month == 1 && timeOfDayValue.Day == 1)
                {
                    result.ResultKind = ValidationResultKind.Valid;
                    result.Message    = string.Empty;
                    return(result);
                }
            }
            catch (Exception ex)
            {
                Logger.Trace(ex);
            }

            result.ResultKind = ValidationResultKind.Invalid;
            result.Message    = $"{value} is not a valid Time of Day, for valid Time Of Day formats see http://www.w3.org/TR/xmlschema-2/#time.";
            return(result);
        }
Exemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TimeOfDayParameterTypeDialogViewModel"/> class
 /// </summary>
 /// <param name="timeOfDayParameterType">
 /// The <see cref="TimeOfDayParameterType"/> that is the subject of the current view-model. This is the object
 /// that will be either created, or edited.
 /// </param>
 /// <param name="thingTransaction">
 /// The <see cref="ThingTransaction"/> that contains the log of recorded changes.
 /// </param>
 /// <param name="session">
 /// The <see cref="ISession"/> in which the current <see cref="Thing"/> is to be added or updated
 /// </param>
 /// <param name="isRoot">
 /// Assert if this <see cref="DialogViewModelBase{T}"/> is the root of all <see cref="DialogViewModelBase{T}"/>
 /// </param>
 /// <param name="thingDialogKind">
 /// The kind of operation this <see cref="DialogViewModelBase{T}"/> performs
 /// </param>
 /// <param name="thingDialogNavigationService">
 /// The <see cref="IThingDialogNavigationService"/> that is used to navigate to a dialog of a specific <see cref="Thing"/>.
 /// </param>
 /// <param name="container">
 /// The <see cref="Thing"/> that contains the created <see cref="Thing"/> in this Dialog
 /// </param>
 /// <param name="chainOfContainers">
 /// The optional chain of containers that contains the <paramref name="container"/> argument
 /// </param>
 public TimeOfDayParameterTypeDialogViewModel(TimeOfDayParameterType timeOfDayParameterType, IThingTransaction thingTransaction, ISession session, bool isRoot, ThingDialogKind thingDialogKind, IThingDialogNavigationService thingDialogNavigationService, Thing container = null, IEnumerable <Thing> chainOfContainers = null)
     : base(timeOfDayParameterType, thingTransaction, session, isRoot, thingDialogKind, thingDialogNavigationService, container, chainOfContainers)
 {
 }