/// <summary>
        /// Create a copy of a dictionary of ProvisionedZone objects.
        /// </summary>
        /// <param name="sourceProvisionedZones">Dictionary of ProvisionedZone objects to copy.</param>
        /// <returns>New copy of the dictionary of ProvisionedZone objects.</returns>
        private IDictionary <string, ProvisionedZone> CopyProvisionedZones(IDictionary <string, ProvisionedZone> sourceProvisionedZones)
        {
            IDictionary <string, ProvisionedZone> destinationProvisionedZones = null;

            if (sourceProvisionedZones != null)
            {
                destinationProvisionedZones = new Dictionary <string, ProvisionedZone>();

                foreach (string key in sourceProvisionedZones.Keys)
                {
                    ProvisionedZone sourceProvisionedZone;
                    sourceProvisionedZones.TryGetValue(key, out sourceProvisionedZone);
                    ProvisionedZone destinationProvisionedZone = new ProvisionedZone {
                        SifId = sourceProvisionedZone.SifId
                    };

                    if (sourceProvisionedZone.Services != null)
                    {
                        destinationProvisionedZone.Services = CopyServices(sourceProvisionedZone.Services);
                    }

                    destinationProvisionedZones.Add(key, destinationProvisionedZone);
                }
            }

            return(destinationProvisionedZones);
        }
        /// <summary>
        /// Create a copy of a dictionary of ProvisionedZone objects.
        /// </summary>
        /// <param name="sourceZones">Dictionary of ProvisionedZone objects to copy.</param>
        /// <returns>New copy of the dictionary of ProvisionedZone objects if not null; null otherwise.</returns>
        private static IDictionary <string, ProvisionedZone> CopyProvisionedZones(
            IDictionary <string, ProvisionedZone> sourceZones)
        {
            if (sourceZones == null)
            {
                return(null);
            }

            var destinationZones = new Dictionary <string, ProvisionedZone>();

            foreach (string key in sourceZones.Keys)
            {
                if (sourceZones.TryGetValue(key, out ProvisionedZone sourceZone))
                {
                    var destinationZone = new ProvisionedZone {
                        SifId = sourceZone.SifId
                    };

                    if (sourceZone.Services != null)
                    {
                        destinationZone.Services = CopyServices(sourceZone.Services);
                    }

                    destinationZones.Add(key, destinationZone);
                }
            }

            return(destinationZones);
        }
示例#3
0
        /// <summary>
        /// Retrieve the rights for a service in a given zone.
        /// </summary>
        /// <param name="serviceType">The service type used for the request <see cref="ServiceType"/> for valid types.</param>
        /// <param name="serviceName">The service name.</param>
        /// <param name="zone">The zone to retrieve the rights for.</param>
        /// <returns>An array of declared rights</returns>
        private static IDictionary <string, Right> GetRightsForService(string serviceType, string serviceName,
                                                                       ProvisionedZone zone)
        {
            Model.Infrastructure.Service service =
                (from Model.Infrastructure.Service s in zone.Services
                 where s.Type.Equals(serviceType) && s.Name.Equals(serviceName)
                 select s).FirstOrDefault();

            return(service?.Rights);
        }
示例#4
0
        /// <summary>
        /// Internal method to retrieve the rights for a service in a given zone.
        /// </summary>
        /// <param name="serviceName">The service name to look for</param>
        /// <param name="zone">The zone to retrieve the rights for</param>
        /// <returns>An array of declared rights</returns>
        private IDictionary <string, Right> getRights(string serviceName, ProvisionedZone zone)
        {
            Model.Infrastructure.Service service = (from Model.Infrastructure.Service s in zone.Services
                                                    where s.Type.Equals(ServiceType.FUNCTIONAL.ToString()) &&
                                                    s.Name.Equals(serviceName)
                                                    select s).FirstOrDefault();

            if (service == null)
            {
                string msg = "No Functional Service called " + serviceName + " found in Environment.";
                log.Debug(msg);
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, msg));
            }

            log.Debug("Found access rights for " + service.Type + " service " + service.Name);
            return(service.Rights);
        }
