Exemple #1
0
        public IEnumerator StartTracker(TrackerConfig config, string backupFilename, IBridge bridge = null)
        {
            trackerConfig = config;
            string domain = "";
            int    port   = 80;
            bool   secure = false;

            Debug.Log("[ANALYTICS] Setting up tracker...");
            try
            {
                if (config.getHost() != "")
                {
                    string[] splitted = config.getHost().Split('/');

                    if (splitted.Length > 1)
                    {
                        string[] host_splitted = splitted[2].Split(':');
                        if (host_splitted.Length > 0)
                        {
                            domain = host_splitted[0];
                            port   = (host_splitted.Length > 1) ? int.Parse(host_splitted[1]) : (splitted[0] == "https:" ? 443 : 80);
                            secure = splitted[0] == "https:";
                        }
                    }
                }
                else
                {
                    config.setHost("localhost");
                }
                Debug.Log("[ANALYTICS] Config: " + JsonConvert.SerializeObject(config));
            }
            catch (System.Exception e)
            {
                Debug.Log("Tracker error: Host bad format");
            }

            TrackerAsset.TraceFormats format;
            switch (config.getTraceFormat())
            {
            case TrackerConfig.TraceFormat.XAPI:
                format = TrackerAsset.TraceFormats.xapi;
                break;

            default:
                format = TrackerAsset.TraceFormats.csv;
                break;
            }
            Debug.Log("[ANALYTICS] Format: " + format);

            TrackerAsset.StorageTypes storage;
            switch (config.getStorageType())
            {
            case TrackerConfig.StorageType.NET:
                storage = TrackerAsset.StorageTypes.net;
                break;

            default:
                storage = TrackerAsset.StorageTypes.local;
                break;
            }
            Debug.Log("[ANALYTICS] Storage: " + storage);

            TrackerAssetSettings tracker_settings = new TrackerAssetSettings()
            {
                Host                     = domain,
                TrackingCode             = config.getTrackingCode(),
                BasePath                 = trackerConfig.getBasePath() ?? "/api",
                LoginEndpoint            = trackerConfig.getLoginEndpoint() ?? "login",
                StartEndpoint            = trackerConfig.getStartEndpoint() ?? "proxy/gleaner/collector/start/{0}",
                TrackEndpoint            = trackerConfig.getStartEndpoint() ?? "proxy/gleaner/collector/track",
                Port                     = port,
                Secure                   = secure,
                StorageType              = storage,
                TraceFormat              = format,
                BackupStorage            = config.getRawCopy(),
                UseBearerOnTrackEndpoint = trackerConfig.getUseBearerOnTrackEndpoint()
            };

            if (!string.IsNullOrEmpty(backupFilename))
            {
                tracker_settings.BackupFile = backupFilename;
            }

            Debug.Log("[ANALYTICS] Settings: " + JsonConvert.SerializeObject(tracker_settings));
            TrackerAsset.Instance.StrictMode = false;
            TrackerAsset.Instance.Bridge     = bridge ?? new UnityBridge();
            TrackerAsset.Instance.Settings   = tracker_settings;
            TrackerAsset.Instance.StrictMode = false;

            var done = false;

            Debug.Log("[ANALYTICS] Starting tracker without login...");
            TrackerAsset.Instance.StartAsync(() => done = true);

            this.nextFlush = config.getFlushInterval();

            Debug.Log("[ANALYTICS] Waiting until start");
            yield return(new WaitUntil(() => done));

            Debug.Log("[ANALYTICS] Start done, result: " + TrackerAsset.Instance.Started);
        }
Exemple #2
0
        private void PrepareTracker(TrackerConfig config)
        {
            string domain = "";
            int    port   = 80;
            bool   secure = false;

            try
            {
                if (config.getHost() != "")
                {
                    string[] splitted = config.getHost().Split('/');

                    if (splitted.Length > 1)
                    {
                        string[] host_splitted = splitted[2].Split(':');
                        if (host_splitted.Length > 0)
                        {
                            domain = host_splitted[0];
                            port   = (host_splitted.Length > 1) ? int.Parse(host_splitted[1]) : (splitted[0] == "https:" ? 443 : 80);
                            secure = splitted[0] == "https:";
                        }
                    }
                }
                else
                {
                    config.setHost("localhost");
                }
            }
            catch (System.Exception e)
            {
                Debug.Log("Tracker error: Host bad format");
            }

            TrackerAsset.TraceFormats format;
            switch (config.getTraceFormat())
            {
            case TrackerConfig.TraceFormat.XAPI:
                format = TrackerAsset.TraceFormats.xapi;
                break;

            default:
                format = TrackerAsset.TraceFormats.csv;
                break;
            }

            TrackerAsset.StorageTypes storage;
            switch (config.getStorageType())
            {
            case TrackerConfig.StorageType.NET:
                storage = TrackerAsset.StorageTypes.net;
                break;

            default:
                storage = TrackerAsset.StorageTypes.local;
                break;
            }

            TrackerAssetSettings tracker_settings = new TrackerAssetSettings()
            {
                Host          = domain,
                TrackingCode  = config.getTrackingCode(),
                BasePath      = "/api",
                Port          = port,
                Secure        = secure,
                StorageType   = storage,
                TraceFormat   = format,
                BackupStorage = config.getRawCopy()
            };

            TrackerAsset.Instance.Bridge   = new UnityBridge();
            TrackerAsset.Instance.Settings = tracker_settings;

            /* TODO: login disabled
             * if (!String.IsNullOrEmpty(username))
             *  TrackerAsset.Instance.Login(username, password);
             */

            TrackerAsset.Instance.Start();
            this.nextFlush = config.getFlushInterval();
        }