private Dictionary <string, object> getItemUpdates(AccountWin account, Guid identifier, List <ChangedProperty> changedProperties)
        {
            BaseItemWin item = account.Find(identifier);

            if (item == null)
            {
                return(null);
            }


            if (changedProperties.Any(i => i.PropertyName == BaseItemWin.PropertyNames.All))
            {
                foreach (ChangedProperty p in changedProperties)
                {
                    p.HasBeenSent = true;
                }

                return(item.SerializeToDictionary());
            }


            Dictionary <string, object> answer = new Dictionary <string, object>();

            answer["Identifier"] = identifier;
            answer["Updated"]    = item.Updated;

            foreach (ChangedProperty p in changedProperties)
            {
                answer[p.PropertyName.ToString()] = item.GetPropertyValue(p.PropertyName);
                p.HasBeenSent = true;
            }

            return(answer);
        }
        /// <summary>
        /// As long as Json.NET is used, it'll serialize dictionaries correctly. DataContractJson formats them as Key: xx Value: xx, which is incorrect.
        /// </summary>
        /// <param name="accountWin"></param>
        /// <returns></returns>
        public IEnumerable <Dictionary <string, object> > GetUpdates(AccountWin accountWin)
        {
            List <Dictionary <string, object> > answer = new List <Dictionary <string, object> >();

            foreach (var pair in Changes)
            {
                Dictionary <string, object> item = getItemUpdates(accountWin, pair.Key, pair.Value);

                if (item != null)
                {
                    answer.Add(item);
                }
            }

            return(answer);
        }
Beispiel #3
0
        /// <summary>
        /// Ensures there's only one reference of each account. Creates new account object if account file wasn't found.
        /// </summary>
        /// <param name="localAccountId"></param>
        /// <returns></returns>
        /// <exception cref="Exception">Throws exception if the folder for the account isn't found.</exception>
        private static async Task <AccountWin> getAccount(LoginWin login)
        {
            if (login.Account != null)
            {
                return(login.Account);
            }

            StorageFolder accountFolder = await GetAccountFolder(login.LocalAccountId);

            if (accountFolder == null)
            {
                throw new Exception("The folder for the requested account with id " + login.LocalAccountId + " wasn't found.");
            }



            //using (Stream s = await StorageHelper.LoadStream(accountFolder, Files.ACCOUNT_FILE))
            //{
            //    if (s != null)
            //        UIHandler.ShowMessageBox(new StreamReader(s).ReadToEnd(), "Data");
            //    //return null;
            //}



            AccountWin account = await StorageHelper.Load <AccountWin>(accountFolder, Files.ACCOUNT_FILE);

            if (account == null)
            {
                account = new AccountWin();
            }


            //just in case data was randomly wiped, we'll make sure it syncs everything
            //if (account.School.Years.Count == 0)
            //    account.CurrentChangeNumber = 0;

            //throw new ArgumentException("The account with id " + login.LocalAccountId + " was not found.");

            account.Login = login;
            login.Account = account;

            account.Initialize();


            return(account);
        }
Beispiel #4
0
        /// <summary>
        /// Returns all the updated items
        /// </summary>
        /// <param name="offset"></param>
        /// <returns></returns>
        public UpdatedItems Serialize(AccountWin account)
        {
            UpdatedItems answer = new UpdatedItems();

            //foreach (var pair in _changedItems)
            //{
            //    if (pair.Value.IsUpdated)
            //    {
            //        //mark it sent
            //        pair.Value.HasBeenSent = true;

            //        //find its item
            //        BaseItemWin entity = account.Find(pair.Key);
            //        if (entity == null)
            //            continue;

            //        //add the serialized item to the list
            //        answer.Add(entity.Serialize());
            //    }
            //}

            return(answer);
        }