multilingual codeeffects rule editor - c#

How can I render the CodeEffects Rule Editor in a different language (Let's say Arabic).
I am using a custom class as the source object for the rule model and passing that in the viewbag to the view, there i am rendering the rule editor using that. I have not explictely called any source xml or help xml doc. the rule editor is picking the default english version.
#{
Html.CodeEffects().RuleEditor()
.Id("ruleEditor")
.SaveAction("SaveGroup", "Campaign")
.DeleteAction("DeleteGroup", "Campaign")
.LoadAction("LoadGroup", "Campaign")
.Mode(RuleType.Evaluation)
.ToolBarRules(ViewBag.ToolBarRules)
.Rule(ViewBag.Rule)
.Render();
}
So far on CodeEffects official documentation I have come accross this Help XML and Multilingual Support in Code Effects but I couldn't understand it properly
How can I load a custom help xml and source xml file from the cshtml page using razor syntax
Any help would be appreciated.

In general, you simply create your own version of the Help XML in your language and pass it to the editor on the server using the editor's HelpXmlFile property during the editor initialization.
You also need to have your own version of the Source XML with all display names translated in your language if you want your fields, in-rule methods and rule actions to be displayed in your language on the client. You can pass that source xml to the editor using the its SourceXmlFile property.
Call editor.GetHelpXml() method to get the default version of the Help XML to be translated; call editor.GetSourceXML() to get the Source XML of your source object to be translated (pass your source class to your editor first before calling that method, of course.)
EDIT:
As I said earlier, you need to use your own custom version of the Help XML which sets language-specific labels of all static UI elements such as buttons, Help String, etc. To do that, create a default instance of the RuleEditor class and call its GetHelpXml() method. That gives youa string of the default English xml document. Translate all its node values to your language, save it and pass that new xml to the editor using one of the overloads of its Help() extension method. Details can be found here.
I assume that you also need to have all properties, in-rule methods and rule actions displayed in your language. You have two options here:
If your project only uses one language, then simply use the FieldAttribute, MethodAttribute and/or ActionAttribute to set their DisplayName properties to values in your language. Details are here, here, and here.
If your project uses multiple languages then create an instance of the RuleEditor class, set its SourceType property to the type of your source class and call its GetSourceXml() method whoch returns a string of the XML doc that represents your source class. Create a copy of that doc for each of the language your project uses, translate all value of the "displayName" attributes in correspondent language, save those files and pass the desired one to the RuleModel.Create() method when you init the editor on the server. Details are here.

Related

How to format/style ///<summary> in Web API 2

Maybe this isn't even possible, but it seems silly that I can't figure it out (nor can find anything conclusive after searching).
With a MVC/C# Web API 2 project, your controllers can be documented using something like:
///<summary>
///This is something really cool that you should use. I want <b>this bold</b>.
///</summary>
[HttpPost]
public MyResponse MyMethod(SomeInput input)
{
....
}
When the API runs, the project automatically builds the help site, and I can see the above endpoint/method, and its description ( text), but I've head to figure out how to do any sort of styling to the summary. It appears that the HTML tags get striped from the help page's output. Notice in my example above, I have "this bold". I'm not so much concerned about bold, but more interested in being able to use unordered lists () and other basic HTML tags to just do some real basic formatting.
Is this even possible?
Is there a trick to it?
Is there some other markup/formatting I should be using?
Note - The actual endpoint that I'm trying to document at moment, happens to be a mime multipart form, and the framework won't document those out of the box. To get around this, I've created some helper methods in HelpPageConfigurationExtensions (to determine if the current endpoint view is one that requires custom documentation), in HelpPageApiModel.cshtml to determine if it should show the stock documentation or the custom docs, a helper library that contains the custom doc information, and a series of help functions that use some reflection to rapidly build HTML tables for the rest of the help page's documentation (e.g. the request and response objs). I'm mentioning this because maybe I just need to further extend my custom doc library to include (hard code) the value, and then in the view I can just #Html.Raw it -- opposed to trying to get the actual method's to output with formatting.
Thoughts?
Thanks!

How to write a Wix Custom Action to Read XML data and set Properties

