コード例 #1
0
        /// <summary>
        ///     Select a project. Subsequent queries will be executed in the context of this project.
        /// </summary>
        /// <param name="projectGuid"> Guid of the project to select </param>
        public void SelectProject(Guid projectGuid)
        {
            if (SelectedProjectGuid.Equals(projectGuid))
            {
                return;
            }
            string       result;
            RQLException exception = null;

            try
            {
                result =
                    ExecuteRQLRaw(
                        string.Format(RQL_SELECT_PROJECT, _loginGuidStr, projectGuid.ToRQLString().ToUpperInvariant()),
                        RQL.IODataFormat.LogonGuidOnly);
            } catch (RQLException e)
            {
                exception = e;
                result    = e.Response;
            }

            var xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(result);
            XmlNodeList xmlNodes = xmlDoc.GetElementsByTagName("SERVER");

            if (xmlNodes.Count > 0)
            {
                SessionKey          = ((XmlElement)xmlNodes[0]).GetAttributeValue("key");
                SelectedProjectGuid = projectGuid;
                return;
            }

            throw new SmartAPIException(ServerLogin,
                                        String.Format("Couldn't select project {0}", projectGuid.ToRQLString()),
                                        exception);
        }
コード例 #2
0
 public MissingPrivilegesException(RQLException exception)
     : base(exception)
 {
 }
コード例 #3
0
        /// <summary>
        ///     Send RQL statement to CMS server and return result.
        /// </summary>
        /// <param name="rqlQuery"> Query to send to CMS server </param>
        /// <param name="debugRQLQuery"> Query to save in log file (this is used to hide passwords in the log files) </param>
        /// <exception cref="RedDotConnectionException">CMS Server not found or couldn't establish connection</exception>
        /// <returns> Result of RQL query </returns>
        private string SendRQLToServer(string rqlQuery, string debugRQLQuery = null)
        {
            try
            {
                LOG.DebugFormat("Sending RQL [{0}]: {1}", ServerLogin.Name, debugRQLQuery ?? rqlQuery);

                object error      = "x";
                object resultInfo = "";
                var    binding    = new BasicHttpBinding();

                var isUsingHttps = ServerLogin.Address.Scheme.ToLowerInvariant() == "https";
                if (isUsingHttps)
                {
                    binding.Security.Mode = BasicHttpSecurityMode.Transport;
                }
                binding.ReaderQuotas.MaxStringContentLength = 2097152 * 10; //20MB
                binding.ReaderQuotas.MaxArrayLength         = 2097152 * 10; //20mb
                binding.MaxReceivedMessageSize = 2097152 * 10;              //20mb
                binding.ReceiveTimeout         = TimeSpan.FromMinutes(10);
                binding.SendTimeout            = TimeSpan.FromMinutes(10);

                if (ServerLogin.WindowsAuthentication != null)
                {
                    binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
                    binding.Security.Mode = isUsingHttps ? BasicHttpSecurityMode.TransportWithMessageCredential : BasicHttpSecurityMode.TransportCredentialOnly;
                }

                var add = new EndpointAddress(CmsServerConnectionUrl);

                try
                {
                    var client = new RqlWebServiceClient(binding, add);
                    if (ServerLogin.WindowsAuthentication != null)
                    {
                        client.ClientCredentials.Windows.ClientCredential = ServerLogin.WindowsAuthentication;
                        //client.ClientCredentials.Windows.AllowNtlm = true;
                        client.ClientCredentials.Windows.AllowedImpersonationLevel =
                            TokenImpersonationLevel.Impersonation;
                    }
                    //var channel = client.ChannelFactory.CreateChannel();
                    //var res = channel.Execute(new ExecuteRequest(rqlQuery, error, resultInfo));
                    //var result = res.Result;

                    string result   = client.Execute(rqlQuery, ref error, ref resultInfo);
                    string errorStr = (error ?? "").ToString();
                    if (!string.IsNullOrEmpty(errorStr))
                    {
                        var exception = new RQLException(ServerLogin.Name, errorStr, result);
                        if (exception.ErrorCode == ErrorCode.NoRight || exception.ErrorCode == ErrorCode.RDError110)
                        {
                            throw new MissingPrivilegesException(exception);
                        }
                        throw exception;
                    }
                    LOG.DebugFormat("Received RQL [{0}]: {1}", ServerLogin.Name, result);
                    return(result);
                } catch (Exception e)
                {
                    string msg = ExtractMessagesWithInnerExceptions(e);
                    LOG.Error(msg);
                    LOG.Debug(e.StackTrace);
                    throw;
                }
            } catch (EndpointNotFoundException e)
            {
                LOG.ErrorFormat("Server not found: {0}", CmsServerConnectionUrl);
                throw new RedDotConnectionException(RedDotConnectionException.FailureTypes.ServerNotFound,
                                                    string.Format(@"Server ""{0}"" not found", CmsServerConnectionUrl),
                                                    e);
            }
        }
コード例 #4
0
 public MissingPrivilegesException(RQLException exception) : base(exception)
 {
 }