public Task SaveMedia(Stream stream, LocalItem localItem, ServerInfo server)
 {
     return(Task.FromResult(true));
 }
Example #2
0
 public static LocalItem CreateLocalItem(int ID)
 {
     LocalItem localItem = new LocalItem();
     localItem.ID = ID;
     return localItem;
 }
 public Task Delete(LocalItem item)
 {
     return(Task.FromResult(true));
 }
 public Task <List <ItemFileInfo> > GetFiles(LocalItem item)
 {
     return(Task.FromResult(new List <ItemFileInfo>()));
 }
 private void SetStaticMediaSourceInfo(LocalItem item, MediaSourceInfo mediaSource)
 {
     mediaSource.Id = item.Id;
     mediaSource.SupportsTranscoding = false;
 }
Example #6
0
 public Task SaveMedia(Windows.Storage.IStorageFile file, LocalItem localItem, ServerInfo server)
 {
     return(Task.FromResult(true));
 }
Example #7
0
        public async Task <List <BaseItem> > GetChangesFromChangeTracker(KnownLibraryId libraryId, FolderAssociation association, List <StorageLibraryChangeType> supportedChangeTypes)
        {
            var result  = new List <BaseItem>();
            var library = await StorageLibrary.GetLibraryAsync(libraryId);

            library.ChangeTracker.Enable();
            _changeReader = library.ChangeTracker.GetChangeReader();
            var changes = await _changeReader.ReadBatchAsync();

            foreach (var change in changes)
            {
                if (change.ChangeType == StorageLibraryChangeType.ChangeTrackingLost)
                {
                    await LogHelper.Write($"Changetracking lost: {change.Path}");

                    library.ChangeTracker.Reset();
                    return(null);
                }
                try
                {
                    if (supportedChangeTypes.Contains(change.ChangeType))
                    {
                        Debug.WriteLine($"File: {change.Path} ChangeType: {change.ChangeType}");
                        if (change.Path.EndsWith("thumb"))
                        {
                            continue;
                        }
                        var file = await change.GetStorageItemAsync();

                        if (file == null && change.ChangeType == StorageLibraryChangeType.Deleted)
                        {
                            var localItem = new LocalItem();
                            localItem.Association = association;
                            localItem.EntityId    = change.Path;
                            result.Add(localItem);
                        }
                        else if (file == null || file.IsOfType(StorageItemTypes.Folder))
                        {
                            await LogHelper.Write($"Skipping {change.Path}");
                        }
                        else
                        {
                            try
                            {
                                //check if the file is currently in use, for example a video currently being recorded
                                var stream = await((StorageFile)file).OpenStreamForWriteAsync();
                                stream.Dispose();
                            }
                            catch (Exception)
                            {
                                continue;
                            }
                            var props = await file.GetBasicPropertiesAsync();

                            var item = new LocalItem(association, file, props);

                            if (change.ChangeType == StorageLibraryChangeType.ContentsChanged)
                            {
                                //for some reason something is writing to the files after the upload, but without making changes
                                var existingItem = ItemTableModel.GetDefault().GetItem(item);
                                if (existingItem?.Size == item.Size)
                                {
                                    continue;
                                }
                            }
                            result.Add(item);
                        }
                    }
                }
                catch (Exception e)
                {
                    await LogHelper.Write($"InstantUpload: {e.Message} File: {change.Path} ChangeType: {change.ChangeType}");

                    await LogHelper.Write(e.StackTrace);
                }
            }
            return(result);
        }
 /// <summary>
 /// Adds the or update.
 /// </summary>
 /// <param name="item">The item.</param>
 /// <returns>Task.</returns>
 public Task AddOrUpdate(LocalItem item)
 {
     return(_itemRepository.AddOrUpdate(item));
 }
