public bool PostFunctionDetails(FunctionDetails r)
        {
            try
            {
                Function_Details fs = new Function_Details();

                fs.Function_Category_ID = r.Function_Category_ID;
                fs.Owner_ID             = r.Owner_ID;
                fs.Function_Date        = r.Function_Date;
                fs.Function_Details1    = r.Function_Details;
                fs.Function_Time        = r.Function_Time;
                fs.Function_Duration    = r.Function_Duration;
                fs.Function_Status      = r.Function_Status;

                es.Function_Details.Add(fs);
                var res = es.SaveChanges();
                if (res > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public IEnumerable <FunctionDetails> GetFunctionDetails()
 {
     try
     {
         List <FunctionDetails> fn = new List <FunctionDetails>();
         var res = es.Function_Details.ToList();
         foreach (var r in res)
         {
             FunctionDetails fs = new FunctionDetails();
             fs.Function_ID          = r.Function_ID;
             fs.Function_Category_ID = r.Function_Category_ID;
             fs.Owner_ID             = r.Owner_ID;
             fs.Function_Date        = r.Function_Date;
             fs.Function_Details     = r.Function_Details1;
             fs.Function_Time        = r.Function_Time;
             fs.Function_Duration    = r.Function_Duration;
             fs.Function_Status      = r.Function_Status;
             fn.Add(fs);
         }
         return(fn);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public FunctionDetails GetFunctionDetails(int id)
        {
            try
            {
                var             r  = es.Function_Details.Where(x => x.Function_ID == id).SingleOrDefault();
                FunctionDetails fs = new FunctionDetails();
                if (r != null)
                {
                    fs.Function_ID          = r.Function_ID;
                    fs.Function_Category_ID = r.Function_Category_ID;
                    fs.Owner_ID             = r.Owner_ID;
                    fs.Function_Date        = r.Function_Date;
                    fs.Function_Details     = r.Function_Details1;
                    fs.Function_Time        = r.Function_Time;
                    fs.Function_Duration    = r.Function_Duration;
                    fs.Function_Status      = r.Function_Status;
                }
                else
                {
                    throw new Exception("Invalid Id");
                }


                return(fs);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public string PutFunctionDetails(FunctionDetails r, int id)
        {
            try
            {
                var fs = (from f in es.Function_Details
                          where f.Function_ID == id
                          select f).SingleOrDefault();
                if (r == null)
                {
                    return("ID Invalid");
                }
                else
                {
                    fs.Function_Category_ID = r.Function_Category_ID;
                    fs.Owner_ID             = r.Owner_ID;
                    fs.Function_Date        = r.Function_Date;
                    fs.Function_Details1    = r.Function_Details;
                    fs.Function_Time        = r.Function_Time;
                    fs.Function_Duration    = r.Function_Duration;
                    fs.Function_Status      = r.Function_Status;

                    var res = es.SaveChanges();

                    if (res > 0)
                    {
                        return("Data Updated");
                    }
                }
                return("Error In Inserting the data");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 5
0
    public override object Evaluate(UnityELEvaluator context)
    {
        FunctionDetails functionDetails = ResolveFunction(context);

        if (functionDetails.Function == null)
        {
            if (functionDetails.ResolutionFailedReason == null)
            {
                functionDetails.ResolutionFailedReason = $"Unable to resolve function: {functionDetails.Name} " +
                                                         $"(host={functionDetails.Host})"; //, namespace={functionDetails.Namespace})";
            }
            throw new NoSuchFunctionException(this, functionDetails.ResolutionFailedReason);
        }

        // Map parameters...
        MethodInfo    function   = functionDetails.Function;
        List <object> parameters = functionDetails.Parameters;

        ParameterInfo[] parameterInfos = function.GetParameters();
        if (parameterInfos.Length > 0)
        {
            // If there is a different number of arguments, see if the last argument is a params
            // and then wrap up the required number of arguments in an array (coercing as needed)
            ParameterInfo lastParam = parameterInfos[parameterInfos.Length - 1];
            if (lastParam.IsDefined(typeof(ParamArrayAttribute), false))
            {
                int   varargCount = parameters.Count - parameterInfos.Length + 1;
                Type  elementType = lastParam.ParameterType.GetElementType();
                Array varargs     = Array.CreateInstance(elementType, varargCount);
                for (int i = 0; i < varargCount; ++i)
                {
                    varargs.SetValue(TypeCoercer.CoerceToType(elementType, this,
                                                              parameters[parameters.Count - varargCount + i]), i);
                }

                parameters[parameterInfos.Length - 1] = varargs;
                parameters.RemoveRange(parameterInfos.Length,
                                       parameters.Count - parameterInfos.Length);
            }

            // Coerce the parameters if needed
            for (int i = 0; i < parameters.Count; ++i)
            {
                parameters[i] = TypeCoercer.CoerceToType(parameterInfos[i].ParameterType,
                                                         this, parameters[i]);
            }
        }

        return(function.Invoke(functionDetails.Host, parameters.ToArray()));
    }
        public List <ServiceInfo> GetServiceContracts()
        {
            var list        = new List <ServiceInfo>();
            var serviceInfo = new ServiceInfo();

            foreach (var hub in _hubmanager.GetHubs())
            {
                Type hubType = hub.HubType;

                string moduleName    = hubType.Namespace;
                string interfaceName = hubType.Name;
                serviceInfo.ModuleName    = moduleName;
                serviceInfo.InterfaceName = interfaceName;

                Type   clientType     = TypeHelper.ClientType(hubType);
                string clientTypeName = clientType != null ? clientType.FullName : "any";
                serviceInfo.ClientType = clientTypeName;

                // Server type and functions
                string serverType          = hubType.Name + "Server";
                string serverFullNamespace = hubType.FullName + "Server";
                serviceInfo.ServerType = serverType;
                serviceInfo.ServerTypeFullNamespace = serverFullNamespace;
                foreach (var method in _hubmanager.GetHubMethods(hub.Name))
                {
                    var ps = method.Parameters.Select(x => x.Name + " : " + TypeHelper.GetTypeContractName(x.ParameterType));
                    var functionDetails = new FunctionDetails()
                    {
                        Name       = _typeHelper.FirstCharLowered(method.Name),
                        Arguments  = "(" + string.Join(", ", ps) + ")",
                        ReturnType = "JQueryPromise<" + TypeHelper.GetTypeContractName(method.ReturnType) + ">"
                    };

                    serviceInfo.ServerFunctions.Add(functionDetails);
                }

                list.Add(serviceInfo);
            }

            return(list);
        }
Exemplo n.º 7
0
        public List <FunctionDetails> GetClientFunctions(Type hubType)
        {
            var list = new List <FunctionDetails>();

            Type clientType = ClientType(hubType);

            if (clientType != null)
            {
                foreach (var method in clientType.GetMethods())
                {
                    var functionDetails     = new FunctionDetails();
                    IEnumerable <string> ps = method.GetParameters().Select(x => x.Name + " : " + GetTypeContractName(x.ParameterType));
                    string functionName     = FirstCharLowered(method.Name);
                    string functionArgs     = "(" + string.Join(", ", ps) + ")";

                    functionDetails.Name      = functionName;
                    functionDetails.Arguments = functionArgs;

                    list.Add(functionDetails);
                }
            }

            return(list);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Generate a function in the current session using the specified
        /// function details
        /// </summary>
        /// <param name="details">details of the function</param>
        private void UpdateFunctionFromXaml(FunctionDetails details)
        {
            // Bind the command into the caller's command table. Note that if
            // ~/ has been passed to this cmdlet, then the Set operation will also be logged
            // the verbose stream. This is desirable as it shows the generated function...
            string functionName = "function:\\script:" + details.Name;

            // This script block is defined as FullLanguage mode, since it contains
            // no text that can be injected by the user.
            ScriptBlock xamlFunctionDefinition = null;
            PSLanguageMode oldLanguageMode = this.SessionState.LanguageMode;
            try
            {
                this.SessionState.LanguageMode = PSLanguageMode.FullLanguage;
                xamlFunctionDefinition = ScriptBlock.Create(details.FunctionDefinition);
            }
            finally
            {
                this.SessionState.LanguageMode = oldLanguageMode;
            }

            WorkflowInfo workflow = new WorkflowInfo(details.Name, "", xamlFunctionDefinition, details.Xaml, null);

            SessionState.InvokeProvider.Item.Set(functionName, workflow);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Load a workflow XAML file from the specified path and generate a PowerShell
        /// function from the file. The name of the generated function will be the basename
        /// of the XAML file.
        /// </summary>
        /// <param name="name">The name of workflow.</param>
        /// <param name="xaml">The xaml of workflow.</param>
        /// <param name="requiredAssemblies"></param>
        /// <param name="dependentWorkflows">Any workflows required by this workflow.</param>
        /// <param name="dependentAssemblyPath">Path to the dependent assembly.</param>
        /// <param name="resolvedPath">Resolved Path of the xaml</param>
        /// <param name="sourceLanguageMode">Language mode of source in which workflow should run</param>
        private static FunctionDetails GenerateFunctionFromXaml(
            string name, 
            string xaml, 
            Dictionary<string, string> requiredAssemblies, 
            string[] dependentWorkflows, 
            string dependentAssemblyPath, 
            string resolvedPath,
            PSLanguageMode sourceLanguageMode)
        {
            if (name == null)
            {
                ArgumentNullException argNullException = new ArgumentNullException("name");
                Tracer.TraceException(argNullException);
                throw argNullException;
            }

            string modulePath = System.IO.Path.GetDirectoryName(resolvedPath);
            string functionDefinition = CreateFunctionFromXaml(
                name, 
                xaml, 
                requiredAssemblies, 
                dependentWorkflows, 
                dependentAssemblyPath, 
                null, 
                modulePath, 
                false, 
                "[CmdletBinding()]",
                null,   /* scriptContent */
                null,   /* fullScript */
                null,   /* rootWorkflowName */
                sourceLanguageMode,
                null);

            FunctionDetails details = new FunctionDetails
                                          {Name = name, FunctionDefinition = functionDefinition, Xaml = xaml};

            return details;
        }
Exemplo n.º 10
0
    public bool Exists(UnityELEvaluator context)
    {
        FunctionDetails functionDetails = ResolveFunction(context);

        return(functionDetails.Function != null);
    }
Exemplo n.º 11
0
    private FunctionDetails ResolveFunction(UnityELEvaluator context)
    {
        FunctionDetails functionDetails = new FunctionDetails();

        // See if there is a host object, otherwise we're looking for a static function on the evaluator
        if (FunctionName is PropertyAccessToken)
        {
            PropertyAccessToken propertyAccess = (PropertyAccessToken)FunctionName;
            functionDetails.Host = propertyAccess.Host.Evaluate(context);
            if (functionDetails.Host == null)
            {
                return(null);
            }

            functionDetails.Name = propertyAccess.Property.Value;
        }
        else if (FunctionName is IdentifierToken)
        {
            IdentifierToken identifier = (IdentifierToken)FunctionName;
            functionDetails.Host = null;
            functionDetails.Name = identifier.Value;
        }

        // Resolve arguments (if any)
        functionDetails.Parameters = new List <object>();
        List <System.Type> types = new List <System.Type>();
        int argIndex             = 0;

        foreach (TokenImpl childToken in Children)
        {
            object value = null;
            if (childToken is ArgumentGroupToken)
            {
                value = ((ArgumentGroupToken)childToken).EvaluateForArgument(context, functionDetails.Name, argIndex);
            }
            else
            {
                value = childToken.Evaluate(context);
            }

            functionDetails.Parameters.Add(value);

            if (value != null)
            {
                types.Add(value.GetType());
            }
            else
            {
                types.Add(null);
            }

            ++argIndex;
        }

        if (functionDetails.Host != null)
        {
            if (context.MemberFunctionResolver == null)
            {
                functionDetails.ResolutionFailedReason = $"Cannot resolve a member function as no MemberFunctionResolver has been configured on the context";
            }
            else
            {
                functionDetails.Function = context.MemberFunctionResolver.ResolveFunction(functionDetails.Host.GetType(), functionDetails.Name, types.ToArray());
            }

            /*} else if (functionDetails.Namespace != null) {
             *  if (!context.FunctionResolvers.ContainsKey(functionDetails.Namespace)) {
             *      functionDetails.ResolutionFailedReason = $"Unknown function namespace: {functionDetails.Namespace}";
             *  } else {
             *      functionDetails.Function = context.FunctionResolvers[functionDetails.Namespace].ResolveFunction(functionDetails.Name, types.ToArray());
             *  }*/
        }
        else
        {
            if (context.DefaultFunctionResolver == null)
            {
                functionDetails.ResolutionFailedReason = $"No function namespace was supplied and no default function resolver was setup";
            }
            else
            {
                functionDetails.Function = context.DefaultFunctionResolver.ResolveFunction(functionDetails.Name, types.ToArray());
            }
        }

        return(functionDetails);
    }
 public bool Post(FunctionDetails fs)
 {
     return(fn.PostFunctionDetails(fs));
 }
 public string Put(int id, FunctionDetails fs)
 {
     return(fn.PutFunctionDetails(fs, id));
 }
Exemplo n.º 14
0
 public bool Post([FromBody] FunctionDetails fs)
 {
     return(fn.PostFunctionDetails(fs));
 }