Ejemplo n.º 1
0
        /// <summary>
        /// Sends an HTTP Request to the backend and parse the response (expected as a list of objects)
        /// </summary>
        /// <param name="action">action to query (e.g. "Snippets/Get")</param>
        /// <param name="data">
        ///     if the request is a GET, the parameters to be put in the querystring (e.g. "snippetID=100"),
        ///     otherwise data to be put in the post (e.g. "content=...")
        /// </param>
        /// <param name="isPost">whether this request is a GET(false) or a POST(true)</param>
        /// <param name="requiresLogin">false if this request calls a public web service</param>
        /// <returns>null if any error occurred; the result of the invocation otherwise</returns>
        protected S2CResListObj <string> SendReqListObj(string action, string data, bool isPost, bool requiresLogin = true)
        {
            string response = PrepareAndSendReq(action, data, isPost, requiresLogin);

            if (string.IsNullOrEmpty(response))
            {
                ErrorCodes errCode = ErrorCodes.COMMUNICATION_ERROR;
                if (WebConnector.Current.IsTimeout)
                {
                    errCode = ErrorCodes.TIMEOUT;
                }
                SetLastError(log, errCode, S2CRes <string> .GetErrorMsg(errCode));
                return(new S2CResListObj <string>(0.0, errCode, null, 0));
            }

            S2CResListObj <string> resp = S2CSerializer.DeserializeObjList(response, m_serialFormat);

            if (!CheckResp <string>(resp))
            {
                PrintRespError <string>(resp);

                //if the problem is related to user not logged in, reset login status and retry another time:
                if (requiresLogin && (resp != null) && (resp.Status == ErrorCodes.NOT_LOGGED_IN))
                {
                    WebConnector.Current.ResetLoginStatus(); //reset login status

                    //retry the WS call:
                    response = PrepareAndSendReq(action, data, isPost, requiresLogin);
                    resp     = S2CSerializer.DeserializeObjList(response, m_serialFormat);
                }
            }

            return(resp);
        }
Ejemplo n.º 2
0
        public ICollection <int> GetChannels(long snippetID)
        {
            //check for erroneous input:
            if (snippetID <= 0)
            {
                SetLastError(log, ErrorCodes.WRONG_INPUT, string.Format("Input error: snippetID={0}", snippetID));
                return(new List <int>());
            }

            //send the request and parse the response:
            S2CResListObj <string> resp = SendReqListObj(GET_CHANNELS_URL, "id=" + snippetID, false, false);

            //build the result:
            int totNum = 0;

            return(resp.GetListOfIntFromResp(out totNum));
        }
Ejemplo n.º 3
0
        public IList <long> FindPublicItemsID(int start, int count, int minRelevance, out int totNum)
        {
            //check for erroneous input:
            totNum = 0;
            if ((count <= 0) || (start < 0))
            {
                SetLastError(log, ErrorCodes.WRONG_INPUT,
                             string.Format("Input error: userID={0}, count={1}, start={2}", CurrentUserID, count, start));
                return(new List <long>());
            }

            //send the request and parse the response:
            string querystring          = string.Format("start={0}&count={1}&minRelevance={2}", start, count, minRelevance);
            S2CResListObj <string> resp = SendReqListObj(FINDPUB_SNIPPETS_URL, querystring, false, false);

            //build the result:
            IList <long> snipIDs = resp.GetListOfLongsFromResp(out totNum);

            return(snipIDs);
        }