|
I'm not sure how do you want to get the second sample. In the first case, string manipulation is a way to go. Other, more math (and probably faster) solution is to get a length of begin and then divide it by 10^(length-4). Ot sth like (not tested):
uint shorter=begin;
while(shorter >= 10000) {
shorter /= 10;
}
Greetings - Jacek
|
|
|
|
|
Thank you everyone. If I explain my requirements maybe it will help.
I am generating a serial number in the following format:
00000-00000-00000-00000
I pass in two values into the serialGenerator class
int ProductID
int ProductVersion
I then combine these into one int value, say for example 12345123
Then I get the hex byte array representing this value, and hash it.
I then take 2 bytes of the hash from predetermined positions.
Then, I need to perform the bitwise so that I take a fixed part of teh new int value, which will always be 5 digits (first part of the serial number)
Generating the rest I have figured out.
Hope this clears things
Regards,
Stephen
|
|
|
|
|
stephen.darling wrote: I then take 2 bytes
You can't get 293844 from two "bytes".
Largest unsigned value from two 8 bit bytes used to create a 16 bit value is 256*256=65536.
|
|
|
|
|
jschell wrote: You can't get 293844 from two "bytes".
Sorry, I meant two uint32 values...
Steve
|
|
|
|
|
I use the following code when closing a form:
protected override void OnClosing(CancelEventArgs e)
{
//Your alternate implementation
FormClosingEventArgs ce = e as FormClosingEventArgs;
if (ce != null)
{
switch (ce.CloseReason)
{
case CloseReason.ApplicationExitCall:
//Handle application exit call
break;
case CloseReason.FormOwnerClosing:
//Handle Form owner close
break;
case CloseReason.MdiFormClosing:
//Handle MDI parent closing
break;
case CloseReason.None:
//Handle unknown reason
break;
case CloseReason.TaskManagerClosing:
//Handle taskmanager close
break;
case CloseReason.UserClosing:
//Handle User close
break;
case CloseReason.WindowsShutDown:
//Handle system shutdown
break;
}
}
base.OnClosing(e);
}
However on one of my forms it just working, it used to work fine
I setup a new form but still no results, I set a breakpoint and it doesn't even hit it.
Can anyone help with this problem.
Any help will be appreciated.
Thanks in advance,
Michael
|
|
|
|
|
I find your code confusing for two reasons
1) you override OnClosing instead of the preferred OnFormClosing method. Are you targetting .Net 1.1?
2) you cast the CancelEventArgs to FormClosingEventArgs. Surely this will never work and the resultant value will always be null.
The breakpoint problem might be explained by the cautionary note regarding the Application.Exit method in http://msdn.microsoft.com/en-us/library/system.windows.forms.form.onclosing.aspx[^].
|
|
|
|
|
i have FTP server in my computer (Windows-7) called MyFTP
i have thit code to transfer from local directory to FTP server
this code work excellent
string MyFile = @"d:\Test.txt";
//string url = "ftpUrl/FileName";
string url = "ftp://127.0.0.1/Test.txt";
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(url);
request.Method = WebRequestMethods.Ftp.UploadFile;
//request.Credentials = new NetworkCredential("user name", "password");
request.UsePassive = true;
request.UseBinary = true;
request.KeepAlive = false;
byte[] buffer = File.ReadAllBytes(MyFile);
using (Stream reqStream = request.GetRequestStream())
{
reqStream.Write(buffer, 0, buffer.Length);
}
and now i need to to transfer from FTP server to local directory in my computer
how to do it ?
modified on Thursday, August 11, 2011 5:11 PM
|
|
|
|
|
Hello Experts,
I would like ask how I will alow my client(the one browsing the internet) to upload the file into my web server. I set up my web application using the abyss web server so that I can host the website to my local machine, and for the FTP I use filezilla.
Below here is my code but it's only working in my local machine.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.IO;
using System.Net;
using System.Web.UI.WebControls;
namespace ftpPractice
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public void uploadFileUsingFTP(String CompleteFTPPath, String CompleteLocalPat)
{
try
{
FtpWebRequest reqObj = WebRequest.Create(CompleteFTPPath) as FtpWebRequest;
reqObj.Method = WebRequestMethods.Ftp.UploadFile;
reqObj.Credentials = new NetworkCredential("Akosidan", "newbie");
FileStream streamObj = File.OpenRead(CompleteLocalPat);
byte[] buffer = new byte[streamObj.Length];
streamObj.Read(buffer, 0, buffer.Length);
streamObj.Close();
streamObj = null;
reqObj.GetRequestStream().Write(buffer, 0, buffer.Length);
reqObj = null;
lblMessage.Text= "File Uploaded Successfully :)";
}
catch (Exception error)
{
Response.Write(error.ToString());
}
}
protected void cmdUpload_Click(object sender, EventArgs e)
{
uploadFileUsingFTP("ftp://localhost/recieveSample.txt", "C:\\someUsers\\someFolder\\Desktop\\sample.txt");
}
}
}
Comments,suggestion or recommendation is so much appreciated.
AkosiDAN <- newbie
|
|
|
|
|
|
Hello,
Thanks for the link. Now I don't need anymore 3rd party ftp server just to transfer file
Thanks again,
DAN
|
|
|
|
|
Hello,
I have an activeMQ broker and .net(c#) application that send and consume message without problem.
Now, I want to add some security to broker to avoid anyone else send or consume my messages.
So, I add simpleAuthenticationPlugin with username/password in AMQ configuration file, now in .net client I can't send messages because username/passw should be provided.
Until now all is ok, the problem is I dont found where to supply this information from code.
I can't set it in CachingConnectionFactory or SimpleConnectionFactory, it is not allowed, I dont find any other type of ConnectionFactory available in Spring.Messagin.Nms namespace I could use.
So I need some hint from any of you.
spring conf file is very simple:
<object id="ActiveMqConnectionFactory" type="Apache.NMS.ActiveMQ.ConnectionFactory, Apache.NMS.ActiveMQ">
<property name="UserName" value="usertest"/>
<property name="Password" value="passwordtest"/>
</object>
<object id="ConnectionFactory" type="Spring.Messaging.Nms.Connections.CachingConnectionFactory, Spring.Messaging.Nms">
<constructor-arg index="0" ref="ActiveMqConnectionFactory"/>
<property name="SessionCacheSize" value="10"/>
</object>
<object id="NmsTemplate" type="Spring.Messaging.Nms.Core.NmsTemplate, Spring.Messaging.Nms">
<constructor-arg index="0" ref="ConnectionFactory"/>
<property name="MessageConverter" ref="SimpleMessageConverter"/>
</object>
and in c# code I just use NmsTemplate as:
this.NmsTemplate.ConvertAndSend(msg);
Thanks in advances
|
|
|
|
|
Hi everybody!
I want to know if it is possible to get the USB port current value when I plug the device in it. The value should be get programmatically using C#. The second parameter I need is USB save power mode. The correct name of the property in the device manager is "Allow the computer to turn off this device to save power".
I managed to detect the device (if it is connected or disconnected) and read data from it correctly. Do these two properties belong to USB device or to USB port?! WinUSB Api did not give me clear answers to my questions.
Thanks!
|
|
|
|
|
Ok, this is probably a very basic question, but how would I go about creating the following (bear with me. I'm new to oop):
Lets say I'm in the automotive industry and I build a c# class called "Cars". Within this class, I have 2 properties:
-Model
-Year
So I can call them via Cars.Model & Cars.Year via code like this:
public class Cars
{
public string Model { get; set; }
public string Year { get; set; }
}
So far, so good....HOWEVER....now, I want to do a sub-property of Model, called Color. I would want to call it with something like this:
Cars.Model.Color = "green";
How would I create this "Color" property so that it becomes a sub-property of "Model"?
Thanks
|
|
|
|
|
You give Model a type that has a property called Color
|
|
|
|
|
I don't think somebody likes us giving this poster answers.
|
|
|
|
|
So it would seem..
Oh well, we probably got more upvotes because of it
|
|
|
|
|
I have been repeatedly asking to make comments mandatory for downvotes. I understand that the voter may put some garbage in the comments just for the sake of it. But it would help us to identify the trolls and banish them. (It can also help Chris to delete those downvotes).
|
|
|
|
|
As your code currently stands, you can't. What you need to do is create a class that Model implements (let's call it the Model class). Now, in this Model class, you'll have your Color property, so you end up with something like the following:
public class Cars
{
public Model Model { get; set; }
public string Year { get; set; }
}
public class Model
{
public string Color { get; set; }
} Now, a couple of things to consider here. First of all, you shouldn't be using a string for the Year property - it's really a number. Secondly, you shouldn't really call your class Cars - it's describing a single car, so it should really be called Car.
|
|
|
|
|
I think you're going about it wrong.
I think the Model class should have the Year property, but not the Color property. Although the Model class could have an AvailableColors collections.
|
|
|
|
|
Hey Guys,
I want to write a C# WinForms application, which on clicking a button will go to a particular web page and input the user name and password correctly. Once this step is done, it will go to the inbox and here i want to click a button. All this needs to be done with the web page in hidden mode.
For eg, Go to mail.yahoo.com and correctly enter the user name and password. Now it should click on the "Delete" button in my inbox.
Is it possible? Any sample code is welcome.
Thanks in advance
|
|
|
|
|
Gmail offers access over it's own API[^], might be easier.
Bastard Programmer from Hell
|
|
|
|
|
.NET 4.0
I have just finished finally figuring out how (in WinForms) to make changes to Properties in an ObservableCollection<T> fire notifications ... attaching events to ObservableCollection items, like adds, and deletes, are, of course, easily handled ... and it required a rather ugly hack to do it which involved casting an instance of an Observable<t> to the INotifyPropertyChanged interface.
Attempting to figure out if I have created a monstrosity, or if there's a better way, I have been searching CP for information on generic ObservableCollections<T>, and INotifyPropertyChanged, and just about everything that comes up is WPF or SilverLight related.
My impression is that WPF and SilverLight offer much more flexibile facilities for wiring-up property changes than WinForms, that 'INotifyPropertyChanged' is a different critter in WPF, and that one would not have the problem I encountered in WinForms in getting Property changes to raise events.
But, I would appreciate an opinion from those of you who I am sure know both WinForms and WPF well, if my impression is correct.
In the unlikely case I have discovered some useful technique for WinForms, I'll certainly publish an article on it here on CP.
thanks, Bill
"In the River of Delights, Panic has not failed me." Jorge Luis Borges
modified on Thursday, August 11, 2011 2:23 PM
|
|
|
|
|
First question, if you're data binding, why not use a BindingList<T>? Binding to that automatically causes the collection changes to be attached to, though I think that is the case for anything which implements INotifyCollectionChanged.
If your element type (i.e. 'T') implements INotifyPropertyChanged, the data consumer will hook to it and will update its display when you fire it (for the property which you declare as notified). I have tried this at least for a DataGridView and basic one-property controls (text box, check box etc) and it works as expected. You shouldn't need to do any casting if T implements that interface.
I'm not quite sure if you're asking a question here or just providing information about your experience so replying to the post is a bit tricky!
|
|
|
|
|
Hi Bob, thanks for your response !BobJanova wrote: if you're data binding, why not use a BindingList<T>? In this case I am not binding anything; there's no dataset in the woodpile I will go and take a look at Binding<T> now that you've pointed that out to me. fyi: I am familiar with implementing property notifications, like for the Text in a TextBox changing without any use of a dataset, or datasource.BobJanova wrote: not quite sure if you're asking a question here or just providing information about your experience I'm not quite sure either; I believe I am asking the question of whether the requirement, in the case of using an OC<T>, to cast an instance of it to INotifyPropertyChanged, in order to use its internally implemented property change notifications ... which I consider a very odd thing to have to do ... is worth the 'ugliness' involved.
And, I am hoping that you, or someone else here, who I am sure are at very advanced levels in .NET development, will give me some insights into what seems like a 'mystery' (to my 'naive' eyes). Perhaps, insights, based on your knowledge of how .NET has evolved. I know that OC<T> has changed library locations, and possibly some internal behavior, from .NET 3.0=>3.5=>4.0.
My intent in exploring this area is somewhat academic ... but certainly not homework (I'm nearing 68 years old) ... I am just deeply interested in understanding .NET's implementation, in WinForms, C#.
On a practical level, the ability to get a notification when a value is changed of a member of an arbitrarily typed collection, independent of binding to a datasource, seems valuable to me; I focused on OC<T> because that gives you 'out-of-the-box' notifcations when an item is added, or deleted, from the Collection<T>. It seemed natural, once I found out that OC<T> implemented property notification, to want to use that.
I did 'stumble' into finding out how to use the native property notification facility in OC<T>, but finding even a 'clue' about how to use it took pretty thorough research here, on StackOverFlow, and on MSDN. And, the way I found to actually use it, in a fairly standard scenario, I came up with on my own; didn't find a single example of that in my research (which of course doesn't mean it isn't there, somewhere on the internet).
Let me see if I can 'wrap this up:' for example, if you, or Pete O., or Shameel, or others here, said to me: 'yeah the fact that OC<T>'s INotifyPropertyChanged implementation is kind of 'sealed,' and you have to cast an instance of your collection to it to be able to use it, really is weird, probably better ... because of .?. not to use it, I'd feel enlightened, temporarily.
On the other hand, if I heard here that it might be valuable to use a technique for making an OC<T>'s property notifications available, I'd certainly at least write up a tip/trick for CP.
On the broader level, I do look forward to one-day, perhaps, having something like Property Extensions in .NET, and I understand that has been considered seriously, but is not on the .NET time-line now. I'd definitely like to be able to do some of the things that it seems WPF offers you in terms of property bindings, etc.
best, Bill
"In the River of Delights, Panic has not failed me." Jorge Luis Borges
|
|
|
|
|
Unfortunately I'm not really that familiar with ObservableCollection, though I have used the Silverlight version (is it the same?).
If I understand you correctly, you want to get an event on the collection when a property of an element is changed (and notified through INotifyPropertyChanged on the element – T must implement INotifyPropertyChanged and fire the notification event for any method of having observer updates). The ObservableCollection explicitly implements the INotifyPropertyChanged interface, so yes, if that event is correctly fired when a member element is updated, you will need to cast the collection to hook it. I haven't tried it so I don't know if it works.
(I.e., does the event get fired in this test case, and if so are the arguments useful:
void Test(){
var c = new ObservableCollection<Notifier>();
((INotifyPropertyChanged)c).PropertyChanged += (s,e) => MessageBox.Show("Property "+e.PropertyName+" on "+s+" updated");
c.Add(new Notifier());
c[0].NotificationProperty = 42;
}
class Notifier : INotifyPropertyChanged {
public event PropertyChangedEventHandler PropertyChanged;
public int NotificationProperty {
get { return notificationProperty; }
set { notificationProperty = value; PropertyChanged(this, "NotificationProperty"); }
}
}
)
The fact that they made that interface implementation explicit and force the cast implies they probably aren't expecting you to use it in this way, but if the event is fired when properties on the elements change and that is useful to you, I don't see a problem with using it in that fashion.
|
|
|
|
|