Example #9
0
        /// <summary>
        /// Fills element in the remote storage from the element synchronization
        /// in the local storage.<paramref name="localItem"/>.
        /// </summary>
        /// <param name="localItem">The element synchronization in the local storage.</param>
        /// <param name="context">Synchronization context.</param>
        public override void FillRemoteItem(SyncContext context, LocalItem localItem)
        {
            var        exchangeContact = (Exchange.Contact)Item;
            SyncEntity localEntity     = localItem.Entities["Contact"][0];

            if (localEntity == null)
            {
                return;
            }
            if (localEntity.State == SyncState.Deleted)
            {
                return;
            }
            if (Action == SyncAction.None)
            {
                return;
            }
            var localContact = localEntity.Entity;

            if (localContact == null || GetEntityLockedForSync(localContact.PrimaryColumnValue, context))
            {
                Action = SyncAction.None;
                return;
            }
            if (Action == SyncAction.Update)
            {
                InitIdProperty(context);
            }
            exchangeContact.DisplayName = localContact.GetTypedColumnValue <string>("Name");
            exchangeContact.Surname     = localContact.GetTypedColumnValue <string>("Surname");
            exchangeContact.GivenName   = localContact.GetTypedColumnValue <string>("GivenName");
            exchangeContact.MiddleName  = localContact.GetTypedColumnValue <string>("MiddleName");
            exchangeContact.CompanyName = localContact.GetTypedColumnValue <string>("AccountName");
            exchangeContact.JobTitle    = localContact.GetTypedColumnValue <string>("JobTitle");
            exchangeContact.Department  = localContact.GetTypedColumnValue <string>("DepartmentName");
            var birthDate = localContact.GetTypedColumnValue <DateTime>("BirthDate");

            if (birthDate != DateTime.MinValue)
            {
                exchangeContact.Birthday = birthDate;
            }
            if (Action == SyncAction.Create)
            {
                exchangeContact.FileAsMapping = Exchange.FileAsMapping.DisplayName;
                exchangeContact.SetExtendedProperty(ExchangeUtilityImpl.LocalIdProperty, localContact.PrimaryColumnValue.ToString());
            }
            exchangeContact.BusinessHomePage = GetWebPageForRemoteItem(localItem, context.UserConnection,
                                                                       localContact.PrimaryColumnValue);
            SetContactTitle(exchangeContact, localContact.GetTypedColumnValue <string>("SalutationTypeName"));
            SetContactGender(exchangeContact, localContact.GetTypedColumnValue <Guid>("GenderId"));
            var emailAddressesSynchronizer =
                new ExchangeEmailAddressDetailsSynchronizer(context, localItem, exchangeContact);
            var addressesSynchronizer =
                new ExchangeAddressDetailsSynchronizer(context, localItem, exchangeContact);
            var phoneNumbersSynchronizer =
                new ExchangePhoneNumbersDetailsSynchronizer(context, localItem, exchangeContact);

            emailAddressesSynchronizer.SyncRemoteDetails();
            addressesSynchronizer.SyncRemoteDetails();
            phoneNumbersSynchronizer.SyncRemoteDetails();
        }
 static public string GetLocalText(LocalLang lang, LocalItem item)
 {
     return(lang == LocalLang.RU ? russianLocalText[(int)item] : englishLocalText[(int)item]);
 }
