예제 #1
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 = AntiXss.HtmlEncode(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 = AntiXss.HtmlEncode(GetExceedingQuotasMessage(result.ExceedingQuotas));
                        return;
                    }
                }
                catch (Exception ex)
                {
                    ShowErrorMessage("PACKAGE_UPDATE_ADDON", ex);
                    return;
                }
            }

            RedirectBack();
        }
예제 #2
0
 public PackageResult UpdatePackageAddon(PackageAddonInfo addon)
 {
     return PackageController.UpdatePackageAddon(addon);
 }
예제 #3
0
 public PackageResult UpdatePackageAddonLiteral(
             int packageAddonId,
             int planId,
             int quantity,
             int statusId,
             DateTime purchaseDate,
             string comments)
 {
     PackageAddonInfo pa = new PackageAddonInfo();
     pa.PackageAddonId = packageAddonId;
     pa.PlanId = planId;
     pa.Quantity = quantity;
     pa.StatusId = statusId;
     pa.PurchaseDate = purchaseDate;
     pa.Comments = comments;
     return PackageController.UpdatePackageAddon(pa);
 }
예제 #4
0
        public static PackageResult UpdatePackageAddon(PackageAddonInfo addon)
        {
            PackageResult result = new PackageResult();

            // check account
            result.Result = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive
                | DemandAccount.IsReseller);
            if (result.Result < 0) return result;

            result.ExceedingQuotas = DataProvider.UpdatePackageAddon(SecurityContext.User.UserId, addon.PackageAddonId,
                addon.PlanId, addon.Quantity, addon.StatusId, addon.PurchaseDate, addon.Comments);

            if (result.ExceedingQuotas.Tables[0].Rows.Count > 0)
                result.Result = BusinessErrorCodes.ERROR_PACKAGE_QUOTA_EXCEED;

            return result;
        }
예제 #5
0
 public PackageResult AddPackageAddon(PackageAddonInfo addon)
 {
     return PackageController.AddPackageAddon(addon);
 }
예제 #6
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();
		}
예제 #7
0
        public static PackageResult AddPackageAddonById(int packageId, int addonPlanId, int quantity)
        {
            PackageAddonInfo addon = new PackageAddonInfo();
            addon.PackageId = packageId;
            addon.PlanId = addonPlanId;
            addon.Quantity = quantity;
            addon.PurchaseDate = DateTime.Now;
            addon.StatusId = 1; // active
            addon.Comments = "";

            return AddPackageAddon(addon);
        }
예제 #8
0
 /// <remarks/>
 public void UpdatePackageAddonAsync(PackageAddonInfo addon) {
     this.UpdatePackageAddonAsync(addon, null);
 }
예제 #9
0
 /// <remarks/>
 public void UpdatePackageAddonAsync(PackageAddonInfo addon, object userState) {
     if ((this.UpdatePackageAddonOperationCompleted == null)) {
         this.UpdatePackageAddonOperationCompleted = new System.Threading.SendOrPostCallback(this.OnUpdatePackageAddonOperationCompleted);
     }
     this.InvokeAsync("UpdatePackageAddon", new object[] {
                 addon}, this.UpdatePackageAddonOperationCompleted, userState);
 }
예제 #10
0
 /// <remarks/>
 public System.IAsyncResult BeginUpdatePackageAddon(PackageAddonInfo addon, System.AsyncCallback callback, object asyncState) {
     return this.BeginInvoke("UpdatePackageAddon", new object[] {
                 addon}, callback, asyncState);
 }
예제 #11
0
 public PackageResult UpdatePackageAddon(PackageAddonInfo addon) {
     object[] results = this.Invoke("UpdatePackageAddon", new object[] {
                 addon});
     return ((PackageResult)(results[0]));
 }
예제 #12
0
 /// <remarks/>
 public void AddPackageAddonAsync(PackageAddonInfo addon) {
     this.AddPackageAddonAsync(addon, null);
 }
예제 #13
0
        public static PackageResult UpdatePackageAddon(PackageAddonInfo addon)
        {
            PackageResult result = new PackageResult();

            // check account
            result.Result = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive
                | DemandAccount.IsReseller);

            if (result.Result < 0)
                result.Result = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive
                | DemandAccount.IsPlatformCSR);

            if (result.Result < 0)
                result.Result = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive
                | DemandAccount.IsResellerCSR);

            if (result.Result < 0) return result;

            result.ExceedingQuotas = DataProvider.UpdatePackageAddon(SecurityContext.User.UserId, addon.PackageAddonId,
                addon.PlanId, addon.Quantity, addon.StatusId, addon.PurchaseDate, addon.Comments);

            if (result.ExceedingQuotas.Tables[0].Rows.Count > 0)
                result.Result = BusinessErrorCodes.ERROR_PACKAGE_QUOTA_EXCEED;

            // Update the Hard quota on home folder in case it was enabled and in case there was a change in disk space
            UpdatePackageHardQuota(addon.PackageId);
            return result;
        }
		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;
		}