Esempio n. 1
0
        internal static ExpandNode Create(ExpandProperty property, string select, string filter, string orderby, XElement schema, ParameterCollection parameterCollection)
        {
            if (property is EntityProperty)
            {
                EntityProperty entityProperty = property as EntityProperty;
                return(new EntityExpandNode(property.Relationship, property.Name, entityProperty.Entity,
                                            select, filter, orderby, schema, parameterCollection));
            }
            else if (property is CollectionProperty)
            {
                CollectionProperty collectionProperty = property as CollectionProperty;
                return(new CollectionExpandNode(property.Relationship, property.Name, collectionProperty.Collection,
                                                select, filter, orderby, schema, parameterCollection));
            }

            throw new NotSupportedException(property.GetType().ToString()); // never
        }
Esempio n. 2
0
        // Trips($filter=contains(Name, {f5eac763-e025-4cf8-aa1d-9bb3a2986515}) $select=Id,Name $orderby=Id desc $expand=Hotels),Contacts($filter=Name eq {670bc07f-6b33-47fb-be01-63834e25ff21})
        protected ExpandNode[] Compose(string value, XElement parentSchema, string parentPath)
        {
            List <ExpandNode> expands = new List <ExpandNode>();

            string val = value;

            //
            Dictionary <string, string> placeholders = new Dictionary <string, string>();

            val = Regex.Replace(val, ParenthesesPairPattern, new MatchEvaluator(m =>
            {
                string guid = GetGuid();
                placeholders.Add(guid, m.Value);
                return(guid);
            }));

            //
            string[] expandStrings = val.Split(',');
            for (int i = 0; i < expandStrings.Length; i++)
            {
                string expandString = expandStrings[i].Trim();
                expandString = DecodeString(expandString, placeholders);

                string property = GetProperty(expandString, out string select, out string filter, out string orderby, out string expand);

                XElement[] propertyPath = Schema.GenerateExpandPropertyPath(parentSchema, property);

                ExpandProperty oProperty = ExpandProperty.Create(property, propertyPath, parentSchema, Schema);

                string     path    = parentPath + "/" + property;
                ExpandNode oExpand = ExpandNode.Create(oProperty, select, filter, orderby, Schema, Parameters);
                oExpand.Path = path;
                expands.Add(oExpand);

                //
                if (!string.IsNullOrWhiteSpace(expand))
                {
                    oExpand.Children = Compose(expand, propertyPath[propertyPath.Length - 1], path);
                }
            }

            return(expands.ToArray());
        }
Esempio n. 3
0
        protected ExpandNode Compose(Expand expand, XElement parentSchema, string parentPath)
        {
            string property = expand.Property;

            XElement[] propertyPath = Schema.GenerateExpandPropertyPath(parentSchema, property);

            ExpandProperty oProperty = ExpandProperty.Create(property, propertyPath, parentSchema, Schema);

            string     path    = parentPath + "/" + property;
            ExpandNode oExpand = ExpandNode.Create(oProperty, expand.Select, expand.Filter, expand.Orderby, Schema, Parameters);

            oExpand.Path = path;

            oExpand.Children = new ExpandNode[expand.Children.Length];
            for (int i = 0; i < expand.Children.Length; i++)
            {
                oExpand.Children[i] = Compose(expand.Children[i], propertyPath[propertyPath.Length - 1], path);
            }

            return(oExpand);
        }
Esempio n. 4
0
        // Module defining this command


        // Optional custom code for this activity


        /// <summary>
        /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run.
        /// </summary>
        /// <param name="context">The NativeActivityContext for the currently running activity.</param>
        /// <returns>A populated instance of System.Management.Automation.PowerShell</returns>
        /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks>
        protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context)
        {
            System.Management.Automation.PowerShell invoker       = global::System.Management.Automation.PowerShell.Create();
            System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName);

            // Initialize the arguments

            if (InputObject.Expression != null)
            {
                targetCommand.AddParameter("InputObject", InputObject.Get(context));
            }

            if (Property.Expression != null)
            {
                targetCommand.AddParameter("Property", Property.Get(context));
            }

            if (ExcludeProperty.Expression != null)
            {
                targetCommand.AddParameter("ExcludeProperty", ExcludeProperty.Get(context));
            }

            if (ExpandProperty.Expression != null)
            {
                targetCommand.AddParameter("ExpandProperty", ExpandProperty.Get(context));
            }

            if (Unique.Expression != null)
            {
                targetCommand.AddParameter("Unique", Unique.Get(context));
            }

            if (Last.Expression != null)
            {
                targetCommand.AddParameter("Last", Last.Get(context));
            }

            if (First.Expression != null)
            {
                targetCommand.AddParameter("First", First.Get(context));
            }

            if (Skip.Expression != null)
            {
                targetCommand.AddParameter("Skip", Skip.Get(context));
            }

            if (SkipLast.Expression != null)
            {
                targetCommand.AddParameter("SkipLast", SkipLast.Get(context));
            }

            if (Wait.Expression != null)
            {
                targetCommand.AddParameter("Wait", Wait.Get(context));
            }

            if (Index.Expression != null)
            {
                targetCommand.AddParameter("Index", Index.Get(context));
            }


            return(new ActivityImplementationContext()
            {
                PowerShellInstance = invoker
            });
        }