/// <summary>
 ///     Removes a soup name from the master soup, if it exists.
 /// </summary>
 /// <param name="soupName"></param>
 private void RemoveSoupNameFromMasterSoup(String soupName)
 {
     if (!DoesMasterSoupContainSoup(soupName))
     {
         return;
     }
     try
     {
         long soupEntryId = _smartStore.LookupSoupEntryId(SoupOfSoups,
                                                          SoupNamesKey, soupName);
         _smartStore.Delete(SoupOfSoups, new[] { soupEntryId }, false);
     }
     catch (SmartStoreException e)
     {
         Debug.WriteLine("SmartStoreException occurred while attempting to cache data: ", e.ToString());
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 ///     Removes a soup name from the master soup, if it exists.
 /// </summary>
 /// <param name="soupName"></param>
 private void RemoveSoupNameFromMasterSoup(String soupName)
 {
     if (!DoesMasterSoupContainSoup(soupName))
     {
         return;
     }
     try
     {
         long soupEntryId = _smartStore.LookupSoupEntryId(SoupOfSoups,
                                                          SoupNamesKey, soupName);
         _smartStore.Delete(SoupOfSoups, new[] { soupEntryId }, false);
     }
     catch (SmartStoreException e)
     {
         PlatformAdapter.SendToCustomLogger(e, LoggingLevel.Error);
         Debug.WriteLine("SmartStoreException occurred while attempting to cache data");
     }
 }
Ejemplo n.º 3
0
        private async Task <bool> SyncUpOneRecord(SyncUpTarget target, string soupName, List <string> fieldList, JObject record,
                                                  SyncState.MergeModeOptions mergeMode)
        {
            var action = SyncAction.None;

            if (record.ExtractValue <bool>(LocallyDeleted))
            {
                action = SyncAction.Delete;
            }
            else if (record.ExtractValue <bool>(LocallyCreated))
            {
                action = SyncAction.Create;
            }
            else if (record.ExtractValue <bool>(LocallyUpdated))
            {
                action = SyncAction.Update;
            }
            if (SyncAction.None == action)
            {
                // nothing to do for this record
                return(true);
            }

            // getting type and id

            string objectType       = SmartStore.Store.SmartStore.Project(record, Constants.SobjectType).ToString();
            var    objectId         = record.ExtractValue <string>(target.GetId());
            var    lastModifiedDate = record.ExtractValue <DateTime>(target.GetModificationDate()).Ticks;

            /*
             * Check if we're attempting to update a record that has been updated on the server after the client update.
             * If merge mode passed in tells us to leave the record alone, we will do nothing and return here.
             */
            if (SyncState.MergeModeOptions.LeaveIfChanged == mergeMode &&
                (action == SyncAction.Update || action == SyncAction.Delete))
            {
                bool isNewer = await IsNewerThanServer(target, objectType, objectId, lastModifiedDate.ToString());

                if (!isNewer)
                {
                    return(true);
                }
            }

            var fields = new Dictionary <string, object>();

            if (SyncAction.Create == action || SyncAction.Update == action)
            {
                foreach (
                    string fieldName in
                    fieldList.Where(fieldName => !target.GetId().Equals(fieldName, StringComparison.CurrentCulture) &&
                                    !target.GetModificationDate().Equals(fieldName, StringComparison.CurrentCulture) &&
                                    !Constants.SystemModstamp.Equals(fieldName, StringComparison.CurrentCulture)))
                {
                    fields.Add(fieldName, record[fieldName]);
                }
            }

            switch (action)
            {
            case SyncAction.Create:
                String recordServerId = await target.CreateOnServerAsync(this, objectType, fields);

                if (recordServerId != null)
                {
                    record[target.GetId()] = recordServerId;
                    CleanAndSaveRecord(soupName, record);
                }
                break;

            case SyncAction.Delete:
                if (await target.DeleteOnServer(this, objectType, objectId))
                {
                    _smartStore.Delete(soupName,
                                       new[] { record.ExtractValue <long>(SmartStore.Store.SmartStore.SoupEntryId) }, false);
                }
                break;

            case SyncAction.Update:
                if (await target.UpdateOnServer(this, objectType, objectId, fields))
                {
                    CleanAndSaveRecord(soupName, record);
                }
                break;
            }

            return(false);
        }