Пример #1
0
        /// <summary>
        /// Create a new user to the database.
        /// </summary>
        /// <param name="userName">UserName for the user, existing or desired.</param>
        /// <param name="hashedPassword">The pre-hashed password for this user.</param>
        /// <param name="email">The email address of this user.</param>
        /// <param name="name">The actual name of this user.</param>
        /// <param name="roles">A comma seperated list of roles assigned to this user.</param>
        /// <param name="affiliation">The company or organization the user is affiliated with.
        /// Not necessarily the Network Preservation org, but could also be.</param>
        /// <param name="network">Did this user request to be recognized as a Network member?</param>
        public static User CreateUser(string userName, string hashedPassword, string email,
                                      string name, string roles, string affiliation = null, bool network = false)
        {
            User user = new User();

            // Apply the information to the account
            user.UserName         = userName;
            user.Password         = hashedPassword;
            user.Email            = email;
            user.Name             = name;
            user.Active           = true;
            user.Affiliation      = affiliation;
            user.NetworkRequested = network;

            if (StringHelper.IsNonBlank(roles))
            {
                user.Roles = roles;
            }
            else
            {
                user.Roles = [email protected]("G");
            }
            user.SetConfirmationToken();
            _userDao.Insert(user);

            return(user);
        }
        /// <summary>
        /// Add an organization to the database.
        /// </summary>
        /// <param name="name"></param>
        public static void Add(string name)
        {
            var org = new Organization {
                Name = name, Active = true
            };

            _orgWriteDao.Insert(org);
        }
        private static void CreateRestriction(SecurityRole role)
        {
            var vis = new ChildResourceInfo
            {
                Resource       = ChildResourceType.ReacHistory,
                RoleForDisplay = role
            };

            _restricDao.Insert(vis);
        }
Пример #4
0
        public static void AddUploadRevision(UploadTypes type, String data, User u)
        {
            var ur = new PdbUploadRevision
            {
                Type   = type.ToString(),
                Data   = data,
                Date   = DateTime.Now,
                UserId = u.Id
            };

            _urDao.Insert(ur);
        }
        public void SetUp()
        {
            _reacDao.Truncate();
            _restricDao.Truncate();

            var reac = new Reac
            {
                NlihcId     = _id,
                Score       = "23a*",
                ScoreDate   = DateTime.Today,
                ScoreLetter = "a",
                ScoreNum    = 23
            };

            _reacDao.Insert(reac);
        }
Пример #6
0
        public static Comment AddComment(string nlihcId, User user,
                                         CommentAccessLevel level, string text, byte[] image)
        {
            var imageVal = image ?? new byte[] {};

            var created = DateTime.Now;
            var comment = new Comment
            {
                NlihcId         = nlihcId,
                AccessLevel     = level,
                AssociatedOrgId = GetAssociatedOrgId(user, level),
                Created         = created,
                Modified        = created,
                Username        = user.UserName,
                Text            = text,
                Image           = imageVal
            };

            _dao.Insert(comment, true);
            return(comment);
        }
        /// <summary>
        /// Import from a class defined csv file.  Remove all existing
        /// records in the target data set, load new rows and archive
        /// the records for restore points
        /// </summary>
        /// <param name="data"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public ImportResult Load(Stream data, User user)
        {
            if (ReadOnly)
            {
                return(null);
            }

            var reader = new StreamReader(data);
            var csv    = reader.ReadToEnd();

            var engine = new FileHelperEngine <T> {
                ErrorMode = ErrorMode.SaveAndContinue
            };
            var rows    = engine.ReadString(csv);
            var results = new ImportResult {
                ImportCount = rows.Length, Errors = engine.ErrorManager
            };

            if (results.Errors.ErrorCount == 0)
            {
                var trans = new SqlTransaction((AbstractSqlConnectionDescriptor)_writeDao.ConnDesc);
                try
                {
                    // Refresh the data if successfull
                    PreProcess(trans, rows);
                    _writeDao.DeleteAll(trans);
                    _writeDao.Insert(trans, rows);
                    PostProcess(trans, rows);
                    trans.Commit();

                    PdbUploadRevision.AddUploadRevision(UploadType, csv, user);
                }
                catch (Exception)
                {
                    trans.Rollback();
                    throw;
                }
            }
            return(results);
        }
Пример #8
0
        /// <summary>
        /// Create a new user to the database.
        /// </summary>
        /// <param name="userName">UserName for the user, existing or desired.</param>
        /// <param name="hashedPassword">The pre-hashed password for this user.</param>
        /// <param name="email">The email address of this user.</param>
        /// <param name="name">The actual name of this user.</param>
        /// <param name="roles">A comma seperated list of roles assigned to this user.</param>
        public static User CreateUser(string userName, string hashedPassword, string email,
                                      string name, string roles)
        {
            User user = new User();

            // Apply the information to the account
            user.UserName = userName;
            user.Password = hashedPassword;
            user.Email    = email;
            user.Name     = name;
            if (StringHelper.IsNonBlank(roles))
            {
                user.Roles = roles;
            }
            else
            {
                user.Roles = [email protected]("G");
            }

            _userDao.Insert(user);

            return(user);
        }
