public virtual PSFunction CreatePSFunction(CreatePSFunctionParameter parameter)
        {
            if (parameter == null)
            {
                throw new ArgumentNullException("parameter");
            }

            PSFunction function       = null;
            Action     createFunction = () =>
            {
                function = new PSFunction(
                    CreateOrUpdatePSFunction(parameter.ResourceGroupName,
                                             parameter.JobName,
                                             parameter.FunctionName,
                                             parameter.RawJsonContent))
                {
                    ResourceGroupName = parameter.ResourceGroupName,
                    JobName           = parameter.JobName
                };
            };

            if (parameter.Force)
            {
                // If user decides to overwrite anyway, then there is no need to check if the linked service exists or not.
                createFunction();
            }
            else
            {
                bool functionExists = CheckFunctionExists(parameter.ResourceGroupName, parameter.JobName, parameter.FunctionName);

                parameter.ConfirmAction(
                    !functionExists,
                    string.Format(
                        CultureInfo.InvariantCulture,
                        Resources.FunctionExists,
                        parameter.FunctionName,
                        parameter.JobName,
                        parameter.ResourceGroupName),
                    string.Format(
                        CultureInfo.InvariantCulture,
                        Resources.FunctionCreating,
                        parameter.FunctionName,
                        parameter.JobName,
                        parameter.ResourceGroupName),
                    parameter.FunctionName,
                    createFunction);
            }

            return(function);
        }
        public virtual PSFunction CreatePSFunction(CreatePSFunctionParameter parameter)
        {
            if (parameter == null)
            {
                throw new ArgumentNullException("parameter");
            }

            PSFunction function = null;
            Action createFunction = () =>
            {
                function = new PSFunction(
                    CreateOrUpdatePSFunction(parameter.ResourceGroupName,
                        parameter.JobName,
                        parameter.FunctionName,
                        parameter.RawJsonContent))
                {
                    ResourceGroupName = parameter.ResourceGroupName,
                    JobName = parameter.JobName
                };
            };

            if (parameter.Force)
            {
                // If user decides to overwrite anyway, then there is no need to check if the linked service exists or not.
                createFunction();
            }
            else
            {
                bool functionExists = CheckFunctionExists(parameter.ResourceGroupName, parameter.JobName, parameter.FunctionName);

                parameter.ConfirmAction(
                        !functionExists,
                        string.Format(
                            CultureInfo.InvariantCulture,
                            Resources.FunctionExists,
                            parameter.FunctionName,
                            parameter.JobName,
                            parameter.ResourceGroupName),
                        string.Format(
                            CultureInfo.InvariantCulture,
                            Resources.FunctionCreating,
                            parameter.FunctionName,
                            parameter.JobName,
                            parameter.ResourceGroupName),
                        parameter.FunctionName,
                        createFunction);
            }

            return function;
        }
 private bool CheckFunctionExists(string resourceGroupName, string jobName, string functionName)
 {
     try
     {
         PSFunction function = GetFunction(resourceGroupName, jobName, functionName);
         return(true);
     }
     catch (CloudException e)
     {
         //Get throws Exception message with NotFound Status
         if (e.Response.StatusCode == HttpStatusCode.NotFound)
         {
             return(false);
         }
         else
         {
             throw;
         }
     }
 }
Beispiel #4
0
        public virtual PSFunction CreatePSFunction(CreatePSFunctionParameter parameter)
        {
            if (parameter == null)
            {
                throw new ArgumentNullException("parameter");
            }

            PSFunction function = null;

            parameter.ConfirmAction(
                parameter.Force,
                string.Format(
                    CultureInfo.InvariantCulture,
                    Resources.FunctionExists,
                    parameter.FunctionName,
                    parameter.JobName,
                    parameter.ResourceGroupName),
                string.Format(
                    CultureInfo.InvariantCulture,
                    Resources.FunctionCreating,
                    parameter.FunctionName,
                    parameter.JobName,
                    parameter.ResourceGroupName),
                parameter.FunctionName,
                () =>
            {
                function = new PSFunction(
                    CreateOrUpdatePSFunction(parameter.ResourceGroupName,
                                             parameter.JobName,
                                             parameter.FunctionName,
                                             parameter.RawJsonContent))
                {
                    ResourceGroupName = parameter.ResourceGroupName,
                    JobName           = parameter.JobName
                };
            },
                () => CheckFunctionExists(parameter.ResourceGroupName, parameter.JobName, parameter.FunctionName));

            return(function);
        }
        public virtual PSFunction CreatePSFunction(CreatePSFunctionParameter parameter)
        {
            if (parameter == null)
            {
                throw new ArgumentNullException("parameter");
            }

            PSFunction function = null;
            parameter.ConfirmAction(
                    parameter.Force,
                    string.Format(
                        CultureInfo.InvariantCulture,
                        Resources.FunctionExists,
                        parameter.FunctionName,
                        parameter.JobName,
                        parameter.ResourceGroupName),
                    string.Format(
                        CultureInfo.InvariantCulture,
                        Resources.FunctionCreating,
                        parameter.FunctionName,
                        parameter.JobName,
                        parameter.ResourceGroupName),
                    parameter.FunctionName,
                    () =>
                    {
                        function = new PSFunction(
                            CreateOrUpdatePSFunction(parameter.ResourceGroupName,
                                parameter.JobName,
                                parameter.FunctionName,
                                parameter.RawJsonContent))
                        {
                            ResourceGroupName = parameter.ResourceGroupName,
                            JobName = parameter.JobName
                        };
                    },
                    () => CheckFunctionExists(parameter.ResourceGroupName, parameter.JobName, parameter.FunctionName));

            return function;
        }