Exemplo n.º 1
0
        public static JObject profileconvert(Credentials credentials, string hubName, string stream, string[] profileNames)
        {
            if (stream == null)
            {
                throw new PiliException(MessageConfig.NULL_STREAM_ID_EXCEPTION_MSG);
            }
            stream = UrlSafeBase64.encodeToString(stream);

            string          urlStr   = string.Format("{0}/hubs/{1}/streams/{2}/converts", API_BASE_URL, hubName, stream);
            HttpWebResponse response = null;
            JObject         json     = new JObject();

            json.Add("converts", new JArray(profileNames));
            try
            {
                Uri url = new Uri(urlStr);
                mOkHttpClient = (HttpWebRequest)HttpWebRequest.Create(url);
                string contentType = "application/json";
                byte[] body        = json.ToString().GetBytes(Config.UTF8);
                string macToken    = credentials.signRequest(url, "POST", body, contentType);
                mOkHttpClient.Method      = WebRequestMethods.Http.Post;
                mOkHttpClient.ContentType = contentType;
                mOkHttpClient.UserAgent   = Utils.UserAgent;
                mOkHttpClient.Headers.Add("Authorization", macToken);
                mOkHttpClient.ContentLength = body.Length;
                using (System.IO.Stream requestStream = mOkHttpClient.GetRequestStream())
                {
                    Utils.CopyN(requestStream, new MemoryStream(body), body.Length);
                }
                response = (HttpWebResponse)mOkHttpClient.GetResponse();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
                throw new PiliException(e);
            }
            // response never be null
            if ((int)response.StatusCode == 200)
            {
                try
                {
                    StreamReader reader  = new StreamReader(response.GetResponseStream());
                    string       text    = reader.ReadToEnd();
                    JObject      jsonObj = JObject.Parse(text);
                    return(jsonObj);
                }
                catch (IOException e)
                {
                    Console.WriteLine(e.ToString());
                    Console.Write(e.StackTrace);
                    throw new PiliException(e);
                }
            }
            else
            {
                throw new PiliException(response);
            }
        }
Exemplo n.º 2
0
        public static JObject getStreamHistory(Credentials credentials, string hubName, string streamTitle, int start, int end)
        {
            if (streamTitle == null)
            {
                throw new PiliException(MessageConfig.NULL_STREAM_ID_EXCEPTION_MSG);
            }
            streamTitle = UrlSafeBase64.encodeToString(streamTitle);
            if (start < 0 || start > end)
            {
                throw new PiliException(MessageConfig.ILLEGAL_FORMAT_EXCEPTION_MSG);
            }
            string          urlStr   = string.Format("{0}/hubs/{1}/streams/{2}/historyactivity?start={3}&end={4}", API_BASE_URL, hubName, streamTitle, start, end);
            HttpWebResponse response = null;

            try
            {
                Uri url = new Uri(urlStr);
                mOkHttpClient        = (HttpWebRequest)HttpWebRequest.Create(url);
                mOkHttpClient.Method = WebRequestMethods.Http.Get;
                string macToken = credentials.signRequest(url, "GET", null, null);
                mOkHttpClient.UserAgent = Utils.UserAgent;
                mOkHttpClient.Headers.Add("Authorization", macToken);
                response = (HttpWebResponse)mOkHttpClient.GetResponse();
            }
            catch (Exception e)
            {
                throw new PiliException(e);
            }
            // response never be nulle
            if ((int)response.StatusCode == 200)
            {
                try
                {
                    StreamReader reader  = new StreamReader(response.GetResponseStream());
                    string       text    = reader.ReadToEnd();
                    JObject      jsonObj = JObject.Parse(text);
                    return(jsonObj);
                }
                catch (IOException e)
                {
                    Console.WriteLine(e.ToString());
                    Console.Write(e.StackTrace);
                    throw new PiliException(e);
                }
            }
            else
            {
                throw new PiliException(response);
            }
        }
Exemplo n.º 3
0
        public static JObject getStreamLiveInformation(Credentials credentials, string hubName, string streamtitle)
        {
            string encodedStreamTitle = UrlSafeBase64.encodeToString(streamtitle);
            string urlStr             = string.Format("{0}/hubs/{1}/streams/{2}/live", API_BASE_URL, hubName, encodedStreamTitle);

            HttpWebResponse response = null;

            try
            {
                Uri    url      = new Uri(urlStr);
                string macToken = credentials.signRequest(url, "GET", null, null);
                mOkHttpClient           = (HttpWebRequest)HttpWebRequest.Create(url);
                mOkHttpClient.Method    = WebRequestMethods.Http.Get;
                mOkHttpClient.UserAgent = Utils.UserAgent;
                mOkHttpClient.Headers.Add("Authorization", macToken);
                response = (HttpWebResponse)mOkHttpClient.GetResponse();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
                throw new PiliException(e);
            }

            // response never be null
            if ((int)response.StatusCode == 200)
            {
                try
                {
                    StreamReader reader  = new StreamReader(response.GetResponseStream());
                    string       text    = reader.ReadToEnd();
                    JObject      jsonObj = JObject.Parse(text);
                    return(jsonObj);
                }
                catch (IOException e)
                {
                    Console.WriteLine(e.ToString());
                    Console.Write(e.StackTrace);
                    throw new PiliException(e);
                }
            }
            else
            {
                throw new PiliException(response);
            }
        }
