|
Please look into the Bayeux Protocol[^]. It was based on the idea of inverting the usual client request / server response paradigm. Of course the client still has to connect to the server and keep that connection open, but after that the server can push notifications/data to the client.
I'm not sure if there are any client side APIs that would let you use this in a WinForm application, but you could circumvent this by using a webbrowser control inside your WinForm application.
Best Regards,
—MRB
"With sufficient thrust, pigs fly just fine."
Ross Callon, The Twelve Networking Truths, RFC1925modified on Monday, August 22, 2011 10:58 AM
|
|
|
|
|
|
Thanks Keith. It looks as if deep linking isn't allowed. I pasted in the link from the google page and now it works.
Cheers!
"With sufficient thrust, pigs fly just fine."
Ross Callon, The Twelve Networking Truths, RFC1925
|
|
|
|
|
Don't have the attention span to post as article - but thought this might be interesting:
Automatic properties are great but the annoyance of not being able to set them automatically defers a lot of people from using them.
What we (read - I) want to be able to do something like this:
double MyPie { get; set; } = "3.141";
string MyLove { get; set; } = "Pizza";
The default value attribute in System.ComponentModel is of no help there, though a lot of us (read - me) tried that in the beginning:
[DefaultValue(0.3141)]
double MyPie { get; set; }
[DefaultValue("Pizza")]
string MyLove { get; set; }
Initializing the properties one by one in the constructor is at least as annoying as simply doing this:
double _myPie = 0.3141;
double MyPie { get { return _myPie; } set { _myPie = value; } }
double _myLove = "Pizza";
double MyLove { get { return _myLove; } set { _myLove = value; } }
Luckily the nice little feature of extension methods allows us something not exactly optimal or fully elegant - but functional and a good exercise in C# clockwork.
So with just a bit of hammering we can enable automatic reset properties to their declared System.ComponentModel.DefaultValueAttribute if any was specified.
Test code:
using System;
using System.ComponentModel;
using System.Text;
using System.Windows.Forms;
using CSharpUtils;
namespace MyAppNamespace
{
public class TestClass
{
[DefaultValue(0.3141)]
public double MyPie { get; set; }
[DefaultValue("Pizza")]
public string MyLove { get; set; }
public TestClass()
{
MessageBox.Show(string.Format("MyPie = {0}, MyLove = {1}", MyPie, MyLove == null ? "null" : MyLove));
int ret = (this as Object).ResetPropsUsingDefaultAttributes(false);
MessageBox.Show(string.Format("MyPie = {0}, MyLove = {1}. {2} properties we set", MyPie, MyLove == null ? "null" : MyLove, ret));
MyLove = "My dear wife";
MessageBox.Show(string.Format("MyPie = {0}, MyLove = {1}", MyPie, MyLove == null ? "null" : MyLove));
ret = (this as Object).ResetPropsUsingDefaultAttributes(false);
MessageBox.Show(string.Format("MyPie = {0}, MyLove = {1}. {2} properties we set", MyPie, MyLove == null ? "null" : MyLove, ret));
}
}
}
This (as you may have already guessed) is done using an extension method to the System.
You will need a public static class to define the extension method in. here's the basic implementation source (feel free to use the code and extend it's functionality):
using System;
using System.Text;
using System.Reflection;
using System.ComponentModel;
namespace CSharpUtils
{
static class CSharpUtilsExtensionMethods
{
public static int ResetPropsUsingDefaultAttributes(this Object oThis, bool initInheritedProperties)
{
int count = 0;
Type oType = oThis.GetType();
PropertyInfo[] infos = oType.GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
foreach (PropertyInfo inf in infos)
{
if (initInheritedProperties || inf.DeclaringType.Equals(oType))
{
object[] oDefAtts = inf.GetCustomAttributes(typeof(DefaultValueAttribute), initInheritedProperties);
if (oDefAtts.Length > 0)
{
DefaultValueAttribute defAtt = oDefAtts[oDefAtts.Length - 1] as DefaultValueAttribute;
if (defAtt != null && defAtt.Value != null && !defAtt.Value.Equals(inf.GetValue(oThis, BindingFlags.GetProperty, null, null, null)))
{
inf.SetValue(oThis, defAtt.Value, BindingFlags.SetProperty, null, null, null);
count++;
}
}
}
}
return count;
}
}
}
All that's left now is use out test class (here again - with no message box and other nonsense
using System;
using System.ComponentModel;
using System.Text;
using System.Windows.Forms;
using CSharpUtils;
namespace MyAppNamespace
{
public class TestClass
{
[DefaultValue(0.3141)]
public double MyPie { get; set; }
[DefaultValue("Pizza")]
public string MyLove { get; set; }
public void ResetProps()
{
(this as Object).ResetPropsUsingDefaultAttributes(false);
}
public TestClass()
{
ResetProps();
}
}
}
Notes:
- To use the extension method - the .cs file making the call must have a 'using' declaration of namespace where the extension method resides in.
- Passing true for parameter initInheritedProperties also initializes any parent class properties - at the expense of possibly resetting already initialized properties. you can always extend the extension method to try and account for these cases.
- Resetting the properties in this manner works also outside constructor - anywhere in the program with the proper access.
- There's still the annoyance of having to add a line in the constructor - but it is just one line and will no require additional modifications if properties are added, removed or their type/default value is changed.
There you go,
have fun
Yours,
<><<br mode="hold" />Itai
|
|
|
|
|
Itai Basel wrote: Don't have the attention span to post as article
Then post it as a Tip/Trick[^]
where do these people come from?
[edit]
I see from the profile - a lurker for 8 years with never a message, impressive. Must have been a bitch trying to find your old password
Do use the tip/trick area as it is specifically designed for those with limited attention spans and good ideas. They do get vetted and need to be released by a gold member but this one would have no problem at all. Keep it up!
[/edit]
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thanks.
I always plan to post cool stuffs but never do due to having to go through all that publishing a web-page for it.. Never been much of a writer and am not a native English speaker so I always find out afterward that I written something funny too.
I'll go look where the tips&tricks area is.
Yours,
<><<br mode="hold" />Itai
|
|
|
|
|
And about remembering the password - no worries - since I need it to download sources.
Anyway - I posted as top/trick. now I need to change the awkward signature since it's got html symbols in it and looks weird after it's posted
Yours,
<><<br mode="hold" />Itai
|
|
|
|
|
I'm just glad you weren't discouraged by a grumpy old bugger on a Sunday morning!
There is a definite warm, fuzzy feeling when you see your contribution put to use by others, it's the main reason why this site works I think, people actually do want to help.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I second it as a tip/trick, or at least as a blog entry.
|
|
|
|
|
Agree with others. Based on length better post it as a blog post. If possible attach download for the source code.
Off Topic:
I found broken text in your signature.
thatraja
My Tip/Tricks My Dad had a Heart Attack on this day so don't...
All these are my opinions. Different people. different way of thinking. I am no one to judge others - Chandru
|
|
|
|
|
hi all
I have uploaded a picture into table but i am stuck, that how may I show the picture in Crystal Reports from table.
I used following codes to upload the picture it works fine
fileStream = new System.IO.FileStream(strFile, System.IO.FileMode.Open, System.IO.FileAccess.Read);
reader = new System.IO.BinaryReader(fileStream);
data = reader.ReadBytes((int)fileStream.Length);
cmd = new OleDbCommand();
cmd.Connection = Module.objConnection;
string strQuery =
"SELECT * FROM PICTURES WHERE " +
"STCODE="+ textBox1.Text +" AND " +
"STSEQ="+ dataGridView1["STSEQ",dataGridView1.CurrentCell.RowIndex].Value.ToString() +" ";
cmd.CommandText = strQuery;
dr = cmd.ExecuteReader();
if (dr.HasRows == false)
{
dr.Close();
cmd.CommandText = "INSERT INTO PICTURES (STCODE,STRNO,STSEQ,FILENAME,FILESIZE,FILETYPE) " +
"VALUES(" + textBox1.Text + ", " +
"" + dataGridView1["STRNO", dataGridView1.CurrentCell.RowIndex].Value.ToString() + ", " +
"" + dataGridView1["STSEQ", dataGridView1.CurrentCell.RowIndex].Value.ToString() + ", " +
"'" + fileName + "'," + data.Length + ",'" + type + "') ";
cmd.ExecuteNonQuery();
(Riaz)
|
|
|
|
|
|
I need to decode CSR message (pkcs#10) to solve different kind of broblems in it.
The following piece of code works fine, but unfortunately only in vista and windows7, which uses Certenroll.lib. My code will be used also in XP, why I have included Xenroll.lib into my code as well. But what is the respective piece of code using xenroll to decode pkcs#10 request?
if (Environment.OSVersion.Version.Major >= 6)
{
CX509CertificateRequestPkcs10 request = new CX509CertificateRequestPkcs10();
request.InitializeDecode(txtP10.Text, EncodingType.XCN_CRYPT_STRING_BASE64_ANY); request.CheckSignature(Pkcs10AllowedSignatureTypes.AllowedKeySignature);
lblSubject.Text = "Subject:" + (((CX500DistinguishedName)request.Subject).Name);
lblKeyLenght.Text = "Key length:" + (request.PublicKey.Length);
lblAlgorithm.Text = "Algorithm:" + (request.HashAlgorithm.FriendlyName);
}
else
{
}
Thanks for any help!
modified on Wednesday, August 24, 2011 1:44 PM
|
|
|
|
|
Hello I have the "following" code:
controller = Controller.BuildSingleRow(_sheet);
_animator = Animator
.WithStartupInfo(_controller, PlayMode.Normal, 1f);
I have used a static method in the Controller class to setup some method of build pattern, I was going to use a constructor but a static instantiation won it for me.
Is this bad to do this?
Thanks
|
|
|
|
|
Seems OK, depends on the usage.
|
|
|
|
|
Read up on static constructors [^]
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I read through it and I can see how that would be useful however "perform a particular action that needs performed once only", I intended those methods to be used more than once and to increase the usability of the code.
So when people see:
Controller.BuildSingleRow(_sheet);
They realise that it constructs the object set to a single row sprite sheet...
It seems ok to me but im sure there is someone out there who would slap me in the face...
|
|
|
|
|
It seems related to the Abstract Factory and Factory Method Design Patterns, but not as complex.
|
|
|
|
|
It is not bad if there is a good reason why the 'constructor' shouldn't actually be a constructor in language terms. For example, if Controller is a pseudo-factory class that can actually build several different final classes in these methods, or the build methods need differentiation by name for clarity.
If this is the only 'BuildXxx' method and it returns an instance of Controller, it should be a constructor (and the class should probably be named with the 'single row' aspect) – after all, that's what a constructor is, a static method that returns a new instance of the class, and people expect to instantiate classes that way.
One small point to bear in mind is that any sort of reflection-based instantiation is not likely to find your static method. You may well not be doing any of that though.
|
|
|
|
|
hi
This is kind of desparate - Is it possible to call Excel XLA function from .NET via Microsoft.Office.Interop?
Many thanks!
dev
|
|
|
|
|
I am creating a window application that need to use sql server database. I want to install this application to client machine without installing sql server or sql express so that my application can still connect to a database on server that i will be providing at client system.
How can i connect to a database(mdf) on client machine through my window application without installing sql server. ? I dont know is it possible or not.
is this software sifficient :
ADONETDataServices_v15_CTP1.exe
|
|
|
|
|
Edit it your message and take the text out of the code block, it doesn't look good.
|
|
|
|
|
Just develop the application as normal, and use the System.Data namepsace which include SQL client classes for working with an existing SQL database. Then all you need to ensure is the relevant version of the .Net framework is installed on the client machine you are installing the application on.
Going by the question, I would take it you are new to all this, and will have some interesting challenges ahead.
Search the articles on CodeProject for SQL and C#.
|
|
|
|
|
As Dave has already answered, develop your application as if it was intended for a local instance of SQL Server, but put your connection string into a app.config file to make it easier to change later. You can test most of the functionality on a local copy of SQL Server Express, then change the connection string before you install it on a client to point to the SQL Server instance located on the network server.
For lack of time, I haven't yet completed the app I've been working on to accomplish much the same. But I have managed to get some major bits working. I've got some code around here that allows the user to browse for SQL Server instances on the network, select one and connect to it. I've also got some unfinished, but mostly working stuff to check for the existence of the target database on the selected server, or create the database if it doesn't yet exist. The pieces all work great, but I haven't got around to integrating them all together into a completed application. It has been extremely challenging, but everything needed is available either here at CodeProject, or on MSDN (via Google). Get started on a client-only version, and when you have it working, post again about this remote connection aspect. Maybe I'll be done with it and be able to send you specifics...
Good luck, learn lots, and have fun!
Will Rogers never met me.
|
|
|
|
|
hello everyone,
I must make an application to send commands from one company to another B transmission. I really do not know where to start so thank you for help.
|
|
|
|
|