Example #11
0
        /// <summary>
        /// Fills element synchronization in the local storage <paramref name="localItem"/>
        /// the value of the element in the external storage.
        /// </summary>
        /// <param name="localItem">Local storage synchronization element.</param>
        /// <param name="context">Synchronization context.</param>
        public override void FillLocalItem(SyncContext context, ref LocalItem localItem)
        {
            if (IsDeletedProcessed("Contact", ref localItem) || IsLocalItemDeleted(ref localItem))
            {
                return;
            }
            var contactRemoteProvider = context.RemoteProvider as ExchangeContactSyncProviderImpl;
            var exchangeContact       = Item as Exchange.Contact;

            if (exchangeContact == null)
            {
                context.LogError(Action, SyncDirection.Upload,
                                 GetLocalizableString(context.UserConnection, "InvalidItemTypeTpl"), GetItemSimpleId(),
                                 Item.Subject);
                Action = SyncAction.None;
                return;
            }
            string surname    = exchangeContact.Surname;
            string givenName  = exchangeContact.GivenName;
            string middleName = exchangeContact.MiddleName;

            if (GetIsContactNameEmpty(exchangeContact, context) || GetRemoteItemLockedForSync(context))
            {
                Action = SyncAction.None;
                return;
            }
            LoadItemProperties(exchangeContact);
            var contact = GetContactInstance(context, localItem, exchangeContact);

            if (contact == null || !SetContactExtendProperty(context, exchangeContact, contact.PrimaryColumnValue))
            {
                Action = SyncAction.None;
                return;
            }
            contact.SetColumnValue("Surname", surname);
            contact.SetColumnValue("GivenName", givenName);
            contact.SetColumnValue("MiddleName", middleName);
            contact.SetColumnValue("OwnerId", context.UserConnection.CurrentUser.ContactId);
            contact.SetColumnValue("JobTitle", exchangeContact.JobTitle);
            var birthdate = exchangeContact.SafeGetValue <DateTime>(Exchange.ContactSchema.Birthday);

            if (birthdate != DateTime.MinValue)
            {
                contact.SetColumnValue("BirthDate", birthdate);
            }
            Dictionary <string, Guid> accountsMap = contactRemoteProvider.AccountsMap;

            if (accountsMap != null)
            {
                string companyName = exchangeContact.CompanyName;
                if (string.IsNullOrEmpty(companyName))
                {
                    contact.SetColumnValue("AccountId", null);
                }
                else if (accountsMap.ContainsKey(companyName))
                {
                    contact.SetColumnValue("AccountId", accountsMap[companyName]);
                }
            }
            AddOrReplaceWebPageInLocalItem(context.UserConnection, localItem, contact.PrimaryColumnValue,
                                           exchangeContact.BusinessHomePage);
            var emailAddressesSynchronizer = new ExchangeEmailAddressDetailsSynchronizer(context, localItem,
                                                                                         exchangeContact);
            var addressesSynchronizer    = new ExchangeAddressDetailsSynchronizer(context, localItem, exchangeContact);
            var phoneNumbersSynchronizer = new ExchangePhoneNumbersDetailsSynchronizer(context, localItem,
                                                                                       exchangeContact);

            emailAddressesSynchronizer.SyncLocalDetails();
            addressesSynchronizer.SyncLocalDetails();
            phoneNumbersSynchronizer.SyncLocalDetails();
        }
Example #12
0
 public static async Task <LocalItem> GetItemInfo(LocalItem item)
 {
     throw new NotImplementedException();
 }
Example #13
0
 public void AddToLocal(LocalItem localItem)
 {
     base.AddObject("Local", localItem);
 }
 public Task SaveMedia(Stream stream, LocalItem localItem, ServerInfo server)
 {
     _logger.Debug("Saving media to " + localItem.LocalPath);
     return(_fileRepository.SaveFile(stream, localItem.LocalPath));
 }
Example #15
0
        /// <summary>Returns activity instance for exchange appointment, in case of changed remote id.</summary>
        /// <param name="context">Synchronization context.</param>
        /// <param name="exchangeItem">Exchange item in external storage.</param>
        /// <param name="storedId">Id of bpm activity, stored in external property of exchange item.</param>
        /// <param name="localItem">Local storage item.</param>
        /// <returns>Activity instance.</returns>
        protected Entity GetSyncedActivityWithChangedRemoteId(SyncContext context, Exchange.Item exchangeItem, Guid storedId, LocalItem localItem)
        {
            Entity instance;
            var    syncValueName = localItem.Schema.SyncValueName;
            var    schema        = context.UserConnection.EntitySchemaManager.GetInstanceByName("Activity");

            instance = schema.CreateEntity(context.UserConnection);
            if (!localItem.Entities["Activity"].Any(se => se.EntityId.Equals(storedId)) &&
                instance.FetchFromDB(storedId))
            {
                SyncEntity syncEntity         = SyncEntity.CreateNew(instance);
                var        isCurrentUserOwner = context.UserConnection.CurrentUser.ContactId == instance.GetTypedColumnValue <Guid>("OwnerId");
                syncEntity.Action = isCurrentUserOwner ? SyncAction.Update : SyncAction.None;
                context.LogInfo(SyncAction.None, SyncDirection.DownloadAndUpload,
                                "GetSyncedActivityWithChangedRemoteId set action {0} for {1}",
                                syncEntity.Action, GetDisplayName());
                localItem.AddOrReplace("Activity", syncEntity);
                if (syncValueName == ExchangeConsts.ExchangeAppointmentClassName)
                {
                    context.LogInfo(SyncAction.None, SyncDirection.DownloadAndUpload,
                                    "GetSyncedActivityWithChangedRemoteId ExchangeAppointmentClassName action update for {0}",
                                    GetDisplayName());
                    Action            = SyncAction.Update;
                    syncEntity.Action = SyncAction.Update;
                }
                else
                {
                    Action = isCurrentUserOwner ? SyncAction.Update : SyncAction.None;
                    context.LogInfo(SyncAction.None, SyncDirection.DownloadAndUpload,
                                    "GetSyncedActivityWithChangedRemoteId action {0} for {1}", Action, GetDisplayName());
                    if (isCurrentUserOwner)
                    {
                        ActualizeOldMetadata(context, storedId, Id);
                    }
                }
            }
            else
            {
                context.LogInfo(SyncAction.None, SyncDirection.DownloadAndUpload,
                                "GetSyncedActivityWithChangedRemoteId not found entity action {0} for {1}",
                                Action, GetDisplayName());
                instance = GetEntityInstance <Entity>(context, localItem, "Activity");
            }
            return(instance);
        }
 /// <summary>
 /// Deletes the specified item.
 /// </summary>
 /// <param name="item">The item.</param>
 /// <returns>Task.</returns>
 public Task Delete(LocalItem item)
 {
     return(_itemRepository.Delete(item.Id));
 }
