|
What does ClearFields() and EnableFieldsEvents() do?
|
|
|
|
|
ClearFields is an event that goes back to the main form and clear the fields out.
mvm.ClearFields += this.ClearFields;
private void ClearFields()
{
txUsername.Clear();
cbA.IsChecked = false;
cbB.IsChecked = false;
cbB.IsChecked = false;
}
EnableFields just sets isEnabled to true for the controls.
Tee123
|
|
|
|
|
I've been trying to get this method to work. According to others and everything I've read, this should be the answer. As you can see, I've tried different methods and under machines that I don't have permission, I get error code 5 (no permission) but on other machines I get error code 87 (invalid parameter. Please help!
Here's the code:
Boolean SetComputerName(String name)
{
String RegLocComputerName = @"SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName";
try
{
string compPath= "Win32_ComputerSystem.Name='" + System.Environment.MachineName + "'";
ManagementObject mo = new ManagementObject(compPath);
{
ManagementBaseObject inputArgs = mo.GetMethodParameters("Rename");
inputArgs["Name"] = name;
ManagementBaseObject output = mo.InvokeMethod("Rename", inputArgs, null);
uint retValue = (uint)Convert.ChangeType(output.Properties["ReturnValue"].Value, typeof(uint));
if (retValue != 0)
{
MessageBox.Show(String.Format("Computer could not be changed due to unknown reason. return = {0}",retValue));
throw new Exception("Computer could not be changed due to unknown reason.");
}
}
RegistryKey ComputerName = Registry.LocalMachine.OpenSubKey(RegLocComputerName);
if (ComputerName == null)
{
throw new Exception("Registry location '" + RegLocComputerName + "' is not readable.");
}
if (((String)ComputerName.GetValue("ComputerName")) != Name)
{
throw new Exception("The computer name was set by WMI but was not updated in the registry location: '" + RegLocComputerName + "'");
}
ComputerName.Close();
ComputerName.Dispose();
}
catch (Exception ex)
{
return false;
}
return true;
}
|
|
|
|
|
If you dont have permission you cannot execute the Rename operation, but the reason for Invalid parameter is you need to provide user name and password along with the new name. Check this
http://www.codeproject.com/Questions/267044/Rename-a-Remote-Computer-and-remove-it-from-the-do
Dim inParams As ManagementBaseObject = _
classInstance.GetMethodParameters("Rename")
inParams("Name") = "NewComputerName"
inParams("Password") = "xxxxxxxx"
inParams("UserName") = "xxxxxxxx"
Dim outParams As ManagementBaseObject = _
classInstance.InvokeMethod("Rename", inParams, Nothing)
Jibesh V P
|
|
|
|
|
In the docs it says that if the username is null then it uses the current user which in this case is an admin account. See:
http://msdn.microsoft.com/en-us/library/aa393056(VS.85).aspx[^]
I've tried this on a computer with and without those set to null and I still get the same issue. On a computer that I don't have permission, it gives the error code 5 which is no permission.
I also have tried this on a computer of which I am personally logged in with my username and password and I still get error 87 with the username and password set to the appropriate strings.
Thanks.
modified 11-Jan-13 15:38pm.
|
|
|
|
|
Turns out that part of the problem is that the name had '.' in it, which apparently isn't allowed.
That said, even though the user has Admin permissions, I can't get it to do it. I *can* run the shell command via a cmd window with Admin rights.
Anyone know how to get around this?
|
|
|
|
|
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."
|
|
|
|