예제 #1
0
        public void SaveScenarioFileInfo()
        {
            if (CurExperiment == null)
            {
                return;
            }

            VisDashboardDataDataContext db = new VisDashboardDataDataContext();
            Experiment experiment          = null;

            var query = from e in db.Experiments
                        where e.ExperimentID == CurExperiment.ExperimentID
                        select e;

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

            experiment.ScenarioFilePath = CurExperiment.ScenarioFilePath;
            experiment.ScenarioFileType = CurExperiment.ScenarioFileType;

            db.SubmitChanges();
        }
예제 #2
0
        public bool AddNewUser(CreateUserInfo newUserInfo)
        {
            VisDashboardDataDataContext db = new VisDashboardDataDataContext();

            using (TransactionScope ts = new TransactionScope())
            {
                try
                {
                    // Lookup the role ID
                    Role desiredRole = null;
                    var  query       = from p in db.Roles where p.RoleName == newUserInfo.UserInRole select p;

                    try
                    {
                        desiredRole = query.Single();
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Could not process user role.", "User Creation Failed", MessageBoxButton.OK, MessageBoxImage.Error);
                        return(false);
                    }

                    // Try to add new user to database
                    User newUser = new User {
                        Username = newUserInfo.Username, Password = newUserInfo.Password
                    };
                    UserInRole newUserInRole = new UserInRole
                    {
                        ApplicationName = "DashboardPermissionTool",
                        RoleID          = desiredRole.RoleID
                    };

                    newUserInRole.User = newUser;
                    db.UserInRoles.InsertOnSubmit(newUserInRole);
                    db.SubmitChanges();
                    ts.Complete();
                }
                catch (SqlException e)
                {
                    if (e.Message.Contains("Violation of UNIQUE KEY constraint 'U_Username'. Cannot insert duplicate key in object 'dbo.User'"))
                    {
                        MessageBox.Show("This user already exists.", "User Creation Failed", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    else
                    {
                        MessageBox.Show("Database Error: " + e.Message, "User Creation Failed", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    return(false);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    return(false);
                }
            }

            return(true);
        }
예제 #3
0
        public bool UpdateConfigDisplay(ConfigDisplay configDisplay, int width, int height)
        {
            if (configDisplay == null)
            {
                return(false);
            }

            // Obtain the edited display display
            VisDashboardDataDataContext db      = new VisDashboardDataDataContext();
            ConfigDisplay existingConfigDisplay = null;

            using (TransactionScope ts = new TransactionScope())
            {
                try
                {
                    var query = from cd in db.ConfigDisplays
                                where cd.ConfigID == configDisplay.ConfigID &&
                                cd.Name == configDisplay.Name
                                select cd;

                    try
                    {
                        existingConfigDisplay = query.Single();
                    }
                    catch (Exception)
                    {
                        return(false);
                    }

                    // Update the size if needed
                    if ((existingConfigDisplay.Width != width) || (existingConfigDisplay.Height != height))
                    {
                        existingConfigDisplay.Width  = width;
                        existingConfigDisplay.Height = height;
                        db.SubmitChanges();
                    }
                }
                catch (SqlException e)
                {
                    MessageBox.Show("Database Error: " + e.Message, "Display Deletion Failed", MessageBoxButton.OK, MessageBoxImage.Error);
                    return(false);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    return(false);
                }
                finally
                {
                    ts.Complete();
                    ts.Dispose();
                    db = null;
                }
            }

            return(true);
        }
예제 #4
0
        public void DeleteExperimentDisplays(Experiment experiment)
        {
            if (experiment == null)
            {
                return;
            }

            VisDashboardDataDataContext db = new VisDashboardDataDataContext();

            var oldExperimentMeasures = from ed in db.ExperimentDisplays
                                        where ed.ExperimentID == experiment.ExperimentID
                                        select ed;

            db.ExperimentDisplays.DeleteAllOnSubmit(oldExperimentMeasures);
            db.SubmitChanges();
        }
예제 #5
0
        private void ClearExperimentEntities()
        {
            if (CurExperiment == null)
            {
                return;
            }

            VisDashboardDataDataContext db = new VisDashboardDataDataContext();

            var oldEntities = from e in db.ExperimentEntities
                              where e.ExperimentID == CurExperiment.ExperimentID
                              select e;

            db.ExperimentEntities.DeleteAllOnSubmit(oldEntities);
            db.SubmitChanges();
        }
예제 #6
0
        public bool AddNewConfig(CreateConfigInfo newConfigInfo)
        {
            VisDashboardDataDataContext db = new VisDashboardDataDataContext();

            using (TransactionScope ts = new TransactionScope())
            {
                try
                {
                    Config newConfig = new Config
                    {
                        Name         = newConfigInfo.Name,
                        ExperimentID = newConfigInfo.ExperimentID
                    };

                    db.Configs.InsertOnSubmit(newConfig);
                    db.SubmitChanges();
                }
                catch (SqlException e)
                {
                    MessageBox.Show("Database Error: " + e.Message, "Config Creation Failed", MessageBoxButton.OK, MessageBoxImage.Error);
                    return(false);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    return(false);
                }
                finally
                {
                    ts.Complete();
                    ts.Dispose();
                    db = null;
                }
            }

            return(true);
        }
예제 #7
0
        public void SaveDatabaseChanges()
        {
            if (dbContext != null)
            {
                // Add pending adds
                foreach (UsersInExperiment addObject in pendingAdds)
                {
                    // Make sure this add object does not already exist
                    UsersInExperiment[] userInExperiment = (from uIe in dbContext.UsersInExperiments
                                                            where ((uIe.UserID == addObject.UserID) && (uIe.ExperimentID == ExpDataModel.CurExperiment.ExperimentID))
                                                            select uIe).ToArray();

                    if (userInExperiment.Length == 0)
                    {
                        dbContext.UsersInExperiments.InsertOnSubmit(addObject);
                    }
                }

                // Add pending deletes
                foreach (int deleteUserID in pendingDeletes)
                {
                    UsersInExperiment[] userInExperiment = (from uIe in dbContext.UsersInExperiments
                                                            where ((uIe.UserID == deleteUserID) && (uIe.ExperimentID == ExpDataModel.CurExperiment.ExperimentID))
                                                            select uIe).ToArray();
                    if (userInExperiment.Length == 1)
                    {
                        DatabaseHelper.DeleteByPK <UsersInExperiment, int>(userInExperiment[0].ID, dbContext);
                    }
                }

                dbContext.SubmitChanges();
                ts.Complete();
                ts.Dispose();
                dbContext = null;
            }
        }
예제 #8
0
        public Boolean RemoveCurrentDisplay()
        {
            // Remove the current display if it already exists
            VisDashboardDataDataContext db      = new VisDashboardDataDataContext();
            ConfigDisplay existingConfigDisplay = null;

            using (TransactionScope ts = new TransactionScope())
            {
                try
                {
                    var query = from cd in db.ConfigDisplays
                                where cd.ConfigID == CurConfig.ConfigID &&
                                cd.Name == CurConfigDisplay.Name
                                select cd;

                    try
                    {
                        existingConfigDisplay = query.Single();
                    }
                    catch (Exception)
                    {
                        return(false);
                    }

                    // Delete any contained DisplayFactors
                    foreach (DisplayFactor factor in existingConfigDisplay.DisplayFactors)
                    {
                        db.DisplayFactors.DeleteOnSubmit(factor);
                    }

                    // Delete any contained DisplayBlockedFactors
                    foreach (DisplayBlockedFactor blockedFactor in existingConfigDisplay.DisplayBlockedFactors)
                    {
                        db.DisplayBlockedFactors.DeleteOnSubmit(blockedFactor);
                    }

                    // Delete this ConfigDisplay
                    db.ConfigDisplays.DeleteOnSubmit(existingConfigDisplay);

                    db.SubmitChanges();
                }
                catch (SqlException e)
                {
                    MessageBox.Show("Database Error: " + e.Message, "Display Deletion Failed", MessageBoxButton.OK, MessageBoxImage.Error);
                    return(false);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    return(false);
                }
                finally
                {
                    ts.Complete();
                    ts.Dispose();
                    db = null;
                }
            }

            return(true);
        }
예제 #9
0
        public Boolean AddCurrentDisplay()
        {
            VisDashboardDataDataContext db = new VisDashboardDataDataContext();

            using (TransactionScope ts = new TransactionScope())
            {
                try
                {
                    // Copy data into new object
                    ConfigDisplay newConfigDisplay = new ConfigDisplay
                    {
                        Name              = CurConfigDisplay.Name,
                        ConfigID          = CurConfig.ConfigID,
                        DisplayID         = CurConfigDisplay.Display.DisplayID,
                        MeasureName       = CurConfigDisplay.MeasureName,
                        MetricName        = CurConfigDisplay.MetricName,
                        NumFactors        = CurConfigDisplay.NumFactors,
                        NumBlockedFactors = CurConfigDisplay.NumBlockedFactors,
                        Width             = CurConfigDisplay.Width,
                        Height            = CurConfigDisplay.Height
                    };

                    // Copy DisplayFactors to new object
                    foreach (DisplayFactor factor in CurConfigDisplay.DisplayFactors)
                    {
                        DisplayFactor newDisplayFactor = new DisplayFactor
                        {
                            FactorName  = factor.FactorName,
                            FactorLabel = factor.FactorLabel,
                            FactorPos   = factor.FactorPos
                        };
                        newConfigDisplay.DisplayFactors.Add(newDisplayFactor);
                    }

                    // Copy DisplayBlockedFactors to new object
                    foreach (DisplayBlockedFactor blockedFactor in CurConfigDisplay.DisplayBlockedFactors)
                    {
                        DisplayBlockedFactor newDisplayBlockedFactor = new DisplayBlockedFactor
                        {
                            MeasureID = blockedFactor.MeasureID,
                            LevelName = blockedFactor.LevelName
                        };
                        newConfigDisplay.DisplayBlockedFactors.Add(newDisplayBlockedFactor);
                    }

                    db.ConfigDisplays.InsertOnSubmit(newConfigDisplay);
                    db.SubmitChanges();
                }
                catch (SqlException e)
                {
                    MessageBox.Show("Database Error: " + e.Message, "Display Creation Failed", MessageBoxButton.OK, MessageBoxImage.Error);
                    return(false);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    return(false);
                }
                finally
                {
                    ts.Complete();
                    ts.Dispose();
                    db = null;
                }
            }

            return(true);
        }
예제 #10
0
        public Boolean AddCurrentDisplay()
        {
            VisDashboardDataDataContext db = new VisDashboardDataDataContext();

            using (TransactionScope ts = new TransactionScope())
            {
                try
                {
                    // Copy data into new object
                    ConfigDisplay newConfigDisplay = new ConfigDisplay
                    {
                        Name = CurConfigDisplay.Name,
                        ConfigID = CurConfig.ConfigID,
                        DisplayID = CurConfigDisplay.Display.DisplayID,
                        MeasureName = CurConfigDisplay.MeasureName,
                        MetricName = CurConfigDisplay.MetricName,
                        NumFactors = CurConfigDisplay.NumFactors,
                        NumBlockedFactors = CurConfigDisplay.NumBlockedFactors,
                        Width = CurConfigDisplay.Width,
                        Height = CurConfigDisplay.Height
                    };

                    // Copy DisplayFactors to new object
                    foreach (DisplayFactor factor in CurConfigDisplay.DisplayFactors)
                    {
                        DisplayFactor newDisplayFactor = new DisplayFactor
                        {
                            FactorName = factor.FactorName,
                            FactorLabel = factor.FactorLabel,
                            FactorPos = factor.FactorPos
                        };
                        newConfigDisplay.DisplayFactors.Add(newDisplayFactor);
                    }

                    // Copy DisplayBlockedFactors to new object
                    foreach (DisplayBlockedFactor blockedFactor in CurConfigDisplay.DisplayBlockedFactors)
                    {
                        DisplayBlockedFactor newDisplayBlockedFactor = new DisplayBlockedFactor
                        {
                            MeasureID = blockedFactor.MeasureID,
                            LevelName = blockedFactor.LevelName
                        };
                        newConfigDisplay.DisplayBlockedFactors.Add(newDisplayBlockedFactor);
                    }

                    db.ConfigDisplays.InsertOnSubmit(newConfigDisplay);
                    db.SubmitChanges();
                }
                catch (SqlException e)
                {
                    MessageBox.Show("Database Error: " + e.Message, "Display Creation Failed", MessageBoxButton.OK, MessageBoxImage.Error);
                    return false;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    return false;
                }
                finally
                {
                    ts.Complete();
                    ts.Dispose();
                    db = null;
                }
            }

            return true;
        }
예제 #11
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;
            }
        }
예제 #12
0
        public void SaveScenarioFileInfo()
        {
            if (CurExperiment == null)
            {
                return;
            }

            VisDashboardDataDataContext db = new VisDashboardDataDataContext();
            Experiment experiment = null;

            var query = from e in db.Experiments
                      where e.ExperimentID == CurExperiment.ExperimentID
                      select e;

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

            experiment.ScenarioFilePath = CurExperiment.ScenarioFilePath;
            experiment.ScenarioFileType = CurExperiment.ScenarioFileType;

            db.SubmitChanges();
        }
예제 #13
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;
            }
        }
