Exemple #1
0
        public static GenericSvcResult CancelService(int serviceId, bool sendEmail)
        {
            GenericSvcResult result = new GenericSvcResult();

            try
            {
                Service svc = GetRawCustomerService(serviceId);
                //
                ES.TaskManager.StartTask(SystemTasks.SOURCE_SPF, SystemTasks.SVC_CANCEL);
                ES.TaskManager.WriteParameter("Service", svc.ServiceName);
                //
                CancelOverdueInvoicesTask task = new CancelOverdueInvoicesTask();
                // obtain result
                result = task.CancelService(serviceId, sendEmail);
            }
            catch (Exception ex)
            {
                ES.TaskManager.WriteError(ex);
            }
            finally
            {
                ES.TaskManager.CompleteTask();
            }
            //
            return(result);
        }
Exemple #2
0
        public static GenericSvcResult ActivateService(int serviceId, bool sendEmail)
        {
            GenericSvcResult result = new GenericSvcResult();

            try
            {
                Service svc = GetRawCustomerService(serviceId);
                //
                ES.TaskManager.StartTask(SystemTasks.SOURCE_SPF, SystemTasks.SVC_ACTIVATE);
                ES.TaskManager.WriteParameter("Service", svc.ServiceName);
                //
                ActivatePaidInvoicesTask task = new ActivatePaidInvoicesTask();
                // obtain result
                result = task.ActivateService(serviceId, sendEmail, false);
            }
            catch (Exception ex)
            {
                ES.TaskManager.WriteError(ex);
            }
            finally
            {
                ES.TaskManager.CompleteTask();
            }
            //
            return(result);
        }
        public GenericSvcResult ActivateService(int serviceId, bool sendEmail, bool logSvcUsage)
        {
            GenericSvcResult result = null;
            // load svc type
            ProductType svc_type = ServiceController.GetServiceItemType(serviceId);

            //
            if (svc_type == null)
            {
                result         = new GenericSvcResult();
                result.Succeed = true;
                return(result);
            }
            // instantiate svc controller
            IServiceProvisioning controller = (IServiceProvisioning)Activator.CreateInstance(
                Type.GetType(svc_type.ProvisioningController));
            // create context
            ProvisioningContext context = controller.GetProvisioningContext(serviceId, sendEmail);

            // activate svc
            result = controller.ActivateService(context);
            // check result
            if (result.Succeed)
            {
                // log svc usage
                if (logSvcUsage)
                {
                    controller.LogServiceUsage(context);
                }
            }
            //
            return(result);
        }
        public GenericSvcResult ActivateInvoiceItem(InvoiceItem item)
        {
            GenericSvcResult svc_result = ActivateService(item.ServiceId, true, true);

            //
            if (svc_result.Succeed)
            {
                InvoiceController.SetInvoiceItemProcessed(item.InvoiceId, item.ItemId);
            }
            //
            return(svc_result);
        }
        public bool CheckOperationClientPermissions(GenericSvcResult result)
        {
            // 1. Do security checks
            SecurityResult secResult = StorehouseController.CheckAccountIsAdminOrReseller();

            // ERROR
            if (!secResult.Success)
            {
                result.Succeed    = false;
                result.ResultCode = secResult.ResultCode;
                //
                return(false);
            }
            //
            return(true);
        }
Exemple #6
0
        public GenericSvcResult CancelService(int serviceId, bool sendEmail)
        {
            GenericSvcResult result = null;
            // load svc type
            ProductType svc_type = ServiceController.GetServiceItemType(serviceId);
            // instantiate svc controller
            IServiceProvisioning controller = (IServiceProvisioning)Activator.CreateInstance(
                Type.GetType(svc_type.ProvisioningController));
            // create context
            ProvisioningContext context = controller.GetProvisioningContext(serviceId, sendEmail);

            // cancel svc
            result = controller.CancelService(context);
            //
            return(result);
        }
        public bool CheckOperationClientStatus(GenericSvcResult result)
        {
            // 2. Check account status
            SecurityResult secResult = StorehouseController.CheckAccountNotDemoAndActive();

            // ERROR
            if (!secResult.Success)
            {
                result.Succeed    = false;
                result.ResultCode = secResult.ResultCode;
                //
                return(false);
            }
            //
            return(true);
        }
        public GenericSvcResult CancelService(ProvisioningContext context)
        {
            GenericSvcResult result = new GenericSvcResult();

            //
            result.Succeed = true;
            //
            DomainNameSvc service = (DomainNameSvc)context.ServiceInfo;

            service.Status = ServiceStatus.Cancelled;
            //
            UpdateServiceInfo(service);
            //
            SetOutboundParameters(context);
            //
            return(result);
        }
