protected override List <ScanResult> ScanSelfText(ScanSource textSource) { var result = new List <ScanResult>(); List <string> rowsList = _textUtil.SplitTextToRows(textSource.Text); Dictionary <string, int> selfDuplCode = _selfTextScanner.Scan(rowsList); foreach (var selfDupl in selfDuplCode) { var resObj = new ScanResult() { DuplicateText = selfDupl.Key, DuplicateFilesInfos = new List <FileWithDuplicates>() { new FileWithDuplicates() { Name = textSource.Name, Path = textSource.Path, DupliateItemCount = selfDupl.Value } } }; result.Add(resObj); } return(result); }
private List<Image> GetPagesFromScanner(ScanSource source, Item item) { SetDeviceProperty(ref _device, 3088, (int)source); List<Image> images = new List<Image>(); int handlingStatus = GetDeviceProperty(ref _device, WIA_DPS_DOCUMENT_HANDLING_STATUS); if ((source == ScanSource.DocumentFeeder && handlingStatus == FEED_READY) || (source == ScanSource.Flatbed && handlingStatus == FLATBED_READY)) { do { ImageFile wiaImage = null; try { wiaImage = item.Transfer(WIA_FORMAT_JPEG); } catch (COMException ex) { if ((uint)ex.ErrorCode == WIA_ERROR_PAPER_EMPTY) break; else throw; } if (wiaImage != null) { System.Diagnostics.Trace.WriteLine(String.Format("Image is {0} x {1} pixels", (float)wiaImage.Width / 150, (float)wiaImage.Height / 150)); Image image = ConvertToImage(wiaImage); images.Add(image); } } while (source == ScanSource.DocumentFeeder); } return images; }
protected override List <ScanResult> ScanSources(ScanSource textSource) { var result = new List <ScanResult>(); List <string> rowsList = _textUtil.SplitTextToRows(textSource.Text); foreach (var itemScanSource in _textsForScan) { List <string> itemRowsList = _textUtil.SplitTextToRows(itemScanSource.Text); string processedText = ""; Dictionary <string, int> dupliateTexts = TextRowsCompare(rowsList, itemRowsList, out processedText); itemScanSource.Text = processedText; foreach (var duplItem in dupliateTexts) { if (result.Any(w => w.DuplicateText == duplItem.Key)) { ScanResult scanResultItem = result.First(w => w.DuplicateText == duplItem.Key); var duplFileInfo = new FileWithDuplicates() { Name = itemScanSource.Name, Path = itemScanSource.Path, DupliateItemCount = duplItem.Value }; scanResultItem.DuplicateFilesInfos.Add(duplFileInfo); } else { var selfSourceInfo = new FileWithDuplicates() { Name = textSource.Name, Path = textSource.Path, DupliateItemCount = 1 }; var duplSourceInfo = new FileWithDuplicates() { Name = itemScanSource.Name, Path = itemScanSource.Path, DupliateItemCount = duplItem.Value }; var scanResultItem = new ScanResult() { DuplicateText = duplItem.Key, DuplicateFilesInfos = new List <FileWithDuplicates>() { selfSourceInfo, duplSourceInfo } }; result.Add(scanResultItem); } } } return(result); }
public ScanEntry(string protocol , int port , string state , string nmapNameNew , string nmapNameOriginal , string version , bool tls , int confidence , string osType , ScanSource source) { if (protocol == "tcp") { this.Protocol = ServiceProtocol.tcp; } else if (protocol == "udp") { this.Protocol = ServiceProtocol.udp; } else { throw new NotImplementedException(String.Format("ServiceProtocol '{0}' not implemented.", protocol)); } if (state == "open") { this.State = ServiceState.open; } else if (state == "closed") { this.State = ServiceState.closed; } else if (state == "filtered") { this.State = ServiceState.filtered; } else if (state == "open|filtered") { this.State = ServiceState.openFiltered; } else if (state == "closed|filtered") { this.State = ServiceState.closedFiltered; } else { throw new NotImplementedException(String.Format("Service state '{0}' not implemented.", state)); } this.Port = port; this.NmapNameNew = nmapNameNew; this.NmapNameOriginal = confidence != 10 && !string.IsNullOrEmpty(nmapNameOriginal) ? String.Format("{0}?", nmapNameOriginal) : nmapNameOriginal; this.Version = version; this.Confidence = confidence; this.OsType = osType; this.Tls = tls; this.Source = source; }
private async Task <List <Image> > GetPagesFromScanner(ScanSource source, Item item) { SetDeviceProperty(ref _device, 3088, (int)source); List <Image> images = new List <Image>(); try { int handlingStatus = GetDeviceProperty(ref _device, WIA_DPS_DOCUMENT_HANDLING_STATUS); Debug.Write(source); // ICommonDialog wiaDiag = new WIA.CommonDialog(); //var res = wiaDiag.show(this._device, WiaImageIntent.UnspecifiedIntent, WiaImageBias.MaximizeQuality, false, true, false); do { ImageFile wiaImage = null; try { // wiaImage = wiaDiag.ShowTransfer(item); // SplashScreenManager.ShowForm(this, typeof(frm), true, true, SplashFormStartPosition.Default, new Point(0, 0), ParentFormState.Locked); wiaImage = await Task.Run(() => item.Transfer(WIA_FORMAT_JPEG)); // SplashScreenManager.CloseForm(); } catch (COMException ex) { if ((uint)ex.ErrorCode == WIA_ERROR_PAPER_EMPTY) { break; } } if (wiaImage != null) { System.Diagnostics.Trace.WriteLine(String.Format("Image is {0} x {1} pixels", (float)wiaImage.Width / 150, (float)wiaImage.Height / 150)); Image image = ConvertToImage(wiaImage); images.Add(image); } } while (source == ScanSource.DocumentFeeder); } catch (Exception ex) { //MessageBox.Show(ex.Message, ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error); } return(images); }
public ScanEntry(ScanEntry entry) { this.Host = entry.Host; this.Protocol = entry.Protocol; this.State = entry.State; this.Port = entry.Port; this.Tls = entry.Tls; this.NmapNameNew = entry.NmapNameNew; this.NmapNameOriginal = entry.NmapNameOriginal; this.Version = entry.Version; this.Confidence = entry.Confidence; this.OsType = entry.OsType; this.Scan = entry.Scan; this.Source = entry.Source; }
/// <summary> /// Search duplicated code in text sources /// </summary> /// <returns></returns> public List <ScanResult> SearchDuplicates() { var result = new List <ScanResult>(); while (_textsForScan.Count > 0) { ScanSource currText = _textsForScan.Dequeue(); List <ScanResult> selfScanResult = ScanSelfText(currText); List <ScanResult> sourcesScanResult = ScanSources(currText); List <ScanResult> mergedScanResult = MergeScanResults(selfScanResult, sourcesScanResult); if (mergedScanResult.Count > 0) { result.AddRange(sourcesScanResult); } } return(result); }
public XmlScanLoaderBase(string[] files , List <ServiceState> states , ScanSource scanSource) : base() { this.BackgroundWorker = null; this.EventArguments = null; this.Files = files; this.States = states; this.Source = scanSource; this.exceptions = new List <Exception>(); if (scanSource == ScanSource.nmap) { this.XmlBaseBath = "/nmaprun/host"; } else if (scanSource == ScanSource.nessus) { this.XmlBaseBath = "/NessusClientData_v2/Report/ReportHost"; } else { throw new NotImplementedException(String.Format("Scan source '{0}' not implemented.", scanSource.ToString())); } }
static void Main(string[] args) { Console.Clear(); Console.WriteLine("======================"); string text1 = "Row1\r\n" + "Row2\r\n" + "\tRow3\r\n" + "Row1\r\n" + "Row2\r\n" + "Row2.1"; string text2 = "row1.1\r\n" + "row1.2\r\n" + "row1.3\r\n" + "row2\r\n" + "row3\r\n" + "row4\r\n" + "row4.1\r\n" + "row1.1\r\n" + "row1.2\r\n" + "row1.3\r\n" + "row2\r\n" + "row3\r\n" + "row4\r\n" + "row1.1\r\n" + "row1.2\r\n" + "row1.3\r\n"; string text3 = "Row1.1\r\n" + "Row1.2\r\n" + "Row1.3\r\n" + "row2\r\n" + "row3\r\n" + "row4\r\n" + "Row1\r\n" + "Row2\r\n" + "Row3\r\n"; string realFilePath = @"/Users/macbookair/Desktop/test.php"; var realSource = new ScanSource() { Name = Path.GetFileName(realFilePath), Path = realFilePath, Text = File.ReadAllText(realFilePath) }; var sourceQueue = new Queue <ScanSource>(); //sourceStack.Push(new ScanSource() { Name = "Text1", Text = text1 }); //sourceStack.Push(new ScanSource() { Name = "Text2", Text = text2 }); //sourceStack.Push(new ScanSource() { Name = "Text3", Text = text3 }); sourceQueue.Enqueue(realSource); var stopWatch = System.Diagnostics.Stopwatch.StartNew(); SearcherBase scanerObj = new RowByRowScanner(sourceQueue); List <ScanResult> res = scanerObj.SearchDuplicates(); stopWatch.Stop(); Console.WriteLine($"Calc time => {stopWatch.ElapsedMilliseconds} mlsec"); //Console.WriteLine($"TotalIterationCount = {scanerObj.TotalIterationCount}"); string resJson = JsonConvert.SerializeObject(res.OrderByDescending(r => r.TotalItems), Formatting.Indented); Console.WriteLine(resJson); Console.WriteLine("Done!"); Console.ReadKey(); Console.Clear(); }
/// <summary> /// Scan text source on duplicate code in other sources /// </summary> /// <param name="textSource">Source text for scan</param> /// <returns></returns> protected abstract List <ScanResult> ScanSources(ScanSource textSource);