Search Unity

Get response from azure to Hololens

Discussion in 'VR' started by schetty, Apr 7, 2019.

  1. schetty

    schetty

    Joined:
    Jul 23, 2012
    Posts:
    424
    Hello All,

    I am working on a simple project in Hololens with the Azure environment. I have a small task where I want to get the values from my Azure to Hololens.

    When i run the script in my unity editor and if i connect with the Holographic emulator its works fine.

    but after i deployed to Hololens i am not getting any response form the Azure and its throwing null reference error message.

    Anyone have any idea why its not working?

    I have give my script below:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using System.Threading.Tasks;
    5. using Microsoft.Azure.Documents;
    6. using Microsoft.Azure.Documents.Client;
    7. using System;
    8. using Microsoft.Azure.Documents.Linq;
    9. using System.Linq;
    10. using System.Runtime;
    11. using Newtonsoft.Json;
    12. using ChartAndGraph;
    13.  
    14. public class GraphChartFeed : MonoBehaviour
    15. {
    16.     private static readonly string endpointString = "------------------------------------------";
    17.     private static readonly string authKeyString = "-----------------------------------------";
    18.     private static readonly string databaseId = "Tasks";
    19.     private static readonly string collectionId = "Items";
    20.     DocumentClient documentClient;
    21.     GraphChartBase graph;
    22.  
    23.     void Start ()
    24.     {
    25.         try
    26.         {
    27.             documentClient = new DocumentClient(new Uri(endpointString), authKeyString);
    28.             //Task.Run(TestTableConnection);
    29.         }
    30.         catch (Exception ex)
    31.         {
    32.             print("Some error occured: " + ex.Message);
    33.         }
    34.  
    35.         var collectionLink = UriFactory.CreateDocumentCollectionUri(databaseId, collectionId);
    36.         print("Initiating sql query!");
    37.         var response = documentClient.CreateDocumentQuery(collectionLink, "SELECT TOP 1 c.name,c.category FROM c ORDER BY c._ts DESC").ToList();
    38.         var document = response.First();
    39.         var result = JsonConvert.DeserializeObject(document.ToString());
    40.         var res = JsonConvert.DeserializeObject(result.category.ToString());
    41.         float multiplier = 0.001f;
    42.         float a = res.r1 * multiplier;
    43.         float b = res.r2 * multiplier;
    44.         float c = res.r3 * multiplier;
    45.         float d = res.r4 * multiplier;
    46.         float e = res.r5 * multiplier;
    47.  
    48.  
    49.         print(UnityEngine.Random.value * 10f);
    50.  
    51.         graph = GetComponent<GraphChartBase>();
    52.         if (graph != null)
    53.         {
    54.             graph.DataSource.StartBatch();
    55.             graph.DataSource.ClearCategory("Player 1");
    56.             graph.DataSource.ClearAndMakeBezierCurve("Player 2");
    57.             graph.DataSource.AddPointToCategory("Player 1", 1, -a * 10f);
    58.             graph.DataSource.AddPointToCategory("Player 1", 2, -b * 10f);
    59.             graph.DataSource.AddPointToCategory("Player 1", 3, -c * 10f);
    60.             graph.DataSource.AddPointToCategory("Player 1", 4, -d * 10f);
    61.             graph.DataSource.AddPointToCategory("Player 1", 5, -e * 10f);
    62.             //for (int i = 0; i < 5; i++)
    63.             //{
    64.             //    graph.DataSource.AddPointToCategory("Player 1", UnityEngine.Random.value * 10f, UnityEngine.Random.value * 10f + 20f);
    65.             //    //if (i == 0)
    66.             //    //    graph.DataSource.SetCurveInitialPoint("Player 2", 0f, Random.value * 10f + 10f);
    67.             //    //else
    68.             //    //    graph.DataSource.AddLinearCurveToCategory("Player 2",
    69.             //    //new DoubleVector2(i * 10f / 30f, Random.value * 10f + 10f));
    70.             //}
    71.             //graph.DataSource.MakeCurveCategorySmooth("Player 1");
    72.             graph.DataSource.EndBatch();
    73.         }
    74.     }
    75.     //private async Task TestTableConnection()
    76.     //{
    77.     //    var collectionLink = UriFactory.CreateDocumentCollectionUri(databaseId, collectionId);
    78.     //    print("Initiating sql query!");
    79.     //    var response = documentClient.CreateDocumentQuery(collectionLink, "SELECT TOP 1 c.name,c.category FROM c ORDER BY c._ts DESC").ToList();
    80.     //    var document = response.First();
    81.     //    var result = JsonConvert.DeserializeObject(document.ToString());
    82.     //    print(result.category.r1);
    83.     //}
    84.     //void Update()
    85.     //{
    86.     //    //Task.Run(TestTableConnection)
    87.     //}
    88. }
    Thanks in Advance.