示例#1
0
        public void Order()
        {
            int rootServiceId = Utils.ParseInt(ServiceSettings[ROOT_SERVICE_ID], 0);

            // each add-on should have root service id assigned
            if (rootServiceId < 0)
            {
                throw new Exception(
                          "Incorrect add-on settings. Root Service ID couldn't be found please review logs and correct this issue."
                          );
            }

            // get root service settings
            KeyValueBunch rootSettings = ServiceController.GetServiceSettings(
                ServiceInfo.SpaceId,
                rootServiceId
                );

            // failed to load root service settings
            if (rootSettings == null)
            {
                throw new Exception("Unable to load root service settings.");
            }

            // add package add-on
            PackageAddonInfo addon = new PackageAddonInfo();

            // load Package ID
            int packageId = 0;

            if (!Int32.TryParse(rootSettings[PACKAGE_ID], out packageId))
            {
                throw new Exception("Couldn't parse parent service settings: PackageID property. Parent Service ID: " + rootServiceId);
            }

            // load Plan ID
            int hostingAddon = 0;

            if (!Int32.TryParse(ServiceSettings[HOSTING_ADDON], out hostingAddon))
            {
                throw new Exception("Couldn't parse service settings: HostingAddon property. Service ID: " + ServiceInfo.ServiceId);
            }

            addon.PackageId    = packageId;
            addon.PlanId       = hostingAddon;
            addon.Quantity     = 1;
            addon.StatusId     = (int)PackageStatus.Active;
            addon.PurchaseDate = DateTime.UtcNow;

            PackageResult result = PackageController.AddPackageAddon(addon);

            // failed to create package add-on
            if (result.Result < 0)
            {
                throw new Exception("Unable to add package add-on. Status code: " + result.Result);
            }

            // save service settings
            PackageAddonID = result.Result.ToString();
        }
示例#2
0
        public void Suspend()
        {
            int packageAddonId = 0;

            if (!Int32.TryParse(PackageAddonID, out packageAddonId))
            {
                throw new Exception("Unable to parse Package Add-On ID: " + PackageAddonID);
            }
            // try to get package addon
            PackageAddonInfo addon = PackageController.GetPackageAddon(packageAddonId);

            // check returned package
            if (addon != null)
            {
                // workaround for bug in GetPackageAddon routine
                addon.PackageAddonId = packageAddonId;
                // change package add-on status
                addon.StatusId = (int)PackageStatus.Suspended;
                // save package add-on changes
                PackageResult result = PackageController.UpdatePackageAddon(addon);
                // check returned result
                if (result.Result < 0)
                {
                    throw new Exception("Unable to suspend Package Add-On: " + addon.PackageAddonId);
                }
            }
        }
示例#3
0
        private void SaveAddon()
        {
            if (!Page.IsValid)
            {
                return;
            }

            // gather form data
            PackageAddonInfo addon = new PackageAddonInfo();

            addon.PackageAddonId = PanelRequest.PackageAddonID;
            addon.PackageId      = PanelSecurity.PackageId;
            addon.Comments       = txtComments.Text;
            addon.PlanId         = Utils.ParseInt(ddlPlan.SelectedValue, 0);
            addon.StatusId       = Utils.ParseInt(ddlStatus.SelectedValue, 0);
            addon.PurchaseDate   = PurchaseDate.SelectedDate;
            addon.Quantity       = Utils.ParseInt(txtQuantity.Text, 1);

            if (PanelRequest.PackageAddonID == 0)
            {
                // add a new package addon
                try
                {
                    PackageResult result = ES.Services.Packages.AddPackageAddon(addon);
                    if (result.Result < 0)
                    {
                        ShowResultMessage(result.Result);
                        lblMessage.Text = PortalAntiXSS.Encode(GetExceedingQuotasMessage(result.ExceedingQuotas));
                        return;
                    }
                }
                catch (Exception ex)
                {
                    ShowErrorMessage("PACKAGE_ADD_ADDON", ex);
                    return;
                }
            }
            else
            {
                // update existing package addon
                try
                {
                    PackageResult result = ES.Services.Packages.UpdatePackageAddon(addon);
                    if (result.Result < 0)
                    {
                        ShowResultMessage(result.Result);
                        lblMessage.Text = PortalAntiXSS.Encode(GetExceedingQuotasMessage(result.ExceedingQuotas));
                        return;
                    }
                }
                catch (Exception ex)
                {
                    ShowErrorMessage("PACKAGE_UPDATE_ADDON", ex);
                    return;
                }
            }

            RedirectBack();
        }
示例#4
0
        private void BindPackageAddon()
        {
            try
            {
                int packageId = PanelSecurity.PackageId;

                PackageInfo      package = null;
                PackageAddonInfo addon   = null;

                if (PanelRequest.PackageAddonID != 0)
                {
                    // load package addon
                    addon = ES.Services.Packages.GetPackageAddon(PanelRequest.PackageAddonID);

                    if (addon == null)
                    {
                        // package not found
                        RedirectBack();
                    }

                    packageId = addon.PackageId;
                }

                // load addon package
                package = ES.Services.Packages.GetPackage(packageId);
                if (package == null)
                {
                    RedirectBack();
                }

                // bind addons list
                BindAddons(package.UserId);

                // init other fields
                PurchaseDate.SelectedDate = DateTime.Now;

                if (PanelRequest.PackageAddonID == 0)
                {
                    return;
                }

                Utils.SelectListItem(ddlPlan, addon.PlanId);

                txtComments.Text = addon.Comments;

                PurchaseDate.SelectedDate = addon.PurchaseDate;
                Utils.SelectListItem(ddlPlan, addon.PlanId);
                txtQuantity.Text = addon.Quantity.ToString();
                Utils.SelectListItem(ddlStatus, addon.StatusId);
            }
            catch (Exception ex)
            {
                ShowErrorMessage("PACKAGE_GET_ADDON", ex);
                return;
            }
        }
示例#5
0
        private List <PackageAddonInfo> GetAddons()
        {
            var result = new List <PackageAddonInfo>();

            foreach (RepeaterItem item in repHostingAddons.Items)
            {
                var addon = new PackageAddonInfo();
                addon.PackageAddonId = GetDropDownListSelectedValue(item, "ddlPlan");
                addon.Quantity       = Utils.ParseInt(GetTextBoxText(item, "txtQuantity"), 1);
                result.Add(addon);
            }

            return(result);
        }
