Exemplo n.º 1
0
        /// <summary>
        /// Call the Spotfire API
        /// </summary>
        /// <param name="mobiusApiMethodName"></param>
        /// <param name="args"></param>
        /// <returns></returns>

        public string CallSpotfireApi(
            string mobiusApiMethodName,
            params string[] args)
        {
            if (SCC == null)
            {
                throw new NullReferenceException("SpotfireComClient is null");
            }

            string methodAndParms = SpotfireComClient.JoinMethodAndParms(mobiusApiMethodName, args);

            methodAndParms = (SpotfireComClient.CallId + 1).ToString() + "\t" + methodAndParms;

            DebugLog.Message("CallMobiusSpotfireApi: " + methodAndParms);

            string response = SCC.CallMobiusSpotfireApi(mobiusApiMethodName, args);

            DebugLog.Message("Response: " + response);

            return(response);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Call the Spotfire API
        /// </summary>
        /// <param name="mobiusApiMethodName"></param>
        /// <param name="args"></param>
        /// <returns></returns>

        public string CallSpotfireApi(
            string mobiusApiMethodName,
            params string[] args)
        {
            CallId++;

            int responseId = -1, responseLength = -1, chunkId = -1;;

            string methodAndParms =             // join the mobius
                                    SpotfireComClient.JoinMethodAndParms(mobiusApiMethodName, args);

            methodAndParms = CallId.ToString() + "\t" + methodAndParms;

            if (Debug)
            {
                DebugLog.Message("CallMobiusSpotfireApi: " + methodAndParms);
            }

            ResponseHasBeenReceived = false;

            string result = InvokeScriptMethod("CallMobiusSpotfireApi", methodAndParms);             // start the call

            while (!ResponseHasBeenReceived)
            {
                Application.DoEvents();
                Thread.Sleep(10);
            }

            string response = MobiusSpotfireApiResponse;             // copy the response

            if (response == null)
            {
                response = "<null>";
            }

            MobiusSpotfireApiResponse = null;            // null out the buffer
            ResponseHasBeenRetrieved  = true;            // indicate it's been retrieved

            if (Debug)
            {
                DebugLog.Message("Response: " + response);
            }

            if (Lex.Contains(response, "<MsxException>"))
            {
                return(response);
            }

            // Parse out the chunk id, response id and length

            Lex.TryParseOffFirstIntegerToken(ref response, '\t', out chunkId);
            Lex.TryParseOffFirstIntegerToken(ref response, '\t', out responseId);
            Lex.TryParseOffFirstIntegerToken(ref response, '\t', out responseLength);

            if (responseLength > response.Length)                                                    // get remaining chunks for long response strings stored in additional doc properties
            {
                for (int i1 = 2; ; i1++)                                                             // loop until we get all chunks
                {
                    string propName = MobiusSpotfireApiResponseDocumentPropertyname + i1.ToString(); // next prop to get
                    string chunk    = GetDocumentProperty(propName);

                    if (chunk == null || chunk.Length == 0)
                    {
                        throw new Exception("Null/empty value for Document Property : " + propName);
                    }

                    Lex.TryParseOffFirstIntegerToken(ref chunk, '\t', out chunkId);

                    response += chunk;
                    if (response.Length >= responseLength)
                    {
                        break;
                    }
                    else if (response.Length > responseLength)
                    {
                        throw new Exception("Response longer than expected " + response.Length + " > " + responseLength + " for Document Property : " + propName);
                    }
                }
            }

            if (response == "<null>")
            {
                response = null;
            }

            return(response);
        }