|
Ok. Ill do so.
Thank you again.
|
|
|
|
|
You're welcome!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Ignorissimus' vote of #1 leavened with the yeast of #5
« There is only one difference between a madman and me. The madman thinks he is sane. I know I am mad. » Salvador Dali
|
|
|
|
|
Thank you Bill!
How are you this (locally grey, wet, and miserable but probably for you it's) fine day?
All finished setting up the new house?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Note that C# does not, like Pascal, have a separate syntax for procedures (do not return a value) and functions (return a value): in C# both are termed "methods."
There's no direct equivalent in C# to Pascal's nested functions where the inner functions have access to the variables in their "container" ... if that's what you are asking.
What exactly do you mean by "in program method:" do you mean in the Program.cs class that in the default Windows Forms application contains the 'Main method ?
It's easier to say where you can't create methods:
1. outside a NameSpace
2. inside a Method
However, one can, in a way, create methods inside methods by creating instances of delegates or anonymous methods/lambda expressions. The 'Action and 'Func delegates are useful to define methods inside a method.
And, you can have nested Classes in .NET, with each Class containing methods: by making an inner Class static one can easily execute the method given an instance of the outer Class.
« There is only one difference between a madman and me. The madman thinks he is sane. I know I am mad. » Salvador Dali
modified 18-Oct-14 4:39am.
|
|
|
|
|
BillWoodruff wrote: It's easier to say where you can't create methods:
1. outside a NameSpace
2. inside a Method
That's clear.
Thanks.
ill check later rest wide information
|
|
|
|
|
My DeepCopy method:
public static T DeepCopy<T>(T entity)
{
if (entity == null)
{
throw new ArgumentNullException("Entity cannot be null");
}
using (var ms = new MemoryStream())
{
var formatter = new BinaryFormatter();
formatter.Serialize(ms, entity);
ms.Position = 0;
return (T)formatter.Deserialize(ms);
}
}
The entity I'm trying to copy:
[Serializable]
[DataContract]
public class SafetyInfractionEntity : _BaseEntity
{
#region Properties
private int _SafetyInfractionId;
[DataMember]
public int SafetyInfractionId
{
get { return _SafetyInfractionId; }
set
{
if(_SafetyInfractionId != value)
{
_SafetyInfractionId = value;
IsDirty = true;
RaisePropertyChanged("SafetyInfractionId");
RaiseEntityChanged();
}
}
}
private int _EmployeeId;
[DataMember]
public int EmployeeId
{
get { return _EmployeeId; }
set
{
if(_EmployeeId != value)
{
_EmployeeId = value;
IsDirty = true;
RaisePropertyChanged("EmployeeId");
RaiseEntityChanged();
}
}
}
private int _InfractionTypeId;
[DataMember]
public int InfractionTypeId
{
get { return _InfractionTypeId; }
set
{
if(_InfractionTypeId != value)
{
_InfractionTypeId = value;
IsDirty = true;
RaisePropertyChanged("InfractionTypeId");
RaiseEntityChanged();
}
}
}
private LookupEntity _InfractionType;
[DataMember]
public LookupEntity InfractionType
{
get { return _InfractionType; }
set
{
if (_InfractionType != value)
{
_InfractionType = value;
RaisePropertyChanged("InfractionType");
RaiseEntityChanged();
}
}
}
private DateTime? _InfractionDate;
[DataMember]
public DateTime? InfractionDate
{
get { return _InfractionDate; }
set
{
if (_InfractionDate != value)
{
_InfractionDate = value;
IsDirty = true;
RaisePropertyChanged("InfractionDate");
RaiseEntityChanged();
}
}
}
private int _JobRevisionId;
[DataMember]
public int JobRevisionId
{
get { return _JobRevisionId; }
set
{
if (_JobRevisionId != value)
{
_JobRevisionId = value;
IsDirty = true;
RaisePropertyChanged("JobRevisionId");
RaiseEntityChanged();
}
}
}
private int _ReportedByEmpId;
[DataMember]
public int ReportedByEmpId
{
get { return _ReportedByEmpId; }
set
{
if(_ReportedByEmpId != value)
{
_ReportedByEmpId = value;
IsDirty = true;
RaisePropertyChanged("ReportedByEmpId");
RaiseEntityChanged();
}
}
}
private string _Comments;
[DataMember]
public string Comments
{
get { return _Comments; }
set
{
if(_Comments != value)
{
_Comments = value;
IsDirty = true;
RaisePropertyChanged("Comments");
RaiseEntityChanged();
}
}
}
private JobEntity _InfractionJobLocation;
[DataMember]
public JobEntity InfractionJobLocation
{
get { return _InfractionJobLocation; }
set
{
if (_InfractionJobLocation != value)
{
_InfractionJobLocation = value;
RaisePropertyChanged("InfractionJobLocation");
}
}
}
#endregion
}
Using it like this:
private SafetyInfractionEntity originalSelectedInfraction;
.
.
.
private void editInfraction()
{
originalSelectedInfraction= Utilities.DeepCopy<SafetyInfractionEntity>(SelectedInfraction);
InfractionEditMode = EditMode.Edit;
refreshView();
}
It's not copying. Changes to SelectedInfraction also appear in the originalSelectedInfractioncopy.
Anyone see what I'm doing wrong?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
What kind of debugging have you done, and what do you see ?
If you set a break-point in 'DeepCopy at: ms.Position = 0; and examine what's in 'ms: what do you find: what you expected to find ?
Have you experimented with using a non-Generic 'DeepCopy, or, a non-static version, to see if that might make a difference ? What's in originalSelectedInfraction after the DeepCopy: anything ?
« There is only one difference between a madman and me. The madman thinks he is sane. I know I am mad. » Salvador Dali
|
|
|
|
|
From what I can see, there's no way that changes in your original are going to show up in the copy, they are two completely distinct objects.
I'd check where else you are doing this:
originalSelectedInfraction = Utilities.DeepCopy<SafetyInfractionEntity>(SelectedInfraction);
Regards,
Rob Philpott.
|
|
|
|
|
That can only happen due to side-effects of other code which you did not show here. What does happen in the PropertyChanged event handlers? Do you "refresh" some data somewhen from the database?
|
|
|
|
|
Hi everybody,
I am new to c# and have a question that is rather related to wireshark or how to capture messages in plain text sent over the network.
I created a socket server and a tcpclient in c#. I am sending a message like "Here I am" over tcp using the client. The Server answers with a simple string like "Hello". I do this on a local ip address and port 7.
I see the messages in the command line (console), but Wireshark does not show me the text. I am filtering ip.adress source and ip.address dest, but the capture window is empty.
I appreciate any help.
Cheers
Lillepige
|
|
|
|
|
This question has more to do with Wireshark than C#. I suggest you go to their website to see how to use it.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
What does this have to do with C#?
Chances are you didn't capture on the correct interface.
|
|
|
|
|
Install Fiddler.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
If the two apps are both on the same PC it probably is not routed via you NIC (going via 127.0.0.1 which wireshark cannot monitor)- so you cannot see it
Ta
|
|
|
|
|
Hi, I want to create a text file in C sharp at the specified time in a day for e.g., 00:30 am. Pl help.
|
|
|
|
|
What have you tried so far ? Show us some code.
Is your application guaranteed to be running at that time every day ?
« There is only one difference between a madman and me. The madman thinks he is sane. I know I am mad. » Salvador Dali
|
|
|
|
|
Hi, I have been following the below logic in C#
1- Text file is written at a source location continuously with fixed file name and destination.
2- Source needs to replicated at specified interval say 3 mins or more. Reason in case of loss of source file data is not lost as its written at destination path. i.e., replicated.
3- During EOD source file will be moved to backup folder and needs to be created at specified time. Such file backup needs to be retain as per number of files or a days.
4- File at destination should be with the naming convention such as file_YYYYMMDD.
5- Program should be running as service in client machine which needs to be auto start mode.
To start with i have been facing issue in below code for file creation. I have still not created main method.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Security.Permissions;
using System.IO;
using System.Configuration;
using System.Security.AccessControl;
namespace SyncFile
{
class Create
{
public void Sync (string spath, string dpath, string sbpath, string dbpath)
{
String source = ConfigurationManager.AppSettings["spath"];
String target = ConfigurationManager.AppSettings["dpath"];
String bsource = ConfigurationManager.AppSettings["sbpath"];
String btarget = ConfigurationManager.AppSettings["dbpath"];
FileSystemWatcher fsw = new FileSystemWatcher();
fsw.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
fsw.Created += new FileSystemEventHandler(FileCreated);
fsw.EnableRaisingEvents = true;
}
public void FileCreated(Object source, FileSystemEventArgs e)
{
FileSecurity fs = new FileSecurity();
fs.AddAccessRule(new FileSystemAccessRule("spath", FileSystemRights.ReadData, AccessControlType.Allow));
if (!File.Exists("dpath"))
{
//File.SetCreationTime("dpath",(00,01,00));
DateTime fileTime = DateTime.Now;
//File.SetCreationTime("dpath", new DateTime(2014, 4, 3));
File.CreateText("dpath" + "File_"+ DateTime.Now.ToString("ddMMYYYY"));
}
else
{
// Take an action that will affect the write time.
File.SetLastWriteTime("dpath", new DateTime(1985,4,3));
Thread.Sleep (30000);
}
}
}
}
|
|
|
|
|
This is a significant change from your original specific question to many general questions.kanswal77 wrote: To start with i have been facing issue in below code for file creation What issue: where in the code does the issue occur. What error message do you see ?
« There is only one difference between a madman and me. The madman thinks he is sane. I know I am mad. » Salvador Dali
|
|
|
|
|
NO error while debugging but code is not executing as per logic. How can we define file creation in code at the specific time in a day, say at 00:30 am.
|
|
|
|
|
I don't think we'll make progress here until you really tell us what you are doing now, and answer questions people have already asked you, like my question: "Is your application guaranteed to be running at that time every day ?"
At issue here is whether you have have created an application, or a service, that's "always on," or, whether you have run an application that sets up a Windows Task that will execute at the correct intervals. And, what happens if the computer is put to sleep/hibernate, or automatically goes into sleep mode ?
And, what about Nicholas Marty's suggestion to use a batch file ?
CodeProject is your friend: take a look at: "How to create a task in Windows Task Scheduler" [^]
« There is only one difference between a madman and me. The madman thinks he is sane. I know I am mad. » Salvador Dali
|
|
|
|
|
The program is at initial stage. What i am looking is the method of file creation at specific time in c sharp, not using batch file or task scheduler as the program would be running at client PC. Would thankful if some one can share the logic to build the same in code.
|
|
|
|
|
There are many ways (and for some you wouldn't even have to use a c# program)
Solution 1
No need for C#. Create a batch file that you run daily at that specified time using the Task Scheduler. (Windows 7 explanation[^], but something like that exists in basically every OS)
Requirements: The OS has to be running during that time.
Batch-File :
copy /y NUL YourFileName.txt > NUL
Or just write some text into the file. It doesn't actually matter what you write inside your batch script. The Task Scheduler will just execute it.
Solution 2
Again, use the Task Scheduler. Just write your application in c# that outputs something to your text file.
Requirements: The OS has to be running during that time.
Solution 3
Write an Application that is always running. Implement a Timer that periodically checks what time it is. You'll probably need to check if you have already written the file for that day and reset it when you're rolling over to the next day.
Requirements: The OS and your application have to be running during that time.
There are probably many other possibilities depending on what exactly you're trying to do.
Without any information about what you're trying to do, it's basically impossible to recommend you anything. You may get a few ideas from this or you could provide some further details.
|
|
|
|
|
Thanks Nicholas for the possible way of achieving. What i am looking is to create a c# program which would be running at client PC and would be replicating the source file with destination. Currently the program is not completed and is looking for the sample logic where file would be created at destination folder at specific time say 00:30 am every day. If you refer the code, i am trying to use file system watcher for the replication. How to use below in file creation at the specified time.
File.SetCreationTime("dpath", new DateTime(2014, 4, 3));
How to define time in DateTime(2014, 4, 3) function. What would be the logic code ?
|
|
|
|
|
OK, so what's the problem?
|
|
|
|