Esempio n. 1
0
 private void reloadMeasuresB_Click(object sender, RoutedEventArgs e)
 {
     measureDataModel.LoadExperiementMeasures(experimentDataModel.CurExperiment,
                                              experimentDataModel.UsersInExperiment);
 }
Esempio n. 2
0
        public void ScanDDDScenario(MeasuresDataModel measureDataModel)
        {
            List<String> dmIDs = new List<String>();
            List<AssetEntity> entities = new List<AssetEntity>();
            Dictionary<String, ExperimentEntity> entityMap = new Dictionary<string, ExperimentEntity>();

            int operatorTypeID = -1;
            int assetTypeID = -1;

            try
            {
                if ((CurExperiment.ScenarioFilePath == null) || (CurExperiment.ScenarioFilePath.Length <= 0))
                {
                    return;
                }

                MessageBoxResult result = MessageBox.Show("Scanning a scenario file will clear all selections on the Measures tab.  Do you wish to continue?", "Warning", MessageBoxButton.YesNo, MessageBoxImage.Question);

                if (result != MessageBoxResult.Yes)
                {
                    return;
                }

                // Open scenario file
                XPathDocument Doc = new XPathDocument(CurExperiment.ScenarioFilePath);
                XPathNavigator navigator = Doc.CreateNavigator();
                navigator.MoveToRoot();

                // Make sure this is a DDD Scenario file
                XPathNavigator node = navigator.SelectSingleNode("/Scenario/ScenarioName");
                String scenarioName = node.Value;

                if ((scenarioName == null) || (scenarioName.Length <= 0))
                {
                    return;
                }

                // Get all of the DecisionMaker ids
                XPathNodeIterator iterator = navigator.Select("/Scenario/DecisionMaker");
                String dmID = null;

                while (iterator.MoveNext())
                {
                    node = iterator.Current.SelectSingleNode("Identifier");
                    dmID = node.Value;

                    if ((dmID == null) || (dmID.Length <= 0))
                    {
                        continue;
                    }

                    dmIDs.Add(dmID);
                }

                // Get all of the entity names
                iterator = navigator.Select("/Scenario/Create_Event");
                String entityID = null;

                while (iterator.MoveNext())
                {
                    string ownerName = null;
                    node = iterator.Current.SelectSingleNode("ID");
                    entityID = node.Value;

                    node = iterator.Current.SelectSingleNode("Owner");
                    if (node != null)
                    {
                        ownerName = node.Value;
                    }

                    if ((dmID == null) || (dmID.Length <= 0))
                    {
                        continue;
                    }

                    AssetEntity newAssetEntity = new AssetEntity();
                    newAssetEntity.AssetName = entityID;
                    newAssetEntity.OwnerName = ownerName;
                    entities.Add(newAssetEntity);
                }

                // Clear the experiment measures
                measureDataModel.DeleteExperimentMeasures(CurExperiment);

                // Clear the experiment entities
                ClearExperimentEntities();

                // Connect to database
                VisDashboardDataDataContext db = new VisDashboardDataDataContext();

                // Get Entity type for operators
                var query = from et in db.EntityTypes where et.Name == "Operator" select et;

                try
                {
                    operatorTypeID = query.Single().EntityTypeID;
                }
                catch (Exception)
                {
                    return;
                }

                // Get Entity type for assets
                query = from et in db.EntityTypes where et.Name == "Asset" select et;

                try
                {
                    assetTypeID = query.Single().EntityTypeID;
                }
                catch (Exception)
                {
                    return;
                }

                // Add the new experiment DMs
                ExperimentEntity newExpEntity = null;

                foreach (String id in dmIDs)
                {
                    newExpEntity = new ExperimentEntity();
                    newExpEntity.Name = id;
                    newExpEntity.ExperimentID = CurExperiment.ExperimentID;
                    newExpEntity.EntityTypeID = operatorTypeID;
                    newExpEntity.OwnerExperimentEntityID = null;

                    db.ExperimentEntities.InsertOnSubmit(newExpEntity);
                    entityMap.Add(id, newExpEntity);
                }

                foreach (AssetEntity entity in entities)
                {
                    newExpEntity = new ExperimentEntity();
                    newExpEntity.Name = entity.AssetName;
                    newExpEntity.ExperimentID = CurExperiment.ExperimentID;
                    newExpEntity.EntityTypeID = assetTypeID;
                    if ((entity.OwnerName != null) && (entityMap.Keys.Contains(entity.OwnerName)))
                    {
                        newExpEntity.ExperimentEntity1 = entityMap[entity.OwnerName];
                    }
                    else
                    {
                        newExpEntity.OwnerExperimentEntityID = null;
                    }

                    db.ExperimentEntities.InsertOnSubmit(newExpEntity);
                    entityMap.Add(entity.AssetName, newExpEntity);
                }
                db.SubmitChanges();

                // Add new Experiment Measures
                ExperimentMeasure newExperimentMeasure = null;
                var queryMeasures = from p in db.Measures select p;

                foreach(UsersInExperiment user in CurExperiment.UsersInExperiments)
                {

                    foreach (var measure in queryMeasures)
                    {
                        if (measure.Name.CompareTo("Operator") == 0)
                        {
                            foreach (String id in dmIDs)
                            {
                                newExperimentMeasure = new ExperimentMeasure
                                {
                                    ExperimentID = CurExperiment.ExperimentID,
                                    MeasureID = measure.MeasureID,
                                    UserID = user.UserID,
                                    ExperimentEntity = entityMap[id],
                                    Allowed = false
                                };
                                db.ExperimentMeasures.InsertOnSubmit(newExperimentMeasure);
                            }
                        }
                        else if (measure.Name.CompareTo("Asset") == 0)
                        {
                            foreach (AssetEntity entity in entities)
                            {
                                newExperimentMeasure = new ExperimentMeasure
                                {
                                    ExperimentID = CurExperiment.ExperimentID,
                                    MeasureID = measure.MeasureID,
                                    UserID = user.UserID,
                                    ExperimentEntity = entityMap[entity.AssetName],
                                    Allowed = false
                                };
                                db.ExperimentMeasures.InsertOnSubmit(newExperimentMeasure);
                            }
                        }
                    }
                }

                db.SubmitChanges();

                // Reload experiment measures
                measureDataModel.LoadExperiementMeasures(CurExperiment,
                    UsersInExperiment);

            }
            catch (Exception)
            {
                return;
            }
        }
