コード例 #1
0
        public ActionResult Post([FromBody] JToken token)
        {
            string loginguid = string.Empty;

            HttpContext.Request.Cookies.TryGetValue("loginguid", out loginguid);
            string  jsonStr = JsonConvert.SerializeObject(token);
            string  action  = token.Value <string>("action");
            XmlNode node    = JsonConvert.DeserializeXmlNode(jsonStr, "OBJ");
            XmlGet  xmlget  = new XmlGet
            {
                loginguid = loginguid,
                action    = action,
                obj       = node
            };
            var result = PDMUtils.getExportData(xmlget);
            // 保存到Session中,然后返回session的key,也就是随机guid
            string key = Guid.NewGuid().ToString("N");

            _cache.Set(key, result);
            return(Ok(new ResultInfo <string>
            {
                code = "0",
                obj = key
            }));
        }
コード例 #2
0
        public ActionResult Get()
        {
            string loginguid = string.Empty;

            HttpContext.Request.Cookies.TryGetValue("loginguid", out loginguid);
            XmlGet xmlGet = new XmlGet
            {
                loginguid = loginguid
            };

            return(Json(PDMUtils.getMessage(xmlGet)));
        }
コード例 #3
0
        public ActionResult Post([FromBody] JToken token)
        {
            string loginguid = string.Empty;

            HttpContext.Request.Cookies.TryGetValue("loginguid", out loginguid);
            string  jsonStr = JsonConvert.SerializeObject(token);
            string  action  = token.Value <string>("action");
            XmlNode node    = JsonConvert.DeserializeXmlNode(jsonStr, "OBJ");
            XmlGet  xmlget  = new XmlGet
            {
                loginguid = loginguid,
                action    = action,
                obj       = node
            };
            var result = PDMUtils.getDataRows(xmlget);

            return(Json(result));
        }
コード例 #4
0
ファイル: Player.cs プロジェクト: mitchscobell/PlexDL
        private static StreamInfo GetContentDownloadInfo(int index)
        {
            if (index + 1 <= TableManager.ReturnCorrectTable().Rows.Count)
            {
                var result  = TableManager.ReturnCorrectTable().Rows[index];
                var key     = result["key"].ToString();
                var baseUri = Strings.GetBaseUri(false);
                key = key.TrimStart('/');
                var uri = baseUri + key + "/?X-Plex-Token=";

                var reply = XmlGet.GetXmlTransaction(uri, false, false, false);

                var obj = DownloadInfoGatherers.GetContentDownloadInfo(reply);
                return(obj);
            }

            UIMessages.Error(@"Index was higher than row count; could not process data.",
                             @"Indexing Error");
            return(new StreamInfo());
        }
コード例 #5
0
ファイル: XMLCaching.cs プロジェクト: mitchscobell/PlexDL
        public static XmlDocument XmlFromCache(string sourceUrl)
        {
            if (ObjectProvider.Settings.CacheSettings.Mode.EnableXmlCaching)
            {
                if (XmlInCache(sourceUrl))
                {
                    var fqPath = XmlCachePath(sourceUrl);
                    if (ObjectProvider.Settings.CacheSettings.Expiry.Enabled)
                    {
                        if (!CachingExpiry.CheckCacheExpiry(fqPath,
                                                            ObjectProvider.Settings.CacheSettings.Expiry.Interval))
                        {
                            LoggingHelpers.RecordCacheEvent("Cached URL is not expired; loading from cached copy.",
                                                            sourceUrl);
                            var doc = new XmlDocument();
                            doc.Load(fqPath);
                            return(doc);
                        }
                        else
                        {
                            LoggingHelpers.RecordCacheEvent("Cached URL is out-of-date; attempting to get a new copy.",
                                                            sourceUrl);
                            var doc = XmlGet.GetXmlTransaction(sourceUrl, true, false, false);
                            XmlReplaceCache(doc, sourceUrl);
                            return(doc);
                        }
                    }

                    {
                        LoggingHelpers.RecordCacheEvent("Loading from cached copy", sourceUrl);
                        var doc = new XmlDocument();
                        doc.Load(fqPath);
                        return(doc);
                    }
                }

                LoggingHelpers.RecordCacheEvent("URL isn't cached; couldn't load from specified file.", sourceUrl);
            }

            return(new XmlDocument());
        }