Пример #9
0
        public void TestWriteCsv()
        {
            CsvTestObj testObj1 = new CsvTestObj();
            CheckedDictionary<string, object> testDict1 = new CheckedDictionary<string, object>();
            testObj1.One = 50;
            testObj1.Two = -1.0;
            testObj1.Three = "Yo";
            testObj1.Four = new DateTime(2001, 1, 1, 1, 1, 1);
            testObj1.Five = null;
            testDict1["One"] = testObj1.One;
            testDict1["Two"] = testObj1.Two;
            testDict1["Three"] = testObj1.Three;
            testDict1["Four"] = testObj1.Four;
            testDict1["Five"] = testObj1.Five;

            CsvTestObj testObj2 = new CsvTestObj();
            CheckedDictionary<string, object> testDict2 = new CheckedDictionary<string, object>();
            testObj2.One = int.MaxValue;
            testObj2.Two = double.MinValue;
            testObj2.Three = null;
            testObj2.Four = DateTime.MinValue;
            testObj2.Five = "";
            testDict2["One"] = testObj2.One;
            testDict2["Two"] = testObj2.Two;
            testDict2["Three"] = testObj2.Three;
            testDict2["Four"] = testObj2.Four;
            testDict2["Five"] = testObj2.Five;

            ClassMapping mapping1 = MakeMapping("n/a", "WriteOne", true);
            CsvDescriptor desc1 = new CsvDescriptor("..\\..\\Tests");
            DictionaryDao dao1 = new DictionaryDao(desc1, mapping1);
            dao1.Truncate();
            dao1.Insert(testDict1);
            dao1.Insert(testDict2);

            ClassMapping mapping2 = MakeMapping("Azavea.Open.DAO.CSV.Tests.CsvTestObj,Azavea.Open.DAO.CSV", "Doesn'tMatter", true);
            CsvDescriptor desc2 = new CsvDescriptor(CsvConnectionType.FileName,
                                                    "..\\..\\Tests\\WriteTwo.csv");
            FastDAO<CsvTestObj> dao2 = new FastDAO<CsvTestObj>(desc2, mapping2);
            dao2.Truncate();
            dao2.Insert(testObj1);
            dao2.Insert(testObj2);

            ClassMapping mapping3 = MakeMapping("n/a", "AlsoDoesn'tMatter", true);
            using (StreamWriter sw = new StreamWriter("..\\..\\Tests\\WriteThree.csv", false))
            {
                CsvDescriptor desc3 = new CsvDescriptor(sw);
                DictionaryDao dao3 = new DictionaryDao(desc3, mapping3);
                // Can't truncate this one.
                dao3.Insert(testDict1);
                dao3.Insert(testDict2);
            }

            ClassMapping mapping4 = MakeMapping("n/a", "WriteFour", false);
            CsvDescriptor desc4 = new CsvDescriptor("..\\..\\Tests");
            DictionaryDao dao4 = new DictionaryDao(desc4, mapping4);
            dao4.Truncate();
            dao4.Insert(testDict1);
            dao4.Insert(testDict2);

            ClassMapping mapping5 = MakeMapping("Azavea.Open.DAO.CSV.Tests.CsvTestObj,Azavea.Open.DAO.CSV", "Doesn'tMatter", false);
            CsvDescriptor desc5 = new CsvDescriptor(CsvConnectionType.FileName,
                                                    "..\\..\\Tests\\WriteFive.csv");
            FastDAO<CsvTestObj> dao5 = new FastDAO<CsvTestObj>(desc5, mapping5);
            dao5.Truncate();
            dao5.Insert(testObj1);
            dao5.Insert(testObj2);

            ClassMapping mapping6 = MakeMapping("n/a", "AlsoDoesn'tMatter", false);
            using (StreamWriter sw = new StreamWriter("..\\..\\Tests\\WriteSix.csv", false))
            {
                CsvDescriptor desc6 = new CsvDescriptor(sw);
                DictionaryDao dao6 = new DictionaryDao(desc6, mapping6);
                // Can't truncate this one.
                dao6.Insert(testDict1);
                dao6.Insert(testDict2);
            }

            // Now, assert they are all correct.  1, 2, and 3 should be the same (they have headers)
            // and 4, 5, and 6 should be the same (without headers).
            AssertFileContentsSame("..\\..\\Tests\\WriteOne.csv", "..\\..\\Tests\\WriteTwo.csv");
            AssertFileContentsSame("..\\..\\Tests\\WriteOne.csv", "..\\..\\Tests\\WriteThree.csv");
            AssertFileGreater("..\\..\\Tests\\WriteOne.csv", "..\\..\\Tests\\WriteFour.csv");
            AssertFileContentsSame("..\\..\\Tests\\WriteFour.csv", "..\\..\\Tests\\WriteFive.csv");
            AssertFileContentsSame("..\\..\\Tests\\WriteFour.csv", "..\\..\\Tests\\WriteFive.csv");
        }