예제 #1
0
        public StorageService(CloudAuthenticator authenticator)
            : base(authenticator)
        {
            if (authenticator == null)
                throw new ArgumentNullException(nameof(authenticator));

            _config = new StorageConfiguration();
        }
예제 #2
0
파일: Bucket.cs 프로젝트: neil-119/GAE-NET
        public Bucket(string bucketId, CloudAuthenticator authenticator, StorageConfiguration configuration)
        {
            this._bucketId = bucketId;
            this._authenticator = authenticator;
            this._config = configuration;

            _authenticator.GetInitializer().GZipEnabled = _config.EnableGzip;
            _googleStorageService = new Google.Apis.Storage.v1.StorageService(_authenticator.GetInitializer());
        }
예제 #3
0
        public StorageService(CloudAuthenticator authenticator) : base(authenticator)
        {
            if (authenticator == null)
            {
                throw new ArgumentNullException(nameof(authenticator));
            }

            _config = new StorageConfiguration();
        }
예제 #4
0
        public Bucket(string bucketId, CloudAuthenticator authenticator, StorageConfiguration configuration)
        {
            this._bucketId      = bucketId;
            this._authenticator = authenticator;
            this._config        = configuration;

            _authenticator.GetInitializer().GZipEnabled = _config.EnableGzip;
            _googleStorageService = new Google.Apis.Storage.v1.StorageService(_authenticator.GetInitializer());
        }
예제 #5
0
        public DatastoreService(CloudAuthenticator authenticator, DatastoreConfiguration configuration)
            : this(authenticator)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            Configuration = configuration;
        }
예제 #6
0
        public DatastoreService(CloudAuthenticator authenticator) : base(authenticator)
        {
            if (authenticator == null)
            {
                throw new ArgumentNullException(nameof(authenticator));
            }

            if (IndexContainer == null)
            {
                IndexContainer = new InMemoryIndexContainer();
            }

            Configuration = new DatastoreConfiguration(); // default config
        }
예제 #7
0
        protected DatastoreProvider(CloudAuthenticator authenticator, DatastoreConfiguration configuration, IIndexContainer indexContainer)
        {
            if (authenticator == null)
            {
                throw new NullReferenceException(nameof(authenticator));
            }

            if (configuration == null)
            {
                throw new NullReferenceException(nameof(configuration));
            }

            if (indexContainer == null)
            {
                throw new NullReferenceException(nameof(indexContainer));
            }

            Authenticator  = authenticator;
            Configuration  = configuration;
            IndexContainer = indexContainer;
        }
예제 #8
0
        private bool IsKeyUsed(CloudAuthenticator authenticator, string key)
        {
            // TODO consider using AllocateIds()
            var result = new Google.Apis.Datastore.v1beta3.DatastoreService(authenticator.GetInitializer()).Projects.Lookup(new LookupRequest
            {
                Keys = new List <Key>
                {
                    new Key
                    {
                        Path = new List <PathElement>
                        {
                            new PathElement
                            {
                                Name = key,
                                Kind = typeof(T).Name
                            }
                        }
                    }
                }
            }, authenticator.GetProjectId()).Execute();

            return(result.Found.Any());
        }
예제 #9
0
 public StorageService(CloudAuthenticator authenticator, StorageConfiguration config) : this(authenticator)
 {
     _config = config;
 }
예제 #10
0
 public DatastoreTranslatorProvider(CloudAuthenticator authenticator, DatastoreConfiguration configuration, IIndexContainer indexes)
     : base(authenticator, configuration, indexes)
 {
 }
예제 #11
0
        public List <Entity> SerializeAndAutoKey(IEnumerable <T> entities, CloudAuthenticator authenticator, bool verifyThatIdIsUnused)
        {
            var datastoreEntities = new List <Entity>();

            foreach (var entity in entities)
            {
                var    idPropInfo = QueryHelper.GetIdProperty <T>();
                string key        = null;

                if (idPropInfo != null)
                {
                    var typeCode = idPropInfo.PropertyType.GetTypeCode();
                    switch (typeCode)
                    {
                    case TypeCode.String:
                    {
                        var idField = idPropInfo.GetValue(entity);

                        if (string.IsNullOrWhiteSpace((string)idField))
                        {
                            string autoId;

                            do
                            {
                                autoId = Guid.NewGuid().ToString();
                            } while (verifyThatIdIsUnused && IsKeyUsed(authenticator, autoId));

                            idPropInfo.SetValue(entity, autoId);
                            key = autoId;
                        }
                        else
                        {
                            key = (string)idField;
                        }
                        break;
                    }

                    default:
                        throw new NotSupportedException($"Id type `{typeCode}` is not supported. Id type must be a string.");
                    }
                }
                else
                {
                    // Require that an id or key field exists.
                    throw new MissingMemberException($"`{typeof(T).Name}` does not contain an Id property nor any other property with the DatastoreKey attribute.");
                }

                // TODO(neil-119) Right now the id duplicates the key column, need to change behavior, must account for Select(x => x.key) projection

                // Serialize it.
                var datastoreEntity = SerializeEntity(entity);

                // Setup its key.
                if (datastoreEntity == null)
                {
                    throw new NullReferenceException("Serialized entity is null");
                }

                if (datastoreEntity?.Key?.Path == null)
                {
                    datastoreEntity.Key = new Key {
                        Path = new List <PathElement>()
                    }
                }
                ;

                datastoreEntity.Key.Path.Add(new PathElement
                {
                    Kind = typeof(T).GetTypeInfo().Name,
                    Name = key
                });

                datastoreEntities.Add(datastoreEntity);
            }

            return(datastoreEntities);
        }
예제 #12
0
 public StorageService(CloudAuthenticator authenticator, StorageConfiguration config)
     : this(authenticator)
 {
     _config = config;
 }
예제 #13
0
 protected GAEService(CloudAuthenticator authenticator)
 {
     Authenticator = authenticator;
 }