public CloudinaryClient(string imagePath, MySecureString cloudinaryUrl)
 {
     this.imagePath = imagePath;
     cloudinary     = new Cloudinary(cloudinaryUrl.GetStr());
 }
Exemple #2
0
 public StreamlootsClient(MySecureString bearerToken)
 {
     client.DefaultRequestHeaders.Add("authorization", $"Bearer {bearerToken.GetStr()}");
     //TestApi();
 }
Exemple #3
0
 public void InitializeClient(MySecureString bearerToken)
 {
     client.DefaultRequestHeaders.Add("authorization", $"Bearer {bearerToken.GetStr()}");
 }
Exemple #4
0
        private async void BackgroundCheck()
        {
            //`! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            //`! !!!                                                                                      !!!
            //`! !!!  Turn off Debug Visualizer before stepping through this method live on the stream!!! !!!
            //`! !!!                                                                                      !!!
            //`! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

            webRequest = WebRequest.Create(string.Format("https://widgets.streamloots.com/alerts/{0}/media-stream", streamlootsID.GetStr()));
            ((HttpWebRequest)webRequest).AllowReadStreamBuffering = false;
            WebResponse response = webRequest.GetResponse();

            responseStream = response.GetResponseStream();

            UTF8Encoding encoder = new UTF8Encoding();
            string       cardStr = string.Empty;
            var          buffer  = new byte[100000];

            while (true)
            {
                try
                {
                    while (responseStream.CanRead)
                    {
                        int len = await responseStream.ReadAsync(buffer, 0, 100000);

                        if (len <= 10)
                        {
                            continue;
                        }

                        string text = encoder.GetString(buffer, 0, len);
                        if (string.IsNullOrEmpty(text))
                        {
                            continue;
                        }

                        cardStr += text;
                        try
                        {
                            JObject cardObject = JObject.Parse("{ " + cardStr + " }");
                            if (cardObject == null)
                            {
                                continue;
                            }

                            if (!cardObject.ContainsKey("data"))
                            {
                                continue;
                            }

                            cardStr = string.Empty;
                            JObject cardData = cardObject.Value <JObject>("data");
                            if (!cardData.ContainsKey("data"))
                            {
                                continue;
                            }

                            JObject cardDataData = cardData.Value <JObject>("data");
                            if (!cardDataData.ContainsKey("type"))
                            {
                                continue;
                            }

                            string type = cardDataData.Value <string>("type");
                            switch (type.ToLower())
                            {
                            case "purchase":
                                ProcessChestPurchase(cardObject);
                                break;

                            case "redemption":
                                ProcessCardRedemption(cardObject);
                                break;

                            default:
                                Console.WriteLine($"Unknown Streamloots packet type: {type}");
                                break;
                            }
                        }
                        catch (Exception) { }                           // To handle the case where partial packet data is received
                    }
                }
                catch (Exception ex)
                {
                    //System.Diagnostics.Debugger.Break();
                    Console.WriteLine(ex.ToString());

                    webRequest = WebRequest.Create(string.Format("https://widgets.streamloots.com/alerts/{0}/media-stream", streamlootsID.GetStr()));
                    ((HttpWebRequest)webRequest).AllowReadStreamBuffering = false;
                    response       = webRequest.GetResponse();
                    responseStream = response.GetResponseStream();

                    encoder = new UTF8Encoding();
                    cardStr = string.Empty;
                    buffer  = new byte[100000];
                }
            }
        }