Example #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();
        }
Example #2
0
        public PackageResult AddPackageAddonLiteral(
            int packageId,
            int planId,
            int quantity,
            int statusId,
            DateTime purchaseDate,
            string comments)
        {
            PackageAddonInfo pa = new PackageAddonInfo();

            pa.PackageId    = packageId;
            pa.PlanId       = planId;
            pa.Quantity     = quantity;
            pa.StatusId     = statusId;
            pa.PurchaseDate = purchaseDate;
            pa.Comments     = comments;
            return(PackageController.AddPackageAddon(pa));
        }
Example #3
0
 public PackageResult AddPackageAddon(PackageAddonInfo addon)
 {
     return(PackageController.AddPackageAddon(addon));
 }
Example #4
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);
        }