|
Hi to all developers.
I try to program something like Yahoo messenger ( school project).
I write tow program, Server and Client. when a client request new account, server receive the command and made new user object but it won't add new user to database. in server every socket process within a thread.
I debug line by line, everything is OK ( I think ..! )
I also try update my DB via Stored procedure, but no luck
for more details take a look at my code.
any help appreciate.
User table:
http://i52.tinypic.com/2hyvskn.jpg
private void CommandReceived(object sender, CommandEventArgs e)
{
switch (e.Command.CommandType)
{
case CommandsType.NewUser:
{
int ret = CreateNewUser(e.Command.SenderUsername, e.Command.MetaData);
Command cmd = new Command(CommandsType.NewUser, "server", e.Command.SenderUsername, ret.ToString());
SendCommandToTarget(cmd);
UpdateConsole("new client registration ", "", IPAddress.None, 0);
break;
}
}
}
private int CreateNewUser(string u, string pne)
{
try
{
RMData db = new RMData();
string username = u;
string password = pne.Split(new char[] { ':' })[0];
string email = pne.Split(new char[] { ':' })[1];
Users user = db.Users.SingleOrDefault(usr => usr.Username == username);
if (user != null)
return 1;
user = db.Users.SingleOrDefault(usr => usr.Email == email);
if (user != null)
return 2;
user = new Users();
user.Username = username;
user.AddedDate = DateTime.Now;
user.Email = email;
user.Password = password;
db.Users.InsertOnSubmit(user);
return 0;
}
catch (Exception ex)
{
return 3;
}
}
whole project:
http://www.mediafire.com/?bf5e5d6lqoolbbs
Password is: 123
N
o
N
ame
modified on Tuesday, January 25, 2011 5:16 PM
|
|
|
|
|
Use all available information, and when that does not work for you, tell it in this thread. "Does not work" is not helpful.
Always give expectations and symptoms.
You should:
- add a try-catch in CommandReceived
- in each catch, log the entire Exception using Exception.ToString()
- watch for the line numbers in the exceptions and in your source editor windows.
NoName_ark wrote: catch (Exception ex)
{
return 3;
}
Don't swallow exceptions like that, you're throwing away valuable information.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
thanks for your reply.
I debug my code, there is no error in my code that try block catch it!.
I told everything is alright. the function return return zero ( no error)
I just can't step in to db context. actually debugger can't do it.
I will upload whole project, if there is no problem take a look at it, and debug only server side program.
U can put a check point in CammandReceived line.
In client side I just complete new user. Please try create new user form.
Very thanks for your time.
http://www.mediafire.com/?bf5e5d6lqoolbbs
Password is: 123
N
o
N
ame
|
|
|
|
|
No thanks, nobody is going to download and debug your project for you, it is your job. Now start by improving your code, give it better observability, and if any problems are left, ask specific questions here with sufficient detail.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Ok, thanks for your time.
I know My LINQ code have error.
I investigate it
N
o
N
ame
|
|
|
|
|
Hi
I found my problem.
I explain my answer to other people may have problem as same as me!
Actually I ( visual studio) make 2 DB file, first one is my solution folder,
and second one was in Bin/debug folder.
when I run or debug my program, data saved in bin/debug folder...!
but when I look at my DB by Visual Studio, it show Solution Database file that contain nothing.
I think it is a bug because I foolish myself for five days for nothing
N
o
N
ame
|
|
|
|
|
It's not a bug. What you have here is a limitation in your understanding of the build/run process in Visual Studio. If you look at your database in Solution Explorer, the properties have been set to Copy Always in the Copy to Output Folder dropdown.
|
|
|
|
|
I need some help. Would u guys mind helping me out on my new project? that's if your're not busy. Our project is somewhat similar to the one that has been submitted here in codeproject. Our project is about simulating a robot ball gatherer. The robot will gather the ball depending on the color and place it back inside a box that corresponds to the color of the ball. Obstacle avoidance is also present. And the robot's speed will gradually slow don until it reaches the ball. I would really appreciate if you will help me on this. I have been coding for 2 weeks already, and I can't even start the robot move. tsk. It's kinda hard especially for me as a second year student. Thank you very much in advance and hope I can hear from you soon.
thanks a lot. 
|
|
|
|
|
The Coding4Fun[^] blog often features articles on building robots, using various techniques. Most of the articles are complete walkthroughs, and it's nice to have a material-list and an indication of the cost.
I are Troll
|
|
|
|
|
could u send us somelinks? ur blog is great but i can't find what im looking for. 
|
|
|
|
|
Did you actually look at the link Eddy posted? It took me 2 seconds to find this[^].
I must get a clever new signature for 2011.
|
|
|
|
|
It's not "my" blog. No, it won't have an exact walkthrough of what you're looking for - but it might be a good starting point for your own research
I are Troll
|
|
|
|
|
Surprisingly, I have never had to do this before until now. I figured it would be a property of the column, but I am having difficulty determining how to do this. The GridView is populated at run time.
|
|
|
|
|
Here[^] you go, they can explain it way better then I could
I are Troll
|
|
|
|
|
Thanks a bunch. I should have found that out on my own. 
|
|
|
|
|
My pleasure. MSDN is a large place where things get lost easily
I are Troll
|
|
|
|
|
I have tried this with the code:
dt.Columns.Add("Pair");
dt.Columns["Pair"].ReadOnly = true;
dt.Columns.Add("Last");
dt.Columns.Add("TimeStamp");
dt.Columns["TimeStamp"].ReadOnly = true;
The Pairs column remains readonly, yet the TimeStamp column allows the text to be manipulated, then throws an error that the column is read only once the focus has left the cell...
|
|
|
|
|
The "dt" prefix suggests that you're setting the Columns of the DataTable to readonly. The link that I posted set the readonly property on the Columns of a DataGridView . Both are possible, and seem to work correctly from a test-project;
public Form1()
{
InitializeComponent();
DataGridView dgv = new DataGridView();
dgv.Dock = DockStyle.Fill;
Controls.Add(dgv);
DataTable dt = new DataTable();
dt.Columns.Add("Pair");
dt.Columns.Add("Last");
dt.Columns.Add("TimeStamp");
dt.Rows.Add();
dgv.DataSource = dt;
dgv.Columns[0].ReadOnly = true;
dgv.Columns[2].ReadOnly = true;
}
Uncomment the "dt" lines if you want to test that variant
I are Troll
|
|
|
|
|
Assuming that you are asking about a WPF/SilverLight component, all items in GridView retain attributes of their cell templates. For example, if you used TextBlock in your data template, you'd set its IsEnabled property to "False" to gray out the column.
DataGrid, on the other hand, lets you set properties on individual columns (very much in line with what you described). For example, DataGridTextColumn and DataGridTemplateColumn have an IsReadOnly property that you can set in XAML.
EDIT: It looks like you were not talking about WCF after all 
|
|
|
|
|
It writes to the log file every 2 seconds, so I know it is looping, but it does not stop the shutdown executable from running. However if I loop it with a batch file it works perfect? Is there a way to have the command text write to the console window as well?
Thanks for reading.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Threading;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
while (true)
{
System.Diagnostics.ProcessStartInfo shutDownBlocker = new ProcessStartInfo();
shutDownBlocker.FileName = @"c:\windows\system32\shutdown.exe";
shutDownBlocker.WindowStyle = ProcessWindowStyle.Normal;
shutDownBlocker.Arguments = " /a";
shutDownBlocker.CreateNoWindow = false;
Thread.Sleep(2000);
File.AppendAllText(@"c:\temp\shutdownlog.txt", "ran command" + System.Environment.NewLine);
}
}
}
}
|
|
|
|
|
As per my understanding to the question, you have only created the object of ProcessStartInfo and assigned some values to it.
you need to call the Process.Start() API of Process class with object of ProcessStartInfo as a parameter.
Then and only then your 'shutdown.exe' will start and perform its duty.
Refer this link for more details and example http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.aspx[^]
If you have further query, please elaborate it.
Hope this helps!!!
Praveen Raghuvanshi
Software Developer
|
|
|
|
|
 Hi Praveen, that looks to be my problem, thank you very much.
