Example #1
0
        public IEnumerable <DownloadPackageQuery> QueryLinks(JdDevice device)
        {
            dynamic obj = new ExpandoObject();

            obj.bytesTotal   = true;
            obj.comment      = true;
            obj.status       = true;
            obj.enabled      = true;
            obj.packageUUIDs = null;
            obj.host         = true;
            obj.url          = true;
            obj.finished     = true;
            obj.running      = true;
            string  json       = JsonConvert.SerializeObject(obj);
            var     param      = new[] { json };
            string  result     = CallAction(device, "/downloadsV2/queryLinks", param);
            dynamic jsonObject = JObject.Parse(result);
            dynamic links      = jsonObject.data.ToObject <List <DownloadPackageQuery> >();

            if (string.IsNullOrEmpty(result))
            {
                return(null);
            }
            return(links);
        }
Example #2
0
        public void RestartJd(JdDevice device)
        {
            string response = CallAction(device, "/system/restartJD", null);

            if (!string.IsNullOrEmpty(response))
            {
                dynamic jsonContent = JObject.Parse(response);
                string  data        = jsonContent.data;
            }
        }
Example #3
0
        public bool Start(JdDevice device)
        {
            string result = CallAction(device, "/downloadcontroller/start", null);

            if (string.IsNullOrEmpty(result))
            {
                return(false);
            }
            return(true);
        }
Example #4
0
        public string PackageCount(JdDevice device)
        {
            string response = CallAction(device, "/downloadsV2/packageCount", null);

            if (!string.IsNullOrEmpty(response))
            {
                dynamic jsonContent = JObject.Parse(response);
                return(jsonContent.data);
            }
            return("");
        }
Example #5
0
        public string GetSpeedInBps(JdDevice device)
        {
            string response = CallAction(device, "/downloadcontroller/getSpeedInBps", null);

            if (!string.IsNullOrEmpty(response))
            {
                dynamic jsonContent = JObject.Parse(response);
                return(jsonContent.data);
            }
            return("");
        }
Example #6
0
        private string CallAction(JdDevice device, string action, dynamic param)
        {
            if (Devices == null || Devices.Count == 0)
            {
                Debug.WriteLine("No device or not enumerate device list yet");
                return(null);
            }

            if (!Devices.Contains(device))
            {
                Debug.WriteLine("No device with the given name");
                return(null);
            }
            if (string.IsNullOrEmpty(device.Id))
            {
                Debug.WriteLine("Device is found with empty id");
                return(null);
            }
            string  query = "/t_" + HttpUtility.UrlEncode(_sessiontoken) + "_" + HttpUtility.UrlEncode(device.Id) + action;
            dynamic p     = new ExpandoObject();

            p.url = action;
            if (param != null)
            {
                p.@params = param;
            }
            p.rid    = GetUniqueRid();
            p.ApiVer = ApiVer;
            string json = Newtonsoft.Json.JsonConvert.SerializeObject(p);

            File.WriteAllText("json.txt", json);

            json = Encrypt(json, _deviceEncryptionToken);
            string url      = ApiUrl + query;
            string response = PostQuery(url, json, _deviceEncryptionToken);

            if (string.IsNullOrEmpty(response))
            {
                return(null);
            }
            dynamic jsonContent    = JObject.Parse(response);
            int     jsonContentRid = jsonContent.rid;

            if (!jsonContentRid.Equals(_ridCounter) && jsonContentRid > 0)
            {
                Debug.WriteLine("error: rid mismatch!\n");
                return(null);
            }
            Debug.WriteLine("url=" + url);
            Debug.WriteLine("response=" + response);
            return(response);
        }
 public bool AddLink(JdDevice device, string link, string package)
 {
     dynamic obj = new ExpandoObject();
     obj.priority = "DEFAULT";
     obj.links = link;
     obj.autostart = true;
     obj.packageName = package;
     string json = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
     var param = new[] { json };
     string result = CallAction(device, "/linkgrabberv2/addLinks", param);
     if (string.IsNullOrEmpty(result))
         return false;
     return true;
 }
