コード例 #1
0
        private static void RecurseSpecs(BuildSpecification spec, bool runningCoreOs, PciScopeConstant pciScope,
                                         int environmentId, out List <Port> ports, out List <SoftwareComponent> softwares,
                                         out string osName, out string osVersion, ref PlatformConstant pt)
        {
            softwares = new List <SoftwareComponent>();
            ports     = new List <Port>();
            osName    = spec.OperatingSystemName;
            osVersion = spec.OperatingSystemVersion;
            var it = spec;

            while (it != null)
            {
                osName    = it.OperatingSystemName;
                osVersion = it.OperatingSystemVersion;
                var softToAdd = runningCoreOs
                    ? it.SoftwareComponents.Where(p => !p.NonCore)
                    : it.SoftwareComponents;
                softToAdd = softToAdd.Where(p => p.PciScope == null || (p.PciScope & pciScope) != 0);
                softToAdd = softToAdd.Where(p => !p.SoftwareComponentEnvironments.Any() || p.SoftwareComponentEnvironments.Any(q => q.EnvironmentId == environmentId));
                softwares.AddRange(softToAdd);
                ports.AddRange(it.Ports.Where(p => !p.IsOutgoing));
                if (it.Platform.HasValue)
                {
                    pt = it.Platform.Value;
                }
                it = it.Parent;
            }
        }
コード例 #2
0
        private IEnumerable <Suggestion> CreateAdd(BuildSpecification spec, Employee owner,
                                                   JustificationTypeConstant resultType, string value,
                                                   PortTypeConstant?portType = null)
        {
            yield return(new Suggestion(spec.BuildSpecificationType, spec.Id, spec.Name,
                                        owner.OwnerText(false), owner.SamAccountName, resultType, portType, value, false));

            yield return(new Suggestion(spec.BuildSpecificationType, spec.Id, spec.Name,
                                        owner.OwnerText(false), owner.SamAccountName, resultType, portType, value, true));
        }
コード例 #3
0
        public override async Task AddOrUpdate(AppSpecInformation info)
        {
            if (info == null)
            {
                throw new ArgumentNullException(nameof(info));
            }

            if (!await IsUnique(info))
            {
                throw new ArgumentException(@"The name is not unique", nameof(info));
            }
            BuildSpecification it = null;
            var osSpec            = await Ctx.BuildSpecifications.ById(BuildSpecificationTypeConstant.OperatingSystem, info.OsSpecId.GetValueOrDefault());

            if (info.Id.HasValue)
            {
                it = await Ctx.BuildSpecifications.ById(BuildSpecificationTypeConstant.Application,
                                                        info.Id.Value);
            }


            if (it == null)
            {
                it = Ctx.BuildSpecifications.Add(new BuildSpecification
                {
                    BuildSpecificationType = BuildSpecificationTypeConstant.Application,
                    Name                   = info.Name,
                    OwnerEmployeeId        = info.OwnerId.GetValueOrDefault(),
                    ParentId               = info.OsSpecId,
                    WikiLink               = info.WikiLink,
                    Overview               = info.Overview,
                    EmailAddress           = info.Email,
                    RunningCoreOs          = osSpec?.Platform == PlatformConstant.WindowsServer && info.RunningCoreOs.GetValueOrDefault(),
                    IncludeRemedyEmailList = info.IncludeRemedyEmailList
                }).Entity;
            }
            else
            {
                it.Name                   = info.Name;
                it.OwnerEmployeeId        = info.OwnerId.GetValueOrDefault();
                it.RunningCoreOs          = osSpec?.Platform == PlatformConstant.WindowsServer && info.RunningCoreOs.GetValueOrDefault();
                it.ParentId               = info.OsSpecId;
                it.WikiLink               = info.WikiLink;
                it.Overview               = info.Overview;
                it.EmailAddress           = info.Email;
                it.IncludeRemedyEmailList = info.IncludeRemedyEmailList;
            }

            await Ctx.SaveChangesAsync();

            info.Id = it.Id;
        }
コード例 #4
0
 protected override OsSpecInformation ModelMapper(BuildSpecification it)
 {
     return(new OsSpecInformation
     {
         OsName = it.OperatingSystemName,
         OsVersion = it.OperatingSystemVersion,
         OwnerId = it.OwnerEmployeeId,
         OwnerName = it.Owner.OwnerText(),
         Platform = it.Platform.GetValueOrDefault(),
         Name = it.Name,
         Email = it.EmailAddress,
         Id = it.Id
     });
 }
