Beispiel #1
0
        public async Task CalculateRelationshipMetadataAsync()
        {
            this.NextSyncDisplayString         = "Calculating...";
            this.RelationshipSizeDisplayString = "Calculating...";
            this.DatabaseSizeDisplayString     = "Calculating...";

            Stopwatch stopwatch = Stopwatch.StartNew();

            if (this.TriggerType == SyncTriggerType.Manual)
            {
                this.NextSyncDisplayString = "When manually triggered";
            }
            else if (this.TriggerType == SyncTriggerType.Scheduled)
            {
                DateTime nextSyncTime = this.BaseModel.GetNextScheduledTriggerTime();
                this.NextSyncDisplayString = nextSyncTime.ToString("dddd, MMMM dd, HH:mm");
            }
            else if (this.SyncSourceAdapter.AdapterBase.SupportsChangeNotification())
            {
                IChangeNotification changeNotification =
                    (IChangeNotification)this.SyncSourceAdapter.AdapterBase;

                DateTime nextNotify = changeNotification.GetNextNotificationTime();

                if (nextNotify != DateTime.MinValue)
                {
                    this.NextSyncDisplayString = nextNotify.ToString("dddd, MMMM dd, HH:mm:ss");
                }
            }
            else
            {
                this.NextSyncDisplayString = "Unknown!";
            }

            int  fileCount      = 0;
            int  directoryCount = 0;
            long byteCount      = 0;

            using (var db = await this.BaseModel.GetDatabaseAsync())
            {
                foreach (SyncEntry syncEntry in db.Entries)
                {
                    if (syncEntry.Type == SyncEntryType.File)
                    {
                        fileCount++;
                        byteCount += syncEntry.GetSize(this.BaseModel, SyncEntryPropertyLocation.Source);
                    }
                    else if (syncEntry.Type == SyncEntryType.Directory)
                    {
                        directoryCount++;
                    }
                }
            }

            this.RelationshipSizeDisplayString = string.Format(
                "{0} in {1} files, {2} folders",
                FileSizeConverter.Convert(byteCount, 2),
                fileCount,
                directoryCount);

            string databasePath = SyncDatabase.GetDatabaseFilePath(this.BaseModel.Configuration.RelationshipId);

            System.IO.FileInfo fileInfo = new System.IO.FileInfo(databasePath);

            this.DatabaseSizeDisplayString = FileSizeConverter.Convert(fileInfo.Length, 2);

            stopwatch.Stop();
            Logger.Debug("Finished CalculateRelationshipMetadataAsync. Duration=" + stopwatch.Elapsed);
        }