Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FunctionImportSegmentTemplate" /> class.
        /// </summary>
        /// <param name="segment">The input function import segment.</param>
        public FunctionImportSegmentTemplate(OperationImportSegment segment)
        {
            if (segment == null)
            {
                throw Error.ArgumentNull(nameof(segment));
            }

            IEdmOperationImport operationImport = segment.OperationImports.First();

            if (!operationImport.IsFunctionImport())
            {
                throw new ODataException(Error.Format(SRResources.SegmentShouldBeKind, "FunctionImport", "FunctionImportSegmentTemplate"));
            }

            FunctionImport = (IEdmFunctionImport)operationImport;

            NavigationSource = segment.EntitySet;

            ParameterMappings = OperationHelper.BuildParameterMappings(segment.Parameters, operationImport.Name);

            // join the parameters as p1={p1}
            Literal = FunctionImport.Name + "(" + string.Join(",", ParameterMappings.Select(a => $"{a.Key}={{{a.Value}}}")) + ")";

            IsSingle = FunctionImport.Function.ReturnType.TypeKind() != EdmTypeKind.Collection;
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FunctionSegmentTemplate" /> class.
        /// </summary>
        /// <param name="operationSegment">The operation segment, it should be a function segment and the parameters are template.</param>
        public FunctionSegmentTemplate(OperationSegment operationSegment)
        {
            if (operationSegment == null)
            {
                throw Error.ArgumentNull(nameof(operationSegment));
            }

            IEdmOperation operation = operationSegment.Operations.FirstOrDefault();

            if (!operation.IsFunction())
            {
                throw new ODataException(Error.Format(SRResources.SegmentShouldBeKind, "Function", "FunctionSegmentTemplate"));
            }

            Function = (IEdmFunction)operation;

            NavigationSource = operationSegment.EntitySet;

            ParameterMappings = OperationHelper.BuildParameterMappings(operationSegment.Parameters, operation.FullName());

            // join the parameters as p1={p1}
            string routeKey = ParameterMappings.BuildRouteKey();

            string parameterStr = ParameterMappings.Count == 0 ? "()" : $"({{{routeKey}}})";

            UnqualifiedIdentifier = Function.Name + parameterStr;

            Literal = Function.FullName() + parameterStr;

            // Function will always have the return type
            IsSingle = Function.ReturnType.TypeKind() != EdmTypeKind.Collection;
        }
Example #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FunctionSegmentTemplate" /> class.
        /// </summary>
        /// <param name="parameters">The function parameter template mappings.The key string is case-sensitive, the value string should wrapper with { and }.</param>
        /// <param name="function">The Edm function, it should be bound function.</param>
        /// <param name="navigationSource">The Edm navigation source of this function return. It could be null.</param>
        public FunctionSegmentTemplate(IDictionary <string, string> parameters, IEdmFunction function, IEdmNavigationSource navigationSource)
        {
            if (parameters == null)
            {
                throw Error.ArgumentNull(nameof(parameters));
            }

            Function = function ?? throw Error.ArgumentNull(nameof(function));

            NavigationSource = navigationSource;

            // Only accept the bound function
            if (!function.IsBound)
            {
                throw new ODataException(Error.Format(SRResources.FunctionIsNotBound, function.Name));
            }

            // Parameters should include all required parameter, but maybe include the optional parameter.
            ParameterMappings = function.VerifyAndBuildParameterMappings(parameters);

            // Join the parameters as p1={p1}
            string parameterStr = "(" + string.Join(",", ParameterMappings.Select(a => $"{a.Key}={{{a.Value}}}")) + ")";

            UnqualifiedIdentifier = function.Name + parameterStr;

            Literal = function.FullName() + parameterStr;

            // Function will always have the return type
            IsSingle = function.ReturnType.TypeKind() != EdmTypeKind.Collection;
        }
Example #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FunctionSegmentTemplate" /> class.
        /// </summary>
        /// <param name="parameters">The function parameter template mappings.The key string is case-sensitive, the value string should wrapper with { and }.</param>
        /// <param name="function">The Edm function, it should be bound function.</param>
        /// <param name="navigationSource">The Edm navigation source of this function return. It could be null.</param>
        public FunctionSegmentTemplate(IDictionary <string, string> parameters, IEdmFunction function, IEdmNavigationSource navigationSource)
        {
            if (parameters == null)
            {
                throw Error.ArgumentNull(nameof(parameters));
            }

            Function = function ?? throw Error.ArgumentNull(nameof(function));

            NavigationSource = navigationSource;

            // Only accept the bound function
            if (!function.IsBound)
            {
                throw new ODataException(Error.Format(SRResources.FunctionIsNotBound, function.Name));
            }

            // Parameters should include all required parameter, but maybe include the optional parameter.
            ParameterMappings = function.VerifyAndBuildParameterMappings(parameters);

            string routeKey = ParameterMappings.BuildRouteKey();

            string parameterStr = ParameterMappings.Count == 0 ? "()" : $"({{{routeKey}}})";

            UnqualifiedIdentifier = function.Name + parameterStr;

            Literal = function.FullName() + parameterStr;

            // Function will always have the return type
            IsSingle = function.ReturnType.TypeKind() != EdmTypeKind.Collection;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="FunctionImportSegmentTemplate" /> class.
        /// </summary>
        /// <param name="segment">The input function import segment.</param>
        public FunctionImportSegmentTemplate(OperationImportSegment segment)
        {
            if (segment == null)
            {
                throw Error.ArgumentNull(nameof(segment));
            }

            IEdmOperationImport operationImport = segment.OperationImports.First();

            if (!operationImport.IsFunctionImport())
            {
                throw new ODataException(Error.Format(SRResources.SegmentShouldBeKind, "FunctionImport", "FunctionImportSegmentTemplate"));
            }

            FunctionImport = (IEdmFunctionImport)operationImport;

            NavigationSource = segment.EntitySet;

            ParameterMappings = OperationHelper.BuildParameterMappings(segment.Parameters, operationImport.Name);

            // join the parameters as p1={p1}
            string routeKey     = ParameterMappings.BuildRouteKey();
            string parameterStr = ParameterMappings.Count == 0 ? "()" : $"({{{routeKey}}})";

            Literal = FunctionImport.Name + parameterStr;

            IsSingle = FunctionImport.Function.ReturnType.TypeKind() != EdmTypeKind.Collection;
        }
Example #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FunctionSegmentTemplate" /> class.
        /// </summary>
        /// <param name="operationSegment">The operation segment, it should be a function segment and the parameters are template.</param>
        public FunctionSegmentTemplate(OperationSegment operationSegment)
        {
            if (operationSegment == null)
            {
                throw Error.ArgumentNull(nameof(operationSegment));
            }

            IEdmOperation operation = operationSegment.Operations.FirstOrDefault();

            if (!operation.IsFunction())
            {
                throw new ODataException(Error.Format(SRResources.SegmentShouldBeKind, "Function", "FunctionSegmentTemplate"));
            }

            Function = (IEdmFunction)operation;

            NavigationSource = operationSegment.EntitySet;

            ParameterMappings = OperationHelper.BuildParameterMappings(operationSegment.Parameters, operation.FullName());

            // Join the parameters as p1={p1}
            string parameterStr = "(" + string.Join(",", ParameterMappings.Select(a => $"{a.Key}={{{a.Value}}}")) + ")";

            UnqualifiedIdentifier = Function.Name + parameterStr;

            Literal = Function.FullName() + parameterStr;

            // Function will always have the return type
            IsSingle = Function.ReturnType.TypeKind() != EdmTypeKind.Collection;

            HasOptionalMissing = ParameterMappings.Count != Function.Parameters.Count() - 1;
        }
Example #7
0
        /// <inheritdoc />
        public override IEnumerable <string> GetTemplates(ODataRouteOptions options)
        {
            options = options ?? ODataRouteOptions.Default;

            if (ParameterMappings.Count == 0 && options.EnableNonParenthsisForEmptyParameterFunction)
            {
                yield return($"/{FunctionImport.Name}");
            }
            else
            {
                string parameters = string.Join(",", ParameterMappings.Select(a => $"{a.Key}={{{a.Value}}}"));
                yield return($"/{FunctionImport.Name}({parameters})");
            }
        }
Example #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FunctionImportSegmentTemplate" /> class.
        /// </summary>
        /// <param name="parameters">The function parameter template mappings.The key string is case-sensitive, the value string should wrapper with { and }.</param>
        /// <param name="functionImport">The Edm function import.</param>
        /// <param name="navigationSource">The target navigation source, it could be null.</param>
        public FunctionImportSegmentTemplate(IDictionary <string, string> parameters, IEdmFunctionImport functionImport, IEdmNavigationSource navigationSource)
        {
            if (parameters == null)
            {
                throw Error.ArgumentNull(nameof(parameters));
            }

            FunctionImport   = functionImport ?? throw Error.ArgumentNull(nameof(functionImport));
            NavigationSource = navigationSource;

            // parameters should include all required parameter, but maybe include the optional parameter.
            ParameterMappings = functionImport.Function.VerifyAndBuildParameterMappings(parameters);

            Literal = functionImport.Name + "(" + string.Join(",", ParameterMappings.Select(a => $"{a.Key}={{{a.Value}}}")) + ")";

            IsSingle = functionImport.Function.ReturnType.TypeKind() != EdmTypeKind.Collection;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="FunctionImportSegmentTemplate" /> class.
        /// </summary>
        /// <param name="parameters">The function parameter template mappings.The key string is case-sensitive, the value string should wrapper with { and }.</param>
        /// <param name="functionImport">The Edm function import.</param>
        /// <param name="navigationSource">The target navigation source, it could be null.</param>
        public FunctionImportSegmentTemplate(IDictionary <string, string> parameters, IEdmFunctionImport functionImport, IEdmNavigationSource navigationSource)
        {
            if (parameters == null)
            {
                throw Error.ArgumentNull(nameof(parameters));
            }

            FunctionImport   = functionImport ?? throw Error.ArgumentNull(nameof(functionImport));
            NavigationSource = navigationSource;

            // parameters should include all required parameter, but maybe include the optional parameter.
            ParameterMappings = functionImport.Function.VerifyAndBuildParameterMappings(parameters);

            string routeKey     = ParameterMappings.BuildRouteKey();
            string parameterStr = ParameterMappings.Count == 0 ? "()" : $"({{{routeKey}}})";

            Literal = functionImport.Name + parameterStr;

            IsSingle = functionImport.Function.ReturnType.TypeKind() != EdmTypeKind.Collection;
        }
        /// <inheritdoc />
        public override IEnumerable <string> GetTemplates(ODataRouteOptions options)
        {
            options = options ?? ODataRouteOptions.Default;
            Contract.Assert(options.EnableQualifiedOperationCall || options.EnableUnqualifiedOperationCall);

            string unqualifiedIdentifier, qualifiedIdentifier;

            if (ParameterMappings.Count == 0 && options.EnableNonParenthsisForEmptyParameterFunction)
            {
                unqualifiedIdentifier = "/" + Function.Name;
                qualifiedIdentifier   = "/" + Function.FullName();
            }
            else
            {
                string parameterStr = "(" + string.Join(",", ParameterMappings.Select(a => $"{a.Key}={{{a.Value}}}")) + ")";
                unqualifiedIdentifier = "/" + Function.Name + parameterStr;
                qualifiedIdentifier   = "/" + Function.FullName() + parameterStr;
            }

            if (options.EnableQualifiedOperationCall && options.EnableUnqualifiedOperationCall)
            {
                // "/NS.Function(...)"
                yield return(qualifiedIdentifier);

                // "/Function(...)"
                yield return(unqualifiedIdentifier);
            }
            else if (options.EnableQualifiedOperationCall)
            {
                // "/NS.Function(...)"
                yield return(qualifiedIdentifier);
            }
            else
            {
                // "/Function(...)"
                yield return(unqualifiedIdentifier);
            }
        }
        private void UserControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (this.DataContext is IDataItem)
            {
                _instance = (this.DataContext as IDataItem);

                ParameterMappings mappings = null;
                if (_instance.HasProperty("ParameterMappings"))
                {
                    try
                    {
                        mappings = ParameterMappings.CreateFromString((string)_instance["ParameterMappings"]);
                    }
                    catch (Exception) {}
                }
                if (mappings == null)
                    mappings = new ParameterMappings();

                Init(mappings, (Guid)(_instance["$Class$"] as IDataItem)["Id"]);


                if (!(bool)_instance["$IsNew$"])
                {
                    RunbookGrid.IsEnabled = false;
                    JobTabItem.Visibility = Visibility.Visible;
                    HistoryTabItem.Visibility = Visibility.Visible;

                    /*
                    var className = (_instance["$Class$"] as IDataItem)["Name"].ToString();
                    var activityClass = _emg.EntityTypes.GetClasses(new ManagementPackClassCriteria("Name = '" + className + "'")).FirstOrDefault();
                    if (activityClass != null)
                    {
                        foreach (var p in activityClass.GetProperties(BaseClassTraversalDepth.None))
                        {
                            AddPropertyEditor(p);
                        }
                    } 
                    */
                }
                else
                {
                    RunbookGrid.IsEnabled = true;
                    JobTabItem.Visibility = Visibility.Collapsed;
                    HistoryTabItem.Visibility = Visibility.Collapsed;
                }

                var t = RefreshRunbookParameters();
            }
        }
 public void Init(ParameterMappings mappings, Guid mpClassId)
 {
     PropertyDefinitions = ConsoleHandler.Current.GetPropertyDefinitionsForClass(mpClassId).OrderBy(x => x.DisplayName).ToList();
     Mappings = mappings;
     ParametersPanel.DataContext = Mappings;
 }