示例#6
0
        private void CreateHostingSpace()
        {
            if (!Page.IsValid)
            {
                return;
            }

            string spaceName = ddlPlans.SelectedItem.Text;

            string ftpAccount = (rbFtpAccountName.SelectedIndex == 0) ? null : ftpAccountName.Text;

            string domainName = txtDomainName.Text.Trim();

            PackageResult result = null;

            try
            {
                result = ES.Services.Packages.AddPackageWithResources(PanelSecurity.SelectedUserId,
                                                                      Utils.ParseInt(ddlPlans.SelectedValue, 0),
                                                                      spaceName,
                                                                      Utils.ParseInt(ddlStatus.SelectedValue, 0),
                                                                      chkPackageLetter.Checked,
                                                                      chkCreateResources.Checked, domainName, false, chkCreateWebSite.Checked,
                                                                      chkCreateFtpAccount.Checked, ftpAccount, chkCreateMailAccount.Checked, txtHostName.Text);

                if (result.Result < 0)
                {
                    ShowResultMessage(result.Result);
                    lblMessage.Text = PortalAntiXSS.Encode(GetExceedingQuotasMessage(result.ExceedingQuotas));
                    return;
                }
                else
                {
                    if ((chkIntegratedOUProvisioning.Checked) & !string.IsNullOrEmpty(domainName))
                    {
                        UserInfo user = UsersHelper.GetUser(PanelSecurity.SelectedUserId);

                        if (user != null)
                        {
                            if (user.Role != UserRole.Reseller)
                            {
                                UserSettings settings = ES.Services.Users.GetUserSettings(user.UserId, UserSettings.EXCHANGE_POLICY);
                                string       orgId    = domainName.ToLower();

                                if (settings != null && settings["OrgIdPolicy"] != null)
                                {
                                    orgId = GetOrgId(settings["OrgIdPolicy"], domainName, result.Result);
                                }

                                ES.Services.Organizations.CreateOrganization(result.Result, orgId, domainName.ToLower(), domainName.ToLower());

                                if (result.Result < 0)
                                {
                                    ShowErrorMessage("USERWIZARD_CREATE_ACCOUNT");
                                    return;
                                }

                                //Add Mail Cleaner
                                Knom.Helpers.Net.APIMailCleanerHelper.DomainAdd(domainName, Utils.ParseInt(ddlPlans.SelectedValue, 0));
                            }
                        }
                    }
                    if ((chkCreateMailAccount.Checked) & !string.IsNullOrEmpty(domainName))
                    {
                        //Add Mail Cleaner
                        Knom.Helpers.Net.APIMailCleanerHelper.DomainAdd(domainName, Utils.ParseInt(ddlPlans.SelectedValue, 0));
                    }
                }
            }
            catch (Exception ex)
            {
                ShowErrorMessage("USERWIZARD_CREATE_ACCOUNT", ex);
                return;
            }

            // Save addons
            try
            {
                int spaceId = result.Result;
                foreach (RepeaterItem item in repHostingAddons.Items)
                {
                    PackageAddonInfo addon = new PackageAddonInfo();
                    addon.PackageAddonId = 0;       //PanelRequest.PackageAddonID;
                    addon.PackageId      = spaceId; //PanelSecurity.PackageId;
                    addon.Comments       = "";
                    addon.PlanId         = Utils.ParseInt(GetDropDownListSelectedValue(item, "ddlPlan"), 0);
                    addon.StatusId       = Utils.ParseInt(ddlStatus.SelectedValue, 0);
                    addon.PurchaseDate   = DateTime.Now;
                    addon.Quantity       = Utils.ParseInt(GetTextBoxText(item, "txtQuantity"), 1);
                    PackageResult addonResult = ES.Services.Packages.AddPackageAddon(addon);
                }

                if (rbPackageQuotas.Checked)
                {
                    //TODO: add logic to recalculate quota
                    //If checked rbPackageQuotas take all addons quota, sum it and replace to main hosting quota
                    //You can look the idea from SpaceEditDetails, but in SpaceEditDetails it is manually, need automatic here
                    //At this moment here is a lot of work, maybe later.
                }

                //PackageContext cntx = PackagesHelper.GetCachedPackageContext(spaceId);
                //string resourceGroup = "VPS2012";
                //if (cntx != null && cntx.Groups.ContainsKey(resourceGroup))
                //{
                //    string pageId = "SpaceVPS2012";
                //    string pageUrl = PortalUtils.NavigatePageURL(
                //pageId, PortalUtils.SPACE_ID_PARAM, spaceId.ToString(), null);
                //    Response.Redirect(pageUrl);
                //}
            }
            catch
            {
                //If something happens here, just ignore it. Addons not so important that a Hosting Space
            }

            if (chkRedirectToCreateVPS.Checked)
            {
                string pageId  = "SpaceVPS2012";
                string pageUrl = PortalUtils.NavigatePageURL(
                    pageId, PortalUtils.SPACE_ID_PARAM, result.Result.ToString(), null);
                Response.Redirect(pageUrl);
            }
            else
            {
                // go to space home
                Response.Redirect(PortalUtils.GetSpaceHomePageUrl(result.Result));
            }
        }