Exemple #9
0
        public void CancelOverdueServices()
        {
            // load store settings
            StoreSettings settings = StorehouseController.GetStoreSettings(SecurityContext.User.UserId,
                                                                           StoreSettings.SYSTEM_SETTINGS);
            //
            int threshold = Convert.ToInt32(settings["SvcCancelThreshold"]);
            //
            TimeSpan ts = new TimeSpan(threshold, 0, 0, 0);
            // calculate actual suspend date
            DateTime dueDate = DateTime.Now.Subtract(ts);
            // lookup for overdue invoices
            List <InvoiceItem> items = InvoiceController.GetInvoicesItemsOverdue(SecurityContext.User.UserId, dueDate);

            // TRACE
            TaskManager.Write("Cancel overdue services");
            TaskManager.WriteParameter("Items found", items.Count);
            //
            foreach (InvoiceItem item in items)
            {
                try
                {
                    TaskManager.Write("Cancelling service");
                    // cancelling
                    GenericSvcResult result = CancelService(item.ServiceId, true);
                    // LOG ERROR
                    if (!result.Succeed)
                    {
                        TaskManager.WriteError(result.Error);
                        if (!String.IsNullOrEmpty(result.ErrorCode))
                        {
                            TaskManager.WriteParameter("Error code", result.ErrorCode);
                        }
                        TaskManager.WriteParameter("Result code", result.ResultCode);
                        // go to next item
                        continue;
                    }
                    //
                    TaskManager.Write("Cancelled");
                }
                catch (Exception ex)
                {
                    TaskManager.WriteError(ex);
                }
            }
        }
Exemple #10
0
 public override void ExecuteTrigger(TriggerEventArgs eventArgs)
 {
     //
     try
     {
         ActivatePaidInvoicesTask activator = new ActivatePaidInvoicesTask();
         // Load invoice items to activate
         List <InvoiceItem> items = InvoiceController.GetCustomerInvoiceItems(Convert.ToInt32(ReferenceId));
         //
         foreach (InvoiceItem item in items)
         {
             try
             {
                 ES.TaskManager.Write("Activating service");
                 // activating
                 GenericSvcResult result = activator.ActivateInvoiceItem(item);
                 // LOG ERROR
                 if (!result.Succeed)
                 {
                     ES.TaskManager.WriteError(result.Error);
                     if (!String.IsNullOrEmpty(result.ErrorCode))
                     {
                         ES.TaskManager.WriteParameter("Error code", result.ErrorCode);
                     }
                     ES.TaskManager.WriteParameter("Result code", result.ResultCode);
                     // go to next item
                     continue;
                 }
                 //
                 ES.TaskManager.Write("Activated");
             }
             catch (Exception ex)
             {
                 ES.TaskManager.WriteError(ex);
             }
         }
     }
     catch (Exception ex)
     {
         TriggerStatus = "ERROR";
         ES.TaskManager.WriteError(ex);
     }
 }
        public void ActivatePaidServices()
        {
            // load paid invoice items
            List <InvoiceItem> items = InvoiceController.GetInvoicesItemsToActivate(SecurityContext.User.UserId);

            // TRACE
            TaskManager.Write("Activate paid services");
            TaskManager.WriteParameter("Items found", items.Count);
            // iterate
            foreach (InvoiceItem item in items)
            {
                try
                {
                    TaskManager.Write("Activating service");
                    // activating
                    GenericSvcResult result = ActivateInvoiceItem(item);
                    // LOG ERROR
                    if (!result.Succeed)
                    {
                        TaskManager.WriteError(result.Error);
                        if (!String.IsNullOrEmpty(result.ErrorCode))
                        {
                            TaskManager.WriteParameter("Error code", result.ErrorCode);
                        }
                        TaskManager.WriteParameter("Result code", result.ResultCode);
                        // go to next item
                        continue;
                    }
                    //
                    TaskManager.Write("Activated");
                }
                catch (Exception ex)
                {
                    TaskManager.WriteError(ex);
                }
            }
        }
