コード例 #1
0
        public ICommandResult Handle(CreateAccessKeyCommand command)
        {
            command.Validate();
            if (Invalid)
            {
                return(new GenericCommandResult(false, "Admin inválido", command.Notifications));
            }

            var admin = _adminRepository.GetAdmin(command.Admin);

            if (admin == null)
            {
                return(new GenericCommandResult(false, "Admin inválido", command.Notifications));
            }

            var key = new KeyAccess();

            key.GenerateKeyAccess();

            key.ValidateKey();

            _keyAccessRepository.Create(key);

            return(new GenericCommandResult(true, "Chave gerada com sucesso", key));
        }
コード例 #2
0
        public Download this[string key, KeyAccess access]
        {
            get
            {
                try
                {
                    Lock();
                    switch (access)
                    {
                    case KeyAccess.FileHash:
                        return(m_DownloadID[m_FileHash[key]]);

                    case KeyAccess.OnceHashedFileHash:
                        return(m_DownloadID[m_OnceHashedFileHash[key]]);

                    case KeyAccess.TwiceHashedFileHash:
                        return(m_DownloadID[m_TwiceHashedFileHash[key]]);

                    case KeyAccess.ThriceHashedFileHash:
                        return(m_DownloadID[m_ThriceHashedFileHash[key]]);

                    default:
                        return(m_DownloadID[key]);
                    }
                }
                finally
                {
                    Unlock();
                }
            }
            set
            {
                throw new NotSupportedException();
            }
        }
コード例 #3
0
        public bool ContainsKey(string key, KeyAccess access)
        {
            try
            {
                Lock();
                switch (access)
                {
                case KeyAccess.FileHash:
                    return(m_FileHash.ContainsKey(key));

                case KeyAccess.OnceHashedFileHash:
                    return(m_OnceHashedFileHash.ContainsKey(key));

                case KeyAccess.TwiceHashedFileHash:
                    return(m_TwiceHashedFileHash.ContainsKey(key));

                case KeyAccess.ThriceHashedFileHash:
                    return(m_ThriceHashedFileHash.ContainsKey(key));

                default:
                    return(m_DownloadID.ContainsKey(key));
                }
            }
            finally
            {
                Unlock();
            }
        }
コード例 #4
0
 public static extern int RegOpenKeyEx
 (
     UIntPtr hkey,
     String lpSubKey,
     uint ulOptions,
     KeyAccess samDesired,
     ref UIntPtr phkResult
 );
コード例 #5
0
 public static extern int RegCreateKeyEx
 (
     UIntPtr hkey,
     String lpSubKey,
     uint Reserved,
     StringBuilder lpClass,
     uint dwOptions,
     KeyAccess samDesired,
     IntPtr lpSecurityAttributes,
     ref UIntPtr phkResult,
     ref uint lpdwDisposition
 );
コード例 #6
0
        public object GetValue(object target)
        {
            var    type  = target.GetType();
            object value = null;

            if (KeyAccess.HasAccessFor(type))
            {
                var key      = KeyAccess.GetId(target, type);
                var metadata = MetadataProvider.GetMetadata(key);
                value = Getter(metadata);
            }
            return(value);
        }
コード例 #7
0
        public void SetValue(object target, object value)
        {
            var type = target.GetType();

            if (!KeyAccess.HasAccessFor(type))
            {
                return;
            }

            var key      = KeyAccess.GetId(target, type);
            var metadata = MetadataProvider.GetMetadata(key);

            Setter(metadata, value);
        }
コード例 #8
0
        public bool TryGetValue(string key, KeyAccess access, out Download download)
        {
            try
            {
                Lock();
                string downloadID;
                switch (access)
                {
                case KeyAccess.FileHash:
                    if (m_FileHash.TryGetValue(key, out downloadID))
                    {
                        return(m_DownloadID.TryGetValue(downloadID, out download));
                    }
                    download = null;
                    return(false);

                case KeyAccess.OnceHashedFileHash:
                    if (m_OnceHashedFileHash.TryGetValue(key, out downloadID))
                    {
                        return(m_DownloadID.TryGetValue(downloadID, out download));
                    }
                    download = null;
                    return(false);

                case KeyAccess.TwiceHashedFileHash:
                    if (m_TwiceHashedFileHash.TryGetValue(key, out downloadID))
                    {
                        return(m_DownloadID.TryGetValue(downloadID, out download));
                    }
                    download = null;
                    return(false);

                case KeyAccess.ThriceHashedFileHash:
                    if (m_ThriceHashedFileHash.TryGetValue(key, out downloadID))
                    {
                        return(m_DownloadID.TryGetValue(downloadID, out download));
                    }
                    download = null;
                    return(false);

                default:
                    return(m_DownloadID.TryGetValue(key, out download));
                }
            }
            finally
            {
                Unlock();
            }
        }
