-
I'm working on a C# console/winforms desktop app using .NET Framework 4.7.2. It monitors some local drive properties and displays a status message. Status message display is executed via Task Scheduler with the task programmatically defined and registered (using your very much appreciated NuGet package). XmlWriter/StringBuilder generates Trigger and Action code. I’ve got everything working except Action Arguments. ==> This bit works
This code with a Command peer Element added for Arguments
Throws a runtime Exception: Token EndElement in state EndRootElement would result in an invalid XML document. And with this code
The task is created but won't run. I've also tried:
But it doesn't get registered; just seems to be ignored. I also tried commenting out the XML Action block in an attempt to use the td.Actions approach but that errored out on "foreach (var line in GETXML) td.XmlText = $"{line.XMLcode}";". After uncommenting the XML Action block the code (without Arguments) again ran fine. Any assistance will be much appreciated. EDIT:
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
@ArtHansen Why are you trying to manipulate the XML? You can, of course, create an XML stream and then register it using |
Beta Was this translation helpful? Give feedback.
-
To get lists of those enum values and their corresponding names, I have done the following: // Get MonthsOfTheYear values and current culture names for each month
var monthValues = Enum.GetValues(typeof(MonthsOfTheYear)).Cast<MonthsOfTheYear>().Take(12).ToArray();
var monthNames = monthValues.Select(v => TaskEnumGlobalizer.GetString(v)).ToArray();
|
Beta Was this translation helpful? Give feedback.
-
Here's a little snippet to demonstrate a little more elegant solution: public class Element<T>
{
public Element(T value, string text) { Value = value; Text = text; }
public T Value { get; set; }
public string Text { get; set; }
public bool Selected { get; set; }
public override string ToString() { return Text ?? ""; }
}
public static void Main()
{
// Build a list of elements with the enum values and their localized text values
List<Element<MonthsOfTheYear>> months = Enum.GetValues(typeof(MonthsOfTheYear)).Cast<MonthsOfTheYear>().Take(12).Select(v => new Element<MonthsOfTheYear>(v, TaskEnumGlobalizer.GetString(v))).ToList();
// TODO: Use 'months' to populate UI and set the 'Element<T>.Selected' property, like following
months[0].Selected = true;
months[6].Selected = true;
// Get the accumulated value of all selected elements
MonthsOfTheYear moty = months.Where(m => m.Selected).Aggregate((MonthsOfTheYear)0, (r, m) => r |= m.Value);
} |
Beta Was this translation helpful? Give feedback.
-
Also, consider using the |
Beta Was this translation helpful? Give feedback.
Here's a little snippet to demonstrate a little more elegant solution: