Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
R

Ravadre

@Ravadre
About
Posts
70
Topics
6
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Two-way binding problem
    R Ravadre

    Working great, I think I've tried to over-Xaml heh :). I can see how this can be useful, altough not in every situation, but still, works fine. Thank you very much for the support.

    WPF wpf help csharp wcf com

  • Two-way binding problem
    R Ravadre

    I think we need a 'reset', cause I'm a bit lost in our discussion as well :). So: 1. Not, I do not have any problems with code not working, I'm just referring to your statement, that I could throw out XManager from resources. 2. Let's consider such code (pseudo-xaml):

    <Window>
    <Window.Resources>
    <local:XManager x:Key="xManager"/>
    </Window.Resources>
    <Grid DataContext="{Binding Source={StaticResource xManager}}">
    ...
    <TextBox Text="{Binding Mode=TwoWay, Path=ActiveSession.InputText}" />
    </Grid>
    </Window>

    This is a simplified situation of what I have right now in my code. Referring to your post, I could throw out xManager from resources -> this implies that I create instance of the XManager in the code, fe. in the Window ctor; my question is then, how I could refer to such an instance in XAML in DataContext, and if it's not easy / possible, what's the advantage of throwing out xManager from resources. Also, inside a code I did something like this:

    XManager xMgr;
    public MainWindow()
    {
    InitializeComponent();
    xMgr = (XManager)FindResource("xManager");

    So basically, I do have a straightforward access to this instance from a code.

    WPF wpf help csharp wcf com

  • Two-way binding problem
    R Ravadre

    I do get your point, I just don't see why I can't use XManager as a resource, and how else I can refer to it's instance, if I won't declare it this way? I'm using Data contexts with success while referring to resources, using DataContext="{Binding Source={StaticResource resourceKeyName}}"

    WPF wpf help csharp wcf com

  • Two-way binding problem
    R Ravadre

    Karl Shifflett wrote:

    The Path "ActiveX.Text" should be "Text" Change to: <Binding Mode="TwoWay" Source="{StaticResource xManager}" Path=".Text" />

    I've actually did, just forgot to include this change in my post :), actually, I've manage to make it work without this wrapper thing on XManager. If I would set Path="Text", I'd have to include this wrapper, so XManager would have to catch it's activeX text change and repost it, but now for some reason I am able to set two way binding without this wrapper, just binding to Path="ActiveX.Text" (it did not work earlier heh).

    Karl Shifflett wrote:

    BTW: Any reason you're not setting the DataContext on the TextBoxes Parent container to an instance of the xManager class? Then you don't need a resource. Your application may need to follow the pattern you've described, just want me sure you knew there are other ways.

    This may be a newbie question, but how I do that? If I won't add the XManager to window resources, but only create it's instance in the code part, I don't see any of binding to it, I was actually thinking is it possible to bind to an instance of a class that was created in code, but I gave up and just used resources.

    WPF wpf help csharp wcf com

  • Two-way binding problem
    R Ravadre

    Hi, Recently I'm trying to learn WPF, and I've stumbled across a problem, I can solve it, but I'm not happy with the result code, so maybe someone could help me to polish it a bit. Let's say, I have class XManager, that manages classes X, also, it has reference to currently active X instance, each class X has it's own Text property, I want to do a two way binding between textbox and this text property. It looks like this:

    class XManager
    {
    private X activeX;

    public X ActiveX
    {
    get { return activeX; }
    }
    }

    class X : INotifyPropertyChanged
    {
    public string Text { get; set; }

    public void PutSomeTextProgramatically(string someText)
    {
    Text += someText;
    if (PropertyChanged != null)
    PropertyChanged(this, new PropertyChangedEventArgs("Text"));
    }
    }

    Now, I do have a manager accessible from XAML:

    <Windows.Resources>
    <local:XManager x:Key="xManager"/>
    </Windows.Resources>

    My binding to it looks like this:

    <TextBox Name="someBox">
    <TextBox.Text>
    <Binding Mode="TwoWay" Source="{StaticResource xManager}" Path="ActiveX.Text" />
    </TextBox.Text>
    </TextBox>

    Such code won't work properly, because we've binded to XManager's "ActiveX.Text", but we never change it, so workaroun I did was to add do my manager such code:

    //This one is invoked when activeSession signals PropChange
    void XSession_PropertyChanged(object sender, PropertyChangedEventArgs e)
    {
    if (e.PropertyName == "Text")
    {
    if (PropertyChanged != null)
    PropertyChanged(this, new PropertyChangedEventArgs("ActiveSession.Text"));
    }
    }

    Now it will work, but I find such code a bit ugly, I'd like to bind "directly" to PropertyChange event inside XSession, not to some sort of a wrapper. Is this possible, or maybe I don't see something obvious?

    WPF wpf help csharp wcf com

  • How to execute .jar file in c#
    R Ravadre

    If you would read the parameter's name, you would see that it's called fileName, therefore - there is no file name called "java -Xm......". Try Process proc = Process.Start("java", "-Xms60m...."); Also, make you that java exec is in your env path, otherwise supply full path to it.

    C# csharp java tutorial question

  • IT Books - WPF / WCF
    R Ravadre

    Thank you for your recommendations. I think that I've missed 3. WPF position earlier, but I've checked it, and, just like you, maby people find it really useful, so I'll definitively check it out. As for style of reading, I think we have the same style of learning ;). After I get an overall knowledge, enough to start using some technology / language I just code in it, and use books as references, so I can always update my knowledge, when I have some lacks, on the other hand tough, I just like reading, so often I read whole book from 1st page to the last just for fun of it :).

    The Lounge csharp learning dotnet wpf wcf

  • IT Books - WPF / WCF
    R Ravadre

    Hello, Hopefully, soon I'll have more free time than in the past few months, therefore, I've decided it's time to buy myself few books and learn some technologies, that because of lack of a time, I haven't had chance to master (or at least, to learn them enough :) ). This time, it's time for WPF and WCF, therefore I'd like to ask for some assistance in chosing right books. After some googling and reading some reviews on Amazon (also - visiting message boards, but topics that I've found are pretty old, and I believe something could change in this manner) I've figured out that the best choices would be books from: Unleashed series (WPF Unleashed by Adam Nathan - I've heard it's a great book). Pro series (Pro WPF/WCF) Programming WPF/WCF or Essential WPF/WCF. I've always thought that it's worth to buy at least 2 books for each aspect, because I like to read about the same things from different perspectives, it's easier to understand many things that way, but 4 books for WPF, and 4 books for WCF, I guess that's too much, at least for now :). Do you have any opinions on those? As for now, I'm thinking about getting Unleashed WPF, as I've heard it's the best choice for learning and Pro WPF, to have some sort of a reference book always on my desk. And as for WCF books, I don't have any clue which ones would be better. Also, my experience with WPF/WCF is near to 0, opposed to C#, which I'm using since .NET Framework 1.0, and I know it "pretty well". Thanks in advance.

    The Lounge csharp learning dotnet wpf wcf

  • managing multiple socket connections !?
    R Ravadre

    I'm not sure if I understand your question correctly. If you meant that you don't know who has just connected to your server - well, you don't :), You can get his IP, or authentificate him using some sort of your own protocol. But if you would have meant that, then this is general issue, not only related to 2nd method, so maybe you've meant, how to know which client has sent you some data, which invoked your callback method, well, there are 2 ways to keep this information; when you Invoke BeginRead() you can pass your own parameter, you can pass some sort of structure that will tell you what you need to know, fe.: tcpClient.GetStream().BeginRead(buffer, 0, bufferSize, callback, this) then, in callback: TcpClient myClient = (TcpClient)result.AsyncState; The second approach (which I use) is to create some sort of wrapper class that handles everything, a little example (a bit simplified):

    public class Program
    {
    class NetClient
    {
    const int bufferSize = 4096;
    TcpClient client;
    byte[] writeBuffer;
    byte[] readBuffer;

    		public NetClient(TcpClient client)
    		{
    			this.client = client;
    			writeBuffer = new byte\[bufferSize\];
    			readBuffer = new byte\[bufferSize\];
    
    			client.GetStream().BeginRead(readBuffer, 0, bufferSize, OnDataRead, null);
    		}
    
    		void OnDataRead(IAsyncResult result)
    		{
    			int dataRead = client.GetStream().EndRead(result);
    
    			//...
    
    			client.GetStream().BeginRead(readBuffer, 0, bufferSize, OnDataRead, client);
    		}
    	}
    
    
    	public static void Main()
    	{
    		List<NetClient> clients = new List<NetClient>();
    
    		TcpListener server = new TcpListener(11111);
    
    		server.Start();
    
    		while (true)
    		{
    			TcpClient client = server.AcceptTcpClient();
    			Console.WriteLine((client.Client.RemoteEndPoint as IPEndPoint).Address);
    			clients.Add(new NetClient(client));
    		}
    	}
    

    }

    Alternatively, you could make OnDataRead static, and pass NetClient as a parameter, just like in 1st approach.

    C# sysadmin tutorial question

  • managing multiple socket connections !?
    R Ravadre

    rareseu wrote:

    i've checked the web and msdn but most exmpales are either too convoluted or use different mechanics than mine

    Maybe your mechanism isn't right then? :). 1. The simplest way is creating a thread that will call accept in a loop. For each accepted thread you create new client thread, pass new socket there and voila. Drawback is that you will use 1 socket per connection, so managing a lot of sockets could be expensive. (btw, for each client socket, you can use synchronous operations now). 2. A bit more complicated, but more robust solution is to use asynchrounous communication. Then, foreach connected client, you create him a read buffer, write buffer, supply callbacks methods and just invoke BeginRead/Write. Your callbacks methods will be ran automatically when some data will arive (read) or was sent (write). In callback methods, what you should do is call EndRead/Write to get data, do some quick processing (fe. copy received data to some external buffer) and invoke Begin methods once again, and so on, and so on :).

    C# sysadmin tutorial question

  • how 2 create a software
    R Ravadre

    Everybody also should know that: -blocks of 32bits are still 1's and 0's -fact that cpu's architecture is 32bit doesn't mean it has 32-bits blocks inside, most of instructions inside x86 are 2 byte long (not counting params, fe. most move-if commands are 0x0F 0xXX /r, where /r is register param) -That doesn't stop you to program in machine code by yourself :). Create *.COM file and write pure machine (16-bit though) code with any hex editor :).

    C#

  • how 2 create a software
    R Ravadre

    OriginalGriff wrote:

    Now, organise the Ones and Zeros so that they fullfill your Idea. Pass the Idea through the Compiler / linker / doobry so that the Computer can understand them. Run the compiled Idea on the Computer.

    If you have 0's and 1's why use compiler, organise them is such order that the computer understands them :). Intel books with machine instruction codes can be useful!

    C#

  • regular expressions
    R Ravadre

    Lets say you have: int x; % foo % bar x = 5; %x = 5 Your rules: keyword = 'int' ident = Everything that starts with _ or letter and has letters,digits,_ after that comment = Starts with % to newline. Now you write simple lexer that will scan letter by letter, trying to fit what you have to as many possibilities as you can. When no possibilites are left, you go back one letter, and find first one that fits. So, for our example would be:

    buffer: what it can be:
    'i' int or ident
    'in' int or ident
    'int' int or ident
    'int ' nothing. Go back 1 letter
    'int' first rule that fits is keyword int, so it's int
    ' ' fits nothing from beggining, so ignore it
    'x' fits ident
    'x ' fits nothing, go back
    ...

    So generally, you will get lists of tokens, their start and end position, so you just color them :).

    C#

  • regular expressions
    R Ravadre

    Probably it can be done in regular expressions themselves, but if I were you, I'd consider making your highligher a bit more intelligent. Parse your code chunk by chunk, word by word, then once you find a comment, you will just move to next line, when you find a keyword, you will move to next word etc. It can come handy for more complicated cases. Other way is of course parsing the text, which would be probably to complicated for your needs.

    C#

  • Sleep thread
    R Ravadre

    Infinite wait is not the best option in most cases, timeout can be handy. And for your problem, you could use ManualResetEvent. Msdn[^]

    C#

  • Problems when reimplementing c# class to f#
    R Ravadre

    Hello, Recently I've decided to rewrite some of my C# code to F# (pratice, learn, maybe move and optimize some code for future). Unfortunately I've faced few problems. Let's say I have a c# class that looks like this:

    public class MersenneTwister : Random
    {
    private const int N = 624;
    private uint[] mt = null;

    public MersenneTwister(uint seed)
    {
        mt = new uint\[N\]
        mt\[0\] = seed & 0xffffffffU;
        for (int mti = 1; mti < N; ++mti)
        {
             mt\[mti\] = (69069 \* mt\[mti - 1\]) & 0xffffffffU;
        }
    }
    

    }

    I have no idea how to create constants like N - I could write static let N = 24 but: - After compilation, c#'s version does replace N with number, as consts should work, f# does not (it uses static field to represent N) - I can't use static let if I don't have implicit constructor for type, and I can't have one, because my constructor has to implement some code. I have to create mt array as mutable, but I can't use let (no implicit constructor), if I use member x.mt : uint32 array = Array.create N 0u instead, new array will be created each time I use mt property. I will be grateful for any ideas. I also must add that, I can't believe so many people say f# is much more expressive and easier then c#, I'm trying to learn it, but for now, each time I want to do something my way, I have to search informations in books and/or google a lot :(.

    .NET (Core and Framework)

  • COM interface inheritance
    R Ravadre

    Hi, I am fighting with COM again :), ow I'm struggling with following problem: Let's say we have COM interfaces defined as:

    IA : IUnknown
    IB : IA
    IC : IB

    What I've tried to do is creating C# interfaces:

    [ComImport, System.Security.SuppressUnmanagedCodeSecurity,
    Guid("00-this-is-valid-guid-000"),
    InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    interface IA
    {
    method1();
    }

    The same for IB, with following difference: interface IB : IA IB does not duplicate IA's methods. The same for IC. Now, when I try to create instance of IC using other COM method (from another interface) I receive error (Exception from HRESULT: 0x88990012 to be exact - but I guess that wont be helpful). When I copy-paste method1() from IA to IB, and remove inheritance, but leave inheritance between IB and IC the code seems to work. What is even more surprising, I have pretty the same situation with other "inheritance tree" (IA -> IE -> IF) and I don't have problems with them, what is even funnier, when i completely remove IA, interfaces IE and IF are working properly. Does anyone have an idea what is exactly going on, or have any references that could help me solve that one? (I've read tons about marshalling and COM on msdn, but I haven't found answer for this one). To be exact: All methods from interfaces are defined in correct order (the same order as in *.h file), but some methods has invalid argument (no arguments, even though they should take some, this seems to not break anything, as long as those methods are not invoked of course, and make developing easier (I start with blank ones, and fill the ones I need).

    C# help question csharp com data-structures

  • "Invalid Assembly file" error while registering file to Global Assembly Cache ????
    R Ravadre

    Is it signed? Assemblies in GAC must be signed with key (hash), so they are unique (name + version + hash).

    .NET (Core and Framework) question database sqlite help

  • Cryptography
    R Ravadre

    1. Rijndael algorithm is already implemented in C# Stdlib. 2. The whole purpose of having key is to NOT writing it down. For example you can generate it from password. Lets say you have a password "foobar". To encrypt data you get hashcode from you password and you use it as key, then to decrypt the data, you will just get hash from password again. So, what's the point of keeping key?

    C# graphics security question

  • Crypto-arithmetic problem
    R Ravadre

    We have few troll slayers on CodeProject so I wouldn't panic ;-).

    C# help cryptography
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups