|
The answer here is to build the application with elevated rights. You do this by creating a custom manifest, then HAND EDITing the manifest line to say this:
<requestedexecutionlevel level="requireAdministrator" uiaccess="false">
Instead of "asInvoker". This will cause the "do you really want to allow this to make changes to your computer" question to come up when it starts, but it will work correctly after that assuming that you are logged on as an admin type user.
EvetsMostel
|
|
|
|
|
I'm developing ftp application in c# winform framework 3.5 visual studio 2008.
algorithm im using for encryption is "RijndaelManaged" but in decryption getting error.
i scheduling time it automatically uploads all files from specific directory(client system) to FTP server, pls suggests me which algorithm is used for ftp in c#...
here is my code.
public static void EncryptFile(string inputFile, string outputFile, string skey)
{
RijndaelManaged aes = new RijndaelManaged();
try
{
byte[] key = ASCIIEncoding.UTF8.GetBytes(skey);
using (FileStream fsCrypt = new FileStream(outputFile, FileMode.Create))
{
using (CryptoStream cs = new CryptoStream(fsCrypt, aes.CreateEncryptor(key, key), CryptoStreamMode.Write))
{
using (FileStream fsIn = new FileStream(inputFile, FileMode.Open))
{
int data;
while ((data = fsIn.ReadByte()) != -1)
{
cs.WriteByte((byte)data);
}
aes.Clear();
}
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
aes.Clear();
}
}
private static void DecryptFile(string inputFile, string outputFile, string skey)
{
RijndaelManaged aes = new RijndaelManaged();
try
{
byte[] key = ASCIIEncoding.UTF8.GetBytes(skey);
using (FileStream fsCrypt = new FileStream(inputFile, FileMode.Open))
{
using (FileStream fsOut = new FileStream(outputFile, FileMode.Create))
{
using (CryptoStream cs = new CryptoStream(fsCrypt, aes.CreateDecryptor(key, key), CryptoStreamMode.Read))
{
int data;
while ((data = cs.ReadByte()) != -1)
{
fsOut.WriteByte((byte)data);
}
aes.Clear();
}
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
aes.Clear();
}
}
|
|
|
|
|
..
}
catch (UnclearQuestionException uqex)
{
MessageBox.Show("Your question is not clear. Please tell us more about the exception you see!");
}
|
|
|
|
|
|
Member 8653959 wrote: pls suggests me which algorithm is used for ftp in c#...
There's no algorithm, FTP is a protocol. It works with bytes, and cares little about it's contents.
I suggest you divide this into two separate problems; encrypting/decrypting a local file, and uploading/downloading a file. Once both problems are solved, combine them.
|
|
|
|
|
yup - that'd be the way .. I love it when someone comes to me and says 'my program does this and this and this but doesnt work' ... and I reply 'a) define doesnt work and b) does each of those seperate parts work independently before you try and put them together, hmmmm ?' - admittedly, I need to learn more about unit testing with frameworks, but I usually do a better job
'g'
|
|
|
|
|
|
iTextSharp[^].
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
i never use Dependency Injection in apps. i go through few article with Dependency Injection and found the concept is interesting but believe hard to implement in real life. now i want to implement Dependency Injection in my win form apps.
our company work with many shipping company like UPS, Fedex, Purolator etc for now but in future they have plan to works with many other shipping company. i have developed separate separate class library projects for all those shipping company like UPS, Fedex, Purolator and include those dll into our main form apps. the problem is many time we hard code few things in our code like country code etc.
for example i have one form where 4 buttons are there. like those buttons are "Ship with UPS WorldShip", another button there called "Ship with UPS WebAPI", another button there called "Ship with FedEX Desktop Apps" and another last button called "Ship with Fedex WebAPI".
when user click on UPS WorldShip button then a flat file generate in a folder. when user click on UPS WebAPI button then a request goes to UPS site.
when user click on FedEX WinApps button then a flat file generate in a folder. when user click on FedEX WebAPI button then a request goes to FedEx site.
so what i do now when user click on any button then i call a specific function exist in dll to complete the task.
everything is working fine at my end but the problem is when our company start working with another new shipping company then i have to create another class library for that company.
i said i never use DI ever in my apps and have no experience. so some one guide me how could i handle my situation with DI as a result when a new shipping company will join then i do not have to write any extra code. so guide me how to implement DI in my apps and also guide me with how to handle my situation with sample DI code for guidance.
thanks
tbhattacharjee
|
|
|
|
|
DI doesn't work this way. If you have new functionality, then you have to write code. So, if you add a new company and that has specific logic, then you will have to write that logic - DI is not a magic bullet. What it would do, is save you having to write any logic to hook it up to your UI, for instance.
If you're going to do this, then I'd suggest that you read a few artioles here on Code Project. This[^] is a good place to start. Beyond that, I'd also consider investigating MEF.
|
|
|
|
|
Tridip Bhattacharjee wrote: then a request goes to UPS site.
Adding a bit more emphasis to the previous reply - because you are accessing an external service provider you will always need to write new code for each.
Given your description of how you are implementing this it also seems unlikely that you can generalize it either. Which isn't to say that you are doing it wrong but rather because you are using all the shipping options rather than attempting to normalize it that you won't be able to generalize it. And actually I suspect that if you try to generalize it too much that you could end up with problems.
Tridip Bhattacharjee wrote: then i have to create another class library for that company.
Job security.
|
|
|
|
|
This doesn't sound like a job for plain DI. It sounds more like a job for MEF which is more of a plug-in architecture.
How much of the code is straight up copy & paste between different companies?
If the code is 99% duplicate, why not just move the differences into a SQL database or XML file and just have a single common engine that reads the params and uses them? I.e. like instead of hardcoding one dll to fedex and another to ups, just have one method where you pass in the URL or whatever?
Even if the code is more like 50% to 75% different, I'd refactor it to a data driven engine instead of a plug-in architecture.
I'm guessing most of the code is identical... go to this URL to create an order, go to this URL to do this, etc.
If there are a lot of differences, revisiting the data driven model, you can use javascript or even C# scripts as your "plug-in" model. I.e. for fedex you execute this javascript, for ups you do that one.
|
|
|
|
|
thanks for answer. i think i should go for MEF. can u drive me to few good MEF article from where i can learn plug and play architecture maintain by MEF. thanks
tbhattacharjee
|
|
|
|
|
Use Google to search for MEF.
|
|
|
|
|
Hi
I need to draw digits 1, 2 etc with drawing effect in my WinRT application. The requirement is like the application will be drawing the digit.
Any help will be really appreciated.
Thanks in advance.
|
|
|
|
|
You'll need to draw it in discrete steps, building it up bit by bit. What you'll need to use is a BezierSegment to draw rounded elements and a Path to draw the straight bits.
|
|
|
|
|
I would like to come up with C#.NET 3.5 Code review checklist such as Use Properties instead of variables, Use stringbuilder to combine more string values together, Use using block to open connection and so on. Please do share your thoughts to make a complete list. If you have entire list that would be great.
Please note that I'm using .NET Windows Application NOT asp.net.
|
|
|
|
|
You could consider FxCop; it'll perform statical code-analysis, and you can customize the rules. There's a list of warnings on MSDN[^].
|
|
|
|
|
Beside of FxCop mentioned above take also a look at StyleCop[^]
For best results you can use both. FxCop checks compiled assembly while StyleCop the sources so both give different advises about your code.
In both cases you can choose rules to force for your code.
--
"My software never has bugs. It just develops random features."
|
|
|
|
|
Member 3137078 wrote: Use stringbuilder to combine more string values together
As a general statement that is generally not a good rule.
|
|
|
|
|
Right, it should mention loops.
I'd also say not to throw away a perfectly good StringBuilder just to create another; reuse it if possible.
One thing I've seen done all too often is something like:
for each row in a table
instantiate a StringBuilder (with the default length of 16 no less!)
for each column
Append a comma (possibly with a test first)
Append the value
write it somewhere with ToString()
A better pattern is:
instantiate a StringBuilder (ideally with some estimate of how much space is required by the longest record)
for each row in a table
set the StringBuilder's Length to 0
for each column
AppendFormat the value and a comma
write it somewhere with ToString ( 0 , Length-1 ) to eliminate the extraneous comma
|
|
|
|
|
First, assuming that the compiler understands your program no matter how poorly you write it, it is more important that people understand it. From that flows:
Be consistent -- especially in formatting.
Be verbose -- "saving keystrokes" is a bad thing in the long run.
Too many comments is better than too few -- at least they're easier to delete than add.
Avoid premature optimization.
Expect that the developer who might come after you will come after you.
|
|
|
|
|
hi guys
i just want a program that can connect to other program on other computer and also get connected , and i'll make it clear .
i want a program that send and recive data .
like a server and client in one program .
like a chat program .
|
|
|
|
|
Then write it! We're not going to do the work for you.
|
|
|
|
|
okay then .
the code that im using in the server side is like this
Thread thr;
Socket Soc = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint ipend = new IPEndPoint(IPAddress.Any, 8000);
private void buttonX1_Click(object sender, EventArgs e)
{
thr = new Thread(Listen);
thr.Start();
}
void Listen()
{
Soc.Bind(ipend);
Soc.Listen(10);
byte[] data = new byte[500];
while (true)
{
Socket client = Soc.Accept();
client.Receive(data);
sth = Encoding.ASCII.GetString(data);
client.Shutdown(SocketShutdown.Both);
client.Close();
}
}
and the client side is like this
Socket soc = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint ipend = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8000);
soc.Connect(ipend);
string input = textBoxX1.Text;
byte[] data = new byte[500];
data = Encoding.ASCII.GetBytes(input);
soc.Send(data);
string sth = "";
sth = Encoding.ASCII.GetString(data1);
textBoxX2.Text = sth;
i think you know what im done , but this code is doing so far i get of it . i click the listen button in the server side and the server w'll listen to the line so after i fill the textbox in the client form and click the send button it'll send the data and i can get the data perfectly in the server side
but i need two more things to be done , i want the server do the same thing that the client do that's mean send data to client . and i want the client do the same thing as server that's mean get the data from the server .
i hope you get the idea .
both of them do both sending and receiving at the same time .
how that should be possible ?
|
|
|
|