Ejemplo n.º 1
0
        /// <summary>
        /// During an active sync job, this methods is invoked on progress changed (aka when a change is detected).
        /// </summary>
        /// <param name="sender">The sender</param>
        /// <param name="syncJobProgressInfo">The progressInfo object</param>
        private void RestoreJobOnProgressChanged(object sender, RestoreJobProgressInfo syncJobProgressInfo)
        {
            App.Current.Dispatcher.Invoke(() =>
            {
                if (!double.IsInfinity(syncJobProgressInfo.ProgressValue))
                {
                    this.ShowDiscreteProgress = true;

                    this.ProgressValue = syncJobProgressInfo.ProgressValue;

                    this.BytesCompleted = syncJobProgressInfo.BytesCompleted;
                    this.BytesRemaining = syncJobProgressInfo.BytesTotal - syncJobProgressInfo.BytesCompleted;

                    this.FilesCompleted = syncJobProgressInfo.FilesCompleted;
                    this.FilesRemaining = syncJobProgressInfo.FilesTotal - syncJobProgressInfo.FilesCompleted;

                    this.TimeElapsed = DateTime.Now.Subtract(this.StartTime);

                    if (syncJobProgressInfo.BytesPerSecond > 0)
                    {
                        this.TimeRemaining = TimeSpan.FromSeconds(
                            this.BytesRemaining / syncJobProgressInfo.BytesPerSecond);
                    }
                    else
                    {
                        this.TimeRemaining = TimeSpan.Zero;
                    }

                    this.Throughput = FileSizeConverter.Convert(syncJobProgressInfo.BytesPerSecond, 2) + " per second";
                }
            });
        }
        public SettingsStorageOptimizationPage(IProtoService protoService, ContentDialogBase dialog, StorageStatisticsByChat statistics)
        {
            InitializeComponent();

            _dialog = dialog;

            var chat = protoService.GetChat(statistics.ChatId);

            Title.Text    = chat == null ? "Other Chats" : protoService.GetTitle(chat);
            Subtitle.Text = FileSizeConverter.Convert(statistics.Size);

            Photo.Source     = chat == null ? null : PlaceholderHelper.GetChat(protoService, chat, 36, 36);
            Photo.Visibility = chat == null ? Visibility.Collapsed : Visibility.Visible;

            List.ItemsSource = statistics.ByFileType.OrderByDescending(x => x.Size).ToList();

            foreach (var fileType in statistics.ByFileType)
            {
                switch (fileType.FileType)
                {
                case FileTypeAnimation animation:
                case FileTypeAudio audio:
                case FileTypeDocument document:
                case FileTypeNone none:
                case FileTypePhoto photo:
                case FileTypeUnknown unknown:
                case FileTypeVideo video:
                case FileTypeVideoNote videoNote:
                case FileTypeVoiceNote voiceNote:
                    List.SelectedItems.Add(fileType);
                    break;
                }
            }
        }
Ejemplo n.º 3
0
        private void UpdateEditedVideoParameters()
        {
            var minLength   = Math.Min(Width, Height);
            var scaleFactor = SelectedQuality != null && SelectedQuality.Seconds != 0 ? SelectedQuality.Seconds / minLength : 1.0;
            var duration    = GetEditedDuration(TrimLeft, TrimRight, Duration);

            _editedBitrate = SetEditedBitrate();

            if (IsMuteEnabled)    // gif
            {
                EditedSize = (ulong)(_editedBitrate * duration.TotalSeconds) / 8;
            }
            else if (SelectedQuality != null && SelectedQuality.Seconds > 0)    // compressed quality
            {
                EditedSize = (ulong)(_editedBitrate * duration.TotalSeconds) / 8;
            }
            else    // default quality
            {
                EditedSize = (ulong)(Size / Duration.TotalSeconds * duration.TotalSeconds);
            }

            var editedSizeString = FileSizeConverter.Convert((long)EditedSize);

            _editedHeight = (uint)(Height * scaleFactor);
            _editedWidth  = (uint)(Width * scaleFactor);
            if (_encodingProfile != null)
            {
                _encodingProfile.Video.Height = _properties.Item2.Orientation == VideoOrientation.Normal || _properties.Item2.Orientation == VideoOrientation.Rotate180? _editedHeight : _editedWidth;
                _encodingProfile.Video.Width  = _properties.Item2.Orientation == VideoOrientation.Normal || _properties.Item2.Orientation == VideoOrientation.Rotate180 ? _editedWidth : _editedHeight;
            }

            EditedVideoParameters = string.Format("{0}x{1}, {2}, ~{3}", _editedWidth, _editedHeight, GetDurationString(duration), editedSizeString);
        }
