Example #1
0
        private async Task LoadTransforming()
        {
            if (TracksKeeper == null)
            {
                throw new Exception("Illegal State");
            }

            string url = null;

            if (ConnectState.ContextMetadata.ContainsKey("transforming.url"))
            {
                url = ConnectState.ContextMetadata["transforming.url"];
            }
            if (url == null)
            {
                return;
            }

            var shuffle = false;

            if (ConnectState.ContextMetadata.ContainsKey("transforming.shuffle"))
            {
                shuffle = bool.Parse(ConnectState.ContextMetadata["transforming.shuffle"]);
            }

            var willRequest =
                !ConnectState.Track.Metadata.ContainsKey(
                    "audio.fwdbtn.fade_overlap"); // I don't see another way to do this

            Debug.WriteLine("Context has transforming! url: {0}, shuffle: {1}, willRequest: {2}", url, shuffle,
                            willRequest);

            if (!willRequest)
            {
                return;
            }
            var obj = ProtoUtils.CraftContextStateCombo(ConnectState,
                                                        TracksKeeper.Tracks);

            try
            {
                var body = await url
                           .PostJsonAsync(obj)
                           .ReceiveString();

                if (body != null)
                {
                    UpdateContext(JObject.Parse(body));
                }
                Debug.WriteLine("Updated context with transforming information!");
            }
            catch (FlurlHttpException ex)
            {
                Debug.WriteLine($"Failed loading cuepoints " +
                                $"Error returned from {ex.Call.Request.Url}: {ex.Message}");
                return;
            }
        }