/// <summary>
        /// GET Verb method
        /// </summary>
        internal string GetMethod()
        {
            var screenItem = RequestTransforms.GetScreenFieldsNested(Screen);

            var properties = GetScreenItemProperties(screenItem);

            return($@"
        /// <summary>
        /// {Screen.Title} Get
        /// </summary>
        public virtual async Task<{Screen.FormResponseClass}> GetAsync(ObjectId id)
        {{
            if (id == ObjectId.Empty)
            {{
                throw new ArgumentException(""Invalid ObjectId"", ""id"");
            }}
            
            var filter = Builders<{Screen.Entity.InternalName}>.Filter.Eq(a => a.Id, id);
            var query = _context.{Screen.Entity.InternalNamePlural}.Find(filter)
                .Project(p => new {Screen.FormResponseClass}() {{
{properties.IndentLines(5, ",")}
                }});
            var result = await query.SingleOrDefaultAsync();

            return result;
        }}");
        }
Exemple #2
0
        public IEnumerable <string> Validate()
        {
            if (Transport == null)
            {
                yield return("Transport implementation is not set. It is a required part of configuration.");
            }

            if (ClusterProvider == null)
            {
                yield return("Cluster provider implementation is not set. It is a required part of configuration.");
            }

            if (ResponseCriteria?.Count > 0)
            {
                var lastCriterion = ResponseCriteria.Last();
                if (!(lastCriterion is AlwaysRejectCriterion) && !(lastCriterion is AlwaysAcceptCriterion))
                {
                    yield return($"Last response criterion must always be either an '{typeof (AlwaysRejectCriterion).Name}' or '{typeof (AlwaysAcceptCriterion).Name}'.");
                }
            }

            if (ResponseCriteria != null && ResponseCriteria.Any(criterion => criterion == null))
            {
                yield return("One of provided response criteria is null");
            }

            if (RequestTransforms != null && RequestTransforms.Any(transform => transform == null))
            {
                yield return("One of provided request transforms is null");
            }

            if (ResponseTransforms != null && ResponseTransforms.Any(transform => transform == null))
            {
                yield return("One of provided response transforms is null");
            }

            if (Modules != null && Modules.Any(module => module == null))
            {
                yield return("One of provided request modules is null");
            }

            if (DefaultTimeout <= TimeSpan.Zero)
            {
                yield return($"Default timeout must be positive, but was '{DefaultTimeout}'");
            }

            if (MaxReplicasUsedPerRequest <= 0)
            {
                yield return($"Maximum replicas per request must be > 0, but was {MaxReplicasUsedPerRequest}");
            }
        }
Exemple #3
0
        /// <summary>
        /// POST Verb Method, for adding new records
        /// </summary>
        internal string PostMethod()
        {
            // TODO: Phase 2 get screen section properties that are appropriate using required expression
            var effes = RequestTransforms.GetScreenSectionEntityFields(Screen);

            var properties = new List <string>();

            foreach (var effe in effes)
            {
                if (effe.Entity.Id == Screen.EntityId)
                {
                    properties.AddRange(Property(effe, effes, "post", "newRecord", 0, true));
                }
            }

            var newRecord = $"            var newRecord = new {Screen.Entity.InternalName}();";

            if (!string.IsNullOrWhiteSpace(Screen.DefaultObjectJsonData))
            {
                // TODO: add try catch and logging around JsonConvert
                var content = Newtonsoft.Json.JsonConvert.SerializeObject(Screen.DefaultObjectJsonData);
                newRecord = $@"            var content  = {content};
            var newRecord = Newtonsoft.Json.JsonConvert.DeserializeObject<{Screen.Entity.InternalName}>(content);";
            }

            return($@"
        /// <summary>
        /// {Screen.Title} Add
        /// </summary>
        public virtual async Task<ObjectId> CreateAsync({Screen.InternalName}Request post)
        {{
            if (post == null)
            {{
                throw new ArgumentNullException(); 
            }}
{newRecord}

{string.Join(Environment.NewLine, properties)}

            if (post.Id == null)
            {{
                post.Id = ObjectId.GenerateNewId();
            }}
            await _context.{Screen.Entity.InternalNamePlural}.InsertOneAsync(newRecord);

            return post.Id.Value;
        }}");
        }
Exemple #4
0
        /// <summary>
        /// PUT Verb Method, for updating records
        /// </summary>
        internal string PutMethod()
        {
            // TODO: Phase 2 get screen section properties that are appropriate using required expression
            var effes = RequestTransforms.GetScreenSectionEntityFields(Screen);

            var properties = new List <string>();

            foreach (var effe in effes)
            {
                if (effe.Entity.Id == Screen.EntityId)
                {
                    properties.AddRange(Property(effe, effes));
                }
            }

            return($@"
        /// <summary>
        /// {Screen.Title} Update
        /// </summary>
        public virtual async Task<ObjectId> UpdateAsync(ObjectId id, {Screen.InternalName}Request put)
        {{
            if (put == null)
            {{
                throw new ArgumentNullException(); 
            }}
            /*
            var existingRecord = await _context.{Screen.Entity.InternalNamePlural}
                .SingleOrDefaultAsync(record => record.Id == id);

            if (existingRecord == null){{
                throw new ArgumentNullException();
            }}

{string.Join(Environment.NewLine, properties)}

            var result = await collection.UpdateOneAsync(filter, update);*/

            return id;
        }}");
        }
Exemple #5
0
        public IEnumerable<string> Validate()
        {
            if (Transport == null)
                yield return "Transport implementation is not set. It is a required part of configuration.";

            if (ClusterProvider == null)
                yield return "Cluster provider implementation is not set. It is a required part of configuration.";

            if (ResponseCriteria?.Count > 0)
            {
                var lastCriterion = ResponseCriteria.Last();
                if (!(lastCriterion is AlwaysRejectCriterion) && !(lastCriterion is AlwaysAcceptCriterion))
                    yield return $"Last response criterion must always be either an '{typeof(AlwaysRejectCriterion).Name}' or '{typeof(AlwaysAcceptCriterion).Name}'.";
            }

            if (ResponseCriteria != null && ResponseCriteria.Any(criterion => criterion == null))
                yield return "One of provided response criteria is null";

            if (RequestTransforms != null && RequestTransforms.Any(transform => transform == null))
                yield return "One of provided request transforms is null";

            if (ResponseTransforms != null && ResponseTransforms.Any(transform => transform == null))
                yield return "One of provided response transforms is null";

            if (Modules != null && Modules.SelectMany(x => x.Value.After.Concat(x.Value.Before)).Any(module => module == null))
                yield return "One of provided request modules is null";

            if (DefaultTimeout <= TimeSpan.Zero)
                yield return $"Default timeout must be positive, but was '{DefaultTimeout}'";

            if (DefaultConnectionTimeout.HasValue && DefaultConnectionTimeout <= TimeSpan.Zero)
                yield return $"Default connection timeout must be positive, but was '{DefaultConnectionTimeout}'";

            if (MaxReplicasUsedPerRequest <= 0)
                yield return $"Maximum replicas per request must be > 0, but was {MaxReplicasUsedPerRequest}";

            if (ConnectionAttempts <= 0)
                yield return $"Connection attempts per replica must be > 0, but was {ConnectionAttempts}";
        }
        /// <summary>
        /// GET Verb method
        /// </summary>
        internal string GetMethod()
        {
            // TODO: Phase 2 get screen section properties that are appropriate using required expression
            var effes = RequestTransforms.GetScreenSectionEntityFields(Screen);

            var propertyMapping = new List <string>();

            foreach (var effe in effes)
            {
                if (effe.Entity.Id == Screen.EntityId)
                {
                    propertyMapping.AddRange(GetPropertiesRecursive(effe, effes));
                }
            }

            propertyMapping.AddRange(GetParentProperties(Screen.Entity, "item", true));

            return($@"
        /// <summary>
        /// {Screen.Title} Get
        /// </summary>
        public virtual async Task<{Screen.FormResponseClass}> GetAsync(ObjectId id)
        {{
            if (id == null)
            {{
                throw new ArgumentNullException(); 
            }}
            
            var result = _context.{Screen.Entity.InternalNamePlural}.AsQueryable()
                        .Select(item => new {Screen.FormResponseClass}
                        {{
{string.Join(string.Concat(",", Environment.NewLine), propertyMapping)}
                        }})
                        .SingleOrDefault(p => p.Id == id);

            return result;
        }}");
        }