Use ObjectListView For A Logbook With An XML File - c#

I'm creating a logbook application that allows you to create data fields for logbook entries and uses an ObjectListView to display the data. However, this presents a problem. Since field names can change from logbook to logbook, I can't write a single class to deal with the presentation of logbooks.
The application will use an XML format like this:
<entry date="2/18/2014">
<field name="hours" type="int" value="3" display="Hours Used"/>
<field name="gallons" type="double" value="6.8" display="Gallons Used"/>
<filed name="comment" type="string" value="..." display="Comment"/>
</entry>
How can I turn an XML file like the above into data that an ObjectListView can display?

Related

EPPlus - Update Custom Ribbon Elements

I have a excel file which contains several items in a custom ribbon. I've added these custom elements with Microsoft's "Custom UI Editor for Microsoft Office", my customization looks something like the following:
<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
<ribbon>
<tabs>
<tab id="XXX" label="XXX" insertAfterMso="TabInsert">
<group id="YYY" label="YYY">
<button id="btnXXX"
label="XXXX"
imageMso="PivotTableNewStyle"
size="large"
onAction="ZZZZ"
screentip="XXX"
supertip="XXX" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>
I would like to modify(Add remove elements, change elements) this header with EPPlus, is this possible? If so how would it be done?
I have not found a way to do this in EPPlus, but I have found a way to edit it with the "DocumentFormat.OpenXml" library. Specifically to access that portion of the file I use the following code:
((SpreadsheetDocument)document.WorkbookPart.OpenXmlPackage).RibbonAndBackstageCustomizationsPart
I'm still not sure if it can be done in EPPlus. Maybe in a future version...

How can one set minimalist interface of Excel with C#?

Using C#, I'm writing a program that has to use Excel only in order to edit some tabular data provided by my program. My program just creates an Excel application (the Microsoft.Office.Interop.Excel.Application object), creates within it a workbook, creates a worksheet, puts the data in Excel, and, after this, allows to a user to edit these data. The edited data can be easily read by my program. That's, in principal, all what I need from Excel.
This, therefore, means that a user of my program should not be able to format data in Excel, save an Excel file to the hard drive, open Excel files, and so on and so on. A user even does not need the Excel ribbon. Working with formulas is also does not required. Hotkeys (like "Ctrl + B" making the font bold, "Ctrl + S" saving the file, and so on) should be also not workable.
My question is: Is there a way to simply set such a minimalist interface for Excel? Or I should disable any aspect mentioned above by hand, step by step (disable the ribbon, switch off the hotkeys ans so on)?
When working within a VSTO project, you can disable most/all of the UI by using a custom ribbon XML file (there is a visual designer too but I doubt it would be sufficient for this).
To remove things, add a section for what you're removing, and set visible="false" or enabled="false" (users could still potentially add it back to the ribbon, but disabling it makes it grayed out).
e.g.:
<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
<commands>
<command idMso="Cut" enabled="false" />
</commands>
<ribbon>
<tabs>
<tab idMso="TabHome" visible="false" />
</tabs>
</ribbon>
<contextualTabs>
<tabSet idMso="TabSetDrawingTools" visible="false" />
</contextualTabs>
<backstage>
<tab idMso="TabInfo" visible="false">
</backstage>
<contextMenus>
<contextMenu idMso="ContextMenuText">
<!-- you can't hide a context menu entirely, you have to hide each item -->
<button idMso="FontDialog" visible="false" />
</contextMenu>
</contextMenus>
</customUI>
This may also be possible if you're working with Office in the way that you seem to be, I don't really know.

Custom section in App.Config: How to realize this structure in C#?

I have created a custom configuration section for my App.Config file, right now it looks like this:
<mySection>
<myCollection>
<element name="1" />
<element name="2" />
</myCollection>
</mySection>
As the naming suggests, I have classes inherited from ConfigurationSection (MySection), ConfigurationElementCollection (MyCollection with AddItemName="element" set in the attributes of MySection), and ConfigurationElement. But I wonder how I can realize a structure similar to the following:
<mySection>
<myElements>
<element name="1" />
<element name="2" />
<additionalInfo>"..."</additionalInfo>
</myElements>
<someOtherSetting option="blub" />
</mySection>
Can I still use ConfigurationElementCollection for MyElements or do I have to use something else, as there is not just the element tag (specified by AddItemName="element" in the MySection class), but also another one? If not, what is the class to use here?
And I guess having something between the tags has to just correspond to a property of some AdditionalInfo class, so that it'd be equivalent to the following?
<additionalInfo content="..." />
As for someOtherSetting I guess I could just add another property to MySection corresponding to this, but I didn't get to testing that yet.

