public bool AddSnippetProperties(long snippetID, ICollection <SnippetProperty> properties) { if ((snippetID <= 0) || properties.IsNullOrEmpty()) { SetLastError(log, ErrorCodes.WRONG_INPUT, string.Format("Input error: snippetID={0}, properties={1}", snippetID, properties.Print <SnippetProperty>())); return(false); } //check input properties and clean them if not valid: List <SnippetProperty> cleanProperties = SnippetProperty.CleanPropertyList(properties, snippetID); //fastly return if no properties are to be added: if (cleanProperties.IsNullOrEmpty()) { return(true); } //send the request and parse the response: S2CSerializer ser = new S2CSerializer(m_serialFormat, snippetID); string contentToSend = "content=" + HttpUtility.UrlEncode(ser.SerializeBaseEntityList <SnippetProperty>(cleanProperties.ToArray(), null)); S2CResObj <object> resp = SendReqObj(ADD_PROPERTIES_URL, contentToSend, true); //build the result: return(ParseBoolResponse(resp)); }
/// <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); }
public bool AddSnippetTags(long snippetID, ICollection <string> tags) { if ((snippetID <= 0) || tags.IsNullOrEmpty()) { SetLastError(log, ErrorCodes.WRONG_INPUT, string.Format("Input error: snippetID={0}, tags={1}", snippetID, tags.Print <string>())); return(false); } //send the request and parse the response: S2CSerializer ser = new S2CSerializer(m_serialFormat, snippetID); string contentToSend = "content=" + HttpUtility.UrlEncode(ser.SerializeListObj <string>(tags.ToArray())); S2CResObj <object> resp = SendReqObj(ADD_TAGS_URL, contentToSend, true); //build the result: return(ParseBoolResponse(resp)); }
public bool DeleteSnippetTags(long snippetID, ICollection<string> tagsToDelete) { if ((snippetID <= 0) || tagsToDelete.IsNullOrEmpty()) { SetLastError(log, ErrorCodes.WRONG_INPUT, string.Format("Input error: snippetID={0}, tags={1}", snippetID, tagsToDelete.Print<string>())); return false; } //send the request and parse the response: S2CSerializer ser = new S2CSerializer(m_serialFormat, snippetID); string contentToSend = "content=" + HttpUtility.UrlEncode(ser.SerializeListObj<string>(tagsToDelete.ToArray())); S2CResObj<object> resp = SendReqObj(DELETE_TAGS_URL, contentToSend, true); //build the result: return ParseBoolResponse(resp); }
public bool AddSnippetProperties(long snippetID, ICollection<SnippetProperty> properties) { if ((snippetID <= 0) || properties.IsNullOrEmpty()) { SetLastError(log, ErrorCodes.WRONG_INPUT, string.Format("Input error: snippetID={0}, properties={1}", snippetID, properties.Print<SnippetProperty>())); return false; } //check input properties and clean them if not valid: List<SnippetProperty> cleanProperties = SnippetProperty.CleanPropertyList(properties, snippetID); //fastly return if no properties are to be added: if (cleanProperties.IsNullOrEmpty()) return true; //send the request and parse the response: S2CSerializer ser = new S2CSerializer(m_serialFormat, snippetID); string contentToSend = "content=" + HttpUtility.UrlEncode(ser.SerializeBaseEntityList<SnippetProperty>(cleanProperties.ToArray(), null)); S2CResObj<object> resp = SendReqObj(ADD_PROPERTIES_URL, contentToSend, true); //build the result: return ParseBoolResponse(resp); }