Beispiel #1
0
        public override Stream GetReadStreamForEntry(SyncEntry entry)
        {
            // Get the adapter entry for the parent entry
            var adapterEntry = entry.AdapterEntries.First(e => e.AdapterId == this.Configuration.Id);

            return(new GoogleFileDownloadStream(this.googleDriveClient, adapterEntry.AdapterEntryId));
        }
 private void PlayerMovement_OnDestroy()
 {
     _player.Data.Position = _position;
     _player.Data.Rotation = _rotation;
     _entry  = null;
     _player = null;
 }
Beispiel #3
0
 private void ScriptedMovement_OnDestroy()
 {
     _wait?.Destroy();
     _wait    = null;
     _entry   = null;
     _current = null;
 }
Beispiel #4
0
        public SyncEntryViewModel(NavigationNodeViewModel navigationNodeViewModel, SyncEntry syncEntry, SyncRelationshipViewModel syncRelationship)
        {
            this.navigationNodeViewModel = navigationNodeViewModel;
            this.syncRelationship        = syncRelationship;
            this.SyncEntry = syncEntry;

            this.Name              = syncEntry.Name;
            this.LastModified      = syncEntry.EntryLastUpdatedDateTimeUtc;
            this.Size              = Convert.ToUInt64(syncEntry.OriginalSize);
            this.IsDirectory       = syncEntry.Type == SyncEntryType.Directory;
            this.SelectItemCommand = new DelegatedCommand(o => this.SelectItem());

            if (this.IsDirectory)
            {
                var fileInfo = FileInfoCache.GetFolderInfo();
                this.IconImageSource = fileInfo.SmallIcon;
                this.LargeIcon       = fileInfo.LargeIcon;
                this.TypeName        = "Folder";
                return;
            }

            int      lastIndex2 = this.Name.LastIndexOf(".", StringComparison.Ordinal);
            FileInfo fileInfo2  = FileInfoCache.GetFileInfo(this.Name.Substring(lastIndex2).ToLowerInvariant());

            this.IconImageSource = fileInfo2.SmallIcon;
            this.TypeName        = fileInfo2.TypeName;
        }
