Beispiel #1
0
        public async Task SaveCompleteReviewToSoup(MediaLink mediaLink, bool emailed, double viewedTime, string playListId, string contactId)
        {
            await DispatcherHelper.RunAsync(async() =>
            {
                var location = await _geolocationService.GetLocation();
                var store    = SmartStore.GetGlobalSmartStore();
                SetupSoupIfNotExistsNeeded(store, SoupName);

                var contentReview = new ContentReview
                {
                    ContentId            = mediaLink.ID,
                    ContentTitle         = mediaLink.Name,
                    PlaylistId           = string.IsNullOrWhiteSpace(playListId) ? string.Empty : playListId,
                    ContactId            = string.IsNullOrWhiteSpace(contactId) ? string.Empty : contactId,
                    GeolocationLatitude  = location.Latitude,
                    GeolocationLongitude = location.Longitude,
                    DocumentEmailed      = emailed,
                    Rating     = 0,
                    TimeViewed = viewedTime
                };

                SaveReview(store, contentReview);
                SyncUpContentReview();
            });
        }
        public Task <bool> RemovePlaylist(String playlistId)
        {
            return(Task <bool> .Factory.StartNew(() =>
            {
                var globalStore = SmartStore.GetGlobalSmartStore();

                long internalId = globalStore.LookupSoupEntryId("Playlist", Constants.Id, playlistId);
                if (internalId == -1)
                {
                    return false;//cannot find item in soup
                }
                var items = globalStore.Retrieve("Playlist", internalId);
                if (items.Count == 0)
                {
                    return false;//canot retrieve item from soup
                }
                var item = items[0].ToObject <JObject>();
                var isLocalObject = Constants.ExtractValue <bool>(item, SyncManager.LocallyCreated);
                if (isLocalObject)
                {//if it is only local object, we should remove it
                    return globalStore.Delete("Playlist", new[] { internalId }, false);
                }
                else
                {//if it is not local object, we should mark it as deleted
                    item[SyncManager.Local] = true;
                    item[SyncManager.LocallyDeleted] = true;
                    var result = globalStore.Update("Playlist", item, internalId, false);
                    return result != null;
                }
            }));
        }
Beispiel #3
0
        public static QuerySpec RemoveLimit(this QuerySpec querySpec, SmartStore store)
        {
            if (string.IsNullOrWhiteSpace(querySpec.SoupName) == false && store.HasSoup(querySpec.SoupName) == false)
            {
                return(querySpec);
            }

            var count = (int)store.CountQuery(querySpec);

            switch (querySpec.QueryType)
            {
            case QuerySpec.SmartQueryType.Exact:
                return(QuerySpec.BuildExactQuerySpec(querySpec.SoupName, querySpec.Path, querySpec.MatchKey, count));

            case QuerySpec.SmartQueryType.Like:
                return(QuerySpec.BuildLikeQuerySpec(querySpec.SoupName, querySpec.Path, querySpec.LikeKey, querySpec.Order, count));

            case QuerySpec.SmartQueryType.Range:
                return(QuerySpec.BuildRangeQuerySpec(querySpec.SoupName, querySpec.Path, querySpec.BeginKey, querySpec.EndKey, querySpec.Order, count));

            default:
            case QuerySpec.SmartQueryType.Smart:
                return(QuerySpec.BuildSmartQuerySpec(querySpec.SmartSql, count));
            }
        }
Beispiel #4
0
 private DsaSyncLog(SmartStore store) : base(store)
 {
     if (IndexedFieldsForSObjects != null)
     {
         AddIndexSpecItems(IndexedFieldsForSObjects);
     }
 }
Beispiel #5
0
 public SearchTerm(SmartStore store) : base(store)
 {
     if (IndexedFieldsForSObjects != null)
     {
         AddIndexSpecItems(IndexedFieldsForSObjects);
     }
 }
        public Task <bool> UpdatePlaylist(string playlistId, JObject updatedPlaylist)
        {
            return(Task <bool> .Factory.StartNew(() =>
            {
                var globalStore = SmartStore.GetGlobalSmartStore();

                long internalId = globalStore.LookupSoupEntryId("Playlist", Constants.Id, playlistId);
                if (internalId == -1)
                {
                    return false;//cannot find item in soup
                }
                var items = globalStore.Retrieve("Playlist", internalId);
                if (items.Count == 0)
                {
                    return false;//canot retrieve item from soup
                }
                var item = items[0].ToObject <JObject>();

                //merge changes
                var mergeSettings = new JsonMergeSettings
                {
                    MergeArrayHandling = MergeArrayHandling.Replace,
                    MergeNullValueHandling = MergeNullValueHandling.Merge
                };
                item.Merge(updatedPlaylist);

                //mark record as locally update
                item[SyncManager.Local] = true;
                item[SyncManager.LocallyUpdated] = true;

                var result = globalStore.Update("Playlist", item, internalId, false);
                return result != null;
            }));
        }
 public ContentDocumentTag(SmartStore store) : base(store)
 {
     if (IndexedFieldsForSObjects != null)
     {
         AddIndexSpecItems(IndexedFieldsForSObjects);
     }
 }
