|
 well am thinking of putting it on a server.
{
public partial class frmNotifier : Form
{
private StringBuilder m_Sb;
private bool m_bDirty;
private System.IO.FileSystemWatcher m_Watcher;
private bool m_bIsWatching;
public frmNotifier()
{
InitializeComponent();
m_Sb = new StringBuilder();
m_bDirty = false;
m_bIsWatching = false;
}
private void btnWatchFile_Click(object sender, EventArgs e)
{
if (m_bIsWatching)
{
m_bIsWatching = false;
m_Watcher.EnableRaisingEvents = false;
m_Watcher.Dispose();
btnWatchFile.BackColor = Color.LightSkyBlue;
btnWatchFile.Text = "Start Watching";
}
else
{
m_bIsWatching = true;
btnWatchFile.BackColor = Color.Red;
btnWatchFile.Text = "Stop Watching";
m_Watcher = new System.IO.FileSystemWatcher();
if (rdbDir.Checked)
{
m_Watcher.Filter = "*.*";
m_Watcher.Path = txtFile.Text + "\\";
}
else
{
m_Watcher.Filter = txtFile.Text.Substring(txtFile.Text.LastIndexOf('\\') + 1);
m_Watcher.Path = txtFile.Text.Substring(0, txtFile.Text.Length - m_Watcher.Filter.Length);
}
if (chkSubFolder.Checked)
{
m_Watcher.IncludeSubdirectories = true;
}
m_Watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
| NotifyFilters.FileName | NotifyFilters.DirectoryName;
m_Watcher.Changed += new FileSystemEventHandler(OnChanged);
m_Watcher.Created += new FileSystemEventHandler(OnChanged);
m_Watcher.Deleted += new FileSystemEventHandler(OnChanged);
m_Watcher.Renamed += new RenamedEventHandler(OnRenamed);
m_Watcher.EnableRaisingEvents = true;
}
}
private void OnChanged(object sender, FileSystemEventArgs e)
{
if (!m_bDirty)
{
m_Sb.Remove(0, m_Sb.Length);
m_Sb.Append(e.FullPath);
m_Sb.Append(" ");
m_Sb.Append(e.ChangeType.ToString());
m_Sb.Append(" ");
m_Sb.Append(DateTime.Now.ToString());
m_bDirty = true;
}
}
private void OnRenamed(object sender, RenamedEventArgs e)
{
if (!m_bDirty)
{
m_Sb.Remove(0, m_Sb.Length);
m_Sb.Append(e.OldFullPath);
m_Sb.Append(" ");
m_Sb.Append(e.ChangeType.ToString());
m_Sb.Append(" ");
m_Sb.Append("to ");
m_Sb.Append(e.Name);
m_Sb.Append(" ");
m_Sb.Append(DateTime.Now.ToString());
m_bDirty = true;
if (rdbFile.Checked)
{
m_Watcher.Filter = e.Name;
m_Watcher.Path = e.FullPath.Substring(0, e.FullPath.Length - m_Watcher.Filter.Length);
}
}
}
private void tmrEditNotify_Tick(object sender, EventArgs e)
{
if (m_bDirty)
{
lstNotification.BeginUpdate();
lstNotification.Items.Add(m_Sb.ToString());
lstNotification.EndUpdate();
m_bDirty = false;
}
}
private void btnBrowseFile_Click(object sender, EventArgs e)
{
if (rdbDir.Checked)
{
DialogResult resDialog = dlgOpenDir.ShowDialog();
if (resDialog.ToString() == "OK")
{
txtFile.Text = dlgOpenDir.SelectedPath;
}
}
else
{
DialogResult resDialog = dlgOpenFile.ShowDialog();
if (resDialog.ToString() == "OK")
{
txtFile.Text = dlgOpenFile.FileName;
}
}
}
private void btnLog_Click(object sender, EventArgs e)
{
DialogResult resDialog = dlgSaveFile.ShowDialog();
if (resDialog.ToString() == "OK")
{
FileInfo fi = new FileInfo(dlgSaveFile.FileName);
StreamWriter sw = fi.CreateText();
foreach (string sItem in lstNotification.Items)
{
sw.WriteLine(sItem);
}
sw.Close();
}
}
private void rdbFile_CheckedChanged(object sender, EventArgs e)
{
if (rdbFile.Checked == true)
{
chkSubFolder.Enabled = false;
chkSubFolder.Checked = false;
}
}
private void rdbDir_CheckedChanged(object sender, EventArgs e)
{
if (rdbDir.Checked == true)
{
chkSubFolder.Enabled = true;
}
}
private void frmNotifier_Load(object sender, EventArgs e)
{
}
}
}
thats a full code of filemonitor i found online.
am trying to edit it in such a way that when i click the exe file it already starts checking the files, without having to click the start button and stop button.
|
|
|
|
|
Like I said, write it as a windows service, and it can just sit there watching the file/folder without any user interaction at all.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
thanks, so am new to programing, how can i write it as a windows service? sorry for asking too much,
|
|
|
|
|
0) I suspect that you don't have the requisite skillset to handle it. Windows services require a more intimate knowledge of how Windows works.
1) The act of writing a Windows service cannot possibly be covered on a programming forum. However, CodeProject has many dozens of articles that can show you the basics.
2) As a new developer, if you learn nothing else, learn this - google is your friend. If you don't learn how to use google, your development career will be less than stellar. Here's a Microsoft site that explains how to write a Windows service. I found it with google.
Walkthrough: Creating a Windows Service Application in the Component Designer | Microsoft Docs[^]
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
modified 2-Feb-18 6:59am.
|
|
|
|
|
Sort of. All you can guarantee is that, at some point, you should be able to make the application stop. The reason that I'm being cagey about this is because you can't exactly guarantee the point at which an operation is going to be run on a computer because there might be other tasks running that push your timing slightly out.
This space for rent
|
|
|
|
|
thanx, for example its a file checker, with start and stop function, at a specific time i would like it to stop and restart agin, while the app is still on. is there code i can view to help me with this
|
|
|
|
|
how to create the image button using asp.net program and how to browsing the image?
|
|
|
|
|
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
And we have no idea what you have tried, where you are stuck, or what help you need. Heck, we don;t even know what you mean by "how to browsing the image?"
So tell us these things! Help us to help you.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
// the code below works for reading the header, but what is the extension method for reading the footer ?
Word.Range range = selection.HeaderFooter.Range;
string HeaderText = range.Text;
|
|
|
|
|
|
Here's a weird one.
I have a class library assembly with the following (pseudo)code:
namespace MyStaticNameSpace
{
public static partial class MyStaticClass
{
public static void MyMethod1()
{
}
}
}
In my (MVC web) application (that references the assembly described above), I have this:
namespace MyStaticNameSpace
{
public static partial class MyStaticClass
{
public static void MyOtherMethod()
{
MyMethod1();
}
}
}
My problem is that the code in the app can't see MyMethod1 in the library assembly. What am I missing?
I event tried using "MyStaticClass.MyMethod1(); "...
When I try to reference methods in MyStaticNameSpace.MyStaticClass from anywhere else in the app, it sees all methods in both the assembly and the local namespace extension.
If I rename the app's class to something other than MyStaticClass, I can then do this - MyStaticClass.MyMethod1() , but that defeats the purpose of making the class partial.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
modified 30-Jan-18 9:43am.
|
|
|
|
|
John Simmons / outlaw programmer wrote: What am I missing? The fact that they're two completely different classes.
You can only use partial to split a class into different files within the same project.
Partial Classes and Methods (C# Programming Guide) | Microsoft Docs[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
So I'm missing most of my cerebral material this morning. :/
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
I'm new to the unit-testing world and want to know how I can improve and write better tests 
|
|
|
|
|
Buy a book on the topic, find tutorials, and practice.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Any recommended book? 
|
|
|
|
|
|
|
You're welcome
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
I have been researching a solution to this and have not found an answer so I thought I would ask it here.
I have an application that derives from System.Windows.Forms.TreeNode for a few of the classes. I want to create a "lockable" tree node for the base nodes of my tree which ensures that programmers don't accidentally (or purposefully) modify the nodes once they are "locked" because the base nodes are "immutable" while the rest of the tree is not. However, since I cannot derive from TreeNodeCollection and there is no c# equivalent of the C++ const method contract (that I have been able to find for properties), I am having trouble coming up with a way to prevent the following from happening:
someInstanceOfMyLockableTreeNodeClass.Nodes.Add("newNode")
The only thing I can think of is possibly hiding the original Nodes Property (using the new keyword) with a less accessible one (if that would even work). The problem is that I would no longer be able to access the node indexer either... so I would have to create a less intuitive wrapper for that as well. Is there a different approach that I could use?
|
|
|
|
|
You'd have to write your own. If you make the TreeNodes private, I'll simply use reflection to add my nodes (not accidentally, ofc).
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Before I switched to using the Integral UI TreeView (Lidor Systems) [^], I used the following strategy to wrap the native WinForm TreeView in a way that let me do multiple selection:
1. a UserControl 'TreeXHost in which a WinForm TreeView 'WFTree is docked 'Full: 'WFTree is set to DrawMode 'OwnerDrawText. WFTree is declared 'private.
1.a when 'TreeXHost loads: the instance of the WinForm TreeView, is passed into a class 'TreeX, a pretty standard tree implementation.
2. in 'TreeX : event handlers are wired up for all the TreeView events
2.a a variety of Dictionaries and Lists were used to keep track of state and enable custom node (not inheriting from WF TreeNode) <=>to WF Node lookup:
public Dictionary<string, Node> AllNodes { set; get; }
public Dictionary<string, TreeNode> AllTreeNodes { set; get; }
public Dictionary<TreeNode, Node> TNodeToNode { set; get; }
public Dictionary<Node, TreeNode> NodeToTNode { set; get; }
public List<Node> DisabledNodes { set; get; }
public List<Node> SelectedNodes { set; get; } So the basic idea was to isolate the WinForm TreeView completely, and present an API to use that behind the scenes inter-oped with the WinForm TreeView.
There were several reasons I chose not to sub-class the WF TreeView or TreeNode: of course, the issue/danger of exposing the "can't inherit from" TreeNodeCollection; the need to add some complex annotations to each node; ease of writing a serialize/deserialize facility, etc.
Yes, indeed. it got tricky: I ended up canceling every WF TV Event I could in the 'Before... Event Handlers; in the DrawNode Event you need to color the Node, or otherwise alter the TreeNode appearance based on its state. A design issue was whether disabling/enabling a Node with a non-empty TreeNodeCollection should recursively disable/enab;e every Node "under" it: I decided that was necessary. Not to mention issues of drag-drop
It got so tricky I went looking for a 3rd. party Treeview that I could afford ... and, I found the IntegralUI TreeView that was (and, still is) quite remarkable
Hope this is helpful.
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
modified 4-Feb-18 1:09am.
|
|
|
|
|
Thanks for the info! It was helpful for future reference. For my current solution, I decided to use the hiding technique after evaluating my code and realizing I was over-complicating what I needed to do (due to having a separate artificial "node" class where I didn't need one).
But yeah... the capabilities of your link look promising if I need a more robust tree in the future. I am curious about the filtering though. Do you know if the filtering capabilities allow for you to hide or show nodes of a certain type?
|
|
|
|
|
@primem0ver One further comment:
If you implement, as I described, a kind of parallel tree class which manages an internal WF TreeView, then hiding Nodes is relatively simple, but:
The trade-off is that you'll have to re-render the WF TreeView every time you hide nodes, or show hidden nodes: imho, depending on frequency of hide/show calls, and your hardware, that might result in lower performance.
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
|
|
|
|
|