Пример #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> 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;
            }));
        }
        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);
                }
            }
        }
        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;
                }
            }));
        }
        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();
            }));
        }
Пример #6
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);
     });
 }
Пример #7
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();
     }));
 }
        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();
            }));
        }
Пример #9
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();
     }));
 }
Пример #10
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();
            }));
        }
Пример #11
0
        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());
        }
Пример #12
0
        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 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();
            }));
        }
        public async Task <List <ContentDocument> > GetContentDocumentsByID15(IEnumerable <string> contentID15s)
        {
            return(await Task.Factory.StartNew(() =>
            {
                var globalStore = SmartStore.GetGlobalSmartStore();
                var querySpec = QuerySpec.BuildAllQuerySpec(_soupName, "Id", QuerySpec.SqlOrder.ASC, SfdcConfig.PageSize).RemoveLimit(globalStore);

                return globalStore
                .Query(querySpec, 0)
                .Select(item => CustomPrefixJsonConvert.DeserializeObject <ContentDocument>(item.ToString()))
                .Where(c => contentID15s.Contains(c.Id15))
                .ToList();
            }));
        }
        public async Task <List <PlaylistContent> > GetPlaylistContent(IEnumerable <string> playlistIDs)
        {
            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()))
                .Where(c => (playlistIDs.Contains(c.PlasylistId)) && (c.__isDeleted == false))
                .ToList();
            }));
        }
        public async Task <List <ContentDocument> > GetMyLibraryContentDocuments()
        {
            return(await Task.Factory.StartNew(() =>
            {
                var globalStore = SmartStore.GetGlobalSmartStore();
                var userId = _userSessionService.GetCurrentUserId();
                var smartQuery = "SELECT {" + _soupName + ":_soup} FROM {" + _soupName + "} WHERE {" + _soupName + ":" + ContentDocument.OwnerIdIndexKey + "} = '" + userId + "' AND {" + _soupName + ":" + ContentDocument.PublishStatusIndexKey + "} ='R'";

                var querySpec = QuerySpec.BuildSmartQuerySpec(smartQuery, SfdcConfig.PageSize).RemoveLimit(globalStore);
                return globalStore
                .Query(querySpec, 0)
                .Select(item => CustomPrefixJsonConvert.DeserializeObject <ContentDocument>(item[0].ToObject <JObject>().ToString()))
                .ToList();
            }));
        }
Пример #17
0
        private static List <string> SearchForDocumentIdByAssetTypeSync(string query)
        {
            var store = SmartStore.GetGlobalSmartStore();

            if (!store.HasSoup(AssetTypeSoupName))
            {
                return(new List <string>());
            }

            var querySpec = QuerySpec.BuildContainQuerySpec(AssetTypeSoupName, AssetTypeKey, query, QuerySpec.SqlOrder.ASC, SfdcConfig.PageSize).RemoveLimit(store);
            var results   = store.Query(querySpec, 0)
                            .Select(item => CustomPrefixJsonConvert.DeserializeObject <DocumentAssetType>(item.ToString()))
                            .SelectMany(x => x.DocumentIds).Distinct().ToList();

            return(results);
        }
Пример #18
0
        public async Task SaveCompleteReviewsToSoup(List <ContentReview> contentReviews)
        {
            await DispatcherHelper.RunAsync(async() =>
            {
                var location = await _geolocationService.GetLocation();
                var store    = SmartStore.GetGlobalSmartStore();
                SetupSoupIfNotExistsNeeded(store, SoupName);
                contentReviews.ForEach(cr =>
                {
                    cr.GeolocationLatitude  = location.Latitude;
                    cr.GeolocationLongitude = location.Longitude;
                });

                contentReviews.ForEach(cr => SaveReview(store, cr));
                SyncUpContentReview();
            });
        }
        public async Task <List <ContentDocument> > GetContentDocumentsByID(IEnumerable <string> contentIDs)
        {
            return(await Task.Factory.StartNew(() =>
            {
                var globalStore = SmartStore.GetGlobalSmartStore();

                var inCondition = string.Join(",", contentIDs.Select(s => $"'{s}'"));
                var smartQuery = "SELECT {" + _soupName + ":_soup} FROM {" + _soupName + "} WHERE {" + _soupName + ":Id} IN (" + inCondition + ")";
                var querySpec = QuerySpec.BuildSmartQuerySpec(smartQuery, SfdcConfig.PageSize).RemoveLimit(globalStore);

                return globalStore
                .Query(querySpec, 0)
                .Select(item => CustomPrefixJsonConvert.DeserializeObject <ContentDocument>(item[0].ToObject <JObject>().ToString()))
                .Where(c => contentIDs.Contains(c.Id))
                .ToList();
            }));
        }
        public async Task <List <CategoryMobileConfig> > GetCategoryMobileConfigs(string mobileAppConfigurationId)
        {
            if (string.IsNullOrWhiteSpace(mobileAppConfigurationId))
            {
                return(new List <CategoryMobileConfig>());
            }

            return(await Task.Factory.StartNew(() =>
            {
                var globalStore = SmartStore.GetGlobalSmartStore();
                var querySpec = QuerySpec.BuildExactQuerySpec(CategoryMobileConfig.SoupName, CategoryMobileConfig.MobileAppConfigurationIdIndexKey, mobileAppConfigurationId, SfdcConfig.PageSize).RemoveLimit(globalStore);

                return globalStore
                .Query(querySpec, 0)
                .Select(item => CustomPrefixJsonConvert.DeserializeObject <CategoryMobileConfig>(item.ToString()))
                .ToList();
            }));
        }
