Beispiel #1
0
        private Package.DependencySet GetDependencySet()
        {
            var set     = new Package.DependencySet();
            var targets =
                dependencyGrid.Rows.Cast <DataGridViewRow>()
                .Select(r => r.Cells[2].Value?.ToString().Trim() ?? "").Distinct();

            if (targets.Any(t => !string.IsNullOrWhiteSpace(t)))
            {
                var groups = new List <Package.DependencyGroup>();
                foreach (var target in targets)
                {
                    var group = new Package.DependencyGroup
                    {
                        TargetFramework = string.IsNullOrWhiteSpace(target) ? null : target
                    };
                    Expression <Func <DataGridViewRow, bool> > exp = null;
                    if (string.IsNullOrWhiteSpace(target))
                    {
                        exp = (r => (r.Cells[0].Value != null && r.Cells[1].Value != null) && (r.Cells[2].Value == null || string.IsNullOrWhiteSpace(r.Cells[2].Value.ToString())));
                    }
                    else
                    {
                        exp = (r => (r.Cells[0].Value != null && r.Cells[1].Value != null) && r.Cells[2].Value != null && r.Cells[2].Value.ToString().Trim() == target);
                    }
                    group.Dependencies =
                        dependencyGrid.Rows.Cast <DataGridViewRow>()
                        .Where(exp.Compile())
                        .Select(r => new Package.Dependency
                    {
                        Id      = r.Cells[0].Value.ToString().Trim(),
                        Version = r.Cells[1].Value.ToString().Trim()
                    }).OrderBy(m => m.Id).ToList();
                    if (group.Dependencies.Count > 0)
                    {
                        groups.Add(group);
                    }
                }

                set.Groups = groups.OrderBy(m => m.TargetFramework).ToList();
            }
            else
            {
                set.Dependencies =
                    dependencyGrid.Rows.Cast <DataGridViewRow>().Where(r => (r.Cells[0].Value != null && r.Cells[1].Value != null))
                    .Select(r => new Package.Dependency
                {
                    Id      = r.Cells[0].Value.ToString().Trim(),
                    Version = r.Cells[1].Value.ToString().Trim()
                }).OrderBy(m => m.Id).ToList();
            }

            return(set);
        }
Beispiel #2
0
        public Package.DependencySet GetDependencySet()
        {
            var dependencies = GetDependencies().ToList();
            var set          = new Package.DependencySet();
            var targets      = dependencies.Select(r => r.TargetFramework).Distinct().ToList();

            if (targets.Any(t => !string.IsNullOrWhiteSpace(t)))
            {
                var groups = new List <Package.DependencyGroup>();
                foreach (var target in targets)
                {
                    var group = new Package.DependencyGroup
                    {
                        TargetFramework = string.IsNullOrWhiteSpace(target) ? null : target
                    };
                    Expression <Func <DependencyViewModel, bool> > exp = null;
                    if (string.IsNullOrWhiteSpace(target))
                    {
                        exp = r => (string.IsNullOrWhiteSpace(r.TargetFramework));
                    }
                    else
                    {
                        exp = (r => r.TargetFramework == target);
                    }
                    group.Dependencies =
                        dependencies
                        .Where(exp.Compile())
                        .Select(r => new Package.Dependency
                    {
                        Id      = r.Id,
                        Version = r.Version
                    }).OrderBy(m => m.Id).ToList();
                    if (group.Dependencies.Count > 0)
                    {
                        groups.Add(group);
                    }
                }

                set.Groups = groups.OrderBy(m => m.TargetFramework).ToList();
            }
            else
            {
                set.Dependencies =
                    dependencies
                    .Select(r => new Package.Dependency
                {
                    Id      = r.Id,
                    Version = r.Version
                }).OrderBy(m => m.Id).ToList();
            }

            return(set);
        }