Beispiel #1
0
        // these 2 methods must be called in sequence
        public bool Initialize(string provider, Dictionary <string, string> parameters)
        {
            dvdsByName     = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
            dvdsById       = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
            dvdsBySortName = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            if (!string.IsNullOrEmpty(collectionPath) && File.Exists(collectionPath))
            {
                using (XmlTextReader reader = new XmlTextReader(collectionPath))
                {
                    document = new XPathDocument(reader);

                    var navigator = document.CreateNavigator();

                    foreach (XPathNavigator dvd in navigator.Select("/Collection/DVD|/DVD")) // Allow both collection file and single profile export
                    {
                        string name     = null;
                        string id       = null;
                        string sortName = null;

                        foreach (XPathNavigator dvdElement in dvd.SelectChildren(XPathNodeType.Element))
                        {
                            if (dvdElement.Name == "ID")
                            {
                                id = dvdElement.Value;
                            }
                            else if (dvdElement.Name == "Title")
                            {
                                name = dvdElement.Value;
                            }
                            else if (dvdElement.Name == "SortTitle")
                            {
                                sortName = dvdElement.Value;
                            }

                            if (name != null && id != null && sortName != null)
                            {
                                name = CleanString(SDKUtilities.GetFolderNameString(name));

                                if (dvdsByName.ContainsKey(name))
                                {
                                    name += " " + Guid.NewGuid().ToString();
                                }

                                dvdsByName.Add(name, id);

                                sortName = CleanString(SDKUtilities.GetFolderNameString(sortName));

                                if (dvdsBySortName.ContainsKey(sortName))
                                {
                                    sortName += " " + Guid.NewGuid().ToString();
                                }

                                dvdsBySortName.Add(sortName, id);

                                if (!dvdsById.ContainsKey(id))
                                {
                                    dvdsById.Add(id, name);
                                }

                                break;
                            }
                        }
                    }
                }
            }

            return(true);
        }