|
bwBooks.Write(FillBlanks(bookTittle, 30));
bwBooks.Write(FillBlanks(bookTittle,25));
bwBooks.Write(FillBlanks(pubCompany, 15));
the book tittle is a mistake i have made
this the code I use to read the Books
<pre lang="c#">public static void ReadBooks()
{
bool found = false;
Console.WriteLine("Write the number u are looking for");
int wantedNR = Int32.Parse(Console.ReadLine());
FileStream file = new FileStream("Books.bin", FileMode.Open, FileAccess.Read);
BinaryReader binReader = new BinaryReader(file);
while (file.Position!=file.Length)
{
int bookNumber = binReader.ReadInt32();
if (bookNumber==wantedNR)
{
found=true;
string bookName = binReader.ReadString();
string authorName = binReader.ReadString();
string pubCompany = binReader.ReadString();
Console.WriteLine("============================================");
Console.WriteLine("Book Number:" + bookNumber);
Console.WriteLine("Book Name:" + bookName);
Console.WriteLine("Author:" + authorName);
Console.WriteLine("Publishing Company:" + pubCompany);
Console.WriteLine("===========================================");
break;
}
else
{
binReader.BaseStream.Seek(73, SeekOrigin.Current);
}
}
binReader.Close();
file.Close();
if (found == false)
{
Console.WriteLine("The Wanted Number u are looking for{0} doesn't exist in this file", wantedNR);
}
}
if u can help me and tell me how to use this Dictionary thing u posted(since this is the first time I see it) it would help me lot since I really don't know how to do this
|
|
|
|
|
well, Im not going to do all your work for you - as a programmer, you are expected to know how to research for example. So, here's a start point for using a dictionary
http://www.dotnetperls.com/dictionary[^]
... and you have most of the code you need in ReadBooks
So, I would do a number of phases
1) copy all the code in ReadBooks() to a new method called (for example) ReadAllBooks
2) remove the input/check logic from ReadAllBooks so that it prints the entire file - make sure this works before proceeding !
3) Once (2) is working, add (for example)
Dictionary<String, Int> booktitle_counts = new Dictionary<String, Int>();
and the logic I outlined in my first reply for checking if a booktitle exists and adding it if it doesnt or incrementing the counter if it does already exist
4) Then you simply need to remove the book print code, and add some code to loop through the dictionary looking at the book title vs counts - big hint - look at the reference I gave you and see 'foreach'
Learn how to break your problems down into small chunks - then build up/extend code, making sure the basic parts work first, and each subsequent change works
|
|
|
|
|
Thank You very much for your Help
I will now read the content of the web page u sent me and will check if i can do it
Thanks aggain
|
|
|
|
|
Hello fellow coders, I was wondering if anyone ever experienced any latency in the button click when using the MVVM approach? I have 4 buttons and it seems when I click on either one initially there's a 3 second latency before the text changes and the other buttons become disabled. After that initial click it runs quicker. No matter which button it is on that first click it takes 3 seconds to respond then after that each button responds immediately. So here is what I'm doing.
1. I'm using the RelayCommand that was located in Josh Smith's article.
2. I have the following setup in my xaml behind my buttons. Each button has a different CommandParameter.
<Button x:Name="btnAddSaveUpdate" Content="{Binding AddSaveUpdateContent}" Style="{StaticResource ButtonStyle}" Command="{Binding AddSaveUpdateCmd}" CommandParameter="AddSaveButton" />
3. In the creation of my mobileViewModel I have the following code in the constructor. I assign the AddSaveUpdateContent property to update the text. Note, that this property has an OnPropertyChanged call inside.
_addSaveUpdateCmd = new RelayCommand(param => OnExecute(param), this.CanExecute);
AddSaveUpdateContent = "Add";
4. Inside the CanExecute is a case statement that gets the CommandParameter:
case "AddSaveButton":
return true;
5. Inside the OnExecute is another case statement that gets the CommandParameter as well then calls another method:
case "AddSaveButton":
PerformButtonTask(AddSaveUpdateContent);
break;
6. Then in my PerformButtonTask method all I'm doing is is running through one more case statment to perform the appropriate task. The EnableFields and ClearFields are events that call a method in the code behind on the xaml page.
case "Add":
AddSaveUpdateContent = "Save";
ExitCancelCmdContent = "Cancel";
ClearFields();
EnableFieldsEvent(true);
break;
That's pretty much it. So, if anyone has any ideas please share. Thanks.
Update: Just to let you know. The problem is occurring in Visual Studio 2012 in debug mode; however, when I create my executable the response is immediately as expected. So, is because of the development environment?
Tee123
|
|
|
|
|
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.
|
|
|
|