Beispiel #5
0
        /// <summary>
        /// Get a stream for writing the contents of an item
        /// </summary>
        /// <param name="entry">The entry representing the file to be uploaded</param>
        /// <param name="length">The length of the file to be uploaded</param>
        /// <returns>The <see cref="Stream"/>that the file's content can be written to</returns>
        public override Stream GetWriteStreamForEntry(SyncEntry entry, long length)
        {
            // Create a default session. By itself, the file will be uploaded to Backblaze when the stream
            // containins the session is disposed.
            BackblazeB2UploadSession session = new BackblazeB2UploadSession(entry, length);

            // If the file is large enough, call the method below to get the large file upload information. When
            // these properties are present, the stream will upload the file's parts individually.
            if (length >= this.TypedConfiguration.ConnectionInfo.RecommendedPartSize)
            {
                session.StartLargeFileResponse =
                    this.backblazeClient.StartLargeUpload(
                        this.TypedConfiguration.BucketId,
                        entry.GetRelativePath(null, "/"))
                    .Result;

                session.GetUploadPartUrlResponse =
                    this.backblazeClient.GetUploadPartUrl(session.StartLargeFileResponse.FileId).Result;

                // Return the stream type dedicated to uploading large files (via parts)
                return(new BackblazeB2LargeUploadStream(
                           this,
                           session,
                           Constants.LimitPartMaximumSize,
                           length));
            }

            // The file size is below the large-file limit, so upload directly
            return(new BackblazeB2UploadStream(this, session));
        }
        private void CreateItem(SyncEntry entry)
        {
            string fullPath;

            using (var database = this.Relationship.GetDatabase())
            {
                fullPath = Path.Combine(this.Config.RootDirectory, entry.GetRelativePath(database, this.PathSeparator));
            }

            switch (entry.Type)
            {
            case SyncEntryType.Directory:
                Directory.CreateDirectory(fullPath);
                break;

            case SyncEntryType.File:
                using (File.Create(fullPath))
                {
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Beispiel #7
0
        public override void DeleteItem(SyncEntry entry)
        {
            string fullPath;

            using (var database = this.Relationship.GetDatabase())
            {
                fullPath = Path.Combine(this.Config.RootDirectory, entry.GetRelativePath(database, this.PathSeparator));
            }

            switch (entry.Type)
            {
            case SyncEntryType.Directory:
                Directory.Delete(fullPath);
                break;

            case SyncEntryType.File:
                File.Delete(fullPath);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            entry.EntryLastUpdatedDateTimeUtc = DateTime.UtcNow;
        }
Beispiel #8
0
        public override bool IsEntryUpdated(SyncEntry childEntry, IAdapterItem adapterItem, out EntryUpdateResult result)
        {
            const long TicksPerMillisecond = 10000;

            // 2017/11/24: There appears to be a discrepency when reading ModifiedDateTimeUtc and CreationTimeUtc
            // from FileSystemInfo objects. The Ticks value is being rounded to the nearest 10000 ticks, causing
            // some directories to appear to be modified. For now, we will set the threshold for an item being
            // changed to 10ms
            const long Epsilon = TicksPerMillisecond * 10;

            FileSystemFolder fileSystemItem = adapterItem as FileSystemFolder;

            if (fileSystemItem == null)
            {
                throw new ArgumentException("The adapter item is not of the correct type.", nameof(adapterItem));
            }

            result = new EntryUpdateResult();

            if (Math.Abs(childEntry.ModifiedDateTimeUtc.Ticks - fileSystemItem.FileSystemInfo.LastWriteTimeUtc.Ticks) > Epsilon)
            {
                result.ChangeFlags |= SyncEntryChangedFlags.ModifiedTimestamp;
                result.ModifiedTime = fileSystemItem.FileSystemInfo.LastWriteTimeUtc;
            }

            if (Math.Abs(childEntry.CreationDateTimeUtc.Ticks - fileSystemItem.FileSystemInfo.CreationTimeUtc.Ticks) > Epsilon)
            {
                result.ChangeFlags |= SyncEntryChangedFlags.CreatedTimestamp;
                result.CreationTime = fileSystemItem.FileSystemInfo.CreationTimeUtc;
            }

            FileInfo      fileInfo = fileSystemItem.FileSystemInfo as FileInfo;
            SyncEntryType fileType = SyncEntryType.Directory;

            if (fileInfo != null)
            {
                fileType = SyncEntryType.File;

                if (fileInfo.Length != childEntry.GetSize(this.Relationship, SyncEntryPropertyLocation.Source))
                {
                    result.ChangeFlags |= SyncEntryChangedFlags.FileSize;
                }
            }

            if (!string.Equals(fileSystemItem.Name, childEntry.Name, StringComparison.Ordinal))
            {
                result.ChangeFlags |= SyncEntryChangedFlags.Renamed;
            }

            // It is possible that a directory was created over a file that previously existed (with the same name). To
            // handle this, we need to check if the type changed.
            if (childEntry.Type != fileType)
            {
                // TODO: Handle this
                throw new NotImplementedException();
            }

            return(result.ChangeFlags != SyncEntryChangedFlags.None);
        }
 public PetMovement(CreatureObject parent)
     : base(parent)
 {
     _entry            = new SyncEntry();
     _position         = _creature.SpawnPosition;
     _rotation         = _creature.SpawnRotation;
     parent.OnSpawn   += PetMovement_OnSpawn;
     parent.OnDestroy += PetMovement_OnDestroy;
 }
Beispiel #10
0
        public override SyncEntry CreateSyncEntryForAdapterItem(IAdapterItem item, SyncEntry parentEntry)
        {
            GoogleDriveAdapterItem adapterItem = item as GoogleDriveAdapterItem;

            Pre.Assert(adapterItem != null, "adapterItem != null");
            Pre.Assert(adapterItem.Item != null, "adapterItem.Item != null");

            return(this.CreateEntry(adapterItem.Item, parentEntry));
        }
Beispiel #11
0
        private SyncEntry CreateEntry(Item item, SyncEntry parent)
        {
            SyncEntry entry = new SyncEntry
            {
                CreationDateTimeUtc = item.CreatedTime.ToUniversalTime(),
                ModifiedDateTimeUtc = item.ModifiedTime,
                Name           = item.Name,
                AdapterEntries = new List <SyncEntryAdapterData>()
            };

            if (parent != null)
            {
                entry.ParentEntry = parent;
                entry.ParentId    = parent.Id;
            }

            entry.AdapterEntries.Add(new SyncEntryAdapterData()
            {
                AdapterId      = this.Configuration.Id,
                SyncEntry      = entry,
                AdapterEntryId = item.Id
            });

            if (item.IsFolder)
            {
                entry.Type = SyncEntryType.Directory;
            }
            else
            {
                entry.Type = SyncEntryType.File;

                if (this.Relationship.EncryptionMode == EncryptionMode.None ||
                    this.Relationship.EncryptionMode == EncryptionMode.Encrypt)
                {
                    entry.OriginalSize    = item.Size;
                    entry.OriginalMd5Hash = HexToBytes(item.Md5Checksum);
                }
                else
                {
                    entry.EncryptedSize    = item.Size;
                    entry.EncryptedMd5Hash = HexToBytes(item.Md5Checksum);
                }
            }


            // TODO: FIX THIS
            //if (this.Relationship.Configuration.SyncTimestamps)
            //{
            //    entry.CreationDateTimeUtc = info.CreationTimeUtc;
            //    entry.ModifiedDateTimeUtc = info.LastWriteTimeUtc;
            //}

            entry.EntryLastUpdatedDateTimeUtc = DateTime.UtcNow;

            return(entry);
        }
Beispiel #12
0
 public MobMovement(WO_MOB parent)
     : base(parent)
 {
     _entry               = new SyncEntry();
     _position            = _creature.SpawnPosition;
     _rotation            = _creature.SpawnRotation.ToRadians();
     parent.OnSpawn      += MobMovement_OnSpawn;
     parent.OnDestroy    += MobMovement_OnDestroy;
     parent.OnInitialize += MobMovement_OnInitialize;
 }
        public SyncFoldersNodeViewModel(NavigationNodeViewModel parent, SyncRelationshipViewModel syncRelationship, SyncEntry syncEntry)
            : base(parent, null, LazyLoadPlaceholderNodeViewModel.Instance)
        {
            this.syncRelationship = syncRelationship;
            this.syncEntry        = syncEntry;
            this.Name             = syncEntry.Name;
            this.IconImageSource  = "/SyncPro.UI;component/Resources/Graphics/folder_open_16.png";

            this.MenuCommands.Add(new RestoreItemMenuCommand(this, this.syncRelationship));
        }
 public PlayerMovement(WO_Player parent)
     : base(parent)
 {
     _player           = parent.Player;
     _entry            = new SyncEntry();
     _position         = _player.Data.Position;
     _rotation         = _player.Data.Rotation;
     parent.OnSpawn   += PlayerMovement_OnSpawn;
     parent.OnDestroy += PlayerMovement_OnDestroy;
 }
Beispiel #15
0
        public override Stream GetReadStreamForEntry(SyncEntry entry)
        {
            // Get the adapter entry for the parent entry
            var adapterEntry = entry.AdapterEntries.First(e => e.AdapterId == this.Configuration.Id);

            Uri downloadUri = this.oneDriveClient.GetDownloadUriForItem(adapterEntry.AdapterEntryId).Result;

            Logger.Debug("Opening READ stream for OneDrive file {0} with Uri {1}", entry.Name, downloadUri);

            return(new OneDriveFileDownloadStream(this.oneDriveClient, downloadUri));
        }
Beispiel #16
0
        public override SyncEntry CreateSyncEntryForAdapterItem(IAdapterItem item, SyncEntry parentEntry)
        {
            FileSystemFolder fileSystemItem = item as FileSystemFolder;

            if (fileSystemItem == null)
            {
                throw new InvalidOperationException("Item type is incorrect.");
            }

            return(this.CreateEntry(fileSystemItem.FileSystemInfo, parentEntry));
        }
Beispiel #17
0
        public BackblazeB2UploadSession(SyncEntry entry, long fileSize)
        {
            this.Entry    = entry;
            this.FileSize = fileSize;

            this.PartHashes = new Dictionary <int, string>();

            // Per the spec, part numbers start at 1 (not 0)
            // See: https://www.backblaze.com/b2/docs/b2_upload_part.html
            this.CurrentPartNumber = 1;
        }
Beispiel #18
0
        public override Stream GetWriteStreamForEntry(SyncEntry entry, long length)
        {
            // Get the adapter entry for the parent entry
            var parentAdapterEntry = entry.ParentEntry.AdapterEntries.First(e => e.AdapterId == this.Configuration.Id);

            // Create the upload sessiond
            OneDriveUploadSession session =
                this.oneDriveClient.CreateUploadSession(parentAdapterEntry.AdapterEntryId, entry.Name, length).Result;

            return(new OneDriveFileUploadStream(this.oneDriveClient, session));
        }
Beispiel #19
0
        public override SyncEntry CreateSyncEntryForAdapterItem(IAdapterItem item, SyncEntry parentEntry)
        {
            OneDriveAdapterItem oneDriveAdapterItem = item as OneDriveAdapterItem;

            Pre.Assert(oneDriveAdapterItem != null, "oneDriveAdapterItem != null");
            Pre.Assert(oneDriveAdapterItem.Item != null, "oneDriveAdapterItem.Item != null");

            // Is this always true?
            Pre.Assert(parentEntry != null, "parentEntry != null");

            return(this.CreateEntry(oneDriveAdapterItem.Item, parentEntry));
        }
Beispiel #20
0
        public override SyncEntry CreateSyncEntryForAdapterItem(IAdapterItem item, SyncEntry parentEntry)
        {
            AzureStorageAdapterItem adapterItem = (AzureStorageAdapterItem)item;

            SyncEntry entry = new SyncEntry
            {
                Name                = item.Name,
                AdapterEntries      = new List <SyncEntryAdapterData>(),
                CreationDateTimeUtc = adapterItem.CreationTimeUtc,
                ModifiedDateTimeUtc = adapterItem.ModifiedTimeUtc
            };

            if (parentEntry != null)
            {
                entry.ParentEntry = parentEntry;
                entry.ParentId    = parentEntry.Id;
            }

            entry.AdapterEntries.Add(new SyncEntryAdapterData()
            {
                AdapterId      = this.Configuration.Id,
                SyncEntry      = entry,
                AdapterEntryId = item.UniqueId
            });

            if (adapterItem.ItemType == SyncAdapterItemType.File)
            {
                entry.Type = SyncEntryType.File;
                entry.SetSize(this.Relationship, SyncEntryPropertyLocation.Source, adapterItem.Size);
                // TODO Set MD5 hash?
            }
            else
            {
                entry.Type = SyncEntryType.Directory;
            }


            if (entry.Type == SyncEntryType.Undefined)
            {
                throw new Exception(string.Format("Unknown type for Item {0} ({1})", item.Name, item.UniqueId));
            }

            // TODO: FIX THIS
            //if (this.Relationship.Configuration.SyncTimestamps)
            //{
            //    entry.CreationDateTimeUtc = info.CreationTimeUtc;
            //    entry.ModifiedDateTimeUtc = info.LastWriteTimeUtc;
            //}

            entry.EntryLastUpdatedDateTimeUtc = DateTime.UtcNow;

            return(entry);
        }
Beispiel #21
0
        public override Stream GetReadStreamForEntry(SyncEntry entry)
        {
            long size = entry.GetSize(this.Relationship, SyncEntryPropertyLocation.Destination);

            using (SyncDatabase db = this.Relationship.GetDatabase())
            {
                return(new AzureStorageDownloadStream(
                           this.storageClient,
                           this.TypedConfiguration.ContainerName,
                           entry.GetRelativePath(db, "/"),
                           size));
            }
        }
Beispiel #22
0
        public EntryUpdateInfo(SyncEntry entry, AdapterBase originatingAdapter, SyncEntryChangedFlags flags, string relativePath)
        {
            Pre.ThrowIfArgumentNull(entry, "entry");
            Pre.ThrowIfArgumentNull(originatingAdapter, "originatingAdapter");

            this.Entry = entry;
            this.OriginatingAdapter = originatingAdapter;
            this.Flags        = flags;
            this.RelativePath = relativePath;

            if (flags != SyncEntryChangedFlags.None)
            {
                this.State = EntryUpdateState.NotStarted;
            }
        }
Beispiel #23
0
        public async Task <BackblazeB2FileUploadResponse> UploadFileDirect(
            SyncEntry entry,
            Stream contentStream,
            byte[] sha1Hash)
        {
            long size = entry.GetSize(this.Relationship, SyncEntryPropertyLocation.Destination);

            return(await this.backblazeClient.UploadFile(
                       entry.GetRelativePath(null, "/"),
                       BitConverter.ToString(sha1Hash).Replace("-", ""),
                       size,
                       this.TypedConfiguration.BucketId,
                       contentStream)
                   .ConfigureAwait(false));
        }
Beispiel #24
0
 public ScriptedMovement(ushort id, CreatureObject parent)
     : base(parent)
 {
     _state     = 0;
     _entry     = new SyncEntry();
     _direction = Vector3.UnitZ;
     _position  = _creature.SpawnPosition;
     _rotation  = _creature.SpawnRotation.ToRadians();
     if (DataMgr.Select(id, out _entries))
     {
         Execute();
     }
     parent.OnSpawn   += ScriptedMovement_OnSpawn;
     parent.OnDestroy += ScriptedMovement_OnDestroy;
 }
 private void View_ReceivedStream(NetMessage message, Player player)
 {
     if ((m_state & ReciveingFlag) != 0)
     {
         SyncEntry sync = default(SyncEntry), last = m_last;
         sync.OnDeserialize(message);
         if (m_time > sync.Time)
         {
             sync.Position = m_owner.Position + (sync.Position - last.Position);
             sync.Rotation = m_owner.Rotation + (sync.Rotation - last.Rotation);
         }
         m_last = sync;
         m_owner.UpdateLocation(sync.Position, sync.Rotation);
     }
 }
Beispiel #26
0
 public ScriptedMovement(ScriptedMovement original, CreatureObject clone)
     : base(clone)
 {
     _speed           = original._speed;
     _state           = original._state;
     _entry           = new SyncEntry();
     _entries         = original._entries;
     _current         = original._current;
     _waiting         = original._waiting;
     _position        = original.Position;
     _rotation        = original.Rotation;
     _direction       = original._direction;
     clone.OnSpawn   += ScriptedMovement_OnSpawn;
     clone.OnDestroy += ScriptedMovement_OnDestroy;
 }
Beispiel #27
0
        private SyncEntry CreateEntry(FileSystemInfo info, SyncEntry parentEntry)
        {
            SyncEntry entry = new SyncEntry
            {
                CreationDateTimeUtc = info.CreationTimeUtc,
                ModifiedDateTimeUtc = info.LastWriteTimeUtc,
                Name           = info.Name,
                AdapterEntries = new List <SyncEntryAdapterData>()
            };

            if (parentEntry != null)
            {
                entry.AdapterEntries.Add(
                    new SyncEntryAdapterData()
                {
                    AdapterId      = this.Configuration.Id,
                    SyncEntry      = entry,
                    AdapterEntryId = GetItemId(info)
                });

                entry.ParentEntry = parentEntry;
                entry.ParentId    = parentEntry.Id;
            }

            FileInfo fileInfo = info as FileInfo;

            if (fileInfo != null)
            {
                entry.Type = SyncEntryType.File;
                entry.SetSize(this.Relationship, SyncEntryPropertyLocation.Source, fileInfo.Length);
            }

            DirectoryInfo directoryInfo = info as DirectoryInfo;

            if (directoryInfo != null)
            {
                entry.Type = SyncEntryType.Directory;
            }

            if (entry.Type == SyncEntryType.Undefined)
            {
                throw new Exception("Unknown type for FileSystemInfo " + info.FullName);
            }

            entry.EntryLastUpdatedDateTimeUtc = DateTime.UtcNow;

            return(entry);
        }
        public override Stream GetWriteStreamForEntry(SyncEntry entry, long length)
        {
            if (entry.Type != SyncEntryType.File)
            {
                throw new InvalidOperationException("Cannot get a filestream for a non-file.");
            }

            string fullPath;

            using (var db = this.Relationship.GetDatabase())
            {
                fullPath = Path.Combine(this.Config.RootDirectory, entry.GetRelativePath(db, this.PathSeparator));
            }

            return(File.Open(fullPath, FileMode.OpenOrCreate, FileAccess.ReadWrite));
        }
Beispiel #29
0
        public override async Task CreateItemAsync(SyncEntry entry)
        {
            ItemContainer parent;

            // Get the parent entry to the one we will be creating. If that entry's parent ID is null, use the target root
            // as the place to create the item
            if (entry.ParentEntry.ParentId == null)
            {
                parent = await this.GetRootItemContainer().ConfigureAwait(false);
            }
            else
            {
                var parentEntryData = entry.ParentEntry.AdapterEntries.First(e => e.AdapterId == this.Configuration.Id);
                parent = new Item()
                {
                    Id = parentEntryData.AdapterEntryId
                };
            }

            string uniqueId;

            if (entry.Type == SyncEntryType.Directory)
            {
                var newFolder = await this.oneDriveClient.CreateFolderAsync(parent, entry.Name).ConfigureAwait(false);

                uniqueId = newFolder.Id;
            }
            else if (entry.Type == SyncEntryType.File)
            {
                var newFile = await this.oneDriveClient.CreateItem(parent, entry.Name).ConfigureAwait(false);

                uniqueId = newFile.Id;
            }
            else
            {
                throw new NotImplementedException();
            }

            entry.AdapterEntries.Add(new SyncEntryAdapterData()
            {
                SyncEntryId    = entry.Id,
                AdapterId      = this.Configuration.Id,
                AdapterEntryId = uniqueId
            });
        }
Beispiel #30
0
        private void AddSyncEntriesRecursive(
            SyncDatabase db,
            List <EntryUpdateInfo> updatesToRestore,
            SyncEntry syncEntry,
            RestoreOnlyWindowsFileSystemAdapter destAdapter)
        {
            EntryUpdateInfo updateInfo = new EntryUpdateInfo(
                syncEntry,
                destAdapter,
                SyncEntryChangedFlags.Restored,
                syncEntry.GetRelativePath(db, "/"));

            updatesToRestore.Add(updateInfo);

            if (syncEntry.Type == SyncEntryType.Directory)
            {
                List <SyncEntry> childEntries = db.Entries.Where(e => e.ParentId == syncEntry.Id).ToList();
                foreach (SyncEntry childEntry in childEntries)
                {
                    this.AddSyncEntriesRecursive(db, updatesToRestore, childEntry, destAdapter);
                }
            }
        }