示例#7
0
        protected void RollbackOperation(int packageAddonId)
        {
            // check input parameters first
            if (packageAddonId < 1)
            {
                return;                 // exit
            }
            //
            try
            {
                TaskManager.Write(START_ROLLBACK_MSG);
                // restore service
                HostingAddonSvc  addonSvc  = (HostingAddonSvc)RestoreObjectState(SERVICE_INFO);
                PackageAddonInfo addonInfo = PackageController.GetPackageAddon(addonSvc.PackageAddonId);
                //
                int apiResult = 0;

                // during rollback addon should be reverted to its original state
                // compensation logic - revert back addon status
                switch (addonSvc.Status)
                {
                // Active State
                case ServiceStatus.Active:
                    addonInfo.StatusId = (int)PackageStatus.Active;
                    apiResult          = PackageController.UpdatePackageAddon(addonInfo).Result;
                    break;

                // Suspended State
                case ServiceStatus.Suspended:
                    addonInfo.StatusId = (int)PackageStatus.Suspended;
                    apiResult          = PackageController.UpdatePackageAddon(addonInfo).Result;
                    break;

                // Cancelled State
                case ServiceStatus.Cancelled:
                    addonInfo.StatusId = (int)PackageStatus.Cancelled;
                    apiResult          = PackageController.UpdatePackageAddon(addonInfo).Result;
                    break;

                // service has been just ordered & during rollback should be removed
                case ServiceStatus.Ordered:
                    // compensation logic - remove created package
                    apiResult = PackageController.DeletePackageAddon(packageAddonId);
                    break;
                }
                // check WebsitePanel API result
                if (apiResult < 0)
                {
                    //
                    if (addonSvc.Status == ServiceStatus.Ordered)
                    {
                        TaskManager.WriteError(ERROR_ROLLBACK_ORDER_MSG);
                    }
                    else
                    {
                        TaskManager.WriteError(ERROR_ROLLBACK_MSG);
                    }
                    //
                    TaskManager.WriteParameter(RESULT_CODE_PARAM, apiResult);
                }

                // rollback service changes in EC metabase
                apiResult = UpdateServiceInfo(addonSvc);
                // check API result
                if (apiResult < 0)
                {
                    // LOG ERROR
                    TaskManager.WriteError(ERROR_ROLLBACK_SVC_MSG);
                    TaskManager.WriteParameter(RESULT_CODE_PARAM, apiResult);

                    //
                    return;
                }

                //
                TaskManager.Write(ROLLBACK_SUCCEED_MSG);
            }
            catch (Exception ex)
            {
                TaskManager.WriteError(ex);
            }
        }
示例#8
0
        public GenericSvcResult CancelService(ProvisioningContext context)
        {
            GenericSvcResult result = new GenericSvcResult();

            //
            SaveObjectState(SERVICE_INFO, context.ServiceInfo);
            // concretize service to be provisioned
            HostingAddonSvc addonSvc = (HostingAddonSvc)context.ServiceInfo;

            //
            try
            {
                //
                TaskManager.StartTask(SystemTasks.SOURCE_ECOMMERCE, SystemTasks.SVC_CANCEL);
                // LOG INFO
                TaskManager.Write(START_CANCELLATION_MSG);
                TaskManager.WriteParameter(CONTRACT_PARAM, addonSvc.ContractId);
                TaskManager.WriteParameter(SVC_PARAM, addonSvc.ServiceName);
                TaskManager.WriteParameter(SVC_ID_PARAM, addonSvc.ServiceId);

                // 0. Do security checks
                if (!CheckOperationClientPermissions(result))
                {
                    // LOG ERROR
                    TaskManager.WriteError(ERROR_CLIENT_OPERATION_PERMISSIONS);
                    TaskManager.WriteParameter(RESULT_CODE_PARAM, result.ResultCode);
                    // EXIT
                    return(result);
                }
                //
                if (!CheckOperationClientStatus(result))
                {
                    // LOG ERROR
                    TaskManager.WriteError(ERROR_CLIENT_OPERATION_STATUS);
                    TaskManager.WriteParameter(RESULT_CODE_PARAM, result.ResultCode);
                    // EXIT
                    return(result);
                }

                // dummy addon should be just updated in metabase
                if (addonSvc.DummyAddon)
                {
                    goto UpdateSvcMetaInfo;
                }

                PackageAddonInfo addonInfo = PackageController.GetPackageAddon(addonSvc.PackageAddonId);
                addonInfo.StatusId = (int)PackageStatus.Cancelled;
                // cancel hosting addon
                int apiResult = PackageController.UpdatePackageAddon(addonInfo).Result;

                // check WebsitePanel API result
                if (apiResult < 0)
                {
                    result.ResultCode = apiResult;
                    //
                    result.Succeed = false;

                    // LOG ERROR
                    TaskManager.WriteError(ERROR_CANCEL_ADDON_MSG);
                    TaskManager.WriteParameter(RESULT_CODE_PARAM, result.ResultCode);

                    // exit
                    return(result);
                }

UpdateSvcMetaInfo:
                // change addon status to Cancelled
                addonSvc.Status = ServiceStatus.Cancelled;
                // put data into metabase
                int svcResult = UpdateServiceInfo(addonSvc);
                //
                if (svcResult < 0)
                {
                    result.ResultCode = svcResult;
                    //
                    result.Succeed = false;

                    // LOG ERROR
                    TaskManager.WriteError(ERROR_SVC_UPDATE_MSG);
                    TaskManager.WriteParameter(RESULT_CODE_PARAM, result.ResultCode);

                    // ROLLBACK CHANGES
                    RollbackOperation(addonSvc.PackageAddonId);

                    // EXIT
                    return(result);
                }
                //
                SetOutboundParameters(context);
                // LOG INFO
                TaskManager.Write(ADDON_PROVISIONED_MSG);
                //
                result.Succeed = true;
            }
            catch (Exception ex)
            {
                //
                TaskManager.WriteError(ex);

                // ROLLBACK CHANGES
                RollbackOperation(addonSvc.PackageAddonId);

                //
                result.Succeed = false;
                //
                result.Error = ex.Message;
            }
            finally
            {
                // complete task
                TaskManager.CompleteTask();
            }

            //
            return(result);
        }
