Beispiel #1
0
        internal async Task <User> GetCurrentUserFromSoql(SyncManager syncManager)
        {
            User   currentUser = new NullUser();
            JArray results;

            try
            {
                var target = new SoqlSyncDownTarget(SoqlQuery);
                if (target.hasTokenExpired())
                {
                    //logout
                    await ObjectSyncDispatcher.Instance.RefreshToken();

                    return(currentUser);
                }
                results = await target.StartFetch(syncManager, -1);
            }
            catch
            {
                UseAlternativeFields = true;
                var target = new SoqlSyncDownTarget(SoqlQuery);
                results = await target.StartFetch(syncManager, -1);
            }

            var curUser = results?.Select(x => CustomPrefixJsonConvert.DeserializeObject <User>(x.ToString())).SingleOrDefault();

            return(curUser ?? currentUser);
        }
Beispiel #2
0
        // Methods
        /// <summary>
        /// Get content documents from local db
        /// </summary>
        internal IList <Model.Models.ContentDocument> GetFromSoup()
        {
            var querySpec = QuerySpec.BuildAllQuerySpec(SoupName, "Id", QuerySpec.SqlOrder.ASC, PageSize).RemoveLimit(Store);
            var results   = Store.Query(querySpec, 0);

            return(results.Select(item => CustomPrefixJsonConvert.DeserializeObject <Model.Models.ContentDocument>(item.ToString())).ToList());
        }
        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 #4
0
        public IList <Model.Models.ContentReview> GetAll()
        {
            var querySpec = QuerySpec.BuildAllQuerySpec(SoupName, Constants.Id, QuerySpec.SqlOrder.ASC, PageSize);
            var results   =
                Store?.Query(querySpec, 0)
                .Select(item => CustomPrefixJsonConvert.DeserializeObject <Model.Models.ContentReview>(item.ToString()))
                .ToList();

            return(results);
        }
        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 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);
        }
        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();
            }));
        }
 public void SaveToSoup(List <Model.Models.CategoryContent> newCategoryContents)
 {
     if (newCategoryContents == null)
     {
         return;
     }
     foreach (var newCategoryContent in newCategoryContents)
     {
         _store.Upsert(SoupName, JObject.Parse(CustomPrefixJsonConvert.SerializeObject(newCategoryContent)));
     }
 }
        public Dictionary <string, SuccessfulSync> GetAllVersionedsSyncsFromSoupIndexedByDocId()
        {
            SetupSyncsSoupIfNotExists();
            var querySpec = QuerySpec.BuildAllQuerySpec(SoupName, SuccessfulSync.SyncIdIndexKey, QuerySpec.SqlOrder.ASC, SfdcConfig.PageSize).RemoveLimit(_store);
            var results   = _store.Query(querySpec, 0);

            var allTransactions    = results.Select(item => CustomPrefixJsonConvert.DeserializeObject <SuccessfulSync>(item.ToString()));
            var onlyVersionedTrans = allTransactions.Where(item => !string.IsNullOrEmpty(item.TransactionItemType)).ToList();

            return(onlyVersionedTrans.ToDictionary(docTrans => docTrans.TransactionItemType));
        }
Beispiel #10
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 #12
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 <IList <string> > SearchForDocumentIdByTag(string query)
 {
     return(await Task.Factory.StartNew(() =>
     {
         var querySpec = QuerySpec.BuildLikeQuerySpec(SoupName, "Tag", query, QuerySpec.SqlOrder.ASC, PageSize);
         var results =
             Store?.Query(querySpec, 0)
             .Select(item => CustomPrefixJsonConvert.DeserializeObject <DocumentsTag>(item.ToString()))
             .SelectMany(x => x.DocumentIds).Distinct().ToList();
         return results;
     }));
 }
        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);
            }));
        }
Beispiel #15
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();
            }));
        }
        // Methods
        internal IList <AttachmentMetadata> GetMobileAppConfigAttachmentsFromSoup()
        {
            var querySpec    = QuerySpec.BuildAllQuerySpec(TempSoupName, "Id", QuerySpec.SqlOrder.ASC, PageSize).RemoveLimit(Store);
            var results      = Store.Query(querySpec, 0);
            var macList      = results.Select(item => CustomPrefixJsonConvert.DeserializeObject <AttachmentMetadata>(item.ToString())).ToList();
            var endWithError = SaveMetadataToSoup(results);

            if (Store.HasSoup(TempSoupName) && !endWithError)
            {
                Store.DropSoup(TempSoupName);
            }

            return(macList);
        }
        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> > 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 <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();
            }));
        }
