Example #1
0
 public void BasicFormattingTests()
 {
     // Ensures that the basic formatting works. The actual details of how the number is converted
     // into a human readable size are implemented by the Win32 API StrFormatByteSizeW. This test ensures
     // that we can call into the API and get a valid result.
     Assert.AreEqual("10 bytes", StringFormatUtils.FormatByteSize(10));
     Assert.AreEqual("1.00 KB", StringFormatUtils.FormatByteSize(1024));
     Assert.AreEqual("1.00 MB", StringFormatUtils.FormatByteSize(1024 * 1024));
     Assert.AreEqual("1.00 GB", StringFormatUtils.FormatByteSize(1024 * 1024 * 1024));
 }
Example #2
0
        private void OnUpdateUI()
        {
            if (StatisticsSelected)
            {
                PackageDiscardedWarning = false;

                TotalReceived = StringFormatUtils.GetSizeAsString(_rateMonitor.TotalReceivedBytes);
                RateReceive   = StringFormatUtils.GetRateAsString(_rateMonitor.CurrentReceiveRate) + " (" + StringFormatUtils.GetSizeAsString(_rateMonitor.CurrentReceiveRate / 8) + "/s)";
                TotalSent     = StringFormatUtils.GetSizeAsString(_rateMonitor.TotalSentBytes);
                RateSend      = StringFormatUtils.GetRateAsString(_rateMonitor.CurrentSendRate) + " (" + StringFormatUtils.GetSizeAsString(_rateMonitor.CurrentSendRate / 8) + "/s)";;

                // dont update conversation view if more than 100kbps
                // is received and view not selected.
                if (_rateMonitor.CurrentReceiveRate > 100000)
                {
                    return;
                }
            }
            else
            {
                PackageDiscardedWarning = ((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - _lastPackageDiscarded) < 10000;
            }

            _conversation.BeginBatch();

            Transmission msg;

            while (_incomingQueue.TryTake(out msg))
            {
                _conversation.Add(new ConversationItemViewModel(msg, _formatter));
            }

            while (_conversation.Count > _incomingQueue.BoundedCapacity)
            {
                _conversation.RemoveAt(0);
            }

            _conversation.EndBatch();
        }
 /// <summary>
 /// Takes in the <paramref name="size"/> and returns a human readable version of the size
 /// with the KB, MB, etc... suffix.
 /// </summary>
 private static string FormatSize(ulong size)
 {
     return(StringFormatUtils.FormatByteSize(size));
 }
Example #4
0
        protected override void OnEntitiesChanged(object key, Type changedType, EntityMessageType messageType, object sender)
        {
            if (sender == MainViewModel)
            {
                return;
            }

            if (loadPROJECT != null && changedType == typeof(BluePrints.Data.PROJECT) && loadPROJECT.GUID.ToString() == key.ToString())
            {
                if (messageType == EntityMessageType.Added)
                {
                    MessageBoxService.ShowMessage(string.Format(CommonResources.Notify_View_Restored, StringFormatUtils.GetEntityNameByType(changedType)));
                }
                else if (messageType == EntityMessageType.Deleted)
                {
                    MessageBoxService.ShowMessage(string.Format(CommonResources.Notify_View_Removed, StringFormatUtils.GetEntityNameByType(changedType)));
                }
            }

            if (loadPROJECT != null)
            {
                if (MainViewModel != null)
                {
                    mainThreadDispatcher.BeginInvoke(new Action(() => MainViewModel.Refresh()));
                }
                else if (loadPROJECT != null)
                {
                    mainThreadDispatcher.BeginInvoke(new Action(() => InitializeAndLoadEntitiesLoaderDescription()));
                }
            }
        }
Example #5
0
        protected override void OnEntitiesChanged(object key, Type changedType, EntityMessageType messageType, object sender)
        {
            //Map the changes from PROGRESS_ITEM to BASELINE_ITEM so undo/redo operation is valid
            if (changedType == typeof(PROGRESS_ITEM))
            {
                PROGRESS_ITEMProjection mappedEntity = MainViewModel.Entities.FirstOrDefault(x => x.PROGRESS_ITEMCurrent != null && x.PROGRESS_ITEMCurrent.GUID.ToString() == key.ToString());
                mainThreadDispatcher.BeginInvoke(new Action(() => Messenger.Default.Send(new EntityMessage <BASELINE_ITEM, Guid>(mappedEntity.GUID, EntityMessageType.Changed, this))));
                return;
            }

            if (sender == this)
            {
                return;
            }

            if (loadPROGRESS != null && changedType == typeof(PROGRESS) && loadPROGRESS.GUID.ToString() == key.ToString() ||
                loadBASELINE != null && changedType == typeof(BASELINE) && loadBASELINE.GUID.ToString() == key.ToString() ||
                loadPROJECT != null && changedType == typeof(BluePrints.Data.PROJECT) && loadPROJECT.GUID.ToString() == key.ToString())
            {
                if (messageType == EntityMessageType.Added)
                {
                    MessageBoxService.ShowMessage(string.Format(CommonResources.Notify_View_Restored, StringFormatUtils.GetEntityNameByType(changedType)));
                }
                else if (messageType == EntityMessageType.Deleted)
                {
                    MessageBoxService.ShowMessage(string.Format(CommonResources.Notify_View_Removed, StringFormatUtils.GetEntityNameByType(changedType)));
                }
            }

            if (loadPROJECT != null || loadBASELINE != null || loadPROGRESS != null)
            {
                if (MainViewModel != null)
                {
                    mainThreadDispatcher.BeginInvoke(new Action(() => MainViewModel.Refresh()));
                }
                else if (loadPROJECT != null || loadBASELINE != null)
                {
                    mainThreadDispatcher.BeginInvoke(new Action(() => InitializeAndLoadEntitiesLoaderDescription()));
                }
            }
        }