示例#9
0
        public GenericSvcResult ActivateService(ProvisioningContext context)
        {
            GenericSvcResult result = new GenericSvcResult();

            // remeber svc state
            SaveObjectState(SERVICE_INFO, context.ServiceInfo);

            // concretize service to be provisioned
            HostingAddonSvc addonSvc = (HostingAddonSvc)context.ServiceInfo;
            // concretize parent svc
            HostingPackageSvc packageSvc = (HostingPackageSvc)context.ParentSvcInfo;

            //
            try
            {
                //
                TaskManager.StartTask(SystemTasks.SOURCE_ECOMMERCE, SystemTasks.SVC_ACTIVATE);

                // LOG INFO
                TaskManager.Write(START_ACTIVATION_MSG);
                TaskManager.WriteParameter(CONTRACT_PARAM, addonSvc.ContractId);
                TaskManager.WriteParameter(SVC_PARAM, addonSvc.ServiceName);
                TaskManager.WriteParameter(SVC_ID_PARAM, addonSvc.ServiceId);

                // 0. Do security checks
                if (!CheckOperationClientPermissions(result))
                {
                    // LOG ERROR
                    TaskManager.WriteError(ERROR_CLIENT_OPERATION_PERMISSIONS);
                    TaskManager.WriteParameter(RESULT_CODE_PARAM, result.ResultCode);
                    // EXIT
                    return(result);
                }
                //
                if (!CheckOperationClientStatus(result))
                {
                    // LOG ERROR
                    TaskManager.WriteError(ERROR_CLIENT_OPERATION_STATUS);
                    TaskManager.WriteParameter(RESULT_CODE_PARAM, result.ResultCode);
                    // EXIT
                    return(result);
                }

                // dummy addon should be just updated in metabase
                if (addonSvc.DummyAddon)
                {
                    goto UpdateSvcMetaInfo;
                }

                if (addonSvc.Status == ServiceStatus.Ordered)
                {
                    // error: hosting addon should have parent svc assigned
                    if (packageSvc == null || packageSvc.PackageId == 0)
                    {
                        result.Succeed = false;
                        //
                        result.Error = PARENT_SVC_NOT_FOUND_MSG;
                        //
                        result.ResultCode = EcommerceErrorCodes.ERROR_PARENT_SVC_NOT_FOUND;

                        // LOG ERROR
                        TaskManager.WriteError(result.Error);
                        TaskManager.WriteParameter(RESULT_CODE_PARAM, result.ResultCode);

                        // EXIT
                        return(result);
                    }

                    // fill package add-on fields
                    PackageAddonInfo addon = new PackageAddonInfo();
                    //
                    addon.PackageId = packageSvc.PackageId;
                    //
                    addon.PlanId = addonSvc.PlanId;
                    // set addon quantity
                    addon.Quantity = addonSvc.Quantity;
                    //
                    addon.StatusId = (int)PackageStatus.Active;
                    //
                    addon.PurchaseDate = DateTime.Now;

                    // Create hosting addon through WebsitePanel API
                    PackageResult apiResult = PackageController.AddPackageAddon(addon);
                    // Failed to create addon
                    if (apiResult.Result < 1)
                    {
                        result.Succeed = false;
                        //
                        result.ResultCode = apiResult.Result;

                        // LOG ERROR
                        TaskManager.WriteError(ERROR_CREATE_ADDON_MSG);
                        TaskManager.WriteParameter(RESULT_CODE_PARAM, result.ResultCode);

                        // EXIT
                        return(result);
                    }
                    // store package id
                    addonSvc.PackageAddonId = apiResult.Result;
                }
                else
                {
                    // load package addon
                    PackageAddonInfo addonInfo = PackageController.GetPackageAddon(addonSvc.PackageAddonId);
                    // package addon not found
                    if (addonInfo == null)
                    {
                        result.Succeed = false;
                        //
                        result.ResultCode = EcommerceErrorCodes.ERROR_PCKG_ADDON_NOT_FOUND;
                        //
                        result.Error = ADDON_NOT_FOUND_MSG;

                        // LOG ERROR
                        TaskManager.WriteError(result.Error);
                        TaskManager.WriteParameter(RESULT_CODE_PARAM, result.ResultCode);

                        // EXIT
                        return(result);
                    }

                    // workaround for bug in GetPackageAddon routine
                    //addonInfo.PackageAddonId = addonSvc.PackageAddonId;
                    // change package add-on status
                    addonInfo.StatusId = (int)PackageStatus.Active;

                    // save hosting addon changes
                    PackageResult apiResult = PackageController.UpdatePackageAddon(addonInfo);
                    // check returned result
                    if (apiResult.Result < 0)
                    {
                        result.Succeed = false;
                        //
                        result.ResultCode = apiResult.Result;

                        // LOG ERROR
                        TaskManager.WriteError(ERROR_ACTIVATE_ADDON_MSG);
                        TaskManager.WriteParameter(RESULT_CODE_PARAM, result.ResultCode);

                        // EXIT
                        return(result);
                    }
                }

UpdateSvcMetaInfo:
                // update status only if necessary
                if (addonSvc.Status != ServiceStatus.Active)
                {
                    // change service status to active
                    addonSvc.Status = ServiceStatus.Active;
                    // put data into metabase
                    int svcResult = UpdateServiceInfo(addonSvc);
                    // failed to update metabase
                    if (svcResult < 0)
                    {
                        result.ResultCode = svcResult;
                        //
                        result.Succeed = false;
                        //
                        result.Error = ERROR_SVC_UPDATE_MSG;

                        // LOG ERROR
                        TaskManager.WriteError(result.Error);
                        TaskManager.WriteParameter(RESULT_CODE_PARAM, result.ResultCode);

                        // ROLLBACK CHANGES
                        RollbackOperation(addonSvc.PackageAddonId);

                        // EXIT
                        return(result);
                    }
                }
                //
                SetOutboundParameters(context);
                // LOG INFO
                TaskManager.Write(ADDON_PROVISIONED_MSG);
                //
                result.Succeed = true;
            }
            catch (Exception ex)
            {
                //
                TaskManager.WriteError(ex);

                // ROLLBACK CHANGES
                RollbackOperation(addonSvc.PackageAddonId);

                //
                result.Succeed = false;
                //
                result.Error = ex.Message;
            }
            finally
            {
                // complete task
                TaskManager.CompleteTask();
            }

            //
            return(result);
        }