Beispiel #21
0
        internal User GetCurrentUserFromSoup()
        {
            User currentUser = new NullUser();

            var querySpec   = QuerySpec.BuildExactQuerySpec(SoupName, "Id", _account.UserId, 10);
            var resultsArr  = Store?.Query(querySpec, 0);
            var resultToken = resultsArr?.FirstOrDefault();

            if (resultToken != null)
            {
                currentUser = CustomPrefixJsonConvert.DeserializeObject <User>(resultToken.ToString());
            }

            return(currentUser);
        }
        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);
        }
        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 <IList <DocumentsTag> > GetAll()
        {
            return(await Task.Factory.StartNew(() =>
            {
                if (!Store.HasSoup(SoupName))
                {
                    return new List <DocumentsTag>();
                }

                var querySpec = QuerySpec.BuildAllQuerySpec(SoupName, "Tag", QuerySpec.SqlOrder.ASC, PageSize);
                var results =
                    Store?.Query(querySpec, 0)
                    .Select(item => CustomPrefixJsonConvert.DeserializeObject <DocumentsTag>(item.ToString()))
                    .ToList();
                return results;
            }));
        }
        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();
            }));
        }
Beispiel #26
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();
            }));
        }
Beispiel #27
0
        public async Task SaveProductTypeToSoup(string productTypes, string docId, CancellationToken token = default(CancellationToken))
        {
            await Task.Factory.StartNew(() =>
            {
                if (string.IsNullOrWhiteSpace(productTypes))
                {
                    return;
                }

                SetupSoupIfNotExistsNeeded();

                var productTypeArray = productTypes.Split(';');
                foreach (var productType in productTypeArray)
                {
                    var querySpec = QuerySpec.BuildExactQuerySpec(SoupName, "ProductType", productType, 1);
                    var results   =
                        Store?.Query(querySpec, 0)
                        .Select(
                            item => CustomPrefixJsonConvert.DeserializeObject <DocumentProductType>(item.ToString()))
                        .FirstOrDefault();
                    var docTitle = new DocumentProductType
                    {
                        ProductType = productType,
                        DocumentIds = new List <string> {
                            docId
                        }
                    };

                    if (results != null)
                    {
                        if (results.DocumentIds.Contains(docId))
                        {
                            continue;
                        }
                        results.DocumentIds.Add(docId);
                        docTitle.DocumentIds = results.DocumentIds;
                    }

                    var jTag = JObject.FromObject(docTitle);
                    Store?.Upsert(SoupName, jTag, "ProductType");
                }
            }, token);
        }
Beispiel #28
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();
            }));
        }
Beispiel #29
0
        public async Task SaveTitleToSoup(string title, string docId, CancellationToken token = default(CancellationToken))
        {
            await Task.Factory.StartNew(() =>
            {
                if (string.IsNullOrWhiteSpace(title))
                {
                    return;
                }

                SetupSoupIfNotExistsNeeded();

                var querySpec = QuerySpec.BuildExactQuerySpec(SoupName, "Title", title, 1);
                var results   =
                    Store?.Query(querySpec, 0)
                    .Select(item => CustomPrefixJsonConvert.DeserializeObject <DocumentTitle>(item.ToString()))
                    .FirstOrDefault();
                var docTitle = new DocumentTitle
                {
                    Title       = title,
                    DocumentIds = new List <string> {
                        docId
                    }
                };

                if (results != null)
                {
                    if (results.DocumentIds.Contains(docId))
                    {
                        return;
                    }
                    results.DocumentIds.Add(docId);
                    docTitle.DocumentIds = results.DocumentIds;
                }

                var jTag = JObject.FromObject(docTitle);
                Store?.Upsert(SoupName, jTag, "Title");
            }, token);
        }
        public async Task ClearNotNeededContentDistribution(IList <Model.Models.ContentDocument> contentDocuments)
        {
            await Task.Factory.StartNew(() =>
            {
                var querySpec = QuerySpec.BuildAllQuerySpec(SoupName, Key, QuerySpec.SqlOrder.ASC, PageSize).RemoveLimit(Store);
                var results   = Store.Query(querySpec, 0);
                var distributionSoupObjectsList = results.Select(x => x.ToObject <JObject>()).ToList();

                var versionIdsList = contentDocuments.Select(x => x.LatestPublishedVersionId);

                var distributionListToDelete = distributionSoupObjectsList
                                               .Select(item => CustomPrefixJsonConvert.DeserializeObject <DSA.Model.Dto.ContentDistribution>(item.ToString()))
                                               .Where(x => x.IsDeleted || x.ExpiryDate <= DateTime.Now || !versionIdsList.Contains(x.ContentVersionId))
                                               .Select(x => x.Id)
                                               .ToList();

                var soupIds = distributionSoupObjectsList.Select(x => new { SoupId = x.ExtractValue <long>(SoupId), Id = x.ExtractValue <string>(Constants.Id) })
                              .Where(x => distributionListToDelete.Contains(x.Id))
                              .Select(x => x.SoupId).ToArray();

                Store.Delete(SoupName, soupIds, false);
            });
        }