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;
                }
            }
        }
예제 #2
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;
        }
예제 #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);
        }
예제 #4
0
        public void Mockup(MessageAudio audio)
        {
            Title.Text    = audio.Audio.GetTitle();
            Subtitle.Text = audio.Audio.GetDuration() + ", " + FileSizeConverter.Convert(4190000);

            Button.SetGlyph(0, MessageContentState.Download);
        }
        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);
        }
예제 #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);
                }
            };
        }
예제 #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());
                    });
                });
            }
        }
예제 #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;
        }
예제 #9
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";
                }
            });
        }
예제 #10
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);
            }
        }
예제 #11
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;
            }
        }
예제 #12
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();
            }
        }
예제 #13
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);
            }
        }
예제 #14
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);
            }
        }
예제 #15
0
        private void OnTimerTick(object sender, System.EventArgs e)
        {
            if (_isCalculating)
            {
                return;
            }

            CalculateCacheSizeAsync(result =>
            {
                Status = FileSizeConverter.Convert(result);
            });
        }
예제 #16
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);
            }));
        }
예제 #17
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;
        }
예제 #18
0
        private LogRecordParts GetLogRecord(IList <string> recordParts)
        {
            var logrecord = new LogRecordParts
            {
                IpAddress      = _ipAddressConverter.Convert(recordParts[0]),
                Hyphen         = _hyphenConverter.Convert(recordParts[1]),
                UserId         = _userIdConverter.Convert(recordParts[2]),
                Date           = _dateConverter.Convert(recordParts[3]),
                RequestLine    = _requestLineConverter.Convert(recordParts[4]),
                CodeDefinition = _codeDefinitionConverter.Convert(recordParts[5]),
                FileSize       = _fileSizeConverter.Convert(recordParts[6])
            };

            return(logrecord);
        }
예제 #19
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;
            });
        }
예제 #20
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
                });
            }
        }
예제 #21
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);
            });
        }
예제 #22
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);
            }
        }
예제 #23
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();
        }
예제 #24
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 { }
        }
예제 #25
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());
            }
        }
예제 #26
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);
                }
            };
        }
예제 #27
0
        public void UpdateEditedVideoDuration()
        {
            var duration = GetEditedDuration(TrimLeft, TrimRight, Duration);

            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);

            EditedVideoParameters = string.Format("{0}x{1}, {2}, ~{3}", _editedWidth, _editedHeight, GetDurationString(duration), editedSizeString);
            NotifyOfPropertyChange(() => EditedVideoParameters);
        }
예제 #28
0
        public void UpdateFileDownloads(UpdateFileDownloads update)
        {
            if (update.TotalSize > 0)
            {
                ShowHide(true);

                Icon.Progress = Math.Max((double)update.DownloadedSize / update.TotalSize, 0.05);
                Count.Text    = Locale.Declension("Files", update.TotalCount);

                if (update.DownloadedSize < update.TotalSize)
                {
                    Size.Text = string.Format("{0} / {1}", FileSizeConverter.Convert(update.DownloadedSize, update.TotalSize), FileSizeConverter.Convert(update.TotalSize));
                }
                else
                {
                    Size.Text = FileSizeConverter.Convert(update.TotalSize);
                }
            }
            else
            {
                ShowHide(false);
            }
        }
        private void CheckBox_Click(object sender, RoutedEventArgs e)
        {
            var check = sender as CheckBox;
            var item  = check.Tag as StorageChartItem;

            var index = Chart.Items.IndexOf(item);

            if (index < 0)
            {
                return;
            }

            if (item.IsVisible && Chart.Items.Except(new[] { item }).Any(x => x.IsVisible))
            {
                item.IsVisible  = false;
                check.IsChecked = false;

                Chart.Update(index, item.IsVisible);
            }
            else if (!item.IsVisible)
            {
                item.IsVisible  = true;
                check.IsChecked = true;

                Chart.Update(index, item.IsVisible);
            }
            else
            {
                VisualUtilities.ShakeView(check);
            }

            var size     = Chart.Items.Where(x => x.IsVisible).Sum(x => x.Size);
            var readable = FileSizeConverter.Convert(size, true).Split(' ');

            SizeLabel.Text = readable[0];
            UnitLabel.Text = readable[1];
        }
예제 #30
0
        public void UpdateFile(Message message, File file)
        {
            _playbackService.PlaybackStateChanged -= OnPlaybackStateChanged;
            _playbackService.PositionChanged      -= OnPositionChanged;

            var voiceNote = GetContent(message.Content);

            if (voiceNote == null)
            {
                return;
            }

            if (voiceNote.Voice.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 || message.SendingState is MessageSendingStateFailed)
            {
                //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 = voiceNote.GetDuration() + ", " + FileSizeConverter.Convert(size);

                //if (message.Delegate.CanBeDownloaded(message))
                //{
                //    _message.ProtoService.DownloadFile(file.Id, 32);
                //}
            }
            else
            {
                if (message.IsEqualTo(_playbackService.CurrentItem))
                {
                    if (_playbackService.PlaybackState == MediaPlaybackState.Paused)
                    {
                        //Button.Glyph = Icons.Play;
                        Button.SetGlyph(file.Id, MessageContentState.Play);
                    }
                    else
                    {
                        //Button.Glyph = Icons.Pause;
                        Button.SetGlyph(file.Id, MessageContentState.Pause);
                    }

                    UpdatePosition();

                    _playbackService.PlaybackStateChanged += OnPlaybackStateChanged;
                    _playbackService.PositionChanged      += OnPositionChanged;
                }
                else
                {
                    //Button.Glyph = Icons.Play;
                    Button.SetGlyph(file.Id, MessageContentState.Play);
                    Button.Progress = 1;

                    Subtitle.Text = voiceNote.GetDuration();
                }

                Button.Progress = 1;
            }
        }