public void Search1Delegate(object frpair)
        {
            FederateRecord      fr      = ((SearchStart)frpair).fed;
            List <SearchResult> results = ((SearchStart)frpair).results;
            string terms = ((SearchStart)frpair).terms;

            System.Net.WebClient wc = GetWebClient();
            System.Runtime.Serialization.DataContractSerializer xmls = new System.Runtime.Serialization.DataContractSerializer(typeof(List <SearchResult>));


            if (fr.ActivationState == FederateState.Active && fr.AllowFederatedSearch == true)
            {
                try
                {
                    byte[] data = wc.DownloadData(fr.RESTAPI + "/Search/" + terms + "/xml?ID=00-00-00");
                    List <SearchResult> fed_results = (List <SearchResult>)xmls.ReadObject(new MemoryStream(data));

                    lock (((System.Collections.IList)results).SyncRoot)
                    {
                        foreach (SearchResult sr in fed_results)
                        {
                            results.Add(sr);
                        }
                    }
                }
                catch (System.Exception e)
                {
                    // throw e;
                    fr.ActivationState = FederateState.Offline;
                    mFederateRegister.UpdateFederateRecord(fr);
                    return;
                }
            }
        }
Esempio n. 2
0
        public FederateRecord CreateFederateRecord(FederateRecord fd)
        {
            if (CheckConnection())
            {
                using (var command = mConnection.CreateCommand())
                {
                    command.CommandText = "{CALL CreateFederateRecord(?,?,?,?,?,?,?,?,?,?,?)}";
                    command.CommandType = System.Data.CommandType.StoredProcedure;

                    command.Parameters.AddWithValue("newPrefix", fd.namespacePrefix);
                    command.Parameters.AddWithValue("newRESTAPI", fd.RESTAPI);
                    command.Parameters.AddWithValue("newSOAPAPI", fd.SOAPAPI);
                    command.Parameters.AddWithValue("newOrganizationName", fd.OrginizationName);
                    command.Parameters.AddWithValue("newOrganizationURL", fd.OrganizationURL);
                    command.Parameters.AddWithValue("newOrganizationPOC", fd.OrganizationPOC);
                    command.Parameters.AddWithValue("newOrganizationPOCEmail", fd.OrganizationPOCEmail);
                    command.Parameters.AddWithValue("newOrganizationPOCPassword", fd.OrganizationPOCPassword);
                    command.Parameters.AddWithValue("newActivationState", fd.ActivationState);
                    command.Parameters.AddWithValue("newAllowFederatedSearch", fd.AllowFederatedSearch);
                    command.Parameters.AddWithValue("newAllowFederatedDownload", fd.AllowFederatedDownload);

                    command.ExecuteScalar();

                }
            }
            else
            {
                throw( new SystemException("Could not connect to Federate Register Database"));
            }
            mConnection.Close();
            return fd;
        }
        public string GetRedirectAddressModelAdvanced(APIType api, string pid, string format, string options)
        {
            string         fednamespace = GetPrefixFromPid(pid);
            FederateRecord fr           = mFederateRegister.GetFederateRecord(fednamespace);

            if (fr == null)
            {
                throw new System.Net.WebException("The prefix for this model is not recognized by the federation");
            }

            if (fr.ActivationState == FederateState.Unapproved)
            {
                throw new System.Net.WebException("The account for this namespace is waiting to be approved. Please visit <a href=\"" + fr.OrganizationURL + "\">" + fr.OrganizationURL + "</a> for more information.");
            }
            if (fr.AllowFederatedDownload != true)
            {
                throw new System.Net.WebException("The account for this namespace is does not allow downloading through the federation. Please visit <a href=\"" + fr.OrganizationURL + "\">" + fr.OrganizationURL + "</a> for more information.");
            }
            if (fr.ActivationState == FederateState.Active && fr.AllowFederatedDownload == true)
            {
                string apibase = "";

                if (api == APIType.REST)
                {
                    apibase = fr.RESTAPI;
                }

                return(apibase + "/" + pid + "/Model/" + format + "/" + options);
            }
            //"should never reach here"
            return(fr.OrganizationURL);
        }
Esempio n. 4
0
        public void UpdateFederateRecord(FederateRecord fd)
        {
            if (CheckConnection())
            {
                using (var command = mConnection.CreateCommand())
                {
                    command.CommandText = "{CALL UpdateFederateRecord(?,?,?,?,?,?,?,?,?,?,?)}";
                    command.CommandType = System.Data.CommandType.StoredProcedure;

                    command.Parameters.AddWithValue("newPrefix", fd.namespacePrefix);
                    command.Parameters.AddWithValue("newRESTAPI", fd.RESTAPI);
                    command.Parameters.AddWithValue("newSOAPAPI", fd.SOAPAPI);
                    command.Parameters.AddWithValue("newOrganizationName", fd.OrginizationName);
                    command.Parameters.AddWithValue("newOrganizationURL", fd.OrganizationURL);
                    command.Parameters.AddWithValue("newOrganizationPOC", fd.OrganizationPOC);
                    command.Parameters.AddWithValue("newOrganizationPOCEmail", fd.OrganizationPOCEmail);
                    command.Parameters.AddWithValue("newOrganizationPOCPassword", fd.OrganizationPOCPassword);
                    command.Parameters.AddWithValue("newActivationState", fd.ActivationState);
                    command.Parameters.AddWithValue("newAllowFederatedSearch", fd.AllowFederatedSearch);
                    command.Parameters.AddWithValue("newAllowFederatedDownload", fd.AllowFederatedDownload);

                    command.ExecuteScalar();
                }
            }
            else
            {
                throw(new SystemException("Could not connect to Federate Register Database"));
            }
            mConnection.Close();
        }
Esempio n. 5
0
        public List <FederateRecord> GetAllFederateRecords()
        {
            List <FederateRecord> results = new List <FederateRecord>();

            if (CheckConnection())
            {
                using (var command = mConnection.CreateCommand())
                {
                    command.CommandText = "{CALL GetAllFederateRecords()}";
                    command.CommandType = System.Data.CommandType.StoredProcedure;

                    using (var resultSet = command.ExecuteReader())
                    {
                        while (resultSet.Read())
                        {
                            FederateRecord fd = new FederateRecord();
                            fd.RESTAPI = resultSet["RESTAPI"].ToString();
                            fd.SOAPAPI = resultSet["SOAPAPI"].ToString();

                            fd.namespacePrefix = resultSet["prefix"].ToString();

                            fd.OrginizationName        = resultSet["OrganizationName"].ToString();
                            fd.OrganizationURL         = resultSet["OrganizationURL"].ToString();
                            fd.OrganizationPOC         = resultSet["OrganizationPOC"].ToString();
                            fd.OrganizationPOCEmail    = resultSet["OrganizationPOCEmail"].ToString();
                            fd.OrganizationPOCPassword = resultSet["OrganizationPOCPassword"].ToString();
                            fd.ActivationState         = (FederateState)(System.Convert.ToInt16(resultSet["ActivationState"].ToString()));

                            if (resultSet["AllowFederatedSearch"].ToString() == "1")
                            {
                                fd.AllowFederatedSearch = true;
                            }
                            if (resultSet["AllowFederatedDownload"].ToString() == "1")
                            {
                                fd.AllowFederatedDownload = true;
                            }

                            results.Add(fd);
                        }
                    }
                }
            }
            else
            {
                throw (new SystemException("Could not connect to Federate Register Database"));
            }
            mConnection.Close();
            return(results);
        }
        public FederatedAPI.implementation.ApproveFederateResponse ApproveFederate(FederatedAPI.implementation.ApproveFederateRequest request)
        {
            ApproveFederateResponse response = new ApproveFederateResponse();

            if (request.OrganizationPOCEmail != AdminUsername)
            {
                response.message = "Only the Federation Admin may approve this federate.";
                return(response);
            }
            if (request.OrganizationPOCPassword != AdminPassword)
            {
                response.message = "Incorrect Federation Admin password.";
                return(response);
            }
            FederateRecord f = mFederateRegister.GetFederateRecord(request.NamespacePrefix);

            f.ActivationState = FederateState.Active;
            mFederateRegister.UpdateFederateRecord(f);
            response.message = "The federate has been activated";
            return(response);
        }
        public string GetRedirectAddress(string function, APIType api, string pid)
        {
            pid = pid.Replace('_', ':');
            string         fednamespace = GetPrefixFromPid(pid);
            FederateRecord fr           = mFederateRegister.GetFederateRecord(fednamespace);

            if (fr == null)
            {
                throw new System.Net.WebException("The prefix for this model is not recognized by the federation");
            }

            if (fr.ActivationState == FederateState.Unapproved)
            {
                throw new System.Net.WebException("The account for this namespace is waiting to be approved. Please visit <a href=\"" + fr.OrganizationURL + "\">" + fr.OrganizationURL + "</a> for more information.");
            }
            if (fr.AllowFederatedSearch != true)
            {
                throw new System.Net.WebException("The account for this namespace is does not allow searching or downloading metadata through the federation. Please visit <a href=\"" + fr.OrganizationURL + "\">" + fr.OrganizationURL + "</a> for more information.");
            }

            if (fr.ActivationState == FederateState.Active && fr.AllowFederatedSearch == true)
            {
                string apibase = "";

                if (api == APIType.REST)
                {
                    apibase = fr.RESTAPI;
                }


                return(apibase + "/" + pid + "/" + function);
            }
            else
            {
                return(fr.OrganizationURL);
            }
        }
