Beispiel #1
0
        protected override void ProcessRecord()
        {
            try
            {
                Latch.FeatureMode twoFactor, lockOnRequest = Latch.FeatureMode.DISABLED;
                if (String.IsNullOrEmpty(AppId))
                {
                    AppId = InputHelper.GetUserInput(this, "AppId");
                }
                if (String.IsNullOrEmpty(SecretKey))
                {
                    SecretKey = InputHelper.GetUserInput(this, "SecretKey");
                }
                if (String.IsNullOrEmpty(ParentId))
                {
                    ParentId = InputHelper.GetUserInput(this, "ParentId");
                }
                if (String.IsNullOrEmpty(Name))
                {
                    Name = InputHelper.GetUserInput(this, "Name");
                }
                if (String.IsNullOrEmpty(TwoFactor))
                {
                    TwoFactor = InputHelper.GetUserInput(this, String.Format("TwoFactor \"( {0} | {1} | {2} )\"",
                                                                             Latch.FeatureMode.DISABLED.ToString(), Latch.FeatureMode.MANDATORY.ToString(), Latch.FeatureMode.OPT_IN.ToString()));
                }
                if (String.IsNullOrEmpty(LockOnRequest))
                {
                    LockOnRequest = InputHelper.GetUserInput(this, String.Format("Name \"( {0} | {1} | {2} )\"",
                                                                                 Latch.FeatureMode.DISABLED.ToString(), Latch.FeatureMode.MANDATORY.ToString(), Latch.FeatureMode.OPT_IN.ToString()));
                }

                Enum.TryParse(TwoFactor, true, out twoFactor);
                Enum.TryParse(LockOnRequest, true, out lockOnRequest);

                Latch latch = new Latch(AppId, SecretKey);
                WriteObject(latch.CreateOperation(ParentId, Name, twoFactor, lockOnRequest), true);
            }
            catch (Exception ex)
            {
                InvokeCommand.InvokeScript(String.Format("Write-Host Error: \"{0}\"", ex.Message));
            }
        }
Beispiel #2
0
        public UmbracoLatchResponse CreateOperation(LatchOperationRequestModel operation)
        {
            if (!AccountIsPaired)
            {
                var errorMessage = GetResponseMessage("accountUnpaired");
                return(new UmbracoLatchResponse(false, errorMessage));
            }

            var application = GetApplication();
            var latch       = new Latch(application.ApplicationId, application.Secret);
            var response    = latch.CreateOperation(application.ApplicationId, operation.Name);

            if (response.Error != null)
            {
                var errorMessage = GetResponseMessage("error" + response.Error.Code);
                return(new UmbracoLatchResponse(false, errorMessage));
            }

            if (response.Data == null || !response.Data.ContainsKey("operationId"))
            {
                var errorMessage = GetResponseMessage("createError");
                return(new UmbracoLatchResponse(false, errorMessage));
            }

            var latchOperation = new LatchOperation
            {
                Name            = operation.Name,
                OperationId     = response.Data["operationId"] as string,
                Type            = operation.Type,
                Action          = operation.Action,
                ApplyToAllUsers = operation.ApplyToAllUsers,
                ApplyToAllNodes = operation.ApplyToAllNodes
            };

            latchRepo.InsertOperation(latchOperation, operation.Users, operation.Nodes);

            var successMessage = GetResponseMessage("createSuccess");

            return(new UmbracoLatchResponse(true, successMessage));
        }