public void CreateSyncContentStream(ISyncPartnership partnership, SyncStartType type, SyncStoppedReason reason, TimeSpan syncDuration) { if ((partnership != null) && this.isSqmEnabled) { SqmSyncContentStream stream = new SqmSyncContentStream(); SetSyncType(partnership, type, stream); if (partnership.Device != null) { string winMoDeviceId = partnership.Device.WinMoDeviceId; long? nullable = (long?) DeviceSettings.Get(winMoDeviceId, "SyncCount"); uint num = 0; if (nullable.HasValue) { num = (uint) nullable.Value; } stream.SyncIndex = ++num; DeviceSettings.Set(winMoDeviceId, "SyncCount", num); } ISyncRules ruleManager = partnership.RuleManager; SetGlobalRules(stream, ruleManager); CalculateMusicSyncSelections(partnership.MusicAndMovieProvider, partnership.RuleManager, stream); this.CalculatePhotoSyncSelections(partnership.PhotoAndVideoProvider, partnership.RuleManager, stream); CalculateSyncResults(partnership, stream); stream.OperationTime = (uint) syncDuration.TotalMilliseconds; SetSyncResult(reason, stream); this.sqmManager.SetStream(stream); } }
public void CreateSyncContentStream(ISyncPartnership partnership, SyncStartType type, SyncStoppedReason reason, TimeSpan syncDuration) { if ((partnership != null) && this.isSqmEnabled) { SqmSyncContentStream stream = new SqmSyncContentStream(); SetSyncType(partnership, type, stream); if (partnership.Device != null) { string winMoDeviceId = partnership.Device.WinMoDeviceId; long? nullable = (long?)DeviceSettings.Get(winMoDeviceId, "SyncCount"); uint num = 0; if (nullable.HasValue) { num = (uint)nullable.Value; } stream.SyncIndex = ++num; DeviceSettings.Set(winMoDeviceId, "SyncCount", num); } ISyncRules ruleManager = partnership.RuleManager; SetGlobalRules(stream, ruleManager); CalculateMusicSyncSelections(partnership.MusicAndMovieProvider, partnership.RuleManager, stream); this.CalculatePhotoSyncSelections(partnership.PhotoAndVideoProvider, partnership.RuleManager, stream); CalculateSyncResults(partnership, stream); stream.OperationTime = (uint)syncDuration.TotalMilliseconds; SetSyncResult(reason, stream); this.sqmManager.SetStream(stream); } }
private static void SetSyncResult(SyncStoppedReason reason, SqmSyncContentStream stream) { switch (reason) { case SyncStoppedReason.Completed: stream.SyncResult = SqmSyncTerminationMethods.Completed; return; case SyncStoppedReason.Cancelled: stream.SyncResult = SqmSyncTerminationMethods.Canceled; return; case SyncStoppedReason.Aborted: stream.SyncResult = SqmSyncTerminationMethods.Aborted; return; case SyncStoppedReason.Paused: case SyncStoppedReason.CouldNotStart: case SyncStoppedReason.Unknown: break; case SyncStoppedReason.Disposed: stream.SyncResult = SqmSyncTerminationMethods.Quit; break; default: return; } }
private static void SetGlobalRules(SqmSyncContentStream stream, ISyncRules rules) { stream.MarkGlobalSyncOption(SqmGlobalSyncOptions.MusicEnabled, rules.IsMusicSyncEnabled); stream.MarkGlobalSyncOption(SqmGlobalSyncOptions.AllMusic, rules.SyncAllMusic); stream.MarkGlobalSyncOption(SqmGlobalSyncOptions.PhotosEnabled, rules.IsPhotoVideoSyncEnabled); stream.MarkGlobalSyncOption(SqmGlobalSyncOptions.AllPhotos, rules.SyncAllPhotosVideos); stream.MarkGlobalSyncOption(SqmGlobalSyncOptions.IncludeVideos, rules.SyncIncludeVideos); stream.MarkGlobalSyncOption(SqmGlobalSyncOptions.VideosEnabled, rules.IsTVMoviesSyncEnabled); stream.MarkGlobalSyncOption(SqmGlobalSyncOptions.AllVideos, rules.SyncAllTvMovies); stream.MarkGlobalSyncOption(SqmGlobalSyncOptions.PodcastsEnabled, rules.IsPodcastSyncEnabled); stream.MarkGlobalSyncOption(SqmGlobalSyncOptions.PodcastSyncAll, rules.SyncAllPodcasts); stream.MarkGlobalSyncOption(SqmGlobalSyncOptions.MusicEnabled, rules.IsMusicSyncEnabled); switch (rules.PodcastSyncCount) { case 1: if (!rules.SyncUnplayedPodcastsOnly) { stream.MarkGlobalSyncOption(SqmGlobalSyncOptions.PodcastSync1MostRecent, true); return; } stream.MarkGlobalSyncOption(SqmGlobalSyncOptions.PodcastSync1Unplayed, true); return; case 3: if (!rules.SyncUnplayedPodcastsOnly) { stream.MarkGlobalSyncOption(SqmGlobalSyncOptions.PodcastSync3MostRecent, true); return; } stream.MarkGlobalSyncOption(SqmGlobalSyncOptions.PodcastSync3Unplayed, true); return; case 5: if (!rules.SyncUnplayedPodcastsOnly) { stream.MarkGlobalSyncOption(SqmGlobalSyncOptions.PodcastSync5MostRecent, true); return; } stream.MarkGlobalSyncOption(SqmGlobalSyncOptions.PodcastSync5Unplayed, true); return; } if (rules.SyncUnplayedPodcastsOnly) { stream.MarkGlobalSyncOption(SqmGlobalSyncOptions.PodcastSyncAllUnplayed, true); } else { stream.MarkGlobalSyncOption(SqmGlobalSyncOptions.PodcastSyncAll, true); } }
private static void CalculateSyncResults(ISyncPartnership partnership, SqmSyncContentStream stream) { long? nullable; double num = 0.0; double num2 = 0.0; uint num3 = 0; List <SyncOperation> list = new List <SyncOperation>(partnership.AttemptedSyncOperations); stream.AttemptedFileCount = (uint)list.Count; foreach (SyncOperation operation in list) { int?nullable2 = operation.Item.Properties.NullableIntForKey("Size"); nullable = nullable2.HasValue ? new long?((long)nullable2.GetValueOrDefault()) : null; if (nullable.HasValue && (operation.OperationType != SyncOperationType.Delete)) { num += (double)nullable.Value; } } stream.AttemptedFileSize = (uint)(num / 1000000.0); num = 0.0; List <SyncOperation> list2 = new List <SyncOperation>(partnership.SuccessfulSyncOperations); stream.SuccessfulFileCount = (uint)list2.Count; foreach (SyncOperation operation2 in list2) { int?nullable4 = operation2.Item.Properties.NullableIntForKey("Size"); nullable = nullable4.HasValue ? new long?((long)nullable4.GetValueOrDefault()) : null; if (nullable.HasValue) { if (operation2.OperationType == SyncOperationType.Delete) { num2 += (double)nullable.Value; } else { num += (double)nullable.Value; } } if (operation2.OperationType == SyncOperationType.DeferredTransferTo) { num3++; } MarkFileType(operation2.Item, stream); } stream.SuccessfulFileSize = (uint)(num / 1000000.0); stream.DeletedFileSize = (uint)(num2 / 1000000.0); stream.SuccessfulTranscodedFileCount = num3; }
private void CalculatePhotoSyncSelections(IPictureSyncSource source, ISyncRules rules, SqmSyncContentStream stream) { uint num = 0; uint num2 = 0; if (rules.IsPhotoVideoSyncEnabled) { int num3; if (rules.SyncAllPhotosVideos) { num = (uint) source.PhotoVideoAlbums.Options.Count<ISyncSelectionOption>(); } else { num = (uint) this.CountTreeItemsFullySelected(source.PhotoVideoAlbums); } num2 = (uint) this.CountTreeItemsSelected(source.PhotoVideoAlbums, out num3); } stream.PhotoTreeSelectedCount = num; stream.PhotoFolderSelectedCount = num2; }
private static void SetSyncType(ISyncPartnership partnership, SyncStartType type, SqmSyncContentStream stream) { if (partnership.IsFirstSync) { stream.SyncType = SqmSyncType.FirstTimeSync; } else { switch (type) { case SyncStartType.AutoSync: stream.SyncType = SqmSyncType.AutoSync; return; case SyncStartType.ManualSync: stream.SyncType = SqmSyncType.ManualSync; return; case SyncStartType.Delete: stream.SyncType = SqmSyncType.Delete; return; case SyncStartType.CopyToPC: stream.SyncType = SqmSyncType.CopyToPC; return; case SyncStartType.SendRingtones: stream.SyncType = SqmSyncType.Ringtones; return; } } }
private static void MarkFileType(ISyncable item, SqmSyncContentStream stream) { string localPath = null; if (item.OriginalLocation != null) { localPath = item.OriginalLocation.LocalPath; } if (string.IsNullOrEmpty(localPath)) { localPath = (string) item.Properties.FirstObjectForKeys(new string[] { ZMEDIAITEM_STRINGATTRIBUTE.ZMEDIAITEM_ATTRIBUTE_FILEPATH.ToString(), "DevicePath" }); } if (string.IsNullOrEmpty(localPath)) { localPath = (string) item.Properties.ObjectForKey("Location"); } string extension = Path.GetExtension(localPath); if (extension != null) { switch (extension.ToUpperInvariant()) { case ".JPG": case ".JPEG": stream.MarkFileType(SqmFileTypes.jpg, true); return; case ".PNG": stream.MarkFileType(SqmFileTypes.png, true); return; case ".GIF": stream.MarkFileType(SqmFileTypes.gif, true); return; case ".MP3": stream.MarkFileType(SqmFileTypes.mp3, true); return; case ".WMA": stream.MarkFileType(SqmFileTypes.wma, true); return; case ".AAC": stream.MarkFileType(SqmFileTypes.aac, true); return; case ".MP4": stream.MarkFileType(SqmFileTypes.mp4, true); return; case ".WMV": stream.MarkFileType(SqmFileTypes.wmv, true); return; case ".M4R": stream.MarkFileType(SqmFileTypes.m4r, true); return; } stream.MarkFileType(SqmFileTypes.other, true); } }
private static void CalculateSyncResults(ISyncPartnership partnership, SqmSyncContentStream stream) { long? nullable; double num = 0.0; double num2 = 0.0; uint num3 = 0; List<SyncOperation> list = new List<SyncOperation>(partnership.AttemptedSyncOperations); stream.AttemptedFileCount = (uint) list.Count; foreach (SyncOperation operation in list) { int? nullable2 = operation.Item.Properties.NullableIntForKey("Size"); nullable = nullable2.HasValue ? new long?((long) nullable2.GetValueOrDefault()) : null; if (nullable.HasValue && (operation.OperationType != SyncOperationType.Delete)) { num += (double) nullable.Value; } } stream.AttemptedFileSize = (uint) (num / 1000000.0); num = 0.0; List<SyncOperation> list2 = new List<SyncOperation>(partnership.SuccessfulSyncOperations); stream.SuccessfulFileCount = (uint) list2.Count; foreach (SyncOperation operation2 in list2) { int? nullable4 = operation2.Item.Properties.NullableIntForKey("Size"); nullable = nullable4.HasValue ? new long?((long) nullable4.GetValueOrDefault()) : null; if (nullable.HasValue) { if (operation2.OperationType == SyncOperationType.Delete) { num2 += (double) nullable.Value; } else { num += (double) nullable.Value; } } if (operation2.OperationType == SyncOperationType.DeferredTransferTo) { num3++; } MarkFileType(operation2.Item, stream); } stream.SuccessfulFileSize = (uint) (num / 1000000.0); stream.DeletedFileSize = (uint) (num2 / 1000000.0); stream.SuccessfulTranscodedFileCount = num3; }
private static void CalculateMusicSyncSelections(IMusicSyncSource source, ISyncRules rules, SqmSyncContentStream stream) { uint num = 0; uint num2 = 0; uint num3 = 0; uint num4 = 0; uint num5 = 0; uint num6 = 0; if (rules.IsMusicSyncEnabled) { if (rules.SyncAllMusic) { num = (uint) source.Playlists.Options.Count<ISyncSelectionOption>(); num2 = (uint) source.Genres.Options.Count<ISyncSelectionOption>(); num3 = (uint) source.Artists.Options.Count<ISyncSelectionOption>(); num4 = 0; } else { num = (uint) source.Playlists.Options.Where<ISyncSelectionOption>(delegate (ISyncSelectionOption o) { if (o.IsSelectedForSync.HasValue) { return o.IsSelectedForSync.Value; } return false; }).Count<ISyncSelectionOption>(); num2 = (uint) source.Genres.Options.Where<ISyncSelectionOption>(delegate (ISyncSelectionOption o) { if (o.IsSelectedForSync.HasValue) { return o.IsSelectedForSync.Value; } return false; }).Count<ISyncSelectionOption>(); num3 = (uint) source.Artists.Options.Where<ISyncSelectionOption>(delegate (ISyncSelectionOption o) { if (o.IsSelectedForSync.HasValue) { return o.IsSelectedForSync.Value; } return false; }).Count<ISyncSelectionOption>(); num4 = (uint) (from o in source.Artists.Options where !o.IsSelectedForSync.HasValue select o).Count<ISyncSelectionOption>(); } } if (rules.IsTVMoviesSyncEnabled) { if (rules.SyncAllTvMovies) { num5 = (uint) source.MoviesTVShows.Options.Count<ISyncSelectionOption>(); } else { num5 = (uint) source.MoviesTVShows.Options.Where<ISyncSelectionOption>(delegate (ISyncSelectionOption o) { if (o.IsSelectedForSync.HasValue) { return o.IsSelectedForSync.Value; } return false; }).Count<ISyncSelectionOption>(); } } if (rules.IsPodcastSyncEnabled) { if (rules.SyncAllPodcasts) { num6 = (uint) source.Podcasts.Options.Count<ISyncSelectionOption>(); } else { num6 = (uint) source.Podcasts.Options.Where<ISyncSelectionOption>(delegate (ISyncSelectionOption o) { if (o.IsSelectedForSync.HasValue) { return o.IsSelectedForSync.Value; } return false; }).Count<ISyncSelectionOption>(); } } stream.PlaylistFileSelectedCount = num; stream.GenreFileSelectedCount = num2; stream.ArtistFileSelectedCount = num3; stream.MusicAlbumFileSelectedCount = num4; stream.MovieFileSelectedCount = num5; stream.PodcastSeriesSelectedCount = num6; }
private static void MarkFileType(ISyncable item, SqmSyncContentStream stream) { string localPath = null; if (item.OriginalLocation != null) { localPath = item.OriginalLocation.LocalPath; } if (string.IsNullOrEmpty(localPath)) { localPath = (string)item.Properties.FirstObjectForKeys(new string[] { ZMEDIAITEM_STRINGATTRIBUTE.ZMEDIAITEM_ATTRIBUTE_FILEPATH.ToString(), "DevicePath" }); } if (string.IsNullOrEmpty(localPath)) { localPath = (string)item.Properties.ObjectForKey("Location"); } string extension = Path.GetExtension(localPath); if (extension != null) { switch (extension.ToUpperInvariant()) { case ".JPG": case ".JPEG": stream.MarkFileType(SqmFileTypes.jpg, true); return; case ".PNG": stream.MarkFileType(SqmFileTypes.png, true); return; case ".GIF": stream.MarkFileType(SqmFileTypes.gif, true); return; case ".MP3": stream.MarkFileType(SqmFileTypes.mp3, true); return; case ".WMA": stream.MarkFileType(SqmFileTypes.wma, true); return; case ".AAC": stream.MarkFileType(SqmFileTypes.aac, true); return; case ".MP4": stream.MarkFileType(SqmFileTypes.mp4, true); return; case ".WMV": stream.MarkFileType(SqmFileTypes.wmv, true); return; case ".M4R": stream.MarkFileType(SqmFileTypes.m4r, true); return; } stream.MarkFileType(SqmFileTypes.other, true); } }
private void CalculatePhotoSyncSelections(IPictureSyncSource source, ISyncRules rules, SqmSyncContentStream stream) { uint num = 0; uint num2 = 0; if (rules.IsPhotoVideoSyncEnabled) { int num3; if (rules.SyncAllPhotosVideos) { num = (uint)source.PhotoVideoAlbums.Options.Count <ISyncSelectionOption>(); } else { num = (uint)this.CountTreeItemsFullySelected(source.PhotoVideoAlbums); } num2 = (uint)this.CountTreeItemsSelected(source.PhotoVideoAlbums, out num3); } stream.PhotoTreeSelectedCount = num; stream.PhotoFolderSelectedCount = num2; }
private static void CalculateMusicSyncSelections(IMusicSyncSource source, ISyncRules rules, SqmSyncContentStream stream) { uint num = 0; uint num2 = 0; uint num3 = 0; uint num4 = 0; uint num5 = 0; uint num6 = 0; if (rules.IsMusicSyncEnabled) { if (rules.SyncAllMusic) { num = (uint)source.Playlists.Options.Count <ISyncSelectionOption>(); num2 = (uint)source.Genres.Options.Count <ISyncSelectionOption>(); num3 = (uint)source.Artists.Options.Count <ISyncSelectionOption>(); num4 = 0; } else { num = (uint)source.Playlists.Options.Where <ISyncSelectionOption>(delegate(ISyncSelectionOption o) { if (o.IsSelectedForSync.HasValue) { return(o.IsSelectedForSync.Value); } return(false); }).Count <ISyncSelectionOption>(); num2 = (uint)source.Genres.Options.Where <ISyncSelectionOption>(delegate(ISyncSelectionOption o) { if (o.IsSelectedForSync.HasValue) { return(o.IsSelectedForSync.Value); } return(false); }).Count <ISyncSelectionOption>(); num3 = (uint)source.Artists.Options.Where <ISyncSelectionOption>(delegate(ISyncSelectionOption o) { if (o.IsSelectedForSync.HasValue) { return(o.IsSelectedForSync.Value); } return(false); }).Count <ISyncSelectionOption>(); num4 = (uint)(from o in source.Artists.Options where !o.IsSelectedForSync.HasValue select o).Count <ISyncSelectionOption>(); } } if (rules.IsTVMoviesSyncEnabled) { if (rules.SyncAllTvMovies) { num5 = (uint)source.MoviesTVShows.Options.Count <ISyncSelectionOption>(); } else { num5 = (uint)source.MoviesTVShows.Options.Where <ISyncSelectionOption>(delegate(ISyncSelectionOption o) { if (o.IsSelectedForSync.HasValue) { return(o.IsSelectedForSync.Value); } return(false); }).Count <ISyncSelectionOption>(); } } if (rules.IsPodcastSyncEnabled) { if (rules.SyncAllPodcasts) { num6 = (uint)source.Podcasts.Options.Count <ISyncSelectionOption>(); } else { num6 = (uint)source.Podcasts.Options.Where <ISyncSelectionOption>(delegate(ISyncSelectionOption o) { if (o.IsSelectedForSync.HasValue) { return(o.IsSelectedForSync.Value); } return(false); }).Count <ISyncSelectionOption>(); } } stream.PlaylistFileSelectedCount = num; stream.GenreFileSelectedCount = num2; stream.ArtistFileSelectedCount = num3; stream.MusicAlbumFileSelectedCount = num4; stream.MovieFileSelectedCount = num5; stream.PodcastSeriesSelectedCount = num6; }