예제 #14
0
        public bool AddNewUser(CreateUserInfo newUserInfo)
        {
            VisDashboardDataDataContext db = new VisDashboardDataDataContext();

            using (TransactionScope ts = new TransactionScope())
            {
                try
                {
                    // Lookup the role ID
                    Role desiredRole = null;
                    var query = from p in db.Roles where p.RoleName == newUserInfo.UserInRole select p;

                    try
                    {
                        desiredRole = query.Single();
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Could not process user role.", "User Creation Failed", MessageBoxButton.OK, MessageBoxImage.Error);
                        return false;
                    }

                    // Try to add new user to database
                    User newUser = new User { Username = newUserInfo.Username, Password = newUserInfo.Password };
                    UserInRole newUserInRole = new UserInRole
                        {
                            ApplicationName = "DashboardPermissionTool",
                            RoleID = desiredRole.RoleID                            
                        };

                    newUserInRole.User = newUser;
                    db.UserInRoles.InsertOnSubmit(newUserInRole);
                    db.SubmitChanges();
                    ts.Complete();
                }
                catch (SqlException e)
                {
                    if (e.Message.Contains("Violation of UNIQUE KEY constraint 'U_Username'. Cannot insert duplicate key in object 'dbo.User'"))
                    {
                        MessageBox.Show("This user already exists.", "User Creation Failed", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    else
                    {
                        MessageBox.Show("Database Error: " + e.Message, "User Creation Failed", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    return false;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    return false;
                }
            }

            return true;
        }
예제 #15
0
        public bool UpdateConfigDisplay(ConfigDisplay configDisplay, int width, int height)
        {
            if (configDisplay == null)
            {
                return false;
            }

            // Obtain the edited display display
            VisDashboardDataDataContext db = new VisDashboardDataDataContext();
            ConfigDisplay existingConfigDisplay = null;

            using (TransactionScope ts = new TransactionScope())
            {
                try
                {
                    var query = from cd in db.ConfigDisplays
                                where cd.ConfigID == configDisplay.ConfigID &&
                                cd.Name == configDisplay.Name
                                select cd;

                    try
                    {
                        existingConfigDisplay = query.Single();
                    }
                    catch (Exception)
                    {
                        return false;
                    }

                    // Update the size if needed
                    if ((existingConfigDisplay.Width != width) || (existingConfigDisplay.Height != height))
                    {
                        existingConfigDisplay.Width = width;
                        existingConfigDisplay.Height = height;
                        db.SubmitChanges();
                    }
                }
                catch (SqlException e)
                {
                    MessageBox.Show("Database Error: " + e.Message, "Display Deletion Failed", MessageBoxButton.OK, MessageBoxImage.Error);
                    return false;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    return false;
                }
                finally
                {
                    ts.Complete();
                    ts.Dispose();
                    db = null;
                }
            }

            return true;

        }
예제 #16
0
        public bool AddNewConfig(CreateConfigInfo newConfigInfo)
        {
            VisDashboardDataDataContext db = new VisDashboardDataDataContext();

            using (TransactionScope ts = new TransactionScope())
            {
                try
                {
                    Config newConfig = new Config
                    {
                        Name = newConfigInfo.Name,
                        ExperimentID = newConfigInfo.ExperimentID
                    };

                    db.Configs.InsertOnSubmit(newConfig);
                    db.SubmitChanges();
                }
                catch (SqlException e)
                {
                    MessageBox.Show("Database Error: " + e.Message, "Config Creation Failed", MessageBoxButton.OK, MessageBoxImage.Error);
                    return false;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    return false;
                }
                finally
                {
                    ts.Complete();
                    ts.Dispose();
                    db = null;
                }
            }

            return true;
        }
예제 #17
0
        private void ClearExperimentEntities()
        {
            if (CurExperiment == null)
            {
                return;
            }

            VisDashboardDataDataContext db = new VisDashboardDataDataContext();

            var oldEntities = from e in db.ExperimentEntities
                        where e.ExperimentID == CurExperiment.ExperimentID
                        select e;

            db.ExperimentEntities.DeleteAllOnSubmit(oldEntities);
            db.SubmitChanges();
        }
예제 #18
0
        public Boolean RemoveCurrentDisplay()
        {
            // Remove the current display if it already exists
            VisDashboardDataDataContext db = new VisDashboardDataDataContext();
            ConfigDisplay existingConfigDisplay = null;

            using (TransactionScope ts = new TransactionScope())
            {
                try
                {
                    var query = from cd in db.ConfigDisplays
                                where cd.ConfigID == CurConfig.ConfigID &&
                                cd.Name == CurConfigDisplay.Name
                                select cd;

                    try
                    {
                        existingConfigDisplay = query.Single();
                    }
                    catch (Exception)
                    {
                        return false;
                    }

                    // Delete any contained DisplayFactors
                    foreach (DisplayFactor factor in existingConfigDisplay.DisplayFactors)
                    {
                        db.DisplayFactors.DeleteOnSubmit(factor);
                    }

                    // Delete any contained DisplayBlockedFactors
                    foreach (DisplayBlockedFactor blockedFactor in existingConfigDisplay.DisplayBlockedFactors)
                    {
                        db.DisplayBlockedFactors.DeleteOnSubmit(blockedFactor);
                    }

                    // Delete this ConfigDisplay
                    db.ConfigDisplays.DeleteOnSubmit(existingConfigDisplay);

                    db.SubmitChanges();
                }
                catch (SqlException e)
                {
                    MessageBox.Show("Database Error: " + e.Message, "Display Deletion Failed", MessageBoxButton.OK, MessageBoxImage.Error);
                    return false;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    return false;
                }
                finally
                {
                    ts.Complete();
                    ts.Dispose();
                    db = null;
                }
            }

            return true;
        }
예제 #19
0
        public void SaveExperiementDisplays(Experiment currentExperiment,
                                            ObservableCollection <User> experimentUsers)
        {
            VisDashboardDataDataContext db = null;

            // Parameter checking
            if ((currentExperiment == null) || (experimentUsers == null) ||
                (experimentUsers.Count == 0))
            {
                return;
            }

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

            using (TransactionScope ts = new TransactionScope())
            {
                try
                {
                    // Remove old experiment measures entries
                    var itemsToDelete = from em in db.ExperimentDisplays
                                        where em.ExperimentID == currentExperiment.ExperimentID
                                        select em;
                    db.ExperimentDisplays.DeleteAllOnSubmit(itemsToDelete);

                    // Loop through the data in radio button table
                    for (int i = 0; i < this.Count; i++)
                    {
                        if (this[i].DisplayID > 0)
                        {
                            for (int j = 0; j < experimentUsers.Count; j++)
                            {
                                if (this[i][j] == RadioButtonType.On)
                                {
                                    db.ExperimentDisplays.InsertOnSubmit(new ExperimentDisplay
                                    {
                                        ExperimentID = currentExperiment.ExperimentID,
                                        DisplayID    = this[i].DisplayID,
                                        UserID       = experimentUsers[j].UserID
                                    });
                                }
                            }
                        }
                    }

                    // Submit the database changes
                    db.SubmitChanges();
                }
                catch (SqlException e)
                {
                    MessageBox.Show("Database Error: " + e.Message, "Failed to save database displays", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    return;
                }
                finally
                {
                    // Cleanup
                    ts.Complete();
                    ts.Dispose();
                    db = null;
                }
            }
        }