コード例 #5
0
        public override async Task AddOrUpdate(OsSpecInformation info)
        {
            if (info == null)
            {
                throw new ArgumentNullException(nameof(info));
            }

            if (!await IsUnique(info))
            {
                throw new ArgumentException(@"The name is not unique", nameof(info));
            }
            BuildSpecification it = null;

            if (info.Id.HasValue)
            {
                it = await Ctx.BuildSpecifications.ById(BuildSpecificationTypeConstant.OperatingSystem,
                                                        info.Id.Value);
            }

            if (it == null)
            {
                it = Ctx.BuildSpecifications.Add(new BuildSpecification
                {
                    BuildSpecificationType = BuildSpecificationTypeConstant.OperatingSystem,
                    Name                   = info.Name,
                    OwnerEmployeeId        = info.OwnerId.GetValueOrDefault(),
                    OperatingSystemName    = info.OsName,
                    OperatingSystemVersion = info.OsVersion,
                    Platform               = info.Platform,
                    EmailAddress           = info.Email
                }).Entity;
            }
            else
            {
                it.Name                   = info.Name;
                it.OwnerEmployeeId        = info.OwnerId.GetValueOrDefault();
                it.OperatingSystemName    = info.OsName;
                it.OperatingSystemVersion = info.OsVersion;
                it.Platform               = info.Platform;
                it.EmailAddress           = info.Email;
            }

            await Ctx.SaveChangesAsync();

            info.Id = it.Id;
        }
コード例 #6
0
 protected override AppSpecInformation ModelMapper(BuildSpecification it)
 {
     return(new AppSpecInformation
     {
         OsSpecId = it.ParentId.GetValueOrDefault(),
         OsSpecName = it.Parent?.Name,
         WikiLink = it.WikiLink,
         Overview = it.Overview,
         OwnerId = it.OwnerEmployeeId,
         OwnerName = it.Owner.OwnerText(),
         Platform = (it.Parent?.Platform).GetValueOrDefault(PlatformConstant.Linux).ToString().ToLower(),
         Name = it.Name,
         Id = it.Id,
         Email = it.EmailAddress,
         RunningCoreOs = it.RunningCoreOs
     });
 }
コード例 #7
0
        public async Task <BuildSpec> BuildSpecification(long specId)
        {
            var type    = BuildSpecificationTypeConstant.Application;
            var appSpec = await _ctx.BuildSpecifications.AsNoTracking()
                          .Include(p => p.Parent)
                          .Include(p => p.Nodes)
                          .ById(type, specId);

            var softwareComponent = await GetOrCreateSoftwareComponent();

            BuildSpecification osSpec;

            if (appSpec == null)
            {
                type   = BuildSpecificationTypeConstant.OperatingSystem;
                osSpec = await _ctx.BuildSpecifications.AsNoTracking()
                         .Include(p => p.SoftwareComponents)
                         .ById(type, specId);

                if (osSpec == null)
                {
                    throw new ArgumentException(nameof(specId));
                }

                appSpec = new BuildSpecification
                {
                    Name  = osSpec.Name,
                    Owner = osSpec.Owner,
                    Ports = new List <Port>(0),
                    SoftwareComponents = new List <SoftwareComponent>(0),
                    Nodes = new List <Node>(0)
                };
            }
            else
            {
                appSpec.SoftwareComponents =
                    softwareComponent.Where(x => x.BuildSpecificationId == appSpec.Id).ToList();

                appSpec.Parent.SoftwareComponents =
                    softwareComponent.Where(x => x.BuildSpecificationId == appSpec.Parent.Id).ToList();
                osSpec = appSpec.Parent;
            }

            var apps = appSpec.RunningCoreOs
                ? osSpec.SoftwareComponents.Where(p => !p.NonCore).ToList()
                : osSpec.SoftwareComponents.ToList();

            apps.AddRange(appSpec.SoftwareComponents);

            var ids = apps.Select(p => p.JustificationId).Where(p => p.HasValue).Select(p => p.Value).Distinct()
                      .ToArray();


            var sofwareJts = new List <JustificationTypeConstant>();

            switch (osSpec.Platform.GetValueOrDefault(PlatformConstant.Other))
            {
            case PlatformConstant.Unix:
            case PlatformConstant.Linux:
                sofwareJts.Add(JustificationTypeConstant.Package);
                break;

            case PlatformConstant.WindowsServer:
            case PlatformConstant.WindowsClient:
                sofwareJts.Add(JustificationTypeConstant.Application);
                sofwareJts.Add(JustificationTypeConstant.Feature);
                break;
            }

            var justifications = (await _ctx
                                  .Justifications
                                  .Where(p => ids.Contains(p.Id))
                                  .Where(p => sofwareJts.Contains(p.JustificationType))
                                  .Select(p => new
            {
                p.Id,
                p.JustificationText,
                p.JustificationType,
                p.BuildSpecification.Owner,
                p.BuildSpecification.BuildSpecificationType
            })
                                  .ToArrayAsync()) //Yank from DB
                                 .Select(j => new Justification(j.JustificationType, j.JustificationText, j.Owner.OwnerText(false),
                                                                j.BuildSpecificationType, apps.Where(p => p.JustificationId == j.Id)
                                                                .OrderBy(p => p.JustificationType)
                                                                .Select(p => new Software(p.Name, p.Description, p.JustificationType, p.NonCore, p.PciScope,
                                                                                          p.SoftwareComponentEnvironments.GetEnvironmentNames()))))
                                 .ToArray();

            var uList = apps.Where(p => p.JustificationId == null && sofwareJts.Contains(p.JustificationType))
                        .OrderBy(p => p.JustificationType)
                        .Select(p => new Software(p.Name, p.Description, p.JustificationType, p.NonCore, p.PciScope,
                                                  p.SoftwareComponentEnvironments.GetEnvironmentNames()))
                        .ToArray();
            var nodes = appSpec.Nodes.Select(p => new InventorySystemNode(p.InventoryItemId, p.Fqdn)).ToArray();

            return(new BuildSpec(specId, type, appSpec.Name, appSpec.Owner.OwnerText(),
                                 osSpec.OperatingSystemName, osSpec.OperatingSystemVersion, appSpec.WikiLink, appSpec.Overview,
                                 justifications, await PortReport(specId), uList, nodes));
        }
