示例#1
0
	public void sendAction() {

		GetComponent<Animator>().Play("Click");

		if (buttonType == FLOOR_BUTTON_TYPE.YES || buttonType == FLOOR_BUTTON_TYPE.NO) {

			GameObject.Find("Debug Text").GetComponent<Text>().text += "Setting Position \n";

			HTTPRequest request = new HTTPRequest(new Uri("http://run-west.att.io/d9576f027ee8f/6e9234f387c9/9c7023eee2b3b23/in/flow/action"), HTTPMethods.Put, actionSentCallback);

			JSONClass data = new JSONClass();

			data["value"] = ((int)buttonType).ToString();

			request.AddHeader("Content-Type", "application/json");
			//request.AddHeader("X-M2X-KEY", "9fc7996ea7f03fccc6ef3978f2a4d012");
			request.RawData = Encoding.UTF8.GetBytes(data.ToString());
			request.Send();
		} else {

			HTTPRequest request = new HTTPRequest(new Uri("http://run-west.att.io/d9576f027ee8f/6e9234f387c9/9c7023eee2b3b23/in/flow/dlswitch"), HTTPMethods.Put, actionSentCallback);

			JSONClass data = new JSONClass();

			data["value"] = (dlSwitch).ToString();

			request.AddHeader("Content-Type", "application/json");
			//request.AddHeader("X-M2X-KEY", "9fc7996ea7f03fccc6ef3978f2a4d012");
			request.RawData = Encoding.UTF8.GetBytes(data.ToString());
			request.Send();
		}



	}
	public IEnumerator LogIn(string user, string pass){
		string loginURI = "http://nebinstower.cloudapp.net:5000/login/";
		string jsonString = "{\"username\": \"" + user + "\", \"password\": \"" + pass + "\"}";

		HTTPRequest request = new HTTPRequest (new System.Uri (loginURI), HTTPMethods.Post);

		request.RawData = Encoding.UTF8.GetBytes(jsonString);
		request.AddHeader ("Content-Type", "application/json");

		request.Send();

		yield return StartCoroutine(request);
		Debug.Log (request.Response.DataAsText);
		if (request.Response.StatusCode == 200) {
			Debug.Log ("success");
			JObject o = JObject.Parse (request.Response.DataAsText);

			PlayerPrefs.SetString ("token", o ["token"].Value<string> ());
			PlayerPrefs.SetString ("username", user);

			errorText.text = "";

			loginComplete ();
		} else if (request.Response.StatusCode == 404) {
			string registerURI = "http://nebinstower.cloudapp.net:5000/register/";
			request = new HTTPRequest (new System.Uri (registerURI), HTTPMethods.Post);

			request.RawData = Encoding.UTF8.GetBytes (jsonString);
			request.AddHeader ("Content-Type", "application/json");

			request.Send ();

			yield return StartCoroutine (request);
			Debug.Log (request.Response.DataAsText);
			JObject o = JObject.Parse (request.Response.DataAsText);

			PlayerPrefs.SetString ("token", o ["token"].Value<string> ());
			PlayerPrefs.SetString ("username", user);
			errorText.text = "";

			loginComplete ();
		} else {
			errorText.text = request.Response.DataAsText;
		}
	}
    public IEnumerator saveCharacters(){
		Fighter f = new Fighter ();

		string saveURL = "http://nebinstower.cloudapp.net:5000/saveCharacters/";

		string token = PlayerPrefs.GetString ("token");
		string user = PlayerPrefs.GetString ("username");

		string jsonString = "{\"username\": \"" + user + "\", \"token\": \"" + token + "\", \"savedata\": " + JsonConvert.SerializeObject (f) + "}";

		HTTPRequest request = new HTTPRequest (new System.Uri (saveURL), HTTPMethods.Post);

		request.RawData = Encoding.UTF8.GetBytes (jsonString);
		request.AddHeader ("Content-Type", "application/json");
		request.Send ();

		yield return StartCoroutine (request);

		Debug.Log (request.Response.DataAsText);
	}
    public IEnumerator loadCharactersTest()
    {
        string loadURL = "http://nebinstower.cloudapp.net:5000/loadCharacters/";

        string token = PlayerPrefs.GetString("token");
        string user = PlayerPrefs.GetString("username");

        string jsonString = "{\"username\": \"" + user + "\", \"token\": \"" + token + "\"}";

        HTTPRequest request = new HTTPRequest(new System.Uri(loadURL), HTTPMethods.Post);

        request.RawData = Encoding.UTF8.GetBytes(jsonString);
        request.AddHeader("Content-Type", "application/json");
        request.Send();

        yield return StartCoroutine(request);

        Debug.Log(request.Response.DataAsText);

        SaveState f = JsonConvert.DeserializeObject<SaveState>(request.Response.DataAsText);

        GameObject.Find("LOADER").GetComponent<Loader>().saveState.GoldCount = f.GoldCount;

        Application.LoadLevel("main");
    }