Ejemplo n.º 4
0
 public void RefreshReferenceLabel()
 {
     if (this.Reference != null)
     {
         if (this.Property == FileProperty.ContainsTag)
         {
             this.ReferenceLabel = LibraryOwner.GetCurrent()
                                   .Tags.GetTagValue((int)this.Reference)?.Name;
         }
         else if (this.Property.IsDate())
         {
             if (this.Property == FileProperty.DateTimeCreated ||
                 this.Property == FileProperty.DateTimeModified ||
                 this.Property == FileProperty.DateTimeRegistered)
             {
                 this.ReferenceLabel = ((DateTimeOffset)this.Reference).ToString("G");
             }
             else
             {
                 this.ReferenceLabel = ((DateTimeOffset)this.Reference).ToString("d");
             }
         }
         else if (this.Property == FileProperty.Size)
         {
             this.ReferenceLabel = FileSizeConverter.ConvertAuto((long)this.Reference);
         }
         else
         {
             this.ReferenceLabel = this.Reference.ToString();
         }
     }
 }
Ejemplo n.º 5
0
        public void Mockup(MessageAudio audio)
        {
            Title.Text    = audio.Audio.GetTitle();
            Subtitle.Text = audio.Audio.GetDuration() + ", " + FileSizeConverter.Convert(4190000);

            Button.SetGlyph(0, MessageContentState.Download);
        }
Ejemplo n.º 6
0
        public CacheViewModel(ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator)
            : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator)
        {
            EventAggregator.Subscribe(this);

            Spans = new List <TimerSpan>
            {
                new TimerSpan(AppResources.WeekNominativeSingular, "1", (int)TimeSpan.FromDays(7.0).TotalSeconds, string.Format("{0} {1}", "1", AppResources.WeekNominativeSingular).ToLowerInvariant()),
                new TimerSpan(AppResources.MonthNominativeSingular, "1", (int)TimeSpan.FromDays(30.0).TotalSeconds, string.Format("{0} {1}", "1", AppResources.MonthNominativeSingular).ToLowerInvariant()),
                new TimerSpan(AppResources.Forever, string.Empty, int.MaxValue, AppResources.Forever),
            };
            _selectedSpan = Spans[2];


            Files = new ObservableCollection <TelegramFileInfo>();

            _timer.Interval = TimeSpan.FromSeconds(30.0);
            _timer.Tick    += OnTimerTick;

            CalculateCacheSizeAsync((size1, size2) => BeginOnUIThread(() =>
            {
                Status = FileSizeConverter.Convert(size1);
                LocalDatabaseStatus = FileSizeConverter.Convert(size2);
                _settings.NotifyOfPropertyChange(() => _settings.Self);
            }));

            PropertyChanged += (sender, e) =>
            {
                if (Property.NameEquals(e.PropertyName, () => IsWorking))
                {
                    NotifyOfPropertyChange(() => CanClearCache);
                }
            };
        }
Ejemplo n.º 7
0
        public void ClearLocalDatabase()
        {
            var result = MessageBox.Show(AppResources.ClearLocalDatabaseConfirmation, AppResources.Confirm, MessageBoxButton.OKCancel);

            if (result == MessageBoxResult.OK)
            {
                IsWorking = true;
                CacheService.CompressAsync(() =>
                {
                    long newLength;
                    using (var store = IsolatedStorageFile.GetUserStoreForApplication())
                    {
                        var files = new List <TelegramFileInfo>();
                        newLength = GetDatabaseLength(store, files);
                    }

                    BeginOnUIThread(() =>
                    {
                        IsWorking           = false;
                        LocalDatabaseStatus = FileSizeConverter.Convert(newLength);

                        EventAggregator.Publish(new ClearLocalDatabaseEventArgs());
                    });
                });
            }
        }
