Exemple #1
0
        internal static Workspaces CreateFilteredWorkspaces(DataLayerProviderKind[] kinds, int maxPriority, bool standardOnly, Action <Workspace> beforeWorkspaceCreate)
        {
            Workspaces workspaces = new Workspaces();
            //Find all workspaces
            List <WorkspaceCreation> workspacesToBeInitialized = new List <WorkspaceCreation>();

            //Filter by Test Property information
            foreach (Type t in typeof(Workspaces).Assembly.GetTypes())
            {
                object[] attributes = t.GetCustomAttributes(typeof(WorkspaceAttribute), true);
                if (attributes.Length > 0)
                {
                    WorkspaceAttribute workspaceAttribute = attributes[0] as WorkspaceAttribute;
                    if (kinds.Contains(workspaceAttribute.DataLayerProviderKind) &&
                        workspaceAttribute.Priority <= maxPriority &&
                        (!standardOnly || workspaceAttribute.Standard))
                    {
                        WorkspaceCreation creationType = new WorkspaceCreation();
                        creationType.WorkspaceAttribute = workspaceAttribute;
                        creationType.WorkspaceType      = t;
                        workspacesToBeInitialized.Add(creationType);
                    }
                }
            }

            //Initialize Workspace types
            foreach (WorkspaceCreation wc in
                     workspacesToBeInitialized)
            // some tests RELY on the arbitrary order of the workspaces
            //.OrderBy(wc => wc.WorkspaceAttribute.DataLayerProviderKind + "." + wc.WorkspaceAttribute.Name))
            {
                if (!wc.WorkspaceType.IsSubclassOf(typeof(Workspace)))
                {
                    //TODO: Should possibly error here
                    continue;
                }
                else
                {
                    Workspace workspace = (Workspace)wc.WorkspaceType.GetConstructor(new Type[] { }).Invoke(new object[] { });
                    workspaces.Add(workspace);
                }
            }



            //Now call create on all workspaces
            foreach (Workspace w in workspaces)
            {
                beforeWorkspaceCreate(w);
                w.Create();
            }

            return(workspaces);
        }
Exemple #2
0
        public Workspaces FilterByName(string name)
        {
            Workspaces result = new Workspaces();

            foreach (Workspace workspace in this)
            {
                if (workspace.Name == name)
                {
                    result.Add(workspace);
                }
            }

            return(result);
        }
 protected void HandleWorkspaceCreationEvent(object sender, NewWorkspaceEventArgs e)
 {
     _workspaces.Add(e.Workspace);
 }