Пример #21
0
        private async Task <List <HistoryInfoDto> > GetAllHistoryInfo()
        {
            return(await Task.Factory.StartNew(() =>
            {
                var globalStore = SmartStore.GetGlobalSmartStore();
                if (globalStore.HasSoup(SoupName) == false)
                {
                    return new List <HistoryInfoDto>();
                }

                var querySpec = QuerySpec.BuildAllQuerySpec(SoupName, "Id", QuerySpec.SqlOrder.ASC, SfdcConfig.PageSize).RemoveLimit(globalStore);

                return globalStore
                .Query(querySpec, 0)
                .Select(item => CustomPrefixJsonConvert.DeserializeObject <HistoryInfoDto>(item.ToString()))
                .ToList();
            }));
        }
Пример #22
0
        public async Task SaveEventToSoup(string searchTerm)
        {
            await Task.Factory.StartNew(() =>
            {
                // ReSharper disable once ConditionIsAlwaysTrueOrFalse
                if (!SfdcConfig.CollectSearchTerms)
                {
                    return;
                }

                var store = SmartStore.GetGlobalSmartStore();
                SetupSoupIfNotExistsNeeded(store, SoupName);

                var date             = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, 1, 0, 0, 0, DateTimeKind.Utc);
                var searchTermRecord = new SearchTerms
                {
                    SearchTerm     = searchTerm,
                    SearchTermDate = date,
                    Count          = 1
                };

                var record = JObject.FromObject(searchTermRecord, JsonSerializer.Create(CustomJsonSerializerSettings.Instance.Settings));

                var info = searchTermRecord.GetType().GetTypeInfo().GetCustomAttributes()
                           .SingleOrDefault(t => t is JsonObjectAttribute) as JsonObjectAttribute;

                if (info != null)
                {
                    record[Constants.SobjectType] = string.Format(info.Title, SfdcConfig.CustomerPrefix);
                }

                record[SyncManager.Local]          = true;
                record[SyncManager.LocallyCreated] = true;
                record[SyncManager.LocallyUpdated] = false;
                record[SyncManager.LocallyUpdated] = false;
                record[Constants.Id] = Guid.NewGuid();
                store.Upsert(SoupName, record, Constants.Id, false);

                //SyncUpEvents();
            });
        }
Пример #23
0
        public async Task <List <SuccessfulSync> > GetSyncConfigs(IEnumerable <string> typeOfObjList)
        {
            return(await Task.Factory.StartNew(() =>
            {
                if (typeOfObjList.Any() == false)
                {
                    return new List <SuccessfulSync>();
                }

                var inCondition = string.Join(",", typeOfObjList.Select(s => $"'{s}'"));
                var smartQuery = "SELECT {" + SuccessfulSync.SoupName + ":_soup} FROM {" + SuccessfulSync.SoupName + "}  WHERE {" + SuccessfulSync.SoupName + ":" + SuccessfulSync.TransactionItemTypeIndexKey + "} IN (" + inCondition + ")";

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

                return globalStore
                .Query(querySpec, 0)
                .Select(item => CustomPrefixJsonConvert.DeserializeObject <SuccessfulSync>(item[0].ToObject <JObject>().ToString()))
                .ToList();
            }));
        }
        public async Task <List <ContentDistribution> > GetAllContentDistributions()
        {
            return(await Task.Factory.StartNew(() =>
            {
                if (!SfdcConfig.EmailOnlyContentDistributionLinks)
                {
                    return new List <ContentDistribution>();
                }

                var store = SmartStore.GetGlobalSmartStore();

                if (!store.HasSoup(SoupName))
                {
                    return new List <ContentDistribution>();
                }

                var querySpec = QuerySpec.BuildAllQuerySpec(SoupName, Key, QuerySpec.SqlOrder.ASC, SfdcConfig.PageSize).RemoveLimit(store);
                return store.Query(querySpec, 0)
                .Select(item => CustomPrefixJsonConvert.DeserializeObject <ContentDistribution>(item.ToString()))
                .Where(x => !x.IsDeleted && (x.ExpiryDate == null || x.ExpiryDate > DateTime.Now))
                .ToList();
            }));
        }
