Ejemplo n.º 1
0
        public RequestFederationResponse RequestFederation(FederatedAPI.implementation.FederateRecord request)
        {
            RequestFederationResponse response = new RequestFederationResponse();
            List<FederateRecord> federates = mFederateRegister.GetAllFederateRecords();

            //check for collisions in the names of the services
            foreach (FederateRecord fr in federates)
            {
                if (fr.RESTAPI == request.RESTAPI && fr.ActivationState != FederateState.Delisted)
                {
                    response.message = "This URL is already registered to " + fr.OrginizationName + ". Please contact " + fr.OrganizationPOC + " at " + fr.OrganizationPOCEmail;
                    response.status = (int)RequestStatus.AlreadyRegistered; ;
                    return response;
                }
            }

            //check for collisions in the namespace prefix
            foreach (FederateRecord fr in federates)
            {
                if (fr.namespacePrefix == request.namespacePrefix && fr.ActivationState != FederateState.Delisted)
                {
                    response.message = "This prefix is already registered to " + fr.OrginizationName + ". Please choose a different prefix and try again";
                    response.status = (int)RequestStatus.PrefixCollision; ;
                    return response;
                }
                if (fr.namespacePrefix == request.namespacePrefix && fr.ActivationState == FederateState.Delisted && (fr.OrganizationPOCEmail != request.OrganizationPOCEmail || fr.OrganizationPOCPassword != request.OrganizationPOCPassword || fr.OrginizationName != request.OrginizationName))
                {
                    response.message = "This prefix is inactive but reserved for " + fr.OrginizationName + ". If you are the POC for "+ fr.OrginizationName + " please use your original Federation email and password to relist under this namespace.";
                    response.status = (int)RequestStatus.PrefixCollision; ;
                    return response;
                }
            }

            //Check that the json api works
            try
            {
                System.Net.WebClient wc = GetWebClient();

                try
                {
                    wc.DownloadString(request.RESTAPI + "/Search/test/json?ID=00-00-00");
                }
                catch(Exception ex)
                {
                    response.status = (int)RequestStatus.BadURL;
                    response.message = "Could not contact the API. Your API must be online and visible to register with the federation.";
                    return response;
                }
            }
            catch(SystemException e)
            {
                response.status = (int)RequestStatus.BadURL;
                response.message = "Could not contact the API. Your API must be online and visible to register with the federation.";
                return response;
            }

            //Create the record
            request.ActivationState = FederateState.Unapproved;
            mFederateRegister.CreateFederateRecord(request);

            response.assignedPrefix = request.namespacePrefix;
            response.status = (int)RequestStatus.RequestAccepted;
            response.message = "You have been assigned the prefix: " + response.assignedPrefix + "<br/>You will receive an email when the administrator enables this account<br/>status: " + response.status.ToString();
            return response;
        }
Ejemplo n.º 2
0
        public RequestFederationResponse RequestFederation(FederatedAPI.implementation.FederateRecord request)
        {
            RequestFederationResponse response  = new RequestFederationResponse();
            List <FederateRecord>     federates = mFederateRegister.GetAllFederateRecords();

            //check for collisions in the names of the services
            foreach (FederateRecord fr in federates)
            {
                if (fr.RESTAPI == request.RESTAPI && fr.ActivationState != FederateState.Delisted)
                {
                    response.message = "This URL is already registered to " + fr.OrginizationName + ". Please contact " + fr.OrganizationPOC + " at " + fr.OrganizationPOCEmail;
                    response.status  = (int)RequestStatus.AlreadyRegistered;;
                    return(response);
                }
            }

            //check for collisions in the namespace prefix
            foreach (FederateRecord fr in federates)
            {
                if (fr.namespacePrefix == request.namespacePrefix && fr.ActivationState != FederateState.Delisted)
                {
                    response.message = "This prefix is already registered to " + fr.OrginizationName + ". Please choose a different prefix and try again";
                    response.status  = (int)RequestStatus.PrefixCollision;;
                    return(response);
                }
                if (fr.namespacePrefix == request.namespacePrefix && fr.ActivationState == FederateState.Delisted && (fr.OrganizationPOCEmail != request.OrganizationPOCEmail || fr.OrganizationPOCPassword != request.OrganizationPOCPassword || fr.OrginizationName != request.OrginizationName))
                {
                    response.message = "This prefix is inactive but reserved for " + fr.OrginizationName + ". If you are the POC for " + fr.OrginizationName + " please use your original Federation email and password to relist under this namespace.";
                    response.status  = (int)RequestStatus.PrefixCollision;;
                    return(response);
                }
            }

            //Check that the json api works
            try
            {
                System.Net.WebClient wc = GetWebClient();
                try
                {
                    wc.DownloadString(request.RESTAPI + "/Search/test/json?ID=00-00-00");
                }
                catch (Exception ex)
                {
                    response.status  = (int)RequestStatus.BadURL;
                    response.message = "Could not contact the API. Your API must be online and visible to register with the federation.";
                    return(response);
                }
            }
            catch (SystemException e)
            {
                response.status  = (int)RequestStatus.BadURL;
                response.message = "Could not contact the API. Your API must be online and visible to register with the federation.";
                return(response);
            }


            //Create the record
            request.ActivationState = FederateState.Unapproved;
            mFederateRegister.CreateFederateRecord(request);

            response.assignedPrefix = request.namespacePrefix;
            response.status         = (int)RequestStatus.RequestAccepted;
            response.message        = "You have been assigned the prefix: " + response.assignedPrefix + "<br/>You will receive an email when the administrator enables this account<br/>status: " + response.status.ToString();
            return(response);
        }