public (HttpStatusCode StatusCode, RhinoEnvironmentModel Model) Get(Authentication authentication)
        {
            try
            {
                // ensure
                CreateCollection(authentication);

                // get environment
                var collection            = LiteDb.GetCollection <RhinoEnvironmentModel>(name: Collection);
                var environmentCollection = Get(name: Collection, collection);

                // not found
                if (environmentCollection.StatusCode == HttpStatusCode.NotFound)
                {
                    var onEnvironment = new RhinoEnvironmentModel
                    {
                        Environment = new ConcurrentDictionary <string, object>(),
                        Name        = Collection
                    };

                    return(HttpStatusCode.OK, onEnvironment);
                }

                // append
                var entity = Get(name: Collection, collection).Environment;

                // save
                return(HttpStatusCode.OK, entity);
            }
            catch (Exception e) when(e != null)
            {
                return(HttpStatusCode.InternalServerError, new RhinoEnvironmentModel());
            }
        }
        public void Test(Authentication authentication)
        {
            // ensure
            CreateCollection(authentication);

            // get environment
            var collection            = LiteDb.GetCollection <RhinoEnvironmentModel>(name: Collection);
            var environmentCollection = Get(name: Collection, collection);

            // not found
            if (environmentCollection.StatusCode == HttpStatusCode.NotFound)
            {
                var onEnvironment = new RhinoEnvironmentModel
                {
                    Environment = new ConcurrentDictionary <string, object>(),
                    Name        = Collection
                };

                collection.Insert(onEnvironment);
            }

            if (1 + 1 == 2)
            {
                var a = Get(name: Collection, collection);
            }
        }
        /// <summary>
        /// Creates a new RhinoTestCaseCollection under context.
        /// </summary>
        /// <param name="authentication">Authentication object by which to create RhinoTestCaseCollection.</param>
        /// <param name="data">RhinoTestCaseCollection data to create.</param>
        /// <returns>The <see cref="RhinoTestCaseCollection.Id"/> of the newly created entity.</returns>
        public string Post(Authentication authentication, RhinoTestCaseCollection data)
        {
            // validate
            CreateCollection(authentication);

            // get collection
            var collection = LiteDb.GetCollection <RhinoTestCaseCollection>(name: Collection);

            // insert
            collection.Insert(entity: data);

            // exit conditions
            if (data.Configurations == null || data.Configurations.Count == 0)
            {
                return($"{data.Id}");
            }

            // cascade
            foreach (var configuration in data.Configurations)
            {
                ApplyToConfiguration(authentication, configuration, collection: data);
            }

            // response
            return($"{data.Id}");
        }
        public HttpStatusCode Sync(Authentication authentication)
        {
            try
            {
                // ensure
                CreateCollection(authentication);

                // get environment
                var collection            = LiteDb.GetCollection <RhinoEnvironmentModel>(name: Collection);
                var environmentCollection = Get(name: Collection, collection);

                // not found
                if (environmentCollection.StatusCode == HttpStatusCode.NotFound)
                {
                    return(HttpStatusCode.NotFound);
                }

                // get
                var entity = Get(name: Collection, collection).Environment;
                entity.Environment ??= new ConcurrentDictionary <string, object>();

                // sync
                foreach (var item in entity.Environment)
                {
                    AutomationEnvironment.SessionParams[item.Key] = item.Value;
                }

                // save
                return(HttpStatusCode.OK);
            }
            catch (Exception e) when(e != null)
            {
                return(HttpStatusCode.InternalServerError);
            }
        }
Пример #5
0
        /// <summary>
        /// PUT a new Rhino.Api.Contracts.Configuration.RhinoConfiguration into this domain collection.
        /// </summary>
        /// <param name="authentication">Authentication object by which to access the collection.</param>
        /// <param name="id">Rhino.Api.Contracts.Configuration.RhinoConfiguration.Id to PUT.</param>
        /// <param name="data">The Rhino.Api.Contracts.Configuration.RhinoConfiguration to PUT.</param>
        /// <returns>Status code and configuration (if any).</returns>
        public (HttpStatusCode statusCode, RhinoConfiguration data) Put(Authentication authentication, string id, RhinoConfiguration data)
        {
            // validate
            CreateCollection(authentication);

            // get collection
            var collection = LiteDb.GetCollection <RhinoConfiguration>(name: Collection);

            // get configuration
            var(statusCode, configuration) = Get(id, collection);

            // not found
            if (statusCode == HttpStatusCode.NotFound)
            {
                return(statusCode, configuration);
            }

            // update
            data.Id             = configuration.Id;
            data.Authentication = authentication;
            collection.Update(entity: data);

            // results
            return(HttpStatusCode.OK, data);
        }
