Esempio n. 1
0
        public async Task <IActionResult> OnPostSetCredentialsAsync()
        {
            try
            {
                GD3.AuthHeader authCD = new GD3.AuthHeader()
                {
                    Password = this.Password, Username = this.UserName
                };
                GD3DVD.AuthHeader authDVD = new GD3DVD.AuthHeader()
                {
                    Password = this.Password, Username = this.UserName
                };
                var l = await metaDataGD3.GetNumberLookupsRemainingAsync(authCD, authDVD);

                StringBuilder sb = new StringBuilder();
                sb.Append("CD number of lookups remaining query => ");
                if (l.CD.HasValue)
                {
                    sb.Append("Success ("); sb.Append(l.CD.Value); sb.Append(")\n");
                }
                else
                {
                    sb.Append("Error: "); sb.Append(l.ErrorCD);
                }
                sb.Append('\n');
                sb.Append("DVD number of lookups remaining query => ");
                if (l.DVD.HasValue)
                {
                    sb.Append("Success ("); sb.Append(l.DVD.Value); sb.Append(")\n");
                }
                else
                {
                    sb.Append("Error: "); sb.Append(l.ErrorDVD);
                }
                sb.Append('\n');
                if (l.CD == null && l.DVD == null)
                {
                    throw new Exception("GD3 no access to CD / DVD services with these credentials");
                }
                metaDataGD3.SetCredentials(UserName, Password);
                sb.Append("Credentials Saved");
                metaDataGD3.CurrentLookupsRemaining = l;
                Message = sb.ToString();
            }
            catch (Exception e)
            {
                Message += "\nException:" + e.Message;
            }

            return(Page());
        }
Esempio n. 2
0
 public void SetCredentials(string userName, string passWord)
 {
     if (!String.IsNullOrEmpty(userName) && !String.IsNullOrEmpty(passWord))
     {
         settings.UserName = _protector.Protect(userName);
         settings.Password = _protector.Protect(passWord);
         authCD            = new GD3.AuthHeader()
         {
             Username = userName, Password = passWord
         };
         authDVD = new GD3DVD.AuthHeader()
         {
             Username = userName, Password = passWord
         };
     }
     else
     {
         settings.UserName = null; settings.Password = null; authCD = null; authDVD = null;
     }
     UpdateLookupsRemaining();
     SaveSettings();
 }
Esempio n. 3
0
        public MetaDataGD3(IDataProtectionProvider provider, string contentRootPath, string GD3Path, string GD3RelPath)
        {
            _protector = provider.CreateProtector("DiscChanger.NET.GD3");

            settingsJsonFileName = Path.Combine(contentRootPath, "GD3settings.json");
            try
            {
                settings = File.Exists(settingsJsonFileName) ? JsonSerializer.Deserialize <Settings>(File.ReadAllBytes(settingsJsonFileName)) : new Settings();
                if (settings?.UserName != null && settings?.Password != null)
                {
                    var u = _protector.Unprotect(settings.UserName);
                    var p = _protector.Unprotect(settings.Password);
                    authCD = new GD3.AuthHeader()
                    {
                        Username = u, Password = p
                    };
                    authDVD = new GD3DVD.AuthHeader()
                    {
                        Username = u, Password = p
                    };
                    UpdateLookupsRemaining();
                }
            }
            catch (Exception e)
            {
                if (settings == null)
                {
                    settings = new Settings();
                }
                System.Diagnostics.Debug.WriteLine($"Error {e.Message} reading or processing GD3 settings from: {settingsJsonFileName}");
            }
            this.GD3Path   = GD3Path;
            this.GD3CDPath = Path.Combine(GD3Path, "CD");
            var dirGD3CD = Directory.CreateDirectory(GD3CDPath);

            this.GD3DVDPath = Path.Combine(GD3Path, "DVD");
            var dirGD3DVD = Directory.CreateDirectory(GD3DVDPath);

            this.GD3BDPath = Path.Combine(GD3Path, "BD");
            var dirGD3BD = Directory.CreateDirectory(GD3BDPath);

            this.GD3RelPath    = GD3RelPath;
            this.GD3CDRelPath  = GD3RelPath + "/CD";
            this.GD3DVDRelPath = GD3RelPath + "/DVD";
            this.GD3BDRelPath  = GD3RelPath + "/BD";

            foreach (var fileInfo in dirGD3CD.GetFiles("Match_*.json"))
            {
                MatchCD m = JsonSerializer.Deserialize <MatchCD>(File.ReadAllText(fileInfo.FullName));
                m.SetMetaDataGD3(this);
                string baseName = Path.GetFileNameWithoutExtension(fileInfo.Name);
                nameToMatchCD[baseName]   = m;
                lengths2NameCD[m.Lengths] = baseName;
            }
            foreach (var fileInfo in dirGD3DVD.GetFiles("Match_*.json"))
            {
                MatchDVD m = JsonSerializer.Deserialize <MatchDVD>(File.ReadAllText(fileInfo.FullName));
                m.SetMetaDataGD3(this);
                string baseName = Path.GetFileNameWithoutExtension(fileInfo.Name);
                nameToMatchDVD[baseName] = m;
                if (!String.IsNullOrEmpty(m.GraceNoteDiscID))
                {
                    graceNoteID2NameDVD[m.GraceNoteDiscID] = baseName;
                }
            }
            foreach (var fileInfo in dirGD3BD.GetFiles("Match_*.json"))
            {
                MatchBD m = JsonSerializer.Deserialize <MatchBD>(File.ReadAllText(fileInfo.FullName));
                m.SetMetaDataGD3(this);
                string baseName = Path.GetFileNameWithoutExtension(fileInfo.Name);
                nameToMatchBD[baseName] = m;
                if (m.AACSDiscID != null && m.AACSDiscID.Length > 0)
                {
                    AACSDiscID2NameBD[m.AACSDiscID] = baseName;
                }
            }
            foreach (var fileInfo in dirGD3CD.GetFiles("Meta_*.json"))
            {
                MetaDataCD m = JsonSerializer.Deserialize <MetaDataCD>(File.ReadAllText(fileInfo.FullName));
                cdCodeToMetaData[m.AlbumCode] = m;
            }
            foreach (var fileInfo in dirGD3DVD.GetFiles("Meta_*.json").Concat(dirGD3BD.GetFiles("Meta_*.json")))
            {
                MetaDataDVD m = JsonSerializer.Deserialize <MetaDataDVD>(File.ReadAllText(fileInfo.FullName));
                dvdCodeDiscIDToMetaData[Tuple.Create(m.DVDCode, m.DiscID)] = m;
            }
        }
Esempio n. 4
0
        public async Task <LookupsRemaining> GetNumberLookupsRemainingAsync(GD3.AuthHeader ahCD, GD3DVD.AuthHeader ahDVD)
        {
            var l = new LookupsRemaining();

            try
            {
                var r = await SoapClientCD.GetNumberOfLookupsRemainingAsync(ahCD);

                l.CD = r.GetNumberOfLookupsRemainingResult;
            }
            catch (Exception e)
            {
                l.ErrorCD = e.Message;
            }
            try
            {
                var r = await SoapClientDVD.GetNumberOfLookupsRemainingAsync(ahDVD);

                l.DVD = r.GetNumberOfLookupsRemainingResult;
            }
            catch (Exception e)
            {
                l.ErrorDVD = e.Message;
            }
            return(l);
        }