public PackageStatusResponse GetPackageStatusResponse(Hash[] packageIds)
        {
            var packages = new PackageStatusDetail[packageIds.Length];

            for (int i = 0; i < packageIds.Length; i++)
            {
                var  detail = new PackageStatusDetail();
                Hash id     = packageIds[i];
                packages[i] = detail;
                if (!packageRegistry.TryGetPackage(id, out LocalPackageInfo info) || info.LockProvider.IsMarkedToDelete)
                {
                    detail.IsFound = false;
                    continue;
                }

                // found
                detail.IsFound         = true;
                detail.BytesDownloaded = info.DownloadStatus.Data.DownloadedBytes;
                detail.SegmentsBitmap  = info.DownloadStatus.Data.SegmentsBitmap;
            }

            var result = new PackageStatusResponse()
            {
                Packages = packages
            };

            return(result);
        }
Exemplo n.º 2
0
 public void PrintMessage(Package package, PackageStatusResponse statusResponse)
 {
     if (PrintStrategy == null)
     {
         throw new Exception("No se definió la estrategia de impresion");
     }
     PrintStrategy.Print(package, statusResponse);
 }
Exemplo n.º 3
0
        public void PrintMessage_Method_should_throw_exception_when_strategy_is_null()
        {
            //Arrange
            _deliveryMessagePrinter.PrintStrategy = null;
            Package package = new Package();
            PackageStatusResponse packageStatusResponse = new PackageStatusResponse();

            //Act
            Assert.ThrowsException <Exception>(() => _deliveryMessagePrinter.PrintMessage(package, packageStatusResponse));
            //Assert
        }
Exemplo n.º 4
0
        public void PrintMessage_Method_should_call_strategy_print()
        {
            //Arrange
            _deliveryMessagePrinter.PrintStrategy = _printStrategyMock.Object;
            _printStrategyMock.Setup(x => x.Print(It.IsAny <Package>(), It.IsAny <PackageStatusResponse>()));
            Package package = new Package();
            PackageStatusResponse packageStatusResponse = new PackageStatusResponse();

            //Act
            _deliveryMessagePrinter.PrintMessage(package, packageStatusResponse);
            //Assert
            _printStrategyMock.Verify(x => x.Print(package, packageStatusResponse), Times.Once);
        }
        public void Print(Package package, PackageStatusResponse packageStatusResponse)
        {
            RangoResponse rangoResponse = _rangoDeTiempoProvider.GetValorPorRango(packageStatusResponse.TimeCheckerResponse.TimePast);
            decimal       costoEnvio    = _calculadorCostoEnvio.ObtenerCostoEnvio(package);

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine(string.Format(Template,
                                            Expression1,
                                            package.Origen,
                                            Expression2,
                                            package.Destino,
                                            Expression3,
                                            rangoResponse.Valor + " " + rangoResponse.Rango,
                                            Expression4,
                                            costoEnvio,
                                            package.Empresa.Name
                                            ));
            Console.ResetColor();
        }
Exemplo n.º 6
0
 public override void ReportPackage(Package package)
 {
     if (package.IsSupported)
     {
         if (package.Empresa == null)
         {
             _strategies.TryGetValue(PackageStatus.unsupported, out IPrintStrategy printStrategy);
             DoPrint(package, printStrategy, null);
         }
         else
         {
             PackageStatusResponse packageStatusResponse = _deliveryManager.CheckPackageStatus(package);
             _strategies.TryGetValue(packageStatusResponse.Status, out IPrintStrategy printStrategy);
             DoPrint(package, printStrategy, packageStatusResponse);
         }
     }
     else
     {
         _strategies.TryGetValue(PackageStatus.unknown, out IPrintStrategy printStrategy);
         DoPrint(package, printStrategy, null);
     }
 }
 public void Print(Package package, PackageStatusResponse packageStatusResponse)
 {
     Console.ForegroundColor = ConsoleColor.Red;
     Console.WriteLine(string.Format(_template, package.UnSupportedCompany));
     Console.ResetColor();
 }
Exemplo n.º 8
0
 public void Print(Package package, PackageStatusResponse packageStatusResponse)
 {
     Console.ForegroundColor = ConsoleColor.Red;
     Console.WriteLine(string.Format(_template, package.Empresa.Name, package.MedioTransporte));
     Console.ResetColor();
 }
Exemplo n.º 9
0
 private void DoPrint(Package package, IPrintStrategy printStrategy, PackageStatusResponse statusResponse)
 {
     _deliveryMessagePrinter.PrintStrategy = printStrategy;
     _deliveryMessagePrinter.PrintMessage(package, statusResponse);
 }