Saving A Specific Node As HTML Using HtmlAgilityPack - c#

I have a web site that displays a table along with some buttons, navigation tabs, etc. Using HtmlAgilityPack I would like to save only the node containing the table (a div) to a .html file. I have been experimenting with this code:
string dashboard = doc.DocumentNode.SelectSingleNode("//div[#id='Dashboard']").InnerHtml;
doc.LoadHtml(dashboard);
doc.Save(currDir + "\\dashboardOutputFile.html");
But this only preserves the text components of the table and none of its layout/display information. I have tried adding a Doctype declaration as well as enclosing html and body tags to the dashboard string but it has no effect.
Any advice is appreciated.
Regards.
EDIT:
I should be more explicit. I am capturing the html of my page by overriding the Render method:
protected override void Render(HtmlTextWriter writer)
{
using (HtmlTextWriter htmlwriter = new HtmlTextWriter(new StringWriter()))
{
base.Render(htmlwriter);
string renderedContent = htmlwriter.InnerWriter.ToString();
var doc = new HtmlDocument();
doc.LoadHtml(renderedContent);
try
{
string dashboard = doc.DocumentNode.SelectSingleNode("//div[#id='Dashboard']").InnerHtml;
dashboard = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><br><html xmlns=\"http://www.w3.org/1999/xhtml\"><head></head><body><div><br>" + dashboard + "<br></div></body></html>";
doc.LoadHtml(dashboard);
doc.Save(currDir + "\\dashboardOutputFile.html");
}
catch (NullReferenceException ex)
{
// Do nothing.
}
writer.Write(renderedContent);
}
}
To the best of my knowledge the string "dashboard" should contain a complete HTML page after this. However the resulting .html file displays like this:
INCIDENT MANAGEMENT
Jun '12 F'12
Trend F'12 2011
(avg)
Severe Incidents (Sev1/2): 2 2 4.16
Severe Avoidable Incidents (Sev1/2): 1 1.3 1.91
Incidents (Sev3): 600 459 460.92
Incidents (Sev4) - No business Impact: 869 782 793
Proactive Tickets Opened: 24 20 14
Proactive Tickets Resolved/Closed: 22 17.8 11
CHANGE MANAGEMENT
Total Planned Changes: 623 564 583.58
Change Success Rate (%): 99.9 99.4 99
Non-Remedial Urgent Changes: 5 11.4 47.08
PROBLEM MANAGEMENT
New PIRs: 1 1.4 2
Closed PIRs: 1 2.3 3
Overdue Action items: 2 3.4 0
COMPLIANCE MEASUREMENTS
Jun Trend May
Total Number of Perimeter Devices: 258 242
Perimeter Devices - Non Compliant: 31 7
Total Number of Internal Devices: 6632 6521
Internal Devices - Non Compliant: 160 38
Unauthorized Perimeter Changes: 0 0
Unauthorized Internal Changes 0 0
LEGEND
ISP LINKS
June May Trend
SOC CPO DRP SOC CPO DRP
39% 35% 74% 38% 35% 73%
BELL MPLS HEAD ENDS
June May Trend
SOC CPO SOC CPO
8% 5.5% 7% 10% 7.5% 5% 6% 10%
ENTERPRISE NETWORK (# of issues called out)
June May Trend
CORE FW/DMZ CORE FW/DMZ
1 0 1 0
US & INTL (# of issues called out)
June May Trend
US Intl US Intl
2 3 2 3
LINE OF BUSINESS BELL WAN MPLS
<> 50%-65% >65% <> 50%-65% >65% Trend
Retail: 2269 4 0 2271 2 0
Business Banking: 60 0 0 51 1 0
Wealth: 121 2 1 111 3 2
Corporate: 49 2 0 51 1 1
Remote ATM: 280 0 0 279 0 0
TOOLS
Version Currency Vulnerability Status Health Status
Key Messages:
Only the text of the table cells is being displayed. There is no table layout, no background colours, etc. Even when I copy the file into JSFiddle it displays like this. What am I missing to make this a complete HTML page?

There's probably a css file linked into the original html not being read in your downloaded page.

Related

Read printer status after writing test string

I'm trying to write a string to a serial port, then send a command to tell the printer to return it's status in real time, if OK then send the next string.
I know how to create the form, create a serial port and write my string:
serialPort.Write("ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMN\n");
// send command to read status
// if status = 4, warn user & close port, if not...
// send next string
serialPort.Write("ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMN\n");
Where I'm having trouble is sending & receiving the real time status.
The command is:
Transmit real-time status
ASCII DLE EOTn [a]
Hex 10 04 n [a]
Decimal 16 4 n [a]
TM-T90, TM-T88IV, TM-U220 : 1 ≤ n ≤ 4, n = 7
TM-L90: 1 ≤ n ≤ 4, n = 8, a = 3 (when n = 8) (TM-L90 with Peeler)
1 ≤ n ≤ 4 (TM-L90 without Peeler)
n a Function
1 -- Transmit printer status
2 -- Transmit offline status
3 -- Transmit error status
4 -- Transmit roll paper sensor status
7 1 Transmit ink status A
2 Transmit ink status B
8 3 Transmit peeler status
All I care about is where n = 4 (Transmit roll paper sensor status)
If n returns 4, stop and close port with message to user that paper is low.
I will be using the same program for a 4 printers listed, like I said all I care about is if the status changes from 0 to 4.
I hope someone can help. Thank you.

How can we get Disk Performance info in C#

I want to get the following information about the disk performance.
I used MSStorageDriver_FailurePredictThresholds, MSStorageDriver_ATAPISmartData, MSStorageDriver_FailurePredictStatus class to get relative information but not getting the right result.
This isn't everything you wanted, but the Win32_PerfFormattedData_PerfDisk_PhysicalDisk WMI class gives you current read / write / transfer rate and activity time. It also gives some averages but I'm not sure how they are calculated (it seems odd that AvgDiskBytesPerWrite is 0)
// NOTE: Use ManagementObjectSearcher to find the path your interested in
var path = "Win32_PerfFormattedData_PerfDisk_PhysicalDisk.Name='0 C:'";
var wmiObj = new ManagementObject(path);
wmiObj.Properties.Cast<PropertyData>().ToDictionary(p => p.Name, p => p.Value).Dump();
/* OUTPUT */
AvgDiskBytesPerRead 63167
AvgDiskBytesPerTransfer 63167
AvgDiskBytesPerWrite 0
AvgDiskQueueLength 0
AvgDiskReadQueueLength 0
AvgDisksecPerRead 0
AvgDisksecPerTransfer 0
AvgDisksecPerWrite 0
AvgDiskWriteQueueLength 0
Caption null
CurrentDiskQueueLength 0
Description null
DiskBytesPersec 20991616
DiskReadBytesPersec 20991616
DiskReadsPersec 332
DiskTransfersPersec 332
DiskWriteBytesPersec 0
DiskWritesPersec 0
Frequency_Object null
Frequency_PerfTime null
Frequency_Sys100NS null
Name 0 C:
PercentDiskReadTime 80
PercentDiskTime 80
PercentDiskWriteTime 0
PercentIdleTime 32
SplitIOPerSec 0
Timestamp_Object null
Timestamp_PerfTime null
Timestamp_Sys100NS null
if you looking for this, check this Link. An example of output is:
###############################################################
Current Directory Path: D:\WinDDK\32bit\drivespeed
Total MB 230000, Free MB 103752, Used MB 126248
Windows Storage Speed Test 32-Bit Version 1.2, Thu Mar 01 22:31:08 2012
Copyright (C) Roy Longbottom 2011
8 MB File 1 2 3 4 5
Writing MB/sec 56.68 105.37 61.95 72.48 75.33
Reading MB/sec 80.65 108.15 81.10 81.42 82.25
16 MB File 1 2 3 4 5
Writing MB/sec 81.53 94.61 81.41 88.06 71.39
Reading MB/sec 88.25 72.75 93.53 93.51 92.70
32 MB File 1 2 3 4 5
Writing MB/sec 90.35 83.60 72.52 80.24 72.71
Reading MB/sec 87.00 87.67 78.39 80.24 78.62
---------------------------------------------------------------------
8 MB Cached File 1 2 3 4 5
Writing MB/sec 703.27 628.08 1050.99 1617.29 1609.70
Reading MB/sec 1930.60 2045.13 2054.49 2135.91 2390.08
---------------------------------------------------------------------
Bus Speed Block KB 64 128 256 512 1024
Reading MB/sec 174.36 189.07 221.83 247.82 261.21
---------------------------------------------------------------------
1 KB Blocks File MB > 2 4 8 16 32 64 128
Random Read msecs 0.14 0.14 0.15 0.17 3.24 6.96 8.90
Random Write msecs 0.53 0.66 1.03 1.38 1.74 1.83 2.42
---------------------------------------------------------------------
500 Files Write Read Delete
File KB MB/sec ms/File MB/sec ms/File Seconds
2 0.32 6.44 0.95 2.17 0.123
4 6.49 0.63 12.21 0.34 0.113
8 11.54 0.71 15.17 0.54 0.121
16 22.04 0.74 41.78 0.39 0.116
32 32.92 1.00 26.31 1.25 0.074
64 68.72 0.95 51.88 1.26 0.132
End of test Thu Mar 01 22:32:11 2012

FFMPEG - Scrambled Output converting from VOB with ffmpeg

I've concatenated a series of VOB files from a DVD into a single VOB file and I am trying to convert it to MP4 or other similar format. I see a lot of errors when converting and the output appears scrambled.
>ffmpeg.exe" -i file.vob -sameq file.mp4
FFmpeg version git-N-29181-ga304071, Copyright (c) 2000-2011 the FFmpeg develope
rs
built on Apr 18 2011 21:24:03 with gcc 4.5.2
configuration: --enable-gpl --enable-version3 --enable-runtime-cpudetect --ena
ble-memalign-hack --enable-avisynth --enable-bzlib --enable-frei0r --enable-libo
pencore-amrnb --enable-libopencore-amrwb --enable-libfreetype --enable-libgsm --
enable-libmp3lame --enable-libopenjpeg --enable-librtmp --enable-libschroedinger
--enable-libspeex --enable-libtheora --enable-libvorbis --enable-libvpx --enabl
e-libx264 --enable-libxavs --enable-libxvid --enable-zlib --cross-prefix=i686-w6
4-mingw32- --target-os=mingw32 --arch=x86_32 --extra-cflags=-I/home/kyle/softwar
e/ffmpeg/external-libraries/win32/include --extra-ldflags=-L/home/kyle/software/
ffmpeg/external-libraries/win32/lib --pkg-config=pkg-config
libavutil 50. 40. 1 / 50. 40. 1
libavcodec 52.120. 0 / 52.120. 0
libavformat 52.108. 0 / 52.108. 0
libavdevice 52. 4. 0 / 52. 4. 0
libavfilter 1. 79. 0 / 1. 79. 0
libswscale 0. 13. 0 / 0. 13. 0
[mpeg2video # 01751A90] ac-tex damaged at 5 16
[mpeg2video # 01751A90] invalid mb type in I Frame at 0 1
[mpeg2video # 01751A90] invalid mb type in I Frame at 0 2
[mpeg2video # 01751A90] invalid mb type in I Frame at 0 3
[mpeg2video # 01751A90] invalid mb type in I Frame at 0 4
[...]
I'm guessing this is CSS scrambling and I need to do some sort of DeCSS. Does FFMpeg have an option for this? Cringe if you'd like, but is there C# source to achieve this?
My end goal is really just to get some DVDs that I own onto my media server. I've tried a few demo-ware products with limited success including Acala DVD Ripper, Click to Disk, AVIDemux to name a few. I even paid for a couple of them to get the full version, but Acala only works for about half of my DVDs and Click to Disk can decode the VOB, but I need to use FFMpeg to convert. I'd like to have it all in one app that works and I am willing to write some code for it.

HtmlAgilityPack Save Process Not Letting Go Of File

I am saving some of the rendered html of a web site by overriding the Render method and using HtmlAgilityPack. Here is the code:
protected override void Render(HtmlTextWriter writer)
{
using (HtmlTextWriter htmlwriter = new HtmlTextWriter(new StringWriter()))
{
base.Render(htmlwriter);
string output= htmlwriter.InnerWriter.ToString();
var doc = new HtmlDocument();
doc.LoadHtml(output);
doc.Save(currDir + "\\" + reportDir + "\\dashboardTable.html");
}
}
However, some process does not let go of the saved file and I am unable to delete it from the server. Does anyone know of an HtmlAgilityPack issue that would cause this?
Any advice is appreciated.
Regards.
EDIT:
I have tried both of the methods suggested. I can't tell if they are the solution yet because my app is frozen on the server due to the files I can't delete. However, when I use these solutions on my own machine, the rendered HTML does not save as an HTML table anymore but rather like this:
INCIDENT MANAGEMENT
Jul '12 F'12
Trend F'12 2011
(avg)
Severe Incidents (Sev1/2): 3 2.1 4.16
Severe Avoidable Incidents (Sev1/2): 1 1.3 1.91
Incidents (Sev3): 669 482 460.92
Incidents (Sev4) - No business Impact: 1012 808 793
Proactive Tickets Opened: 15 19.3 14
Proactive Tickets Resolved/Closed: 14 17.3 11
CHANGE MANAGEMENT
Total Planned Changes: 531 560 583.58
Change Success Rate (%): 99.5 99.4 99
Non-Remedial Urgent Changes: 6 11 47.08
PROBLEM MANAGEMENT
New PIRs: 2 1.4 2
Closed PIRs: 0 2 3
Overdue Action items: 2 3.2 0
COMPLIANCE MEASUREMENTS
Jul Trend Jun
Total Number of Perimeter Devices: 250 258
Perimeter Devices - Non Compliant: 36 31
Total Number of Internal Devices: 6676 6632
Internal Devices - Non Compliant: 173 160
Unauthorized Perimeter Changes: 0 0
Unauthorized Internal Changes 0 0
LEGEND
ISP LINKS
July June Trend
SOC CPO DRP SOC CPO DRP
40% 34% 74% 39% 35% 74%
BELL MPLS HEAD ENDS
July June Trend
SOC CPO SOC CPO
8% 5% 7% 10% 8% 5.5% 7% 10%
ENTERPRISE NETWORK (# of issues called out)
July June Trend
CORE FW/DMZ CORE FW/DMZ
1 0 1 0
US & INTL (# of issues called out)
July June Trend
US Intl US Intl
2 2 2 3
LINE OF BUSINESS BELL WAN MPLS
<> 50%-65% >65% <> 50%-65% >65% Trend
Retail: 2272 0 1 2269 4 0
Business Banking: 59 1 0 60 0 0
Wealth: 122 2 0 121 2 1
Corporate: 51 0 0 49 2 0
Remote ATM: 280 0 0 280 0 0
TOOLS
Version Currency Vulnerability Status Health Status
Key Messages:
where only the text data has been saved and all of the HTML and CSS is missing. If I just use doc.Save() I get an exact representation of the table as it displays on the website.
Try this instead. Maybe the Save method isn't closing the underlying stream.
using( FileStream stream = File.OpenWrite( currDir + "\\" + reportDir + "\\dashboardTable.html" ) ){
doc.Save(stream);
stream.Close();
}
Edit
Per #L.B's comments it appears that HtmlAgilityPack does use a using block as in my example so it will be ensuring that the stream gets closed.
Thus as I suggested at the end of my original answer this must be a server environment problem
Original Answer
This may be some sort of bug with HtmlAgilityPack - you may want to report it to the developers.
However to eliminate that possibility you may want to consider explicitly controlling the creation of the StreamWriter for the file so you are explicitly closing it yourself. Replace this line:
doc.Save(currDir + "\\" + reportDir + "\\dashboardTable.html");
With the following:
using (StreamWriter fileWriter = new StreamWriter(currDir + "\\" + reportDir + "\\dashboardTable.html"))
{
doc.Save(fileWriter);
fileWriter.Close();
}
If the issue still persists even with this change then that would suggest an issue with your server environment rather than an issue with HtmlAgilityPack. Btw to test if this change makes a difference you should start from a clean server environment rather than one where you are already having issues deleting the file in question.

using the xmldiffpatch class of microsoft with an attribute as ID

I want to use the xmldiffpatch class of microsoft
http://msdn.microsoft.com/en-us/library/aa302294.aspx
now is the question how I can say that I want to use the attribute model as my ID?
<PartPriceInfo xmlns:ns1="http://www.Subaru.com">
<ns1:Subaru model="Legacy">
<ns1:Muffler> 400 </ns1:Muffler>
<ns1:Bumper> 100 </ns1:Bumper>
<ns1:Floormat> 50 </ns1:Floormat>
<ns1:WindShieldWipers> 20 </ns1:WindShieldWipers>
</ns1:Subaru>
<ns1:Subaru model="Outback">
<ns1:Muffler> 500 </ns1:Muffler>
<ns1:Bumper> 150 </ns1:Bumper>
<ns1:Floormat> 75 </ns1:Floormat>
<ns1:WindShieldWipers> 20 </ns1:WindShieldWipers>
</ns1:Subaru>
</PartPriceInfo>
regards Chris

Categories

Resources