Ejemplo n.º 1
0
        public AdicionarAtaEmUmaReuniaoResposta AdicionarAtaEmUmaReuniao(AdicionarAtaEmUmaReuniaoRequisicao requisicao)
        {
            var resposta = new AdicionarAtaEmUmaReuniaoResposta();

            var reuniao     = _reuniaoRepositorio.ObterPor(requisicao.CodigoDaReuniao);
            var responsavel = _funcionarioRepositorio.ObterPor(requisicao.CodigoDoResponsavel);

            try
            {
                var ata = new Ata(responsavel)
                {
                    Assunto       = requisicao.Assunto,
                    FinalDoPrazo  = requisicao.FinalDoPrazo,
                    InicioDoPrazo = requisicao.InicioDoPrazo,
                    Anotacoes     = requisicao.Anotacoes,
                    Status        = requisicao.Status,
                };

                reuniao.AdicionarAta(ata);
                resposta.Ata = ata;
                _unitOfWork.Commit();
                resposta.Sucesso = true;
            }
            catch (RegraException regraException)
            {
                resposta.Erros = regraException.Erros;
            }
            return(resposta);
        }
        public async Task <IActionResult> Create(IFormFile fil, DateTime data)
        {
            string folderName  = "atas";
            string webRootPath = _hostingEnvironment.WebRootPath;
            string newPath     = Path.Combine(webRootPath, folderName);

            var studentId = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Name).Value;

            if (!Directory.Exists(newPath))// Create New Directory if not exist as per the path
            {
                Directory.CreateDirectory(newPath);
            }
            var fiName = Guid.NewGuid().ToString() + Path.GetExtension(fil.FileName);

            using (var fileStream = new FileStream(Path.Combine(newPath, fiName), FileMode.Create))
            {
                fil.CopyTo(fileStream);
            }
            // Get uploaded file path with root
            string   fileName = @"wwwroot/atas/" + fiName;
            FileInfo file     = new FileInfo(fileName);

            using (_context)
            {
                var ata = new Ata();
                ata.StudentId   = int.Parse(User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Name).Value);
                ata.MeetingDate = data.Date;
                ata.FilePath    = file.ToString();
                _context.Add(ata);
                _context.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
        public void ConsigoAdicionarAtasEmUmaReuniao()
        {
            var reuniao = new Reuniao(new Programa(), _funcionario, _local, "ASsunto", _data, StatusDaReunicao.Concluido);

            var ata = new Ata(_funcionario);
            reuniao.AdicionarAta(ata);

            CollectionAssert.Contains(reuniao.Atas, ata);
        }
        public void PossoAdicionarAnexosEmUmaAta()
        {
            var responsavel = FuncionarioBuilder.DadoUmFuncionario().Build();
            var ata = new Ata(responsavel);
            var arquivo = ArquivoBuilder.DadoUmArquivo().Build();

            ata.AdicionarAnexo(arquivo);

            CollectionAssert.Contains(ata.Anexos ,arquivo);
        }
Ejemplo n.º 5
0
        public void ConsigoAdicionarAtasEmUmaReuniao()
        {
            var reuniao = new Reuniao(new Programa(), _funcionario, _local, "ASsunto", _data, StatusDaReunicao.Concluido);

            var ata = new Ata(_funcionario);

            reuniao.AdicionarAta(ata);

            CollectionAssert.Contains(reuniao.Atas, ata);
        }
Ejemplo n.º 6
0
        public void PossoAdicionarAnexosEmUmaAta()
        {
            var responsavel = FuncionarioBuilder.DadoUmFuncionario().Build();
            var ata         = new Ata(responsavel);
            var arquivo     = ArquivoBuilder.DadoUmArquivo().Build();

            ata.AdicionarAnexo(arquivo);

            CollectionAssert.Contains(ata.Anexos, arquivo);
        }
Ejemplo n.º 7
0
 public static AtaViewModel ToViewModel(this Ata ata)
 {
     return(new AtaViewModel
     {
         Codigo = ata.Codigo,
         Anotacoes = ata.Anotacoes,
         Assunto = ata.Assunto,
         FinalDoPrazo = ata.FinalDoPrazo,
         InicioDoPrazo = ata.InicioDoPrazo,
         Status = ata.Status.GetStringValue(),
         CodigoDoStatus = ata.Status,
         Responsavel = ata.Responsavel.ToViewModel()
     });
 }
Ejemplo n.º 8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                string manufacturer = Request.QueryString["manufacturer"];
                string model        = Request.QueryString["model"];
                string revision     = Request.QueryString["revision"];

                // Strip non-ascii, strip slashes and question marks
                if (manufacturer != null)
                {
                    manufacturer = Encoding
                                   .ASCII.GetString(Encoding.Convert(Encoding.UTF8, Encoding.ASCII,
                                                                     Encoding.UTF8.GetBytes(manufacturer))).Replace('/', '_')
                                   .Replace('\\', '_').Replace('?', '_');
                }
                if (model != null)
                {
                    model = Encoding
                            .ASCII.GetString(Encoding.Convert(Encoding.UTF8, Encoding.ASCII, Encoding.UTF8.GetBytes(model)))
                            .Replace('/', '_').Replace('\\', '_').Replace('?', '_');
                }
                if (revision != null)
                {
                    revision = Encoding
                               .ASCII.GetString(Encoding.Convert(Encoding.UTF8, Encoding.ASCII,
                                                                 Encoding.UTF8.GetBytes(revision))).Replace('/', '_')
                               .Replace('\\', '_').Replace('?', '_');
                }

                string xmlFile = null;
                if (!string.IsNullOrWhiteSpace(manufacturer) && !string.IsNullOrWhiteSpace(model) &&
                    !string.IsNullOrWhiteSpace(revision))
                {
                    xmlFile = manufacturer + "_" + model + "_" + revision + ".xml";
                }
                else if (!string.IsNullOrWhiteSpace(manufacturer) && !string.IsNullOrWhiteSpace(model))
                {
                    xmlFile = manufacturer + "_" + model + ".xml";
                }
                else if (!string.IsNullOrWhiteSpace(model) && !string.IsNullOrWhiteSpace(revision))
                {
                    xmlFile = model + "_" + revision + ".xml";
                }
                else if (!string.IsNullOrWhiteSpace(model))
                {
                    xmlFile = model + ".xml";
                }

                if (xmlFile == null ||
                    !File.Exists(Path.Combine(HostingEnvironment.MapPath("~") ?? throw new InvalidOperationException(),
                                              "Reports", xmlFile)))
                {
                    content.InnerHtml = "<b>Could not find the specified report</b>";
                    return;
                }

                lblManufacturer.Text = Request.QueryString["manufacturer"];
                lblModel.Text        = Request.QueryString["model"];
                lblRevision.Text     = Request.QueryString["revision"];

                DeviceReport  report = new DeviceReport();
                XmlSerializer xs     = new XmlSerializer(report.GetType());
                StreamReader  sr     =
                    new
                    StreamReader(Path.Combine(HostingEnvironment.MapPath("~") ?? throw new InvalidOperationException(),
                                              "Reports", xmlFile));
                report = (DeviceReport)xs.Deserialize(sr);
                sr.Close();

                if (report.USB != null)
                {
                    GetUsbDescriptions(report.USB.VendorID, report.USB.ProductID, out string usbVendorDescription,
                                       out string usbProductDescription);

                    lblUsbManufacturer.Text = HttpUtility.HtmlEncode(report.USB.Manufacturer);
                    lblUsbProduct.Text      = HttpUtility.HtmlEncode(report.USB.Product);
                    lblUsbVendor.Text       = $"0x{report.USB.VendorID:x4}";
                    if (usbVendorDescription != null)
                    {
                        lblUsbVendorDescription.Text = $"({HttpUtility.HtmlEncode(usbVendorDescription)})";
                    }
                    lblUsbProductId.Text = $"0x{report.USB.ProductID:x4}";
                    if (usbProductDescription != null)
                    {
                        lblUsbProductDescription.Text = $"({HttpUtility.HtmlEncode(usbProductDescription)})";
                    }
                }
                else
                {
                    divUsb.Visible = false;
                }

                if (report.FireWire != null)
                {
                    lblFirewireManufacturer.Text = HttpUtility.HtmlEncode(report.FireWire.Manufacturer);
                    lblFirewireProduct.Text      = HttpUtility.HtmlEncode(report.FireWire.Product);
                    lblFirewireVendor.Text       = $"0x{report.FireWire.VendorID:x8}";
                    lblFirewireProductId.Text    = $"0x{report.FireWire.ProductID:x8}";
                }
                else
                {
                    divFirewire.Visible = false;
                }

                if (report.PCMCIA != null)
                {
                    lblPcmciaManufacturer.Text     = HttpUtility.HtmlEncode(report.PCMCIA.Manufacturer);
                    lblPcmciaProduct.Text          = HttpUtility.HtmlEncode(report.PCMCIA.ProductName);
                    lblPcmciaManufacturerCode.Text = $"0x{report.PCMCIA.ManufacturerCode:x4}";
                    lblPcmciaCardCode.Text         = $"0x{report.PCMCIA.CardCode:x4}";
                    lblPcmciaCompliance.Text       = HttpUtility.HtmlEncode(report.PCMCIA.Compliance);
                    Tuple[] tuples = CIS.GetTuples(report.PCMCIA.CIS);
                    if (tuples != null)
                    {
                        Dictionary <string, string> decodedTuples = new Dictionary <string, string>();
                        foreach (Tuple tuple in tuples)
                        {
                            switch (tuple.Code)
                            {
                            case TupleCodes.CISTPL_NULL:
                            case TupleCodes.CISTPL_END:
                            case TupleCodes.CISTPL_MANFID:
                            case TupleCodes.CISTPL_VERS_1: break;

                            case TupleCodes.CISTPL_DEVICEGEO:
                            case TupleCodes.CISTPL_DEVICEGEO_A:
                                DeviceGeometryTuple geom = CIS.DecodeDeviceGeometryTuple(tuple.Data);
                                if (geom?.Geometries != null)
                                {
                                    foreach (DeviceGeometry geometry in geom.Geometries)
                                    {
                                        decodedTuples.Add("Device width",
                                                          $"{(1 << (geometry.CardInterface - 1)) * 8} bits");
                                        decodedTuples.Add("Erase block",
                                                          $"{(1 << (geometry.EraseBlockSize - 1)) * (1 << (geometry.Interleaving - 1))} bytes");
                                        decodedTuples.Add("Read block",
                                                          $"{(1 << (geometry.ReadBlockSize - 1)) * (1 << (geometry.Interleaving - 1))} bytes");
                                        decodedTuples.Add("Write block",
                                                          $"{(1 << (geometry.WriteBlockSize - 1)) * (1 << (geometry.Interleaving - 1))} bytes");
                                        decodedTuples.Add("Partition alignment",
                                                          $"{(1 << (geometry.EraseBlockSize - 1)) * (1 << (geometry.Interleaving - 1)) * (1 << (geometry.Partitions - 1))} bytes");
                                    }
                                }

                                break;

                            case TupleCodes.CISTPL_ALTSTR:
                            case TupleCodes.CISTPL_BAR:
                            case TupleCodes.CISTPL_BATTERY:
                            case TupleCodes.CISTPL_BYTEORDER:
                            case TupleCodes.CISTPL_CFTABLE_ENTRY:
                            case TupleCodes.CISTPL_CFTABLE_ENTRY_CB:
                            case TupleCodes.CISTPL_CHECKSUM:
                            case TupleCodes.CISTPL_CONFIG:
                            case TupleCodes.CISTPL_CONFIG_CB:
                            case TupleCodes.CISTPL_DATE:
                            case TupleCodes.CISTPL_DEVICE:
                            case TupleCodes.CISTPL_DEVICE_A:
                            case TupleCodes.CISTPL_DEVICE_OA:
                            case TupleCodes.CISTPL_DEVICE_OC:
                            case TupleCodes.CISTPL_EXTDEVIC:
                            case TupleCodes.CISTPL_FORMAT:
                            case TupleCodes.CISTPL_FORMAT_A:
                            case TupleCodes.CISTPL_FUNCE:
                            case TupleCodes.CISTPL_FUNCID:
                            case TupleCodes.CISTPL_GEOMETRY:
                            case TupleCodes.CISTPL_INDIRECT:
                            case TupleCodes.CISTPL_JEDEC_A:
                            case TupleCodes.CISTPL_JEDEC_C:
                            case TupleCodes.CISTPL_LINKTARGET:
                            case TupleCodes.CISTPL_LONGLINK_A:
                            case TupleCodes.CISTPL_LONGLINK_C:
                            case TupleCodes.CISTPL_LONGLINK_CB:
                            case TupleCodes.CISTPL_LONGLINK_MFC:
                            case TupleCodes.CISTPL_NO_LINK:
                            case TupleCodes.CISTPL_ORG:
                            case TupleCodes.CISTPL_PWR_MGMNT:
                            case TupleCodes.CISTPL_SPCL:
                            case TupleCodes.CISTPL_SWIL:
                            case TupleCodes.CISTPL_VERS_2:
                                decodedTuples.Add("Undecoded tuple ID", tuple.Code.ToString());
                                break;

                            default:
                                decodedTuples.Add("Unknown tuple ID", $"0x{(byte)tuple.Code:X2}");
                                break;
                            }
                        }

                        if (decodedTuples.Count > 0)
                        {
                            repPcmciaTuples.DataSource = decodedTuples;
                            repPcmciaTuples.DataBind();
                        }
                        else
                        {
                            repPcmciaTuples.Visible = false;
                        }
                    }
                    else
                    {
                        repPcmciaTuples.Visible = false;
                    }
                }
                else
                {
                    divPcmcia.Visible = false;
                }

                bool removable = true;
                testedMediaType[] testedMedia = null;
                bool ata      = false;
                bool atapi    = false;
                bool sscMedia = false;

                if (report.ATA != null || report.ATAPI != null)
                {
                    ata = true;
                    List <string> ataOneValue = new List <string>();
                    Dictionary <string, string> ataTwoValue = new Dictionary <string, string>();
                    ataType ataReport;

                    if (report.ATAPI != null)
                    {
                        lblAtapi.Text = "PI";
                        ataReport     = report.ATAPI;
                        atapi         = true;
                    }
                    else
                    {
                        ataReport = report.ATA;
                    }

                    bool cfa = report.CompactFlashSpecified && report.CompactFlash;

                    if (atapi && !cfa)
                    {
                        lblAtaDeviceType.Text = "ATAPI device";
                    }
                    else if (!atapi && cfa)
                    {
                        lblAtaDeviceType.Text = "CompactFlash device";
                    }
                    else
                    {
                        lblAtaDeviceType.Text = "ATA device";
                    }

                    Ata.Report(ataReport, cfa, atapi, ref removable, ref ataOneValue, ref ataTwoValue, ref testedMedia);

                    repAtaOne.DataSource = ataOneValue;
                    repAtaOne.DataBind();
                    repAtaTwo.DataSource = ataTwoValue;
                    repAtaTwo.DataBind();
                }
                else
                {
                    divAta.Visible = false;
                }

                if (report.SCSI != null)
                {
                    List <string> scsiOneValue            = new List <string>();
                    Dictionary <string, string> modePages = new Dictionary <string, string>();
                    Dictionary <string, string> evpdPages = new Dictionary <string, string>();

                    lblScsiVendor.Text =
                        VendorString.Prettify(report.SCSI.Inquiry.VendorIdentification) !=
                        report.SCSI.Inquiry.VendorIdentification
                            ? $"{report.SCSI.Inquiry.VendorIdentification} ({VendorString.Prettify(report.SCSI.Inquiry.VendorIdentification)})"
                            : report.SCSI.Inquiry.VendorIdentification;
                    lblScsiProduct.Text  = report.SCSI.Inquiry.ProductIdentification;
                    lblScsiRevision.Text = report.SCSI.Inquiry.ProductRevisionLevel;

                    scsiOneValue.AddRange(ScsiInquiry.Report(report.SCSI.Inquiry));

                    if (report.SCSI.SupportsModeSense6)
                    {
                        scsiOneValue.Add("Device supports MODE SENSE (6)");
                    }
                    if (report.SCSI.SupportsModeSense10)
                    {
                        scsiOneValue.Add("Device supports MODE SENSE (10)");
                    }
                    if (report.SCSI.SupportsModeSubpages)
                    {
                        scsiOneValue.Add("Device supports MODE SENSE subpages");
                    }

                    if (report.SCSI.ModeSense != null)
                    {
                        ScsiModeSense.Report(report.SCSI.ModeSense, report.SCSI.Inquiry.VendorIdentification,
                                             report.SCSI.Inquiry.PeripheralDeviceType, ref scsiOneValue, ref modePages);
                    }

                    if (modePages.Count > 0)
                    {
                        repModeSense.DataSource = modePages;
                        repModeSense.DataBind();
                    }
                    else
                    {
                        divScsiModeSense.Visible = false;
                    }

                    if (report.SCSI.EVPDPages != null)
                    {
                        ScsiEvpd.Report(report.SCSI.EVPDPages, report.SCSI.Inquiry.VendorIdentification, ref evpdPages);
                    }

                    if (evpdPages.Count > 0)
                    {
                        repEvpd.DataSource = evpdPages;
                        repEvpd.DataBind();
                    }
                    else
                    {
                        divScsiEvpd.Visible = false;
                    }

                    divScsiMmcMode.Visible     = false;
                    divScsiMmcFeatures.Visible = false;
                    divScsiSsc.Visible         = false;

                    if (report.SCSI.MultiMediaDevice != null)
                    {
                        testedMedia = report.SCSI.MultiMediaDevice.TestedMedia;

                        if (report.SCSI.MultiMediaDevice.ModeSense2A != null)
                        {
                            List <string> mmcModeOneValue = new List <string>();
                            ScsiMmcMode.Report(report.SCSI.MultiMediaDevice.ModeSense2A, ref mmcModeOneValue);
                            if (mmcModeOneValue.Count > 0)
                            {
                                divScsiMmcMode.Visible    = true;
                                repScsiMmcMode.DataSource = mmcModeOneValue;
                                repScsiMmcMode.DataBind();
                            }
                        }

                        if (report.SCSI.MultiMediaDevice.Features != null)
                        {
                            List <string> mmcFeaturesOneValue = new List <string>();
                            ScsiMmcFeatures.Report(report.SCSI.MultiMediaDevice.Features, ref mmcFeaturesOneValue);
                            if (mmcFeaturesOneValue.Count > 0)
                            {
                                divScsiMmcFeatures.Visible    = true;
                                repScsiMmcFeatures.DataSource = mmcFeaturesOneValue;
                                repScsiMmcFeatures.DataBind();
                            }
                        }
                    }
                    else if (report.SCSI.SequentialDevice != null)
                    {
                        divScsiSsc.Visible = true;

                        lblScsiSscGranularity.Text = report.SCSI.SequentialDevice.BlockSizeGranularitySpecified
                                                         ? report.SCSI.SequentialDevice.BlockSizeGranularity.ToString()
                                                         : "Unspecified";

                        lblScsiSscMaxBlock.Text = report.SCSI.SequentialDevice.MaxBlockLengthSpecified
                                                      ? report.SCSI.SequentialDevice.MaxBlockLength.ToString()
                                                      : "Unspecified";

                        lblScsiSscMinBlock.Text = report.SCSI.SequentialDevice.MinBlockLengthSpecified
                                                      ? report.SCSI.SequentialDevice.MinBlockLength.ToString()
                                                      : "Unspecified";

                        if (report.SCSI.SequentialDevice.SupportedDensities != null)
                        {
                            repScsiSscDensities.DataSource = report.SCSI.SequentialDevice.SupportedDensities;
                            repScsiSscDensities.DataBind();
                        }
                        else
                        {
                            repScsiSscDensities.Visible = false;
                        }

                        if (report.SCSI.SequentialDevice.SupportedMediaTypes != null)
                        {
                            repScsiSscMedias.DataSource = report.SCSI.SequentialDevice.SupportedMediaTypes;
                            repScsiSscMedias.DataBind();
                        }
                        else
                        {
                            repScsiSscMedias.Visible = false;
                        }

                        if (report.SCSI.SequentialDevice.TestedMedia != null)
                        {
                            List <string> mediaOneValue = new List <string>();
                            SscTestedMedia.Report(report.SCSI.SequentialDevice.TestedMedia, ref mediaOneValue);
                            if (mediaOneValue.Count > 0)
                            {
                                sscMedia = true;
                                repTestedMedia.DataSource = mediaOneValue;
                                repTestedMedia.DataBind();
                            }
                            else
                            {
                                divTestedMedia.Visible = false;
                            }
                        }
                        else
                        {
                            divTestedMedia.Visible = false;
                        }
                    }
                    else if (report.SCSI.ReadCapabilities != null)
                    {
                        removable = false;
                        scsiOneValue.Add("");

                        if (report.SCSI.ReadCapabilities.BlocksSpecified &&
                            report.SCSI.ReadCapabilities.BlockSizeSpecified)
                        {
                            scsiOneValue
                            .Add($"Device has {report.SCSI.ReadCapabilities.Blocks} blocks of {report.SCSI.ReadCapabilities.BlockSize} bytes each");

                            if (report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize / 1024 /
                                1024 > 1000000)
                            {
                                scsiOneValue
                                .Add($"Device size: {report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize} bytes, {report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize / 1000 / 1000 / 1000 / 1000} Tb, {(double)(report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize) / 1024 / 1024 / 1024 / 1024:F2} TiB");
                            }
                            else if (report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize /
                                     1024 / 1024 > 1000)
                            {
                                scsiOneValue
                                .Add($"Device size: {report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize} bytes, {report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize / 1000 / 1000 / 1000} Gb, {(double)(report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize) / 1024 / 1024 / 1024:F2} GiB");
                            }
                            else
                            {
                                scsiOneValue
                                .Add($"Device size: {report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize} bytes, {report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize / 1000 / 1000} Mb, {(double)(report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize) / 1024 / 1024:F2} MiB");
                            }
                        }

                        if (report.SCSI.ReadCapabilities.MediumTypeSpecified)
                        {
                            scsiOneValue.Add($"Medium type code: {report.SCSI.ReadCapabilities.MediumType:X2}h");
                        }
                        if (report.SCSI.ReadCapabilities.DensitySpecified)
                        {
                            scsiOneValue.Add($"Density code: {report.SCSI.ReadCapabilities.Density:X2}h");
                        }
                        if ((report.SCSI.ReadCapabilities.SupportsReadLong ||
                             report.SCSI.ReadCapabilities.SupportsReadLong16) &&
                            report.SCSI.ReadCapabilities.LongBlockSizeSpecified)
                        {
                            scsiOneValue.Add($"Long block size: {report.SCSI.ReadCapabilities.LongBlockSize} bytes");
                        }
                        if (report.SCSI.ReadCapabilities.SupportsReadCapacity)
                        {
                            scsiOneValue.Add("Device supports READ CAPACITY (10) command.");
                        }
                        if (report.SCSI.ReadCapabilities.SupportsReadCapacity16)
                        {
                            scsiOneValue.Add("Device supports READ CAPACITY (16) command.");
                        }
                        if (report.SCSI.ReadCapabilities.SupportsRead)
                        {
                            scsiOneValue.Add("Device supports READ (6) command.");
                        }
                        if (report.SCSI.ReadCapabilities.SupportsRead10)
                        {
                            scsiOneValue.Add("Device supports READ (10) command.");
                        }
                        if (report.SCSI.ReadCapabilities.SupportsRead12)
                        {
                            scsiOneValue.Add("Device supports READ (12) command.");
                        }
                        if (report.SCSI.ReadCapabilities.SupportsRead16)
                        {
                            scsiOneValue.Add("Device supports READ (16) command.");
                        }
                        if (report.SCSI.ReadCapabilities.SupportsReadLong)
                        {
                            scsiOneValue.Add("Device supports READ LONG (10) command.");
                        }
                        if (report.SCSI.ReadCapabilities.SupportsReadLong16)
                        {
                            scsiOneValue.Add("Device supports READ LONG (16) command.");
                        }
                    }
                    else
                    {
                        testedMedia = report.SCSI.RemovableMedias;
                    }

                    repScsi.DataSource = scsiOneValue;
                    repScsi.DataBind();
                }
                else
                {
                    divScsi.Visible = false;
                }

                if (report.MultiMediaCard != null)
                {
                    List <string> mmcOneValue = new List <string>();

                    if (report.MultiMediaCard.CID != null)
                    {
                        mmcOneValue.Add(Decoders.MMC.Decoders.PrettifyCID(report.MultiMediaCard.CID)
                                        .Replace("\n", "<br/>"));
                        mmcOneValue.Add("");
                    }

                    if (report.MultiMediaCard.CSD != null)
                    {
                        mmcOneValue.Add(Decoders.MMC.Decoders.PrettifyCSD(report.MultiMediaCard.CSD)
                                        .Replace("\n", "<br/>"));
                        mmcOneValue.Add("");
                    }

                    if (report.MultiMediaCard.ExtendedCSD != null)
                    {
                        mmcOneValue.Add(Decoders.MMC.Decoders.PrettifyExtendedCSD(report.MultiMediaCard.ExtendedCSD)
                                        .Replace("\n", "<br/>"));
                        mmcOneValue.Add("");
                    }

                    if (report.MultiMediaCard.OCR != null)
                    {
                        mmcOneValue.Add(Decoders.MMC.Decoders.PrettifyCSD(report.MultiMediaCard.OCR)
                                        .Replace("\n", "<br/>"));
                        mmcOneValue.Add("");
                    }

                    repMMC.DataSource = mmcOneValue;
                    repMMC.DataBind();
                }
                else
                {
                    divMMC.Visible = false;
                }

                if (report.SecureDigital != null)
                {
                    List <string> sdOneValue = new List <string>();

                    if (report.SecureDigital.CID != null)
                    {
                        sdOneValue.Add(Decoders.SecureDigital.Decoders.PrettifyCID(report.SecureDigital.CID)
                                       .Replace("\n", "<br/>"));
                        sdOneValue.Add("");
                    }

                    if (report.SecureDigital.CSD != null)
                    {
                        sdOneValue.Add(Decoders.SecureDigital.Decoders.PrettifyCSD(report.SecureDigital.CSD)
                                       .Replace("\n", "<br/>"));
                        sdOneValue.Add("");
                    }

                    if (report.SecureDigital.SCR != null)
                    {
                        sdOneValue.Add(Decoders.SecureDigital.Decoders.PrettifySCR(report.SecureDigital.SCR)
                                       .Replace("\n", "<br/>"));
                        sdOneValue.Add("");
                    }

                    if (report.SecureDigital.OCR != null)
                    {
                        sdOneValue.Add(Decoders.SecureDigital.Decoders.PrettifyCSD(report.SecureDigital.OCR)
                                       .Replace("\n", "<br/>"));
                        sdOneValue.Add("");
                    }

                    repSD.DataSource = sdOneValue;
                    repSD.DataBind();
                }
                else
                {
                    divSD.Visible = false;
                }

                if (removable && !sscMedia && testedMedia != null)
                {
                    List <string> mediaOneValue = new List <string>();
                    TestedMedia.Report(testedMedia, ata, ref mediaOneValue);
                    if (mediaOneValue.Count > 0)
                    {
                        divTestedMedia.Visible    = true;
                        repTestedMedia.DataSource = mediaOneValue;
                        repTestedMedia.DataBind();
                    }
                    else
                    {
                        divTestedMedia.Visible = false;
                    }
                }
                else
                {
                    divTestedMedia.Visible &= sscMedia;
                }
            }
            catch (Exception)
            {
                content.InnerHtml = "<b>Could not load device report</b>";
#if DEBUG
                throw;
#endif
            }
        }
        public ActionResult View(int?id)
        {
            if (id == null || id <= 0)
            {
                return(Content("Incorrect device report request"));
            }

            try
            {
                DicServerContext ctx    = new DicServerContext();
                Device           report = ctx.Devices.FirstOrDefault(d => d.Id == id);

                if (report is null)
                {
                    return(Content("Cannot find requested report"));
                }

                ViewBag.lblManufacturer = report.Manufacturer;
                ViewBag.lblModel        = report.Model;
                ViewBag.lblRevision     = report.Revision;

                if (report.USB != null)
                {
                    string usbVendorDescription  = null;
                    string usbProductDescription = null;

                    UsbProduct dbProduct =
                        ctx.UsbProducts.FirstOrDefault(p => p.ProductId == report.USB.ProductID &&
                                                       p.Vendor != null &&
                                                       p.Vendor.VendorId == report.USB.VendorID);

                    if (dbProduct is null)
                    {
                        UsbVendor dbVendor = ctx.UsbVendors.FirstOrDefault(v => v.VendorId == report.USB.VendorID);

                        if (!(dbVendor is null))
                        {
                            usbVendorDescription = dbVendor.Vendor;
                        }
                    }
                    else
                    {
                        usbProductDescription = dbProduct.Product;
                        usbVendorDescription  = dbProduct.Vendor.Vendor;
                    }

                    ViewBag.UsbItem = new Item
                    {
                        Manufacturer      = report.USB.Manufacturer,
                        Product           = report.USB.Product,
                        VendorDescription =
                            usbVendorDescription != null
                                ? $"0x{report.USB.VendorID:x4} ({usbVendorDescription})"
                                : $"0x{report.USB.VendorID:x4}",
                        ProductDescription = usbProductDescription != null
                                                 ? $"0x{report.USB.ProductID:x4} ({usbProductDescription})"
                                                 : $"0x{report.USB.ProductID:x4}"
                    };
                }

                if (report.FireWire != null)
                {
                    ViewBag.FireWireItem = new Item
                    {
                        Manufacturer       = report.FireWire.Manufacturer,
                        Product            = report.FireWire.Product,
                        VendorDescription  = $"0x{report.FireWire.VendorID:x8}",
                        ProductDescription = $"0x{report.FireWire.ProductID:x8}"
                    }
                }
                ;

                if (report.PCMCIA != null)
                {
                    ViewBag.PcmciaItem = new PcmciaItem
                    {
                        Manufacturer       = report.PCMCIA.Manufacturer,
                        Product            = report.PCMCIA.ProductName,
                        VendorDescription  = $"0x{report.PCMCIA.ManufacturerCode:x4}",
                        ProductDescription = $"0x{report.PCMCIA.CardCode:x4}",
                        Compliance         = report.PCMCIA.Compliance
                    };

                    Tuple[] tuples = CIS.GetTuples(report.PCMCIA.CIS);
                    if (tuples != null)
                    {
                        Dictionary <string, string> decodedTuples = new Dictionary <string, string>();
                        foreach (Tuple tuple in tuples)
                        {
                            switch (tuple.Code)
                            {
                            case TupleCodes.CISTPL_NULL:
                            case TupleCodes.CISTPL_END:
                            case TupleCodes.CISTPL_MANFID:
                            case TupleCodes.CISTPL_VERS_1: break;

                            case TupleCodes.CISTPL_DEVICEGEO:
                            case TupleCodes.CISTPL_DEVICEGEO_A:
                                DeviceGeometryTuple geom = CIS.DecodeDeviceGeometryTuple(tuple.Data);
                                if (geom?.Geometries != null)
                                {
                                    foreach (DeviceGeometry geometry in geom.Geometries)
                                    {
                                        decodedTuples.Add("Device width",
                                                          $"{(1 << (geometry.CardInterface - 1)) * 8} bits");
                                        decodedTuples.Add("Erase block",
                                                          $"{(1 << (geometry.EraseBlockSize - 1)) * (1 << (geometry.Interleaving - 1))} bytes");
                                        decodedTuples.Add("Read block",
                                                          $"{(1 << (geometry.ReadBlockSize - 1)) * (1 << (geometry.Interleaving - 1))} bytes");
                                        decodedTuples.Add("Write block",
                                                          $"{(1 << (geometry.WriteBlockSize - 1)) * (1 << (geometry.Interleaving - 1))} bytes");
                                        decodedTuples.Add("Partition alignment",
                                                          $"{(1 << (geometry.EraseBlockSize - 1)) * (1 << (geometry.Interleaving - 1)) * (1 << (geometry.Partitions - 1))} bytes");
                                    }
                                }

                                break;

                            case TupleCodes.CISTPL_ALTSTR:
                            case TupleCodes.CISTPL_BAR:
                            case TupleCodes.CISTPL_BATTERY:
                            case TupleCodes.CISTPL_BYTEORDER:
                            case TupleCodes.CISTPL_CFTABLE_ENTRY:
                            case TupleCodes.CISTPL_CFTABLE_ENTRY_CB:
                            case TupleCodes.CISTPL_CHECKSUM:
                            case TupleCodes.CISTPL_CONFIG:
                            case TupleCodes.CISTPL_CONFIG_CB:
                            case TupleCodes.CISTPL_DATE:
                            case TupleCodes.CISTPL_DEVICE:
                            case TupleCodes.CISTPL_DEVICE_A:
                            case TupleCodes.CISTPL_DEVICE_OA:
                            case TupleCodes.CISTPL_DEVICE_OC:
                            case TupleCodes.CISTPL_EXTDEVIC:
                            case TupleCodes.CISTPL_FORMAT:
                            case TupleCodes.CISTPL_FORMAT_A:
                            case TupleCodes.CISTPL_FUNCE:
                            case TupleCodes.CISTPL_FUNCID:
                            case TupleCodes.CISTPL_GEOMETRY:
                            case TupleCodes.CISTPL_INDIRECT:
                            case TupleCodes.CISTPL_JEDEC_A:
                            case TupleCodes.CISTPL_JEDEC_C:
                            case TupleCodes.CISTPL_LINKTARGET:
                            case TupleCodes.CISTPL_LONGLINK_A:
                            case TupleCodes.CISTPL_LONGLINK_C:
                            case TupleCodes.CISTPL_LONGLINK_CB:
                            case TupleCodes.CISTPL_LONGLINK_MFC:
                            case TupleCodes.CISTPL_NO_LINK:
                            case TupleCodes.CISTPL_ORG:
                            case TupleCodes.CISTPL_PWR_MGMNT:
                            case TupleCodes.CISTPL_SPCL:
                            case TupleCodes.CISTPL_SWIL:
                            case TupleCodes.CISTPL_VERS_2:
                                decodedTuples.Add("Undecoded tuple ID", tuple.Code.ToString());
                                break;

                            default:
                                decodedTuples.Add("Unknown tuple ID", $"0x{(byte)tuple.Code:X2}");
                                break;
                            }
                        }

                        if (decodedTuples.Count > 0)
                        {
                            ViewBag.repPcmciaTuples = decodedTuples;
                        }
                    }
                }

                bool removable = true;
                List <TestedMedia> testedMedia = null;
                bool ata      = false;
                bool atapi    = false;
                bool sscMedia = false;

                if (report.ATA != null || report.ATAPI != null)
                {
                    ata = true;
                    List <string> ataOneValue = new List <string>();
                    Dictionary <string, string> ataTwoValue = new Dictionary <string, string>();
                    CommonTypes.Metadata.Ata    ataReport;

                    if (report.ATAPI != null)
                    {
                        ViewBag.AtaItem = "ATAPI";
                        ataReport       = report.ATAPI;
                        atapi           = true;
                    }
                    else
                    {
                        ViewBag.AtaItem = "ATA";
                        ataReport       = report.ATA;
                    }

                    bool cfa = report.CompactFlash;

                    if (atapi && !cfa)
                    {
                        ViewBag.lblAtaDeviceType = "ATAPI device";
                    }
                    else if (!atapi && cfa)
                    {
                        ViewBag.lblAtaDeviceType = "CompactFlash device";
                    }
                    else
                    {
                        ViewBag.lblAtaDeviceType = "ATA device";
                    }

                    Ata.Report(ataReport, cfa, atapi, ref removable, ref ataOneValue, ref ataTwoValue, ref testedMedia);

                    ViewBag.repAtaOne = ataOneValue;
                    ViewBag.repAtaTwo = ataTwoValue;
                }

                if (report.SCSI != null)
                {
                    List <string> scsiOneValue            = new List <string>();
                    Dictionary <string, string> modePages = new Dictionary <string, string>();
                    Dictionary <string, string> evpdPages = new Dictionary <string, string>();

                    string vendorId = StringHandlers.CToString(report.SCSI.Inquiry?.VendorIdentification);
                    if (report.SCSI.Inquiry != null)
                    {
                        Inquiry.SCSIInquiry inq = report.SCSI.Inquiry.Value;
                        ViewBag.lblScsiVendor = VendorString.Prettify(vendorId) != vendorId
                                                    ? $"{vendorId} ({VendorString.Prettify(vendorId)})"
                                                    : vendorId;
                        ViewBag.lblScsiProduct  = StringHandlers.CToString(inq.ProductIdentification);
                        ViewBag.lblScsiRevision = StringHandlers.CToString(inq.ProductRevisionLevel);
                    }

                    scsiOneValue.AddRange(ScsiInquiry.Report(report.SCSI.Inquiry));

                    if (report.SCSI.SupportsModeSense6)
                    {
                        scsiOneValue.Add("Device supports MODE SENSE (6)");
                    }
                    if (report.SCSI.SupportsModeSense10)
                    {
                        scsiOneValue.Add("Device supports MODE SENSE (10)");
                    }
                    if (report.SCSI.SupportsModeSubpages)
                    {
                        scsiOneValue.Add("Device supports MODE SENSE subpages");
                    }

                    if (report.SCSI.ModeSense != null)
                    {
                        PeripheralDeviceTypes devType = PeripheralDeviceTypes.DirectAccess;
                        if (report.SCSI.Inquiry != null)
                        {
                            devType = (PeripheralDeviceTypes)report.SCSI.Inquiry.Value.PeripheralDeviceType;
                        }
                        ScsiModeSense.Report(report.SCSI.ModeSense, vendorId, devType, ref scsiOneValue, ref modePages);
                    }

                    if (modePages.Count > 0)
                    {
                        ViewBag.repModeSense = modePages;
                    }

                    if (report.SCSI.EVPDPages != null)
                    {
                        ScsiEvpd.Report(report.SCSI.EVPDPages, vendorId, ref evpdPages);
                    }

                    if (evpdPages.Count > 0)
                    {
                        ViewBag.repEvpd = evpdPages;
                    }

                    if (report.SCSI.MultiMediaDevice != null)
                    {
                        testedMedia = report.SCSI.MultiMediaDevice.TestedMedia;

                        if (report.SCSI.MultiMediaDevice.ModeSense2A != null)
                        {
                            List <string> mmcModeOneValue = new List <string>();
                            ScsiMmcMode.Report(report.SCSI.MultiMediaDevice.ModeSense2A, ref mmcModeOneValue);
                            if (mmcModeOneValue.Count > 0)
                            {
                                ViewBag.repScsiMmcMode = mmcModeOneValue;
                            }
                        }

                        if (report.SCSI.MultiMediaDevice.Features != null)
                        {
                            List <string> mmcFeaturesOneValue = new List <string>();
                            ScsiMmcFeatures.Report(report.SCSI.MultiMediaDevice.Features, ref mmcFeaturesOneValue);
                            if (mmcFeaturesOneValue.Count > 0)
                            {
                                ViewBag.repScsiMmcFeatures = mmcFeaturesOneValue;
                            }
                        }
                    }
                    else if (report.SCSI.SequentialDevice != null)
                    {
                        ViewBag.divScsiSscVisible = true;

                        ViewBag.lblScsiSscGranularity =
                            report.SCSI.SequentialDevice.BlockSizeGranularity?.ToString() ?? "Unspecified";

                        ViewBag.lblScsiSscMaxBlock =
                            report.SCSI.SequentialDevice.MaxBlockLength?.ToString() ?? "Unspecified";

                        ViewBag.lblScsiSscMinBlock =
                            report.SCSI.SequentialDevice.MinBlockLength?.ToString() ?? "Unspecified";

                        if (report.SCSI.SequentialDevice.SupportedDensities != null)
                        {
                            ViewBag.repScsiSscDensities = report.SCSI.SequentialDevice.SupportedDensities;
                        }

                        if (report.SCSI.SequentialDevice.SupportedMediaTypes != null)
                        {
                            ViewBag.repScsiSscMedias = report.SCSI.SequentialDevice.SupportedMediaTypes;
                        }

                        if (report.SCSI.SequentialDevice.TestedMedia != null)
                        {
                            List <string> mediaOneValue = new List <string>();
                            SscTestedMedia.Report(report.SCSI.SequentialDevice.TestedMedia, ref mediaOneValue);
                            if (mediaOneValue.Count > 0)
                            {
                                sscMedia = true;
                                ViewBag.repTestedMedia = mediaOneValue;
                            }
                        }
                    }
                    else if (report.SCSI.ReadCapabilities != null)
                    {
                        removable = false;
                        scsiOneValue.Add("");

                        if (report.SCSI.ReadCapabilities.Blocks.HasValue &&
                            report.SCSI.ReadCapabilities.BlockSize.HasValue)
                        {
                            scsiOneValue
                            .Add($"Device has {report.SCSI.ReadCapabilities.Blocks} blocks of {report.SCSI.ReadCapabilities.BlockSize} bytes each");

                            if (report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize / 1024 /
                                1024 > 1000000)
                            {
                                scsiOneValue
                                .Add($"Device size: {report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize} bytes, {report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize / 1000 / 1000 / 1000 / 1000} Tb, {(double)(report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize) / 1024 / 1024 / 1024 / 1024:F2} TiB");
                            }
                            else if (report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize /
                                     1024 /
                                     1024 > 1000)
                            {
                                scsiOneValue
                                .Add($"Device size: {report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize} bytes, {report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize / 1000 / 1000 / 1000} Gb, {(double)(report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize) / 1024 / 1024 / 1024:F2} GiB");
                            }
                            else
                            {
                                scsiOneValue
                                .Add($"Device size: {report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize} bytes, {report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize / 1000 / 1000} Mb, {(double)(report.SCSI.ReadCapabilities.Blocks * report.SCSI.ReadCapabilities.BlockSize) / 1024 / 1024:F2} MiB");
                            }
                        }

                        if (report.SCSI.ReadCapabilities.MediumType.HasValue)
                        {
                            scsiOneValue.Add($"Medium type code: {report.SCSI.ReadCapabilities.MediumType:X2}h");
                        }
                        if (report.SCSI.ReadCapabilities.Density.HasValue)
                        {
                            scsiOneValue.Add($"Density code: {report.SCSI.ReadCapabilities.Density:X2}h");
                        }
                        if ((report.SCSI.ReadCapabilities.SupportsReadLong == true ||
                             report.SCSI.ReadCapabilities.SupportsReadLong16 == true) &&
                            report.SCSI.ReadCapabilities.LongBlockSize.HasValue)
                        {
                            scsiOneValue.Add($"Long block size: {report.SCSI.ReadCapabilities.LongBlockSize} bytes");
                        }
                        if (report.SCSI.ReadCapabilities.SupportsReadCapacity == true)
                        {
                            scsiOneValue.Add("Device supports READ CAPACITY (10) command.");
                        }
                        if (report.SCSI.ReadCapabilities.SupportsReadCapacity16 == true)
                        {
                            scsiOneValue.Add("Device supports READ CAPACITY (16) command.");
                        }
                        if (report.SCSI.ReadCapabilities.SupportsRead6 == true)
                        {
                            scsiOneValue.Add("Device supports READ (6) command.");
                        }
                        if (report.SCSI.ReadCapabilities.SupportsRead10 == true)
                        {
                            scsiOneValue.Add("Device supports READ (10) command.");
                        }
                        if (report.SCSI.ReadCapabilities.SupportsRead12 == true)
                        {
                            scsiOneValue.Add("Device supports READ (12) command.");
                        }
                        if (report.SCSI.ReadCapabilities.SupportsRead16 == true)
                        {
                            scsiOneValue.Add("Device supports READ (16) command.");
                        }
                        if (report.SCSI.ReadCapabilities.SupportsReadLong == true)
                        {
                            scsiOneValue.Add("Device supports READ LONG (10) command.");
                        }
                        if (report.SCSI.ReadCapabilities.SupportsReadLong16 == true)
                        {
                            scsiOneValue.Add("Device supports READ LONG (16) command.");
                        }
                    }
                    else
                    {
                        testedMedia = report.SCSI.RemovableMedias;
                    }

                    ViewBag.repScsi = scsiOneValue;
                }

                if (report.MultiMediaCard != null)
                {
                    List <string> mmcOneValue = new List <string>();

                    if (report.MultiMediaCard.CID != null)
                    {
                        mmcOneValue.Add(Decoders.MMC.Decoders.PrettifyCID(report.MultiMediaCard.CID)
                                        .Replace("\n", "<br/>"));
                        mmcOneValue.Add("");
                    }

                    if (report.MultiMediaCard.CSD != null)
                    {
                        mmcOneValue.Add(Decoders.MMC.Decoders.PrettifyCSD(report.MultiMediaCard.CSD)
                                        .Replace("\n", "<br/>"));
                        mmcOneValue.Add("");
                    }

                    if (report.MultiMediaCard.ExtendedCSD != null)
                    {
                        mmcOneValue.Add(Decoders.MMC.Decoders.PrettifyExtendedCSD(report.MultiMediaCard.ExtendedCSD)
                                        .Replace("\n", "<br/>"));
                        mmcOneValue.Add("");
                    }

                    if (report.MultiMediaCard.OCR != null)
                    {
                        mmcOneValue.Add(Decoders.MMC.Decoders.PrettifyCSD(report.MultiMediaCard.OCR)
                                        .Replace("\n", "<br/>"));
                        mmcOneValue.Add("");
                    }

                    ViewBag.repMMC = mmcOneValue;
                }

                if (report.SecureDigital != null)
                {
                    List <string> sdOneValue = new List <string>();

                    if (report.SecureDigital.CID != null)
                    {
                        sdOneValue.Add(Decoders.SecureDigital.Decoders.PrettifyCID(report.SecureDigital.CID)
                                       .Replace("\n", "<br/>"));
                        sdOneValue.Add("");
                    }

                    if (report.SecureDigital.CSD != null)
                    {
                        sdOneValue.Add(Decoders.SecureDigital.Decoders.PrettifyCSD(report.SecureDigital.CSD)
                                       .Replace("\n", "<br/>"));
                        sdOneValue.Add("");
                    }

                    if (report.SecureDigital.SCR != null)
                    {
                        sdOneValue.Add(Decoders.SecureDigital.Decoders.PrettifySCR(report.SecureDigital.SCR)
                                       .Replace("\n", "<br/>"));
                        sdOneValue.Add("");
                    }

                    if (report.SecureDigital.OCR != null)
                    {
                        sdOneValue.Add(Decoders.SecureDigital.Decoders.PrettifyCSD(report.SecureDigital.OCR)
                                       .Replace("\n", "<br/>"));
                        sdOneValue.Add("");
                    }

                    ViewBag.repSD = sdOneValue;
                }

                if (removable && !sscMedia && testedMedia != null)
                {
                    List <string> mediaOneValue = new List <string>();
                    App_Start.TestedMedia.Report(testedMedia, ref mediaOneValue);
                    if (mediaOneValue.Count > 0)
                    {
                        ViewBag.repTestedMedia = mediaOneValue;
                    }
                }
            }
            catch (Exception)
            {
                #if DEBUG
                throw;
                #endif
                return(Content("Could not load device report"));
            }

            return(View());
        }