コード例 #6
0
        public static XmlMetadata GetMetadata(DataRow result,
                                              string msgNoKey     = "Error occurred whilst getting the unique content key",
                                              string logNoKeyMsg  = "Error occurred whilst getting the unique content key",
                                              string logNoKeyType = "NoUnqKeyError", string column = "key")
        {
            var         obj   = new XmlMetadata();
            XmlDocument reply = null;

            var key = "";

            if (result[column] != null)
            {
                if (!Equals(result[column], string.Empty))
                {
                    key = result[column].ToString();
                }
            }

            if (string.IsNullOrEmpty(key))
            {
                UIMessages.Error(msgNoKey, @"Data Error");
                LoggingHelpers.RecordGeneralEntry("Unique key error");
                LoggingHelpers.RecordException(logNoKeyMsg, logNoKeyType);
            }
            else
            {
                var baseUri = Strings.GetBaseUri(false);
                key = key.TrimStart('/');
                var uri = baseUri + key + "/?X-Plex-Token=";

                LoggingHelpers.RecordGeneralEntry("Contacting the API");
                reply = XmlGet.GetXmlTransaction(uri);
            }

            obj.Xml    = reply;
            obj.ApiUri = $"/{key}";
            return(obj);
        }
コード例 #7
0
        public static List <Server> GetServerRelays()
        {
            try
            {
                var          relays = new List <Server>();
                const string uri    = "https://plex.tv/api/resources?includeHttps=1&includeRelay=1&X-Plex-Token=";

                //cache is disabled for relays. This is because they're always changing, and cache would need to be frequently cleared.
                var reply = XmlGet.GetXmlTransaction(uri, true, true, false);

                //an invalid reply isn't usable; so we just return the blank list declared above :)
                if (!Methods.PlexXmlValid(reply))
                {
                    return(relays);
                }

                var root = reply.SelectSingleNode("MediaContainer");
                //UIMessages.Info(root.Name);

                if (root != null && !root.HasChildNodes)
                {
                    return(relays);
                }

                //null root node is bad news; so we can just return the blank list (no relays
                //are available anyway)
                if (root == null)
                {
                    return(relays);
                }

                for (var i = 0; i < root.ChildNodes.Count; i++)
                {
                    var node        = root.ChildNodes[i];
                    var accessToken = "";

                    if (node.Attributes?["accessToken"] != null)
                    {
                        accessToken = node.Attributes["accessToken"].Value;
                    }

                    var name = node.Attributes?["name"].Value;

                    if (!node.HasChildNodes)
                    {
                        continue;
                    }

                    foreach (XmlNode n in node.ChildNodes)
                    {
                        var u      = new Uri(n.Attributes?["uri"].Value ?? string.Empty);
                        var uParse = u.Host;
                        var local  = n.Attributes?["address"].Value;

                        if (!uParse.Contains(".plex.direct") || Methods.IsPrivateIp(local))
                        {
                            continue;
                        }

                        var address  = uParse;
                        var port     = Convert.ToInt32(n.Attributes?["port"].Value);
                        var svrRelay = new Server
                        {
                            address     = address,
                            port        = port,
                            name        = name,
                            accessToken = accessToken
                        };
                        relays.Add(svrRelay);
                        break;
                    }
                }

                return(relays);
            }
            catch (Exception ex)
            {
                UIMessages.Error("Relay Retrieval Error\n\n" + ex, "Relay Data Error");
                LoggingHelpers.RecordException(ex.Message, "GetRelaysError");
                return(new List <Server>());
            }
        }