Exemplo n.º 4
0
        public static void  disableStream(Credentials credentials, string hubName, string streamtitle, int disabledTill)
        {
            string  encodedStreamTitle = UrlSafeBase64.encodeToString(streamtitle);
            string  urlStr             = string.Format("{0}/hubs/{1}/streams/{2}/disabled", API_BASE_URL, hubName, encodedStreamTitle);
            JObject json = new JObject();

            json.Add("disabledTill", disabledTill);
            HttpWebResponse response = null;

            try
            {
                Uri    url     = new Uri(urlStr);
                string jsonobj = JsonConvert.SerializeObject(json);
                byte[] body    = jsonobj.ToString().GetBytes(Config.UTF8);
                mOkHttpClient = (HttpWebRequest)HttpWebRequest.Create(url);
                string contentType = "application/json";
                string macToken    = credentials.signRequest(url, "POST", body, contentType);
                mOkHttpClient.Method      = WebRequestMethods.Http.Post;
                mOkHttpClient.ContentType = contentType;
                mOkHttpClient.UserAgent   = Utils.UserAgent;
                mOkHttpClient.Headers.Add("Authorization", macToken);
                mOkHttpClient.ContentLength = body.Length;
                using (System.IO.Stream requestStream = mOkHttpClient.GetRequestStream())
                {
                    Utils.CopyN(requestStream, new MemoryStream(body), body.Length);
                }

                response = (HttpWebResponse)mOkHttpClient.GetResponse();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
                throw new PiliException(e);
            }

            // response never be null
            if ((int)response.StatusCode == 200)
            {
                return;
            }
            else
            {
                throw new PiliException(response);
            }
        }
Exemplo n.º 5
0
        public static JObject saveAs(Credentials credentials, string hubName, string stream, string fileName, long start, long end, string format, string pipleline, string notifyUrl, int expireDays)
        {
            if (stream == null)
            {
                throw new PiliException(MessageConfig.NULL_STREAM_ID_EXCEPTION_MSG);
            }

            if (start < 0 || end < 0 || start > end)
            {
                throw new PiliException(MessageConfig.ILLEGAL_TIME_MSG);
            }
            stream = UrlSafeBase64.encodeToString(stream);
            string          urlStr   = string.Format("{0}/hubs/{1}/streams/{2}/saveas", API_BASE_URL, hubName, stream);
            HttpWebResponse response = null;
            JObject         json     = new JObject();

            if (Utils.isArgNotEmpty(fileName))
            {
                json.Add("fname", fileName);
            }
            if (Utils.isArgNotEmpty(notifyUrl))
            {
                json.Add("notifyUrl", notifyUrl);
            }
            if (start != 0)
            {
                json.Add("start", start);
            }
            if (end != 0)
            {
                json.Add("end", end);
            }
            if (Utils.isArgNotEmpty(format))
            {
                json.Add("format", format);
            }
            if (pipleline != "")
            {
                json.Add("pipeline", pipleline);
            }

            if (expireDays >= -1)
            {
                json.Add("expireDays", expireDays);
            }
            try
            {
                Uri url = new Uri(urlStr);
                mOkHttpClient = (HttpWebRequest)HttpWebRequest.Create(url);
                string contentType = "application/json";
                byte[] body        = json.ToString().GetBytes(Config.UTF8);
                string macToken    = credentials.signRequest(url, "POST", body, contentType);
                mOkHttpClient.Method      = WebRequestMethods.Http.Post;
                mOkHttpClient.ContentType = contentType;
                mOkHttpClient.UserAgent   = Utils.UserAgent;
                mOkHttpClient.Headers.Add("Authorization", macToken);
                mOkHttpClient.ContentLength = body.Length;
                using (System.IO.Stream requestStream = mOkHttpClient.GetRequestStream())
                {
                    Utils.CopyN(requestStream, new MemoryStream(body), body.Length);
                }
                response = (HttpWebResponse)mOkHttpClient.GetResponse();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
                throw new PiliException(e);
            }
            // response never be null
            if ((int)response.StatusCode == 200)
            {
                try
                {
                    StreamReader reader  = new StreamReader(response.GetResponseStream());
                    string       text    = reader.ReadToEnd();
                    JObject      jsonObj = JObject.Parse(text);
                    return(jsonObj);
                }
                catch (IOException e)
                {
                    Console.WriteLine(e.ToString());
                    Console.Write(e.StackTrace);
                    throw new PiliException(e);
                }
            }
            else
            {
                throw new PiliException(response);
            }
        }