Ejemplo n.º 10
0
        internal static void DoMediaScan(MediaScanOptions options)
        {
            DicConsole.DebugWriteLine("Media-Scan command", "--debug={0}", options.Debug);
            DicConsole.DebugWriteLine("Media-Scan command", "--verbose={0}", options.Verbose);
            DicConsole.DebugWriteLine("Media-Scan command", "--device={0}", options.DevicePath);
            DicConsole.DebugWriteLine("Media-Scan command", "--mhdd-log={0}", options.MhddLogPath);
            DicConsole.DebugWriteLine("Media-Scan command", "--ibg-log={0}", options.IbgLogPath);

            if (options.DevicePath.Length == 2 && options.DevicePath[1] == ':' && options.DevicePath[0] != '/' &&
                char.IsLetter(options.DevicePath[0]))
            {
                options.DevicePath = "\\\\.\\" + char.ToUpper(options.DevicePath[0]) + ':';
            }

            Device dev = new Device(options.DevicePath);

            if (dev.Error)
            {
                DicConsole.ErrorWriteLine("Error {0} opening device.", dev.LastError);
                return;
            }

            Core.Statistics.AddDevice(dev);

            ScanResults results;

            switch (dev.Type)
            {
            case DeviceType.ATA:
                results = Ata.Scan(options.MhddLogPath, options.IbgLogPath, options.DevicePath, dev);
                break;

            case DeviceType.MMC:
            case DeviceType.SecureDigital:
                results = SecureDigital.Scan(options.MhddLogPath, options.IbgLogPath, options.DevicePath, dev);
                break;

            case DeviceType.NVMe:
                results = Nvme.Scan(options.MhddLogPath, options.IbgLogPath, options.DevicePath, dev);
                break;

            case DeviceType.ATAPI:
            case DeviceType.SCSI:
                results = Scsi.Scan(options.MhddLogPath, options.IbgLogPath, options.DevicePath, dev);
                break;

            default: throw new NotSupportedException("Unknown device type.");
            }

            DicConsole.WriteLine("Took a total of {0} seconds ({1} processing commands).", results.TotalTime,
                                 results.ProcessingTime);
            DicConsole.WriteLine("Avegare speed: {0:F3} MiB/sec.", results.AvgSpeed);
            DicConsole.WriteLine("Fastest speed burst: {0:F3} MiB/sec.", results.MaxSpeed);
            DicConsole.WriteLine("Slowest speed burst: {0:F3} MiB/sec.", results.MinSpeed);
            DicConsole.WriteLine("Summary:");
            DicConsole.WriteLine("{0} sectors took less than 3 ms.", results.A);
            DicConsole.WriteLine("{0} sectors took less than 10 ms but more than 3 ms.", results.B);
            DicConsole.WriteLine("{0} sectors took less than 50 ms but more than 10 ms.", results.C);
            DicConsole.WriteLine("{0} sectors took less than 150 ms but more than 50 ms.", results.D);
            DicConsole.WriteLine("{0} sectors took less than 500 ms but more than 150 ms.", results.E);
            DicConsole.WriteLine("{0} sectors took more than 500 ms.", results.F);
            DicConsole.WriteLine("{0} sectors could not be read.",
                                 results.UnreadableSectors.Count);
            if (results.UnreadableSectors.Count > 0)
            {
                foreach (ulong bad in results.UnreadableSectors)
                {
                    DicConsole.WriteLine("Sector {0} could not be read", bad);
                }
            }

            DicConsole.WriteLine();

            #pragma warning disable RECS0018     // Comparison of floating point numbers with equality operator
            if (results.SeekTotal != 0 || results.SeekMin != double.MaxValue || results.SeekMax != double.MinValue)
                #pragma warning restore RECS0018 // Comparison of floating point numbers with equality operator
            {
                DicConsole.WriteLine("Testing {0} seeks, longest seek took {1:F3} ms, fastest one took {2:F3} ms. ({3:F3} ms average)",
                                     results.SeekTimes, results.SeekMax, results.SeekMin, results.SeekTotal / 1000);
            }

            Core.Statistics.AddMediaScan((long)results.A, (long)results.B, (long)results.C, (long)results.D,
                                         (long)results.E, (long)results.F, (long)results.Blocks, (long)results.Errored,
                                         (long)(results.Blocks - results.Errored));
            Core.Statistics.AddCommand("media-scan");
        }
Ejemplo n.º 11
0
        public async Task <IActionResult> Create(IFormFile fil, DateTime data, string comments, int userId, int activityId, String DocumentType, String documentName)
        {
            string folderName = "";

            if (DocumentType.Equals("Ata") || DocumentType.Equals("Ata_Corrigida"))
            {
                folderName = "atas";
            }
            else if (DocumentType.Equals("Relatorio"))
            {
                folderName = "documentos";
            }

            string webRootPath = _hostingEnvironment.WebRootPath;
            string newPath     = Path.Combine(webRootPath, folderName);

            if (!Directory.Exists(newPath))// Create New Directory if not exist as per the path
            {
                Directory.CreateDirectory(newPath);
            }
            var fiName = Guid.NewGuid().ToString() + Path.GetExtension(fil.FileName);

            using (var fileStream = new FileStream(Path.Combine(newPath, fiName), FileMode.Create))
            {
                fil.CopyTo(fileStream);
            }
            // Get uploaded file path with root
            string   fileName = @"wwwroot/" + folderName + "/" + fiName;
            FileInfo file     = new FileInfo(fileName);

            try
            {
                if (DocumentType.Equals("Ata") || DocumentType.Equals("Ata_Corrigida"))
                {
                    var ata = new Ata();
                    ata.MeetingDate = data.Date;
                    ata.FilePath    = file.ToString();
                    ata.ActivityId  = activityId;
                    if (User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Role).Value != "Aluno")
                    {
                        ata.UserId = userId;
                    }
                    else
                    {
                        ata.StudentId = int.Parse(User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Name).Value);
                    }
                    _context.Add(ata);
                }
                else
                {
                    var document = new Activity_Document();
                    document.DocumentName  = documentName;
                    document.DocumentPath  = file.ToString();
                    document.SubmitionData = data;
                    document.Comments      = comments;
                    document.UserId        = userId;
                    document.ActivityId    = activityId;
                    _context.Add(document);
                }
                Alert("Documento Adicionado!", "O Documento foi criado com sucesso", NotificationType.success);
                _context.SaveChanges();
            }
            catch
            {
                Alert("Ocorreu um erro", "Não foi possivel adicionar o documento à atividade!", NotificationType.error);
            }

            return(RedirectToAction("Details", "Activities", new { id = activityId }));
        }