Пример #6
0
        /// <summary>
        /// Creates a new RhinoPageModelCollection under context.
        /// </summary>
        /// <param name="authentication">Authentication object by which to create RhinoPageModelCollection.</param>
        /// <param name="data">RhinoPageModelCollection data to create.</param>
        /// <returns>The <see cref="RhinoPageModelCollection.Id"/> of the newly created entity.</returns>
        public string Post(Authentication authentication, RhinoPageModelCollection data)
        {
            // validate
            CreateCollection(authentication);

            // get collection
            var collection = LiteDb.GetCollection <RhinoPageModelCollection>(name: Collection);

            // get models
            var namesToExclude = collection.FindAll().SelectMany(i => i.Models).Select(i => i.Name);

            data.Models = data.Models.Where(i => !namesToExclude.Contains(i.Name)).ToList();

            // insert
            if (data.Models.Count == 0)
            {
                return(string.Empty);
            }
            collection.Insert(entity: data);

            // exit conditions
            if (data.Configurations == null || data.Configurations.Count == 0)
            {
                return($"{data.Id}");
            }

            // cascade
            foreach (var configuration in data.Configurations)
            {
                ApplyToConfiguration(authentication, configuration, collection: data);
            }

            // response
            return($"{data.Id}");
        }
        /// <summary>
        /// Gets a single RhinoTestCaseCollection from context.
        /// </summary>
        /// <param name="authentication">Authentication object by which to get RhinoTestCaseCollection.</param>
        /// <param name="id"><see cref="RhinoTestCaseCollection.Id"/> by which to find this RhinoTestCaseCollection.</param>
        /// <returns>A RhinoTestCaseCollection instance.</returns>
        public (HttpStatusCode statusCode, RhinoTestCaseCollection data) Get(Authentication authentication, string id)
        {
            // validate
            CreateCollection(authentication);

            // get collection
            var collection = LiteDb.GetCollection <RhinoTestCaseCollection>(name: Collection);

            // get configuration
            return(Get(id, collection));
        }
Пример #8
0
        /// <summary>
        /// DELETE all configurations from this domain state.
        /// </summary>
        /// <param name="authentication">Authentication object by which to access the collection.</param>
        /// <returns>Status code.</returns>
        public HttpStatusCode Delete(Authentication authentication)
        {
            // validate
            CreateCollection(authentication);

            // get collection > configuration
            var collection = LiteDb.GetCollection <RhinoConfiguration>(name: Collection);

            // delete
            collection.DeleteAll();
            return(HttpStatusCode.NoContent);
        }
        /// <summary>
        /// Gets all RhinoTestCaseCollection under context.
        /// </summary>
        /// <param name="authentication">Authentication object by which to get RhinoTestCaseCollection.</param>
        /// <returns>A collection of RhinoTestCaseCollection.</returns>
        public (HttpStatusCode statusCode, IEnumerable <RhinoTestCaseCollection> data) Get(Authentication authentication)
        {
            // validate
            CreateCollection(authentication);

            // get collection
            var collection = LiteDb.GetCollection <RhinoTestCaseCollection>(name: Collection);

            collection.EnsureIndex(i => i.Id);

            // get configuration
            return(HttpStatusCode.OK, collection.FindAll());
        }
Пример #10
0
        /// <summary>
        /// GET all configuration in this domain collection.
        /// </summary>
        /// <param name="authentication">Authentication object by which to access the collection.</param>
        /// <returns>Collection of Rhino.Api.Contracts.Configuration.RhinoConfiguration.</returns>
        public IEnumerable <RhinoConfiguration> Get(Authentication authentication)
        {
            // validate
            CreateCollection(authentication);

            // get collection
            var collection = LiteDb.GetCollection <RhinoConfiguration>(name: Collection);

            collection.EnsureIndex(i => i.Id);

            // get configuration
            return(collection.FindAll());
        }
Пример #11
0
        /// <summary>
        /// POST a new Rhino.Api.Contracts.Configuration.RhinoConfiguration into this domain collection.
        /// </summary>
        /// <param name="authentication">Authentication object by which to access the collection.</param>
        /// <param name="data">The Rhino.Api.Contracts.Configuration.RhinoConfiguration to POST.</param>
        /// <returns>Rhino.Api.Contracts.Configuration.RhinoConfiguration.Id.</returns>
        public string Post(Authentication authentication, RhinoConfiguration data)
        {
            // validate
            CreateCollection(authentication);

            // get collection
            var collection = LiteDb.GetCollection <RhinoConfiguration>(name: Collection);

            // security
            data.Authentication = authentication;

            // insert
            collection.Insert(entity: data);

            // results
            return($"{data.Id}");
        }