Beispiel #8
0
 private Playlist(SmartStore store) : base(store)
 {
     if (IndexedFieldsForSObjects != null)
     {
         AddIndexSpecItems(IndexedFieldsForSObjects);
     }
 }
        private async void CleanUpContentThumbnails(JArray results)
        {
            var parentIds = results.Select(item => CustomPrefixJsonConvert.DeserializeObject <AttachmentMetadata>(item.ToString()).ParentId).ToList();
            var ctFolder  = await ContentThumbnailFolder.Instance.GetContentThumbnailFolder();

            if (ctFolder != null)
            {
                var thumbnailFolders = await ctFolder.GetFoldersAsync();

                var idsToDelete = new List <long>();
                var globalStore = SmartStore.GetGlobalSmartStore();
                foreach (var thumbnailFolder in thumbnailFolders)
                {
                    if (!parentIds.Contains(thumbnailFolder.Name))
                    {
                        Debug.WriteLine("Delete Content Thumbnail " + thumbnailFolder.Name);
                        thumbnailFolder.DeleteAsync(StorageDeleteOption.PermanentDelete);
                        idsToDelete.Add(globalStore.LookupSoupEntryId(SoupName, "ParentId", thumbnailFolder.Name));
                    }
                }
                if (idsToDelete.Any())
                {
                    Store.Delete(SoupName, idsToDelete.ToArray(), false);
                }
            }
        }
Beispiel #10
0
 public PlaylistContent(SmartStore store) : base(store)
 {
     if (IndexedFieldsForSObjects != null)
     {
         AddIndexSpecItems(IndexedFieldsForSObjects);
     }
 }
Beispiel #11
0
 public DocIndexDeltaSieve(SmartStore store)
 {
     if (store == null)
     {
         throw new SyncException("store param is required to filtered data.");
     }
     _store = store;
 }
Beispiel #12
0
 public AttMetaDropSameFilesForDeltaSieve(SmartStore store)
 {
     if (store == null)
     {
         throw new SyncException("store params is required to filted data.");
     }
     _store = store;
 }
Beispiel #13
0
 private ContentReview(SmartStore store) : base(store)
 {
     InstanceID = Guid.NewGuid();
     if (IndexedFieldsForSObjects != null)
     {
         AddIndexSpecItems(IndexedFieldsForSObjects);
     }
 }
        public ContentDistribution(SmartStore store, bool clearSoup = true) : base(store)
        {
            if (IndexedFieldsForSObjects != null)
            {
                AddIndexSpecItems(IndexedFieldsForSObjects);
            }

            ClearSoup = clearSoup;
        }
Beispiel #15
0
        public DocMetaByOwnershipAndUsageInCategoriesSieve(SmartStore store, User currentUser)
        {
            if (store == null || currentUser == null)
            {
                throw new SyncException("store and currentUser params are required to filted data.");
            }

            _store       = store;
            _currentUser = currentUser;
        }
        internal ContentThumbnailAttachment(SmartStore store) : base(store)
        {
            if (IndexedFieldsForSObjects != null)
            {
                AddIndexSpecItems(IndexedFieldsForSObjects);
            }

            SoupName     = "AttachmentMetadata";
            TempSoupName = "ContentThumbnailAttMeta";
        }
        public static SyncManager GetInstance(Account account, string communityId, SmartStore.SmartStore smartStore)
        {
            var nativeAccount = JsonConvert.SerializeObject(account);
            var nativeSmartStore = JsonConvert.SerializeObject(smartStore);
            var nativeSyncManager = SDK.SmartSync.Manager.SyncManager.GetInstance(
                JsonConvert.DeserializeObject<SDK.Auth.Account>(nativeAccount), communityId, JsonConvert.DeserializeObject<SDK.SmartStore.Store.SmartStore>(nativeSmartStore));

            var nativeJson = JsonConvert.SerializeObject(nativeSyncManager);
            return JsonConvert.DeserializeObject<SyncManager>(nativeJson);
        }