示例#5
0
    // https://library.vuforia.com/articles/Solution/How-To-Use-the-Vuforia-Web-Services-API.htm#How-To-Delete-a-Target
    IEnumerator DeleteTarget()
    {
        Debug.Log("CustomMessage: DeleteTarget()");

        // Setting up query.
        string requestPath = "/targets/" + currentImageData.UniqueTargetId;
        string serviceURI  = url + requestPath;
        string httpAction  = "DELETE";
        string contentType = "";
        string date        = string.Format("{0:r}", DateTime.Now.ToUniversalTime());

        // Create ContentMD5.
        MD5 md5             = MD5.Create();
        var contentMD5bytes = md5.ComputeHash(System.Text.Encoding.ASCII.GetBytes(""));

        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        for (int i = 0; i < contentMD5bytes.Length; i++)
        {
            sb.Append(contentMD5bytes[i].ToString("x2"));
        }

        string contentMD5   = sb.ToString();
        string stringToSign = string.Format("{0}\n{1}\n{2}\n{3}\n{4}", httpAction, contentMD5, contentType, date, requestPath);

        // Build signature.
        HMACSHA1 sha1 = new HMACSHA1(System.Text.Encoding.ASCII.GetBytes(secret_key));

        byte[]       sha1Bytes = System.Text.Encoding.ASCII.GetBytes(stringToSign);
        MemoryStream stream    = new MemoryStream(sha1Bytes);

        byte[] sha1Hash  = sha1.ComputeHash(stream);
        string signature = System.Convert.ToBase64String(sha1Hash);

        Debug.Log("<color=green>Signature: " + signature + "</color>");

        // Build Http Request.
        BestHTTP.HTTPRequest request = new BestHTTP.HTTPRequest(new Uri(serviceURI));

        request.MethodType = BestHTTP.HTTPMethods.Delete;
        request.RawData    = Encoding.UTF8.GetBytes("");
        request.AddHeader("Authorization", string.Format("VWS {0}:{1}", access_key, signature));
        request.AddHeader("Content-Type", contentType);
        request.AddHeader("Date", date);
        request.Send();

        yield return(StartCoroutine(request));

        switch (request.State)
        {
        case BestHTTP.HTTPRequestStates.Error:

            Debug.Log("request error: " + request.Exception.Message);

            string errorText = request.Exception.Message;
            PrintStatusText("Exception: " + errorText);

            editButton.interactable = true;

            break;

        case BestHTTP.HTTPRequestStates.Finished:

            // There is an error
            if (request.Response.StatusCode != 200)
            {
                Debug.Log("request error: " + request.Response.Message);

                string result_code = JsonUtility.FromJson <VWSResponse>(request.Response.DataAsText).result_code;

                // The target is still being processed in Vuforia API.
                if (result_code == "TargetStatusProcessing")
                {
                    PrintStatusText("Error: Profile is still being processed in Vuforia!");
                }
                else
                {
                    PrintStatusText("Error: " + result_code);
                }

                editButton.interactable = true;
            }
            else
            {
                Debug.Log("request success");
                PrintStatusText("Deleted!");

                // We disable cloud tracking for x seconds. The reason why we do this is because it takes time for
                // Vuforia to actually delete the record. If we continue cloud tracking, it would retrack the record.
                DisableCloudTracking(2f);

                // To get all the tracked targets. For testing.
                // IEnumerable<Vuforia.ObjectTarget> obj = Vuforia.TrackerManager.Instance.GetTracker<Vuforia.ObjectTracker>().GetTargetFinder<Vuforia.ImageTargetFinder>().GetObjectTargets();
                // IEnumerator myEnum = obj.GetEnumerator();

                // while(myEnum.MoveNext()){
                //     print(myEnum.Current);
                // }

                // Clear local copy.
                Vuforia.TrackerManager.Instance.GetTracker <Vuforia.ObjectTracker>().GetTargetFinder <Vuforia.ImageTargetFinder>().ClearTrackables(false);

                // Vuforia.TrackerManager.Instance.GetTracker<Vuforia.ObjectTracker>().GetTargetFinder<Vuforia.ImageTargetFinder>().Stop();
                // Vuforia.TrackerManager.Instance.GetTracker<Vuforia.ObjectTracker>().GetTargetFinder<Vuforia.ImageTargetFinder>().StartRecognition();

                // Close edit menu.
                ToggleEditMenu();

                // Enable the upload button. This is needed because the tracker is disabled, and therefore, events are not being triggered
                // which in turn stops our handler from setting button states.
                uploadButton.interactable = true;
            }

            break;
        }

        // Enable buttons.
        deleteDeleteButton.interactable = true;
        putEditButton.interactable      = true;
    }
