|
You had the answer, because you knew the right question to ask.
I asked the question, but I asked the wrong question.
Or, more probably, asked the right question in the wrong manner.
|
|
|
|
|
If you're into free IDEs then SharpDevelop (clicky[^]) is worth a look, it will read VS project files and it's pretty full featured.
|
|
|
|
|
Thanks, will examine it.
This is an interface to an external box on my desk.
We have a useful interface already. We send a command and the box responds; and we see the response on our screen; exactly as the spec told the guy to do a year or two ago; and he did his job quite well.
We now want to add our own smarts into this arrangement, and write an interface that lets us give the box a command, and then read the response; and make a decision on what to do as a result.
e.g., something like...
SendTheCommand("X Y Z")
Response = ReadTheResponse()
if (Response == 1)
{
DoTheFirstThing()
}
if (Response == 2)
{
DoTheSecondThing()
}
I think this is going to have to be C# by fiat more than logistics.
Anyway, I will certainly spend a few minutes looking at your open source suggestion.
|
|
|
|
|
I may not have been clear there, #Dev is an IDE for writing .Net (i.e. C#) programs.
|
|
|
|
|
How does it compare with VS Express?
|
|
|
|
|
I've never actually used VS Express because the only time I tried (back in the day) it wouldn't run on my low spec machine at the time. At work my employer pays for VS Pro. However I think a lot of the more useful features of VS (unit test execution, object model inspection, following references into libraries, probably the refactoring stuff) isn't in Express. And #Dev is still far kinder on memory and resources so it will generally run significantly faster.
|
|
|
|
|
|
Hi all
I have been searching and have found very little on this subject.
I am trying to connect simply to a webservice, call a method and get a response.
The service requires a nonce for authentication, but i can not ofr the life of me figure out how to generate one and pass it correctly.
I am call the webservice from a c# script using webClient.
I can add basic network credentials, of username and password.
But how do i add the full header correctly with a generated nonce.
The authentication part of the header looks like this.
<pre lang="xml"> <SOAP-ENV:Header>
<wsse:Security mustUnderstand="true">
<wsse:UsernameToken>
<wsse:Username>admin</wsse:Username>
<wsse:Password
Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">bG4Gz8elJibVIABSaX5nB7uTSBM=</wsse:Password>
<wsse:Nonce
EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">+MnwDfmScWNR2j5MBV+Ikg==</wsse:Nonce>
<wsu:Created>2014-03-06T12:37:36.174525Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</SOAP-ENV:Header>
</pre>
I am new to using webservices so for give my ignorance.
|
|
|
|
|
If you're using WCF, I would advise reading the answers detailed here[^].
|
|
|
|
|
Hi fellow members
I'm working on a personal C# project , in which i estimate the budget - assets , account receivables , debts ... etc. The main requirement is that the code should not interact with a server side database , instead it can interact with a client MS access database.
It has a snowflake schema . Need your help in understanding how we can setup a MS access database and use it in C# code.
If any such code is available ,please send the link.
Appreciate your help
Thanks
Praneeth
Bob.
|
|
|
|
|
bobba praneeth wrote: If any such code is available ,please send the link.
You really just need to google "c# ms access database tutorial", this returns in excess of 23,000,000 results. At least one of these is going to get you started.
Unless you are tied to Access for some reason, you could swap to SQL express, this will allow you to use Entity Framework which takes a lot of the effort out of pushing information in/out of objects.
|
|
|
|
|
Here is an article I wrote on database connection[^], but if you can help it avoid Access databases. They are a pain in the ass. Both Oracle and SQL-Server have free versions out there and MySQL and PostgreSQL are also very good alternatives (both free as well)
If you're developing pure .Net I'd go for SQL-Server Express.
PS: My article is one way of doing things, there are other ways as well.
hope this helps.
|
|
|
|
|
The wording 'set up an Access database' implies you don't have it yet and therefore have a free choice of tech. In which case: don't use access. Even a System.Data.DataSet serialised to disk is probably better than that. Really you should set yourself up a proper ODBC data source (e.g. SQL Server, mySQL etc) and use System.Data to interact with it.
|
|
|
|
|
Just to back up what the others say: if you are using this for multi-user at all - i.e. if at any time there will be more than one user using the database in any way, then Access is a poor solution, and will give you nasty problems. You do need to use a "proper" multiuser system, and that means SQL Server or MySql.
If you only ever need it for a single user, then Access will work, but I'd still be tempted to use SQLCE or SQLite instead - and I have Access on my system!
If you must use Access, then you need to install the appropriate ACE driver: 32 bit or 64 bit (you can't install them both on the same machine), and use OleDbConnection and OleDBCommand objects to access them: Google can help with that.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Many times in C/C++ I have used arrays of structs into struct and it was very nice and useful to aggregate data sets. Now with C# My question is, can I make the same using class ? I know, there are struct also in C#, but they are allocated into stack and I don't want use to much stack area, and I have two method to serialize and deserialize not static objects classes and I don't know if and how struct are serializable.
Here is my code:
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
namespace My_Space
{
[Serializable()]
public class Parameters
{
public int autoLockTime;
public int screenOffTime;
public int loopAutoStartTime;
public class product
{
public bool enabled;
public string productName;
public double zero;
public double span;
public string unit;
public class preProcessing
{
public string preProcessingName;
public double[] param = new double[5];
}
}
public void InitParameters()
{
autoLockTime = 0;
screenOffTime = 0;
loopAutoStartTime = 0;
product[] p = new product[30];
p[0].enabled = false;
p[0].unit = "mm";
p[0].productName = "H2O";
product.preProcessing[] pp = new product.preProcessing[10];
pp[0].preProcessingName = "Derivative";
pp[0].param[0] = 100.0f;
pp[0].param[1] = 200.0f;
}
public void SaveParameters(Parameters obj)
{
Stream stream = File.Open("Parameters.bin", FileMode.Create);
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(stream, obj);
stream.Close();
}
public void ReadParameters(out Parameters obj)
{
Stream stream = File.Open("Parameters.bin", FileMode.Open);
BinaryFormatter formatter = new BinaryFormatter();
obj = (Parameters)formatter.Deserialize(stream);
stream.Close();
}
}
}
I can also write in other classes:
private Parameters q = new Parameters q();
private Parameters.product[] p = new Parameters.product[30];
private Parameters.product.preProcessing[] pr = new Parameters.product.preProcessing[10];
public Form()
{
q.ReadParameters(out q);
p[0].productName = "aaa";
pr[0].preProcessingName = "bbb";
}
but I cannot link the preProcessing object to the product object and I cannot serialize array of classes as p or pr.
Maybe using static class ... ?
How can I serialize/deserialize structs ?
What is the best solution ?
Thanks
modified 24-Mar-14 12:21pm.
|
|
|
|
|
The problem here is that you have only marked one of your classes as Serializable . You need to mark all of the classes that can be serialized like this.
|
|
|
|
|
This code seems to work:
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
namespace Base_NIR
{
[Serializable()]
public class Parameters
{
public int autoLockTime;
public int screenOffTime;
public int loopAutoStartTime;
public class product
{
public bool enabled;
public string productName;
public double zero;
public double span;
public string unit;
public preProcessing[] preProc = new preProcessing[10];
}
public class preProcessing
{
public string preProcessingName;
public double[] param = new double[5];
}
[NonSerialized()]
public static string member5 = "hello world!";
public void InitParameters()
{
autoLockTime = 0;
screenOffTime = 0;
loopAutoStartTime = 0;
preProcessing[] pr = new preProcessing[10];
pr[0].preProcessingName = "bbb";
product[] p = new product[30];
p[0].preProc[1].preProcessingName = "aaa";
p[0].enabled = false;
p[0].unit = "mm";
p[0].productName = "H2O";
p[0].preProc[3].param[5] = 123.45f;
p[0].preProc[2].preProcessingName = "Derivative";
}
public void SaveParameters(Parameters obj)
{
Stream stream = File.Open("Parameters.bin", FileMode.Create);
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(stream, obj);
stream.Close();
}
public void ReadParameters(out Parameters obj)
{
Stream stream = File.Open("Parameters.bin", FileMode.Open);
BinaryFormatter formatter = new BinaryFormatter();
obj = (Parameters)formatter.Deserialize(stream);
stream.Close();
}
}
}
And I can also write:
private Parameters.product[] p = new Parameters.product[30];
private Parameters pr = new Parameters();
public MainForm()
{
pr.InitParameters();
pr.ReadParameters(out pr);
p[0].preProc[2].preProcessingName = "xxx";
pr.SaveParameters(pr);
pr.ReadParameters(out pr);
}
But everytime I write in a field I have the error of nullReference exception.
|
|
|
|
|
You're facing another issue here, and it's a common misunderstanding. The issue is down to the fact that newing up arrays doesn't actually add class instances, you have to explicitly add them yourself. So, after you have allocated your array, you need to add a new instance of the class against each item in the array.
|
|
|
|
|
Sorry Pete, to be clear, please can you write 5 lines of code of example to better explain ?
|
|
|
|
|
This should give you an idea. The line in bold is the one I added.
preProcessing[] pr = new preProcessing[10];
pr[0] = new preProcessing();
pr[0].preProcessingName = "bbb";
|
|
|
|
|
OK thanks Pete. Sorry, it wasn't so easy to use that objects for me but now it's working fine. Do you have some other idea on how it would be better to implement them. What do you thinks about to use these classes with Lists ?
|
|
|
|
|
There's two problems here which I think come from the same misunderstanding.
In C, the code
struct A {
int someField;
struct B {
long somethingElse; }
} B;
}
... defines an object tree. That is, I can say
A a;
a.B.somethingElse = 12L;
In C#, you have not written the equivalent. Nested classes (and structs) define only the class, they do not define a field that goes with it. The fact that they're nested only affect name resolution and visibility. You need to also provide a field or property that is linked to an instance or array of the inner class.
That means I think you want:
public class product
{
public bool enabled;
public string productName;
public double zero;
public double span;
public string unit;
public preProcessing[] pp;
public class preProcessing
{
public string preProcessingName;
public double[] param = new double[5];
}
}
(Set aside for the moment questions of array vs list and public fields.) That means you can say
var p = new product();
p.pp = new product.preProcessing[10];
p.pp[0] = new product.preProcessing();
p.pp[0].param[3] = 12.8;
You've made the same mistake at the top level: Parameters should have a field of type product[].
When you do that you'll see the second mistake, because your code will stop compiling due to inconsistent [Serializable] attributes. You need to put [Serializable] on all the inner classes that are part of your data tree, too.
|
|
|
|
|
Thanks Bob you were, as usual, clear and helpful. Now the work is running in the right way!
|
|
|
|
|
Sorry, my application doesn't serialize/deserialize. How can I save all my classes together in the same file ? With only one simple class (Parameters) it was correct, now with more classes I don't know how to fix the code. The code to test the serailize and deserialize method now is:
private Parameters param = new Parameters();
private Parameters.product[] p = new Parameters.product[30];
private Parameters.preProcessing[] pp = new Parameters.preProcessing[10];
public MainForm()
{
param.InitParameters();
p[0] = new Parameters.product();
p[0].productName = "H2O";
p[0].preProcessId[0] = 0;
p[0].preProcessId[1] = 1;
param.SaveParameters(p[0]);
param.ReadParameters(out p);
pp[0] = new Parameters.preProcessing();
pp[0].preProcessId = 0;
pp[0].preProcessingName = "Derivative";
pp[0].preProcessingParms[0] = 10.0;
pp[0].preProcessingParms[1] = 20.0;
}
and the file with the classes to save and the serialize/deserialize methods is:
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
namespace My_Test_Space
{
[Serializable()]
public class Parameters
{
public int autoLockTime;
public int screenOffTime;
public int loopAutoStartTime;
[Serializable()]
public class product
{
public bool enabled;
public string productName;
public double zero;
public double span;
public string unit;
public int[] preProcessId = new int[10];
}
[Serializable()]
public class preProcessing
{
public int preProcessId;
public string preProcessingName;
public double[] preProcessingParms = new double[5];
}
public void InitParameters()
{
autoLockTime = 0;
screenOffTime = 0;
loopAutoStartTime = 0;
preProcessing[] pp = new preProcessing[10];
for (int i = 0; i < 9; i++)
{
pp[i] = new preProcessing();
pp[i].preProcessId = i;
pp[i].preProcessingName = "";
for (int j = 0; j < 5; j++) pp[i].preProcessingParms[j] = 0.0;
}
product[] p = new product[30];
for (int i = 0; i < 30; i++)
{
p[i] = new product();
p[i].enabled = false;
p[i].unit = "mm";
p[i].productName = "H2O";
p[i].zero = 0.0;
p[i].span = 0.0;
for (int j = 0; j < 10; j++)
{
p[i].preProcessId[j] = 0;
}
}
}
public void SaveParameters(Parameters obj)
{
Stream stream = File.Open("Parameters.bin", FileMode.Create);
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(stream, obj);
stream.Close();
}
public void ReadParameters(out Parameters obj)
{
Stream stream = File.Open("Parameters.bin", FileMode.Open);
BinaryFormatter formatter = new BinaryFormatter();
obj = (Parameters)formatter.Deserialize(stream);
stream.Close();
}
}
}
|
|
|
|
|
You still haven't quite got the concept that an instance of Parameters should contain all references to instances of the subclasses. You're storing references to the inner classes in MainForm – that means they're not in the same object tree and really aren't related to the object 'param' you create.
Your MainForm initialisation should just be
private Parameters param = new Parameters();
Parameters.InitParameters should build the instances of products and products.preProcessing – not as local variables it is now. You're currently building arrays in that function that are never assigned to anything and go out of scope immediately.
public void InitParameters()
{
autoLockTime = 0;
screenOffTime = 0;
loopAutoStartTime = 0;
this.pp = new preProcessing[10];
for (int i = 0; i < 9; i++)
{
pp[i] = new preProcessing();
pp[i].preProcessId = i;
pp[i].preProcessingName = "";
for (int j = 0; j < 5; j++) pp[i].preProcessingParms[j] = 0.0;
}
this.p = new product[30];
for (int i = 0; i < 30; i++)
{
p[i] = new product();
p[i].enabled = false;
p[i].unit = "mm";
p[i].productName = "H2O";
p[i].zero = 0.0;
p[i].span = 0.0;
for (int j = 0; j < 10; j++)
{
p[i].preProcessId[j] = 0;
}
}
}
You'll have to add the declarations for p and pp to the Parameters class as I explained in my previous post to make those assignments work.
Now, all you have to do is serialise an instance of Parameters (i.e. MainForm.param), and it will serialise the whole object tree.
|
|
|
|