Example #17
0
        /// <summary>
        /// Returns activity instance.
        /// </summary>
        /// <param name="context">Synchronization context.</param>
        /// <param name="exchangeItem">Sync element in external storage.</param>
        /// <param name="localItem">Sync element in local storage.</param>
        protected Entity GetActivity(SyncContext context, Exchange.Item exchangeItem, ref LocalItem localItem)
        {
            Entity instance;
            Object localId;

            if (exchangeItem.TryGetProperty(ExchangeUtilityImpl.LocalIdProperty, out localId))
            {
                context.LogInfo(SyncAction.None, SyncDirection.DownloadAndUpload,
                                "GetActivity use localId action {0} for {1}",
                                Action, GetDisplayName());
                instance = GetSyncedActivityWithChangedRemoteId(context, exchangeItem, Guid.Parse(localId.ToString()), localItem);
            }
            else
            {
                context.LogInfo(SyncAction.None, SyncDirection.DownloadAndUpload,
                                "GetActivity not use localId action {0} for {1}",
                                Action, GetDisplayName());
                instance = GetEntityInstance <Entity>(context, localItem, "Activity");
            }
            return(instance);
        }
Example #18
0
        private async Task _GetChangesFromSearchIndex(StorageFolder folder, long associationId,
                                                      List <BaseItem> result)
        {
            var association = FolderAssociationTableModel.GetDefault().GetItem(associationId);
            var files       = new List <IStorageItem>();
            var options     = new QueryOptions();

            options.FolderDepth   = FolderDepth.Deep;
            options.IndexerOption = IndexerOption.UseIndexerWhenAvailable;
            //details about filesystem queries using the indexer
            //https://msdn.microsoft.com/en-us/magazine/mt620012.aspx
            string timeFilter = "System.Search.GatherTime:>=" + association.LastSync;

            options.ApplicationSearchFilter = timeFilter;
            var prefetchedProperties = new List <string> {
                "System.DateModified", "System.Size"
            };

            options.SetPropertyPrefetch(PropertyPrefetchOptions.BasicProperties, prefetchedProperties);
            if (!folder.AreQueryOptionsSupported(options))
            {
                throw new Exception($"Windows Search Index has to be enabled for {folder.Path}");
            }

            var queryResult = folder.CreateItemQueryWithOptions(options);

            queryResult.ApplyNewQueryOptions(options);
            files.AddRange(await queryResult.GetItemsAsync());

            foreach (var file in files)
            {
                try
                {
                    IDictionary <string, object> propertyResult = null;
                    if (file.IsOfType(StorageItemTypes.File))
                    {
                        propertyResult =
                            await((StorageFile)file).Properties.RetrievePropertiesAsync(prefetchedProperties);
                    }
                    else if (file.IsOfType(StorageItemTypes.Folder))
                    {
                        propertyResult =
                            await((StorageFolder)file).Properties.RetrievePropertiesAsync(prefetchedProperties);
                    }
                    var item = new LocalItem(new FolderAssociation {
                        Id = associationId
                    }, file, propertyResult);

                    var existingItem = ItemTableModel.GetDefault().GetItem(item);
                    if (existingItem != null)
                    {
                        if (!item.IsCollection)
                        {
                            //additional check if the file has changed:
                            //even though the size not the best way to make sure if a file has changed
                            //its very unlikely that after a change they have the exact same byte count
                            //so its the best option we have
                            if ((ulong)propertyResult["System.Size"] == existingItem.Size)
                            {
                                continue;
                            }
                        }
                    }
                    result.Add(item);
                }
                catch (Exception)
                {
                    Debug.WriteLine(file);
                    throw;
                }
            }

            if (files.Count == 0)
            {
                await _GetChangedFilesRecursive(folder, association, result);
            }

            if (!IsBackgroundSync)
            {
                var unsynced =
                    ItemTableModel.GetDefault()
                    .GetPostponedItems()
                    .Where(x => x.AdapterType == typeof(FileSystemAdapter));
                foreach (var abstractItem in unsynced)
                {
                    abstractItem.SyncPostponed = false;
                }
                result.AddRange(unsynced);
            }
        }