Exemple #12
0
        public void SuspendOverdueServices()
        {
            // lookup for today's overdue invoices
            List <InvoiceItem> items = InvoiceController.GetInvoicesItemsOverdue(SecurityContext.User.UserId, DateTime.Now);

            // TRACE
            TaskManager.Write("Suspend overdue services");
            TaskManager.WriteParameter("Items found", items.Count);
            //
            foreach (InvoiceItem item in items)
            {
                try
                {
                    TaskManager.Write("Suspending service");
                    // suspending
                    GenericSvcResult result = SuspendService(item.ServiceId, true);
                    // LOG ERROR
                    if (!result.Succeed)
                    {
                        TaskManager.WriteError(result.Error);
                        if (!String.IsNullOrEmpty(result.ErrorCode))
                        {
                            TaskManager.WriteParameter("Error code", result.ErrorCode);
                        }
                        TaskManager.WriteParameter("Result code", result.ResultCode);
                        // go to next item
                        continue;
                    }
                    //
                    TaskManager.Write("Suspended");
                }
                catch (Exception ex)
                {
                    TaskManager.WriteError(ex);
                }
            }
        }
		public bool CheckOperationClientStatus(GenericSvcResult result)
		{
			// 2. Check account status
			SecurityResult secResult = StorehouseController.CheckAccountNotDemoAndActive();
			// ERROR
			if (!secResult.Success)
			{
				result.Succeed = false;
				result.ResultCode = secResult.ResultCode;
				//
				return false;
			}
			//
			return true;
		}
		public static GenericSvcResult CancelService(int serviceId, bool sendEmail)
		{
			GenericSvcResult result = new GenericSvcResult();

			try
			{
				Service svc = GetRawCustomerService(serviceId);
				//
				ES.TaskManager.StartTask(SystemTasks.SOURCE_SPF, SystemTasks.SVC_CANCEL);
				ES.TaskManager.WriteParameter("Service", svc.ServiceName);
				//
				CancelOverdueInvoicesTask task = new CancelOverdueInvoicesTask();
				// obtain result
				result = task.CancelService(serviceId, sendEmail);
			}
			catch (Exception ex)
			{
				ES.TaskManager.WriteError(ex);
			}
			finally
			{
				ES.TaskManager.CompleteTask();
			}
			//
			return result;
		}
		public static GenericSvcResult ActivateService(int serviceId, bool sendEmail)
		{
			GenericSvcResult result = new GenericSvcResult();

			try
			{
				Service svc = GetRawCustomerService(serviceId);
				//
				ES.TaskManager.StartTask(SystemTasks.SOURCE_SPF, SystemTasks.SVC_ACTIVATE);
				ES.TaskManager.WriteParameter("Service", svc.ServiceName);
				//
				ActivatePaidInvoicesTask task = new ActivatePaidInvoicesTask();
				// obtain result
				result = task.ActivateService(serviceId, sendEmail, false);
			}
			catch (Exception ex)
			{
				ES.TaskManager.WriteError(ex);
			}
			finally
			{
				ES.TaskManager.CompleteTask();
			}
			//
			return result;
		}
		public GenericSvcResult CancelService(ProvisioningContext context)
		{
			GenericSvcResult result = new GenericSvcResult();

			// 
			SaveObjectState(SERVICE_INFO, context.ServiceInfo);
			// 
			SaveObjectState(CONSUMER_INFO, context.ConsumerInfo);

			// concretize service to be provisioned
			HostingPackageSvc packageSvc = (HostingPackageSvc)context.ServiceInfo;

			//
			try
			{
				//
				TaskManager.StartTask(SystemTasks.SOURCE_ECOMMERCE, SystemTasks.SVC_CANCEL);
				// LOG INFO
				TaskManager.Write(START_CANCELLATION_MSG);
				TaskManager.WriteParameter(CONTRACT_PARAM, context.ConsumerInfo[ContractAccount.USERNAME]);
				TaskManager.WriteParameter(SVC_PARAM, context.ServiceInfo.ServiceName);
				TaskManager.WriteParameter(SVC_ID_PARAM, context.ServiceInfo.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;
				}

				// cancel hosting package
				int apiResult = PackageController.ChangePackageStatus(packageSvc.PackageId, 
					PackageStatus.Cancelled, false);

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

					// LOG ERROR
					TaskManager.WriteError(ERROR_CANCEL_PCKG_MSG);
					TaskManager.WriteParameter(RESULT_CODE_PARAM, result.ResultCode);
					
					// EXIT
					return result;
				}

				// change service status to Cancelled
				packageSvc.Status = ServiceStatus.Cancelled;
				// put data into metabase
				int svcResult = UpdateServiceInfo(packageSvc);

				//
				if (svcResult < 0)
				{
					result.ResultCode = svcResult;
					//
					result.Error = ERROR_SVC_UPDATE_MSG;
					//
					result.Succeed = false;

					// ROLLBACK CHANGES
					RollbackOperation(packageSvc.PackageId);

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

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

				// ROLLBACK CHANGES
				RollbackOperation(packageSvc.PackageId);

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

			//
			return result;
		}
		public GenericSvcResult ActivateService(ProvisioningContext context)
		{
			GenericSvcResult result = new GenericSvcResult();

			// 
			SaveObjectState(SERVICE_INFO, context.ServiceInfo);
			// 
			SaveObjectState(CONSUMER_INFO, context.ConsumerInfo);

			// concretize service to be provisioned
			HostingPackageSvc packageSvc = (HostingPackageSvc)context.ServiceInfo;
			//
			try
			{
				//
				TaskManager.StartTask(SystemTasks.SOURCE_ECOMMERCE, SystemTasks.SVC_ACTIVATE);

				// LOG INFO
				TaskManager.Write(START_ACTIVATION_MSG);
				TaskManager.WriteParameter(USERNAME_PARAM, context.ConsumerInfo[ContractAccount.USERNAME]);
				TaskManager.WriteParameter(SVC_PARAM, context.ServiceInfo.ServiceName);
				TaskManager.WriteParameter(SVC_ID_PARAM, context.ServiceInfo.ServiceId);
			    TaskManager.TaskParameters[SystemTaskParams.PARAM_SEND_EMAIL] = context.SendEmail;

				// 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;
				}

				// 1. Hosting package is just ordered
				if (context.ServiceInfo.Status == ServiceStatus.Ordered && context.ContractInfo.CustomerId > 0)
				{
					// LOG INFO
					TaskManager.Write(CREATE_PCKG_MSG);
					// create new package
					PackageResult apiResult = PackageController.AddPackage(context.ContractInfo.CustomerId, packageSvc.PlanId, 
						packageSvc.ServiceName, String.Empty, (int)packageSvc.InitialStatus, DateTime.Now, true, true);

					// failed to instantiate package
					if (apiResult.Result <= 0)
					{
						result.ResultCode = apiResult.Result;
						//
						result.Succeed = false;

						// LOG ERROR
						TaskManager.WriteError(CREATE_PCKG_ERROR_MSG);
						TaskManager.WriteParameter(RESULT_CODE_PARAM, result.ResultCode);
						
						// EXIT
						return result;
					}
					// save result PackageId
					packageSvc.PackageId = apiResult.Result;
				}
				else // 2. Package requires only to update its status
				{
					// LOG INFO
					TaskManager.Write(START_ACTIVATION_MSG);

					//
					int apiResult = PackageController.ChangePackageStatus(packageSvc.PackageId,
						PackageStatus.Active, false);
					//
					if (apiResult < 0)
					{
						result.ResultCode = apiResult;
						//
						result.Succeed = false;

						// LOG ERROR
						TaskManager.WriteError(ERROR_ACTIVATE_PCKG_MSG);
						TaskManager.WriteParameter(RESULT_CODE_PARAM, result.ResultCode);
						
						// EXIT
						return result;
					}
				}
				// check user role
				if (context.ContractInfo.CustomerId > 0)
				{
                    UserInfo user = UserController.GetUserInternally(context.ContractInfo.CustomerId);
                    // check user status
                    //
                    if (user.Status != UserStatus.Active)
                    {
                        // LOG INFO
                        TaskManager.Write(START_USR_ACTIVATION_MSG);

                        // trying to change user status
                        int userResult = UserController.ChangeUserStatus(context.ContractInfo.CustomerId,
                            UserStatus.Active);
                        // failed to activate user account
                        if (userResult < 0)
                        {
                            result.ResultCode = userResult;
                            //
                            result.Succeed = false;

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

                            // ROLLBACK CHANGES
                            RollbackOperation(result.ResultCode);

                            // EXIT
                            return result;
                        }
                    }
                    // check user role
                    if (user.Role != packageSvc.UserRole)
                    {
                        // LOG INFO
                        TaskManager.Write(START_CHANGE_USR_ROLE_MSG);
                        //
                        user.Role = packageSvc.UserRole;
                        // trying to change user role
                        int roleResult = UserController.UpdateUser(user);
                        // failed to change user role
                        if (roleResult < 0)
                        {
                            result.ResultCode = roleResult;
                            //
                            result.Succeed = false;

                            //
							TaskManager.WriteError(ERROR_CHANGE_USR_ROLE_MSG);
                            TaskManager.WriteParameter(RESULT_CODE_PARAM, result.ResultCode);

                            // ROLLBACK CHANGES
                            RollbackOperation(result.ResultCode);

                            // EXIT
                            return result;
                        }
                    }
				}
				// update plan status if necessary
				if (packageSvc.Status != ServiceStatus.Active)
				{
					// change service status to active
					packageSvc.Status = ServiceStatus.Active;
					// put data into metabase
					int svcResult = UpdateServiceInfo(packageSvc);

					// error updating svc details
					if (svcResult < 0)
					{
						result.ResultCode = svcResult;
						//
						result.Succeed = false;

						// ROLLBACK CHANGES
						RollbackOperation(packageSvc.PackageId);

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

						// EXIT
						return result;
					}
				}
                //
                SetOutboundParameters(context);
				// LOG INFO
				TaskManager.Write(PCKG_PROVISIONED_MSG);

				//
				result.Succeed = true;
			}
			catch (Exception ex)
			{
				//
				TaskManager.WriteError(ex);

				// ROLLBACK CHANGES
				RollbackOperation(packageSvc.PackageId);

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

			//
			return result;
		}
Exemple #18
0
        public GenericSvcResult ActivateService(ProvisioningContext context)
        {
            GenericSvcResult result = new GenericSvcResult();

            //
            SaveObjectState(SERVICE_INFO, context.ServiceInfo);
            //
            SaveObjectState(CONSUMER_INFO, context.ConsumerInfo);

            // concretize service to be provisioned
            HostingPackageSvc packageSvc = (HostingPackageSvc)context.ServiceInfo;

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

                // LOG INFO
                TaskManager.Write(START_ACTIVATION_MSG);
                TaskManager.WriteParameter(USERNAME_PARAM, context.ConsumerInfo[ContractAccount.USERNAME]);
                TaskManager.WriteParameter(SVC_PARAM, context.ServiceInfo.ServiceName);
                TaskManager.WriteParameter(SVC_ID_PARAM, context.ServiceInfo.ServiceId);
                TaskManager.TaskParameters[SystemTaskParams.PARAM_SEND_EMAIL] = context.SendEmail;

                // 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);
                }

                // 1. Hosting package is just ordered
                if (context.ServiceInfo.Status == ServiceStatus.Ordered && context.ContractInfo.CustomerId > 0)
                {
                    // LOG INFO
                    TaskManager.Write(CREATE_PCKG_MSG);
                    // create new package
                    PackageResult apiResult = PackageController.AddPackage(context.ContractInfo.CustomerId, packageSvc.PlanId,
                                                                           packageSvc.ServiceName, String.Empty, (int)packageSvc.InitialStatus, DateTime.Now, true, true);

                    // failed to instantiate package
                    if (apiResult.Result <= 0)
                    {
                        result.ResultCode = apiResult.Result;
                        //
                        result.Succeed = false;

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

                        // EXIT
                        return(result);
                    }
                    // save result PackageId
                    packageSvc.PackageId = apiResult.Result;
                }
                else                 // 2. Package requires only to update its status
                {
                    // LOG INFO
                    TaskManager.Write(START_ACTIVATION_MSG);

                    //
                    int apiResult = PackageController.ChangePackageStatus(packageSvc.PackageId,
                                                                          PackageStatus.Active, false);
                    //
                    if (apiResult < 0)
                    {
                        result.ResultCode = apiResult;
                        //
                        result.Succeed = false;

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

                        // EXIT
                        return(result);
                    }
                }
                // check user role
                if (context.ContractInfo.CustomerId > 0)
                {
                    UserInfo user = UserController.GetUserInternally(context.ContractInfo.CustomerId);
                    // check user status
                    //
                    if (user.Status != UserStatus.Active)
                    {
                        // LOG INFO
                        TaskManager.Write(START_USR_ACTIVATION_MSG);

                        // trying to change user status
                        int userResult = UserController.ChangeUserStatus(context.ContractInfo.CustomerId,
                                                                         UserStatus.Active);
                        // failed to activate user account
                        if (userResult < 0)
                        {
                            result.ResultCode = userResult;
                            //
                            result.Succeed = false;

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

                            // ROLLBACK CHANGES
                            RollbackOperation(result.ResultCode);

                            // EXIT
                            return(result);
                        }
                    }
                    // check user role
                    if (user.Role != packageSvc.UserRole)
                    {
                        // LOG INFO
                        TaskManager.Write(START_CHANGE_USR_ROLE_MSG);
                        //
                        user.Role = packageSvc.UserRole;
                        // trying to change user role
                        int roleResult = UserController.UpdateUser(user);
                        // failed to change user role
                        if (roleResult < 0)
                        {
                            result.ResultCode = roleResult;
                            //
                            result.Succeed = false;

                            //
                            TaskManager.WriteError(ERROR_CHANGE_USR_ROLE_MSG);
                            TaskManager.WriteParameter(RESULT_CODE_PARAM, result.ResultCode);

                            // ROLLBACK CHANGES
                            RollbackOperation(result.ResultCode);

                            // EXIT
                            return(result);
                        }
                    }
                }
                // update plan status if necessary
                if (packageSvc.Status != ServiceStatus.Active)
                {
                    // change service status to active
                    packageSvc.Status = ServiceStatus.Active;
                    // put data into metabase
                    int svcResult = UpdateServiceInfo(packageSvc);

                    // error updating svc details
                    if (svcResult < 0)
                    {
                        result.ResultCode = svcResult;
                        //
                        result.Succeed = false;

                        // ROLLBACK CHANGES
                        RollbackOperation(packageSvc.PackageId);

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

                        // EXIT
                        return(result);
                    }
                }
                //
                SetOutboundParameters(context);
                // LOG INFO
                TaskManager.Write(PCKG_PROVISIONED_MSG);

                //
                result.Succeed = true;
            }
            catch (Exception ex)
            {
                //
                TaskManager.WriteError(ex);

                // ROLLBACK CHANGES
                RollbackOperation(packageSvc.PackageId);

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

            //
            return(result);
        }
		public GenericSvcResult CancelService(ProvisioningContext context)
		{
			GenericSvcResult result = new GenericSvcResult();
			//
			result.Succeed = true;
            //
            DomainNameSvc service = (DomainNameSvc)context.ServiceInfo;
            service.Status = ServiceStatus.Cancelled;
            //
            UpdateServiceInfo(service);
            //
            SetOutboundParameters(context);
			//
			return result;
		}
