예제 #1
0
        public void AddExample(ExampleModel example)
        {
            Validate(example);

            try
            {
                var possiblePackageServices = coreApi.FindServicesByPath(new ServiceSearchCriteria[] {
                    new ServiceSearchCriteria {
                        ParentService = null,
                        ServicePath   = csBaseServiceData.Path,
                        ServiceName   = csBaseServiceData.ServiceName
                    }
                }, null, accountId, "", true);
                var packageServices = PackageSelectHelper.FilterServicesToSelectedPackage(controller.RouteData, possiblePackageServices);

                var newService = coreApi.CreateService(exampleServiceData.ServiceName, packageServices.First(), accountId);
                SetServicePropertyValue(newService, "Name", example.Name);

                var addedService = coreApi.AddService(newService, packageServices.First(), accountId, null);
                example.LogicalID = addedService.logicalId;

                LogAdded(addedService, example);
            }
            catch (AtomiaServerSideValidationException e)
            {
                var error = e.Errors.First();
                throw new AtomiaServerSideValidationException(error.PropertyName, error.ErrorMessage);
            }
            catch (Exception e)
            {
                var errorMessage = String.Format(controller.LocalResource("Add", "CantAddExample"), example.Name, e.Message);
                throw new AtomiaServerSideValidationException("Name", errorMessage);
            }
        }
예제 #2
0
        public List <ExampleModel> FetchObjectsWithPaging(string search, string iDisplayStart, string iDisplayLength, int sortColumn, string sortDirection, out long total)
        {
            var examples = new List <ExampleModel>();

            total = 0;

            try
            {
                var serviceSearchCriteria = new ServiceSearchCriteria[] {
                    new ServiceSearchCriteria {
                        ParentService = null,
                        ServicePath   = exampleServiceData.Path,
                        ServiceName   = exampleServiceData.ServiceName
                    }
                };
                var searchDictionary = search.Length > 0
                    ? new Dictionary <string, string> {
                    { exampleServiceData.ServiceProperties["Name"], "%*" + search + "%*" }
                }
                    : null;
                var exampleServices = coreApi.FindServicesByPathWithPaging(
                    out total,
                    serviceSearchCriteria,
                    searchDictionary,
                    accountId,
                    exampleServiceData.ServiceProperties["Name"],
                    sortDirection.ToLower() == "asc",
                    Convert.ToInt32(iDisplayStart) / Convert.ToInt32(iDisplayLength),
                    Convert.ToInt32(iDisplayLength));

                exampleServices = PackageSelectHelper.FilterServicesToSelectedPackage(controller.RouteData, exampleServices);

                foreach (var exampleService in exampleServices)
                {
                    examples.Add(new ExampleModel {
                        LogicalID = exampleService.logicalId,
                        Name      = GetServicePropertyValue(exampleService, "Name"),
                        Status    = GetServicePropertyValue(exampleService, "Status")
                    });
                }
            }
            catch (Exception ex)
            {
                HostingControlPanelLogger.LogHostingControlPanelException(ex);
                total = 0;
            }

            return(examples);
        }
예제 #3
0
        private static ProvisioningService GetRootService(RouteData routeData)
        {
            var coreService = AtomiaServiceChannelManager.GetCoreService(false);
            var fetchedProvisioningDescriptionID = AtomiaServicesManager.FetchProvisioningDescriptionID(routeData.Values["accountID"].ToString());
            var fetchedRootFolderServiceData     = AtomiaServicesManager.FetchServiceData(
                "Hosting Complex Service",
                fetchedProvisioningDescriptionID,
                routeData.DataTokens["area"].ToString(),
                routeData.Values["controller"].ToString(),
                routeData.Values["action"].ToString());
            var serviceSearchCriteria = new[]
            {
                new ServiceSearchCriteria
                {
                    ParentService = null,
                    ServicePath   = fetchedRootFolderServiceData.Path,
                    ServiceName   = fetchedRootFolderServiceData.ServiceName
                }
            };
            var fetchedServices = coreService.FindServicesByPath(serviceSearchCriteria, null, routeData.Values["accountID"].ToString(), "", true);

            return(PackageSelectHelper.FilterServicesToSelectedPackage(routeData, fetchedServices).FirstOrDefault());
        }
예제 #4
0
        public void EditExample(ExampleModel example)
        {
            Validate(example);

            try
            {
                var serviceId     = example.LogicalID;
                var exampleBefore = FetchExample(serviceId);

                var possibleServices = coreApi.FindServicesByPath(new ServiceSearchCriteria[] { new ServiceSearchCriteria {
                                                                                                    ParentService = null,
                                                                                                    ServicePath   = exampleServiceData.Path,
                                                                                                    ServiceName   = exampleServiceData.ServiceName
                                                                                                } }, null, accountId, "", true);
                var services        = PackageSelectHelper.FilterServicesToSelectedPackage(controller.RouteData, possibleServices);
                var existingService = services.First(svc => svc.logicalId == serviceId);
                if (!services.Any(svc => svc.logicalId == serviceId))
                {
                    existingService = coreApi.GetServiceById(serviceId, accountId);
                }
                SetServicePropertyValue(existingService, "Name", example.Name);
                var editedService = coreApi.ModifyService(existingService, accountId);

                LogUpdated(exampleBefore, FetchExample(serviceId));
            }
            catch (AtomiaServerSideValidationException e)
            {
                var error = e.Errors.First();
                throw new AtomiaServerSideValidationException(error.PropertyName, error.ErrorMessage);
            }
            catch (Exception e)
            {
                var errorMessage = String.Format(controller.LocalResource("Edit", "CantEditExample"), example.Name, e.Message);
                throw new AtomiaServerSideValidationException("Name", errorMessage);
            }
        }