public async void LoadDataFromSmartStore(bool includeEdit)
        {
            if (!_store.HasSoup(NotesSoup))
            {
                NotifyNotesSynced();
                return;
            }
            QuerySpec querySpec = QuerySpec.BuildAllQuerySpec(NotesSoup, NoteObject.TitleField,
                                                              QuerySpec.SqlOrder.ASC,
                                                              Limit);
            CoreDispatcher core    = CoreApplication.MainView.CoreWindow.Dispatcher;
            JArray         results = _store.Query(querySpec, 0);

            if (results == null)
            {
                NotifyNotesSynced();
                return;
            }
            NoteObject[] notes;

            if (includeEdit)
            {
                notes = (from note in results
                         let model = new NoteObject(note.Value <JObject>())
                                     select model).ToArray();
            }
            else
            {
                notes = (from note in results
                         let model = new NoteObject(note.Value <JObject>())
                                     where !model.ObjectId.Contains("local")
                                     orderby model.Title
                                     select model).ToArray();
            }
            string[] references =
                (from note in notes
                 let title = note.Title[0].ToString().ToLower()
                             group note by title
                             into g
                             orderby g.Key
                             select g.Key).ToArray();
            await core.RunAsync(CoreDispatcherPriority.Normal, () => IndexReference.Clear());

            await core.RunAsync(CoreDispatcherPriority.Normal, () => IndexReference.Add("all"));

            for (int i = 0, max = references.Length; i < max; i++)
            {
                int closure = i;
                await core.RunAsync(CoreDispatcherPriority.Normal, () => IndexReference.Add(references[closure]));
            }
            for (int i = 0, max = notes.Length; i < max; i++)
            {
                NoteObject t = notes[i];
                await UpdateNote(t);
            }
            NotifyNotesSynced();
            await core.RunAsync(CoreDispatcherPriority.Normal, () => MainPage.MainPageReference.UpdateTable());
        }
Exemplo n.º 2
0
        public IList <SuccessfulSync> GetAllSuccessfulSyncsFromSoup()
        {
            SetupSyncsSoupIfNotExists();
            var querySpec = QuerySpec.BuildAllQuerySpec(SoupName, SuccessfulSync.SyncIdIndexKey, QuerySpec.SqlOrder.ASC, SfdcConfig.PageSize).RemoveLimit(_store);
            var results   = _store.Query(querySpec, 0);

            var macList = results.Select(item => CustomPrefixJsonConvert.DeserializeObject <SuccessfulSync>(item.ToString())).ToList();

            return(macList);
        }
 public async void SaveContact(ContactObject contact, bool isCreated)
 {
     if (contact == null)
     {
         return;
     }
     try
     {
         QuerySpec querySpec = QuerySpec.BuildExactQuerySpec(ContactSoup, Constants.Id, contact.ObjectId, 1);
         JArray    returned  = _store.Query(querySpec, 0);
         JObject   item      = returned.Count > 0 ? returned[0].ToObject <JObject>() : new JObject();
         item[ContactObject.FirstNameField]  = contact.FirstName;
         item[ContactObject.LastNameField]   = contact.LastName;
         item[Constants.NameField]           = contact.ContactName;
         item[ContactObject.TitleField]      = contact.Title;
         item[ContactObject.DepartmentField] = contact.Department;
         item[ContactObject.PhoneField]      = contact.Phone;
         item[ContactObject.EmailField]      = contact.Email;
         item[ContactObject.AddressField]    = contact.Address;
         item[SyncManager.Local]             = true;
         item[SyncManager.LocallyUpdated]    = !isCreated;
         item[SyncManager.LocallyCreated]    = isCreated;
         item[SyncManager.LocallyDeleted]    = false;
         if (isCreated && item[Constants.Attributes.ToLower()] == null)
         {
             item[Constants.Id] = "local_" + SmartStore.CurrentTimeMillis;
             contact.ObjectId   = item[Constants.Id].Value <string>();
             var attributes = new JObject();
             attributes[Constants.Type.ToLower()] = Constants.Contact;
             item[Constants.Attributes.ToLower()] = attributes;
             _store.Create(ContactSoup, item);
         }
         else
         {
             _store.Upsert(ContactSoup, item);
         }
         contact.UpdatedOrCreated = true;
         await UpdateContact(contact);
     }
     catch (Exception)
     {
         Debug.WriteLine("Exception occurred while trying to save");
     }
 }
Exemplo n.º 4
0
        public IList <Model.Models.CategoryContent> GetAllFromSoup()
        {
            SetupNewCategoryContentSoupIfNotExists();
            var querySpec = QuerySpec.BuildAllQuerySpec(SoupName, "Id", QuerySpec.SqlOrder.ASC, SfdcConfig.PageSize).RemoveLimit(_store);
            var results   = _store.Query(querySpec, 0);

            var categoryContentList = results.Select(item => CustomPrefixJsonConvert.DeserializeObject <Model.Models.CategoryContent>(item.ToString())).ToList();

            return(categoryContentList);
        }
Exemplo n.º 5
0
        public bool CheckIfAccountExistsInSoup(Account account)
        {
            SetupSyncsSoupIfNotExistsNeeded();
            var querySpec = QuerySpec.BuildAllQuerySpec("LastLoggedAccountState", "UserName", QuerySpec.SqlOrder.ASC, SfdcConfig.PageSize).RemoveLimit(_store);

            var result = _store
                         .Query(querySpec, 0)
                         .Select(item => JsonConvert.DeserializeObject <LoginAccount>(item.ToString()))
                         .ToList();

            return(result.SingleOrDefault(item
                                          => item.UserName.Equals(account.UserName, StringComparison.OrdinalIgnoreCase) &&
                                          item.LoginUrl.Equals(account.LoginUrl, StringComparison.OrdinalIgnoreCase)) != null);
        }
Exemplo n.º 6
0
        public JArray Query(string smartSql)
        {
            JArray    result    = null;
            QuerySpec querySpec = QuerySpec.BuildSmartQuerySpec(smartSql, 10);
            var       count     = (int)_store.CountQuery(querySpec);

            querySpec = QuerySpec.BuildSmartQuerySpec(smartSql, count);
            try
            {
                result = _store.Query(querySpec, 0);
            }
            catch (SmartStoreException e)
            {
                Debug.WriteLine("Error occurred while attempting to run query. Please verify validity of the query.");
            }
            return(result);
        }