Exemple #20
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);
        }
Exemple #21
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);
        }
Exemple #22
0
        public GenericSvcResult CancelService(ProvisioningContext context)
        {
            GenericSvcResult result = new GenericSvcResult();

            //
            SaveObjectState(SERVICE_INFO, context.ServiceInfo);
            //
            SaveObjectState(CONSUMER_INFO, context.ConsumerInfo);

            // concretize service to be provisioned
            HostingPackageSvc packageSvc = (HostingPackageSvc)context.ServiceInfo;

            //
            try
            {
                //
                TaskManager.StartTask(SystemTasks.SOURCE_ECOMMERCE, SystemTasks.SVC_CANCEL);
                // LOG INFO
                TaskManager.Write(START_CANCELLATION_MSG);
                TaskManager.WriteParameter(CONTRACT_PARAM, context.ConsumerInfo[ContractAccount.USERNAME]);
                TaskManager.WriteParameter(SVC_PARAM, context.ServiceInfo.ServiceName);
                TaskManager.WriteParameter(SVC_ID_PARAM, context.ServiceInfo.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);
                }

                // cancel hosting package
                int apiResult = PackageController.ChangePackageStatus(packageSvc.PackageId,
                                                                      PackageStatus.Cancelled, false);

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

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

                    // EXIT
                    return(result);
                }

                // change service status to Cancelled
                packageSvc.Status = ServiceStatus.Cancelled;
                // put data into metabase
                int svcResult = UpdateServiceInfo(packageSvc);

                //
                if (svcResult < 0)
                {
                    result.ResultCode = svcResult;
                    //
                    result.Error = ERROR_SVC_UPDATE_MSG;
                    //
                    result.Succeed = false;

                    // ROLLBACK CHANGES
                    RollbackOperation(packageSvc.PackageId);

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

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

                // ROLLBACK CHANGES
                RollbackOperation(packageSvc.PackageId);

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

            //
            return(result);
        }
		public GenericSvcResult ActivateService(ProvisioningContext context)
		{
			GenericSvcResult result = new GenericSvcResult();

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

			// concretize service to be provisioned
			DomainNameSvc domainSvc = (DomainNameSvc)context.ServiceInfo;
			// concretize parent service
			HostingPackageSvc packageSvc = (HostingPackageSvc)context.ParentSvcInfo;

			try
			{
				// LOG INFO
                TaskManager.StartTask(SystemTasks.SOURCE_ECOMMERCE, SystemTasks.SVC_ACTIVATE);
				TaskManager.WriteParameter(CONTRACT_PARAM, domainSvc.ContractId);
				TaskManager.WriteParameter(SVC_PARAM, domainSvc.ServiceName);
				TaskManager.WriteParameter(SVC_ID_PARAM, domainSvc.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;
				}

				// 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;
				}

				// first of all - create internal domain in WebsitePanel
				if (domainSvc.Status == ServiceStatus.Ordered)
				{
					// create domain info object
					DomainInfo domain = ServerController.GetDomain(domainSvc.Fqdn);
					//
					if (domain != null)
						domainSvc.DomainId = domain.DomainId;
					//
					if (domain == null)
					{
						domain = new DomainInfo();
						domain.DomainName = domainSvc.Fqdn;
						domain.HostingAllowed = false;
						domain.PackageId = packageSvc.PackageId;
						// add internal domain
						domainSvc.DomainId = ServerController.AddDomain(domain);
						// check API result
						if (domainSvc.DomainId < 1)
						{
							// ASSEMBLE ERROR
							result.Succeed = false;
							// try to find corresponding error code->error message mapping
							if (ApiErrorCodesMap.ContainsKey(domainSvc.DomainId))
								result.Error = ApiErrorCodesMap[domainSvc.DomainId];
							else
								result.Error = ERROR_ADD_INTERNAL_DOMAIN;
							// copy result code
							result.ResultCode = domainSvc.DomainId;

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

							// EXIT
							return result;
						}
					}
				}

				// update nameservers only
				if (domainSvc["SPF_ACTION"] == "UPDATE_NS")
				{
					// remove service here...
					ServiceController.DeleteCustomerService(domainSvc.ServiceId);
					//
					result.Succeed = true;
					// EXIT
					return result;
				}
				
				// load registrar wrapper
				IDomainRegistrar registrar = (IDomainRegistrar)SystemPluginController.GetSystemPluginInstance(
					domainSvc.ContractId, domainSvc.PluginId, true);

				#region Commented operations
				// prepare consumer account information
				/*CommandParams cmdParams = PrepeareAccountParams(context.ConsumerInfo);
				// copy svc properties
				foreach (string keyName in domainSvc.GetAllKeys())
					cmdParams[keyName] = domainSvc[keyName];

				// check registrar requires sub-account to be created
				if (registrar.SubAccountRequired)
				{
					// 1. Load user's settings
					UserSettings userSettings = LoadUserSettings(context.ConsumerInfo.UserId, registrar.PluginName);
					// 2. Ensure user has account on registrar's side
					if (userSettings.SettingsArray == null || userSettings.SettingsArray.Length == 0)
					{
						// 3. Check account exists
						bool exists = registrar.CheckSubAccountExists(context.ConsumerInfo.Username, context.ConsumerInfo.Email);
						//
						AccountResult accResult = null;
						//
						if (!exists)
						{
							// 4. Create user account
							accResult = registrar.CreateSubAccount(cmdParams);
							// copy keys & values
							foreach (string keyName in accResult.AllKeys)
							{
								userSettings[keyName] = accResult[keyName];
							}
						}
						else
						{
							// 4a. Get sub-account info
							accResult = registrar.GetSubAccount(context.ConsumerInfo.Username, 
								context.ConsumerInfo.Email);
							//
							foreach (string keyName in accResult.AllKeys)
								userSettings[keyName] = accResult[keyName];
						}
						// 5. Update user settings
						int apiResult = UserController.UpdateUserSettings(userSettings);
						// check API result
						if (apiResult < 0)
						{
							// BUILD ERROR
							result.Error = ERROR_UPDATE_USR_SETTINGS_MSG;
							result.Succeed = false;
							result.ResultCode = apiResult;
							// LOG ERROR
							TaskManager.WriteError(result.Error);
							TaskManager.WriteParameter(RESULT_CODE_PARAM, result.ResultCode);
							// ROLLBACK
							RollbackOperation(domainSvc.DomainId);
							// EXIT
							return result;
						}
					}
					// copy registrar-specific data
					foreach (string[] pair in userSettings.SettingsArray)
					{
						// copy 2
						cmdParams[pair[0]] = pair[1];
					}
				}*/
				#endregion

				// load NS settings
				PackageSettings nsSettings = PackageController.GetPackageSettings(packageSvc.PackageId, PackageSettings.NAME_SERVERS);
				// build name servers array
				string[] nameServers = null;
				if (!String.IsNullOrEmpty(nsSettings[PackageSettings.NAME_SERVERS]))
					nameServers = nsSettings[PackageSettings.NAME_SERVERS].Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

				// register or renew domain
				if (domainSvc.Status == ServiceStatus.Ordered)
					// try to register domain
					registrar.RegisterDomain(domainSvc, context.ConsumerInfo, nameServers);
				else
					// try to renew domain
					registrar.RenewDomain(domainSvc, context.ConsumerInfo, nameServers);

				// change svc status to active
					domainSvc.Status = ServiceStatus.Active;
				// update service info
					int updResult = UpdateServiceInfo(domainSvc);
				// check update result for errors
					if (updResult < 0)
					{
						// BUILD ERROR
						result.ResultCode = updResult;
						result.Succeed = false;
						result.Error = ERROR_SVC_UPDATE_MSG;
						// LOG ERROR
						TaskManager.WriteError(result.Error);
						TaskManager.WriteParameter(RESULT_CODE_PARAM, result.ResultCode);
						// ROLLBACK
						RollbackOperation(domainSvc.DomainId);
						// EXIT
						return result;
					}
				//
				result.Succeed = true;
                //
                SetOutboundParameters(context);
			}
			catch (Exception ex)
			{
				// LOG ERROR
				TaskManager.WriteError(ex);
				result.Succeed = false;
				// ROLLBACK
				RollbackOperation(result.ResultCode);
			}
			finally
			{
				TaskManager.CompleteTask();
			}
			//
			return result;
		}
		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;
		}
		public bool CheckOperationClientPermissions(GenericSvcResult result)
		{
			// 1. Do security checks
			SecurityResult secResult = StorehouseController.CheckAccountIsAdminOrReseller();
			// ERROR
			if (!secResult.Success)
			{
				result.Succeed = false;
				result.ResultCode = secResult.ResultCode;
				//
				return false;
			}
			//
			return true;
		}
        public GenericSvcResult ActivateService(ProvisioningContext context)
        {
            GenericSvcResult result = new GenericSvcResult();

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

            // concretize service to be provisioned
            DomainNameSvc domainSvc = (DomainNameSvc)context.ServiceInfo;
            // concretize parent service
            HostingPackageSvc packageSvc = (HostingPackageSvc)context.ParentSvcInfo;

            try
            {
                // LOG INFO
                TaskManager.StartTask(SystemTasks.SOURCE_ECOMMERCE, SystemTasks.SVC_ACTIVATE);
                TaskManager.WriteParameter(CONTRACT_PARAM, domainSvc.ContractId);
                TaskManager.WriteParameter(SVC_PARAM, domainSvc.ServiceName);
                TaskManager.WriteParameter(SVC_ID_PARAM, domainSvc.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);
                }

                // 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);
                }

                // first of all - create internal domain in WebsitePanel
                if (domainSvc.Status == ServiceStatus.Ordered)
                {
                    // create domain info object
                    DomainInfo domain = ServerController.GetDomain(domainSvc.Fqdn);
                    //
                    if (domain != null)
                    {
                        domainSvc.DomainId = domain.DomainId;
                    }
                    //
                    if (domain == null)
                    {
                        domain                = new DomainInfo();
                        domain.DomainName     = domainSvc.Fqdn;
                        domain.HostingAllowed = false;
                        domain.PackageId      = packageSvc.PackageId;
                        // add internal domain
                        domainSvc.DomainId = ServerController.AddDomain(domain);
                        // check API result
                        if (domainSvc.DomainId < 1)
                        {
                            // ASSEMBLE ERROR
                            result.Succeed = false;
                            // try to find corresponding error code->error message mapping
                            if (ApiErrorCodesMap.ContainsKey(domainSvc.DomainId))
                            {
                                result.Error = ApiErrorCodesMap[domainSvc.DomainId];
                            }
                            else
                            {
                                result.Error = ERROR_ADD_INTERNAL_DOMAIN;
                            }
                            // copy result code
                            result.ResultCode = domainSvc.DomainId;

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

                            // EXIT
                            return(result);
                        }
                    }
                }

                // update nameservers only
                if (domainSvc["SPF_ACTION"] == "UPDATE_NS")
                {
                    // remove service here...
                    ServiceController.DeleteCustomerService(domainSvc.ServiceId);
                    //
                    result.Succeed = true;
                    // EXIT
                    return(result);
                }

                // load registrar wrapper
                IDomainRegistrar registrar = (IDomainRegistrar)SystemPluginController.GetSystemPluginInstance(
                    domainSvc.ContractId, domainSvc.PluginId, true);

                #region Commented operations
                // prepare consumer account information

                /*CommandParams cmdParams = PrepeareAccountParams(context.ConsumerInfo);
                 * // copy svc properties
                 * foreach (string keyName in domainSvc.GetAllKeys())
                 *      cmdParams[keyName] = domainSvc[keyName];
                 *
                 * // check registrar requires sub-account to be created
                 * if (registrar.SubAccountRequired)
                 * {
                 *      // 1. Load user's settings
                 *      UserSettings userSettings = LoadUserSettings(context.ConsumerInfo.UserId, registrar.PluginName);
                 *      // 2. Ensure user has account on registrar's side
                 *      if (userSettings.SettingsArray == null || userSettings.SettingsArray.Length == 0)
                 *      {
                 *              // 3. Check account exists
                 *              bool exists = registrar.CheckSubAccountExists(context.ConsumerInfo.Username, context.ConsumerInfo.Email);
                 *              //
                 *              AccountResult accResult = null;
                 *              //
                 *              if (!exists)
                 *              {
                 *                      // 4. Create user account
                 *                      accResult = registrar.CreateSubAccount(cmdParams);
                 *                      // copy keys & values
                 *                      foreach (string keyName in accResult.AllKeys)
                 *                      {
                 *                              userSettings[keyName] = accResult[keyName];
                 *                      }
                 *              }
                 *              else
                 *              {
                 *                      // 4a. Get sub-account info
                 *                      accResult = registrar.GetSubAccount(context.ConsumerInfo.Username,
                 *                              context.ConsumerInfo.Email);
                 *                      //
                 *                      foreach (string keyName in accResult.AllKeys)
                 *                              userSettings[keyName] = accResult[keyName];
                 *              }
                 *              // 5. Update user settings
                 *              int apiResult = UserController.UpdateUserSettings(userSettings);
                 *              // check API result
                 *              if (apiResult < 0)
                 *              {
                 *                      // BUILD ERROR
                 *                      result.Error = ERROR_UPDATE_USR_SETTINGS_MSG;
                 *                      result.Succeed = false;
                 *                      result.ResultCode = apiResult;
                 *                      // LOG ERROR
                 *                      TaskManager.WriteError(result.Error);
                 *                      TaskManager.WriteParameter(RESULT_CODE_PARAM, result.ResultCode);
                 *                      // ROLLBACK
                 *                      RollbackOperation(domainSvc.DomainId);
                 *                      // EXIT
                 *                      return result;
                 *              }
                 *      }
                 *      // copy registrar-specific data
                 *      foreach (string[] pair in userSettings.SettingsArray)
                 *      {
                 *              // copy 2
                 *              cmdParams[pair[0]] = pair[1];
                 *      }
                 * }*/
                #endregion

                // load NS settings
                PackageSettings nsSettings = PackageController.GetPackageSettings(packageSvc.PackageId, PackageSettings.NAME_SERVERS);
                // build name servers array
                string[] nameServers = null;
                if (!String.IsNullOrEmpty(nsSettings[PackageSettings.NAME_SERVERS]))
                {
                    nameServers = nsSettings[PackageSettings.NAME_SERVERS].Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                }

                // register or renew domain
                if (domainSvc.Status == ServiceStatus.Ordered)
                {
                    // try to register domain
                    registrar.RegisterDomain(domainSvc, context.ConsumerInfo, nameServers);
                }
                else
                {
                    // try to renew domain
                    registrar.RenewDomain(domainSvc, context.ConsumerInfo, nameServers);
                }

                // change svc status to active
                domainSvc.Status = ServiceStatus.Active;
                // update service info
                int updResult = UpdateServiceInfo(domainSvc);
                // check update result for errors
                if (updResult < 0)
                {
                    // BUILD ERROR
                    result.ResultCode = updResult;
                    result.Succeed    = false;
                    result.Error      = ERROR_SVC_UPDATE_MSG;
                    // LOG ERROR
                    TaskManager.WriteError(result.Error);
                    TaskManager.WriteParameter(RESULT_CODE_PARAM, result.ResultCode);
                    // ROLLBACK
                    RollbackOperation(domainSvc.DomainId);
                    // EXIT
                    return(result);
                }
                //
                result.Succeed = true;
                //
                SetOutboundParameters(context);
            }
            catch (Exception ex)
            {
                // LOG ERROR
                TaskManager.WriteError(ex);
                result.Succeed = false;
                // ROLLBACK
                RollbackOperation(result.ResultCode);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
            //
            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;
		}
		public GenericSvcResult ActivateService(int serviceId, bool sendEmail, bool logSvcUsage)
		{
            GenericSvcResult result = null;
			// load svc type
			ProductType svc_type = ServiceController.GetServiceItemType(serviceId);
			// 
			if (svc_type == null)
			{
				result = new GenericSvcResult();
				result.Succeed = true;
				return result;
			}
			// instantiate svc controller
			IServiceProvisioning controller = (IServiceProvisioning)Activator.CreateInstance(
				Type.GetType(svc_type.ProvisioningController));
			// create context
			ProvisioningContext context = controller.GetProvisioningContext(serviceId, sendEmail);
			// activate svc
			result = controller.ActivateService(context);
			// check result
			if (result.Succeed)
			{
				// log svc usage
				if (logSvcUsage)
					controller.LogServiceUsage(context);
			}
			//
			return result;
		}