Exemplo n.º 1
0
        protected override DateTime?OnEvaluateTime(EvaluationContext evalContext)
        {
            int?hour = Arguments[0].EvaluateInt(evalContext);

            if (hour == null)
            {
                return(null);
            }

            int?minute = Arguments[1].EvaluateInt(evalContext);

            if (minute == null)
            {
                return(null);
            }

            int?second = Arguments[2].EvaluateInt(evalContext);

            if (second == null)
            {
                return(null);
            }

            DateTime result = TimeType.NewTime(hour.Value, minute.Value, second.Value);

            return(result);
        }
Exemplo n.º 2
0
        protected override DateTime?OnEvaluateTime(EvaluationContext evalContext)
        {
            // Date is always represented in local timezone.
            DateTime utcNow   = DateTime.UtcNow;
            DateTime localNow = TimeZoneHelper.ConvertToLocalTimeTZ(utcNow, evalContext.TimeZoneInfo);

            return(TimeType.NewTime(localNow.TimeOfDay));
        }
Exemplo n.º 3
0
        public void TestXml_Time()
        {
            TypedValue tv = new TypedValue {
                Type = DatabaseType.TimeType, Value = TimeType.NewTime(15, 30, 0)
            };

            // Changes to TypedValue require dev-manager approval
            const string xml = @"<TypedValue type=""Time"">15:30:00</TypedValue>";

            CheckRoundTrip <DateTime>(tv, xml);
        }
Exemplo n.º 4
0
        public static bool TryParseTime(string value, out DateTime result)
        {
            DateTime parsed;

            if (!DateTime.TryParse(value, DateTimeCulture, DateOrTimeStyle, out parsed))
            {
                result = parsed; // or whatever
                return(false);
            }

            result = TimeType.NewTime(parsed.TimeOfDay);
            return(true);
        }