Ejemplo n.º 8
0
        private void UpdatePlayback(MessageViewModel message, Audio audio, File file)
        {
            if (message.IsEqualTo(message.PlaybackService.CurrentItem))
            {
                if (message.PlaybackService.PlaybackState == MediaPlaybackState.Paused)
                {
                    Button.SetGlyph(file.Id, MessageContentState.Play);
                }
                else
                {
                    Button.SetGlyph(file.Id, MessageContentState.Pause);
                }

                UpdatePosition();

                message.PlaybackService.PlaybackStateChanged += OnPlaybackStateChanged;
                message.PlaybackService.PositionChanged      += OnPositionChanged;
            }
            else
            {
                Button.SetGlyph(file.Id, MessageContentState.Play);
                Button.Progress = 1;

                if (file.Local.CanBeDownloaded && !file.Local.IsFileExisting() && !file.Local.IsDownloadingActive && !file.Remote.IsUploadingActive)
                {
                    Subtitle.Text = audio.GetDuration() + " - " + FileSizeConverter.Convert(Math.Max(file.Size, file.ExpectedSize));
                }
                else
                {
                    Subtitle.Text = audio.GetDuration();
                }
            }

            Button.Progress = 1;
        }
Ejemplo n.º 9
0
        private void UpdatePlayback(Message message, Audio audio, File file)
        {
            if (Equals(message, _playbackService.CurrentItem))
            {
                if (_playbackService.PlaybackState != MediaPlaybackState.Paused && _playbackService.PlaybackState != MediaPlaybackState.None)
                {
                    Button.SetGlyph(file.Id, MessageContentState.Pause);
                }
                else
                {
                    Button.SetGlyph(file.Id, MessageContentState.Play);
                }

                UpdatePosition();

                _playbackService.PositionChanged -= OnPositionChanged;
                _playbackService.PositionChanged += OnPositionChanged;
            }
            else
            {
                Button.SetGlyph(file.Id, MessageContentState.Play);
                Button.Progress = 1;

                if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingCompleted && !file.Local.IsDownloadingActive && !file.Remote.IsUploadingActive)
                {
                    Subtitle.Text = audio.GetDuration() + " - " + FileSizeConverter.Convert(Math.Max(file.Size, file.ExpectedSize));
                }
                else
                {
                    Subtitle.Text = audio.GetDuration();
                }
            }

            Button.Progress = 1;
        }
        private void OnContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args)
        {
            if (args.InRecycleQueue)
            {
                return;
            }

            var check = args.ItemContainer.ContentTemplateRoot as CheckBox;
            var item  = args.Item as StorageChartItem;

            if (item == null)
            {
                return;
            }

            var content = check.Content as StackPanel;

            var title    = content.Children[0] as TextBlock;
            var subtitle = content.Children[1] as TextBlock;

            check.Click -= CheckBox_Click;
            check.Click += CheckBox_Click;

            check.Background = new SolidColorBrush(item.Stroke);
            check.IsChecked  = item.IsVisible;

            check.Tag = item;

            title.Text    = item.Name;
            subtitle.Text = FileSizeConverter.Convert(item.Size, true);
        }
Ejemplo n.º 11
0
        private void UpdateFile(MessageViewModel message, File file)
        {
            var document = GetContent(message.Content);

            if (document == null || !_templateApplied)
            {
                return;
            }

            if (document.DocumentValue.Id != file.Id)
            {
                return;
            }

            var size = Math.Max(file.Size, file.ExpectedSize);

            if (file.Local.IsDownloadingActive)
            {
                Button.SetGlyph(file.Id, MessageContentState.Downloading);
                Button.Progress = (double)file.Local.DownloadedSize / size;

                Subtitle.Text = string.Format("{0} / {1}", FileSizeConverter.Convert(file.Local.DownloadedSize, size), FileSizeConverter.Convert(size));
            }
            else if (file.Remote.IsUploadingActive || message.SendingState is MessageSendingStateFailed)
            {
                Button.SetGlyph(file.Id, MessageContentState.Uploading);
                Button.Progress = (double)file.Remote.UploadedSize / size;

                Subtitle.Text = string.Format("{0} / {1}", FileSizeConverter.Convert(file.Remote.UploadedSize, size), FileSizeConverter.Convert(size));
            }
            else if (file.Local.CanBeDownloaded && !file.Local.IsFileExisting())
            {
                Button.SetGlyph(file.Id, MessageContentState.Download);
                Button.Progress = 0;

                Subtitle.Text = FileSizeConverter.Convert(size);

                if (message.Delegate.CanBeDownloaded(document, file))
                {
                    _message.ProtoService.DownloadFile(file.Id, 32);
                }
            }
            else
            {
                var theme = document.FileName.EndsWith(".unigram-theme");
                if (theme)
                {
                    Button.SetGlyph(file.Id, message.SendingState is MessageSendingStatePending && message.MediaAlbumId != 0 ? MessageContentState.Confirm : MessageContentState.Theme);
                }
                else
                {
                    Button.SetGlyph(file.Id, message.SendingState is MessageSendingStatePending && message.MediaAlbumId != 0 ? MessageContentState.Confirm : MessageContentState.Document);
                }
                Button.Progress = 1;

                Subtitle.Text = FileSizeConverter.Convert(size);
            }
        }
