Beispiel #1
0
        public async Task <contracts::RunbookStep> GetRunbookStepAsync(contracts::RunbookStep request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            var stopwatch = DataAccessBase.StartStopwatch();

            using (var context = this.contextCreator())
            {
                var query = context.RunbookSteps
                            .Include("RunbookStepType")
                            .Include("RunbookStepStatuses")
                            .Include("RunbookStepPbis")
                            .Include("Teams")
                            .Include("Developers")
                            .Include("Resources")
                            .AsQueryable();

                if (request.Id > 0)
                {
                    query = query.Where(p => p.Id == request.Id);
                }

                var data = await query.Select(a => a).FirstOrDefaultAsync().ConfigureAwait(false);

                var mapped = Mapper.Map <entities::RunbookStep, contracts::RunbookStep>(data);

                this.TraceSource.TraceEvent(TraceEventType.Information, String.Format("COMPLETE: Name: {0}.", Text.GetStringInfo(request.Name)), stopwatch.Elapsed, TraceStatus.Success, new Dictionary <String, object> {
                    { "Request", request }
                });

                return(mapped);
            }
        }
Beispiel #2
0
        public async Task <contracts::ServiceResponse> InsertRfcAsync(contracts::Rfc request)
        {
            var stopwatch = DataAccessBase.StartStopwatch();

            var serviceResponse = new contracts::ServiceResponse();

            // Convert Start and End Times
            // Convert Templates to Runbook Steps
            //  - Set the new RFC ID
            //  - Set Template ID's to ZERO

            using (var context = this.contextCreator())
            {
                // RFC
                //  - Save the RFC and get the ID

                var rfc = new Rfc()
                {
                    Number    = request.Number,
                    Name      = request.Name,
                    StartTime = request.StartTime,
                    EndTime   = request.EndTime,
                    ContactId = request.Contact.Id
                };

                context.Rfcs.Add(rfc);
                serviceResponse.RecordsAffected = await context.SaveChangesAsync().ConfigureAwait(false);

                // Runbook Steps
                //  - Save the Runbook Steps with the RFC ID

                foreach (var runbookTemplate in request.Templates)
                {
                    // Don't rely on the template coming from the UI - get from the database instead. Only the ID is really necessary - may refactor later.
                    var template = await this.GetRunbookTemplateAsync(new contracts.RunbookTemplate {
                        Id = runbookTemplate.Id
                    });

                    // Map the Contract Steps in the Template to the Entity Steps in the RFC
                    foreach (var c in template.RunbookSteps)
                    {
                        var runbookStep = new entities::RunbookStep
                        {
                            RfcId                 = rfc.Id,
                            GroupNumber           = c.GroupNumber,
                            StepNumber            = c.StepNumber,
                            Duration              = c.Duration,
                            Name                  = c.Name,
                            Description           = c.Description,
                            Notes                 = c.Notes,
                            RunbookStepStatusCode = c.RunbookStepStatusCode,
                            RunbookStepTypeCode   = c.RunbookStepTypeCode,
                            IsHtml                = c.IsHtml,
                            Time                  = c.Time,
                        };
                        context.RunbookSteps.Add(runbookStep);
                        serviceResponse.RecordsAffected = await context.SaveChangesAsync().ConfigureAwait(false);

                        var templateStepsRequest = new contracts::TemplateStepsRequest {
                            TemplateId = runbookTemplate.Id, OldRunbookStepId = c.Id, NewRunbookStepId = runbookStep.Id
                        };

                        // Save associated RunbookStep Developers, Pbis, Resources, and Teams...

                        serviceResponse = await this.InsertRunbookStepDevelopersAsync(templateStepsRequest);

                        serviceResponse = await this.InsertRunbookStepPbisAsync(templateStepsRequest);

                        serviceResponse = await this.InsertRunbookStepResourcesAsync(templateStepsRequest);

                        serviceResponse = await this.InsertRunbookStepTeamsAsync(templateStepsRequest);
                    }
                }

                serviceResponse.RecordsAffected = await context.SaveChangesAsync().ConfigureAwait(false);

                serviceResponse.IsSuccessful = true;

                this.TraceSource.TraceEvent(TraceEventType.Information, String.Format("COMPLETE: Name: {0}.", Text.GetStringInfo(request.Name)), stopwatch.Elapsed, TraceStatus.Success, new Dictionary <String, object> {
                    { "Request", request }
                });
            }

            return(serviceResponse);
        }
Beispiel #3
0
        public async Task <Page <contracts::ApplicationLink> > GetApplicationLinksAsync(contracts::ApplicationLink request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            var stopwatch = DataAccessBase.StartStopwatch();

            using (var context = this.contextCreator())
            {
                var query = context.ApplicationLinks
                            .Include("ApplicationGroup")
                            .Include("ApplicationType")
                            .Include("ServiceLinks")
                            .Include("ServiceLinks.EnvironmentLinks")
                            .Include("ServiceLinks.EnvironmentLinks.Server")
                            .Include("ServiceLinks.EnvironmentLinks.Server.Environment")
                            .AsQueryable();

                if (!String.IsNullOrWhiteSpace(request.Name))
                {
                    query = query.Where(p => p.Name.Contains(request.Name) || p.ApplicationType.Description.Contains(request.Name));
                }

                if (request.ApplicationType != null)
                {
                    if (!String.IsNullOrWhiteSpace(request.ApplicationType.Code))
                    {
                        query = query.Where(p => p.ApplicationType.Code.Equals(request.ApplicationType.Code));
                    }
                }

                if (request?.ApplicationGroupId > 0)
                {
                    query = query.Where(p => p.ApplicationGroupId == request.ApplicationGroupId);
                }

                var totalRecordCount = query.Count();

                if (totalRecordCount == 0)
                {
                    return(new Page <contracts::ApplicationLink> {
                        Items = new List <contracts::ApplicationLink>(0)
                    });
                }

                var sanitizedPagingInfo = request.Paging.SanitizePaging();

                var data = await query.Select(a => a).TakePage(sanitizedPagingInfo).ToListAsync().ConfigureAwait(false);

                var mapped = Mapper.Map <List <entities::ApplicationLink>, List <contracts::ApplicationLink> >(data);
                var page   = mapped.ToPage(totalRecordCount, sanitizedPagingInfo);

                this.TraceSource.TraceEvent(TraceEventType.Information, String.Format("COMPLETE: Name: {0}.", Text.GetStringInfo(request.Name)), stopwatch.Elapsed, TraceStatus.Success, new Dictionary <String, object> {
                    { "Request", request }
                });

                return(page);
            }
        }