I'm trying to incorporate it into a service I am building and it just does not work. I am probably overlooking something again, if you have any ideas, I'd love to hear them.
Thank you again for the help.
using System;
using System.Diagnostics;
using System.ServiceProcess;
using System.Threading;
using System.Windows.Forms;
namespace WindowsService
{
class WindowsService : ServiceBase
{
Thread thread = new Thread(new ThreadStart(shutDownBlocker));
public WindowsService()
{
this.ServiceName = "AllinOneService";
this.EventLog.Log = "Application";
this.CanHandlePowerEvent = true;
this.CanHandleSessionChangeEvent = true;
this.CanPauseAndContinue = true;
this.CanShutdown = true;
this.CanStop = true;
shutDownBlocker();
thread.Start();
}
static void Main()
{
ServiceBase.Run(new WindowsService());
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
}
protected override void OnStart(string[] args)
{
base.OnStart(args);
}
protected override void OnStop()
{
base.OnStop();
}
protected override void OnPause()
{
base.OnPause();
}
protected override void OnContinue()
{
base.OnContinue();
}
protected override void OnShutdown()
{
base.OnShutdown();
}
protected override void OnCustomCommand(int command)
{
base.OnCustomCommand(command);
}
protected override bool OnPowerEvent(PowerBroadcastStatus powerStatus)
{
return base.OnPowerEvent(powerStatus);
}
protected override void OnSessionChange(SessionChangeDescription changeDescription)
{
base.OnSessionChange(changeDescription);
}
private static void shutDownBlocker()
{
while (true)
{
try
{
System.Diagnostics.ProcessStartInfo shutDownBlocking = new ProcessStartInfo();
shutDownBlocking.CreateNoWindow = true;
shutDownBlocking.FileName = @"c:\windows\system32\shutdown.exe";
shutDownBlocking.WindowStyle = ProcessWindowStyle.Hidden;
shutDownBlocking.Arguments = "/a";
Process.Start(shutDownBlocking);
Thread.Sleep(500);
}
catch (Exception ex)
{
}
}
}
}
}
|
|
|
|
|
You are missing System.Diagnostics.Process.Start(shutDownBlocker);
|
|
|
|
|
On top of what the other people said, this little technique you're using will only stop a shutdown IF it was initiated with the SHUTDOWN.EXE command. If you shutdown the system with Start -> Shutdown, or some other method other than Shutdown.exe, this code won't do a thing to stop it.
|
|
|
|
|
After a quick search I found this
Often people try to code complex soluting when the OS already give them the option...
|
|
|
|