|
Why on earth are you reading the file four characters at a time, looking for an identifier? The file is organised into chunks, where the four character identifier is followed by an int containing the size of the chunk. Just read the chunk size and use that to skip to the next chunk, instead of reading throught the chunk four characters at a time.
Besides, there is no guarantee that the chunk size is a multiple of four, so using that method you may just as well miss the next identifier.
Also, you are catching exceptions and just ignoring them, you should never do that. If you re-throw the exception, you will probably find that when the method takes long time to run, you have missed the data identifier so that you are reading the entire file, and then continue to try to read way past the end of the file, as your loop runs for four times the size of the file.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hi Guffa,
This is the first time I've ever attempted dealing with files like this. I'm a C# newbie (as you can tell) your points about this are sound (scuse the pun) and make complete sense.
If you have the time is there any chance you could provide a code example? I'm going to go and have a play with this idea and see what I can do.
Much appreciated.
Cheers,
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
Hmm ... it doesn't appear to be as simple as you suggest.
I have pieced together some code that performs as you suggest and i'm testing it with some wav files I have here ... after the initial "RIFF" chunk and the "fmt " chunk I have a file here with a "fact" chunk
public class factChunk
{
public string sChunkID;
public uint dwChunkSize;
public uint dwNumSamples;
}
this particular file reports its factChunk ChunkSize as 4 ...
Looking at this file in Riffpad the chunks are detailed as
RIFF = len 611548 offset=0
fmt = len 18 offset 20
fact = len 4 offset 46
smpl = len 54 offset 58
data = len 611348 offset 120
INFO = len 80 offset 611480
INAM = len 17 offset 611488
IPRD = len 15 offset 611514
ISFT = len 17 offset 611538
I don't see how to make these correlate to positions leading on from each other? Can anyone help?
I'm reading in the RIFF and fmt chunks as they are standard to all wav files, then i'm kicking off a method that attempts to find the other chunks, but its completely failing to do so based on the reported chunk sizes.
public void FindNextChunk(BinaryReader bReader, long offset)
{
_startPos = bReader.BaseStream.Position;
genchunk.ChunkID = new string(bReader.ReadChars(4));
genchunk.ChunkSize = bReader.ReadUInt32();
FindNextChunk(bReader, _startPos + (long)genchunk.ChunkSize);
}
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
The chunk size is not including the identifier and chunk size, so you would have to add 8 to your calculation.
Or simply go from the current position:
bReader.BaseStream.Seek((long)genchunk.ChunkSize, SeekOrigin.Current);
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Brilliant!! Thanks for this Guffa, much appreciated!
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
Hi,
I created a Form with a menu bar with a few menu itens pre-made. I've setted the Modifiers to "protected" (or even to public) but when I create an inherited form from this one, the VS (2005) Designer doesn't allow me to add menu itens. Is there any way to make it work?
Thanks,
Dirso
|
|
|
|
|
You remembered that there's "Menu Items", and a "Menu Strip" right?
The menu strip needs to be set to protected or public.
Cheers,
|
|
|
|
|
That' what I did. I can't understand why that "lock" symbol keeps showing in the designer (and all its properties are disabled in the properties window.
Thanks,
Dirso
|
|
|
|
|
Hmmm works fine for me.
Care to post some code?
|
|
|
|
|
I uploaded the solution source code (VS2005) to my website - since I didn't know what code to post - it's only 27k. I hope you can help me.
http://www.jrsoftwares.com.br/JRFW.zip
Thanks,
Dirso
|
|
|
|
|
This worked fine for me:
<br />
<br />
mmMain.Items.Add(new ToolStripMenuItem("Testing"));<br />
<br />
I can't spot why it's breaking on your end.
|
|
|
|
|
Hi,
Not breaking, it works for me too. My question is about the designer: why can't I edit the control at design time?
Thanks,
Dirso
|
|
|
|
|
Opps I've misinterpreted your question.
Your problem is one that is often brought up.
this might help.
There is a good article on this topic somewhere on codeproject as well, but the search is not working for me at the moment.
Cheers,
|
|
|
|
|
Hi,
Thanks for your help. I think this is the best I can get from the current VS version, hopefully it gets better with 2008 or 2100
Thanks a lot,
Dirso
|
|
|
|
|
Well, it was a nice article and at least the form properties are enabled (they weren't before). But I still can't edit the menu itens in the designer. If you find anything else about this issue, I'll appreciate. If I find the solution by myself I'll post it here as well.
Thanks a lot,
Dirso
|
|
|
|
|
Is it possible/valid to call an extension(ext.) method from another ext. method?
Like I've two ext. methods which extend DataContext class : (1) SaveEntity(this DataContext dc, T Entity) & (2) SaveCollection(this DataContext dc, List<T> Colln)
I want to call SaveEntity method from(within) SaveCollection method in a foreach loop like :
foreach(T entity in Colln)
{
if(entity.IsNew) dc.SaveEntity(entity);
if(entity.IsModified) dc.SaveEntity(entity);
....
}
I've tried with various syntax-combinations for calling "SaveEntity" from "SaveCollection" method but end up with compilation-errors.
Will appreciate if someone can let me know (or direct to some link) if this is a valid/supported-feature and if yes, what could be the syntax for calling "SaveEntity" method.
Thanks for reading this & your replies,
Rajesh Moriyani
rkmoriyani@gmail.com
|
|
|
|
|
Calling extension methods from another is quite possible.
I think the problem is that your class is named something like Extensions<t>, which causes the problem. Instead of putting T in the class, put it in the method signature like so: public static void SaveEntity<t>(this DataContext dc, T Entity) where T : whatever
Also, is the containing class static?
If there are still some compilation errors, please post them.
|
|
|
|
|
Yes you can an extension method within inside an extension method.
public static class ExtensionClass1
{
public static string Info<T> (this T obj) where T:class
{
return obj.MoreInfo<T>() + ":" + obj.GetType().Name;
}
}
public static class ExtensionClass2
{
public static string MoreInfo<T>(this object obj) where T: class
{
return obj.GetType().Assembly.FullName;
}
}
Tariq A Karim
http://moplah.blogspot.com/
|
|
|
|
|
I've created buttons automatically based on rows of information. When someone pushes the button I call the eventhandler button1_Click(object sender, EventArgs e).
Is there anyway to tell what the name of the button is? I'm using c# in asp.net. When debugging i can see the clientid but cant get it from sender.
|
|
|
|
|
Cast the sender object to a Button:
Button myButton = sender as Button;
if(myButton != null)
{
string name = myButton.Name;
}
|
|
|
|
|
That did it thanks. Since im using asp i used myButton.id instead of name. Thanks again.
|
|
|
|
|
Hi All,
I have a datatable with some data :
ActivityNr ActivityStartTime ActivityDuration
001 20:30 00:30
002 20:30 00:40
003 20:40 00:30
004 20:50 00:30
005 20:55 00:30
As you can see, Activity 001 and 002 have the same StartTime(20:30), bud activity 002 has a longer Duration(40 minutes) then Activity 001(30 minutes).
Now i have to check all activities StartTimes and when they have the same StartTime(like 001 and 002), then i have to check the 'ActivtityDuration' of those Activities and delete the Activity with shorter duration from the datatable.
Assuming the datatable above, the end resulat most be:
ActivityNr ActivityStartTime ActivityDuration
002 20:30 00:40
003 20:40 00:30
004 20:50 00:30
005 20:55 00:30
001 is deleted because it had the same starttime as 002, bud a shorter duration.
Can anyone help me with this issue with some code ?
Thanx.
|
|
|
|
|
OK guys its clunky but it works lol. Still have a little issue though maybe you guys can help me with a solution or just tell me it cant be done either way.
anyway, I can display the image and if the user types in the captcha it will validate, however since i had to do a if (!Page.IsPostBack) in order for the captcha text not to override itself upon every Async post back it now wont refresh the image if someone clicks get new image.
is there a way i can make this Unaffected by anything causing a post back except my label button?
The Control shown below is being placed onto my Default.aspx page. and the lblbutton is named lbtnCaptchaRefresh.
if i remember right i cant cross name spaces in a custom control since the name space of the current project will never be the same between two projects.
I've also thought about using it as an embedded resources, but not sure how that would work on dynamically created images.
here is the code:
1. using System;
2. using System.Collections.Generic;
3. using System.ComponentModel;
4. using System.Text;
5. using System.Web;
6. using System.Web.UI;
7. using System.Web.UI.WebControls;
8. using System.Drawing;
9. using System.Drawing.Drawing2D;
10. using System.Drawing.Imaging;
11. using System.IO;
12. using System.Net;
13.
14. namespace Captcha
15. {
16. [DefaultProperty("Text")]
17. [ToolboxData("<{0}:Captcha runat=server>")]
18. public class Captcha : WebControl
19. {
20.
21. [Bindable(true)]
22. [Category("Appearance")]
23. [DefaultValue("")]
24. [Localizable(true)]
25.
26.
219. public string BuildImage()
220. {
270.
313. captchafont.Dispose();
314. captchafont2.Dispose();
315. captchagraphic.Dispose();
316. try
317. {
318. captchabmp.Save(imageurl, ImageFormat.Jpeg);
319. }
320. catch (Exception ex)
321. {
322. Context.Response.Write(ex.ToString());
323. }
324. HttpContext.Current.Session.Add("CaptchaURL", IMAGE);
325. HttpContext.Current.Session.Add("captchastr", captchastr);
326.
327.
328.
333.
334. captchabmp.Dispose();
335.
336.
337. return imageurl;
338. }
339. protected override void OnInit(EventArgs e)
340. {
341. base.OnInit(e);
342. if (!Page.IsPostBack)
343. {
344. BuildImage();
345. }
346.
347. }
348.
349. protected override void Render(HtmlTextWriter writer)
350. {
351.
352.
353. writer.RenderBeginTag("img src=\"" + imageurl + "\"");
354. writer.RenderEndTag();
355.
356. base.Render(writer);
357.
358. }
359.
360.
361. }
362. }
|
|
|
|
|
I guess you want the ASP.NET forum ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Well it is an asp.net project with C# code behind, however the captcha is all C# i need to be able to grab the asp control from my default page from the Custom Server Control which is entirely C#.
|
|
|
|