示例#5
0
        private IDictionary <string, ProvisionedZone> CopyProvisionedZones(IDictionary <string, ProvisionedZone> sourceProvisionedZones)
        {
            IDictionary <string, ProvisionedZone> destinationProvisionedZones = new Dictionary <string, ProvisionedZone>();

            if (sourceProvisionedZones != null && sourceProvisionedZones.Count > 0)
            {
                foreach (ProvisionedZone sourceProvisionedZone in sourceProvisionedZones.Values)
                {
                    ProvisionedZone destinationProvisionedZone = new ProvisionedZone {
                        SifId = sourceProvisionedZone.SifId
                    };
                    ICollection <Model.Infrastructure.Service> services = CopyServices(sourceProvisionedZone.Services);

                    if (services.Count > 0)
                    {
                        destinationProvisionedZone.Services = services;
                    }

                    destinationProvisionedZones.Add(destinationProvisionedZone.SifId, destinationProvisionedZone);
                }
            }

            return(destinationProvisionedZones);
        }
 public static Model.Infrastructure.Service GetService(ProvisionedZone zone, string name, ServiceType type)
 {
     return((from service in zone.Services
             where service.Type.Equals(type.ToString()) && service.Name.Equals(name)
             select service).FirstOrDefault());
 }
        public static Environment CreateEnvironmentResponse()
        {
            InfrastructureService environmentURL = new InfrastructureService { Name = InfrastructureServiceNames.environment, Value = "http://rest3api.sifassociation.org/api/solutions/auTestSolution/environments/5b72f2d4-7a83-4297-a71f-8b5fb26cbf14" };
            InfrastructureService provisionRequestsURL = new InfrastructureService { Name = InfrastructureServiceNames.provisionRequests, Value = "http://rest3api.sifassociation.org/api/solutions/auTestSolution/provisionRequests" };
            InfrastructureService queuesURL = new InfrastructureService { Name = InfrastructureServiceNames.queues, Value = "http://rest3api.sifassociation.org/api/solutions/auTestSolution/queues" };
            InfrastructureService requestsConnectorURL = new InfrastructureService { Name = InfrastructureServiceNames.requestsConnector, Value = "http://rest3api.sifassociation.org/api/solutions/auTestSolution/requestsConnector" };
            InfrastructureService subscriptionsURL = new InfrastructureService { Name = InfrastructureServiceNames.subscriptions, Value = "http://rest3api.sifassociation.org/api/solutions/auTestSolution/subscriptions" };
            IDictionary<InfrastructureServiceNames, InfrastructureService> infrastructureServices = new Dictionary<InfrastructureServiceNames, InfrastructureService>
            {
                { environmentURL.Name, environmentURL },
                { provisionRequestsURL.Name, provisionRequestsURL },
                { queuesURL.Name, queuesURL },
                { requestsConnectorURL.Name, requestsConnectorURL },
                { subscriptionsURL.Name, subscriptionsURL }
            };

            Right adminRight = new Right { Type = "ADMIN", Value = "APPROVED" };
            Right createRight = new Right { Type = "CREATE", Value = "APPROVED" };
            IDictionary<string, Right> rights = new Dictionary<string, Right> { { adminRight.Type, adminRight } };

            Infrastructure.Service studentPersonalsService = new Infrastructure.Service
            {
                ContextId = "DEFAULT",
                Name = "StudentPersonals",
                Rights = rights,
                Type = "OBJECT"
            };
            Infrastructure.Service schoolInfosService = new Infrastructure.Service
            {
                ContextId = "DEFAULT",
                Name = "SchoolInfos",
                Rights = rights,
                Type = "OBJECT"
            };
            ICollection<Infrastructure.Service> services = new SortedSet<Infrastructure.Service>
            {
                studentPersonalsService, schoolInfosService
            };

            ProvisionedZone schoolZone = new ProvisionedZone { SifId = "auSchoolTestingZone", Services = services };
            ProvisionedZone studentZone = new ProvisionedZone { SifId = "auStudentTestingZone", Services = services };

            IDictionary<string, ProvisionedZone> provisionedZones = new SortedDictionary<string, ProvisionedZone> { { schoolZone.SifId, schoolZone }, { studentZone.SifId, studentZone } };

            Environment environmentResponse = CreateEnvironmentRequest();
            environmentResponse.InfrastructureServices = infrastructureServices;
            environmentResponse.ProvisionedZones = provisionedZones;

            return environmentResponse;
        }