Ejemplo n.º 1
0
SamiBoolQuery::SamiBoolQuery(String* json) {
    init();
    String str(json->GetPointer());
    int length = str.GetLength();

    ByteBuffer buffer;
    buffer.Construct(length);

    for (int i = 0; i < length; ++i) {
       byte b = str[i];
       buffer.SetByte(b);
    }

    IJsonValue* pJson = JsonParser::ParseN(buffer);
    fromJsonObject(pJson);
    if (pJson->GetType() == JSON_TYPE_OBJECT) {
       JsonObject* pObject = static_cast< JsonObject* >(pJson);
       pObject->RemoveAll(true);
    }
    else if (pJson->GetType() == JSON_TYPE_ARRAY) {
       JsonArray* pArray = static_cast< JsonArray* >(pJson);
       pArray->RemoveAll(true);
    }
    delete pJson;
}
SamiShowcaseDatatypePrimitives*
SamiShowcaseDatatypePrimitives::fromJson(String* json) {
    this->cleanup();
    String str(json->GetPointer());
    int length = str.GetLength();

    ByteBuffer buffer;
    buffer.Construct(length);

    for (int i = 0; i < length; ++i) {
       byte b = str[i];
       buffer.SetByte(b);
    }

    IJsonValue* pJson = JsonParser::ParseN(buffer);
    fromJsonObject(pJson);
    if (pJson->GetType() == JSON_TYPE_OBJECT) {
       JsonObject* pObject = static_cast< JsonObject* >(pJson);
       pObject->RemoveAll(true);
    }
    else if (pJson->GetType() == JSON_TYPE_ARRAY) {
       JsonArray* pArray = static_cast< JsonArray* >(pJson);
       pArray->RemoveAll(true);
    }
    delete pJson;
    return this;
}
Ejemplo n.º 3
0
void
saveProcessor(HttpResponse* pHttpResponse, void (* handler)(void*, SamiError*)) {
  int code = pHttpResponse->GetHttpStatusCode();

  if(code >= 200 && code < 300) {
    ByteBuffer* pBuffer = pHttpResponse->ReadBodyN();
    IJsonValue* pJson = JsonParser::ParseN(*pBuffer);

    SamiCloudObject* out = new SamiCloudObject();
    jsonToValue(out, pJson, L"SamiCloudObject*", L"SamiCloudObject");

    if (pJson) {
      if (pJson->GetType() == JSON_TYPE_OBJECT) {
         JsonObject* pObject = static_cast< JsonObject* >(pJson);
         pObject->RemoveAll(true);
      }
      else if (pJson->GetType() == JSON_TYPE_ARRAY) {
         JsonArray* pArray = static_cast< JsonArray* >(pJson);
         pArray->RemoveAll(true);
      }
      handler(out, null);
    }
    else {
      SamiError* error = new SamiError(0, new String(L"No parsable response received"));
      handler(null, error);
    }
    
  }
  else {
    SamiError* error = new SamiError(code, new String(pHttpResponse->GetStatusText()));
    handler(null, error);
    
  }
}
Ejemplo n.º 4
0
void
ProjectGiraffeTab1::OnTransactionReadyToRead (HttpSession &httpSession, HttpTransaction &httpTransaction, int availableBodyLen)
{
	HttpResponse* pHttpResponse = httpTransaction.GetResponse();
	HttpHeader* pHttpHeader = null;
	AppLog("Checking HTTP Status Code");
	if (pHttpResponse->GetHttpStatusCode() == HTTP_STATUS_OK)
	{
		//		MessageBox msgBox;
		//		msgBox.Construct(L"HTTP STATUS", L"HTTP Request OK", MSGBOX_STYLE_NONE, 3000);
		//		int modalresult = 0;
		//		msgBox.ShowAndWait(modalresult);

		ByteBuffer* pBody = null;
		String statusText = pHttpResponse->GetStatusText();
		String version = pHttpResponse->GetVersion();

		pHttpHeader = pHttpResponse->GetHeader();
		pBody = pHttpResponse->ReadBodyN();
		//delete pBody;

		//Parses from ByteBuffer
		IJsonValue* pValue = JsonParser::ParseN(*pBody);

		AppLog("Received HTTP response.");

		AppLog("Before traverse %d", _tableView->GetItemCount());
		_pJsonKeyList->RemoveAll(true);
		_pValueList->RemoveAll(true);
		_items->RemoveAll(true);
		// Populate the panel
		TraverseFunction(pValue);

		AppLog("After traverse");

		//clean up allocated jsonValues
		if (pValue->GetType() == JSON_TYPE_OBJECT)
		{
			// Converts the pValue to JsonObject
			JsonObject* pObject = static_cast< JsonObject* >(pValue);
			pObject->RemoveAll(true);
		}
		else if (pValue->GetType() == JSON_TYPE_ARRAY)
		{
			// Converts the pValue to JsonArray
			JsonArray* pArray = static_cast< JsonArray* >(pValue);
			pArray->RemoveAll(true);
		}

		delete pBody;
		delete pValue;
		_tableView->ScrollToItem(0);



	}else{
		AppLog("HTTP Status not OK");
	}
	//Remove load icon here.
	//_loadingPopupThread->Quit();
	//_loadingPopupThread->Join();
}