コード例 #9
0
        public int IndexOfKey(string key, KeyAccess access)
        {
            try
            {
                Lock();
                string downloadID;
                switch (access)
                {
                case KeyAccess.FileHash:
                    if (m_FileHash.TryGetValue(key, out downloadID))
                    {
                        return(m_DownloadID.IndexOfKey(downloadID));
                    }
                    return(-1);

                case KeyAccess.OnceHashedFileHash:
                    if (m_OnceHashedFileHash.TryGetValue(key, out downloadID))
                    {
                        return(m_DownloadID.IndexOfKey(downloadID));
                    }
                    return(-1);

                case KeyAccess.TwiceHashedFileHash:
                    if (m_TwiceHashedFileHash.TryGetValue(key, out downloadID))
                    {
                        return(m_DownloadID.IndexOfKey(downloadID));
                    }
                    return(-1);

                case KeyAccess.ThriceHashedFileHash:
                    if (m_ThriceHashedFileHash.TryGetValue(key, out downloadID))
                    {
                        return(m_DownloadID.IndexOfKey(downloadID));
                    }
                    return(-1);

                default:
                    return(m_DownloadID.IndexOfKey(key));
                }
            }
            finally
            {
                Unlock();
            }
        }
コード例 #10
0
        public SharedFile this[string key, KeyAccess access]
        {
            get
            {
                try
                {
                    Lock();
                    switch (access)
                    {
                    case KeyAccess.OnceHashedFileHash:
                        return(m_FileHash[m_OnceHashedFileHash[key]]);

                    case KeyAccess.TwiceHashedFileHash:
                        return(m_FileHash[m_TwiceHashedFileHash[key]]);

                    case KeyAccess.ThriceHashedFileHash:
                        return(m_FileHash[m_ThriceHashedFileHash[key]]);

                    default:
                        return(m_FileHash[key]);
                    }
                }
                finally
                {
                    Unlock();
                }
            }
            set
            {
                try
                {
                    Lock();
                    if (access != KeyAccess.FileHash)
                    {
                        throw new NotSupportedException();
                    }
                    m_FileHash[key] = value;
                }
                finally
                {
                    Unlock();
                }
            }
        }
コード例 #11
0
        public bool TryGetValue(string key, KeyAccess access, out SharedFile sharedFile)
        {
            try
            {
                Lock();
                string fileHash;
                switch (access)
                {
                case KeyAccess.OnceHashedFileHash:
                    if (m_OnceHashedFileHash.TryGetValue(key, out fileHash))
                    {
                        return(m_FileHash.TryGetValue(fileHash, out sharedFile));
                    }
                    sharedFile = null;
                    return(false);

                case KeyAccess.TwiceHashedFileHash:
                    if (m_TwiceHashedFileHash.TryGetValue(key, out fileHash))
                    {
                        return(m_FileHash.TryGetValue(fileHash, out sharedFile));
                    }
                    sharedFile = null;
                    return(false);

                case KeyAccess.ThriceHashedFileHash:
                    if (m_ThriceHashedFileHash.TryGetValue(key, out fileHash))
                    {
                        return(m_FileHash.TryGetValue(fileHash, out sharedFile));
                    }
                    sharedFile = null;
                    return(false);

                default:
                    return(m_FileHash.TryGetValue(key, out sharedFile));
                }
            }
            finally
            {
                Unlock();
            }
        }
コード例 #12
0
		public static extern int RegOpenKeyEx
		(
			UIntPtr hkey,
			String lpSubKey,
			uint ulOptions,
			KeyAccess samDesired,
			ref UIntPtr phkResult
		);
コード例 #13
0
		public static extern int RegCreateKeyEx
		(
			UIntPtr hkey,
			String lpSubKey,
			uint Reserved,
			StringBuilder lpClass,
			uint dwOptions,
			KeyAccess samDesired,              
			IntPtr lpSecurityAttributes,
			ref UIntPtr phkResult,
			ref uint lpdwDisposition
		);
コード例 #14
0
 public void Update(KeyAccess keyAccess)
 {
     _context.Entry(keyAccess).State = EntityState.Modified;
     _context.SaveChanges();
 }
コード例 #15
0
 public void Create(KeyAccess keyAccess)
 {
     _context.KeyAccess.Add(keyAccess);
     _context.SaveChanges();
 }
コード例 #16
0
 public void AddKeyAccess(KeyAccess keyAccess)
 {
     KeyAccess = keyAccess;
     KeyAccess.HasUser();
 }