Ejemplo n.º 12
0
        public void UpdateFile(MessageViewModel message, File file)
        {
            var animation = GetContent(message.Content);

            if (animation == null)
            {
                return;
            }

            if (animation.Thumbnail != null && animation.Thumbnail.Photo.Id == file.Id)
            {
                UpdateThumbnail(message, file);
                return;
            }
            else if (animation.AnimationData.Id != file.Id)
            {
                return;
            }

            var size = Math.Max(file.Size, file.ExpectedSize);

            if (file.Local.IsDownloadingActive)
            {
                Button.Glyph    = "\uE10A";
                Button.Progress = (double)file.Local.DownloadedSize / size;

                Subtitle.Text   = string.Format("{0} / {1}", FileSizeConverter.Convert(file.Local.DownloadedSize, size), FileSizeConverter.Convert(size));
                Overlay.Opacity = 1;
            }
            else if (file.Remote.IsUploadingActive)
            {
                Button.Glyph    = "\uE10A";
                Button.Progress = (double)file.Remote.UploadedSize / size;

                Subtitle.Text   = string.Format("{0} / {1}", FileSizeConverter.Convert(file.Remote.UploadedSize, size), FileSizeConverter.Convert(size));
                Overlay.Opacity = 1;
            }
            else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingCompleted)
            {
                Button.Glyph    = "\uE118";
                Button.Progress = 0;

                Subtitle.Text   = Strings.Resources.AttachGif + ", " + FileSizeConverter.Convert(size);
                Overlay.Opacity = 1;

                if (message.Delegate.CanBeDownloaded(message))
                {
                    _message.ProtoService.Send(new DownloadFile(file.Id, 32));
                }
            }
            else
            {
                Button.Glyph    = "\uE906";
                Button.Progress = 1;

                Overlay.Opacity = 0;
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="value">ChartPoint.Instance (object)</param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value != null && value is LvlChartsDefaultInfo info)
            {
                return($"{FileSizeConverter.GetBytesReadable((long)info.Value * 8)}it/s");
            }

            return("-/-");
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="value">ChartPoint.Instance (object)</param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value != null && value is BandwidthInfo info)
            {
                return($"{FileSizeConverter.GetBytesReadable(info.Value * 8)}it/s");
            }

            return("-/-");
        }
Ejemplo n.º 15
0
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var num = MathExtensions.ToLong(value);

            if (num == null)
            {
                return(null);
            }
            return(FileSizeConverter.ConvertAuto(num.Value));
        }
Ejemplo n.º 16
0
        public void UpdateFile(MessageViewModel message, File file)
        {
            var document = GetContent(message.Content);

            if (document == null)
            {
                return;
            }

            if (document.Thumbnail != null && document.Thumbnail.Photo.Id == file.Id)
            {
                UpdateThumbnail(message, file);
                return;
            }
            else if (document.DocumentData.Id != file.Id)
            {
                return;
            }

            var size = Math.Max(file.Size, file.ExpectedSize);

            if (file.Local.IsDownloadingActive)
            {
                Button.Glyph    = "\uE10A";
                Button.Progress = (double)file.Local.DownloadedSize / size;

                Subtitle.Text = string.Format("{0} / {1}", FileSizeConverter.Convert(file.Local.DownloadedSize, size), FileSizeConverter.Convert(size));
            }
            else if (file.Remote.IsUploadingActive)
            {
                Button.Glyph    = "\uE10A";
                Button.Progress = (double)file.Remote.UploadedSize / size;

                Subtitle.Text = string.Format("{0} / {1}", FileSizeConverter.Convert(file.Remote.UploadedSize, size), FileSizeConverter.Convert(size));
            }
            else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingCompleted)
            {
                Button.Glyph    = "\uE118";
                Button.Progress = 0;

                Subtitle.Text = FileSizeConverter.Convert(size);

                if (message.Delegate.CanBeDownloaded(message))
                {
                    _message.ProtoService.Send(new DownloadFile(file.Id, 32));
                }
            }
            else
            {
                Button.Glyph    = "\uE160";
                Button.Progress = 1;

                Subtitle.Text = FileSizeConverter.Convert(size);
            }
        }