Esempio n. 3
0
        private void ReloadExperimentModels()
        {
            string curExpName            = (string)experimentNameCB.SelectedItem;
            var    myRadioButtonTemplate = this.Resources["myRadioButtonAll"] as DataTemplate;
            int    numColumns            = 0;

            // Clear all but the first (tree) column
            numColumns = measuresDataGrid.Columns.Count;
            for (int i = 1; i < numColumns; i++)
            {
                measuresDataGrid.Columns.RemoveAt(1);
            }
            for (int i = 1; i < numColumns; i++)
            {
                displayDataGrid.Columns.RemoveAt(1);
            }

            // Get the list of experiment users
            string[] experimentUsers = experimentDataModel.CurExperimentUsers;
            if ((experimentUsers == null) || (experimentUsers.Length <= 0))
            {
                measureDataModel = null;
                return;
            }

            // Reload the measure tab
            measureDataModel = new MeasuresDataModel(experimentUsers.Length);
            measureDataModel.LoadExperiementMeasures(experimentDataModel.CurExperiment,
                                                     experimentDataModel.UsersInExperiment);

            // Create column templates
            DataGridTemplateColumn templateColumn = new DataGridTemplateColumn {
                Header = "All", Width = 100
            };

            templateColumn.CellTemplate = myRadioButtonTemplate;
            measuresDataGrid.Columns.Add(templateColumn);

            for (int i = 0; i < measureDataModel.NumOperators; i++)
            {
                String templateName = "Operator" + (i + 1).ToString();
                myRadioButtonTemplate = this.Resources["myRadioButton" + templateName] as DataTemplate;
                templateColumn        = new DataGridTemplateColumn {
                    Header = experimentUsers[i], Width = 100
                };
                measuresDataGrid.Columns.Add(templateColumn);
                templateColumn.CellTemplate = myRadioButtonTemplate;
            }

            // Set item source (don't use static one created in XAML
            measuresDataGrid.ItemsSource = measureDataModel;


            // Reload the display tab
            displayDataModel = new DisplayDataModel(experimentUsers.Length);
            displayDataModel.LoadExperiementDisplays(experimentDataModel.CurExperiment,
                                                     experimentDataModel.UsersInExperiment);

            // Create column templates
            templateColumn = new DataGridTemplateColumn {
                Header = "All", Width = 100
            };
            myRadioButtonTemplate       = this.Resources["myRadioButtonAll"] as DataTemplate;
            templateColumn.CellTemplate = myRadioButtonTemplate;
            displayDataGrid.Columns.Add(templateColumn);

            for (int i = 0; i < displayDataModel.NumOperators; i++)
            {
                String templateName = "Operator" + (i + 1).ToString();
                myRadioButtonTemplate = this.Resources["myRadioButton" + templateName] as DataTemplate;
                templateColumn        = new DataGridTemplateColumn {
                    Header = experimentUsers[i], Width = 100
                };
                displayDataGrid.Columns.Add(templateColumn);
                templateColumn.CellTemplate = myRadioButtonTemplate;
            }

            // Set item source (don't use static one created in XAML
            displayDataGrid.ItemsSource = displayDataModel;
        }
        private void ReloadExperimentModels()
        {
            string curExpName = (string)experimentNameCB.SelectedItem;
            var myRadioButtonTemplate = this.Resources["myRadioButtonAll"] as DataTemplate;
            int numColumns = 0;

            // Clear all but the first (tree) column
            numColumns = measuresDataGrid.Columns.Count;
            for (int i = 1; i < numColumns; i++)
            {
                measuresDataGrid.Columns.RemoveAt(1);
            }
            for (int i = 1; i < numColumns; i++)
            {
                displayDataGrid.Columns.RemoveAt(1);
            }

            // Get the list of experiment users
            string[] experimentUsers = experimentDataModel.CurExperimentUsers;
            if ((experimentUsers == null) || (experimentUsers.Length <= 0))
            {
                measureDataModel = null;
                return;
            }

            // Reload the measure tab
            measureDataModel = new MeasuresDataModel(experimentUsers.Length);
            measureDataModel.LoadExperiementMeasures(experimentDataModel.CurExperiment,
                experimentDataModel.UsersInExperiment);

            // Create column templates
            DataGridTemplateColumn templateColumn = new DataGridTemplateColumn { Header = "All", Width = 100 };
            templateColumn.CellTemplate = myRadioButtonTemplate;
            measuresDataGrid.Columns.Add(templateColumn);

            for (int i = 0; i < measureDataModel.NumOperators; i++)
            {
                String templateName = "Operator" + (i + 1).ToString();
                myRadioButtonTemplate = this.Resources["myRadioButton" + templateName] as DataTemplate;
                templateColumn = new DataGridTemplateColumn { Header = experimentUsers[i], Width = 100 };
                measuresDataGrid.Columns.Add(templateColumn);
                templateColumn.CellTemplate = myRadioButtonTemplate;
            }

            // Set item source (don't use static one created in XAML
            measuresDataGrid.ItemsSource = measureDataModel;


            // Reload the display tab
            displayDataModel = new DisplayDataModel(experimentUsers.Length);
            displayDataModel.LoadExperiementDisplays(experimentDataModel.CurExperiment,
                experimentDataModel.UsersInExperiment);

            // Create column templates
            templateColumn = new DataGridTemplateColumn { Header = "All", Width = 100 };
            myRadioButtonTemplate = this.Resources["myRadioButtonAll"] as DataTemplate;
            templateColumn.CellTemplate = myRadioButtonTemplate;
            displayDataGrid.Columns.Add(templateColumn);

            for (int i = 0; i < displayDataModel.NumOperators; i++)
            {
                String templateName = "Operator" + (i + 1).ToString();
                myRadioButtonTemplate = this.Resources["myRadioButton" + templateName] as DataTemplate;
                templateColumn = new DataGridTemplateColumn { Header = experimentUsers[i], Width = 100 };
                displayDataGrid.Columns.Add(templateColumn);
                templateColumn.CellTemplate = myRadioButtonTemplate;
            }

            // Set item source (don't use static one created in XAML
            displayDataGrid.ItemsSource = displayDataModel;

        }