|
Nice code dump
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Please stand in front of my pistol, smile and wait for the flash - JSOP 2012
|
|
|
|
|
no formatting, no question; what is this?
|
|
|
|
|
|
Collin Jasnoch wrote: its "a module"
I see. That is exactly what I needed, I'll be borrowing it.
|
|
|
|
|
Luc Pattyn wrote: exactly what I needed
Probably a lot easier to use now...
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Please stand in front of my pistol, smile and wait for the flash - JSOP 2012
|
|
|
|
|
If I were you, I would ditch the commented out lines. I would also look into using string.IsNullOrEmpty (or string.IsNullOrWhitespace if you are using .NET 4).
As you've removed your code, here it is for anyone who wonders what my comments are about:
using System;
using System.Web;
using System.Xml;
public class SecurityHttpModule : IHttpModule
{
public SecurityHttpModule() { }
public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(Application_BeginRequest);
}
private void Application_BeginRequest(object source, EventArgs e)
{
HttpContext context = ((HttpApplication)source).Context;
string ipAddress = context.Request.UserHostAddress;
string strIPAddress = context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (strIPAddress == null || strIPAddress == "")
{
");
// st += " Key: " + myservab[i] + "
" ;
// string[] myservab2 = context.Request.ServerVariables.GetValues(myservab[i]);
// for (int j = 0; j < myservab2.Length; j++)
// {
// st1 += "Key : " + myservab[i] + " Value : " + myservab2[j] + "
";
// //Response.Write("Value " + myservab2 + ": " + Server.HtmlEncode(myservab2[j]) + "
");
// }
//}
strIPAddress = context.Request.ServerVariables["REMOTE_ADDR"].ToString();
}
if (!IsValidIpAddress(ipAddress))
{
context.Response.StatusCode = 403; // (Forbidden)
}
else
{
string filePath = context.Request.FilePath;
string fileExtension =
VirtualPathUtility.GetExtension(filePath);
if (fileExtension.Equals(".aspx"))
{
context.Response.Write("
" +
"HelloWorldModule: Beginning of Request" +
"
--------------------------------------------------------------------------------
");
}
}
}
private bool IsValidIpAddress(string ipAddress)
{
double myipnom = IPAddressToNumber(ipAddress);
//long myipnom = ip2ipno(ipAddress);
// long myipra = 3401007104;
string myip = ipno2ipaddress(myipnom);
bool sta = false;
Class1 obj = new Class1();
XmlDocument xmldoc = obj.getdata(myipnom);
//xmldoc.InnerXml
// XmlNodeList xmlist = xmldoc.SelectNodes("CountryIps[@*]");
XmlNodeList xmlist = xmldoc.GetElementsByTagName("CountryIps");
// XmlNodeList xmlist = xmldoc.InnerXml("NewDataSet[@*]");
//XmlNodeList xmll=xmldoc.InnerXml
foreach (XmlNode nl in xmlist)
{
if (nl != null)
{
// XmlNode tablexml = nl.SelectSingleNode("id");
string ipFrom = nl["ipFROM"].InnerXml;
string ipTo = nl["ipTO"].InnerXml;
string countrySHORT = nl["countrySHORT"].InnerXml;
string countryLONG = nl["countryLONG"].InnerXml;
bool conf;
if (ipFrom != null && ipTo != null)
{
conf = IsInRange(myipnom, double.Parse(ipFrom), double.Parse(ipTo));
if (conf == true && countrySHORT=="IN")
{
sta = true;
}
else { sta = false; }
}
}
else
{
sta = false;
}
}
return sta;
// return (ipAddress == "127.0.0.1");
}
public bool IsInRange(double ipNo, double ipFrom, double ipTo)
{
Int64 ipf= Convert.ToInt64(ipFrom);
Int64 ipn = Convert.ToInt64(ipNo);
Int64 ipt = Convert.ToInt64(ipTo);
return ipn >= ipf && ipn <= ipt;
}
public long ip2ipno(string ipAddress)
{
char[] splitchar = { '.' };
string[] strary = ipAddress.Split(splitchar);
long ipNo;
double ipno1;
double ipNumber, ipNumber1, ipNumber2, ipNumber3;
ipNumber = (Math.Pow(2, 24) * int.Parse(strary[0]));
ipNumber1 = (Math.Pow(2, 16) * int.Parse(strary[1]));
ipNumber2 = (Math.Pow(2, 8) * int.Parse(strary[2]));
ipNumber3 = int.Parse(strary[3]);
ipno1 = (ipNumber + ipNumber1+ ipNumber2 + ipNumber3);
ipNo = (Convert.ToInt64(ipNumber) + Convert.ToInt64( ipNumber1 )+ Convert.ToInt32( ipNumber2 )+ Convert.ToInt32(ipNumber3));
return ipNo;
}
public double IPAddressToNumber(string IPaddress)
{
int i;
string[] arrDec;
double num = 0;
if (IPaddress == "")
{
return 0;
}
else
{
arrDec = IPaddress.Split('.');
for (i = arrDec.Length - 1; i >= 0; i = i - 1)
{
num += ((int.Parse(arrDec[i]) % 256) * Math.Pow(256, (3 - i)));
}
return num;
}
}
public string ipno2ipaddress(double ipNo)
{
double w, x, y, z;
w = (ipNo / 16777216) % 256;
x = (ipNo / 65536) % 256;
y = (ipNo / 256) % 256;
z = (ipNo) % 256;
int w1 = Convert.ToInt16(Math.Floor(w));
int x1 = Convert.ToInt16(Math.Floor(x));
int y1 = Convert.ToInt16(Math.Floor(y));
int z1 = Convert.ToInt16(Math.Floor(z));
//int w1 = Math.Floor(w);
return (w1)+ "." + Convert.ToInt32(x1) + "." + Convert.ToInt32(y1) + "." + Convert.ToInt32(z1);
}
public void Dispose() { /* clean up */ }
}
//XmlDocument xml = new XmlDocument();
//xml.LoadXml(myXmlString); //myXmlString is the xml file in string //copying xml to string: string myXmlString = xmldoc.OuterXml.ToString();
//XmlNodeList xnList = xml.SelectNodes("/Element[@*]/ANode/BNode/CNode");
//foreach (XmlNode xn in xnList)
//{
// XmlNode example = xn.SelectSingleNode("Example");
// if (example != null)
// {
// string na = example["Name"].InnerText;
// string no = example["NO"].InnerText;
// }
//}
|
|
|
|
|
Hi,all
I am using dataset and and placing two tables on dataset.xsd pane from my database. so it is valid or i have to manually create tables by right clicking on dataset.xsd pane and select new table.
And if it is valid,then i am fetching data from database of that two tables. So what should i write in adapter.fill(i.e. ds,"which table name");
beacause i am getting my report blank.even if there is data in dataset.
and if i create only one datatable with the columns from two tables in the dataset..i am only getting first row on the report..but actually there are 3 rows..so i m not getting the problem
|
|
|
|
|
Hello guys. I have a Tab Control in which I have placed two Form s. The advantage of this approach is: I designed the Form separately and it has it's own class (unlike TabPage). TabPage is the parent and the Windows Form is the child control here.
But I am having a small problem. When I run the application, the GUI of the the forms is little disturbed. I mean the controls were not there, where I placed them.
NOTE: I also ran the application by modifying form's size w.r.t tab's size but it did not help much: like this
Form1.Height = Tab1.Height;
Form1.Width = Tab1.Width;
If don't change form's original size and show it in messagebox, then this does not show original size which I set at the design time. What could I do to tackle this issue? Thanks for any pointers.
This world is going to explode due to international politics, SOON.
modified 16-Jul-12 5:20am.
|
|
|
|
|
First of all, you can also use a UserControl instead of placing forms in tab pages. Also have a look at the Anchor property[^]
|
|
|
|
|
Obaid ur Rehman wrote: you can also use a UserControl instead of placing forms
Magar yeh meri application requirement nhi hai. Agar main aisa karta to mujhay UserControl ka code bhi apnay customer ko dena parhay ga, jo keh main nhi chahta. Waisay bhi, kitna ajeeb lagay gaa jab hum pooray ka poora inventory form design kar kay, ussay UserControl bnaa dain.
I have seen people preferring my approach over the one you suggested. I think it depends mostly on application requirement.
This world is going to explode due to international politics, SOON.
|
|
|
|
|
Hi, all
There is a WebBrowser in my program. The user select a HtmlElement in the WebBrowser of my program, by a mouse click. So, the program can use the function GetElementFromPoint to detecte which HtmlElement is selected:
HtmlElement htmlEM=GetElementFromPoint(...);
As a result, the program can get all the information using the htmlEM if needed. Then the program writes some information on the hard-disk, and quit. At last, the user runs the program again. and the program reads the information on the hard-disk, and the WebBrowser navigates to the Website again, and automatically gets back the HtmlElement selected just now.
The question is : what information should be write down for the program to get the HtmlElement back?
Since the htmlEM is selected by the user, it could be any HtmlElement, may be a <div>,<p> or even an <iframe>. We don't sure it have an id or not, Also, we don't know its InnerText, it may be the current time, and changes with the time. Even worse, it may be a floating <div>, containing an note or a AD, and keeps moving all the time.
I think the URL of the website will be needed, since the software needs it to navitate to the website again.
However, I don't what to do next. Help is needed.
The question is : what information should be write down for the software to get the HtmlElement back?
modified 16-Jul-12 4:09am.
|
|
|
|
|
The most important information would be the URL so you can navigate back to that page. In order to get back to the exact point that the user chose you would probably need to traverse back up the DOM tree to an element that can be identified, and note all the items in that branch. However if the content of the delivered information is not 100% constant you may not be able to find your way back.
|
|
|
|
|
Thank you for your response.
As you said, the path of the HtmlElement in its DOM tree would lead the program back to itself.
But it is a little complicated.
In my opinion:
1.get the tag name of the HtmlElement selected
string tagName=HtmlElement.TagName;
2.get the collection of that tag of the whole HtmlDocument
HtmlElementCollection emCollection=HtmlElement.Document.GetElementByTagName(tagName);
3.find out the index of the HtmlElement in emCollection
for each(HtmlElement em2 in emCollection)
{
if em2.Equals(HtmlElement) GetTheIndexOfTheElement;
++i;
}
4.write the index and the tagname to a file, once the program run again, gets back the URL, the index, and the tagname back. At last, we can get the element back.
WebBrowser.Navigate(URL);
HtmlElememtCollection emC=WebBrowser.Document.GetElementByTagName(tagname);
HtmlElement em=emC[index];
BUT, I am quiet not sure this will work.
|
|
|
|
|
linuor wrote: BUT, I am quiet not sure this will work. I am not sure either, I just offered a suggestion to get you started. Unfortunately there is no way to be certain of a piece of code until you build and test it.
|
|
|
|
|
Receiving data from an external device with the SerialPort class.
I set the ReadTimeout property variably from 500ms to 5000ms.
Problem:
The ReadLine() method blocks until the exact amount of time equal to the ReadTimeout property transpires even when data arrives immediately at the port.
This means that if I set the ReadTimeout to 5000, then the ReadLine() method will block for 5 seconds even if data has arrived within 10ms at the port.
I set the NewLine property to
'\r' because that is the delimiter that indicates a full packet of data has arrived.
Has anyone else seen this behavior, or have any idea how to work around it so that the ReadLine() method will return as soon as data is received?
Here is how I set up the port:
Port.BaudRate = 19200;
Port.DataBits = 8;
Port.Parity = System.IO.Ports.Parity.None;
Port.StopBits = System.IO.Ports.StopBits.One;
Port.NewLine = "\r";
Port.ReadTimeout = Convert.ToInt32(textBoxTimeout.Text);
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Bugger! I was all set to show you what I've done to deal with a variety of serial devices of varied and unpredictable timing, and found that System.IO.Port won't do it.
My (much older) code dealt with the lower level beast you could access with things like SetupComm() Get/SetCommState() SetCommTimeouts() etc after getting a handle from CreateFile() . The trick was to set ReadIntervalTimeout to infinite (MAXDWORD) and ReadTotalTimeoutConstant and ReadTotalTimeoutMultiplier both to zero.
This had the effect of turning all read calls into non-blocking "give me what you've got in the buffer" calls.
I handled real "device gone AWOL" timeouts at the application level, typically on lack of progress of a message exchange.
As I (and Toyota) said, bugger!
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
That's true. I've written native code that works properly, but this SerialPort class seems to have a bug.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I also have old MFC code setting up the port with the exact same options you mention (as well as buffers and other good stuff), so thank you for the heads up
Currently I don't actually have anything that needs this kind of COM port control in C# code, but I hope there is a workaround to this and I will be watching this thread for pointers.
Soren Madsen
|
|
|
|
|
Umm probably preaching to the choir (i.e. you know this but...) ReadLine() is a blocking method ReadExisting() is not if you use some thing like the below code:
Pause.Elapsed += new System.Timers.ElapsedEventHandler(OnTimeOutPause);
NoDataAtPort = new System.Timers.Timer(25000);
NoDataAtPort.Elapsed += new ElapsedEventHandler(OnTimeOut);
myComPort.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(port_DataReceived);
}
private void OnTimeOut(object sender, ElapsedEventArgs e)
{
Reply_Status = (int)REPLY.TIMEOUT_REPLY;
}
private void OnTimeOutPause(object sender, ElapsedEventArgs e)
{
MessageBox.Show("Something Broke!");
}
private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
Reply_Status = (int)REPLY.YES_REPLY;
InputData = myComPort.ReadExisting();
if (InputData != String.Empty)
{
this.BeginInvoke(new SetTextCallback(SetText), new object[] { InputData });
}
}
private void SetText(string text)
{
this.rtbIncomingData.Text += text;
if (this.rtbIncomingData.Lines.Length > 0)
{
lbIncomingData.Items.AddRange(rtbIncomingData.Lines);
}
if (text.StartsWith("S") && text.EndsWith(">"))
{
text = text.Substring(3, (text.Length - 6));
txtSerialNumber.Text = text;
rtbIncomingData.Text = "";
}
myComPort.DiscardInBuffer();
}
using the Reply_Status as pre-defined Enum list:
enum REPLY : int { NO_REPLY, TIMEOUT_REPLY, YES_REPLY }
is either a work around or the correct way of doing it, as I had a board that was spewing data, waiting, vomiting again at odd times (it was an RF board) much confusion
also try using a listBox as this tends to cope with odd amounts of data better.
(Jan Axelsons Serial Port Complete 2nd Edition is quite a good reference ISBN 978-1-931448-06-2)
Glenn
modified 16-Jul-12 5:13am.
|
|
|
|
|
I have a question, starting the debugger somehow indirectly, in this szenario:
1)
I start a dot-net-executable within a batch-file
2)
When this exe is started from the batch, I want, that the debugger is started "automatically", so that I have the chance to trace the running exe (e.g. by breakpoints)
Question:
How can I start the debugger this way?
Thank you
|
|
|
|
|
Maybe wait for it to throw an unhandled Exception?
But seriously, you can't do it that way. If you're using Visual Studio to develop the app you can attach the debugger to a running app by opening the solution and using the menu: Debug | Attach to process... then select the process from the list.
What I have done with Windows Services is have them pause for a minute when they start so I have time to attach the debugger; you may need to do something like that.
|
|
|
|
|
|
You can launch the JIT debugger from the batch file (with the %WINDIR%\System32\vsjitdebugger.exe util), after you've successfully started your app.
For instructions on how to do it refer to this link: Answer 3[^]
2A
|
|
|
|
|
I use the following for debugging on my dev machine
System.Diagnostics.Debugger.Assert(false);
When it executes it pops a dialog that asks for the debugger to run via the 'retry' option on the first popup.
Once the debugger starts there is a break point on the above line.
There are limitations to this such as where the app is running and timeout issues with execution threads (with the debug line).
|
|
|
|
|
Hello, I need to add element host to one column of my datagridview and attach a user control to each element host. Is there anyway to implement this? Datagridview is in windows form and I designed a user control in WPF with Avalon library.
Thanks,
Amir
|
|
|
|