Exemplo n.º 1
0
        private void ScenarioConfigurationTreeView_OnStartBatch(object sender, RadTreeViewEventArgs e)
        {
            ConfigurationObjectTag selected = scenarioConfigurationTreeView.SelectedConfigurationObject;

            if (selected != null && selected.ObjectType == ConfigurationObjectType.ScenarioFolder)
            {
                mainTabControl.SelectTab(execution_TabPage);
                List <Guid> scenarioIds = null;
                using (EnterpriseTestContext context = new EnterpriseTestContext())
                {
                    scenarioIds = (List <Guid>)ConfigurationTreeFolder.ContainedScenarioIds(context, selected.Id);
                }
                StartSession(scenarioIds);
            }
        }
        private static void DatabaseDelete(IEnumerable <EnterpriseTestMapNode> nodes)
        {
            //--------------------------------------------------------------------------------------------------
            // ADD: CR #1894.  Cascading deletes were throwing an unhandled exception because of a DB Foreign
            // Key Constraint on the folderId field.  What that means is that the ORDER in which things are
            // deleted, now becomes very important.  If we attempt to remove a 'container' before we remove
            // the contents, the exception will be thrown when the contents are removed.  So - in order to make
            // this work, we group the objects to be deleted - and then we have to order those groups (since the
            // order of the GroupBy could be non-deterministic) and make sure that we delete things in the
            // correct sequence.  There is probably a more elegant way of doing this - but there was no time.
            using (EnterpriseTestContext context = new EnterpriseTestContext())
            {
                int[] ordered = new int[6] {
                    -1, -1, -1, -1, -1, -1
                };

                var colls = nodes.GroupBy(n => n.NodeType, n => n.Id);
                int ndx   = 0;
                foreach (var grp in colls)
                {
                    switch (grp.Key)
                    {
                    case ConfigurationObjectType.ResourceMetadata:
                        ordered[0] = ndx++;
                        break;

                    case ConfigurationObjectType.MetadataFolder:
                        ordered[1] = ndx++;
                        break;

                    case ConfigurationObjectType.VirtualResource:
                        ordered[2] = ndx++;
                        break;

                    case ConfigurationObjectType.ResourceFolder:
                        ordered[3] = ndx++;
                        break;

                    case ConfigurationObjectType.EnterpriseScenario:
                        ordered[4] = ndx++;
                        break;

                    case ConfigurationObjectType.ScenarioFolder:
                        ordered[5] = ndx++;
                        break;
                    }
                }

                for (ndx = 0; ndx < 6; ndx++)
                {
                    if (ordered[ndx] >= 0)
                    {
                        switch (colls.ElementAt(ordered[ndx]).Key)
                        {
                        case ConfigurationObjectType.ResourceMetadata:
                            foreach (var vrmd in VirtualResourceMetadata.Select(context, colls.ElementAt(ordered[ndx])))
                            {
                                context.DeleteObject(vrmd);
                            }
                            break;

                        case ConfigurationObjectType.MetadataFolder:
                            foreach (var mdf in ConfigurationTreeFolder.Select(context, colls.ElementAt(ordered[ndx])))
                            {
                                context.DeleteObject(mdf);
                            }
                            break;

                        case ConfigurationObjectType.VirtualResource:
                            foreach (var vr in VirtualResource.Select(context, colls.ElementAt(ordered[ndx])))
                            {
                                context.DeleteObject(vr);
                            }
                            break;

                        case ConfigurationObjectType.ResourceFolder:
                            foreach (var rf in ConfigurationTreeFolder.Select(context, colls.ElementAt(ordered[ndx])))
                            {
                                context.DeleteObject(rf);
                            }
                            break;

                        case ConfigurationObjectType.EnterpriseScenario:
                            foreach (var scenario in EnterpriseScenario.Select(context, colls.ElementAt(ordered[ndx])))
                            {
                                context.DeleteObject(scenario);
                            }
                            break;

                        case ConfigurationObjectType.ScenarioFolder:
                            foreach (var sf in ConfigurationTreeFolder.Select(context, colls.ElementAt(ordered[ndx])))
                            {
                                var deletingScenarioIds = nodes.Where(n => n.NodeType == ConfigurationObjectType.EnterpriseScenario).Select(n => n.Id);
                                foreach (var folder in ConfigurationTreeFolder.Select(context, colls.ElementAt(ordered[ndx])))
                                {
                                    var containedScenarios = ConfigurationTreeFolder.ContainedScenarioIds(context, folder.ConfigurationTreeFolderId);
                                    if (containedScenarios.All(n => deletingScenarioIds.Contains(n)))
                                    {
                                        // All of the sceanrios under this folder are in the list of scenarios to delete,
                                        // so we can delete this folder as well.
                                        context.DeleteObject(folder);
                                    }
                                }
                            }
                            break;
                        }
                        context.SaveChanges();
                    }
                }
            }
        }