|
Hi
I have a binary file and I would like to start reading it from an origin. That origin is the location of a string.
I try to find that string with this method:
public long STRLOC(string File, string strToDig)
{
FileStream fs = null;
BinaryReader br = null;
try { fs = new FileStream(File, FileMode.Open, FileAccess.Read); }
catch { throw new Exception("Dosya akışı oluşturulamadı."); }
try { br = new BinaryReader(fs); }
catch { throw new Exception("Binary okuyucu oluşturulamadı."); }
try
{
byte[] icerik = new byte[fs.Length];
br.Read(icerik, 0, (int)br.BaseStream.Length);
string asText = Encoding.UTF8.GetString(icerik);
int index = asText.IndexOf(strToDig);
if (index == -1)
return -1;
if (strToDig != asText.Substring(index, strToDig.Length))
return -2;
return index;
}
catch { throw new Exception("Dosya okunurken hata oluştu."); }
finally { br.Close(); fs.Close(); fs.Dispose(); }
}
I successfully get the location of that string with this method. My string starts at 551828.
Then I want to start reading the file to it's end with this method:
public string ReadBinary(string File, long origin)
{
FileStream fs = null;
BinaryReader br = null;
try { fs = new FileStream(File, FileMode.Open, FileAccess.Read); }
catch { throw new Exception("Dosya akışı oluşturulamadı."); }
try { br = new BinaryReader(fs); }
catch { throw new Exception("Binary okuyucu oluşturulamadı."); }
try
{
br.BaseStream.Position = origin;
byte[] icerik = new byte[br.BaseStream.Length - origin];
br.Read(icerik, 0, (int)(br.BaseStream.Length - origin));
return Encoding.ASCII.GetString(icerik);
}
catch { throw new Exception("Dosya okunurken hata oluştu."); }
finally { br.Close(); fs.Close(); fs.Dispose(); }
}
I call it with ReadBinary("MY FILE'S LOCATION", 551828)
But it doesn't start reading from the position of my string. It just starts from somewhere a lot before my string or beginning.
What am I doing here wrong? Why doesn't my BinaryReader start from the location that I've set with br.BaseStream.Position = origin; , I've tried br.BaseStream.Seek(origin,SeekOrigin.Begin); but it doesn't work too.
Thanks in advance.
|
|
|
|
|
Hello
Im trying to build a client in c# that talks with some remote (php)server with SOAP using the NuSOAP library.
Here im using a struct/object that will containt the user info of some user:
public struct UserProfile {
public string username;
public string password;
public string email;
public string site;
public string signature;
public int age;
public int points;
And this is the PHP Code:
server->wsdl->addComplexType(
'UserProfile',
'complexType',
'struct',
'all',
'',
array(
'username' => array('name' => 'username', 'type' => 'xsd:string'),
'password' => array('name' => 'password', 'type' => 'xsd:string'),
'email' => array('name' => 'email', 'type' => 'xsd:string'),
'site' => array('name' => 'site', 'type' => 'xsd:string'),
'signature' => array('name' => 'signature', 'type' => 'xsd:string'),
'age' => array('name' => 'age', 'type' => 'xsd:int'),
'points' => array('name' => 'username', 'type' => 'xsd:int'),
)
);
$server->wsdl->addComplexType(
'UserProfileArray',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:UserProfile[]')),
'tns:UserProfile'
);
$server->register("getUserProfile",
array(),
array('return' => 'tns:UserProfileArray'),
$namespace,
false,
'rpc',
false,
'Get the user profile object'
);
function getUserProfile(){
$profile['username'] = "user";
$profile['password'] = "pass";
$profile['email'] = "usern@ame";
$profile['site'] = "u.com";
$profile['signature'] = "usucsdckme";
$profile['age'] = 111;
$profile['points'] = time() / 2444;
return $profile;
}
Now I already have a working login function, and I want to get the info about the logged in user but I dont know howto obtain these. This is what im using to get the userinfo:
string user = txtUser.Text;
string pass = txtPass.Text;
SimpleService.SimpleService service = new SimpleService.SimpleService();
if(service.login(user, pass)){
}
SoapApp.SimpleService.UserProfile[] user = service.getUserProfile();
MessageBox.Show(user[0].username + "--" + user[0].points);
The getUserProfile() function produces an error:
System.Web.Services.Protocols.SoapException was unhandled
Message="unable to serialize result"
Source="System.Web.Services"
The article I used for this was from: http://www.sanity-free.org/125/php_webservices_and_csharp_dotnet_soap_clients.html[^]
The difference on what they are doing and what I try to do is that I only want to get one object returned instead of multiple 'MySoapObjects'.
I hope someone is familiar with this and could help me, thanks in advance!
Regards,
opx
|
|
|
|
|
Ok, php and .net are different platform. So data structers are different. Normally different platform can not talk each other.
If we talk about windows side; windows solve this problem with WCF (Window Communication Foundation). On java side; Sun's Project Tango
http://java.sun.com/developer/technicalArticles/glassfish/ProjectTango/[^]
But your server side is PHP. How to solve I don't know. May you can parse XML format. I know it is not good solution but you can solve using XML parsing.
Best Regards...
|
|
|
|
|
Thank you sir
Parsing XML/String, I can live with that.
Thanks again,
- opx
|
|
|
|
|
|
dataminers wrote: Ok, php and .net are different platform. So data structers are different. Normally different platform can not talk each other.
that's totally incorrect.
the whole point of service oriented architectures is so that disparate systems can work together.
C# can talk to java, java can talk to php, php can talk to C# and vice versa. it doesn't matter what the source or destination languages are, as long as they can serialize/encode and deserialize/decode an http request / response to and from SOAP.
|
|
|
|
|
change
$server->register("getUserProfile",
array(),
array('return' => 'tns:UserProfileArray'),
$namespace,
false,
'rpc',
false,
'Get the user profile object'
);
to
$server->register("getUserProfile",
array(),
array('return' => 'tns:UserProfile'),
$namespace,
false,
'rpc',
false,
'Get the user profile object'
);
to return one profile. There's no point in defining an array of user profiles if all you want to return is one.
|
|
|
|
|
Hi guys! I have an image that I need to process. Actually I want to change brightness and contrast level. I tried to use a lot of algorithms and filters for processing such as AForge.Imaging.Filters, Color Matrix and many many others but no one can't provide a high processing performance. The main idea - to make a program which will allow to change brightness and contrast of the image in realtime by using TrackBar component like it realized in Adobe photoshop or in Windows Vista Photo Gallery in Photo Editing mode. The main problem - processing performance. For small size images Aforge filters works perfectly, but if I try to process the image which has been made by the 9.0Mpx digital camera, with resolution 3712x2088 it becomes a really big problem. Aforge brightness filter works too slow for big bitmaps. If anybody know how to resolve this problem, please help. I wish to know how brightness correction works in Vista Photo gallery... It can change brightness for any image with any size in realtime with incredible speed even if you will shake trackbar pointer side by side. How did they realized it??
|
|
|
|
|
I've dealt with this issue before by using separate bitmaps. You have one smaller bitmap for display, and your full bitmap is being adjusted in a background thread. When the slider is moved, you only adjust the display bitmap, and queue up the change for the full bitmap. Once the user clicks OK on the dialog (or is idle for a long enough period), then you do the operation on the full bitmap using the final value. I'm not sure if this will work for you or not, as it really depends on the app.
Also, this type of bitmap operation is trivial to multithread. There are probably some codeproject articles talking about this.
-----
In the land of the blind, the one eyed man is king.
|
|
|
|
|
Hi,
if you want to see the result while changing some parameters (e.g. by sliding a scrollbar), this would be my approach:
1. create a new image with the exact resolution you are using to currently display it; I assume that would be much smaller than your original image. Possibly even use half that size, and display it at 1/1 or 2/1 scale.
2. apply the algorithms of interest to that image, while changing the parameters;
3. when you are done setting the parameters, apply them to the original image (at full size).
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Guys, I thought about your decisions already to use thumbnails instead of main image. I actually tried to work with small images, but the size of image at which i got accepting filter performance was too small. I have to use an image cropping tool too and that is the main cause why I don't want to use small images. Maybe somebody knows some third party filters with good performance or how this functions realized in Photoshop or Vista? I really don't know how to use exposure features for large images. Maybe it can be possible to involve some graphic card possibility or something else...
|
|
|
|
|
Hey guys.
I'm working on a syntax highlighter, in which my current method of highlighting (RichTextBox + TextChanged + Regular Expressions) has become to unsmooth and slow. I've literally spent days searching for other methods, and the best one I've found was the ICSharpCode.TextEditor, however when taking I look into it I was unable to find the code in which it highlights its code.
So any of you guys have some experience here? Any help'd be appreciated, but code examples more.
PS: my current highlighter is about 10 seconds about highlighting 2100 lines of code, where ICSharpCode.TextEditor is about 1 - 2 seconds.
Theo
|
|
|
|
|
Hi,
You are doing it in the logical way, just like most people asking questions here about the subject; however IMO it is completely inappropriate for a range of reasons:
1. an RTB is a stupid control that doesn't scale well as it holds all the text as one large string, so it may or may not work well for 100 lines, it is bound to fail at serving you right for 10,000 lines of text. I did my own editor based on a Panel; that takes:
- keyboard and mouse handlers to do the editing myself;
- a Paint handler using Graphics.DrawString.
2. Regex is a powerful tool with big performance hits; I tend not to use it, except for offering complex search/replace capabilities in the hands of your apps' users. For maximum speed, code the search and replace stuff yourself, using string methods such as IndexOf and Contains.
3. Finally, my syntax colorizer is inside my Paint handler: it skips all the lines that are scrolled over, then parses just the 20 to 40 lines that are visible, and stops when it reaches the last visible line. In order to correctly skip the beginning of the text, my data structures are such that I keep a few flags for each line of text, related to opening and closing of multi-line comments; the idea is I can start parsing a (modified) line without the need to parse again all previous lines.
The net result is:
- I have an editor that works the way I like it;
- it syntax-colorizes instantaneously;
- when I select some text, it immediately highlights identical strings in the visible part of the text (something extremely useful Visual Studio doesn't do for me).
My advice to you, assuming you will want to keep the RTB, is to replace the Regex parts by string operations.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Thanks for the great reply Luc! It was really helpful!
That idea with the Panel sounds very cool, you still got the source code? I'd love to take a look at it.
And really, I don't really mind if I need to replace the RTB, if it's slow and bad, I'll anytime replace it with something better.
I hope you still have that source, it'd help me soooo much.
Oh yeah, did I mention that I also used StringBuilders in my highlighter? I mean, to build the RTF.
Thanks,
Theo
modified on Tuesday, July 14, 2009 3:01 PM
|
|
|
|
|
Hi,
I created my own Explorer+IDE (it supports a build process for a range of microprocessors, each using different compilers and linkers); and the editor is a big chunk of that. It isn't some small piece of code I can easily carve out and hand over, if I would like to do so, which I don't. I have my own way of dealing with file systems, with logging, with app settings, etc. One of the strong points at the functional level is the find capabilities, which exceed anything I have ever seen in another IDE.
The entire app exceeds 70000 lines of code right now (in more than 250 files), and it continues to grow as I add features. The editor panel isn't a real control, I didn't use many controls anyhow, they tend to slow down things too much. The basic philosophy is to use existing classes/controls when they fit perfectly, and create my own when they don't. So I refuse to fight against shortcomings of say a RichTextBox, I create what I need from scratch. It takes a while, but it pays of.
So in summary I can give you my view, my advice, but not much useful code.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
OK, I'll take that as a no
But anyways, I pretty think I know what to do with the Panel to make it look like the RichTextBox:
- 3D borders.
- Window -colored background.
- When user hovers over the Panel, change cursor.
- When user clicks the Panel, create a custom cursor by using the |, using a timer to display and hide it.
- When user begins to write, have a handler that handles KeyPress (KeyDown maybe?) which draws (?) the text. Have the whole typed text in a string and have an array with all the lines in it.
Is it something like that? You sure you can't just send me the extended Panel Class/Control/Component (?)? Maybe just a little sneakpeak? If not, can I have your MSN or Skype or anything really so I can instant message you when I'm in trouble?
Theo
|
|
|
|
|
You're pretty close, except for the details:
- I didn't want to look it exactly like an RTB, however that is not a primary concern;
- I draw my own cursor, I don't use a Windows cursor; I want it to be located and sized exactly up to the pixel, all my cursors have to be in sync, and the cursor resizes when I resize my fonts;
- I need KeyDown, KeyPress and KeyUp events for functional reasons;
- each line of text becomes a little object holding a string, and some administrative information;
- I keep textlines in a List obviously, not an array.
And you are free to post questions, I am watching several forums including this one. So there is a good chance you will get my reply.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
modified on Wednesday, July 15, 2009 6:22 AM
|
|
|
|
|
You don't got some kind of instant messager? I'd be much easier for me.
Ehhh, I'm kinda stuck at the Caret thingy... How do I convert text locations to Points?
Code:
namespace Storm.TextBox.Document
{
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
public class Caret : Control
{
#region Members
private Timer caretTimer = new Timer();
private int Interval = 50;
private string caretString = "|";
private Font caretFont = new Font(new Font("Courier New", 9.25f), FontStyle.Bold);
private Color caretColor = SystemColors.ControlText;
private bool caretDisplay = true;
private Point caretPos = new Point(-1, -1);
private Size caretSize;
#endregion
#region Properties
public Font CaretFont
{
get { return caretFont; }
set { caretFont = value; }
}
public string DisplayString
{
get { return caretString; }
set { caretString = value; }
}
public int CaretInterval
{
get { return Interval; }
set { Interval = value; }
}
#endregion
#region Methods
private void onTick(object sender, EventArgs e)
{
caretDisplay = !caretDisplay;
Invalidate();
}
private void DrawCaret(Graphics g)
{
if (caretDisplay == true)
{
Rectangle r = new Rectangle(caretPos, caretSize);
ControlPaint.DrawStringDisabled(g, caretString, caretFont, caretColor, r, TextFormatFlags.Default);
}
}
private void onPaint(object sender, PaintEventArgs e)
{
DrawCaret(e.Graphics);
}
#endregion
public Caret()
{
Paint += new PaintEventHandler(onPaint);
caretTimer.Enabled = true;
caretTimer.Tick += new EventHandler(onTick);
caretTimer.Start();
}
}
}
|
|
|
|
|
No, I don't do chat, twitter, and the like.
IIRC monospaced fonts such as Courier New always have integral character widths; so what I probably do is int charwidth=(int)(0.5+Graphics.MeasureString(someLongString).Width/someLongString.Length); once, then use that charwidth to map column numbers to/from pixel numbers.
If the above were incorrect, changing the fontsize slightly would be sufficient to make it hold true.
BTW: for proportional fonts things are much more complex, since then you have to really convert each and every position on its own merits.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Hmm... someLongString being the... what?
> charwidth to map column numbers to/from pixel numbers.
I don't get that, sorry :s
|
|
|
|
|
just a long string with arbitrary content; although it probably does not matter much since all characters are assumed to have equal width, so a short string should give the same result in theory.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Hmm, that is weird, it says MeasureString takes 4 arguments. What should I put in the others?
Could you also explain this: charwidth to map column numbers to/from pixel numbers. ?
|
|
|
|
|
Yes, I only gave pseudo-code to convey the idea.
For the details read the documentation, that is what it is for. I will not hold your hand all the way.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Hmm, okay I figured it out
I was thinking, since I'm making the Document class..
Wouldn't it be smarter to have a Dictionary<int, string=""> than a List<string>? Since I'm creating a method "UpdateLine" that takes (int lineNum, string newLine)? The reason I'm asking is because I'm not sure if it's the most efficient way.
Really, I now it's kinda disturbing that I ask so much, but I am totally new to making this custom-Caret-Cursor-textpoint-to-pixel-thingy, I know nothing about it. I simply always used the default Windows controls or inheritted them in my own. Please bear with me
The thing about the map column thing... should I simply just, when the Document is updated, add the charWidth to the current caret point (of course substract when the user hit backspace) ? That is what seems most logical to me.
|
|
|
|
|
Hi,
having a method UpdateLine(int lineNum, string newLine) seems appropriate.
you don't need a Dictionary for that, most collections support indexing, so you could have a List<string> textLines and then perform textLines[ineNum]=newLine; as if it were an array, except I guess for adding lines beyond the current end of the list, then you would need textLines.Add(newLine);
I suggest you read up on indexers[^].
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|