Updating an Evernote Note from HTML - c#

Using the C# SDK I'm working on a simple application to load a note from evernote, allow the user to edit the note using a HTML wysiwyg editor and then save it back to Evernote.
I'm a little confused. I can load a ENNote from the standard ENSession and access the HTML version of the note, but to update I have to load a Edam.Type.Note which has no HTML properties to set just the standard XML doc.
I can see there is a ENHTMLtoENMLConverter class but its internal? Its counterpart ENMLtoHTMLConverter is public.
Is there an easy to convert basic HTML/ENHTML into a Edam.Type.Note so I can update without writing my own converter or compiling my own version of the SDK?

Creating a note using HTML or web content
The SDK contains a facility for supplying HTML or web content to a
note.
ENNote myFancyNote = new ENNote();
myFancyNote.Title = "My first note";
myFancyNote.Content = ENNoteContent.NoteContentWithSanitizedHTML("<p>Hello, world - <i>this</i> is a <b>fancy</b> note.</p>");
ENNoteRef myFancyNoteRef = ENSession.SharedSession.UploadNote(myFancyNote, null);
This method handles general HTML content, including external style
sheets which it will automatically inline. Please note that this is
not a comprehensive "web clipper", though, and isn't designed to work
fully on all arbitrary pages from the internet. It will work best on
pages which have been generally designed for the purpose of being
captured as note content.
Source : Getting Started with the Evernote Cloud SDK for Windows

You can do this without dipping into the "advanced" stuff. You still want to call ENSession.SharedSession.UploadNote but use the version that lets you specify one of the "replace" policies as appropriate:
public ENNoteRef UploadNote(ENNote note, ENSession.UploadPolicy policy, ENNotebook notebook, ENNoteRef noteToReplace)
You'll still need to create an ENNote with your updated content (you can use the NoteContentWithSanitizedHTML etc). And supply the note ref pointing to the original note you want to replace.

Related

Open AngleSharp document in Chrome

