コード例 #1
0
        public ToLocalTimeTransform(
            IContext context       = null,
            IClock clock           = null,
            ILocalClock localClock = null
            ) : base(context, "datetime")
        {
            if (IsMissingContext())
            {
                return;
            }

            if (IsNotReceiving("date"))
            {
                return;
            }

            _input = SingleInput();

            _clock = clock;

            var localTimeZone = localClock.GetLocalTimeZoneAsync().Result;

            _transform = (dt) => {
                if (dt.Kind != DateTimeKind.Utc)
                {
                    dt = DateTime.SpecifyKind(dt, DateTimeKind.Utc);
                }
                return(_clock.ConvertToTimeZone(dt, localTimeZone).DateTime);
            };
        }
        public OrchardTimeZoneTransform(
            IContext context = null
            ) : base(context, "datetime")
        {
            if (IsMissingContext())
            {
                return;
            }

            if (IsNotReceiving("date"))
            {
                return;
            }

            _input = SingleInput();

            if (IsMissing(Context.Operation.FromTimeZone))
            {
                return;
            }

            if (IsMissing(Context.Operation.ToTimeZone))
            {
                return;
            }

            var fromTimeZone = DateTimeZoneProviders.Tzdb.GetZoneOrNull(Context.Operation.FromTimeZone);

            if (fromTimeZone == null)
            {
                Run = false;
                Context.Error($"The from time zone id {Context.Operation.FromTimeZone} is invalid. See IANA time zones.");
            }

            var toTimeZone = DateTimeZoneProviders.Tzdb.GetZoneOrNull(Context.Operation.ToTimeZone);

            if (toTimeZone == null)
            {
                Run = false;
                Context.Error($"The to time zone id {Context.Operation.ToTimeZone} is invalid. See IANA time zones.");
            }

            _transform = (dt) => {
                dt = DateTime.SpecifyKind(dt, DateTimeKind.Unspecified);
                return(ConvertDateTimeToDifferentTimeZone(dt, fromTimeZone, toTimeZone));
            };
        }
コード例 #3
0
 public string SqlDataType(Transformalize.Configuration.Field field)
 {
     return(_original.SqlDataType(field));
 }
コード例 #4
0
        public static string ToParsley(this Field f)
        {
            if (f.V == string.Empty)
            {
                return(string.Empty);
            }

            var attributes = new Dictionary <string, string>();

            var expressions = new Cfg.Net.Shorthand.Expressions(f.V);

            foreach (var expression in expressions)
            {
                switch (expression.Method)
                {
                case "required":
                    attributes["data-parsley-required"] = "true";
                    switch (f.InputType)
                    {
                    case "file":
                    case "scan":
                        attributes["data-parsley-required-message"] = "a " + f.InputType + " is required";
                        break;

                    default:
                        break;
                    }
                    break;

                case "length":
                    attributes["data-parsley-length"] = string.Format("[{0}, {1}]", expression.SingleParameter, expression.SingleParameter);
                    break;

                case "numeric":
                    attributes["data-parsley-type"] = "number";
                    break;

                case "matches":
                    attributes["data-parsley-pattern"] = expression.SingleParameter;
                    break;

                case "min":
                    attributes["data-parsley-min"] = expression.SingleParameter;
                    break;

                case "max":
                    attributes["data-parsley-max"] = expression.SingleParameter;
                    break;

                case "is":
                    switch (expression.SingleParameter)
                    {
                    case "int":
                    case "int32":
                        attributes["data-parsley-type"] = "integer";
                        break;

                    case "date":
                    case "datetime":
                        attributes["data-parsley-date"] = "true";
                        break;
                    }
                    break;

                case "alphanum":
                    attributes["data-parsley-type"] = "alphanum";
                    break;

                case "digits":
                    attributes["data-parsley-type"] = "digits";
                    break;

                case "email":
                    attributes["data-parsley-type"] = "email";
                    break;

                case "url":
                    attributes["data-parsley-type"] = "url";
                    break;
                }
            }


            return(string.Join(" ", attributes.Select(i => string.Format("{0}=\"{1}\"", i.Key, i.Value))));
        }
コード例 #5
0
        public static string ToParsley(this Field f)
        {
            if (f.V == string.Empty)
            {
                return(string.Empty);
            }

            var attributes = new Dictionary <string, string>();

            var expressions = new Cfg.Net.Shorthand.Expressions(f.V);

            foreach (var expression in expressions)
            {
                switch (expression.Method)
                {
                case "required":
                    if (f.InputType == "file")
                    {
                        continue;
                    }
                    attributes["data-parsley-required"] = "true";
                    break;

                case "length":
                    attributes["data-parsley-length"] = $"[{expression.SingleParameter}, {expression.SingleParameter}]";
                    break;

                case "numeric":
                    attributes["data-parsley-type"] = "number";
                    break;

                case "min":
                    attributes["data-parsley-min"] = expression.SingleParameter;
                    break;

                case "max":
                    attributes["data-parsley-max"] = expression.SingleParameter;
                    break;

                case "is":
                    switch (expression.SingleParameter)
                    {
                    case "int":
                    case "int32":
                        attributes["data-parsley-type"] = "integer";
                        break;

                    case "date":
                    case "datetime":
                        attributes["data-parsley-date"] = "true";
                        break;
                    }
                    break;

                case "alphanum":
                    attributes["data-parsley-type"] = "alphanum";
                    break;
                }
            }


            return(string.Join(" ", attributes.Select(i => $"{i.Key}=\"{i.Value}\"")));
        }
コード例 #6
0
        public FilePartTransform(
            IContext context         = null,
            IFileService fileService = null
            ) : base(context, "string")
        {
            if (IsMissingContext())
            {
                return;
            }

            if (IsNotReceiving("string"))
            {
                return;
            }

            if (IsMissing(Context.Operation.Property))
            {
                return;
            }

            if (fileService == null)
            {
                Run = false;
                Context.Error("FilePartTransform needs file service passed in.");
                return;
            }

            _fileService = fileService;

            _input = SingleInput();

            switch (Context.Operation.Property.ToLower())
            {
            case "filepath":
            case "path":
            case "fullpath":
                _transform = (val, svc) => {
                    if (string.IsNullOrEmpty(val))
                    {
                        return(string.Empty);
                    }
                    if (val.Length != Common.IdLength)
                    {
                        return(string.Empty);
                    }
                    var file = svc.GetFilePart(val).Result;
                    return(file.FullPath.Text);
                };
                break;

            case "originalname":
            case "name":
            case "filename":
                _transform = (val, svc) => {
                    if (string.IsNullOrEmpty(val))
                    {
                        return(string.Empty);
                    }
                    if (val.Length != Common.IdLength)
                    {
                        return(string.Empty);
                    }
                    var file = svc.GetFilePart(val).Result;
                    return(file.OriginalName.Text);
                };
                break;

            default:
                Run = false;
                Context.Error($"FilePartTransform can only retrieve FullPath, FilePath, OriginalName, or FileName. It can not retrieve {Context.Operation.Property}.");
                break;
            }
        }