Example #8
0
        public bool AddLink(JdDevice device, string link, string package)
        {
            dynamic obj = new ExpandoObject();

            obj.priority    = "DEFAULT";
            obj.links       = link;
            obj.autostart   = true;
            obj.packageName = package;
            string json   = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
            var    param  = new[] { json };
            string result = CallAction(device, "/linkgrabberv2/addLinks", param);

            if (string.IsNullOrEmpty(result))
            {
                return(false);
            }
            return(true);
        }
        private string CallAction(JdDevice device, string action, dynamic param)
        {
            if (Devices == null || Devices.Count == 0)
            {
                Debug.WriteLine("No device or not enumerate device list yet");
                return null;
            }

            if (!Devices.Contains(device))
            {
                Debug.WriteLine("No device with the given name");
                return null;
            }
            if (string.IsNullOrEmpty(device.Id))
            {
                Debug.WriteLine("Device is found with empty id");
                return null;
            }
            string query = "/t_" + HttpUtility.UrlEncode(_sessiontoken) + "_" + HttpUtility.UrlEncode(device.Id) + action;
            dynamic p = new ExpandoObject();
            p.url = action;
            if (param != null)
            {
                p.@params = param;
            }
            p.rid = GetUniqueRid();
            p.ApiVer = ApiVer;
            string json = Newtonsoft.Json.JsonConvert.SerializeObject(p);
            File.WriteAllText("json.txt", json);

            json = Encrypt(json, _deviceEncryptionToken);
            string url = ApiUrl + query;
            string response = PostQuery(url, json, _deviceEncryptionToken);
            if (string.IsNullOrEmpty(response))
                return null;
            dynamic jsonContent = JObject.Parse(response);
            int jsonContentRid = jsonContent.rid;
            if (!jsonContentRid.Equals(_ridCounter) && jsonContentRid > 0)
            {
                Debug.WriteLine("error: rid mismatch!\n");
                return null;
            }
            Debug.WriteLine("url=" + url);
            Debug.WriteLine("response=" + response);
            return response;
        }
Example #10
0
 public bool Stop(JdDevice device)
 {
     string result = CallAction(device, "/downloadcontroller/stop", null);
     if (string.IsNullOrEmpty(result))
     {
         return false;
     }
     return true;
 }
Example #11
0
 public void RestartJd(JdDevice device)
 {
     string response = CallAction(device, "/system/restartJD", null);
     if (!string.IsNullOrEmpty(response))
     {
         dynamic jsonContent = JObject.Parse(response);
         string data = jsonContent.data;
     }
 }
Example #12
0
 public IEnumerable<DownloadPackageQuery> QueryLinks(JdDevice device)
 {
     dynamic obj = new ExpandoObject();
     obj.bytesTotal = true;
     obj.comment = true;
     obj.status = true;
     obj.enabled = true;
     obj.packageUUIDs = null;
     obj.host = true;
     obj.url = true;
     obj.finished = true;
     obj.running = true;
     string json = JsonConvert.SerializeObject(obj);
     var param = new[] { json };
     string result = CallAction(device, "/downloadsV2/queryLinks", param);
     dynamic jsonObject = JObject.Parse(result);
     dynamic links = jsonObject.data.ToObject<List<DownloadPackageQuery>>();
     if (string.IsNullOrEmpty(result))
         return null;
     return links;
 }
Example #13
0
 public string PackageCount(JdDevice device)
 {
     string response = CallAction(device, "/downloadsV2/packageCount", null);
     if (!string.IsNullOrEmpty(response))
     {
         dynamic jsonContent = JObject.Parse(response);
         return jsonContent.data;
     }
     return "";
 }
Example #14
0
 public string GetSpeedInBps(JdDevice device)
 {
     string response = CallAction(device, "/downloadcontroller/getSpeedInBps", null);
     if (!string.IsNullOrEmpty(response))
     {
         dynamic jsonContent = JObject.Parse(response);
         return jsonContent.data;
     }
     return "";
 }