コード例 #8
0
 protected abstract TModel ModelMapper(BuildSpecification spec);
コード例 #9
0
        public async Task <long> Clone(long cloneId, IUserSecurity employeeSecurity)
        {
            var toClone = await Ctx.BuildSpecifications
                          .Include(p => p.Justifications)
                          .Include(p => p.Ports)
                          .Include(p => p.SoftwareComponents)
                          .ById(_buildSpecificationType, cloneId);

            if (toClone == null)
            {
                throw new ArgumentException(
                          $@"The id passed in ({
                            cloneId
                        }) is not a valid id for a BuildSpec of Type {_buildSpecificationType}",
                          nameof(cloneId));
            }

            var newSpec = new BuildSpecification
            {
                BuildSpecificationType = _buildSpecificationType,
                Name     = $"Clone {Guid.NewGuid()}",
                WikiLink = toClone.WikiLink,
                Overview = toClone.Overview,
                OperatingSystemVersion = toClone.OperatingSystemVersion,
                OperatingSystemName    = toClone.OperatingSystemName,
                OwnerEmployeeId        = employeeSecurity.EmployeeId,
                ParentId      = toClone.ParentId,
                Platform      = toClone.Platform,
                RunningCoreOs = toClone.RunningCoreOs
            };

            Ctx.BuildSpecifications.Add(newSpec);
            await Ctx.SaveChangesAsync();

            var id      = newSpec.Id;
            var jidDict = new Dictionary <long, Justification>();

            foreach (var justification in toClone.Justifications)
            {
                var newJust = Ctx.Justifications.Add(new Justification
                {
                    BuildSpecificationId = id,
                    Color             = justification.Color,
                    JustificationText = justification.JustificationText,
                    JustificationType = justification.JustificationType
                }).Entity;
                jidDict.Add(justification.Id, newJust);
            }

            await Ctx.SaveChangesAsync();

            foreach (var port in toClone.Ports)
            {
                var newPort = new Port
                {
                    BuildSpecificationId = id,
                    From       = port.From,
                    To         = port.To,
                    IsExternal = port.IsExternal,
                    PortType   = port.PortType
                };
                if (port.Justification != null)
                {
                    newPort.JustificationId = jidDict[port.Justification.Id].Id;
                }

                Ctx.Ports.Add(newPort);
            }

            var sidDict = new Dictionary <long, SoftwareComponent>();

            foreach (var software in toClone.SoftwareComponents)
            {
                var newSoftware = new SoftwareComponent
                {
                    BuildSpecificationId = id,
                    JustificationType    = software.JustificationType,
                    Name        = software.Name,
                    Description = software.Description,
                    NonCore     = software.NonCore,
                    PciScope    = software.PciScope
                };

                if (software.Justification != null)
                {
                    newSoftware.JustificationId = jidDict[software.Justification.Id].Id;
                }

                Ctx.SoftwareComponents.Add(newSoftware);
                sidDict.Add(software.Id, newSoftware);
            }

            await Ctx.SaveChangesAsync();

            foreach (var key in sidDict.Keys)
            {
                var environments = Ctx.SoftwareComponentEnvironments.Where(p => p.SoftwareComponentId == key)
                                   .Select(p => p.EnvironmentId).ToArray();
                foreach (var environment in environments)
                {
                    Ctx.SoftwareComponentEnvironments.Add(new SoftwareComponentEnvironment
                    {
                        SoftwareComponentId = sidDict[key].Id,
                        EnvironmentId       = environment
                    });
                }
            }

            await Ctx.SaveChangesAsync();

            return(id);
        }