|
This is usually the way to do it.
If you generalize it slightly, it may not always work: Especially if we are talking about a hardware level handler, reacting to interrupts, the interrupt handler may have access to hardware registers etc. that you cannot access from an ordinary background level (or whatever it is called in your local lore). The interrupt handler may have access to both physical registers, privileged instructions and protected memory that user code does not.
The handler may call a user space/level function accessible to application code as well, but information provided to this function may come from a privileged context. You may or may not be able to provide valid "fake values" from your user level context. Also, operations performed by this extracted function may require hardware privileges not available in a user level context.
|
|
|
|
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Speech;
using System.Speech.Synthesis;
using System.Speech.Recognition;
using System.Threading;
using System.Diagnostics;
namespace PC_AI_BOT_2020
{
public partial class Form1 : Form
{
// form declarations...
SpeechSynthesizer ss = new SpeechSynthesizer();
PromptBuilder pb = new PromptBuilder();
SpeechRecognitionEngine sre = new SpeechRecognitionEngine();
Choices clist;
public Form1()
{
InitializeComponent();
}
private void Btnstart_Click(object sender, EventArgs e)
{
// start (button_click)
btnstart.Enabled = false;
btnstop.Enabled = true;
clist.Add(new string[] { "hello", "how are you", "what is the current time", "open crome", "thanks you", "close" });
Grammar gr = new Grammar(new GrammarBuilder(clist));
try
{
sre.RequestRecognizerUpdate();
sre.LoadGrammar(gr);
sre.SpeechRecognized += Sre_speechrecognized;
sre.SetInputToDefaultAudioDevice();
sre.RecognizeAsync(RecognizeMode.Multiple);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "error");
}
}
void Sre_speechrecognized(Object sender, SpeechRecognizedEventArgs e)
{
switch (e.Result.Text.ToString())
{
case "hello":
ss.SpeakAsync("hello marcus");
break;
case "how are you today":
ss.SpeakAsync("i am doing grate marcus how about you");
break;
case "wht is the current time":
ss.SpeakAsync("current time is " + DateTime.Now.ToLongTimeString
());
break;
case "thank you":
ss.SpeakAsync("pleasure is mine marcus");
break;
case "open crome":
Process.Start("crome", "http;//www.google.com");
break;
case "close":
Application.Exit();
break;
}
txtcontents.Text += e.Result.Text.ToString() + Environment.NewLine;
}
private void Btnstop_Click(object sender, EventArgs e)
{
// stop (button_click )
sre.RecognizeAsyncStop();
btnstart.Enabled = true;
btnstop.Enabled = false;
}
}
}
|
|
|
|
|
What error?
What does it do that you didn't expect, or not do that you did?
What have you tried to do to find out why?
Are there any error messages, and if so, where and when? What did you do to make them happen?
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 if you get a problem with Youtube code, then two things spring to mind:
1) Talk to the idiot who posted the tutorial: it's his code, he should know how it works. He probably won't, as most Youtube tutorials are produced by people who have no idea what they are doing, but at least it warns others ...
2) If code doesn't work, start with the debugger and see what is going on while it is running.
But just posting a chunk of random code and saying "it doesn't work" when we have no idea what it is supposed to do in the first place is an exercise in futility ...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
What error?
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
Quote: Let me know best practices for audit data handling.
|
|
|
|
|
Better than what?
we have no idea what you are doing, or how you are handling it at the moment, so we couldn't begin to compare practices if we wanted to ...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Write triggers or use the transaction log.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
The best practice is to do it correctly. So use Google to find samples and tutorials on the subject and study them closely.
|
|
|
|
|
Richard MacCutchan wrote: The best practice is to do it correctly. Can you back up that opinion with any fact?
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
|
Hello.
My Name is Ko.
I want to make mapping drive use ftp/sftp.
What kind of dll can help me?
I used dokan, but I failed.
So. I find cNetworkDrive.
[https://www.codeproject.com/Articles/6847/Map-Network-Drive-API]
But this project has only share folder.
Help me plz.
|
|
|
|
|
You can't map a FTP link to a drive: they use different protocols.
To access an FTP link, you need to use an FTP client - I use FileZilla[^]
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hi.
I used FileZilla.
But I want to make something similar to NetDrive.
I need mapping network drive.
|
|
|
|
|
|
It doesn't exist. You cannot map a drive to a FTP server. FTP doesn't speak the same protocols used by any file system Windows supports.
|
|
|
|
|
Well,
There are some new features in Windows 10 that actually allow you to mount a remote filesystem. The 'Cloud' filesystem is protocol agnostic. So you could easily implement this with FTP, HTTP, Bittorrent or whatever.
Windows Projected File System (ProjFS)[^]
There is also a managed API for this feature[^].
Best Wishes,
-David Delaune
Edit:
I just want to add that you can enable this feature via powershell with:
Enable-WindowsOptionalFeature -Online -FeatureName Client-ProjFS -NoRestart
modified 14-Oct-20 2:23am.
|
|
|
|
|
Well that's new. Learn something new every day.
|
|
|
|
|
Randor wrote: The 'Cloud'
Dave Kreskowiak wrote: Well that's new. Learn something new every day.
Old Man Yells At Cloud[^]

|
|
|
|
|
hello,
I'm creating an application that reads data from a PLC and writes it into a database.
In my GUI the user can select which data he wants to log into the database, but I'm wondering how to solve this.
sometimes the user wants to log only one item in the database :
INSERT INTO myTabel (name_data1) VALUES ("123")
but other times I must be able to choose more data :
INSERT INTO myTabel (name_data1, name_data2, name_data3) VALUES ("123", "456", "789")
how would I code this? The column names name_data1, name_data2, name_data3, ... in my database should be able to change according to which data is chosen
for this purpose I use a list of 2 strings
["name_data1", "123"],
["name_data2", "456"],
["name_data3", "789"]
so the problem also is that I do not know how the table will look like at the moment I insert the data, it all depends on which data the user chooses to be inserted into the database
|
|
|
|
|
Hi,
you can create a table and add columns to it when the need arises, however that would be bad design for several reasons; the table structure would be unpredictable, it would probably be very sparse (most fields remain empty), and processing it could be quite cumbersome.
I'd suggest you use a very simple table with essentially two columns, say my_key and my_value , both string.
Your example
["name_data1", "123"],
["name_data2", "456"]"
["name_data3", "789"]
would then sit in three rows, exactly as you described it yourself!
Of course you might want to also provide a primary key, a created timestamp, and maybe a creator field.
If the data entered is related, you need some kind of parent field or group field, so you can indicate how the records belong together.
I certainly advise you to create some processing code before deciding your final table structure, so you don't paint yourself into a corner.
Luc Pattyn [My Articles]
If you can't find it on YouTube try TikTok...
|
|
|
|
|
The problem is that "expanding tables" is a pain - or you waste a huge amount of space on many rows if they don't want to store much.
Instead, I'd use a number of tables:
Master
ID INT, IDENTITY this ties all the other data for the row together. You may want other columns, but only if they will always be needed.
RowDesc
ID INT,IDENTITY
DataType NVARCHAR This holds the types of data the user may select
RowData
ID INT, IDENTITY
MasterID INT, FOREIGN KEY to Master.ID
RowID INT, FOREIGN KEY to RowDesc.ID
VALUE Your type for the data
When your user inserts a row, it creates a row in MASTER, and as many rows as necessary in RowData
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Further to the very sound advice given by @OriginalGriff and @Luc_Pattyn, you need to know what type of data you are collecting. Are all of the values strings / numbers or a mix of strings, numbers, dates etc? Your sample has numbers masquerading as strings. As a general principle, saving non-strings as strings is a bad idea. If you have a limited set of data types, you could consider extending the simple Key / Value pattern to Key / DataType / ValueIfString / ValueIfNumber / ValueIfDate. This would mean you would be returning to a limited version of the waste space issue that the others have warned you about and is a solution that I would try to avoid. Anything that deals with non-homogeneous data is awkward; if it is homogeneous (e.g. all values are string or all values are numbers) then the methods given by @OriginalGriff and @Luc_Pattyn are preferred.
|
|
|
|
|
This is a genuine "why" question (as in the technical reason why the language prohibits what I want to do) rather than a "how do I get round the limitation?"*
I'm writing a WPF app and implementing a base class for a Command . The base implementation contains common logic to a set of subclasses which must have the Database connection in a non-busy state before they can execute. If the busy state changes, calling CanExecuteChanged?.Invoke(this, e); is naturally fine in this base. The problem is I have secondary conditions in the subclasses which also prevent execution - on those conditiond changing I'd want to call CanExecuteChanged?.Invoke(this, e); from the subclass - this isn't allowed and I can't work out the reasoning.
My current working theory is the even is like syntactic sugar over a delegates (or something) and the part to raise the event is private (which would prevent raising outside the base class) the whereas the subscription side is public (so you can subscribe from an unrelated type).That doesn't explain why the "raise" part isn't protected, or somehow optionally private/protected. There is a gap in my knowledge somewhere.
- I have a couple of solutions for this: like exposing the delegate with a backing field and calling that, or the one I'll probably adopt which is to expose a protected event to raise the event seems more explicit.
|
|
|
|
|
The technical reason is fairly simple. When you declare an event:
public class Foo
{
public event EventHandler Test;
} the compiler actually generates two members:
public class Foo
{
[CompilerGenerated]
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private EventHandler Test;
public event EventHandler Test
{
[CompilerGenerated]
add
{
EventHandler eventHandler = this.Test;
EventHandler eventHandler2;
do
{
eventHandler2 = eventHandler;
EventHandler value2 = (EventHandler)Delegate.Combine(eventHandler2, value);
eventHandler = Interlocked.CompareExchange(ref this.Test, value2, eventHandler2);
}
while ((object)eventHandler != eventHandler2);
}
[CompilerGenerated]
remove
{
EventHandler eventHandler = this.Test;
EventHandler eventHandler2;
do
{
eventHandler2 = eventHandler;
EventHandler value2 = (EventHandler)Delegate.Remove(eventHandler2, value);
eventHandler = Interlocked.CompareExchange(ref this.Test, value2, eventHandler2);
}
while ((object)eventHandler != eventHandler2);
}
}
} Inside the same type, you will either reference the private field (for assignment, Invoke, etc.) or the event (for adding and removing handlers). The compiler will decide which.
Outside of the class, you only have access to the event. All you can do is add or remove a handler.
I believe this is to prevent other classes from raising events without the cooperation of the base class, or swapping out the entire list of handlers. But obviously you'd need to ask the original language designers to know their reasoning.
Of course, the simple workaround is to provide a protected method in the base class which raises the event on demand.
protected void OnTest(EventArgs e)
{
Test?.Invoke(this, e);
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Oh wow thanks, that's exactly what I was hoping for. It's also along the the "syntactic sugar" line of thinking. I've been off C# as my main work for 4/5years now so I'm getting to grips with it all again. I won't utter the name of the language I have been principally using, but it rhymes with Lavascript
|
|
|
|
|