|
You don't need to do the compareTo/ ==0 thing, you can just write if(input[0] == "UNITS") etc
But your code is not formatted..
Ok it is now
An other note, I would probably use an enum for the readmode, but maybe that's just me
|
|
|
|
|
This is my first time posting. I did not realized my formatting would be stripped. I was focused on the message, and did not notice the formatting commands. I edited my original post to indicate code blocks.
I will take any suggestions, even if it does not address my original question. I am very excited about moving on from Fortran after 30 years. I am happy to get new ideas.
|
|
|
|
|
First of all you used:
public override void Read(string[] input)
if (input.Length == 0) return;
The way input is declares as a array of strings. but then it is used as a single string. witch is incorrect syntax. I think you intended to use input.Count . Here I was wrong.
if you want to use ASCII encoding then read this at msdn:
http://msdn.microsoft.com/en-us/library/system.text.encoding.ascii.aspxmodified on Monday, February 22, 2010 12:44 PM
|
|
|
|
|
The length of an array is called Length (Count is used in collections), so there is no incorrect syntax
|
|
|
|
|
I think you have a typo in this line and are missing some curly braces.
if (firstword.CompareTo("FORMATIOM") == 0)
formation = new Formation();
readMode = "FORMATION";
In addition, you can just use
firstword == "FORMATION" , but I would force a convert to uppercase with
firstword.ToUpper() if there is no guarantee that input will be uppercase.
Finally, if those lines or similar are found in all input sequences, there is some room to generalize the input section, but I have no way of knowing whether that is the case or not.
I'm curious, from the input, are you working on geological or reservoir engineering software? I do some of that, so the input looks somewhat familiar.CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
In my hurry to post, I seem to have misses a few braces. I am glad they let you edit your posts.
The code changes you suggested was how I use to do it in Fortran. In Fortran I had to write my own toupper function. There was an intermediate version of this program where I used C++ and the strcmp function. My first C# code was actually a conversion of the C++, and the C# book I have used the CompareTo method. For some reason I got it in my head that I could not do the simple comparison. Later I did start using that method, but I did not rewrite earlier code. I should go back and do that, at least to make the code easier to read.
I am working on numerical simulations of wireline and LWD tools in 1D, 2D, and 3D formations. Until a month ago, all our research code was in Fortran. Our application programmers tend to us C#, and call the research code from a DLL. I am trying to reduce the Fortran to just the core computational subroutine. Keeping track of tool and formation objects will be easier in C#. Eventaully I would like to also replace the core routines, but the scientists who write them only know Fortran.
|
|
|
|
|
spainchaud wrote: Until a month ago, all our research code was in Fortran.
Been there and done that! Fortunately I haven't done more than browse some FORTRAN in 10 or 12 years now, but everything technical used to be written that way. I translated all my old FORTRAN routines to C, C++, C#, etc. long ago.
I've done some informal benchmarking and I'd suggest that you consider converting even the core routines to make things easier to manage and maintai. The scientists may complain, but learning rudimentary C# isn't that bad if one already knows FORTRAN.
It's always amazing to me that so many technical people think FORTRAN is the best of all possible languages, yet they don't know any others!CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
You can do direct comparisons of strings in C#, but if you use CompareTo, there is an option for case insensitive comparison.
|
|
|
|
|
I've never done crystal reports before.can you please help me.
I managed to do a simple report, now i need to display information for the past 24 hours only.
how do i do that. I need the formula.
|
|
|
|
|
One, read How to get ansers to your questions[^]
Reports is not a very descriptive subject.
Two, the formula depends on the data you are using.
I would suggest you get a book or find some tutorial about Crystal Reports before trying anything more. I know the language. I've read a book. - _Madmatt
|
|
|
|
|
For that you should learn from Books and Sites. If you can think then I Can.
|
|
|
|
|
Hi all, i have been using a Rijndael algorithm to encrypt and decrypt a sequence of bytes, but when i run the code i get the following exeption "Padding is invalid and cannot be removed.", this exeption belongs to decrypt function at line <code>int decryptedByteCount = cryptoStream.Read(pTextBytes, 0, pTextBytes.Length);
</code>
i writ my code here:
<pre>public static byte[] Encrypt(byte[] clearData)
{
System.Configuration.AppSettingsReader settingsReader = new AppSettingsReader();
//Get your key from config file to open the lock!
string key = (string)settingsReader.GetValue("SecurityKey", typeof(String));
MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
byte[] keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));
hashmd5.Clear();
Rijndael rijKey = Rijndael.Create();
rijKey.Mode = CipherMode.ECB;
rijKey.Padding = PaddingMode.PKCS7;
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms,rijKey.CreateEncryptor(), CryptoStreamMode.Write);
cs.Write(clearData, 0, clearData.Length);
cs.FlushFinalBlock();
byte[] cipherTextBytes = ms.ToArray();
ms.Close();
cs.Close();
return cipherTextBytes;
}
public static byte[] Decrypt(byte[] encryptedData)
{
System.Configuration.AppSettingsReader settingsReader = new AppSettingsReader();
//Get your key from config file to open the lock!
string key = (string)settingsReader.GetValue("SecurityKey", typeof(String));
MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
byte[] keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));
hashmd5.Clear();
Rijndael rijKey = Rijndael.Create();
rijKey.Mode = CipherMode.ECB;
rijKey.Padding = PaddingMode.PKCS7;
MemoryStream memoryStream = new MemoryStream(encryptedData);
CryptoStream cryptoStream = new CryptoStream(memoryStream, rijKey.CreateDecryptor(),
CryptoStreamMode.Read);
byte[] pTextBytes = new byte[encryptedData.Length];
int decryptedByteCount = cryptoStream.Read(pTextBytes, 0, pTextBytes.Length);
memoryStream.Close();
cryptoStream.Close();
return pTextBytes;
}</pre>
thanks.....................
|
|
|
|
|
Hi all, i have been using a Rijndael algorithm to encrypt and decrypt a sequence of bytes, but when i run the code i get the following exeption "Padding is invalid and cannot be removed.", this exeption belongs to decrypt function at line <code>int decryptedByteCount = cryptoStream.Read(pTextBytes, 0, pTextBytes.Length);
</code>
i writ my code here:
<pre>public static byte[] Encrypt(byte[] clearData)
{
System.Configuration.AppSettingsReader settingsReader = new AppSettingsReader();
//Get your key from config file to open the lock!
string key = (string)settingsReader.GetValue("SecurityKey", typeof(String));
MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
byte[] keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));
hashmd5.Clear();
Rijndael rijKey = Rijndael.Create();
rijKey.Mode = CipherMode.;
rijKey.Padding = PaddingMode.PKCS7;
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms,rijKey.CreateEncryptor(), CryptoStreamMode.Write);
cs.Write(clearData, 0, clearData.Length);
cs.FlushFinalBlock();
byte[] cipherTextBytes = ms.ToArray();
ms.Close();
cs.Close();
return cipherTextBytes;
}
public static byte[] Decrypt(byte[] encryptedData)
{
System.Configuration.AppSettingsReader settingsReader = new AppSettingsReader();
//Get your key from config file to open the lock!
string key = (string)settingsReader.GetValue("SecurityKey", typeof(String));
MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
byte[] keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));
hashmd5.Clear();
Rijndael rijKey = Rijndael.Create();
rijKey.Mode = CipherMode.ECB;
rijKey.Padding = PaddingMode.PKCS7;
MemoryStream memoryStream = new MemoryStream(encryptedData);
CryptoStream cryptoStream = new CryptoStream(memoryStream, rijKey.CreateDecryptor(),
CryptoStreamMode.Read);
byte[] pTextBytes = new byte[encryptedData.Length];
int decryptedByteCount = cryptoStream.Read(pTextBytes, 0, pTextBytes.Length);
memoryStream.Close();
cryptoStream.Close();
return pTextBytes;
}</pre>
thanks.....................
|
|
|
|
|
Format the code.
Remove the duplicate post before some replies to it. I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Your code is unformatted, you need to ensure that the > & <g; appear, rather than > etc.
The problem you are getting is due to extra characters being read from the stream. The length of encrypyted string will always be a multiple of a set length (which itself is a power of two). Our encryption rountine always produces blocks of length 16, So the string "1" as does "12345678901234" would produce an encrypted string 16 hex characters long, "123456789012345" produces 32 character long string. I thnk the actual block size relates to the key and/or the IV value.
In this case, for a string to be decrypted, the count of hex characters must be evenly divisible by 16.
You are probably either reading past the end of the string in the memory stream, or the stream is including padding characters. In either case, you must stop reading before then.Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
|
|
|
|
|
Hi,
you have been around for several months, so you should know code needs to be shown with PRE tags so it keeps its formatting; and posting the same stuff twice isn't acceptable either. Please delete the one without replies, and edit the one heading this thread.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|
|
Actually, the Pre tags are there, its just that he's used < instead of < I'm assuming he had Encode "<" (and other HTML) characters when pasting ticked. Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
|
|
|
|
|
You're right, I did not notice as I don't look at unformatted code at all...
If the poster isn't willing to do the posting right, then he is beyond help as far as I'm concerned.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|
|
How to change the Index of one row of datatable ?
I have 10 items in datatable and now i wanna to bring the 6th item to zeroIndex of Datatable ?
|
|
|
|
|
Sort the datasource being used to populate the datatable or remove the item in question and use InsertAt to place it at index 0 I know the language. I've read a book. - _Madmatt
|
|
|
|
|
|
Hi everyone,
Does anyone have any idea how to do the following code snippet i posted below in web method?
protected void Page_Load(object sender, EventArgs e)
{
// Get the hostname
string myHost = System.Net.Dns.GetHostName();
// Get the IP from the host name
//string myIP = System.Net.Dns.GetHostEntry(myHost).AddressList[0].ToString();
string connect = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=C:\\inetpub\\wwwroot\\Request\\App_Data\\TV.mdb";
string query = "SELECT COUNT(IPAddress) FROM Request WHERE IPAddress = ?";
int result = 0;
using (OleDbConnection conn = new OleDbConnection(connect))
{
using (OleDbCommand cmd = new OleDbCommand(query, conn))
{
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("IPAddress", myHost);
conn.Open();
result = (int)cmd.ExecuteScalar();
}
}
if (result <= 0)
{
Response.Redirect("Unautorized.aspx");
}
thanks.
|
|
|
|
|
Do you mean using a method decorated with the WebMethod attribute and called from JavaScript? I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Ya, something like that. But i need to use C# instead of Javascript. Can you show me some examples on it?
thanks.
|
|
|
|
|
This make no sence. If you are using C# then call the method like any other method. I know the language. I've read a book. - _Madmatt
|
|
|
|
|