I am using AngleSharp in C# to simulate a web browser. For debugging purposes, sometimes I want to see the page I am traversing. I am asking if there is an easy way to show the current document in a web browser (preferably the system's default browser) and if possible with current cookie states.
I am very late to the party, but hopefully someone will find my answer useful: The short answer is no, the long answer is, yes - with some work that is possible in a limited way.
How to make it possible? By injecting some code into AngleSharp that opens a (local) webserver. The content from this webserver could then be inspected in any webbrowser (e.g., the system's default browser).
The injected local webserver would serve the current document at its root (e.g., http://localhost:9000/), along with all auxiliary information in HTTP headers (e.g., cookie states). The problem with this approach is that we either transport the document's original source or a serialization of the DOM as seen by AngleSharp. Therefore, there could be some deviations and it may not be what you want. Alternatively, the server could emit JS code that replicates what AngleSharp currently sees (however, then standard debugging seems more viable).
Any approach, however, requires some (tedious?) work and therefore needs to be justified. Since you want to "see" the page I guess a CSS renderer would be more interesting (also it could be embedded in any application or made available in form of a VS extension).
Hope this helps!

Custom metadata for service stack

I'm looking to generate custom documentation for a service stack end point. I'm aware of service stack's api for such a thing but the problem is that I have is a have to build a highly customized meta data page that is different depending on the values that are feed into the request:
\myendpoint\1\metadata
\myendpoint\2\metadata
These two urls would generate to totally different sets of metadata pages. Part of the data is procedurally generated so that adds to the complexity as well.
So my question is there an easy way to wire in a custom html page for meta for a specific end point?
Thanks in advance,
Sieg
Please see the documentation on modifying ServiceStack's built-in metadata templates:
The VFS lets you replace built-in ServiceStack templates with your own by simply copying the metadata or HtmlFormat Template files you want to customize and placing them in your Website Directory at:
/Templates/HtmlFormat.html // The auto HtmlFormat template
/Templates/IndexOperations.html // The /metadata template
/Templates/OperationControl.html // Individual operation template
Which you can customize locally that ServiceStack will pick up and use instead.
Using JavaScript to modify links to point to custom pages
As the templates are static html with template placeholders, one approach you could do is to add additional JavaScript behavior to either add links to custom metadata pages (or modify/remove the existing ones).

Create dynamic code with templates based on options

I've a question related to dynamic code generation (html) with C# based on a template. The user sets all options (e.g. whether or not a <div> should be displayed, whether or not an image in the template should change by a specific date,...) and provides the content (text, images) needed for code generation. The generated code is needed for a WIFI hotspot site.
The template consists of HTML, CSS and JavaScript which gets extended and modified by the user-defined settings at runtime. I also think of providing "meta settings" in the template to define, whether or not some options CAN be disabled set or not.
My major problem:
How to define the template to dynamically extend the template code easily? For example, if a user option is enabled at runtime, I'm in need to add JavaScript code on top and HTML code below another (specific) place. Another example is to hide content (a defined ) when another option is disabled...
I'm not sure what's the best practice to handle that requirement. Maybe HTML elements with id attribute can help eliminate some of the problems. But with JavaScript I'm not sure. Maybe the template needs to be a XML which creates the final HTML at runtime? Any idea?
Has anyone an idea how to handle that?
UPDATE/INFO:
The project is written in pure C# - without any ASP.NET. It is a desktop project working with HTML files and GENERATING HTML files (as an output).
I suppose you can use ASP.NET MVC Razor view engine to render an html to a file with the help of this question. With Razor you will get the support of dynamic view (aka template) changes, rich template syntax etc. Everything you can do when create a web site. Just render the html to a file not a response body.

Custom server script

I have built a small HTTP server based on the HTTPListener class.
What I would like to know is, is there any scripting language I can put in my HTML files that can be natively executed in C#?
Something similar to how PHP works when it is mixed with HTML code.
lee
You could use any of the available templating engines for .NET such as WebForms, Razor, ...
There is one you can use: T4.
If you want to have templated defined at runtime, you will need a reference to Microsoft.VisualStudio.TextTemplating to be present, you can learn how to use it pragmatically from the article Processing Text Templates by using a Custom Host (at msdn).
From the article:
To execute a text template, you call the ProcessTemplate method of
Microsoft.VisualStudio.TextTemplating.Engine:
using Microsoft.VisualStudio.TextTemplating;
...
Engine engine = new Engine();
string output = engine.ProcessTemplate(templateString, host);
In the host parameter, you must provide a class that implements
ITextTemplatingEngineHost. This is called back by the Engine.
By this method you can have make your program read the template from a file or load it from a resource.
The article Walkthrough: Creating a Custom Text Template Host (also at msdn) will help you to implement the interface ITextTemplatingEngineHost.
As an alternative, if you will have fixed templates defined beforehand, you can create the tt files and use the following method:
TestTemplate testTemplate = new TestTemplate();
string output = testTemplate.TransformText();
Where TestTemplate is a class generated by VisualStudio from a TestTemplate.tt file. Using this method the template is fixed at compile time. So you will not be able to define it at runtime, from example by reading it from a file.
If you want something simple I recommend you to take a look at T4 templates. You can start from here and here

AssetUrlSelector toolpart

What I need to do is quite simple although is causing me lots of trouble.
I need to create programmatically an AssetUrlSelector in a web part that selects a file in sharepoint 2010 and makes its path available to be used elsewhere.
So far I have managed to create the AssetUrlSelector and display the path on a textbox, however I cannot use this as every reference to it will be null.
Have you got any practical example?
Try the Document ID Service. In short this service generates IDs for documents (files) and generates an url with this ID so even if the file is moved the url stays valid and the service returns the document. This service might rely on search functionality unless you implement your custom search. Here is an article on how to configure OOB Doc IDs here. Also you can google further if you're interested.

Categories