Ejemplo n.º 17
0
        public void UpdateFile(MessageViewModel message, File file)
        {
            var audio = GetContent(message.Content);

            if (audio == null)
            {
                return;
            }

            if (audio.AlbumCoverThumbnail != null && audio.AlbumCoverThumbnail.Photo.Id == file.Id)
            {
                UpdateThumbnail(message, file);
                return;
            }
            else if (audio.AudioValue.Id != file.Id)
            {
                return;
            }

            var size = Math.Max(file.Size, file.ExpectedSize);

            if (file.Local.IsDownloadingActive)
            {
                Button.Glyph    = "\uE10A";
                Button.Progress = (double)file.Local.DownloadedSize / size;

                Subtitle.Text = string.Format("{0} / {1}", FileSizeConverter.Convert(file.Local.DownloadedSize, size), FileSizeConverter.Convert(size));
            }
            else if (file.Remote.IsUploadingActive || message.SendingState is MessageSendingStateFailed)
            {
                Button.Glyph    = "\uE10A";
                Button.Progress = (double)file.Remote.UploadedSize / size;

                Subtitle.Text = string.Format("{0} / {1}", FileSizeConverter.Convert(file.Remote.UploadedSize, size), FileSizeConverter.Convert(size));
            }
            else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingCompleted)
            {
                Button.Glyph    = "\uE118";
                Button.Progress = 0;

                Subtitle.Text = audio.GetDuration() + ", " + FileSizeConverter.Convert(size);

                if (message.Delegate.CanBeDownloaded(message))
                {
                    _message.ProtoService.Send(new DownloadFile(file.Id, 32));
                }
            }
            else
            {
                Button.Glyph    = "\uE102";
                Button.Progress = 1;

                Subtitle.Text = audio.GetDuration();
            }
        }
Ejemplo n.º 18
0
        public void UpdateFile(Message message, File file)
        {
            var data = message.GetFileAndThumbnailAndName(false);

            if (data.File == null)
            {
                return;
            }

            if (data.Thumbnail != null && data.Thumbnail.File.Id == file.Id)
            {
                UpdateThumbnail(message, data.Thumbnail, file);
                return;
            }
            else if (data.File.Id != file.Id)
            {
                return;
            }

            var size = Math.Max(file.Size, file.ExpectedSize);

            if (file.Local.IsDownloadingActive)
            {
                //Button.Glyph = Icons.Cancel;
                Button.SetGlyph(file.Id, MessageContentState.Downloading);
                Button.Progress = (double)file.Local.DownloadedSize / size;

                Subtitle.Text = string.Format("{0} / {1}", FileSizeConverter.Convert(file.Local.DownloadedSize, size), FileSizeConverter.Convert(size));
            }
            else if (file.Remote.IsUploadingActive)
            {
                //Button.Glyph = Icons.Cancel;
                Button.SetGlyph(file.Id, MessageContentState.Uploading);
                Button.Progress = (double)file.Remote.UploadedSize / size;

                Subtitle.Text = string.Format("{0} / {1}", FileSizeConverter.Convert(file.Remote.UploadedSize, size), FileSizeConverter.Convert(size));
            }
            else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingCompleted)
            {
                //Button.Glyph = Icons.Download;
                Button.SetGlyph(file.Id, MessageContentState.Download);
                Button.Progress = 0;

                Subtitle.Text = FileSizeConverter.Convert(size) + " — " + UpdateTimeLabel(message);
            }
            else
            {
                //Button.Glyph = Icons.Document;
                Button.SetGlyph(file.Id, MessageContentState.Document);
                Button.Progress = 1;

                Subtitle.Text = FileSizeConverter.Convert(size) + " — " + UpdateTimeLabel(message);
            }
        }