Ejemplo n.º 12
0
        internal static void DoDumpMedia(DumpMediaOptions options)
        {
            // TODO: Be able to cancel hashing
            Sidecar.InitProgressEvent    += Progress.InitProgress;
            Sidecar.UpdateProgressEvent  += Progress.UpdateProgress;
            Sidecar.EndProgressEvent     += Progress.EndProgress;
            Sidecar.InitProgressEvent2   += Progress.InitProgress2;
            Sidecar.UpdateProgressEvent2 += Progress.UpdateProgress2;
            Sidecar.EndProgressEvent2    += Progress.EndProgress2;
            Sidecar.UpdateStatusEvent    += Progress.UpdateStatus;

            DicConsole.DebugWriteLine("Dump-Media command", "--debug={0}", options.Debug);
            DicConsole.DebugWriteLine("Dump-Media command", "--verbose={0}", options.Verbose);
            DicConsole.DebugWriteLine("Dump-Media command", "--device={0}", options.DevicePath);
            DicConsole.DebugWriteLine("Dump-Media command", "--raw={0}", options.Raw);
            DicConsole.DebugWriteLine("Dump-Media command", "--stop-on-error={0}", options.StopOnError);
            DicConsole.DebugWriteLine("Dump-Media command", "--force={0}", options.Force);
            DicConsole.DebugWriteLine("Dump-Media command", "--retry-passes={0}", options.RetryPasses);
            DicConsole.DebugWriteLine("Dump-Media command", "--persistent={0}", options.Persistent);
            DicConsole.DebugWriteLine("Dump-Media command", "--resume={0}", options.Resume);
            DicConsole.DebugWriteLine("Dump-Media command", "--lead-in={0}", options.LeadIn);
            DicConsole.DebugWriteLine("Dump-Media command", "--encoding={0}", options.EncodingName);
            DicConsole.DebugWriteLine("Dump-Media command", "--output={0}", options.OutputFile);
            DicConsole.DebugWriteLine("Dump-Media command", "--format={0}", options.OutputFormat);
            DicConsole.DebugWriteLine("Dump-Media command", "--force={0}", options.Force);
            DicConsole.DebugWriteLine("Dump-Media command", "--options={0}", options.Options);
            DicConsole.DebugWriteLine("Dump-Media command", "--cicm-xml={0}", options.CicmXml);
            DicConsole.DebugWriteLine("Dump-Media command", "--skip={0}", options.Skip);
            DicConsole.DebugWriteLine("Dump-Media command", "--no-metadata={0}", options.NoMetadata);

            Dictionary <string, string> parsedOptions = Options.Parse(options.Options);

            DicConsole.DebugWriteLine("Dump-Media command", "Parsed options:");
            foreach (KeyValuePair <string, string> parsedOption in parsedOptions)
            {
                DicConsole.DebugWriteLine("Dump-Media command", "{0} = {1}", parsedOption.Key, parsedOption.Value);
            }

            Encoding encoding = null;

            if (options.EncodingName != null)
            {
                try
                {
                    encoding = Claunia.Encoding.Encoding.GetEncoding(options.EncodingName);
                    if (options.Verbose)
                    {
                        DicConsole.VerboseWriteLine("Using encoding for {0}.", encoding.EncodingName);
                    }
                }
                catch (ArgumentException)
                {
                    DicConsole.ErrorWriteLine("Specified encoding is not supported.");
                    return;
                }
            }

            if (options.DevicePath.Length == 2 && options.DevicePath[1] == ':' && options.DevicePath[0] != '/' &&
                char.IsLetter(options.DevicePath[0]))
            {
                options.DevicePath = "\\\\.\\" + char.ToUpper(options.DevicePath[0]) + ':';
            }

            Device dev = new Device(options.DevicePath);

            if (dev.Error)
            {
                DicConsole.ErrorWriteLine("Error {0} opening device.", dev.LastError);
                return;
            }

            Core.Statistics.AddDevice(dev);

            string outputPrefix = Path.Combine(Path.GetDirectoryName(options.OutputFile),
                                               Path.GetFileNameWithoutExtension(options.OutputFile));

            Resume        resume = null;
            XmlSerializer xs     = new XmlSerializer(typeof(Resume));

            if (File.Exists(outputPrefix + ".resume.xml") && options.Resume)
            {
                try
                {
                    StreamReader sr = new StreamReader(outputPrefix + ".resume.xml");
                    resume = (Resume)xs.Deserialize(sr);
                    sr.Close();
                }
                catch
                {
                    DicConsole.ErrorWriteLine("Incorrect resume file, not continuing...");
                    return;
                }
            }

            if (resume != null && resume.NextBlock > resume.LastBlock && resume.BadBlocks.Count == 0)
            {
                DicConsole.WriteLine("Media already dumped correctly, not continuing...");
                return;
            }

            CICMMetadataType sidecar   = null;
            XmlSerializer    sidecarXs = new XmlSerializer(typeof(CICMMetadataType));

            if (options.CicmXml != null)
            {
                if (File.Exists(options.CicmXml))
                {
                    try
                    {
                        StreamReader sr = new StreamReader(options.CicmXml);
                        sidecar = (CICMMetadataType)sidecarXs.Deserialize(sr);
                        sr.Close();
                    }
                    catch
                    {
                        DicConsole.ErrorWriteLine("Incorrect metadata sidecar file, not continuing...");
                        return;
                    }
                }
                else
                {
                    DicConsole.ErrorWriteLine("Could not find metadata sidecar, not continuing...");
                    return;
                }
            }

            PluginBase            plugins    = new PluginBase();
            List <IWritableImage> candidates = new List <IWritableImage>();

            // Try extension
            if (string.IsNullOrEmpty(options.OutputFormat))
            {
                candidates.AddRange(plugins.WritableImages.Values.Where(t =>
                                                                        t.KnownExtensions
                                                                        .Contains(Path.GetExtension(options
                                                                                                    .OutputFile))));
            }
            // Try Id
            else if (Guid.TryParse(options.OutputFormat, out Guid outId))
            {
                candidates.AddRange(plugins.WritableImages.Values.Where(t => t.Id.Equals(outId)));
            }
            // Try name
            else
            {
                candidates.AddRange(plugins.WritableImages.Values.Where(t => string.Equals(t.Name, options.OutputFormat,
                                                                                           StringComparison
                                                                                           .InvariantCultureIgnoreCase)));
            }

            if (candidates.Count == 0)
            {
                DicConsole.WriteLine("No plugin supports requested extension.");
                return;
            }

            if (candidates.Count > 1)
            {
                DicConsole.WriteLine("More than one plugin supports requested extension.");
                return;
            }

            IWritableImage outputFormat = candidates[0];

            DumpLog dumpLog = new DumpLog(outputPrefix + ".log", dev);

            if (options.Verbose)
            {
                dumpLog.WriteLine("Output image format: {0} ({1}).", outputFormat.Name, outputFormat.Id);
                DicConsole.VerboseWriteLine("Output image format: {0} ({1}).", outputFormat.Name, outputFormat.Id);
            }
            else
            {
                dumpLog.WriteLine("Output image format: {0}.", outputFormat.Name);
                DicConsole.WriteLine("Output image format: {0}.", outputFormat.Name);
            }

            switch (dev.Type)
            {
            case DeviceType.ATA:
                Ata.Dump(dev, options.DevicePath, outputFormat, options.RetryPasses, options.Force, options.Raw,
                         options.Persistent, options.StopOnError, ref resume, ref dumpLog, encoding, outputPrefix,
                         options.OutputFile, parsedOptions, sidecar, (uint)options.Skip, options.NoMetadata,
                         options.NoTrim);
                break;

            case DeviceType.MMC:
            case DeviceType.SecureDigital:
                SecureDigital.Dump(dev, options.DevicePath, outputFormat, options.RetryPasses, options.Force,
                                   options.Raw, options.Persistent, options.StopOnError, ref resume, ref dumpLog,
                                   encoding, outputPrefix, options.OutputFile, parsedOptions, sidecar,
                                   (uint)options.Skip, options.NoMetadata, options.NoTrim);
                break;

            case DeviceType.NVMe:
                NvMe.Dump(dev, options.DevicePath, outputFormat, options.RetryPasses, options.Force, options.Raw,
                          options.Persistent, options.StopOnError, ref resume, ref dumpLog, encoding, outputPrefix,
                          options.OutputFile, parsedOptions, sidecar, (uint)options.Skip, options.NoMetadata,
                          options.NoTrim);
                break;

            case DeviceType.ATAPI:
            case DeviceType.SCSI:
                Scsi.Dump(dev, options.DevicePath, outputFormat, options.RetryPasses, options.Force, options.Raw,
                          options.Persistent, options.StopOnError, ref resume, ref dumpLog, options.LeadIn,
                          encoding, outputPrefix, options.OutputFile, parsedOptions, sidecar, (uint)options.Skip,
                          options.NoMetadata, options.NoTrim);
                break;

            default:
                dumpLog.WriteLine("Unknown device type.");
                dumpLog.Close();
                throw new NotSupportedException("Unknown device type.");
            }

            if (resume != null && options.Resume)
            {
                resume.LastWriteDate = DateTime.UtcNow;
                resume.BadBlocks.Sort();

                if (File.Exists(outputPrefix + ".resume.xml"))
                {
                    File.Delete(outputPrefix + ".resume.xml");
                }

                FileStream fs = new FileStream(outputPrefix + ".resume.xml", FileMode.Create, FileAccess.ReadWrite);
                xs = new XmlSerializer(resume.GetType());
                xs.Serialize(fs, resume);
                fs.Close();
            }

            dumpLog.Close();

            Core.Statistics.AddCommand("dump-media");
        }
