Exemplo n.º 1
0
        public Id <T> Compile <T>(params object[] args)
        {
            var placeholderIndex = 0;

            return(new Id <T>(this, string.Join(SeparatorCharacter.ToString(),
                                                Terms.Select(term =>
                                                             new Switch <string>(term)
                                                             .Match((LiteralText t) => t.Text)
                                                             .Match((GuidKeyword t) => Guid.NewGuid().ToString())
                                                             .Match((SGuidKeyword t) => ToSGuid(Guid.NewGuid()))
                                                             .Match((Placeholder t) =>
            {
                if (placeholderIndex >= args.Length)
                {
                    if (!string.IsNullOrEmpty(t.Property))
                    {
                        throw new InvalidOperationException(string.Format(
                                                                "You did not supply a value for the placeholder '{0}' at position {1}",
                                                                t.Property, placeholderIndex));
                    }

                    throw new InvalidOperationException(string.Format(
                                                            "You did not supply a value for the *-placeholder or {{}}-placeholder at position {0}",
                                                            placeholderIndex));
                }

                return args[placeholderIndex++].ToString();
            })
                                                             .OrThrow(new ArgumentOutOfRangeException())))));
        }
    /// <summary>
    /// Checks the value against the Minimum and Maximum categories
    /// </summary>
    /// <returns>If the entry is valid or not.</returns>
    public override bool IsValid()
    {
        bool MinMet = true;
        bool MaxMet = true;

        if (MinimumRelationships > -1)
        {
            if (ValidationHelper.GetString(frmFormControl.Value, "").Trim().Split(SeparatorCharacter.ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Length < MinimumRelationships)
            {
                MinMet = false;
            }
        }
        if (MaximumRelationships > -1)
        {
            if (ValidationHelper.GetString(frmFormControl.Value, "").Trim().Split(SeparatorCharacter.ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Length > MaximumRelationships)
            {
                MaxMet = false;
            }
        }

        if (!MinMet || !MaxMet)
        {
            ValidationError = string.Format("{0} {1} {2}",
                                            (!MinMet ? "Minimum " + MinimumRelationships + " selections allowed" : ""),
                                            (!MinMet && !MaxMet ? " and " : ""),
                                            (!MaxMet ? "Maximum " + MaximumRelationships + " selections allowed" : ""));
        }
        return(MinMet && MaxMet);
    }
Exemplo n.º 3
0
        public string Normalize(string id)
        {
            var match = pattern.Match(id);

            if (!match.Success)
            {
                throw new InvalidOperationException(string.Format(
                                                        "The string '{0}' does not match the expected input '{1}'.", id, ToString()));
            }

            return(string.Join(SeparatorCharacter.ToString(),
                               Terms.Select((term, i) =>
            {
                var value = match.Groups[i + 1].Value;
                return new Switch <string>(term)
                .Match((LiteralText t) => t.Text)
                .Match((GuidKeyword t) => value)
                .Match((SGuidKeyword t) =>
                {
                    Guid guid;
                    return Guid.TryParse(value, out guid) ? ToSGuid(guid) : value;
                })
                .Match((Placeholder t) => value)
                .OrThrow(new ArgumentOutOfRangeException());
            })));
        }
Exemplo n.º 4
0
 public override string ToString()
 {
     return(string.Join(SeparatorCharacter.ToString(),
                        Terms.Select(term =>
                                     new Switch <string>(term)
                                     .Match((LiteralText t) => t.Text)
                                     .Match((GuidKeyword t) => "guid")
                                     .Match((SGuidKeyword t) => "sguid")
                                     .Match((Placeholder t) => string.IsNullOrEmpty(t.Property) ? "*" : "{" + t.Property + "}")
                                     .OrThrow(new ArgumentOutOfRangeException()))));
 }
Exemplo n.º 5
0
 Regex ToRegex()
 {
     return(new Regex(string.Format("^{0}$", string.Join(SeparatorCharacter.ToString(),
                                                         Terms.Select(term =>
                                                                      new Switch <string>(term)
                                                                      .Match((LiteralText t) => t.Text)
                                                                      .Match((GuidKeyword t) => guidPattern)
                                                                      .Match((SGuidKeyword t) => "(?:" + guidPattern + ")|(?:" + sguidPattern + ")")
                                                                      .Match((Placeholder t) => @"[^/]+")
                                                                      .OrThrow(new ArgumentOutOfRangeException()))
                                                         .Select(x => string.Format("({0})", x))))));
 }
    private List <string> GetSelectedObjects()
    {
        string        ObjectRefIDs    = ValidationHelper.GetString(frmFormControl.Value, "");
        List <string> SelectedObjects = ObjectRefIDs.Split(SeparatorCharacter.ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList();

        if (!string.IsNullOrWhiteSpace(RelatedObjectRestrainingWhere))
        {
            List <string> AllPossibleObjects = GetPossibleObjects();
            SelectedObjects.RemoveAll(x => !AllPossibleObjects.Contains(x));
        }
        return(SelectedObjects);
    }
Exemplo n.º 7
0
        /// <summary>
        /// Gets the header attributes for the given <paramref name="headerName"/>
        /// using the information from the given <paramref name="attribute"/>.
        /// This adds the header to the list of container headers if-and-only-if the
        /// header is a container header.
        /// </summary>
        /// <param name="headerName">the header name</param>
        /// <param name="attribute">the attribute for the given header name</param>
        /// <param name="allContainerHeaders">the list of all container headers</param>
        /// <returns>the header attributes</returns>
        private static HeaderAttributes GetHeaderAttributes(Mpeg4HeaderName headerName, Mpeg4Attribute attribute, ICollection <Mpeg4HeaderName> allContainerHeaders)
        {
            // Retrieve list of header start codes
            List <uint> headerStartCodes = new List <uint>();

            if (attribute.HeaderStartCode != null)
            {
                const string SeparatorCharacter = "-";
                if (attribute.HeaderStartCode.Contains(SeparatorCharacter))
                {
                    Debug.Assert(attribute.HeaderStartCode.Length == 5);                     // Example: "40-5F"

                    string[] startCodes = attribute.HeaderStartCode.Split(SeparatorCharacter.ToCharArray());

                    uint firstStartCode = uint.Parse(startCodes[0], System.Globalization.NumberStyles.HexNumber, CultureInfo.InvariantCulture);
                    uint lastStartCode  = uint.Parse(startCodes[1], System.Globalization.NumberStyles.HexNumber, CultureInfo.InvariantCulture);

                    Debug.Assert(firstStartCode < lastStartCode);

                    for (uint startCode = firstStartCode; startCode <= lastStartCode; startCode++)
                    {
                        headerStartCodes.Add(0x100 + startCode);
                    }
                }
                else
                {
                    headerStartCodes.Add(0x100 + uint.Parse(attribute.HeaderStartCode, System.Globalization.NumberStyles.HexNumber, CultureInfo.InvariantCulture));
                }
            }

            // Retrieve suitable parents, all container headers if empty list
            ICollection <Mpeg4HeaderName> suitableParents = attribute.SuitableParents;

            if (suitableParents.Count == 0)
            {
                suitableParents = allContainerHeaders;
            }

            // Update list of all container headers
            if ((attribute.HeaderFlags & HeaderFlags.MasterHeader) == HeaderFlags.MasterHeader)
            {
                allContainerHeaders.Add(headerName);
            }
            return(new HeaderAttributes(headerStartCodes.AsReadOnly(), attribute.HeaderFlags, suitableParents));
        }
Exemplo n.º 8
0
        public SwitchedContentArgument(String name, SwitchCharacter switchChar,
                                       String switchText, SeparatorCharacter sepChar, bool optional, bool multi,
                                       String help, String error, int level, Regex regex)
        {
            IsSet     = false;
            valueList = new List <T>();

            SwitchCharacter    = switchChar;
            Switch             = switchText;
            SeparatorCharacter = sepChar;
            IsOptional         = optional;
            IsSeveralTimes     = multi;
            HelpText           = help;
            Level             = level;
            ErrorText         = error;
            RegularExpression = regex;
            Name = name;
        }
Exemplo n.º 9
0
 public SwitchedContentArgument(String name, SwitchCharacter switchChar,
                                String switchText, SeparatorCharacter sepChar, String help)
     : this(name, switchChar, switchText, sepChar, false, help)
 {
 }
Exemplo n.º 10
0
 public SwitchedContentArgument(String name, SwitchCharacter switchChar,
                                String switchText, SeparatorCharacter sepChar, bool optional, bool multi,
                                String help)
     : this(name, switchChar, switchText, sepChar, optional, multi, help, "%message%")
 {
 }
Exemplo n.º 11
0
 public SwitchedContentArgument(String name, SwitchCharacter switchChar,
                                String switchText, SeparatorCharacter sepChar, bool optional, bool multi,
                                String help, String error, int level)
     : this(name, switchChar, switchText, sepChar, optional, multi, help, error, level, null)
 {
 }
    /// <summary>
    /// Takes the existing value and sets the Category Tree
    /// </summary>
    protected void InitializeControl()
    {
        // Get initial values from Join Table and set the control's value
        if (!IsPostBack)
        {
            // Setup Form Control
            //InitializeFormControl();
            frmFormControl.Value = string.Join(SeparatorCharacter, GetCurrentObjects()).Trim(SeparatorCharacter.ToCharArray());
        }

        /*else if ()
         * {
         *  // Set from Text value
         *  string initialCategories = txtValue.Text;
         *  var CurrentObjectsOfDoc = BaseInfoProvider.GetCategories("CategoryID in ('" + string.Join("','", SplitAndSecure(initialCategories)) + "')", null, -1, null, SiteContext.CurrentSiteID);
         *  if (CurrentObjectsOfDoc != null)
         *  {
         *      CurrentObjects.AddRange(CurrentObjectsOfDoc);
         *  }
         * }*/
    }