Exemplo n.º 5
0
        protected override DateTime?OnEvaluateTime(EvaluationContext evalContext)
        {
            string   value = Argument.EvaluateString(evalContext);
            DateTime result;

            if (!DateTime.TryParse(value, evalContext.Culture.DateTimeFormat, DateTimeStyles.None, out result))
            {
                return(null);
            }

            DateTime timeValue = TimeType.NewTime(result.TimeOfDay);

            return(timeValue);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Reads a field, as a time.
        /// </summary>
        /// <param name="key">The column</param>
        /// <returns>The value</returns>
        /// <exception cref="InvalidCastException"></exception>
        public DateTime?GetTime(string key)
        {
            string value = GetCellText(key);

            if (string.IsNullOrEmpty(value))
            {
                return(null);
            }

            DateTime dateTime = DateTime.FromOADate(Convert.ToDouble(value));
            DateTime time     = TimeType.NewTime(dateTime.TimeOfDay);

            return(time);
        }
Exemplo n.º 7
0
        public void TestXmlLegacy_Time()
        {
            TypedValue tv = new TypedValue {
                Type = DatabaseType.TimeType, Value = TimeType.NewTime(15, 30, 0)
            };

            // Changes to TypedValue require dev-manager approval
            const string xml =
                @"<TypedValue>
  <Type xsi:type=""TimeType"">
  </Type>
  <Value>01/01/1753 15:30:00</Value>
</TypedValue>";

            CheckLegacyLoad <DateTime>(tv, xml);
        }
Exemplo n.º 8
0
        protected override DateTime?OnEvaluateTime(EvaluationContext evalContext)
        {
            // Timezone offset only for datetime
            DateTime?utcDateTime = Argument.EvaluateDateTime(evalContext);

            if (utcDateTime == null)
            {
                return(null);
            }

            // Assume hh:mm:ss are already zero
            var localDateTime = TimeZoneHelper.ConvertToLocalTimeTZ(utcDateTime.Value, evalContext.TimeZoneInfo);
            var time          = TimeType.NewTime(localDateTime.TimeOfDay);

            return(time);
        }
Exemplo n.º 9
0
        public T GetParameter <T>(EvaluationContext evalContext)
        {
            object oResult = evalContext.ResolveParameter(ParameterName);

            try
            {
                if (oResult is TimeSpan)
                {
                    oResult = TimeType.NewTime((TimeSpan)oResult);
                }

                var result = (T)oResult;

                return(result);
            }
            catch (InvalidCastException ex)
            {
                var message = string.Format("Calculation requested value for parameter '{0}' and expected it to be of type '{1}' but it was provided as type '{2}'.", ParameterName, typeof(T).Name, oResult.GetType().Name);
                throw new Exception(message, ex);
            }
        }
Exemplo n.º 10
0
        protected override DateTime?OnEvaluateTime(EvaluationContext evalContext)
        {
            int?number = Left.EvaluateInt(evalContext);

            if (number == null)
            {
                return(null);
            }

            DateTime?initial = Right.EvaluateTime(evalContext);

            if (initial == null)
            {
                return(null);
            }

            DateTime rawResult = AdjustDate(DateTimePart, number.Value, initial.Value);

            // Ensure result is cropped to the 1753-01-01 date.
            DateTime croppedResult = TimeType.NewTime(rawResult.TimeOfDay);

            return(croppedResult);
        }
Exemplo n.º 11
0
 public void Check_Time()
 {
     CheckType(DatabaseType.TimeType, TimeType.NewTime(20, 45, 50));
 }
Exemplo n.º 12
0
        private static TestValue ReadValue(string dataRaw)
        {
            string[] dataParts = dataRaw.Split(new[] { ':' }, 2);
            dataParts[0] = dataParts[0].Trim();

            var    result   = new TestValue();
            string typeName = dataParts[0];
            bool   isList   = typeName.EndsWith(" list");

            if (isList)
            {
                typeName = typeName.Substring(0, typeName.Length - " list".Length);
            }
            bool disallowList = typeName.EndsWith(" disallowlist");

            if (disallowList)
            {
                typeName = typeName.Substring(0, typeName.Length - " disallowlist".Length);
            }
            bool untrimmed = typeName.EndsWith(" untrimmed");

            if (untrimmed)
            {
                typeName = typeName.Substring(0, typeName.Length - " untrimmed".Length);
            }
            else
            {
                if (dataParts.Length > 1)
                {
                    dataParts[dataParts.Length - 1] = dataParts[dataParts.Length - 1].TrimEnd();
                }
            }

            if (typeName == "int")
            {
                typeName = "Int32";
            }

            string[] typeParts    = typeName.Split(new [] { '(', ')' });
            string   typeNameBase = typeParts[0];

            DataType dataType;

            if (Enum.TryParse(typeNameBase, true, out dataType))
            {
                // scalar
                result.ExprType              = new ExprType(dataType);
                result.ExprType.IsList       = isList;
                result.ExprType.DisallowList = disallowList;

                if (typeParts.Length > 1)
                {
                    result.ExprType.DecimalPlaces = int.Parse(typeParts[1]);
                }
                if (dataParts.Length > 1)
                {
                    var dbType = DataTypeHelper.ToDatabaseType(result.ExprType.Type);
                    if (isList)
                    {
                        var      resultList = new List <object>();
                        string[] values     = dataParts[1].Split(',');
                        foreach (string sValue in values)
                        {
                            object value = null;
                            if (sValue != "null")
                            {
                                if (typeNameBase == "date" || typeNameBase == "datetime")
                                {
                                    result.Value = DateTime.Parse(sValue, (new CultureInfo("en-AU")).DateTimeFormat);
                                    if (typeNameBase == "datetime")
                                    {
                                        // treat date-time test data as local time
                                        result.Value = TimeZoneHelper.ConvertToUtc((DateTime)result.Value,
                                                                                   TimeZoneHelper.SydneyTimeZoneName);
                                    }
                                }
                                else
                                {
                                    value = dbType.ConvertFromString(sValue); // this method is stuffed
                                    if (value is float)
                                    {
                                        value = (decimal)(float)result.Value;
                                    }
                                    if (value is TimeSpan)
                                    {
                                        value = TimeType.NewTime((TimeSpan)result.Value);
                                    }
                                }
                            }
                            resultList.Add(value);
                        }
                        result.Value = resultList;
                    }
                    else
                    {
                        if (dataParts[1] != "null")
                        {
                            if (typeNameBase == "date" || typeNameBase == "datetime")
                            {
                                result.Value = DateTime.Parse(dataParts[1], (new CultureInfo("en-AU")).DateTimeFormat);
                                if (typeNameBase == "datetime")
                                {
                                    // treat date-time test data as local time
                                    result.Value = TimeZoneHelper.ConvertToUtc((DateTime)result.Value,
                                                                               TimeZoneHelper.SydneyTimeZoneName);
                                }
                            }
                            else
                            {
                                result.Value = dbType.ConvertFromString(dataParts[1]); // this method is stuffed
                                if (result.Value is float)
                                {
                                    result.Value = (decimal)(float)result.Value;
                                }
                                if (result.Value is TimeSpan)
                                {
                                    result.Value = TimeType.NewTime((TimeSpan)result.Value);
                                }
                            }
                        }
                    }
                }
                else
                {
                    result.NoValue = true;
                }
            }
            else
            {
                // entity
                result.ResourceTypeName = typeName;
                long       resourceTypeId = Factory.ScriptNameResolver.GetTypeByName(result.ResourceTypeName);
                EntityType resourceType   = EDC.ReadiNow.Model.Entity.Get <EntityType>(resourceTypeId);
                if (resourceType == null)
                {
                    throw new Exception("ResourceType not found");
                }

                result.ExprType        = ExprTypeHelper.EntityOfType(new EntityRef(resourceTypeId));
                result.ExprType.IsList = isList;
                if (dataParts.Length > 1)
                {
                    result.ResourceName = dataParts[1];
                    if (isList)
                    {
                        if (dataParts[1] == "")
                        {
                            result.Value = new EntityType[] { }
                        }
                        ;
                        else
                        {
                            var    resList = new List <IEntity>();
                            string names   = dataParts[1].Trim();
                            if (names != "" && names != "empty")
                            {
                                foreach (string name in names.Split(','))
                                {
                                    var match = Factory.ScriptNameResolver.GetInstance(name.Trim(), resourceType.Id);
                                    if (match == null)
                                    {
                                        throw new Exception(string.Format("Test error: could not find {0} called {1}",
                                                                          typeName, name));
                                    }
                                    resList.Add(match);
                                }
                            }
                            result.Value = resList.ToArray();
                        }
                    }
                    else if (result.ResourceName != "null")
                    {
                        result.Resource = Factory.ScriptNameResolver.GetInstance(result.ResourceName, resourceType.Id);
                        result.Value    = result.Resource;
                    }
                }
                else
                {
                    result.NoValue = true;
                }
            }
            result.Untrimmed = untrimmed;
            return(result);
        }
Exemplo n.º 13
0
        /// <summary>Given an arg inst and a value create and activityArgument ready for storage.</summary>
        /// <param name="activity">The <see cref="WfActivity"/> being run. This cannot be null.</param>
        /// <param name="arg">The argument for the activity. This cannot be null.</param>
        /// <param name="value">The value of the argument. Its type is determined by <paramref name="arg"/>. This may be null for certain argument types.</param>
        /// <returns>The converted value.</returns>
        /// <exception cref="ArgumentNullException">Neither <paramref name="activity"/> nor <paramref name="arg"/> can be null.</exception>
        /// <exception cref="ArgumentException"><paramref name="arg"/> must be of a supported type.</exception>
        public static ActivityArgument ConvertArgInstValue(WfActivity activity, ActivityArgument arg, object value)
        {
            if (activity == null)
            {
                throw new ArgumentNullException(nameof(activity));
            }
            if (arg == null)
            {
                throw new ArgumentNullException(nameof(arg));
            }

            ActivityArgument result;

            string name = $"{activity.Name ?? "[Unnamed]"}.{arg.Name ?? "[Unnamed]"}";

            if (arg.Is <ResourceListArgument>())
            {
                var list    = (IEnumerable <IEntity>)value;
                var created = new ResourceListArgument {
                    Name = name
                };
                if (list != null)
                {
                    var cleanList = list.Where(e => e != null).Select(e => e.As <Resource>());
                    created.ResourceListParameterValues.AddRange(cleanList);
                }
                result = created.As <ActivityArgument>();
            }
            else if (arg.Is <ResourceArgument>())
            {
                var res     = (IEntity)value;
                var created = new ResourceArgument {
                    Name = name, ResourceParameterValue = res?.As <Resource>()
                };
                result = created.As <ActivityArgument>();
            }
            else if (arg.Is <StringArgument>())
            {
                var created = new StringArgument {
                    Name = name, StringParameterValue = (string)value
                };
                result = created.As <ActivityArgument>();
            }
            else if (arg.Is <BoolArgument>())
            {
                var created = new BoolArgument {
                    Name = name, BoolParameterValue = (bool?)value ?? false
                };
                result = created.As <ActivityArgument>();
            }
            else if (arg.Is <IntegerArgument>())
            {
                var created = new IntegerArgument {
                    Name = name, IntParameterValue = (int?)value ?? 0
                };
                result = created.As <ActivityArgument>();
            }
            else if (arg.Is <DecimalArgument>())
            {
                var created = new DecimalArgument {
                    Name = name, DecimalParameterValue = (decimal?)value ?? 0
                };
                result = created.As <ActivityArgument>();
            }
            else if (arg.Is <CurrencyArgument>())
            {
                var created = new CurrencyArgument {
                    Name = name, DecimalParameterValue = (decimal?)value ?? 0
                };
                result = created.As <ActivityArgument>();
            }
            else if (arg.Is <DateTimeArgument>())
            {
                var created = new DateTimeArgument {
                    Name = name, DateTimeParameterValue = (DateTime?)value
                };
                result = created.As <ActivityArgument>();
            }
            else if (arg.Is <DateArgument>())
            {
                var created = new DateArgument {
                    Name = name, DateParameterValue = (DateTime?)value
                };
                result = created.As <ActivityArgument>();
            }
            else if (arg.Is <TimeArgument>())
            {
                // ensure that timeparametervalue only ever holds a datetime
                var dt = value is TimeSpan?TimeType.NewTime((TimeSpan)value) : (DateTime?)value;

                var created = new TimeArgument {
                    Name = name, TimeParameterValue = dt
                };
                result = created.As <ActivityArgument>();
            }
            else if (arg.Is <GuidArgument>())
            {
                var created = new GuidArgument {
                    Name = name, GuidParameterValue = (Guid?)value ?? Guid.Empty
                };
                result = created.As <ActivityArgument>();
            }
            else
            {
                throw new ArgumentException($"Unsupported ActivityArgument '{arg.IsOfType.First().Name}' in '{name}'", "arg");
            }

            return(result);
        }