Пример #12
0
        public int Delete(BsonExpression predicate, bool deleteAllCheck = false)
        {
            if (predicate != null && !deleteAllCheck)
            {
                return(LiteDb.GetCollection <T>(CollectionName).DeleteMany(predicate));
            }

            if (predicate == null && deleteAllCheck)
            {
                return(LiteDb.GetCollection <T>(CollectionName).DeleteAll());
            }

            var errorMessage = "Please check the predicate is null and the deleteAllCheck param as well. The provided predicate is null and the input param deleteAllCheck is to false. If you want to delete all the collection please set the deleteAllCheck param to true.";

            Devon4NetLogger.Error(errorMessage);
            throw new ArgumentException(errorMessage);
        }
Пример #13
0
        /// <summary>
        /// DELETE a configuration from this domain state.
        /// </summary>
        /// <param name="authentication">Authentication object by which to access the collection.</param>
        /// <param name="id">The configuration id by which to DELETE.</param>
        /// <returns>Status code.</returns>
        public HttpStatusCode Delete(Authentication authentication, string id)
        {
            // validate
            CreateCollection(authentication);

            // get collection > configuration
            var collection = LiteDb.GetCollection <RhinoConfiguration>(name: Collection);

            var(statusCode, configuration) = Get(id, collection);

            // not found
            if (statusCode == HttpStatusCode.NotFound)
            {
                return(HttpStatusCode.NotFound);
            }

            // delete
            collection.Delete(configuration.Id);
            return(HttpStatusCode.NoContent);
        }
        private HttpStatusCode DoDelete(Authentication authentication, string name)
        {
            try
            {
                // ensure
                CreateCollection(authentication);

                // get environment
                var collection            = LiteDb.GetCollection <RhinoEnvironmentModel>(name: Collection);
                var environmentCollection = Get(name: Collection, collection);

                // not found
                if (environmentCollection.StatusCode == HttpStatusCode.NotFound)
                {
                    return(HttpStatusCode.NoContent);
                }

                // get
                var entity = Get(name: Collection, collection).Environment;
                entity.Environment ??= new ConcurrentDictionary <string, object>();

                // delete
                if (name.Equals("Delete-Entity -Type RhinoEnvironmentModel", StringComparison.OrdinalIgnoreCase))
                {
                    collection.Delete(entity.Id);
                }
                else if (entity.Environment.ContainsKey(name))
                {
                    entity.Environment.Remove(name);
                    collection.Update(entity);
                }

                // save
                return(HttpStatusCode.NoContent);
            }
            catch (Exception e) when(e != null)
            {
                return(HttpStatusCode.InternalServerError);
            }
        }
        public HttpStatusCode Put(Authentication authentication, string name, string value)
        {
            try
            {
                // ensure
                CreateCollection(authentication);

                // get environment
                var collection            = LiteDb.GetCollection <RhinoEnvironmentModel>(name: Collection);
                var environmentCollection = Get(name: Collection, collection);

                // not found
                if (environmentCollection.StatusCode == HttpStatusCode.NotFound)
                {
                    var onEnvironment = new RhinoEnvironmentModel
                    {
                        Environment = new ConcurrentDictionary <string, object>(),
                        Name        = Collection
                    };

                    collection.Insert(onEnvironment);
                }

                // append
                var entity = Get(name: Collection, collection).Environment;
                entity.Environment[name] = value;

                // save
                collection.Update(entity);
                return(HttpStatusCode.OK);
            }
            catch (Exception e) when(e != null)
            {
                return(HttpStatusCode.InternalServerError);
            }
        }
Пример #16
0
        public BsonValue Create(T entity)
        {
            var result = LiteDb.GetCollection <T>(CollectionName).Insert(entity);

            return(result);
        }
Пример #17
0
 public bool Update(T entity)
 {
     return(LiteDb.GetCollection <T>(CollectionName).Update(entity));
 }
Пример #18
0
 public IEnumerable <T> Get()
 {
     return(LiteDb.GetCollection <T>(CollectionName).FindAll());
 }
Пример #19
0
 public IEnumerable <T> Get(BsonExpression predicate, int skip = 0, int limit = int.MaxValue)
 {
     return(LiteDb.GetCollection <T>(CollectionName).Find(predicate, skip, limit));
 }
Пример #20
0
 public T GetFirstOrDefault(Query query)
 {
     return(LiteDb.GetCollection <T>(CollectionName).FindOne(query));
 }
Пример #21
0
 public T GetFirstOrDefault(BsonExpression predicate)
 {
     return(LiteDb.GetCollection <T>(CollectionName).FindOne(predicate));
 }