Beispiel #18
0
        public DocMetaDeltaSieve(SmartStore store, User currentUser)
        {
            if (store == null || currentUser == null)
            {
                throw new SyncException("store and currentUser params are required to filtered data.");
            }

            _store       = store;
            _currentUser = currentUser;
        }
        public async Task <List <PlaylistContent> > GetAllPlaylistContent()
        {
            return(await Task.Factory.StartNew(() =>
            {
                var globalStore = SmartStore.GetGlobalSmartStore();
                var querySpec = QuerySpec.BuildAllQuerySpec("PlaylistContent", "Id", QuerySpec.SqlOrder.ASC, SfdcConfig.PageSize).RemoveLimit(globalStore);

                return globalStore.Query(querySpec, 0).Select(item => CustomPrefixJsonConvert.DeserializeObject <PlaylistContent>(item.ToString())).ToList();
            }));
        }
Beispiel #20
0
        // CTOR
        internal ContentDocument(SmartStore store) : base(store)
        {
            // Allocate new list
            ContentIdList = new List <string>();

            if (IndexedFieldsForSObjects != null)
            {
                AddIndexSpecItems(IndexedFieldsForSObjects);
            }
        }
Beispiel #21
0
 public async Task AddRecentContact(ContactDTO contact)
 {
     await Task.Factory.StartNew(() =>
     {
         var store = SmartStore.GetGlobalSmartStore();
         CheckIfNeededSoupExists(store, RecentContactSoupName);
         var record = JObject.FromObject(contact,
                                         JsonSerializer.Create(CustomJsonSerializerSettings.Instance.Settings));
         store.Upsert(RecentContactSoupName, record, Constants.Id, false);
     });
 }
Beispiel #22
0
 public async Task <List <ContactDTO> > GetRecentContacts()
 {
     return(await Task.Factory.StartNew(() =>
     {
         var store = SmartStore.GetGlobalSmartStore();
         CheckIfNeededSoupExists(store, RecentContactSoupName);
         var querySpec = QuerySpec.BuildAllQuerySpec(RecentContactSoupName, Constants.Id, QuerySpec.SqlOrder.ASC, SfdcConfig.PageSize).RemoveLimit(store);
         return store.Query(querySpec, 0)
         .Select(item => CustomPrefixJsonConvert.DeserializeObject <ContactDTO>(item.ToString()))
         .ToList();
     }));
 }
Beispiel #23
0
 internal SObject(SmartStore store)
 {
     if (store == null)
     {
         throw new ArgumentNullException("Parameter store is mandatory");
     }
     Store                   = store;
     Prefix                  = SfdcConfig.CustomerPrefix;
     PageSize                = SfdcConfig.PageSize;
     FieldsToSyncUp          = FieldsToSyncUp.Select(field => string.Format(field, Prefix)).ToList();
     FieldsToExcludeOnUpdate = FieldsToExcludeOnUpdate.Select(field => string.Format(field, Prefix)).ToList();
 }
Beispiel #24
0
 public async Task <SuccessfulSync> GetSyncConfig(string typeOfObj)
 {
     return(await Task.Factory.StartNew(() =>
     {
         var globalStore = SmartStore.GetGlobalSmartStore();
         var querySpec = QuerySpec.BuildExactQuerySpec(SuccessfulSync.SoupName, SuccessfulSync.TransactionItemTypeIndexKey, typeOfObj, SfdcConfig.PageSize);
         return globalStore
         .Query(querySpec, 0)
         .Select(item => CustomPrefixJsonConvert.DeserializeObject <SuccessfulSync>(item.ToString()))
         .FirstOrDefault();
     }));
 }
        public async Task <List <Playlist> > GetAllFeaturedPlaylistsByMAC(string macId, string userId)
        {
            return(await Task.Factory.StartNew(() =>
            {
                var globalStore = SmartStore.GetGlobalSmartStore();
                var querySpec = QuerySpec.BuildAllQuerySpec("Playlist", "Id", QuerySpec.SqlOrder.ASC, SfdcConfig.PageSize).RemoveLimit(globalStore);

                return globalStore.Query(querySpec, 0).Select(item => CustomPrefixJsonConvert.DeserializeObject <Playlist>(item.ToString()))
                .Where(pl => ((pl.__isDeleted == false && pl.MobileAppConfiguration == macId) || pl.OwnerId == userId))
                .ToList();
            }));
        }
