|
The way i did was sending the user name to server and a flag with the client with which i want to communicate.
Then server send the message to that particular client on that socket.
So this looks like peer to peer but it is not. It is actually Client -to Server -to - Client.
I guess there should be some way in which we can have Peer ro Peer, may not be using TCP but something else.
|
|
|
|
|
i have textbox that do something on GotFocus.
how i can disable the GotFocus on this textbox ?
and how to enable it back ?
thanks in advance
|
|
|
|
|
Presumably you are talking winforms!
GotFocus is an event, you can't disable it, you can disable the control or you can handle the problem inside the event.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
if you want to disable a textbox, you can use
textbox.enable = false; and true to reanable it ofc.
If you don't like this solution, you can try to overwrite the GotFocus method to only do "something" if you want it.
|
|
|
|
|
Gali1978 wrote: how i can disable the GotFocus on this textbox ?
textBox1.GetFocus -= this.textBox1_GotFocus;
Gali1978 wrote: and how to enable it back ?
textBox1.GetFocus += this.textBox1_GotFocus;
Alternatively, you could set a flag to indicate your "disabledness" and act on that;
bool isFocusEnabled = false;
void this.textBox1_GotFocus(object sender, EventArgs e)
{
if (!isFocusEnabled) then return;
} That'd allow you to disable/enable the execution of the event with a simple boolean.
Bastard Programmer from Hell
|
|
|
|
|
We are producing proofs of files we intend to print; however, the files are sometimes 80 mg in size. Producing a proof with variable data is not an issue. The issue is the amount of time it takes to open and view the pdf's over the web; therefore, the question is...
Is there a way to automatically reduce the resolution of the pdf using C#, VB, C++ or iTextSharp?
Thanks,
Steve
|
|
|
|
|
You'd have to recompose the entire document in order to do that. Any "oversized" pictures would need to be resampled to a lower resolution and put back into the document to reduce it's size. You might just want to compose two documents instead. One with reduced size pictures and another with "normal". If they want the "good" one, you can provide a link to the second download.
|
|
|
|
|
|
Are you accidentally including text as images, instead of text? That is usually why PDFs get huge.
For included images (or other large resources e.g. embedded fonts) within a document, make sure you're using a sensible compression scheme (JPEG or gzip). Complex page streams should also be compressed, but simple ones shouldn't (it makes the file bigger).
|
|
|
|
|
Hi, in my project I tried to backup my database and then restore using SMO. While backing up and restoring it gives no errors and catches no exception. All of them seem to work great. However, after I perform backup to a file, I deleted the data and/or a table from my database to see whether restoring operation will perform correctly or not. However, when I deleted a table or just data in the table, if I perform restore operation, neither the table nor the data in the table comes back. As a result either backup or restore operation does not work correctly. My backup and restore methods are as in the following :
public bool BackUpDB(string DBpath)
{
try
{
ServerConnection srvConn = new ServerConnection(Program.serverName);
srvConn.LoginSecure = true;
srvr = new Server(srvConn);
Backup bkpDatabase = new Backup();
bkpDatabase.Action = BackupActionType.Database;
bkpDatabase.Database = Program.databaseName;
bkpDatabase.Incremental = false;
bkpDatabase.Initialize = true;
bkpDatabase.LogTruncation = BackupTruncateLogType.Truncate;
BackupDeviceItem bkpDevice = new BackupDeviceItem(DBpath , DeviceType.File);
bkpDatabase.Devices.Add(bkpDevice);
bkpDatabase.SqlBackupAsync(srvr);
return true;
}
catch (Exception)
{
return false;
}
}
The following is my restore method :
public bool RestoreDB(string DBpath)
{
try
{
ServerConnection srvConn = new ServerConnection(Program.serverName);
srvConn.LoginSecure = true;
srvr = new Server(srvConn);
Restore rstDatabase = new Restore();
rstDatabase.Action = RestoreActionType.Database;
if (!srvr.Databases.Contains(Program.databaseName))
{
try
{
DbConnection dbcon = new DbConnection("Data Source=" + Program.serverName + ";Initial Catalog=master;Integrated Security=True");
dbcon.ExecuteCommand("CREATE DATABASE "+Program.databaseName, null);
}
catch (Exception)
{
MessageBox.Show("Veritabanı yaratılırken hata oluştu. Program yine de yedeğinizi geri yüklemeye çalışacak. Ancak bu değişiklik programınıza yansımayabilir. Bu durumda bizimle iletişime geçiniz.","Uyarı",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
}
rstDatabase.Database = Program.databaseName;
rstDatabase.Devices.AddDevice(@DBpath, DeviceType.File);
rstDatabase.ReplaceDatabase = true;
rstDatabase.SqlRestoreAsync(srvr);
return true;
}
catch (Exception)
{
return false;
}
}
I searched on this issue a lot and all of the codes seems correct however I could not understand why it does not perform correctly. Anyone can help me on this issue ? Please it is a bit urgent, Thanks...
|
|
|
|
|
kutbinayi wrote: Please it is a bit urgent, Thanks...
Not even when the code is on fire.
The code looks like it swallows all exceptions. You could try and change the SqlBackupAsync to SqlBackup ; might be throwing something async
--edit;
The same question is in the database-forum; choose a forum and stick with it, cross-posting is annoying.
Bastard Programmer from Hell
|
|
|
|
|
Yes but when I use SqlBackup method then it nevers succeed backup operation. and catches an exception on data object System.Collections.ListDictionaryInternals. I think this object is used by SqlBackup method. If I use SqlBackupAsync then no exception is thrown. I catched all exceptions but it is not seen in the above code. I just use it while I was trying. Is it normal that SqlBackupAsync succeeds the backup operation but restoring the database does not affect the database ? What could be other reasons ?
|
|
|
|
|
kutbinayi wrote: If I use SqlBackupAsync then no exception is thrown.
I bet it is, only on another thread. That would mean that there could have been an exception, without it being reported.
kutbinayi wrote: Is it normal that SqlBackupAsync succeeds the backup operation but restoring the database does not affect the database ?
No, the software usually does as advertised.
kutbinayi wrote: What could be other reasons ?
Some application open (editing the database) while you're doing a restore? That would lock the database and result in an abort.
Can you paste the entire exception that you're getting?
Bastard Programmer from Hell
|
|
|
|
|
The whole exception is this :
Microsoft.SqlServer.Management.Smo.FailedOperationException: Backup failed for Server 'EMRE-PC\SQLEXPRESS'. ---> Microsoft.SqlServer.Management.Common.ExecutionFailureException: An exception occurred while executing a Transact-SQL statement or batch. ---> System.Data.SqlClient.SqlException: Cannot open backup device 'C:\Users\EMRE\Desktop\YEDEK.bak'. Operating system error 5(failed to retrieve text for this error. Reason: 15105).
BACKUP DATABASE is terminating abnormally.
konum: Microsoft.SqlServer.Management.Common.ConnectionManager.ExecuteTSql(ExecuteTSqlAction action, Object execObject, DataSet fillDataSet, Boolean catchException)
konum: Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(String sqlCommand, ExecutionTypes executionType)
--- İç özel durum yığını izlemesinin sonu ---
konum: Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(String sqlCommand, ExecutionTypes executionType)
konum: Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(StringCollection sqlCommands, ExecutionTypes executionType)
konum: Microsoft.SqlServer.Management.Smo.ExecutionManager.ExecuteNonQuery(StringCollection queries)
konum: Microsoft.SqlServer.Management.Smo.BackupRestoreBase.ExecuteSql(Server server, StringCollection queries)
konum: Microsoft.SqlServer.Management.Smo.Backup.SqlBackup(Server srv)
--- İç özel durum yığını izlemesinin sonu ---
konum: Microsoft.SqlServer.Management.Smo.Backup.SqlBackup(Server srv)
konum: _15_49KADINIZLEM.DbConnection.BackUpDB(String DBpath) C:\Users\EMRE\documents\visual studio 2010\Projects\15-49KADINIZLEM\15-49KADINIZLEM\DbConnection.cs içinde: satır 107
Backup failed for Server 'EMRE-PC\SQLEXPRESS'.
|
|
|
|
|
Cannot open backup device 'C:\Users\EMRE\Desktop\YEDEK.bak'. Operating system error 5(failed to retrieve text for this error. Reason: 15105).
BACKUP DATABASE is terminating abnormally.
There's your answer. Try a different path.
Bastard Programmer from Hell
|
|
|
|
|
what could be the reason of not accepting this file path ? Because there is no restriction to save file to my Desktop folder.
|
|
|
|
|
kutbinayi wrote: what could be the reason of not accepting this file path ? Because there is no restriction to save file to my Desktop folder.
This is the place where you post whether a different path actually worked or not.
Is there a readonly-file in that location?
Bastard Programmer from Hell
|
|
|
|
|
Ok, but why this does not occur when I use SqlBackupAsync method ?
|
|
|
|
|
kutbinayi wrote: Ok, but why this does not occur when I use SqlBackupAsync method ?
It does. It fails, throwing the exact same exception on another thread. Methods that end with "Async" are executed in a different thread, and you don't get the exceptions that they throw.
Bastard Programmer from Hell
|
|
|
|
|
Ok, thank you for all of your replies. As a result using SqlBackup method instead of SqlBackupAsync is better solution for me. And if i solve the file path problem in my code, then everything seems to work great, right.
|
|
|
|
|
kutbinayi wrote: Ok, thank you for all of your replies.
You're welcome
|
|
|
|
|
Hello,
i have a strange problem with a TextBox.
I use a TextBox to show a ComPort Log. A communication Thread fires a datarecieved event and the Form with the Textbox handles this Event and uses Invoke to change the Content of the (multiline) TextBox.
void ComPortLog_PropertyChangedEvent() {
MethodInvoker ComPortLogChanged = delegate {
textBox2.Text = ComPortLog.Log;
};
if (textBox2.InvokeRequired) Invoke(ComPortLogChanged);
else ComPortLogChanged();
}
After a Timespan (0-30 Minutes) this stops Working? The string in ComPortLog.Log is correct and complete but the string in the Textbox.Text isnt...
somehow this isnt working anymore:
textBox2.Text = ComPortLog.Log;
The string in textBox2.Text is truncated to a value which differs from program run to programrun. Why? The Length of the ComPortLog.Log string is far below MaxLength Property of the textbox.
I tried to use a richTextBox instead, i tried to use the Lines Property instead of Text Property but nothing helps.
The Textbox refuses to show the complete ComPortLog.Log string after a while.
Any suggestions/ideas about this?
|
|
|
|
|
The situation isn't quite clear, and a lot of things could go wrong. Here are some suggestions:
1.
as a test, forget about the GUI, just collect the serial port information and log it to a file, using File.AppendAllText . See if that fails at all.
2.
add try-catch constructs to all related code, and log all exceptions (their ToString value) in a separate file, again File.AppendAllText is the right method.
If you need further assistance, please provide more context, a complete description of your serial source, your serial port's code, and examples of the data when it fails.
|
|
|
|
|
Hi,
The Program controls a spectrometer via serail port and triggers multiple measuremets and than collects and processes the results. And it works fine... except the textBox which does not show the ComPortLog in the Program correctly.
to 1: there is already a routine which saves the Log to a File and it also works fine. The textfile contains the complete log string.
to 2: already done... almost every possible exception is catched and written to the trace.
The serialport Communication isn't the problem (i think) because it works without problems, like the whole program. The measurement results are all valid...
I use an own ComPort Class and not the .Net SerialPort due to its unreliability.
If data is send or recieved an Event is fired
public event Action<string> OnSendReceive;
if (OnSendReceive != null)
OnSendReceive(ComPort.PortName + ": Recieved: " + message);
if (OnSendReceive != null)
OnSendReceive(ComPort.PortName + ": Send: " + command);
these Events are handled by a DeviceManager Class which then adds a Timestamp to the string and calls the writeline Method of a global instance (defined in MDI ParentForm) of the following class:
public class LogString {
public delegate void changedEvent();
public event changedEvent PropertyChanged;
private StringBuilder log;
public string Log { get { return log.ToString(); } }
public int Length { get { return log.Length; } }
public string BackupFileName { get; set; }
public LogString(string InitialString = null) {
BackupFileName = null;
log = new StringBuilder(InitialString);
}
public override string ToString() {
return log.ToString();
}
public void Write(string txt) {
log.Append(txt);
UpdateFile();
FireEvent();
}
public void WriteLine(string txt) {
log.AppendLine(txt);
UpdateFile();
FireEvent();
}
public void ClearLog() { log.Clear(); FireEvent(); }
public bool SaveToFile(string FileName, FileMode FMode) {
try {
using (Stream Str = new FileStream(FileName, FMode))
using (TextWriter TW = new StreamWriter(Str))
TW.Write(this.log.ToString());
} catch { return false; }
return true;
}
private void UpdateFile() {
if (BackupFileName != null) {
using (Stream Str = new FileStream(BackupFileName, FileMode.Append))
using (TextWriter TW = new StreamWriter(Str))
TW.Write(message);
}
}
private void FireEvent() {
if (PropertyChanged != null) PropertyChanged();
}
}
So the Log is written to a File on the Disk an the PropertyChanged Event is fired.
there is a separate Form, which shows the Logs in TextBoxes:
public partial class LogWindow : Form {
private Tools.StringTraceListener STL;
private MainWindow parent;
private MethodInvoker ComPortLogChanged, ProgramLogChanged;
private string ComPortLog = string.Empty, ProgramLog = string.Empty;
public LogWindow(Tools.StringTraceListener st, MainWindow p) {
InitializeComponent();
parent = p;
STL = st;
STL.PropertyChanged += new PropertyChangedEventHandler(STL_PropertyChanged);
parent.ComPortLog.PropertyChanged += new Classes.Tools.LogString.changedEvent(ComPortLog_PropertyChangedEvent);
this.CreateHandle();
ComPortLogChanged = delegate {
textBox2.Text = ComPortLog;
textBox2.SelectionStart = textBox2.Text.Length;
textBox2.ScrollToCaret();
};
ProgramLogChanged = delegate {
textBox1.Text = ProgramLog;
textBox1.SelectionStart = textBox1.Text.Length;
textBox1.ScrollToCaret();
};
}
void ComPortLog_PropertyChangedEvent() {
ComPortLog = string.Empty;
ComPortLog = parent.ComPortLog.Log;
if (this.InvokeRequired) Invoke(ComPortLogChanged);
else ComPortLogChanged();
}
void STL_PropertyChanged(object sender, PropertyChangedEventArgs e) {
ProgramLog = string.Empty;
ProgramLog = STL.Trace;
if (this.InvokeRequired) Invoke(ProgramLogChanged);
else ProgramLogChanged();
}
}
This works fine for a while and the Log in the Textbox looks like this:
...
27.09.2011 18:12:37 COM3: Recieved: !01 000000 000071 000291 000106 000150
27.09.2011 18:12:37 COM3: Send: #01c170
27.09.2011 18:12:39 COM3: Recieved: !01 000000 000170 000235 000202 000289
27.09.2011 18:12:39 COM3: Send: #01c171
27.09.2011 18:12:41 COM3: Recieved: !01 000000 000171 000502 000202 000305
27.09.2011 18:12:41 COM3: Send: #01c172
27.09.2011 18:12:44 COM3: Recieved: !01 000000 000172 000521 000203 000309
27.09.2011 18:12:44 COM3: Send: #01c650
27.09.2011 18:12:46 COM3: Recieved: !01 000000 000650 000081 002057 002081
27.09.2011 18:12:46 COM3: Send: #01c651
27.09.2011 18:12:48 COM3: Recieved: !01 000000 000651 000200 002049 002079
27.09.2011 18:12:48 COM3: Send: #01c652
27.09.2011 18:12:50 COM3: Recieved: !01 000000 000652 000207 002046 002088
27.09.2011 18:12:51 COM3: Send: #01c070
27.09.2011 18:12:54 COM3: Recieved: !01 000000 000070 000126 000105 000138
27.09.2011 18:12:54 COM3: Send: #01c071
27.09.2011 18:12:56 COM3: Recieved: !01 000000 000071 000289 000105 000151
27.09.2011 18:12:56 COM3: Send: #01c170
27.09.2011 18:12:58 COM3: Recieved: !01 000000 000170 000199 000201 000299
27.09.2011 18:12:58 COM3: Send: #01c171
27.09.2011 18:13:01 COM3: Recieved: !01 000000 000171 000503 000201 000303
27.09.2011 18:13:01 COM3: Send: #01c172
27.09.2011 18:13:03 COM3: Recieved: !01 000000 000172 000538 000201 000317
27.09.2011 18:13:03 COM3: Send: #01c650
27.09.2011 18:13:05 COM3: Recieved: !01 000000 000650 000077 002045 002070
27.09.2011 18:13:05 COM3: Send: #01c651
27.09.2011 18:13:07 COM3: Recieved: !01 000000 000651 000202 002044 002075
27.09.2011 18:13:08 COM3: Send: #01c652
27.09.2011 18:13:10 COM3: Recieved: !01 000000 000652 000205 002049 002078
27.09.2011 18:13:11 COM3: Send: #01c070
27.09.2011 18:13:13 COM3: Recieved: !01 000000 000070 000119 000106 000146
27.09.2011 18:13:13 COM3: Send: #01c071
27.09.2011 18:13:15 COM3: Recieved: !01 000000 000071 000292 000106 000143
27.09.2011 18:13:15 COM3: Send: #01c170
27.09.2011 18:13:18 COM3: Recieved: !01 000000 000170 000221 000202 000300
27.09.2011 18:13:18 COM3: Send: #01c171
but after a couple of minutes (up to 30) it stops working, and the Text in the Textbox does not change anymore and seem truncated:
...
27.09.2011 18:14:56 COM3: Recieved: !01 000000 000171 000513 000204 000303
27.09.2011 18:14:56 COM3: Send: #01c172
27.09.2011 18:14:58 COM3: Recieved: !01 000000 000172 000546 000204 000304
27.09.2011 18:14:59 COM3: Send: #01c650
27.09.2011 18:15:01 COM3: Recieved: !01 000000 000650 000087 002070 002095
27.09.2011 18:15:01 COM3: Send: #01c651
27.09.2011 18:15:03 COM3: Recieved: !01 000000 000651 000198 002071 002102
27.09.2011 18:15:03 COM3: Send: #01c652
27.09.2011 18:15:05 COM3: Recieved: !01 000000 000652 000197 002071 002102
27.09.2011 18:15:06 COM3: Send: #01c070
27.09.2011 18:15:08 COM3: Recieved: !01 000000 000070 000124 000107 000142
27.09.2011 18:15:09 COM3: Send: #01c071
27.09.2011 18:15:11 COM3: Recieved: !01 000000 000071 000283 000107 000145
27.09.2011 18:15:11 COM3: Send: #01c170
27.09.2011 18:15:13 COM3: Recieved: !01 000000 000170 000216 000204 000303
27.09.2011 18:15:13 COM3: Send: #01c171
27.09.2011 18:15:15 COM3: Recieved: !01 000000 000171 000531 000203 000319
27.09.2011 18:15:15 COM3: Send: #01c172
27.09.2011 18:15:18 COM3: Recieved: !01 000000 000172 000505 000203 000307
27.09.2011 18:15:18 COM3: Send: #01c650
27.09.2011 18:15:20 COM3: Recieved: !01 000000 000650 000080 002070 002097
27.09.2011 18:15:20 COM3: Send: #01c651
27.09.2011 18:15:22 COM3: Recieved: !01 000000 000651 000212 002071 002098
27.09.2011 18:15:22 COM3: Send: #01c652
27.09.2011 18:15:25 COM3: Recieved: !01 000000 000652 000209 002071 002102
27.09.2011 18:15:26 COM3: Send: #01c070
27.09.2011 18:15:28 COM3: Recieved: !01 000000 000070 000116 000107 000140
27.09.2011 18:15:28 COM3: Send: #01c071
27.09.2011 18:15:30 COM3: Recieved: !01 000000 000071 000290 000107 000146
27.09.2011 18:15:30 COM3: Send: #01c170
27.09.2011 18:15:32 COM3: Recieved: !01 000000 000170 000230 000203 000297
27.09.2011 18:15:32 COM3: Send: #01c171
27.09.2011 18:15:35 COM3: Recieved: !01 000000 000171 00054
All the event are fired correctly, and the textbox flashes as it still trys to scroll to the end but Command
textBox2.Text = ComPortLog; doesn't work correctly... the string ComPortLog contains the complete ComPort Log but the Text Property of the TextBox doesn't...
it is a complete Mystery for me...
|
|
|
|
|
Rather than attempting to write a string that's getting bigger and bigger, why don't you simply append to a listbox? It would be far simpler.
|
|
|
|