コード例 #1
0
        public void Add(LicenseContainer license)
        {
            Type licenseType = null;

            foreach (var type in knownLicenseTypes)
            {
                if (license.Is(type))
                {
                    licenseType = type;
                }
            }
            listLocker.Write(licenses =>
            {
                foreach (var l in (licenseType == null
                    ? Enumerable.Empty <LicenseContainer>()
                    : licenses.AsQueryable().OfType(licenseType))
                         .Except(new[] { license }).ToList())
                {
                    licenses.Remove(l);
                }
                licenses.Add(license);
                pathLocker.Write(path => File.WriteAllText(path, licenses.ToJson()));
                LicenseAdded?.Invoke(this, new EventArgs <LicenseContainer>(license));
            });
        }
コード例 #2
0
 public bool Remove(LicenseContainer license)
 {
     return(listLocker.Write(licenses =>
     {
         var res = licenses.Remove(license);
         pathLocker.Write(path => File.WriteAllText(path, licenses.ToJson()));
         LicenseRemoved?.Invoke(this, new EventArgs <LicenseContainer>(license));
         return res;
     }));
 }