Beispiel #26
0
        public async Task <List <SuccessfulSync> > GetSyncConfigs(string syncID)
        {
            return(await Task.Factory.StartNew(() =>
            {
                var globalStore = SmartStore.GetGlobalSmartStore();
                var querySpec = QuerySpec.BuildExactQuerySpec(SuccessfulSync.SoupName, SuccessfulSync.SyncIdIndexKey, syncID, SfdcConfig.PageSize).RemoveLimit(globalStore);

                return globalStore
                .Query(querySpec, 0)
                .Select(item => CustomPrefixJsonConvert.DeserializeObject <SuccessfulSync>(item.ToString()))
                .ToList();
            }));
        }
        public async Task <MobileAppConfig> GetMobileAppConfig(string configID)
        {
            return(await Task.Factory.StartNew(() =>
            {
                var globalStore = SmartStore.GetGlobalSmartStore();
                var querySpec = QuerySpec.BuildExactQuerySpec(MobileAppConfig.SoupName, "Id", configID, SfdcConfig.PageSize);

                return globalStore
                .Query(querySpec, 0)
                .Select(item => CustomPrefixJsonConvert.DeserializeObject <MobileAppConfig>(item.ToString()))
                .FirstOrDefault();
            }));
        }
        private static List <AttachmentMetadata> GetAttachments(string soupName, IEnumerable <string> attachmentIDs)
        {
            var inCondition = string.Join(",", attachmentIDs.Select(s => $"'{s}'"));
            var smartQuery  = "SELECT {" + soupName + ":_soup} FROM {" + soupName + "}  WHERE {" + soupName + ":Id} IN (" + inCondition + ")";

            var globalStore = SmartStore.GetGlobalSmartStore();
            var querySpec   = QuerySpec.BuildSmartQuerySpec(smartQuery, SfdcConfig.PageSize).RemoveLimit(globalStore);

            return(globalStore
                   .Query(querySpec, 0)
                   .Select(item => JsonConvert.DeserializeObject <AttachmentMetadata>(item[0].ToObject <JObject>().ToString()))
                   .ToList());
        }
        // CTOR
        internal MobileAppConfigAttachment(SmartStore store) : base(store)
        {
            // Allocate new list
            MacIdList = new List <string>();

            if (IndexedFieldsForSObjects != null)
            {
                AddIndexSpecItems(IndexedFieldsForSObjects);
            }

            SoupName     = "AttachmentMetadata";
            TempSoupName = "MobileAppConfigAttMeta";
        }
        public async Task <DTO.UserSettingsDto> GetUserSettings(string userID)
        {
            return(await Task.Factory.StartNew(() =>
            {
                var globalStore = SmartStore.GetGlobalSmartStore();
                var querySpec = QuerySpec.BuildAllQuerySpec("UserSettings", "UserId", QuerySpec.SqlOrder.ASC, SfdcConfig.PageSize).RemoveLimit(globalStore);

                return globalStore
                .Query(querySpec, 0)
                .Select(item => CustomPrefixJsonConvert.DeserializeObject <DTO.UserSettingsDto>(item.ToString()))
                .FirstOrDefault(u => u.UserId == userID);
            }));
        }
        public NoteSyncViewModel()
        {
            Account account = AccountManager.GetAccount();

            if (account == null)
            {
                return;
            }
            _store         = SmartStore.GetSmartStore();
            _syncManager   = SyncManager.GetInstance(account);
            Notes          = new SortedObservableCollection <NoteObject>();
            FilteredNotes  = new SortedObservableCollection <NoteObject>();
            IndexReference = new ObservableCollection <string>();
        }
		public static void ToAddress(this OrderReferenceDetails details, SmartStore.Core.Domain.Common.Address address, ICountryService countryService,
			IStateProvinceService stateProvinceService, out bool countryAllowsShipping, out bool countryAllowsBilling)
		{
			countryAllowsShipping = countryAllowsBilling = true;

			if (details.IsSetBuyer() && details.Buyer.IsSetEmail())
			{
				address.Email = details.Buyer.Email;
			}

			if (details.IsSetDestination() && details.Destination.IsSetPhysicalDestination())
			{
				details.Destination.PhysicalDestination.ToAddress(address, countryService, stateProvinceService, out countryAllowsShipping, out countryAllowsBilling);
			}
		}
		public static void ToAddress(this Address amazonAddress, SmartStore.Core.Domain.Common.Address address, ICountryService countryService,
			IStateProvinceService stateProvinceService, out bool countryAllowsShipping, out bool countryAllowsBilling)
		{
			countryAllowsShipping = countryAllowsBilling = true;

			if (amazonAddress.IsSetName())
			{
				address.ToFirstAndLastName(amazonAddress.Name);
			}

			if (amazonAddress.IsSetAddressLine1())
			{
				address.Address1 = amazonAddress.AddressLine1.TrimSafe().Truncate(4000);
			}

			if (amazonAddress.IsSetAddressLine2())
			{
				address.Address2 = amazonAddress.AddressLine2.TrimSafe().Truncate(4000);
			}

			if (amazonAddress.IsSetAddressLine3())
			{
				address.Address2 = address.Address2.Grow(amazonAddress.AddressLine3.TrimSafe(), ", ").Truncate(4000);
			}

			// normalize
			if (address.Address1.IsEmpty() && address.Address2.HasValue())
			{
				address.Address1 = address.Address2;
				address.Address2 = null;
			}
			else if (address.Address1.HasValue() && address.Address1 == address.Address2)
			{
				address.Address2 = null;
			}

			if (amazonAddress.IsSetCity())
			{
				address.City = amazonAddress.City.TrimSafe().Truncate(4000);
			}

			if (amazonAddress.IsSetPostalCode())
			{
				address.ZipPostalCode = amazonAddress.PostalCode.TrimSafe().Truncate(4000);
			}

			if (amazonAddress.IsSetPhone())
			{
				address.PhoneNumber = amazonAddress.Phone.TrimSafe().Truncate(4000);
			}

			if (amazonAddress.IsSetCountryCode())
			{
				var country = countryService.GetCountryByTwoOrThreeLetterIsoCode(amazonAddress.CountryCode);

				if (country != null)
				{
					address.CountryId = country.Id;
					countryAllowsShipping = country.AllowsShipping;
					countryAllowsBilling = country.AllowsBilling;
				}
			}

			if (amazonAddress.IsSetStateOrRegion())
			{
				var stateProvince = stateProvinceService.GetStateProvinceByAbbreviation(amazonAddress.StateOrRegion);

				if (stateProvince != null)
					address.StateProvinceId = stateProvince.Id;
			}

			//amazonAddress.District, amazonAddress.County ??

			if (address.CountryId == 0)
				address.CountryId = null;

			if (address.StateProvinceId == 0)
				address.StateProvinceId = null;
		}
 public static void SetupSyncsSoupIfNeeded(SmartStore.SmartStore store)
 {
     var nativeStore = JsonConvert.SerializeObject(store);
     SDK.SmartSync.Model.SyncState.SetupSyncsSoupIfNeeded(JsonConvert.DeserializeObject<SDK.SmartStore.Store.SmartStore>(nativeStore));
 }
 public static SyncState CreateSyncUp(SmartStore.SmartStore store, SyncUpTarget target, SyncOptions options,
     string soupName)
 {
     var nativeStore = JsonConvert.SerializeObject(store);
     var syncUpTarget = JsonConvert.SerializeObject(target);
     var nativeOptions = JsonConvert.SerializeObject(options);
     var state =
         SDK.SmartSync.Model.SyncState.CreateSyncUp(
             JsonConvert.DeserializeObject<SDK.SmartStore.Store.SmartStore>(nativeStore),
             JsonConvert.DeserializeObject<SDK.SmartSync.Model.SyncUpTarget>(syncUpTarget),
             JsonConvert.DeserializeObject<SDK.SmartSync.Model.SyncOptions>(nativeOptions), soupName);
     var syncState = JsonConvert.SerializeObject(state);
     return JsonConvert.DeserializeObject<SyncState>(syncState);
 }
 public static SyncState ById(SmartStore.SmartStore store, long id)
 {
     var nativeStore = JsonConvert.SerializeObject(store);
     var state = SDK.SmartSync.Model.SyncState.ById(
         JsonConvert.DeserializeObject<SDK.SmartStore.Store.SmartStore>(nativeStore), id);
     var nativeState = JsonConvert.SerializeObject(state);
     return JsonConvert.DeserializeObject<SyncState>(nativeState);
 }
 public void Save(SmartStore.SmartStore store)
 {
     var nativeStore = JsonConvert.SerializeObject(store);
     NativeSyncState.Save(JsonConvert.DeserializeObject<SDK.SmartStore.Store.SmartStore>(nativeStore));
 }