Пример #25
0
        public async Task <List <Category> > GetCategories(string mobileConfigurationID)
        {
            return(await Task.Factory.StartNew(() =>
            {
                var globalStore = SmartStore.GetGlobalSmartStore();

                var smartSql = @"SELECT 
                                    {" + Category.SoupName + @":_soup}  
                                FROM 
                                    {" + Category.SoupName + @"}
	                                JOIN {"     + CategoryMobileConfig.SoupName + @"} 
                                        ON {" + CategoryMobileConfig.SoupName + @"}.{" + CategoryMobileConfig.SoupName + @":" + CategoryMobileConfig.CategoryIdIndexKey + @"} = {" + Category.SoupName + @"}.{" + Category.SoupName + @":Id}
                                 WHERE
                                    {" + CategoryMobileConfig.SoupName + @":" + CategoryMobileConfig.MobileAppConfigurationIdIndexKey + @"} = '" + mobileConfigurationID + "'";

                var querySpec = QuerySpec.BuildSmartQuerySpec(smartSql, SfdcConfig.PageSize).RemoveLimit(globalStore);

                return globalStore
                .Query(querySpec, 0)
                .Select(item => CustomPrefixJsonConvert.DeserializeObject <Category>(item[0].ToObject <JObject>().ToString()))
                .ToList();
            }));
        }
        public Task <PlaylistContent> SavePlaylistContent(PlaylistContent playlistContent)
        {
            return(Task <PlaylistContent> .Factory.StartNew(() =>
            {
                var globalStore = SmartStore.GetGlobalSmartStore();

                var record = JObject.FromObject(playlistContent, JsonSerializer.Create(CustomJsonSerializerSettings.Instance.Settings));
                //remove data which should not be passed to salesforce
                record.Property("Id").Remove();
                record.Property("ContentId15").Remove();
                //set local variable
                record[Constants.Id] = Guid.NewGuid().ToString();//tmp id, we need it to maintain object relation (Id - it is salesforce tmp id, id - it is internal local id)
                record[SyncManager.Local] = true;
                record[SyncManager.LocallyCreated] = true;
                record[SyncManager.LocallyUpdated] = false;
                record[SyncManager.LocallyDeleted] = false;

                //for new record we have to set attributes.type property
                var prefix = SfdcConfig.CustomerPrefix;
                var info = playlistContent.GetType().GetTypeInfo().GetCustomAttributes()
                           .SingleOrDefault(t => t is JsonObjectAttribute) as JsonObjectAttribute;
                if (info != null)
                {
                    record[Constants.SobjectType] = string.Format(info.Title, prefix);
                }
                JObject result = globalStore.Create("PlaylistContent", record, false);

                if (result != null)
                {
                    return CustomPrefixJsonConvert.DeserializeObject <PlaylistContent>(result.ToString());
                }
                else
                {
                    return null;
                }
            }));
        }
Пример #27
0
        public async Task SaveEventToSoup(string notes, IList <ContentReviewInfo> contentReviews)
        {
            await Task.Factory.StartNew(() =>
            {
                var store = SmartStore.GetGlobalSmartStore();
                SetupSoupIfNotExistsNeeded(store, SoupName);

                if (!contentReviews.Any())
                {
                    return;
                }

                var documentTitles = contentReviews.Select((review, index) => $"{index + 1}. {review.ContentReview.ContentTitle}").OrderBy(x => x).ToList();

                var durationInSeconds = contentReviews.Sum(review => review.ContentReview.TimeViewed);
                var durationInMinutes = (int)(durationInSeconds / 60);

                var eventRecord = new Event
                {
                    Subject           = EventSubject,
                    ActivityDateTime  = DateTime.UtcNow,
                    DurationInMinutes = durationInMinutes,
                    Description       = string.Format(EventDescriptionFormat, string.Join(",", documentTitles), notes),
                    WhoId             = contentReviews.FirstOrDefault()?.ContentReview.ContactId
                };

                var record = JObject.FromObject(eventRecord, JsonSerializer.Create(CustomJsonSerializerSettings.Instance.Settings));
                record[Constants.SobjectType]      = SoupName;
                record[SyncManager.Local]          = true;
                record[SyncManager.LocallyCreated] = true;
                record[SyncManager.LocallyUpdated] = false;
                record[SyncManager.LocallyUpdated] = false;
                record[Constants.Id] = Guid.NewGuid();
                store.Upsert(SoupName, record, Constants.Id, false);
            });
        }
Пример #28
0
 private HistoryInfo()
 {
     _store = SmartStore.GetGlobalSmartStore();
     SetupSyncsSoupIfNotExistsNeeded();
 }
Пример #29
0
 private SuccessfulSyncState()
 {
     _store = SmartStore.GetGlobalSmartStore();
     SetupSyncsSoupIfNotExists();
 }
Пример #30
0
 private UserSettings()
 {
     _store = SmartStore.GetGlobalSmartStore();
     SetupSyncsSoupIfNotExistsNeeded();
 }