Пример #1
0
        /// <summary>
        /// Gets user file system item info from the remote storage data.
        /// </summary>
        /// <param name="remoteStorageItem">Remote storage item info.</param>
        /// <returns>User file system item info.</returns>
        public static FileSystemItemBasicInfo GetUserFileSysteItemInfo(FileSystemInfo remoteStorageItem)
        {
            FileSystemItemBasicInfo userFileSystemItem;

            if (remoteStorageItem is FileInfo)
            {
                userFileSystemItem = new FileBasicInfo();
            }
            else
            {
                userFileSystemItem = new FolderBasicInfo();
            }

            userFileSystemItem.Name           = remoteStorageItem.Name;
            userFileSystemItem.Attributes     = remoteStorageItem.Attributes;
            userFileSystemItem.CreationTime   = remoteStorageItem.CreationTime;
            userFileSystemItem.LastWriteTime  = remoteStorageItem.LastWriteTime;
            userFileSystemItem.LastAccessTime = remoteStorageItem.LastAccessTime;
            userFileSystemItem.ChangeTime     = remoteStorageItem.LastWriteTime;

            // Here you will typically store the file ETag. You will send the ETag to
            // the server inside If-Match header togater with updated content from client.
            // This will make sure the file on the server is not modified.
            //
            // In this sample, for the sake of simplicity, we use file last write time.
            userFileSystemItem.CustomData = BitConverter.GetBytes(remoteStorageItem.LastWriteTime.ToBinary());

            if (remoteStorageItem is FileInfo)
            {
                ((FileBasicInfo)userFileSystemItem).Length = ((FileInfo)remoteStorageItem).Length;
            }
            ;

            return(userFileSystemItem);
        }
Пример #2
0
        /// <summary>
        /// Gets a user file system item info from the remote storage data.
        /// </summary>
        /// <param name="remoteStorageItem">Remote storage item info.</param>
        /// <returns>User file system item info.</returns>
        public static FileSystemItemBasicInfo GetUserFileSysteItemBasicInfo(FileSystemInfo remoteStorageItem)
        {
            FileSystemItemBasicInfo userFileSystemItem;

            if (remoteStorageItem is FileInfo)
            {
                userFileSystemItem = new FileBasicInfo();
            }
            else
            {
                userFileSystemItem = new FolderBasicInfo();
            }

            userFileSystemItem.Name           = remoteStorageItem.Name;
            userFileSystemItem.Attributes     = remoteStorageItem.Attributes;
            userFileSystemItem.CreationTime   = remoteStorageItem.CreationTime;
            userFileSystemItem.LastWriteTime  = remoteStorageItem.LastWriteTime;
            userFileSystemItem.LastAccessTime = remoteStorageItem.LastAccessTime;
            userFileSystemItem.ChangeTime     = remoteStorageItem.LastWriteTime;

            // You will send the ETag to
            // the server inside If-Match header togeter with updated content from client.
            // This will make sure the changes on the server is not overwritten.
            //
            // In this sample, for the sake of simplicity, we use file last write time instead of ETag.
            userFileSystemItem.ETag = remoteStorageItem.LastWriteTime.ToBinary().ToString();

            // If the item is locked by another user, set the LockedByAnotherUser to true.
            // Here we just use the read-only attribute from remote storage item for demo purposes.
            userFileSystemItem.LockedByAnotherUser = (remoteStorageItem.Attributes & System.IO.FileAttributes.ReadOnly) != 0;

            if (remoteStorageItem is FileInfo)
            {
                ((FileBasicInfo)userFileSystemItem).Length = ((FileInfo)remoteStorageItem).Length;
            }
            ;

            // Set custom columns to be displayed in file manager.
            // We create property definitions when registering the sync root with corresponding IDs.
            List <FileSystemItemPropertyData> customProps = new List <FileSystemItemPropertyData>();

            if (userFileSystemItem.LockedByAnotherUser)
            {
                customProps.AddRange(
                    new ServerLockInfo()
                {
                    LockToken             = "token",
                    Owner                 = "User Name",
                    Exclusive             = true,
                    LockExpirationDateUtc = DateTimeOffset.Now.AddMinutes(30)
                }.GetLockProperties(Path.Combine(Config.Settings.IconsFolderPath, "LockedByAnotherUser.ico"))
                    );
            }
            userFileSystemItem.CustomProperties = customProps;

            return(userFileSystemItem);
        }
Пример #3
0
        /// <summary>
        /// Gets a user file system item info from the remote storage data.
        /// </summary>
        /// <param name="remoteStorageItem">Remote storage item info.</param>
        /// <returns>User file system item info.</returns>
        public static FileSystemItemBasicInfo GetUserFileSysteItemBasicInfo(FileSystemInfo remoteStorageItem)
        {
            FileSystemItemBasicInfo userFileSystemItem;

            if (remoteStorageItem is FileInfo)
            {
                userFileSystemItem = new FileBasicInfo();
            }
            else
            {
                userFileSystemItem = new FolderBasicInfo();
            }

            userFileSystemItem.Name           = remoteStorageItem.Name;
            userFileSystemItem.Attributes     = remoteStorageItem.Attributes;
            userFileSystemItem.CreationTime   = remoteStorageItem.CreationTime;
            userFileSystemItem.LastWriteTime  = remoteStorageItem.LastWriteTime;
            userFileSystemItem.LastAccessTime = remoteStorageItem.LastAccessTime;
            userFileSystemItem.ChangeTime     = remoteStorageItem.LastWriteTime;

            // You will send the ETag to
            // the server inside If-Match header togeter with updated content from client.
            // This will make sure the changes on the server is not overwritten.
            //
            // In this sample, for the sake of simplicity, we use file last write time instead of ETag.
            userFileSystemItem.ETag = remoteStorageItem.LastWriteTime.ToBinary().ToString();

            // If the item is locked by another user, set the LockedByAnotherUser to true.
            // Here we just use the read-only attribute from remote storage item for demo purposes.
            userFileSystemItem.LockedByAnotherUser = (remoteStorageItem.Attributes & System.IO.FileAttributes.ReadOnly) != 0;

            // If the file is moved/renamed and the app is not running this will help us
            // to sync the file/folder to remote storage after app starts.
            userFileSystemItem.CustomData = new CustomData
            {
                OriginalPath = Mapping.ReverseMapPath(remoteStorageItem.FullName)
            }.Serialize();

            if (remoteStorageItem is FileInfo)
            {
                ((FileBasicInfo)userFileSystemItem).Length = ((FileInfo)remoteStorageItem).Length;
            }
            ;

            return(userFileSystemItem);
        }