示例#6
0
    // https://library.vuforia.com/articles/Solution/How-To-Use-the-Vuforia-Web-Services-API.htm#How-To-Update-a-Target
    IEnumerator PutUpdateTarget(bool updateImage = false)
    {
        Debug.Log("CustomMessage: PutUpdateTarget()");

        // Setting up query.
        string requestPath = "/targets/" + currentImageData.UniqueTargetId;
        string serviceURI  = url + requestPath;
        string httpAction  = "PUT";
        string contentType = "application/json";
        string date        = string.Format("{0:r}", DateTime.Now.ToUniversalTime());

        string metadataStr = jsonData;

        byte[] metadata = System.Text.ASCIIEncoding.ASCII.GetBytes(metadataStr);

        // Create new model to prepare for sending.
        PostNewTrackableRequest model = new PostNewTrackableRequest();

        model.name  = targetName;
        model.width = 64.0f;
        model.application_metadata = System.Convert.ToBase64String(metadata);

        if (updateImage)
        {
            // Create texture and encode pixels to base64.
            Texture2D tex = new Texture2D(texture.width, texture.height, TextureFormat.RGB24, false);
            tex.SetPixels(texture.GetPixels());
            tex.Apply();
            byte[] image = tex.EncodeToPNG();

            model.image = System.Convert.ToBase64String(image);
        }

        // Convert model to json.
        string requestBody = JsonUtility.ToJson(model);

        // Create ContentMD5.
        MD5 md5             = MD5.Create();
        var contentMD5bytes = md5.ComputeHash(System.Text.Encoding.ASCII.GetBytes(requestBody));

        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        for (int i = 0; i < contentMD5bytes.Length; i++)
        {
            sb.Append(contentMD5bytes[i].ToString("x2"));
        }

        string contentMD5   = sb.ToString();
        string stringToSign = string.Format("{0}\n{1}\n{2}\n{3}\n{4}", httpAction, contentMD5, contentType, date, requestPath);

        // Build signature.
        HMACSHA1 sha1 = new HMACSHA1(System.Text.Encoding.ASCII.GetBytes(secret_key));

        byte[]       sha1Bytes = System.Text.Encoding.ASCII.GetBytes(stringToSign);
        MemoryStream stream    = new MemoryStream(sha1Bytes);

        byte[] sha1Hash  = sha1.ComputeHash(stream);
        string signature = System.Convert.ToBase64String(sha1Hash);

        Debug.Log("<color=green>Signature: " + signature + "</color>");

        // Build Http Request.
        BestHTTP.HTTPRequest request = new BestHTTP.HTTPRequest(new Uri(serviceURI));

        request.MethodType = BestHTTP.HTTPMethods.Put;
        request.RawData    = Encoding.UTF8.GetBytes(requestBody);
        request.AddHeader("Authorization", string.Format("VWS {0}:{1}", access_key, signature));
        request.AddHeader("Content-Type", contentType);
        request.AddHeader("Date", date);
        request.Send();

        yield return(StartCoroutine(request));

        switch (request.State)
        {
        case BestHTTP.HTTPRequestStates.Error:

            Debug.Log("request error: " + request.Exception.Message);

            string errorText = request.Exception.Message;
            PrintStatusText("Exception: " + errorText);

            break;

        case BestHTTP.HTTPRequestStates.Finished:

            // There is an error
            if (request.Response.StatusCode != 200)
            {
                Debug.Log("request error: " + request.Response.Message);

                string result_code = JsonUtility.FromJson <VWSResponse>(request.Response.DataAsText).result_code;

                // The target is still being processed in Vuforia API.
                if (result_code == "TargetStatusNotSuccess")
                {
                    PrintStatusText("Error: Profile is still being processed in Vuforia!");
                }
                else
                {
                    PrintStatusText("Error: " + result_code);
                }
            }
            else
            {
                Debug.Log("request success");
                PrintStatusText("Saved!");

                if (rescanCloudAfterEdit)
                {
                    // We disable cloud tracking for x seconds. The reason why we do this is because it takes time for
                    // Vuforia to actually delete the record. If we continue cloud tracking, it would retrack the record.
                    DisableCloudTracking(2f);

                    // To get all the tracked targets. For testing.
                    // IEnumerable<Vuforia.ObjectTarget> obj = Vuforia.TrackerManager.Instance.GetTracker<Vuforia.ObjectTracker>().GetTargetFinder<Vuforia.ImageTargetFinder>().GetObjectTargets();
                    // IEnumerator myEnum = obj.GetEnumerator();

                    // while(myEnum.MoveNext()){
                    //     print(myEnum.Current);
                    // }

                    // Clear local copy.
                    Vuforia.TrackerManager.Instance.GetTracker <Vuforia.ObjectTracker>().GetTargetFinder <Vuforia.ImageTargetFinder>().ClearTrackables(false);
                }
                else
                {
                    // Since the image is saved to the cloud, we can change the local copy.
                    currentImageData.MetaData   = metadataStr;
                    currentImageData.TargetName = targetName;

                    // Force update of target info.
                    cloudContentManager.HandleTargetFinderResult(currentImageData);

                    // The only issue with this method is we do not know the new tracking rating of the copy.
                    // However, since our version of profiler does not show tracking rating, it should work fine.

                    // Also, if the new image fails the processor on Vuforia's side, it wouldn't make sense to
                    // change the local copy's data. However, it would be more convenient for the user to see
                    // the new updated version. Therefore, when changing the local copy, we are assuming the
                    // new image to be processed successfully.
                }

                // Close edit menu.
                ToggleEditMenu();
            }

            break;
        }

        // Enable buttons.
        deleteDeleteButton.interactable = true;
        putEditButton.interactable      = true;
        editButton.interactable         = true;
    }
示例#7
0
	public void setPosition() {

		HTTPRequest request = new HTTPRequest(new Uri("http://run-west.att.io/d9576f027ee8f/6e9234f387c9/9c7023eee2b3b23/in/flow/position"), HTTPMethods.Put, setPositionFinished);

		JSONClass data = new JSONClass();

		data["value"] = position.ToString();

		request.AddHeader("Content-Type", "application/json");
		request.RawData = Encoding.UTF8.GetBytes(data.ToString());
		request.Send();

		moveScreenTo();

	}
示例#8
0
 public SimpleHttpReq AddHeader(string name, string value)
 {
     Req.AddHeader(name, value);
     return(this);
 }