public HashSet <string> ParseSource(ISkAdNetworkSource source)
        {
            var foundIds = new HashSet <string>();

            try
            {
                string jsonData;
                using (var stream = source.Open())
                {
                    if (stream == null)
                    {
                        Debug.LogWarning($"[Unity SKAdNetwork Parser] Unable to parse SKAdNetwork file: {source.Path}");
                        return(foundIds);
                    }

                    jsonData = new StreamReader(stream).ReadToEnd();
                }

                SkAdNetworkIdArray skAdNetworkCompanyInfo = null;
                try
                {
                    skAdNetworkCompanyInfo = JsonUtility.FromJson <SkAdNetworkIdArray>(jsonData);
                }
                catch (Exception) {}

                //Fallback to try and see if this is a JSONObject which contains an array element called skadnetwork_ids instead of the expected JSONArray
                if (skAdNetworkCompanyInfo?.skadnetwork_ids == null || skAdNetworkCompanyInfo.skadnetwork_ids.Count == 0)
                {
                    var updatedJson = "{\"skadnetwork_ids\":" + jsonData + "}";
                    skAdNetworkCompanyInfo = JsonUtility.FromJson <SkAdNetworkIdArray>(updatedJson);
                }

                if (skAdNetworkCompanyInfo?.skadnetwork_ids == null)
                {
                    Debug.LogWarning($"[Unity SKAdNetwork Parser] Unable to parse SKAdNetwork file: {source.Path}");
                    return(foundIds);
                }

                foundIds.UnionWith(skAdNetworkCompanyInfo.skadnetwork_ids.Select(t => t.skadnetwork_id).Where(t => t != null));
            }
            catch (Exception)
            {
                Debug.LogWarning($"[Unity SKAdNetwork Parser] Unable to parse SKAdNetwork file: {source.Path}");
            }

            return(foundIds);
        }
Example #2
0
        public HashSet <string> ParseSource(ISkAdNetworkSource source)
        {
            var foundIds = new HashSet <string>();

            try
            {
                string[] lines;
                using (var reader = new StreamReader(source.Open()))
                {
                    lines = reader.ReadToEnd().Split(Environment.NewLine.ToCharArray());
                }

                lines.Where(url => !string.IsNullOrEmpty(url))
                .Where(url => Uri.IsWellFormedUriString(url, UriKind.Absolute))
                .ToList().ForEach(url => {
                    ISkAdNetworkParser parser = null;
                    switch (GetExtensionFromPath(url))
                    {
                    case SkAdNetworkFileExtension.XML:
                        parser = SkAdNetworkParser.GetParser(SkAdNetworkFileExtension.XML);
                        break;

                    case SkAdNetworkFileExtension.JSON:
                        parser = SkAdNetworkParser.GetParser(SkAdNetworkFileExtension.JSON);
                        break;
                    }

                    if (parser == null)
                    {
                        Debug.LogWarning($"[Unity SKAdNetwork Parser] Unsupported file extension, No parser available to parse SKAdNetwork file: {source.Path} ");
                        return;
                    }

                    foundIds.UnionWith(parser.ParseSource(new SkAdNetworkRemoteSource(url)));
                });
            }
            catch (Exception)
            {
                Debug.LogWarning($"[Unity SKAdNetwork Parser] Unable to parse SKAdNetwork file: {source.Path}");
            }

            return(foundIds);
        }
        public HashSet <string> ParseSource(ISkAdNetworkSource source)
        {
            var foundIds = new HashSet <string>();

            try
            {
                var xmlDocument = new XmlDocument();

                using (var stream = source.Open())
                {
                    if (stream == null)
                    {
                        Debug.LogWarning("[Unity SKAdNetwork Parser] Unable to parse SKAdNetwork file: {source.Path}");
                        return(foundIds);
                    }

                    xmlDocument.Load(stream);
                }

                var items = xmlDocument.GetElementsByTagName("key");
                for (var x = 0; x < items.Count; x++)
                {
                    if (items[x].InnerText == k_SkAdNetworkIdentifier)
                    {
                        var nextSibling = items[x]?.NextSibling;
                        if (nextSibling != null)
                        {
                            foundIds.Add(nextSibling.InnerText);
                        }
                    }
                }
            }
            catch (Exception)
            {
                Debug.LogWarning($"[Unity SKAdNetwork Parser] Unable to parse SKAdNetwork file: {source.Path}");
            }

            return(foundIds);
        }