AvalonEdit (C#) Custom attributes in XSHD files

I'm working on highlighting a small scripting language (that is not a derivative of any of the built in's) and I had a custom XML file setup for different syntax keywords and such.
I would really like to use the XSHD system that exists in AvalonEdit for loading custom keywords, but I need to have custom attributes in them.
So basically, after a lot of searching through the source code, I could not really pin-point the file that reads and specifies the keywords and rulesets.
Does anyone here know where I can edit the needed class to read some custom attributes and storing them?
I have all the XSHD and higlighting stuff in AvalonEdit down and working, so it's not using it that is the problem, per say, it's more the problem of using custom attributes in the keywords collection of the XSHD file.
In example:
<Keywords>
<Word defaultValue="hello" requiresShader="shadertype1, shadertype2" someCustomAttr="value">wordname</word>
</Keyword>
So, I need to set some custom properties to the parser of the XSHD file to load these custom attributes and store them in a custom class I have made that handles a few logical components that are crucial to what I'm trying to do.
I already have a working parser that parses a XML file of all my keywords and their properties (but I wrote it to ScintillaNET, but found AvalonEdit afterwards, that works better with WPF and such).
I will edit the original post with this information, sorry about possible misinformation.
Thank you
To load an XSHD file, you need to import the following libraries:
using ICSharpCode.AvalonEdit;
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.AvalonEdit.Highlighting.Xshd;
And then wherever you create the text editor (omit the first line and just reference the TextEditor if you create it in XAML), use the following code to load def.xshd.
// TextEditor is an AvalonEdit.TextEditor
TextEditor edit = new TextEditor();
XmlReader reader = XmlReader.Create("def.xshd");
edit.SyntaxHighlighting = HighlightingLoader.Load(reader, HighlightingManager.Instance);
A good sample xshd file that I am using for a language in the works is this:
<SyntaxDefinition name="XAPL"
xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008">
<Color name="Comment" foreground="Green" />
<Color name="String" foreground="Pink" />
<Color name="Xml" foreground="Orange" />
<!-- This is the main ruleset. -->
<RuleSet>
<Span color="Comment" begin="//" />
<Span color="Comment" multiline="true"
begin="/\*" end="\*/" />
<Span color="String">
<Begin>"</Begin>
<End>"</End>
<RuleSet>
<!-- nested span for escape sequences -->
<Span begin="\\" end="." />
</RuleSet>
</Span>
<Span color="Xml" multiline="false">
<Begin>spaz</Begin>
<End>spaz</End>
</Span>
<Keywords fontWeight="bold" foreground="Blue">
<Word>dealwith</Word>
<Word>import</Word>
<Word>end</Word>
<Word>var</Word>
<Word>default</Word>
<Word>template</Word>
<Word>sub</Word>
<Word>category</Word>
<Word>if</Word>
<Word>otherwise</Word>
<Word>and</Word>
<Word>xor</Word>
<Word>string</Word>
<Word>int</Word>
<Word>convert</Word>
<Word>to</Word>
<Word>escape</Word>
<Word>native</Word>
<Word>loop</Word>
<Word>is</Word>
<Word>to</Word>
<Word>from</Word>
<Word>by</Word>
</Keywords>
<!-- Digits -->
<Rule foreground="DarkGray">
\b0[xX][0-9a-fA-F]+ # hex number
| \b
( \d+(\.[0-9]+)? #number with optional floating point
| \.[0-9]+ #or just starting with floating point
)
([eE][+-]?[0-9]+)? # optional exponent
</Rule>
</RuleSet>
</SyntaxDefinition>

Silverlight XML Save does not overwrite the entire file

The best way to explain my problem is by a example.
I have a Xml file with some elements in it. When I remove a element, I save the file again and this problem occurs:
Before save
<?xml version="1.0" encoding="utf-8"?>
<ElementTree>
<Elements1 />
<Elements2>
<Element Name="TestElement" ID="4efa7cc9-a89a-429b-81f4-b00cde729f24" />
</Elements2>
<Elements3 />
</ElementTree>
After save
<?xml version="1.0" encoding="utf-8"?>
<ElementTree>
<Elements1 />
<Elements2 />
<Elements3 />
</ElementTree>D="4efa7cc9-a89a-429b-81f4-b00cde729f24" />
</Elements2>
<Elements3 />
</ElementTree>
What I suspect it is doing: It keeps writing the text untill it has reached the end of the text to be saved and then it stops. It does not remove the text that is still writen in the file AFTER the last character in the stream.
How can I fix this?
Make sure you replace the existing file when opening it and you close the stream correctly.

Categories