Ejemplo n.º 13
0
        internal static void DoDeviceReport(DeviceReportOptions options)
        {
            DicConsole.DebugWriteLine("Device-Report command", "--debug={0}", options.Debug);
            DicConsole.DebugWriteLine("Device-Report command", "--verbose={0}", options.Verbose);
            DicConsole.DebugWriteLine("Device-Report command", "--device={0}", options.DevicePath);

            if (options.DevicePath.Length == 2 && options.DevicePath[1] == ':' && options.DevicePath[0] != '/' &&
                char.IsLetter(options.DevicePath[0]))
            {
                options.DevicePath = "\\\\.\\" + char.ToUpper(options.DevicePath[0]) + ':';
            }

            Device dev = new Device(options.DevicePath);

            if (dev.Error)
            {
                DicConsole.ErrorWriteLine("Error {0} opening device.", dev.LastError);
                return;
            }

            Core.Statistics.AddDevice(dev);

            Metadata.DeviceReport report = new Metadata.DeviceReport();
            bool   removable             = false;
            string xmlFile;

            if (!string.IsNullOrWhiteSpace(dev.Manufacturer) && !string.IsNullOrWhiteSpace(dev.Revision))
            {
                xmlFile = dev.Manufacturer + "_" + dev.Model + "_" + dev.Revision + ".xml";
            }
            else if (!string.IsNullOrWhiteSpace(dev.Manufacturer))
            {
                xmlFile = dev.Manufacturer + "_" + dev.Model + ".xml";
            }
            else if (!string.IsNullOrWhiteSpace(dev.Revision))
            {
                xmlFile = dev.Model + "_" + dev.Revision + ".xml";
            }
            else
            {
                xmlFile = dev.Model + ".xml";
            }

            xmlFile = xmlFile.Replace('\\', '_').Replace('/', '_').Replace('?', '_');

            switch (dev.Type)
            {
            case DeviceType.ATA:
                Ata.Report(dev, ref report, options.Debug, ref removable);
                break;

            case DeviceType.MMC:
            case DeviceType.SecureDigital:
                SecureDigital.Report(dev, ref report);
                break;

            case DeviceType.NVMe:
                Nvme.Report(dev, ref report, options.Debug, ref removable);
                break;

            case DeviceType.ATAPI:
            case DeviceType.SCSI:
                General.Report(dev, ref report, options.Debug, ref removable);
                break;

            default: throw new NotSupportedException("Unknown device type.");
            }

            FileStream xmlFs = new FileStream(xmlFile, FileMode.Create);

            XmlSerializer xmlSer = new XmlSerializer(typeof(Metadata.DeviceReport));

            xmlSer.Serialize(xmlFs, report);
            xmlFs.Close();
            Core.Statistics.AddCommand("device-report");

            if (Settings.Settings.Current.ShareReports)
            {
                Remote.SubmitReport(report);
            }
        }
        public AdicionarAtaEmUmaReuniaoResposta AdicionarAtaEmUmaReuniao(AdicionarAtaEmUmaReuniaoRequisicao requisicao)
        {
            var resposta = new AdicionarAtaEmUmaReuniaoResposta();

            var reuniao = _reuniaoRepositorio.ObterPor(requisicao.CodigoDaReuniao);
            var responsavel = _funcionarioRepositorio.ObterPor(requisicao.CodigoDoResponsavel);
            try
            {
                var ata = new Ata(responsavel)
                              {
                                  Assunto = requisicao.Assunto,
                                  FinalDoPrazo = requisicao.FinalDoPrazo,
                                  InicioDoPrazo = requisicao.InicioDoPrazo,
                                  Anotacoes = requisicao.Anotacoes,
                                  Status = requisicao.Status,
                              };

                reuniao.AdicionarAta(ata);
                resposta.Ata = ata;
                _unitOfWork.Commit();
                resposta.Sucesso = true;
            }
            catch (RegraException regraException)
            {
                resposta.Erros = regraException.Erros;
            }
            return resposta;
        }