Ejemplo n.º 19
0
        private void OnTimerTick(object sender, System.EventArgs e)
        {
            if (_isCalculating)
            {
                return;
            }

            CalculateCacheSizeAsync(result =>
            {
                Status = FileSizeConverter.Convert(result);
            });
        }
Ejemplo n.º 20
0
        private void OnTimerTick(object sender, System.EventArgs e)
        {
            if (_isCalculating)
            {
                return;
            }

            CalculateCacheSizeAsync((result1, result2) => BeginOnUIThread(() =>
            {
                Status = FileSizeConverter.Convert(result1);
                LocalDatabaseStatus = FileSizeConverter.Convert(result2);
                _settings.NotifyOfPropertyChange(() => _settings.Self);
            }));
        }
Ejemplo n.º 21
0
        private void OnContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args)
        {
            if (args.InRecycleQueue)
            {
                return;
            }

            var content    = args.ItemContainer.ContentTemplateRoot as Grid;
            var statistics = args.Item as StorageStatisticsByChat;

            var chat = ViewModel.ProtoService.GetChat(statistics.ChatId);

            //if (chat == null)
            //{
            //    return;
            //}

            if (args.Phase == 0)
            {
                var title = content.Children[1] as TextBlock;
                title.Text = chat == null ? "Other Chats" : ViewModel.ProtoService.GetTitle(chat);
            }
            else if (args.Phase == 1)
            {
                var subtitle = content.Children[2] as TextBlock;
                subtitle.Text = FileSizeConverter.Convert(statistics.Size, true);
            }
            else if (args.Phase == 2)
            {
                var photo = content.Children[0] as ProfilePicture;
                if (chat == null)
                {
                    photo.Source     = null;
                    photo.Visibility = Visibility.Collapsed;
                }
                else
                {
                    photo.SetChat(ViewModel.ProtoService, chat, 36);
                    photo.Visibility = Visibility.Visible;
                }
            }

            if (args.Phase < 2)
            {
                args.RegisterUpdateCallback(OnContainerContentChanging);
            }

            args.Handled = true;
        }
Ejemplo n.º 22
0
        private void FillingList()
        {
            FileSizeConverter fileSizeConverter = new FileSizeConverter();

            foreach (string sFileName in fileDialog.FileNames)
            {
                videoDataTempleteList.Add(new VideoDataTemplete()
                {
                    Directory    = sFileName,
                    VideoName    = RemoveSlash(sFileName),
                    Size         = fileSizeConverter.FileSizeConvert(new FileInfo(sFileName).Length),
                    CreationTime = new FileInfo(sFileName).CreationTime
                });
            }
            IListViewIndex.FillingListView(DataListView, videoDataTempleteList);
        }
