Exemplo n.º 1
0
        public static Target Run(ControllerConfiguration context, Guid groupKey)
        {
            var targetsController = new Targets(context);

            var searchEmpty = targetsController.SearchGroupTargets(groupKey);
            Debug.Assert(searchEmpty.TotalCount == 0);
            Debug.Assert(searchEmpty.Targets.Count() == 0);

            var testTarget = new Target() { Name = "Test Target", GroupKey = groupKey };
            targetsController.CreateTarget(testTarget);
            var createdTarget = targetsController.GetTarget(testTarget.Key);
            Debug.Assert(createdTarget.Name == testTarget.Name);
            Debug.Assert(createdTarget.GroupKey == testTarget.GroupKey);

            var searchSingle = targetsController.SearchGroupTargets(groupKey);
            Debug.Assert(searchSingle.TotalCount == 1);
            Debug.Assert(searchSingle.Targets.Count() == 1);
            Debug.Assert(searchSingle.Targets.First().Key == createdTarget.Key);
            Debug.Assert(searchSingle.Targets.First().Name == createdTarget.Name);

            createdTarget.Tags.Add("Foo", "Bar");
            targetsController.UpdateTarget(createdTarget);

            var taggedTarget = targetsController.GetTarget(testTarget.Key);
            Debug.Assert(taggedTarget.GroupKey == createdTarget.GroupKey);
            Debug.Assert(taggedTarget.Tags.ContainsKey("Foo"));
            Debug.Assert(taggedTarget.Tags["Foo"] == "Bar");
            var searchUpdated = targetsController.SearchGroupTargets(groupKey);
            Debug.Assert(searchUpdated.TotalCount == 1);
            Debug.Assert(searchUpdated.Targets.Count() == 1);
            Debug.Assert(searchUpdated.Targets.First().Key == createdTarget.Key);
            Debug.Assert(searchUpdated.Targets.First().Name == createdTarget.Name);

            taggedTarget.Name = "Updated Test Target";
            targetsController.UpdateTarget(taggedTarget);

            var renamedTarget = targetsController.GetTarget(testTarget.Key);
            Debug.Assert(renamedTarget.Name == taggedTarget.Name);
            Debug.Assert(renamedTarget.GroupKey == taggedTarget.GroupKey);
            var searchRenamed = targetsController.SearchGroupTargets(groupKey);
            Debug.Assert(searchRenamed.TotalCount == 1);
            Debug.Assert(searchRenamed.Targets.Count() == 1);
            Debug.Assert(searchRenamed.Targets.First().Key == taggedTarget.Key);
            Debug.Assert(searchRenamed.Targets.First().Name == taggedTarget.Name);

            Searching(groupKey, targetsController, createdTarget);

            targetsController.UpdateTarget(testTarget);
            var searchReset = targetsController.SearchGroupTargets(groupKey);
            Debug.Assert(searchReset.TotalCount == 1);
            Debug.Assert(searchReset.Targets.Count() == 1);
            Debug.Assert(searchReset.Targets.First().Key == testTarget.Key);
            Debug.Assert(searchReset.Targets.First().Name == testTarget.Name);

            // Create default test target.
            targetsController.CreateTarget(new Target() { Key = new Guid("2c50a0af-bc66-41f5-bf52-498118217d12"), GroupKey = new Guid("5615c002-2d9a-46c4-a9a3-26b2b19cd790"), Name = "Test App Server" });

            return testTarget;
        }
Exemplo n.º 2
0
        public TargetAppList SearchTargetApps(Guid targetKey, string query = null, int offset = 0, int pageSize = 50)
        {
            try
            {
                var indexes = new Indexes(Context);
                var targets = new Targets(Context);
                var apps = new Apps(Context);
                var index = indexes.LoadIndex(GetTargetAppsIndexPath(targetKey));
                var target = targets.GetTarget(targetKey);
                var groupAppIndex = indexes.LoadIndex(Apps.GetGroupAppsIndexPath(target.GroupKey));

                var filteredIndex = index.Entries.AsQueryable();

                if (!string.IsNullOrWhiteSpace(query))
                {
                    var queryParts = query.ToLower().Split(new char[] { ' ', '\t', ',' }).Where(qp => !string.IsNullOrWhiteSpace(qp)).ToArray();
                    filteredIndex = filteredIndex.Where(e => queryParts.Any(q => e.Name.ToLower().Contains(q)));
                }

                var count = filteredIndex.Count();

                var listItems = filteredIndex.Skip(offset).Take(pageSize).ToList().Select(e =>
                    {
                        var groupApp = groupAppIndex.Entries.FirstOrDefault(a => a.Key == e.Key);
                        return new AppListItem()
                        {
                            Key = e.Key,
                            Name = (groupApp != null) ? groupApp.Name : TryResolveAppNameDirect(e.Key, apps)
                        };
                    }).ToList().OrderBy(app => app.Name);

                var list = new TargetAppList()
                {
                    Apps = listItems,
                    TargetKey = targetKey,
                    Query = query,
                    Offset = offset,
                    PageSize = pageSize,
                    TotalCount = count,
                };

                return list;
            }
            catch (Exception ex)
            {
                throw new DeploymentException(string.Format("Failed getting app keys for target \"{0}\".", targetKey), ex);
            }
        }