Esempio n. 8
0
        public FederateRecord GetFederateRecord(string prefix)
        {
            FederateRecord fd = null;
            if (CheckConnection())
            {
                using (var command = mConnection.CreateCommand())
                {
                    command.CommandText = "{CALL GetFederateRecord(?)}";
                    command.CommandType = System.Data.CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("newprefix",prefix);
                    using (var resultSet = command.ExecuteReader())
                    {
                        while (resultSet.Read())
                        {
                            fd = new FederateRecord();
                            fd.RESTAPI = resultSet["RESTAPI"].ToString();
                            fd.SOAPAPI = resultSet["SOAPAPI"].ToString();
                            fd.namespacePrefix = resultSet["prefix"].ToString();

                            fd.OrginizationName = resultSet["OrganizationName"].ToString();
                            fd.OrganizationURL = resultSet["OrganizationURL"].ToString();
                            fd.OrganizationPOC = resultSet["OrganizationPOC"].ToString();
                            fd.OrganizationPOCEmail = resultSet["OrganizationPOCEmail"].ToString();
                            fd.OrganizationPOCPassword = resultSet["OrganizationPOCPassword"].ToString();
                            fd.ActivationState = (FederateState)(System.Convert.ToInt16(resultSet["ActivationState"].ToString()));

                            if (resultSet["AllowFederatedSearch"].ToString() == "1")
                                fd.AllowFederatedSearch = true;
                            if (resultSet["AllowFederatedDownload"].ToString() == "1")
                                fd.AllowFederatedDownload = true;
                        }
                    }
                }
            }
            else
            {
                throw (new SystemException("Could not connect to Federate Register Database"));
            }
            mConnection.Close();
            return fd;
        }
        public ModifyFederationResponse SetFederateState(ModifyFederationRequest request, FederateState state)
        {
            ModifyFederationResponse response = new ModifyFederationResponse();

            response.status  = -1;
            response.message = "Not implemented";



            //check for collisions in the names of the services
            FederateRecord fr = mFederateRegister.GetFederateRecord(request.NamespacePrefix);

            if (fr.namespacePrefix == request.NamespacePrefix || request.NamespacePrefix == AdminUsername)
            {
                if ((fr.OrganizationPOCEmail == request.OrganizationPOCEmail && fr.OrganizationPOCPassword == request.OrganizationPOCPassword) ||
                    request.OrganizationPOCEmail == AdminUsername && request.OrganizationPOCPassword == AdminPassword)
                {
                    if (state == FederateState.Delisted)
                    {
                        if (fr.ActivationState == FederateState.Delisted)
                        {
                            response.message = "Federate at " + fr.RESTAPI + " has already been delisted. Please contact the administrator if you would like to re-enable the account.";
                            return(response);
                        }
                        else
                        {
                            fr.ActivationState = FederateState.Delisted;
                            mFederateRegister.UpdateFederateRecord(fr);
                            response.message = "Federate at " + fr.RESTAPI + " has been delisted. The namespace " + fr.namespacePrefix + " will be reserved for this account in the future.";
                            return(response);
                        }
                    }
                    if (state == FederateState.Active)
                    {
                        if (fr.ActivationState == FederateState.Active)
                        {
                            response.message = "Federate at " + fr.RESTAPI + " is already active.";
                            return(response);
                        }
                        else if (fr.ActivationState == FederateState.Offline)
                        {
                            fr.ActivationState = FederateState.Active;
                            mFederateRegister.UpdateFederateRecord(fr);
                            response.message = "Federate at " + fr.RESTAPI + " has been set as online.";
                            return(response);
                        }
                        else
                        {
                            response.message = "Federate at " + fr.RESTAPI + " is awaiting admin approval, and cannot be set as online";
                            return(response);
                        }
                    }
                    if (state == FederateState.Offline)
                    {
                        if (fr.ActivationState == FederateState.Offline)
                        {
                            response.message = "Federate at " + fr.RESTAPI + " is already offline.";
                            return(response);
                        }
                        else if (fr.ActivationState == FederateState.Active)
                        {
                            fr.ActivationState = FederateState.Offline;
                            mFederateRegister.UpdateFederateRecord(fr);
                            response.message = "Federate at " + fr.RESTAPI + " has been set as offline.";
                            return(response);
                        }
                        else
                        {
                            response.message = "Federate at " + fr.RESTAPI + " is awaiting admin approval, and cannot be set as offline";
                            return(response);
                        }
                    }
                }
                else
                {
                    response.message = "Incorrect Password";
                    return(response);
                }
            }
            else
            {
                response.message = "Wrong user for this namespace";
                return(response);
            }



            response.message = "Namespace not found";
            return(response);
        }