Ejemplo n.º 23
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            PlayStickers.IsOn  = SettingsService.Current.Diagnostics.PlayStickers;
            CacheStickers.IsOn = SettingsService.Current.Diagnostics.CacheStickers;

            Verbosity.Badge = Enum.GetName(typeof(VerbosityLevel), (VerbosityLevel)SettingsService.Current.VerbosityLevel);

            try
            {
                var log = new System.IO.FileInfo(System.IO.Path.Combine(ApplicationData.Current.LocalFolder.Path, "log"));
                Log.Badge = FileSizeConverter.Convert(log.Length);
            }
            catch { }

            try
            {
                var logold = new System.IO.FileInfo(System.IO.Path.Combine(ApplicationData.Current.LocalFolder.Path, "log.old"));
                LogOld.Badge = FileSizeConverter.Convert(logold.Length);
            }
            catch { }

            UseTestDC.IsOn = SettingsService.Current.UseTestDC;



            var cache      = TLContainer.Current.Resolve <ICacheService>();
            var properties = typeof(IOptionsService).GetProperties();

            foreach (var prop in properties)
            {
                if (string.Equals(prop.Name, "Values", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                Options.Items.Add(new BadgeButton {
                    Content = prop.Name, Badge = prop.GetValue(cache.Options)
                });
            }

            foreach (var value in cache.Options.Values)
            {
                Options.Items.Add(new BadgeButton {
                    Content = value.Key, Badge = value.Value
                });
            }
        }
Ejemplo n.º 24
0
        public EditVideoViewModel(ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator)
            : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator)
        {
            VideoFile = StateService.VideoFile;
            StateService.VideoFile = null;

            IsCompressionEnabled = true;
            NotifyOfPropertyChange(() => IsCompressionEnabled);

            BeginOnThreadPool(async() =>
            {
                var properties      = await VideoFile.GetBasicPropertiesAsync();
                var videoProperties = await VideoFile.Properties.GetVideoPropertiesAsync();

                Size     = properties.Size;
                Duration = videoProperties.Duration.TotalSeconds;
                Width    = videoProperties.Width;
                Height   = videoProperties.Height;

                DurationString = GetDurationString(videoProperties.Duration);
                NotifyOfPropertyChange(() => DurationString);
                var originalSizeString = FileSizeConverter.Convert((long)properties.Size);

                OriginalVideoParameters = string.Format("{0}x{1}, {2}, {3}", videoProperties.Width, videoProperties.Height, DurationString, originalSizeString);
                NotifyOfPropertyChange(() => OriginalVideoParameters);

                var maxLength   = Math.Max(videoProperties.Width, videoProperties.Height);
                var scaleFactor = maxLength > 640.0 ? 640.0 / maxLength : 1.0;
                if (scaleFactor == 1.0)
                {
                    IsCompressionEnabled = false;
                    NotifyOfPropertyChange(() => IsCompressionEnabled);
                    Compression = false;
                }

                EditedSize           = (ulong)(properties.Size * scaleFactor * scaleFactor);
                var editedSizeString = FileSizeConverter.Convert((long)EditedSize);
                var editedHeight     = videoProperties.Height * scaleFactor;
                var editedWidth      = videoProperties.Width * scaleFactor;

                EditedVideoParameters = string.Format("{0}x{1}, {2}, ~{3}", editedWidth, editedHeight, DurationString, editedSizeString);
                NotifyOfPropertyChange(() => EditedVideoParameters);

                ThumbPhoto = await GetFileThumbAsync(VideoFile);
                NotifyOfPropertyChange(() => ThumbPhoto);
            });
        }
Ejemplo n.º 25
0
        public void ClearCache()
        {
            if (IsWorking)
            {
                return;
            }

            IsWorking = true;
            BeginOnThreadPool(() =>
            {
                var length = 0L;
                using (var store = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    var fileNames = store.GetFileNames();
                    foreach (var fileName in fileNames)
                    {
                        if (IsValidCacheFileName(fileName))
                        {
                            try
                            {
                                store.DeleteFile(fileName);
                            }
                            catch (Exception ex)
                            {
                                TLUtils.WriteException(ex);
                            }
                        }
                        //else
                        //{
                        //    try
                        //    {
                        //        using (var file = store.OpenFile(fileName, FileMode.Open, FileAccess.Read))
                        //        {
                        //            length += file.Length;
                        //        }
                        //    }
                        //    catch (Exception ex)
                        //    {
                        //        TLUtils.WriteException(ex);
                        //    }
                        //}
                    }
                }
                Status    = FileSizeConverter.Convert(length);
                IsWorking = false;
            });
        }
Ejemplo n.º 26
0
        public void UpdateFile(Message message, File file)
        {
            var document = message.Content as MessageDocument;

            if (document == null)
            {
                return;
            }

            if (document.Document.DocumentValue.Id != file.Id)
            {
                return;
            }

            var size = Math.Max(file.Size, file.ExpectedSize);

            if (file.Local.IsDownloadingActive)
            {
                Button.Glyph    = "\uE10A";
                Button.Progress = (double)file.Local.DownloadedSize / size;

                Subtitle.Text = string.Format("{0} / {1}", FileSizeConverter.Convert(file.Local.DownloadedSize, size), FileSizeConverter.Convert(size));
            }
            else if (file.Remote.IsUploadingActive)
            {
                Button.Glyph    = "\uE10A";
                Button.Progress = (double)file.Remote.UploadedSize / size;

                Subtitle.Text = string.Format("{0} / {1}", FileSizeConverter.Convert(file.Remote.UploadedSize, size), FileSizeConverter.Convert(size));
            }
            else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingCompleted)
            {
                Button.Glyph    = "\uE118";
                Button.Progress = 0;

                Subtitle.Text = FileSizeConverter.Convert(size) + " — " + UpdateTimeLabel(message);
            }
            else
            {
                Button.Glyph    = "\uE160";
                Button.Progress = 1;

                Subtitle.Text = FileSizeConverter.Convert(size) + " — " + UpdateTimeLabel(message);
            }
        }
