public QueryDesc getQueryDesc()
        {
            if (queryDesc != null)
            {
                return(queryDesc);
            }

            if (IsCorrelation)
            {
                return(getCorrelationQueryDesc());
            }
            WebRequest webRequest;

            if (QueryId == null)
            {
                webRequest        = createWebRequest("/api/v2/query");
                webRequest.Method = "POST";
                QueryPost queryPost = new QueryPost();
                queryPost.query = Query;
                DataContractJsonSerializer qser = new DataContractJsonSerializer(queryPost.GetType());
                qser.WriteObject(webRequest.GetRequestStream(), queryPost);
                webRequest.ContentType = "application/json";
            }
            else
            {
                String path = String.Format("/api/v2/query/" + QueryId + "/details");
                webRequest        = createWebRequest(path);
                webRequest.Method = "GET";
            }
            WebResponse myWebResponse;

            try
            {
                myWebResponse = webRequest.GetResponse();
            }
            catch (WebException we)
            {
                myWebResponse = we.Response;
                string replyExcep = "unspecified error";
                if (myWebResponse != null && myWebResponse.GetResponseStream() != null)
                {
                    StreamReader readerExcep = new StreamReader(myWebResponse.GetResponseStream());
                    replyExcep = readerExcep.ReadToEnd();
                }

                throw new Exception("Error while executing query: " + replyExcep);
            }
            StreamReader reader = new StreamReader(myWebResponse.GetResponseStream());
            string       reply  = reader.ReadToEnd();
            MemoryStream ms     = new MemoryStream(Encoding.UTF8.GetBytes(reply));

            queryDesc = new QueryDesc();
            DataContractJsonSerializer ser = new DataContractJsonSerializer(queryDesc.GetType());

            queryDesc = ser.ReadObject(ms) as QueryDesc;
            ms.Close();

            return(queryDesc);
        }
        public QueryDesc getCorrelationQueryDesc()
        {
            if (queryDesc != null)
            {
                return(queryDesc);
            }

            WebRequest webRequest;

            if (QueryId == null)
            {
                webRequest        = createWebRequest("/api/v1/instances");
                webRequest.Method = "POST";
                CorrelationQueryPost queryPost = new CorrelationQueryPost();
                string queryToUse = Query;
                if (!queryToUse.TrimStart().ToUpper().StartsWith("RULE"))
                {
                    queryToUse = "RULE Rule1 " + queryToUse;
                }
                queryPost.ecl       = String.Format("BEGIN CORRELATION RULESET\n{0}\nEND CORRELATION RULESET", queryToUse);
                queryPost.startDate = From.ToUniversalTime().ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'");
                queryPost.endDate   = To.ToUniversalTime().ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'");

                DataContractJsonSerializer qser = new DataContractJsonSerializer(queryPost.GetType());
                qser.WriteObject(webRequest.GetRequestStream(), queryPost);
                webRequest.ContentType = "application/json";
            }
            else
            {
                String path = String.Format("/api/v1/instance/{0}/result/{1}/columns", QueryId, "0");
                webRequest        = createWebRequest(path);
                webRequest.Method = "GET";
            }

            WebResponse   myWebResponse    = webRequest.GetResponse();
            StreamReader  reader           = new StreamReader(myWebResponse.GetResponseStream());
            string        reply            = reader.ReadToEnd();
            MemoryStream  ms               = new MemoryStream(Encoding.UTF8.GetBytes(reply));
            CorrQueryDesc corrQueryDesc    = new CorrQueryDesc();
            DataContractJsonSerializer ser = new DataContractJsonSerializer(corrQueryDesc.GetType());

            corrQueryDesc = ser.ReadObject(ms) as CorrQueryDesc;
            ms.Close();
            queryDesc         = new QueryDesc();
            queryDesc.queryId = corrQueryDesc.id;
            queryDesc.columns = corrQueryDesc.columnDescriptors;

            return(queryDesc);
        }
 private void initQuery()
 {
     queryDesc   = lmiHandler.getQueryDesc();
     rowIdx      = -1;
     lastResults = null;
 }