So I just got an entry level job at a company, and I have been given a business application to tweak and improve. I have a senior, and more experienced programmer overseeing me, but I have found what I consider to be a bad practice in the company application. I have been reading a C# data security book, and have been introduced to hash algorithims (crypto). I know that for authentication hash algorithims are useful due to the fact that the company need not store passwod information in the clear as well as the fact that with a hash algorithim you cannot actually reverse the password to it's plain text. What you do when the user submits the password, is instead of decrypting the cypher text, you hash what the user gives you, and therefore get identical cypher texts. What I have found is that my company is using a very secure Symmetric Algorithim. The problem I have with this is we shouldn't be able to decrypt the user's password at all. The code appears to be a drop in and replace thing, but I have little experience in upgrading the database where the cyphertext is stored, so I was wondering, how would one go about swapping out the algorithims in the DB. Would you temporarily allow for the fact that both algorithims could be used in the code, or do you create a program that makes the necessary conversions, and uploads the data to another server, or what? I …
the advantages that C# as a general purpose programing lang
originally created JavaScript, they were going to call it Live
release of Java in order to jump on the hype train. While so
iginally created JavaScript, they were going to call it LiveScript, but changed the name after Sun announced the release of Java in order to jump on the hype train. While some of the changes to JavaScript in versions 2.0 and later on were inspire
Desipte their names, Java and JavaScript are completely unrelated languages; in fact, when Netscape originally created JavaScript, they were going to call it LiveScript, but changed the name after Sun announced the release of Java in order to jump on the hype train. While some of the changes to JavaScript in versions 2.0 and later on were inspired by Java, the two of them are not connected in any way aside from the names.
I have been telling people this for years (javascript != java), nobody believes me though.
You also don't know however whether the applications will all execute on different processsors. It is all up to the OS's discression.
There are probably a few things in play here. First, you got to know that there is a hierearchy of resources on computers, resources which are available in excess are at the top of the chart, and resources at the bottom of the chart are slow. Typically in books this is represented in a triagnle like fashion. I can't find the exact chart right now, but this is what it attempts to convey;
CPU -Very fast, lots of resources
RAM
Hard Disk
Network -Very slow, limited resources
I don't think it is incorrect to say that hard disks are always slower than CPU etc. You also have to take into account that your program appears to be doing no buffering. Hard disk reads are really slow, so programmers designed buffering so that they could read whole gobs of data all in one go instead of having slow single line reads for files. The Buffered Stream class reads n bytes into memory and allows you to use it just like another stream, so you could use your readlines with it and still have similar code. After you exaust your n bytes it will grab n more or something along those lines. If you wrapped your file stream in a buffered stream you could probably speed things up, or you could read it all in one go with a method in the C#/.NET API. Essentially without buffering you have to ask the hard disk to seek to the file …
It's kind of one of those situations where LINQ would solve it nicely, but the code for either LINQ or just regular loops would be approximately the same amount of code. I don't think there are any other ways of implementing specific functionality like this in the .NET framework, no already coded methods.
From what I understand on the subject certain assembly language constructs can be linked to higher level C++/C# language constructs. So yes, you can determine what the original source code looks like if there is no obfuscation/cryption. Don't quote me 100 % though I am no reverser.
I don't think it's a waste of time. At the very least you will make it harder to reverse engineer. Sure it is not impossible, but you may as well do it rather than not do it, especially if you have a tool that you can use in order to do it. It is just one more small step in the development process. Use tools to do it, don't try to implement code obfuscation techniques in your actual source code. Not doing it seems a little bit lazy to me.
The question is how do you prove somebody decompiled your code unless they sell the product, pirate it. Is not illegal to download decompilers and use them on your own code to test your obfuscation methods, is only illegal if you use them in a disreputable manner. Using them on other peoples code, is illegal, usually copyright protected, but he's not going to get in trouble for downloading a decompiler/debugger. Just make sure it is actually a decompiler/debugger and not malware. Also make sure the "proprietary dll" is actually your company's and not someone else's.
Essentially anything that you provide to customers will essentially be prone to reverse engineering, if this is what you are asking. There are techniques for making the reverse engineering process more difficult, like obfuscation, encryption, etc. These techniques make it more difficult, but not impossible to reverse engineer. You should not think that it is a waste of time, it is possible to make your binaries so complicated to reverse that virtually no one will want to partake in it. One technique for actually preventing the majority of people from being able to reverse engineer your code is to put in a call to a service on a server. If you put your proprietary code on the server then people can't reverse it unless they have access to the server.
Am running Visual Studio 2010.
So I am having trouble connecting to an Oracle XE 11g database in visual studio. The Ultimate aim here is to make a webpage I can run on my local machine and send sql to on my local net. From looking around it seems other people have had this problem, but I cannot grasp how they managed to solve it, and it appears I am running all the right software, so I shouldn't be getting this error. This error is this BadImageFormatException, and it suggests that there is a 32 bit/64 bit mismatch somewhere, but my oracle edition seems to be the right one as you can see from the following command.
SQL> SELECT * FROM v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
PL/SQL Release 11.2.0.2.0 - Production
CORE 11.2.0.2.0 Production
TNS for 64-bit Windows: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - Production
SQL>
The full text of this Visual Studio dialog is as follows;
Attempt to load Oracle client libraries threw BadImageFormatException. This problem will occur when running in 64 bit mode with the 32 bit Oracle client components installed.
I am basically trying to add a connection using that data connections node in my ASP.NET project.
I even tried to convert my project to x64 through the solution properties page, but it keeps changing the platform to Active(x64), so I am not sure what is going on. I even tried changing it to x86, knowing that would …
I figured it out, sorry guys. My variable statement was casting it to something that I should have known not to cast it to, you see when you link together an orderbydecending it returns an IOrderedEnumerable, not an IEnumerable. So it was casting it to something that was essentially unordered. I admonish myself to always use var in linq queries from now on because the var statement fixes this particular problm.
public static IEnumerable<int[]> OrderByMatrixRows(this int[][] jagged) {
var query = jagged.OrderByDescending(row => row[0]);
for (int i = 1; i < jagged.Length; i++) {
query = query.ThenBy(row => row[i]);
}//end loop
return query;
}//end method
Hello, I am thinking about doing a matrix RREF function, am still in the research stage, but I thought I should post a bug I have been having. The following code doesn't work. What I am trying to do is orderby the array index [0], and then by [i...] etc. Here is the code I have been having trouble with. I am trying to break the orderby decending, and thenby operations up onto multiple lines as I build the query so I can have a looping like action. I think it doesn't matter which rows you swap in RREF as long as the row with the 0 on the front is at the bottom, and the larger numbers are at the top, but I could be wrong, it has been a while since I had a math class, and I am going to have to sift through my books. I may be attempting to break some LINQ rules here, I don't know. Please enlighten me as I am new to LINQ.
public static IEnumerable<int[]> OrderByMatrixRows(this int[][] jagged) {
IEnumerable<int[]> query = jagged.OrderByDescending(row => row[0]);
for (int i = 1; i < jagged.Length; i++) {
//the following line errors out
query = query.ThenBy(row => row[i]);
}//end loop
return query;
}//end method
If I can't do this with LINQ I will have to figure out some other way of doing so. Also if you all have any good sources for re-learning RREF please post em.
Oh, yeah you're right should be string not float.
It looks like you aren't returning anything in the ToString method right now, if you don't return something it will error out. Also, the SetGrade method does not have a return type specified. Should be "public float SetGrade(float score)".
Ok, I think I fixed it, will have to check the second method in more detail.
public static class StringExt{
public static System.Collections.Generic.IEnumerable<String> NextSplit(
this String str,
char[] tokens) {
int leftOffHere = 0;
int[] tokLoc = new int[tokens.Length];//token location
while (leftOffHere < str.Length) {
for (int tokenIndex = 0; tokenIndex < tokens.Length; tokenIndex++)
tokLoc[tokenIndex] = str.IndexOf(tokens[tokenIndex], leftOffHere);
//find the closest token location
int closest = int.MaxValue;
foreach (int loc in tokLoc)
if (loc < closest && loc != -1)
closest = loc;
if (closest == int.MaxValue)
closest = str.Length;
yield return str.Substring(leftOffHere, closest - leftOffHere);
//left off at closest + 1 so doesn't use same position twice
leftOffHere = closest + 1;
}//end loop
}//end method
public static System.Collections.Generic.IEnumerable<String> NextSplit(
this String str, char[] tokens, int start, int length) {
int leftOffHere = start;
int[] tokLoc = new int[tokens.Length];//token location
//convert length to an index, starting index plus the length
while (leftOffHere < length + start) {
for (int tokenIndex = 0; tokenIndex < tokens.Length; tokenIndex++)
tokLoc[tokenIndex] = str.IndexOf(tokens[tokenIndex], leftOffHere);
//find the closest token location
int closest = int.MaxValue;
foreach (int loc in tokLoc)
if (loc < closest && loc != -1)
closest = loc;
if(closest == int.MaxValue)
yield break;
yield return str.Substring(leftOffHere, closest - leftOffHere);
//left off at closest + 1 so doesn't use same position twice
leftOffHere = closest + 1;
}//end loop
}//end method
}//end class
You are right. I will try to fix it as soon as I am able. If somebody beats me to the punch, please post.
This is kinda what we did, not exactly what we did, but it should give you some ideas. As far as logging, and having all projects inherit, I am unsure of that. You could have them all inherit from heading I suppose, or make something completely different.
/*Author: overwraith*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Heading {
class Program {
static void Main(string[] args) {
Heading heading = new Heading();
Console.WriteLine(heading.ToString());
Console.Write("Press any key to continue... ");
Console.ReadLine();
}//end main
}//end class
public class Heading {
private const String firstName = "Joe";
private const char MI = 'J';//middle initial
private const String LastName = "Schmoe";
public String getAssemblyName(){
return System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
}//end method
public override string ToString() {
StringBuilder str = new StringBuilder();
//append name info
str.AppendFormat("Programmer: {0,6} {1}. {2}\n", firstName, MI, LastName);
str.AppendFormat("Assembly Name: {0,5}\n", this.getAssemblyName());
str.AppendFormat("Date: {0, 28}", DateTime.Now);
return str.ToString();
}//end method
}//end class
}//end namespace
I took a class once where we wrote our own personal heading class for our assignments, it included information such as the developer name, the date the program was run, etc. Information included the following;
First name,
last name,
assignment, //could probably just use a creative naming convention and reflection for this part
Current date,
etc.
Apparenty it has to print everything in a useful format. I am not going to include the java code associated with it, it has my real name associated with it in multiple places, and the instructor made a lot of arbitrary and rediculous coding conventions that quite frankly made the code ugly. We had to code around these rediculous conventions lest we loose points. We even had to cite our textbook in our computer programs, and put the teachers name in the program, and only after we cite the teacher as the "main" useless coder could we put "modified by" and our name. So even though the teacher did absolutely nothing, and was more a hinderance to our getting our coding exercises done, we had to "pretend" that he was the main coder of our assignment. I didn't realize how much I despised him until my rant just now. sorry.
Anyway your name, the program name, and the current date seem the most logical fields for something like this, and if it is a console application you may need a seperate program for a GUI application, or you could just …
Actually this should probably be moved to snippets, that's where I wanted to put it.
So I was recently working on a string program where the strings were easily megabytes long, and I ran into problems with there being out of memory exceptions etc. So I said to myself, this would be a perfect problem which lazy execution solves. Here is a split function that essentially makes it so that only one of the string tokens is in memory at any given time, making it much more efficient in terms of memory. It might be a bit slower in terms of CPU cycles, but I wouldn't bet it would be that much slower. My program also had to split strings according to search threads, and one of the functions preforms that as well. I am happy with it, if you notice any problems with the implementation don't hesitate to point them out and suggest alterations. State machines are really cool this way.
I think it's an improvement, even with the slight overhead introduced. This could make other methods like an RREF function easier to code (it's been a while, I actually don't remember how to do row reduced echilon form, so I don't know). You could probably make this a little more interesting with addition and subtraction methods, RREF, as well as making it generic, and using dynamic casting where the generic inherits from struct to implement the addition and subtraction on the contents. You are talking about a mathematics matrix right?
T[] arr = new T[length];
arr[i] = (dynamic)arr[i] + (dynamic)otherarr[i];
Here is some code I wrote for a matrice program;
/*Author: overwraith*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Matrices {
class Program {
static void Main(string[] args) {
Matrix<int> m1 = new Matrix<int>(new int[,] { { 0, 0, 1 }, { 0, 1, 1 } });
Matrix<int> m2 = new Matrix<int>(new int[,] { { 0, 0, 1 }, { 0, 1, 1 } });
Console.WriteLine(m1 + m2);
Matrix<int> m3 = new Matrix<int>(new int[,] { { 0, 0, 1 } });
Matrix<int> m4 = new Matrix<int>(new int[,] { { 0, 0, 1 } });
Console.WriteLine(m3 + m4);
Matrix<int> m = m3 + m4;
m.To1DArray();
Matrix<int> m5 = new Matrix<int>(new int[,] { { 0, 0, 1 }, { 0, 1, 1 }, { 1, 1, 1 } });
Matrix<int> m6 = new Matrix<int>(new int[,] { { 0, 0, 1 }, { 0, 1, 1 }, { …
I am going to take the hints from everybody else in the forum, and not give away homework answers, but I coded something like this in C# just now, and noticed that the multithreaded searching algorithims worked better for only massive strings, like in a 45 MB text file. Anything less is just inefficient. Wonder how I would learn about optimization and stuff, are there books on it?
I am reading a book right now, called "C# in depth" (3rd ed.), the author mentions contravarience, and covarience in places, but I am not finished yet, so I don't know if the author addresses this problem directly. The author's name is John Skeet, I think he actually has a stack overflow account. The book also has references to his online blogs, but all the links have changed by now. You just have to do some creative googleing to find the blogs. The MSDN site would also probably have information about this topic.
That would be a good fix too. Thanks.
So I figured that a loop might be better than calling recursive methods or something, am not sure. But I wrote this program using 3 big integers to see how big a fibonacci number I can make. Is currently dumping to my screen, and when it runs out of memory it will dump to a binary file. There are probably better ways of figuring fibonacci numbers, I will have to look into it.
/*Author: overwraith*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
using System.IO;
namespace Fibonacci {
class Program {
static void Main(string[] args) {
const String ctFile = "Fibonacci_Current.dat";
const String prevFile = "Fibonacci_Previous.dat";
BigInteger previous = 1, current = 2, fibbonacci = 0;
Console.WriteLine("Fibonacci Num: {0} ", previous);
Console.WriteLine("Fibonacci Num: {0} ", current);
try {
if (File.Exists(prevFile) && File.Exists(ctFile)) {
//pick up where we left off
using (BinaryReader ctReader = new BinaryReader(
new BufferedStream(
new FileStream(ctFile, FileMode.Open,
FileAccess.Read, FileShare.ReadWrite)))) {
current = new BigInteger(ctReader.ReadAllBytes());
}//end using
using (BinaryReader prevReader = new BinaryReader(
new BufferedStream(
new FileStream(prevFile, FileMode.Open,
FileAccess.Read, FileShare.ReadWrite)))) {
previous = new BigInteger(prevReader.ReadAllBytes());
}//end using
}//end if
while (true) {
fibbonacci = previous + current;
Console.WriteLine("Fibonacci Num: {0} ", fibbonacci);
//swap
previous = current;
current = fibbonacci;
}
}
catch (OutOfMemoryException) {
//can't go any higher
}
finally {
//write the resulting fibbonacci nums so other programs can pick
// up if more resources come available later
using (BinaryWriter ctWriter = new BinaryWriter(
new BufferedStream(
new FileStream(ctFile, FileMode.Create,
FileAccess.ReadWrite, FileShare.ReadWrite)))) {
ctWriter.Write(current.ToByteArray());
}//end …
Thanks for the help. I am really just messing around with this code now, I acutally am not very dumb.
Wait a sec, is the + operation returning a new big integer object? Oh. I shoulda seen that.
So the other day I was just experamenting with some code, just for fun, and I ran into some difficulties. So I suppose my question is why the following code does not write to the original bigints array. I am sure I am doing something dumb, but please bear with me. I made my own simple "state machine" thinking that I could return what is essentially a reference to the value in the array, and get away with only two BigIntegers being in memory at any given time. What seems to be happening though is that the value of the BigInteger is copied and then the copy is returned. I thought that whenever you did this "SomeObj obj = new SomeObj();" the left hand side was essentially a really safe pointer. Now this code is really convoluted, so as you can see I was just messing around, and wouldn't use this anywhere else. Perhaps when I access "array[current]" in the getCurrent() method the array copies the datatype instead? I know I am being too clever for my own good, be gentle. Are BigInts value types?
/*Author: overwraith*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
namespace Fibonacci {
class Program {
static void Main(string[] args) {
BigInteger[] bigints = new BigInteger[2] { new BigInteger(1), new BigInteger(2) };
try{
LoopingStateMachine<BigInteger> enumerable1 = new LoopingStateMachine<BigInteger>(bigints);
//advance one on second state machine
LoopingStateMachine<BigInteger> enumerable2 = new LoopingStateMachine<BigInteger>(bigints);
enumerable2.MoveNext();
while(enumerable1.MoveNext() && enumerable2.MoveNext()){
BigInteger current = enumerable1.getCurrent();
current += enumerable2.getCurrent();
Console.WriteLine("Fibonacci Number: …
MSDN is a good resource for getting information on the C# classes, and other aspects of the .NET framework. Didn't see anybody mention it here, but just glanced over the posts. Microsoft Developer Network https://msdn.microsoft.com/en-us/default.aspx . It used to be really bad, especially with the C/C++ languages, hard to figure out what some of the data types were. Perhaps I just don't have a very extensive background in ASM, and system data types. Oh well. These days though, it is usually a lot better, with complete documentation. With more modern languages I have yet to be disappointed. Sometimes they alter the web page slightly to make things harder, for example making it so the search box is hidden at the top of the page until the user has to hunt for the drop down. By and large though the site is a good reference. You kinda gotta take the bad and the good.
Thank you.
Hi, so this has been bugging me for a while about Danni Web website. I seem to have neglected my email account for a while, and now it is on the bounced email list. How do I get my email off this list, and back in working order. I can't read any of the messages I am sent.
So when reading my code, take into account that I am essentially using delegates (callback functions) to make one loop act like two. I have a bachelor's degree. I am inherently more trustworthy.
P.S. whoever came up with this code requirement is evil, don't trust them.
Ok, so I figured out that in my code I had to take into account the fact that when you go half way through the numbers, the logic for the start value flips from even nums to odd nums. The code I wrote to solve this problem is deplorable, I would probably go a different route if I had to do so again. My code also takes into account start and end values for the table. The fudge operations I coded, especially the second one is really messy. I anticipate this code breaking when you plug in different values (possibly, I am not sure). I did get it to display the original table though;
1
1 2
2 3
2 3 4
3 4 5
3 4 5 6
4 5 6 7
4 5 6 7 8
4 5 6 7
3 4 5 6
3 4 5
2 3 4
2 3
1 2
1
And here is what the table looks like for 1 through 9, am not sure if is correct;
1
1 2
2 3
2 3 4
3 4 5
3 4 5 6
4 5 6 7
4 5 6 7 8
5 6 7 8 9
4 5 6 7 8
4 5 6 7
3 4 5 6
3 4 5
2 3 4
2 3
1 2
1
As you can see the 8's and 9's are all in essentially the same column, so I am …
So, whether the start value increments in the loop seems to hinge on whether the current line number is even or odd, so you get the pattern 1, 1, 2, 2, 3, 3, 4, 4, then it decrements 4, 3, 3, 2, 2, 1, 1. My code is going to look different from yours, I am trying to figure out a good way to get the even/odd thing working. The following only does the pattern I showed earlier, it doesn't increment the start value yet.
/*Author: overwraith*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NestedLoopExample {
class Program {
static void Main(string[] args) {
PrettyLoop(1, 9);
Console.Write("Press any key to continue... ");
Console.ReadLine();
}//end main
public delegate bool ComparisonBool<T>(T x, T y) where T : struct;
public delegate void IncrementDecrement<T>(ref T x) where T : struct;
public static void PrettyLoop(int start, int end) {
if (start >= end)
throw new ArgumentException("Start should be greater than end. ");
ComparisonBool<int>[] comparisons = new ComparisonBool<int>[2]{
(int x, int y) => { return x < y; },
(int x, int y) => { return x >= y; }
};
IncrementDecrement<int>[] incDec = new IncrementDecrement<int>[2]{
(ref int x) => x++,
(ref int x) => x--
};
//basically start with one level of indirection, loop alters these values
int startTmp = start;
int endTmp = end;
//int fudge = 0;
//two operations we want to switch between
for (int i = 0; i < comparisons.Length; i++) {
for (; comparisons[i].Invoke(startTmp, endTmp); incDec[i].Invoke(ref startTmp)) …
Why did you put @overwraith? This isn't my thread?
Are you entireley sure that the sequence isn't supposed to look like this?
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
Your sequence seems a little bit different from most programming books.
You would essentially need a deep copy clone of the array. Array only has a shallow copy though, so you would need to find some code that allows for deep copying. This would cause overhead if you were doing it a lot though. Arrays are pass by reference to prevent the overhead of copying a whole array over and over again into local variables. Usually programmers make a concious effort not to modify the array or make changes in a method which should have no side effects. Essentially a deep copy would get you the same effect as pass by value. You should also know that arrays in C# "pass a reference by value". This is somewhat confusing because it is not what typical languages do. So basically if I wanted to change the contents of the array, that would propagate back to the calling method, but if I wanted to get rid of the reference entireley, setting the array to null, then the operation would not propagate back to the calling method because the reference is passed by value.
Here is a discussion where somebody brought up deep copying an array, I like the GenericCopier solution;
http://stackoverflow.com/questions/4054075/how-to-make-a-deep-copy-of-an-array-in-c
I hope nobody takes offence to me linking to stack overflow, I use you guys pretty much interchangably, I try not to limit myself when it comes to resources.
Just curious what kind of application needs to choose one of 50 doubles without going over? Is this some kind of guessing game?
Ok, thanks. None of the school cirriculum books I have read broach the topic. I heard it mentioned in a C class but never substantially. I have had some Calculus classes, so I will understand some of the math, but honestly people just don't know how to teach math these days. From what I understand as a variable approaches infinity the algorithim will tend to reflect some of the features of a certain function, some terms will be dropped, and some will become more dominant. So algorithims can be evaluated for efficiency by attributing certain functions to them.
Have any of you ever done big O notation? I found some websites that describe it, but not many professional ones. Are there any books that describe it too?
Once I coded a C#/ASP.NET citation generator. You can code it in any language however. Involved a database where the citations would be stored (you may be able to get away with flat files if you tweak). Had a lot of fields involved many of which could be null, so the class implementation needs to take that into account. Authors and Editors have their own tables who'se foreign key is the Book Table's refId (reference id). Book also has a foreign key to the Reference table which holds PaperID as the primary key. This way each seperate paper has a way of differentiating themselves from another. The book class had a compare to method which would compare one book to another first matching title, then year, then author as per APA format. Book's tostring method was used to print the books for the references page. This needs to take into account the presence of no editors, no authors, or any other missing variables, so it is a little involved. There needs to be a datatype for every field in the database. There also has to be a char sequence for assignment in seperate code for when there is a sequence of authors in the references page which are all the same author. In such a case there needs to be code that assigns to the books the sequence number a, b, c, etc when these authors are back to back and their work needs differentiating. These books are sorted after …
So I am kinda new to developing client and server sockets (protocols), and am developing something just for fun on my own network. This program basically will send all files from a specific folder to a client. So I am wondering if I wanted to send multiple files over one socket how would I differentiate between different files? I was thinking when we use text files we usually have some sort of delimiter, but what would I use for that kind of thing? Another thought I had was recording the number of bytes of each file in each transmission. I am new to protocol development, how would you all develop this. I am worried that if I use the length property of the FileInfo class it will not be precise, I have had problems before with sizes not being exact, but that could have been accounted for by a programming error on my part. Would the FileInfo length property be precise? I have read a java sockets book, and am in the process of reading a C# one, but the C# one is honestly not as good as the java one I am reading. The following code is untested.
public class LanLeakThread {
private Socket sock;
private String path;
public LanLeakThread(Socket sock, String path) {
this.sock = sock;
this.path = path;
}//end constructor
public void run() {
ThreadPool.QueueUserWorkItem((object state) => {
try {
sock.Send(GetBytes("Server Name: " + Environment.MachineName + "\n"));
sock.Send(GetBytes("Num Files:" + Directory.GetFiles(path).Length + "\n"));
foreach (String …
The following is java, for extracting text from files:
import java.io.IOException;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.parser.PdfReaderContentParser;
import com.itextpdf.text.pdf.parser.SimpleTextExtractionStrategy;
import com.itextpdf.text.pdf.parser.TextExtractionStrategy;
public class PDFToText {
public static void main(String[] args) {
for(int i = 0 ; i < args.length ; i++)
try {
System.out.println(wordsInFile(args[i]));
} catch (IOException e) {
e.printStackTrace();
}
}//end main
//counts words specified in the word map that occur in a given pdf document
public static String wordsInFile(String pdf) throws IOException {
PdfReader reader = new PdfReader(pdf);
PdfReaderContentParser parser = new PdfReaderContentParser(reader);
TextExtractionStrategy strategy;
StringBuilder fullText = new StringBuilder();
//String result = "";
//Only a single page in memory at a given time
for (int i = 1; i <= reader.getNumberOfPages(); i++) {
strategy = (TextExtractionStrategy) parser.processContent(i, new SimpleTextExtractionStrategy());
//one page of text
fullText.append(strategy.getResultantText());
}//end loop
reader.close();
return fullText.toString();
}//end method
}//end class
The reason it is relivant is that instead of using itext, you can use itext sharp, a C# port of itext. I am reading a book about itext sharp in java called "itext in action". I think this is where itext sharp is downloaded.
http://sourceforge.net/projects/itextsharp/
Word documents I am unsure of how to parse, but I seem to remember some code project projects that discuss the process a little. The projects are much different from this itext library.
The toString method does not get overridden enough, and is good for displaying your books. Just override your own version which displays the variables you want displayed. Then you can simply pass the object you want displayed directly to System.out.println(obj) and it will print in string form the object. Here is an example:
//A snippet from a different implementation of a book class
public String toString(){
return super.toString() +
"Author: " + author + "\n";
}//end method
There are built in methods for sorting arrays of objects that implement the Comparable interface. In order to use this interface you need to change the book class to implement this interface, and implement the method compareTo. Here is a link to the Comparable interface:
Click Here
import Java.Util.Arrays;
//sort regular order
Arrays.sort(array);
//sort reverse order
Arrays.sort(array, Collections.reverseOrder());
Now I know that you all said that it was bad form to use multiple where statements in a query, but my compiler says it is ok, and it seems to me that I need a query from a query from a query in order to preserve some form of sequence so that this exception is not thrown. The IsReady property looks like it is the most useful, and seems to work. Here is the code I have so far that works. Do I need to combine with an && or will that just cause the IOException to come up again?
var exfil = from drive in DriveInfo.GetDrives()
where drive.IsReady
where drive.DriveType == DriveType.Removable
where drive.VolumeLabel == "EXFIL"
select drive;
If you don't check the VolumeLabel, then yes it does work, but that means it only does half the job.
Right, but there are no CDs in the drive, I think it could be some other software on the system emulating something in the background, so I need to be able to check for exceptions in the Linq code. Uninstalling the software is not really an option. We need to skip the drives that throw exceptions.