Ejemplo n.º 1
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;
            }
        }
Ejemplo 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;
            }
        }