|
note: this is not about AOP, IL weaving, Furty, PostSharp, etc., although those facilities are related to this discussion.
Context: in WinForms both these notification methods have, imho, very limited uses.
Do you use these mechanisms more frequently in WPF ? Are they valuable to you ? Essential/integral in MVVM ?
Have you ever developed your own notification-with-cancellation mechanism (i have, for WinForms).
0) there's an excellent overview of how INotifyPropertyChanged can be used in different C# versions by SO's resident genius, Marc Gravell: [^]
1) INotifyPropertyChanging has no cancel mechanism ... unless you consider throwing an error in some context you have no control over sweet-smelling code According to PostSharp docs: "INotifyPropertyChanging interface is not portable (in Xamarin, it is even a part of a different namespace)."
2) INotifyPropertyChanged is just post-facto notification. There does appear to be a special benefit in using it with SQL and Linq: [^] ... i've never played with that.
Of course, you could trigger update of a binding connection. And, using Caller Information Attributes is easy in a Notify* changed handler ... imho, those attributes are of very limited value.
3) through "heroic" programming, you can create custom EventArgs that inherit from the INotify* versions and extend them to implement cancellation. however, in your subscribing objects' handlers you will have to cast the incoming args to their extended form.
there's an outstanding 2 article series here on CP from 2007: [^] that shows this kind of EventArgs extending as a way to get cancellation.
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
modified 7-Jun-21 22:00pm.
|
|
|
|
|
BillWoodruff wrote: Do you use these mechanisms more frequently in WPF ? Hardly done any WPF.
BillWoodruff wrote: 1) INotifyPropertyChanging has no cancel mechanism ... unless you consider throwing an error in some context you have no control over sweet-smelling code According to PostSharp docs: "INotifyPropertyChanging interface is not portable (in Xamarin, it is even a part of a different namespace)." Cancelling an update would be exceptional, and not the rule. Never tried Xamarin; Mono is enough for me.
BillWoodruff wrote: 2) INotifyPropertyChanged is just post-facto notification. There does appear to be a special benefit in using it with SQL and Linq: [^] ... i've never played with that.
Of course, you could trigger update of a binding connection. And, using Caller Information Attributes is easy in a Notify* changed handler ... imho, those attributes are of very limited value. Dunno, never tried; I like close control over my queries.
BillWoodruff wrote: 3) through "heroic" programming, you can create custom EventArgs that inherit from the INotify* versions and extend them to implement cancellation. however, in your subscribing objects' handlers you will have to cast the incoming args to their extended form. Why would you, if it is already there? Exceptions aren't that expensive.
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Thanks for you thoughts ! A major use of cancellation+notify code is to implement external validation on a per instance basis for your class. The multi-cast event driven technique enables external subscribers to define the validation code and/or the actions taken if validation passes or fails.
imho, locating responsibility for validation/data integrity outside the class can be seen as a "separation of concerns" strategy.
Of course, you could implement validation as a singleton within the class, so all external consumers are using the same validation.Eddy Vluggen wrote: Cancelling an update would be exceptional, Every time you use some validation method, potentially, cancelling an update can occur.Eddy Vluggen wrote: Exceptions aren't that expensive. When you allow external clients to inject executable code, potentially any of those clients could crash their code by throwing an error: meanwhile, back at the ranch, the calling class' code is waiting ...
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
modified 8-Jun-21 20:37pm.
|
|
|
|
|
BillWoodruff wrote: Every time you use some validation method, potentially, cancelling an update can occur. Yes, but that'd be exceptionally, not the rule.
BillWoodruff wrote: When you allow external clients to inject executable code, potentially any of those clients could crash their code by throwing an error: If you allow external clients that, you got a bigger problem on your hands and them throwing an exception is not the most dramatical consideration.
During classes, we considered all humans interacting with the systen to be potentially evil. It kinda sticked; you prepare for the worst.
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
I'll add to Eddy's information, except as applies to WPF.
This is probably the simplest view, but I use INotifyPropertyChanged for program properties that are bound to screen controls. When the program is changing the value rather than the user it lets you update the value whenever you like, and the screen updates naturally. The benefit of doing things this way is that the relationship between the property and the control is defined by the binding, so that it works the same everywhere. You don't have to worry about changing update code wherever you change the value.
I'll admit I don't particularly like the binding mechanism. It's complex and expressing bindings directly in XAML can be an exercise in frustration. I set most of my bindings in the C# code-behind because the XAML syntax is so awkward.
Software Zen: delete this;
|
|
|
|
|
Thanks, Gary, that's the type of reply i hoped i'd get !
i never explored binding in Win Forms beyond DataSet to Grid. List to ComboBox.
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
Glad to be of help.
In its way binding is very useful. It lets you handle conversions between the on-screen depiction and your internal representation consistently. For data entry you can add your own validation rules and integrity checks.
One caveat to my statements. I don't do data base applications so I'm not familiar with more elaborate bindings, say between a data base table and a grid control. I imagine there are quite a few articles here on CP and examples in the wild that can help if you need it.
Software Zen: delete this;
|
|
|
|
|
This is sort of a "What would you do in this situation" post.
Our company has had a Windows program in use for many years since VB6.
The short description is that this program collects data points. It also makes use of DDE to make that information available to Excel. The user enters the server and topic in an Excel cell and gets the value from our program or can set a new register to monitor.
I have been asked to update the program to .NET and add some features. I am doing this is C#.
DDE is of course outdated and I have been trying other alternatives OLEDB / Interop and such.
The problem is that management wants all of the configuration to be on the Excel side so that its stored with the worksheet. (As it had been previously). For example my program shouldn't put a value in a specific cell. Rather it should behave like the DDE example did. and it shouldn't be using VBA to call the program via dlls or anything as the customer won't have access to that.
My background is not primarily .NET and I don't do much with OLE/COM/Interop ect.
I have been reading as much as I can and I have gotten to the point that if I know what cells to work with from the C# side I can get most of the functionality I want. However I have no idea how I would make this work such that the customer can specify everything about the shared data on the excel side.
Any thoughts? How would you approach a solution?
Edit: Edited to try to clarify that the management is really just trying to retain the functionality that the previous software versions had via DDE. As a developer I am trying to determine the best solution knowing DDE is obsolete. As of yet I haven't been able to find a newer technology that will meet the specific requirements of this tool. Its not a contentious situation or anything like that and I have no issues speaking up when I don't believe things make sense.
So really the question should be rephrased as.... "How would you approach a technical solution?"
Regards,
modified 10-Jun-21 23:34pm.
|
|
|
|
|
So your company wants you to create a solution in Excel but will not allow you to use VBA (or the current scripting language). Management straight out of the 1980s.
You may be able to launch the c# app from a button in the excel sheet, you can also use c# as the scripting language behind the sheets (it is no VBA after all )
I think there may be events available on the cell (onleave maybe) which may be used to access the code behind.
I also think there are excel clones that can be embedded into a c# winforms app that looks and feels like excel that hooks in all the usual events so you can use c# to do the work.
I would stronly recommend telling management that they are shooting themselves in the foot!
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
Love the username Mycroft. and the 1980s comment.
The spreadsheets in this case would generally be setup by the customer using our equipment. Our prior app just acted as a server. At the moment the argument is that all of my solutions are too complicated for the customer or won't save with the excel file. Its for industrial customers not the typical office user.
I thought I might be able to get away with automation and maybe referencing by named ranges. I haven't been able to get it to work from the C# app trying to use named ranges though. Not without the app
already knowing what they are.
Believe me. They have heard my complaints. This is a rarely used feature but they insist it still needs to support it without changing it much. I may have to wind up using DDE (NDDE maybe?) though I would really rather not.
Thanks for the suggestions.
|
|
|
|
|
eremitic19 wrote: The problem is that management wants all of the configuration to be on the Excel side Yup. That's the problem.
And what made those managers such specialists that they get to decide about a technical problem?
eremitic19 wrote: How would you approach a solution? I'd be asking management what qualifies them to dare bring solutions to the table.
And yes, not going to make you popular, but that's what I'd do, since that's what they paying me for.
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
I have an application that receives messages from a network that describe object events and status (think of a CAN Bus data logging type of application).
My plan is to record 'change' events (actual change as opposed to re-transmit) to disk along with 'key frames' (status of all objects) to allow later playback of the data. Data format is not predetermined. I'll work with whatever is the best fit.
I am looking for code that would support playback controls such as 'play', 'pause', 'rewind', 'start playing at <time>', 'fast forward', etc.
My searching of the web gets me lots of things having to do with audio and video playback but nothing in the area of arbitrary data playback.
I can 'roll my own' but a head start would be helpful.
Thanks in advance for your thoughts ...
|
|
|
|
|
You need to be more specific about what you mean by "arbitrary data playback". A system restore involves a "pause, rewind and play" (but there's nothing to see).
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
To be more specific ...
My application is a signal system I have designed for "Ride On Railroads" (7.5" gauge typically here in the USA).
The system consists of controller nodes distributed around the railroad. Each of these nodes detects track occupancy, calculates which train should be permitted to proceed and sets signals accordingly.
All of this data (track occupancy, signal head settings, etc.) is broadcast on a single CAN Bus in real time.
There can be one or more PCs attached to the network for monitoring and control (NOT control of train movements, that's totally done by the controller nodes).
One of the things the PCs support is display of train movements to passengers as well as one or more dispatchers.
I want to record this CAN Bus data as a stream of 'change' events as well as periodic "key frame" records to a disk file. The key frame record records the current status of every object (track, signal, etc.) on the railroad. Thus, starting at a 'key frame' and proceeding forward in time you have a time record of everything that happened on the railroad.
I want to be able to switch the display screen from the 'live data stream' (what is currently happening on the railroad) and display what happened at an earlier time ... i.e.: replay the railroad activity.
So, I need to be able to support things like "play back the data stream from 5pm yesterday", etc.
This is done all the time with audio and video streams but I have not been able to find any examples of code that will do it for an arbitrary stream of data.
I also need to decide the file format that would be efficient for recording the data stream and allows somewhat random read start points. Least efficient, but would work, would be for me to just do a 'binary search' in the file by picking a point in the file and scanning for a key frame, check the time, and jump forward or backward depending on the result of the comparison. No complicated indexes needed. Writing of the stream to disk is a MUCH more frequent activity than read so writing needs to be optimized over reading/playback.
It's kind of like a data acquisition system that gathers a stream of data and you want to be able to play it back from an arbitrary point.
Again, I can roll my own but figured it was worth checking to see if something existed that was close to my needs but all my searches only show up tools for audio or video.
As an aside: forward seems easy, skip back "x seconds" is harder/less efficient.
For more information on the system in general see: http://www.minirailsolutions.com[^]
In this document is an example of the track display: SComm | MiniRailSolutions – Automatic Signals For Ride-on Railroads[^]
|
|
|
|
|
I've never heard of any such tools, probably because of the infinite nature of "arbitrary data".
|
|
|
|
|
"Play back" then simply depends on the "player" having a proper interface; i.e. the same one for real-time playing and historical.
In real-time, you add to a concurrent queue (enque / dequeue) AND a concurrent serial log (append). The real-time "playing" uses the "real-time" queue.
In play-back, you load what you want to the "play-back" queue (a reference) from the serial log, and a new instance of the player runs off of that.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
What format is the data in? Can it be stored into a database in a sequential manner? If so the do as Bill suggested and divorce the real time (which should be recording the data into a database) process and the play back process.
If the data can be stored in a database then play back is a trivial matter.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
I would separate out the task of display of real-time "live" continuous state information from the task of doing a kind of animated slide-show starting from an initial state (key-frame). I think different strategies would be involved: streaming vs. moving back or forward in time in a data store.
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
Thanks to all for the feedback. I am going to reexamine the amount of data involved and the expected frequency of recording .vs. playback to see if it warrants a database approach or another approach.
Thanks to all.
|
|
|
|
|
Hi,
We have a C# windows forms application and I need to work with MS Word files to replace some text, table rows content, or add a new rows to an existed table, we need to know the best way.
I tried using Microsoft.Office.Interop.Word but this way may be old and must use the same office on the all pc's you install the application on it, if you use the MS Office 2007 then you must install it on any PC will use the application.
Please let me know the best way, tools to do that.
Thank You
|
|
|
|
|
Basically, interop is pretty much your only real way - but using Word as a storage medium is the real problem!
There are various libraries that claim to do it - Google found this which lists a few: Reading doc and docx files using C# without having MS Office installed on server - Stack Overflow[^] - but I've not tested any.
Personally, I'd look for a better file format - there is no guarantee that what you read today will stay the same format tomorrow if MS decide to "add features".
"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!
|
|
|
|
|
If you can use the newer Office formats, you can use the OpenXML SDK to work with the files without having Office installed.
|
|
|
|
|
Interop is the only real method of updating Word. We had to make sure ALL users were on EXACTLY the same version of Word to use the application. It was updating legal documents that had to read exactly correctly and turned out to be one of the most painful operations I have ever had to do.
If you cannot control the version of Word on all clients then you have a serious problem.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
|
If you wanted to write a query that contains 'IF' clause, how would you do it?
Please revise this query:
mycommand.CommandText = "IF EXISTS(SELECT * FROM [MyData] WHERE NOT Wo = 'ABC' OR Code = 1200)";
If above statement satisfied:
INSERT INTO[MyData] VALUES('New001', 768353)";
|
|
|
|