Ejemplo n.º 27
0
        private void SyncJobOnSyncFinished(object sender, EventArgs eventArgs)
        {
            this.EndTime = this.SyncJob.EndTime.Value;
            this.ItemsCopiedDisplayString =
                string.Format(
                    "{0} files / {1}",
                    this.SyncJob.FilesTotal,
                    FileSizeConverter.Convert(this.SyncJob.BytesTotal, 1));

            // Calculate unchanges files and folders
            this.ChangeMetricsList[0].Unchanged = this.SyncJob.AnalyzeResult.UnchangedFileCount;
            this.ChangeMetricsList[1].Unchanged = this.SyncJob.AnalyzeResult.UnchangedFolderCount;
            this.ChangeMetricsList[2].Unchanged = this.SyncJob.AnalyzeResult.UnchangedFileBytes;

            this.SetStatusDescription();

            this.metadataUpdateCancellationToken.Cancel();
        }
Ejemplo n.º 28
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            Verbosity.Badge = Enum.GetName(typeof(VerbosityLevel), (VerbosityLevel)ApplicationSettings.Current.VerbosityLevel);

            try
            {
                var log = new FileInfo(Path.Combine(ApplicationData.Current.LocalFolder.Path, "log"));
                Log.Badge = FileSizeConverter.Convert(log.Length);
            }
            catch { }

            try
            {
                var logold = new FileInfo(Path.Combine(ApplicationData.Current.LocalFolder.Path, "log.old"));
                LogOld.Badge = FileSizeConverter.Convert(logold.Length);
            }
            catch { }
        }
Ejemplo n.º 29
0
        public SyncJobViewModel(SyncJob syncJob, SyncRelationshipViewModel relationshipViewModel, bool loadFromHistory)
            : base(syncJob, relationshipViewModel)
        {
            this.loadFromHistory = loadFromHistory;

            this.SyncJob.Started         += this.SyncJobOnSyncStarted;
            this.SyncJob.Finished        += this.SyncJobOnSyncFinished;
            this.SyncJob.ProgressChanged += this.SyncJobOnProgressChanged;

            this.SyncJob.TriggerType = SyncTriggerType.Manual;

            this.BeginSyncJobCommand = new DelegatedCommand(o => this.BeginSyncJob());

            this.ChangeMetricsList = new List <ChangeMetrics>()
            {
                new ChangeMetrics("Files"),
                new ChangeMetrics("Folders"),
                new ChangeMetrics("Bytes", true)
            };

            if (syncJob.HasStarted)
            {
                this.StartTime = syncJob.StartTime;
            }

            if (syncJob.HasFinished)
            {
                this.EndTime = syncJob.EndTime ?? DateTime.MinValue;
                this.ItemsCopiedDisplayString = String.Format(
                    "{0} files / {1}",
                    this.SyncJob.FilesTotal,
                    FileSizeConverter.Convert(this.SyncJob.BytesTotal, 1));
                this.Duration = this.EndTime - this.StartTime;
                this.SetStatusDescription();
            }

            if (this.SyncRelationship.State == SyncRelationshipState.Running)
            {
                this.SyncJobOnSyncStarted(this, new EventArgs());
            }
        }
Ejemplo n.º 30
0
        public CacheViewModel(ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator)
            : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator)
        {
            Files = new ObservableCollection <TelegramFileInfo>();

            _timer.Interval = TimeSpan.FromSeconds(5.0);
            _timer.Tick    += OnTimerTick;

            CalculateCacheSizeAsync(size =>
            {
                Status = FileSizeConverter.Convert(size);
            });

            PropertyChanged += (sender, e) =>
            {
                if (Property.NameEquals(e.PropertyName, () => IsWorking))
                {
                    NotifyOfPropertyChange(() => CanClearCache);
                }
            };
        }