|
|
|
If you are a beginner, then ANY introductory book would be fine, as long as it is a physical book, as opposed to an e-book. IMO you need the opportunity to mark things, to easily browse it, etc.
Most books do not strictly require prior knowledge, as their author/publisher want to sell to as many people as possible. OTOH most books make implicit assumptions; most likely a book on a specific language will not explain the purpose of a loop, nor the principles and best practices in object-orientation. So you might end up needing a few books if you're a newbie, say:
1. introduction to programming
2. introduction to a programming language
3. introduction to Windows programming
4. introduction to object-orientation
However I would still go for #2 first. And then take it from there.
I seldom give specific book recommendations as it is all very subjective, it depends on your prior knowledge, your need for examples and exercises, and much more. My advice is: visit a good bookstore. A lesser alternative is browse a number of books on Amazon's web site.
|
|
|
|
|
Hi again, sorry if I should not have started a new thread, but I have found the c++ code for what I wanted.
1) This is c++, I do not know how I would do it in c#
2) This function only decodes a string of digits into the byte arra, so I still dont know how to encode a byte array ito the string (reverse)
So... This function takes an installation ID (or what will be a serial number) and decodes it into its byte representation of the number.
int DecodeInstID(char *InstID, unsigned char *Result, int ResLen)
{
int i, k, m, Groups;
int Sum, Digit, Aux;
if (strlen(InstID) != 58)
fprintf(stderr, "Warning: Installation ID has non-standard length.\n");
if (strlen(InstID) % 7 < 2)
{
fprintf(stderr, "Installation ID has invalid length.\n");
return -1;
}
memset(Result, 0, ResLen);
Groups = (strlen(InstID) + 6) / 7;
for (i = 0; i < Groups * 7; i += 7)
{
Sum = 0;
for (k = 0; k < 5 && InstID[i + k + 1] != 0; k++)
{
Digit = InstID[i + k] - '0';
if (Digit < 0 || Digit > 9)
{
fprintf(stderr, "Invalid digit in group '");
for (k = 0; k < 6 && InstID[i + k] != 0; k++)
fprintf(stderr, "%c", InstID[i + k]);
fprintf(stderr, "'.\n");
return -1;
}
Aux = Digit;
m = 0;
do
{
Aux += Result[m] * 10;
Result[m++] = (unsigned char)(Aux & 255);
Aux >>= 8;
}
while (m < ResLen);
if ((k & 1) != 0)
Digit *= 2;
Sum += Digit;
}
Digit = InstID[i + k++] - '0';
if (Digit != Sum % 7)
{
fprintf(stderr, "Invalid check digit in group '");
for (k = 0; k < 6 && InstID[i + k] != 0; k++)
fprintf(stderr, "%c", InstID[i + k]);
fprintf(stderr, "'.\n");
return -1;
}
if (InstID[i + k] != '-' && InstID[i + k] != 0)
{
fprintf(stderr, "Expected '-' character after group '");
for (k = 0; k < 6 && InstID[i + k] != 0; k++)
fprintf(stderr, "%c", InstID[i + k]);
fprintf(stderr, "'.\n");
return -1;
}
}
return 0;
}
I know its in c++, but maybe someone can at least figure out what is going on and then maybe this time understand what I want.
So, if you pass ain installation ID string into this function, like the following
("23334 324234 324234 234234 etc")
You get the byte array of the multi precision value for it.
Now, I have my original 2 qustions....
1) How would I do this in c#
2) How would I code a reverse function to ENCODE a byte array (that the above creates) back into a string, like above.
Then I would be able to encode a byte array into a readable long string of digits to give to the user, and,
then DECODE the string (like above) into a byte array
Hopefully you may now understand what I am trying to do, and I cannot start to explain how much I want to do this as I found c# code before and cannot find it now.
Thank you loads in advance, I do appreciate any help.
Steve
|
|
|
|
|
I think you will find the same code will work, almost in C#. Your code is using char arrays, not byte arrays (In c I think there is no difference) however, in C# you have the option of:
string abc;
abc.ToCharArray();
or if you insist on bytes:
string abc;
System.Text.ASCIIEncoding ae = new System.Text.ASCIIEncoding();
ae.GetBytes(abc);
<pre>
<div class="signature"><font size="-2">
Need <a href="http://www.erlglobal.com">custom software developed</a>? I do <a href="http://www.erlglobal.com">custom programming</a> based primarily on MS tools with an emphasis on <a href="http://www.erlglobal.com">C# development and consulting</a>. I also do <a href="http://www.erlglobal.com">Android Programming</a> as I find it a refreshing break from the MS.
"And they, since they Were not the one dead, turned to their affairs" -- Robert Frost
</font></div>
|
|
|
|
|
Thank you.
So do you mean I leave the rest of the code as it is?
And also, Would you possibly be able to point me in the right direction with a function to ENCODE the byte or char array I get from the above, back inot the original string please?
Thank you
Steve
|
|
|
|
|
Message Closed
modified 23-Nov-14 5:57am.
|
|
|
|
|
Dear Qwertz
Thank you, but, the follwoing....
const string INST_ID = "23334 324234 324234 234234";
byte[] instIdInByteArray = Encoding.ASCII.GetBytes(INST_ID);
string instIdInString = Encoding.ASCII.GetString(instIdInByteArray);
That simply returns each byte for each char in the string, so I end up with a larger string.
I want the actual encoding of the digits in the string, into a byte array that is a decimal encoding in litle endian byte order of the digits.
Thank you
Steve
|
|
|
|
|
I know this is off topic, but am I missing something here?
This piece of code caught my eye:
if (strlen(InstID) != 58)
fprintf(stderr, "Warning: Installation ID has non-standard length.\n");
if (strlen(InstID) % 7 < 2)
{
fprintf(stderr, "Installation ID has invalid length.\n");
return -1;
}
My C++ is a bit rusty but why do that? Surely, the second if statement will always be true if the first one is false.
|
|
|
|
|
How so?
strlen(InstID) =
7m + {0, 1}: First is true (not 58), second is true (0 or 1).
58: First is false (not 58), second is false (2).
7m + {2, 3, 4, 5, 6}: First is true (anything but 58), second is false (2, 3, 4, 5, 6).
So basically, the length can only be of the form 58, but maybe 7m + {2, 3, 4, 5, 6} are acceptable.
Still have no idea how this makes sense though.
|
|
|
|
|
Yes, you are right. I was having a brain-fart.
|
|
|
|
|
I'm trying to learn how to communicate between applications and evaluation of the various projects i've come across have helped, but i still have one area i'm not having luck with. Lets say i have a tcpclient connected and it sends a message to server, servers listener accepts it adds the client object to a list and can respond to requests from the client. The connection stays active and my client gui app can press button repeating the process.
Now on sever side gui app lets say i want to initiate a message to the client. I try to utilize the same client object and send some data, but client does not get the message until the connection ends, ie a disconnect.
Anyone have any code examples or links to some that would demonstrate this process?
|
|
|
|
|
Message Closed
modified 23-Nov-14 5:57am.
|
|
|
|
|
Thanks I seem to have gotten that one to work the way i want!
|
|
|
|
|
Good morning folks!
I'm trying to get a Session and redirect the user to another page, but it doesn' work.
If the user doesn't have permission then redirect to root: Default.aspx.
<br />
private UserStats userStats;<br />
<br />
protected void Session_Start(object sender, EventArgs e)<br />
{<br />
if ((UserStats)Session["UserStats"] != null)<br />
{<br />
userStats = (UserStats)Session["UserStats"];<br />
}<br />
}<br />
<br />
protected string PageBasePath<br />
{<br />
get<br />
{<br />
string basePathString = string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Request.ApplicationPath);<br />
if (!basePathString.EndsWith("/")) basePathString = basePathString + "/";<br />
return basePathString;<br />
}<br />
}<br />
<br />
protected bool Compare(String x, String y)<br />
{<br />
Regex rg = new Regex(y);<br />
return rg.IsMatch(x);<br />
}<br />
<br />
protected void Application_PreRequestHandlerExecute(object sender, EventArgs e)<br />
{<br />
<br />
String ExtendsPermissions = "aspx|jpg|png"; <br />
String page = HttpContext.Current.Request.Path.ToString(); <br />
try<br />
{<br />
String expression = @"(/MYSITE/DIRECTORY/)(([a-zA-Z0-9_\/]+)*)\.(" + ExtendsPermissions + ")$";<br />
if (Compare(page, expression ) && userStats.Permission.Equals("DIRECTORY") )<br />
{ <br />
}<br />
else<br />
{<br />
<br />
HttpContext.Current.Response.Redirect(PageBasePath);
<br />
}<br />
}<br />
catch (Exception ex)<br />
{<br />
Response.Write(ex.Message);<br />
}<br />
}<br />
|
|
|
|
|
Better ask this in the asp.net forum.
|
|
|
|
|
hi all,
I wrote a service in c# and I prepared a setup to service but now
I want to unistall if service install before and then install last setup
how I do this??
thanks..
|
|
|
|
|
So you want to do an upgrade??
I will assume you have used a VS Setup project for doing this.
If you want your service to be updated and you use VS2008. Do the following:
Add a custom action for Install, Commit, Rollback and Uninstall and add "Primary output..." of your service project.
Add the Condition NOT PREVIOUSVERSIONSINSTALLED for Install and Commit.
In your Setup-project choose RemovePreviousVersion: True and change the UpgradeCode and Version .
IF you are using VS2005 you don't have to add the NOT PREVIOUSVERSIONSINSTALLED as a Condition. This was altered in VS2008.
I also assumed that you added a ProjectInstaller to your service project
|
|
|
|
|
"Add the Condition NOT PREVIOUSVERSIONSINSTALLED for Install and Commit.
In your Setup-project choose RemovePreviousVersion: True and change the UpgradeCode and Version"
how I add NOT PREVIOUSVERSIONSINSTALLED condition
and choose RemovePreviousVersion where is it??
|
|
|
|
|
I found them and I did them but it is not work
I unistall service "sc delete servisname" from command prompt ,is it necessary tu use this command?
|
|
|
|
|
No not really. Just to make sure I understand your question correctly, is this your scenario:
You have created a Windows Service (NT Service) and you have added a ProjectInstaller in that project.
You added a Setup project to your solution to install your Windows Service.
Now you want to make an upgrade of your Service, for instance upgrading from version 1.0 to 2.0.
Then you should do the following:
1. Create a Custom action to your Setup project for Install, Commit, Rollback and Uninstall, adding the Project Output.. of your Windows Service.
2. Change RemovePreviousVersion from false to true .
3. Change the Version of your Setup project (i.e. from 1.0 to 2.0).
4. Change the UpgradeCode of your Setup project (I believe VS asks you if you want to change this when you change the Version ).
5. If you are using VS 2008 (or 2010?), add the NOT PREVIOUSVERSIONSINSTALLED as a Condition . If you are using VS 2005, this is not necessary (Microsoft changed this behaviour between the 2005 and 2008 version of VS. This means that in 2008 the Service will not really be uninstalled in the Service Control Manager - only the binaries will we changed).
I know i repeated myself a bit from my previous answer, but this is actually the only steps you need to go through to make it work. If it doesn't work - please provide the code in your ProjectInstaller class , because maybe something is missing there. Also provide any error messages displayed.
You should not have to make any commands like "sc delete servisname" etc. All this should be taken care of by MSI.
|
|
|
|
|
thanks for your answers,you understand correctly my problem
my projectinstaller class only like this:
namespace SistemServis
{
[RunInstaller(true)]
public partial class ProjectInstaller : Installer
{
public ProjectInstaller()
{
InitializeComponent();
}
}
I added aproject installer but I didn't add anything else.
Do I have to write different things???
|
|
|
|
|
Okay, then that's your problem. You have to add code to the ProjectInstaller class that actually does the installation of your service. In your case it would look something like this (from MSDN example):
namespace SistemServis
{
[RunInstaller(true)]
public partial class ProjectInstaller : Installer
{
private ServiceInstaller serviceInstaller;
private ServiceProcessInstaller processInstaller;
public ProjectInstaller()
{
InitializeComponent();
processInstaller = new ServiceProcessInstaller();
serviceInstaller = new ServiceInstaller();
processInstaller.Account = ServiceAccount.LocalSystem;
serviceInstaller.StartType = ServiceStartMode.Manual;
serviceInstaller.ServiceName = "YourServiceName";
Installers.Add(serviceInstaller);
Installers.Add(processInstaller);
}
}
}
Good luck!
|
|
|
|
|
nothing changed
when I tried to install, service all times give this error:
error 1001:the apperred system is still there.
|
|
|
|
|
hmm.. that's odd. Could you make sure that your service is uninstalled when you run your "new" MSI (the one generated with the code I added), then make an install, change the version number (and upgrade code) and then perform an upgrade?
|
|
|
|
|