コード例 #1
0
        IEnumerator Execute()
        {
            while (shouldRun)
            {
                while (currentTime < sendInterval)
                {
                    if (pending.Count >= pendingBufferSize)
                    {
                        break;
                    }

                    yield return(new WaitForSeconds(tickInterval));

                    currentTime += tickInterval;
                }

                if (pending.Count > 0)
                {
                    TelemetryProperties commonProperties = TelemetryManager.Instance.GetCommonProperties();
                    yield return(StartCoroutine(SendTelemetry(commonProperties)));
                }

                currentTime = 0;
            }
        }
コード例 #2
0
        public TelemetryBatchPayload(TelemetryProperties common)
        {
            headerObject = new JSONObj(JSONObj.ObjectType.OBJECT);
            eventList    = new System.Collections.Generic.List <JSONObj>();

            foreach (var Prop in common)
            {
                headerObject.AddField(Prop.Key, Prop.Value);
            }
        }
コード例 #3
0
        // Debug utility function for outputting telemetry to a string for printing
        public static string DumpJson(TelemetryProperties properties)
        {
            JSONObj jObject = new JSONObj(JSONObj.ObjectType.OBJECT);

            foreach (var Prop in properties)
            {
                jObject.AddField(Prop.Key, Prop.Value);
            }

            return(jObject.Print());
        }
コード例 #4
0
        IEnumerator SendTelemetry(TelemetryProperties commonProperties)
        {
            TelemetryBatchPayload BatchPayload = new TelemetryBatchPayload(commonProperties);

            while (pending.Count > 0)
            {
                BatchPayload.AddTelemetry(pending.Dequeue());
            }

            string payload = BatchPayload.Finalize();

            using (UnityWebRequest wr = new UnityWebRequest())
            {
                var bytes = System.Text.Encoding.UTF8.GetBytes(payload);
                wr.url    = ingestUrl;
                wr.method = UnityWebRequest.kHttpVerbPOST;
                UploadHandler uploader = new UploadHandlerRaw(bytes);
                wr.uploadHandler = uploader;

                if (authenticationKey.Length > 0)
                {
                    wr.SetRequestHeader("x-functions-key", authenticationKey);
                }

                wr.SetRequestHeader("Content-Type", "application/json");
                wr.SetRequestHeader("x-ms-payload-type", "batch");
                wr.timeout = 30;

                yield return(wr.SendWebRequest());

                if (wr.isNetworkError || wr.isHttpError)
                {
                    Debug.Log(wr.error);
                }
            }
        }
コード例 #5
0
 // Records an event and places it in the buffer to be sent
 public static void Record(string name, string category, string version, TelemetryProperties properties)
 {
     TelemetryManager.Instance.Record(name, category, version, new TelemetryBuilder(properties));
 }
コード例 #6
0
 // Creates a telemetry builder based on provided properties
 public static TelemetryBuilder Create(TelemetryProperties properties)
 {
     return(new TelemetryBuilder(properties));
 }