Пример #1
0
        public void SaveAccount(UserAccount account)
        {
            var data        = account.ToData();
            var allData     = GetData <AccountData>();
            var newDataList = allData.Where(d => d.Id != data.Id).Concat(new[] { data }).ToArray();

            CachedDataAccess.Save(WebCache, newDataList);
        }
Пример #2
0
        public void SaveNote(Note note)
        {
            var data        = note.ToData();
            var allNotes    = GetData <NoteData>();
            var newAllNotes = allNotes.Where(n => n.Id != data.Id).Concat(new[] { data });

            CachedDataAccess.Save(WebCache, newAllNotes.ToArray());
        }
Пример #3
0
        //updates or creates the new item
        public void Save(T item)
        {
            Delete(item.Id);

            var allData = RetreiveAll();
            var newData = allData.Concat(new T[] { item });
            var cache   = HttpContext.Current.Cache;

            CachedDataAccess.Save(cache, newData);
        }
Пример #4
0
        //removes entry from file table
        public void Delete(Guid id)
        {
            var allData = RetreiveAll();
            var newData = allData.Where(d => d.Id != id).ToArray();

            if (newData.Length != allData.Length)
            {
                var cache = HttpContext.Current.Cache;
                CachedDataAccess.Save(cache, newData);
            }
        }
Пример #5
0
        private T[] GetData <T>() where T : class
        {
            var allData = CachedDataAccess.Get <T[]>(WebCache);

            if (allData == null)
            {
                allData = new T[] { };
                CachedDataAccess.Save(WebCache, allData);
            }
            return(allData);
        }
Пример #6
0
        void Application_Start(object sender, EventArgs e)
        {
            // Code that runs on application startup
            GlobalConfiguration.Configure(WebApiConfig.Register);

            RouteConfig.RegisterRoutes(RouteTable.Routes);
            GlobalFilters.Filters.Add(new MvcCookieAuthorizeAttribute());

            var config = new SiteConfiguration();

            CachedDataAccess.Initialize(config.TypecacheStorageDirectory);
        }
Пример #7
0
        //gets all data of type, creates file table if missing
        public T[] RetreiveAll()
        {
            var cache   = HttpContext.Current.Cache;
            var allData = CachedDataAccess.Get <T[]>(cache);

            if (allData == null)
            {
                allData = new T[] { };
                CachedDataAccess.Save(cache, allData);
            }
            return(allData);
        }
Пример #8
0
        public UserAccount CreateNewUser(string email, string password)
        {
            var salt        = Guid.NewGuid().ToString();
            var accountData = new AccountData()
            {
                Email           = email,
                PasswordHash    = AuthorizationHelper.HashPassword(password, salt),
                PasswordSalt    = salt,
                AuthToken       = null,
                DisplayUsername = string.Empty,
                Id      = Guid.NewGuid(),
                NoteIds = new Guid[] { }
            };

            var allAccounts = GetData <AccountData>().Concat(new[] { accountData }).ToArray();

            CachedDataAccess.Save(WebCache, allAccounts);

            return(GetAccountById(accountData.Id));
        }