Example #19
0
 /// <summary>
 /// Fills BPM synchronization item<paramref name="localItem"/>
 /// the values of the elements in the external storage.
 /// </summary>
 /// <param name="localItem">BPM item.</param>
 /// <param name="context">Synchronization context.</param>
 public abstract void FillLocalItem(SyncContext context, ref LocalItem localItem);
Example #20
0
 public Task GetItem(LocalItem item)
 {
     throw new NotImplementedException();
 }
Example #21
0
 /// <summary>
 /// Fills item in remote storage the values
 /// of the BPM element<paramref name="localItem"/>.
 /// </summary>
 /// <param name="localItem">BPM item.</param>
 /// <param name="context">Synchronization context.</param>
 public abstract void FillRemoteItem(SyncContext context, LocalItem localItem);
Example #22
0
 private void SelecionaLocalItem(LocalItem localItem)
 {
     _localItemSelecionado = localItem;
     _localItemSelecionado.Highlight();
 }
Example #23
0
 public Task SaveMedia(Windows.Storage.IStorageFile file, LocalItem localItem, ServerInfo server)
 {
     _logger.Debug("Saving media to " + localItem.LocalPath);
     return(_fileRepository.SaveFile(file, localItem.LocalPath));
 }
 public Task AddOrUpdate(LocalItem item)
 {
     return(Task.FromResult(true));
 }
Example #25
0
 private async Task <SendFileResult> SendFile(IServerSyncProvider provider, string inputPath, LocalItem item, SyncTarget target, CancellationToken cancellationToken)
 {
     using (var stream = _fileSystem.GetFileStream(inputPath, FileMode.Open, FileAccess.Read, FileShare.Read, true))
     {
         return(await provider.SendFile(stream, item.LocalPath, target, new Progress <double>(), cancellationToken).ConfigureAwait(false));
     }
 }
 public Task <string> SaveSubtitles(Stream stream, string format, LocalItem item, string language, bool isForced)
 {
     throw new NotImplementedException();
 }
Example #27
0
        private async Task <List <ItemFileInfo> > GetFiles(IServerSyncProvider provider, LocalItem item, SyncTarget target, CancellationToken cancellationToken)
        {
            var path = item.LocalPath;

            path = provider.GetParentDirectoryPath(path, target);

            var list = await provider.GetFileSystemEntries(path, target, cancellationToken).ConfigureAwait(false);

            var itemFiles = new List <ItemFileInfo>();

            var name = Path.GetFileNameWithoutExtension(item.LocalPath);

            foreach (var file in list.Where(f => f.Name.Contains(name)))
            {
                var itemFile = new ItemFileInfo
                {
                    Path = file.Path,
                    Name = file.Name
                };

                if (IsSubtitleFile(file.Name))
                {
                    itemFile.Type = ItemFileType.Subtitles;
                }

                itemFiles.Add(itemFile);
            }

            return(itemFiles);
        }
Example #28
0
 public ItemModel()
 {
     BasicItem = new Item();
     FoodItem  = new FoodItem();
     LocalItem = new LocalItem();
 }
Example #29
0
 Task IItemRepository.AddOrUpdate(LocalItem item)
 {
     throw new NotImplementedException();
 }