Ejemplo n.º 1
0
        public DtoProvisionResponse ConfirmProvisionRequest(DtoConfirmProvisionRequest request)
        {
            var computerService = new ServiceComputer();
            var computer        = computerService.GetByGuid(request.Guid);

            if (computer == null)
            {
                return new DtoProvisionResponse()
                       {
                           ProvisionStatus = EnumProvisionStatus.Status.Error
                       }
            }
            ;
            if (computer.ProvisionStatus == EnumProvisionStatus.Status.Reset)
            {
                return new DtoProvisionResponse()
                       {
                           ProvisionStatus = EnumProvisionStatus.Status.Reset
                       }
            }
            ;
            computer.ProvisionStatus = EnumProvisionStatus.Status.Provisioned;
            computerService.UpdateComputer(computer);
            var response         = new DtoProvisionResponse();
            var clientComServers = new GetClientComServers().Run(request.Guid);

            if (clientComServers != null)
            {
                response.ComServers = clientComServers;
            }
            response.ProvisionStatus = EnumProvisionStatus.Status.Provisioned;
            return(response);
        }
Ejemplo n.º 2
0
        public DtoProvisionResponse RenewSymmKey(DtoRenewKeyRequest request)
        {
            var response        = new DtoProvisionResponse();
            var computerService = new ServiceComputer();
            var computer        = computerService.GetByGuid(request.Guid);

            if (computer == null)
            {
                return new DtoProvisionResponse()
                       {
                           ProvisionStatus = EnumProvisionStatus.Status.Error
                       }
            }
            ;
            if (computer.ProvisionStatus == EnumProvisionStatus.Status.Reset)
            {
                return new DtoProvisionResponse()
                       {
                           ProvisionStatus = EnumProvisionStatus.Status.Reset
                       }
            }
            ;
            computer.ProvisionStatus  = EnumProvisionStatus.Status.Provisioned;
            computer.SymmKeyEncrypted = new EncryptionServices().EncryptText(request.SymmKey);

            //computer may have been renamed, update the name
            var originalName = computer.Name;

            request.Name = request.Name.ToUpper();
            if (!request.Name.Equals(computer.Name))
            {
                computer.Name = request.Name;

                Logger.Debug("SymmKey Update Requires Computer Name Update");
                Logger.Debug("Old Name: " + originalName);
                Logger.Debug("New Name: " + request.Name);

                var doesExist = computerService.GetByName(request.Name);
                //a computer already exists with this name, what next
                if (doesExist != null)
                {
                    if (doesExist.ProvisionStatus == EnumProvisionStatus.Status.Provisioned)
                    {
                        Logger.Debug("An Active Computer With This Name Already Exists.  Cannot Renew SymmKey");
                        return(new DtoProvisionResponse()
                        {
                            ProvisionStatus = EnumProvisionStatus.Status.Error
                        });
                    }
                    else if (doesExist.ProvisionStatus == EnumProvisionStatus.Status.PreProvisioned)

                    {
                        Logger.Debug("Updating Name, Removing PreProvisioned Computer");
                        //new computer has preprovisioned with this name, allow provison to occur
                        //delete the doesExist entity, allowing the archived computer to be restored
                        new ServiceComputer().DeleteComputer(doesExist.Id); //requires a new instance or delete will fail
                    }
                    else if (doesExist.ProvisionStatus == EnumProvisionStatus.Status.ProvisionApproved ||
                             doesExist.ProvisionStatus == EnumProvisionStatus.Status.Reset)
                    {
                        Logger.Debug("Updating Name, Archiving Existing Computer");
                        //new computer has preprovisioned with this name, allow provison to occur
                        //delete the doesExist entity, allowing the archived computer to be restored
                        new ServiceComputer().ArchiveComputerKeepGroups(doesExist.Id); //requires a new instance or delete will fail
                    }
                    else
                    {
                        return(new DtoProvisionResponse()
                        {
                            ProvisionStatus = EnumProvisionStatus.Status.Error
                        });
                    }
                }
            }

            var result = computerService.UpdateComputer(computer);

            if (result == null)
            {
                Logger.Debug("Could Not Renew SymmKey.  Computer Name May Have Been Updated With An Existing Computer");
                return(new DtoProvisionResponse()
                {
                    ProvisionStatus = EnumProvisionStatus.Status.Error
                });
            }

            if (!result.Success)
            {
                Logger.Debug("Could Not Renew SymmKey.  Computer Name May Have Been Updated With An Existing Computer");
                return(new DtoProvisionResponse()
                {
                    ProvisionStatus = EnumProvisionStatus.Status.Error
                });
            }


            var clientComServers = new GetClientComServers().Run(request.Guid);

            if (clientComServers != null)
            {
                response.ComServers = clientComServers;
            }
            response.ProvisionStatus = EnumProvisionStatus.Status.Provisioned;
            return(response);
        }
    }
}