I have been working on this for days and I just don't get the concept of how Custom Actions work with Wix. Or at least I don't see how to do what I want.
I have several XML files that I want to read a value from and populate a property that gets displayed in a UI Dialog. Then when the install begins update that value in another XML file.
I need to be able to pass the filename including path of the local XML file and the node to search for and the key value pair to extract. I also need to pass what property needs to be updated.
I understand the CustomAction DLL concept. And that the session.CustomActionData["parametername"] syntax for passing in parameters. And the session["property"] = to set a property.
But I can't figure out the syntax of the wsx code to make it all happen. I read different examples doing it different ways?
I searched all the Google links out there an nothing seems to fit what I want to do?
You want this to be an immediate custom action not a deferred custom action so CustomActionData has no relevance to you.
What I would do is write a custom table like such:
Id [PK]
File (Formatted)
XPATH
Property
Here's an example:
mySearch
[SOMEPROPERTY]
/test[#'test'] (something like that, I hate xpath)
MYPROPERTY
You can use things like Property/FileSearch to have MSI's AppSearch resolve the location of a file and assign it to [SOMEPROPERTY]. Then you write a custom action scheduled after AppSearch to fetch this table's data, iterate it and fetch the attribute value (or element innertext) of each row and assign it to MYPROPERTY.
InstallShield gave this to me for free. I don't think WiX has a built in extension to do this. Maybe there is a community extension out there. It would probably take me an hour to write a prototype of this in C#/DTF.

Parsing C# code for contextually aware semantic highlighting

I'm working on a semantic highlighting plugin for VS. Here you can see a web Example.
The goal:
Acquiring all variables and creating different Classifications for every one of them.
The problem:
Getting the variables from the code without writing a C# lexer.
My current approach uses an ITagger. I use an ITagAggregator to get the tags of all the spans that get passed to the ITagger. Then I filter those and get only spans with the "identifier" classification which includes varibles, methods names, class names, usings and properties.
public class Classifier : ITagger<ClassificationTag> {
public IEnumerable<ITagSpan<ClassificationTag>> GetTags(NormalizedSnapshotSpanCollection spans) {
ITextSnapshot snapshot = spans[0].Snapshot;
var tags = _aggregator.GetTags(spans).Where((span) => span.Tag.ClassificationType.Classification.Equals("identifier")).ToArray();
foreach(var classifiedSpan in tags) {
foreach(SnapshotSpan span in classifiedSpan.Span.GetSpans(snapshot)) {
//generate classification based on variable name
yield return new TagSpan<ClassificationTag>(span, new ClassificationTag(_classification));
}
}
}
}
It would be a lot easier to use the builtin C# Lexer to get a list of all variables bundled to a bunch of meta data. Is this data available for plugin development? Is there an alternative way I could acquire it, if not?
The problem: Getting the variables from the code without writing a C# lexer.
Roslyn can do this: https://roslyn.codeplex.com/
There's even a Syntax Visualizer sample that might interest you. I also found an example using Roslyn to create a Syntax Highlighter.
Visual Studio exposes that information as a code model.
Here is an example how you can access class, and then find attribute on the class, and parse attribute arguments:
Accessing attribute info from DTE
Here is more information about code models:
http://msdn.microsoft.com/en-us/library/ms228763.aspx
Here's also automation object model chart what I've been using quite few times: http://msdn.microsoft.com/en-us/library/za2b25t3.aspx
Also, as said, Roslyn is indeed also a possible option. Here is an example for VS2015 using roslyn: https://github.com/tomasr/roslyn-colorizer/blob/master/RoslynColorizer/RoslynColorizer.cs
For building language tools if may be better to use a parser generator for C#. The GOLD parsing system is one such toolkit which can handle LALR grammars. It has a .NET component based engine that you can use in your project and it can be used to integrate with any IDE. You can also find the grammars for various programming languages including C#.

SharePoint 2010 client object model, clear content type collection

I have an SP.ContentTypeCollection for a document library. I'm trying to add a selected one from the site's content types. I also need it to be the new DEFAULT content type for that library.
Thus, I've copied the document library's existing types to a list. Then I want to clear the content types and add my new one FIRST so it becomes default. Then I will add the others I copied.
PROBLEM: I can't find a way to delete one or all of the content types in the collection.
Help? :-) Thanks in advance.
You can't delete an element from SP.ContentTypeCollection list. This article provides a code snippet to delete a content type by using client object model , but the code doesn't check if the content type that is being used as you cannot delete a content type that is being used.
The code snippet use the function ContentType.DeleteObject to delete a content type, please be aware of the exceptions in that MSDN link.

Definition.Entity property is null

Whenever I create a ReloadableObjectRegistry with path to directory containing compiled modules, Definitions in the tree have Entity property set to null. The reason why I need to access this property is to be able to read the syntax of a definition.
I suspect, the Entity property only gets set after parsing a MIB... Is this a correct assumption? How else can I find out definition's syntax? The Type property is always 'Unknown'.
Sample code:
private ReloadableObjectRegistry Objects;
Objects = new ReloadableObjectRegistry(#"some_path");
P.S. By the looks of it, parsed module (.module) does not have any information about MIB Types in it.
The open source edition SharpSnmpLib.Mib was designed that way, where most of the classes are just placeholders.
If you do need to learn the syntax, you have to use SharpSnmpPro.Mib at http://sharpsnmp.com.
A sample project has been published on GitHub to demonstrate usage of the new APIs.

Categories

Resources