For mongodb, how can I create the following index in C# ?
db.reviews.ensureIndex( { comments: "text" } )
I don't see any "Text" option for IndexOptions at http://api.mongodb.org/csharp/current/?topic=html/7e62224e-33ab-098b-4e07-797c45494a63.htm
You'll need to set this up through a script or directly on the MongoDB database as the C# driver doesn't expose the text index creation feature as it's still in "beta".
Unfortunately, you can't easily override the behavior either ... as the classes that control the behavior aren't easily overriden/extensible.
If you created a copy of the IndexKeysBuilder class (here), and added a new method (something like below):
public IndexKeysBuilder Text(string name)
{
_document.Add(name, "text");
return this;
}
You could use that instead of the built in stuff and in theory, it should work (I've not tested this).
the easiest way to create text indexes in c# is by using the driver wrapper library MongoDB.Entities. here's an example of creating a text index:
DB.Index<Review>()
.Key(a => a.Comment, Type.Text)
.Create();
haven't seen anything else that makes it simpler than that.
Related
Here is a little background on the specifications of my project:
We use Specflow and Microsoft CodedUI Framework for UI Automation
I have built a PageFactory that combines three Abstract Base Classes : BasePage, BaseMap, and BaseValidator that all Maps, Pages, and Validators inherit
Our Application that we are automating has numerous workflows that make defined HTML Controls have different InnerText Values (HTMLComboBoxes for example)
Everything is and needs to be abstracted from the actual Specflow Test Code in the Page Object Pattern, no unique code can exist within a Specflow Step
In my Maps I have certain controls like a combobox that has an InnerText change if a certain workflow is selected. I need to build assertion and verification statements to make sure the InnerText is correct for the workflow that is selected. This is not a problem. However, I do not want to just define a new variable for every InnerText change(There are A LOT).
Is there any way I can account for the InnerText variations in the Page Object Pattern and not have to code a new variable for every single one?
Here is an example of a Map Entry:
public HtmlComboBox NextActionControlDropDownList()
{
var NextActionControlDropDownList = new PropertyExpressionCollection {
new PropertyExpression(HtmlComboBox.PropertyNames.Id, "MEDCHARTContent_EmmpsContent_nextActionControl_ActionDropDownList", PropertyExpressionOperator.EqualTo)
};
return Window.Find<HtmlComboBox>(NextActionControlDropDownList);
}
This is the Base Control definition. It can also be this:
public HtmlComboBox NextActionControlARFormalComplReview()
{
var NextActionControlARFormalComplReview = new PropertyExpressionCollection {
new PropertyExpression(HtmlComboBox.PropertyNames.Id, "MEDCHARTContent_EmmpsContent_nextActionControl_ActionDropDownList", PropertyExpressionOperator.EqualTo),
new PropertyExpression(HtmlComboBox.PropertyNames.InnerText, "--Select Action-- Return to USARC ", PropertyExpressionOperator.EqualTo)
};
return Window.Find<HtmlComboBox>(NextActionControlARFormalComplReview);
}
My thoughts so far were to maybe make another map and inherit it? But that wouldn't solve my initial problem of too many variables for a single control. I don't see how If statements would help either because it needs to be defined for the framework to find the control. Maybe I could store the differing values in a collection of sorts and have a parameter key value to access them... but that seems like I would run into a lot of issues.
If you try and see the methods under PropertyExpressionOperator you would see something called Contains.
new PropertyExpression(HtmlComboBox.PropertyNames.InnerText, "--Select Action--", PropertyExpressionOperator.Contains)
This might be a super simple question, but since Google has a hard time giving me answers you might!
I'm wondering if its possible for a part in MEF to get hold of values defined in its own ExportMetadata?
Lets say I got this code for a part:
[ExportMetadata("name", "A Template Plugin")]
[ExportMetadata("guid", "0db79a169xy741229a1b558a07867d60")]
[ExportMetadata("description", "A template for a new plugin")]
[ExportMetadata("version", "1.0.0.43")]
[Export(typeof(IPlugin)), PartCreationPolicy(CreationPolicy.NonShared)]
public class PluginExport : IPlugin, IDisposable
{
... code goes here...
... can I get hold of metadata, ie the "guid" key ??? ...
}
If anyone questions the sanity of this its bcause Im making a plugin template for 3pp developers and some values (not shown in the example above) also needs to be used from within the plugin and I think it would be nice not having them setup a lot of data in two separate places.
You can use reflection regardless of MEF to get the attribute value:
[ExportMetadata("guid", "0db79a169xy741229a1b558a07867d60")]
class PluginExport
{
void PrintGuid()
{
var guid = this.GetType()
.GetCustomAttributes(false)
.OfType<ExportMetadataAttribute>()
.Single(attribute => attribute.Name == "guid").Value;
Console.WriteLine(guid); // Prints your value.
}
}
I am trying to create a list of the Components running on the network. I am trying to get all the components in the ObservableCollection. ObservableCollection<ClsComponent> Now my question is if one of the component in the collection get changed / modified how would I be able to get it reflected to my ObservableCollection of Component
Is there a way to change the it directly in the collection itself?
What is the fast and efficient way doing it?
I have tried: to change it using the LINQ : Find the Component in the collection and change it?
var CompFound = Components.FirstOrDefault(x=>x.Id == myId);
Components.Remove(CompFound);
Components.Add(UpdatedComp);
I am very sure there should have been more optimized way of doing this. Please suggest.
Edit
I am trying to write the code in the function where I can get the parameters of Source Component and Destination Component. Function looks like this
public void UpdateComponent(ClsComponent SourceComp, ClsComponent DestComp)
{
//do something here
}
After the execution of the function I want to Replace Source Component with Destination Component.
I believe this might work for you. I am sure you might be looking for this
Components.Insert(Components.IndexOf(SourceComp), DestComp);
Components.Remove(SourceComp);
One of the most efficient way would be to use a dictionary. There are implementations of ObservableDictionary which will give you the Observable behavior while allowing a fast key-based access to the object.
Check this stackoverflow question. It includes Microsoft's
It should work like ObservableCollection, except it's also a dictionary. So you can Create ObservableDictionary<Int,ClsComponent>
To replace the value simply call
Components[myId] = destComp
It's very possible that I just don't understand the problem space, but I'm having trouble figuring out the MEF (Editor Classifier project).
I've created (piecing together the Walkthrough guides from MSDN https://msdn.microsoft.com/en-us/library/ee197665.aspx) a syntax highligher for Informix Stored Procedure language.
One major problem I have is - I want to be able to find all instances of the keyword "DEFINE" and populate the word directly following it into the Statement Completion extension I have (currently it's populated from a defined list of words).
Much like C#'s native support - when you define a variable, it becomes available in the autocompletion dropdown.
I got rid of the in class hardcoding (from the walkthrough) and my completion words are defined like this:
List<Completion> completions = new List<Completion>();
CompletionTags completionTags = new CompletionTags();
foreach (string completionTag in completionTags.completionTags)
{
completions.Add(new Completion(completionTag));
};
My CompletionTags class is pretty simple:
class CompletionTags
{
public List completionTags;
public CompletionTags()
{
this.completionTags = new List<string> {
// SQL keywords
"COUNT",
"FROM",
"HAVING",
};
}
I know WHAT I need to do. I somehow need to hijack the buffer when it changes and find all occurrences of 'DEFINE ([a-zA-Z0-9_]{1,})' and add \1 to the completionTags list.
I have no idea HOW to do this. Any pointers in the right (or any) direction at this point would be greatly appreciated.
Be kind - we've all been out of our depth at some stage (I've been programming in C# now for 3 days)...
Reading this answer will be helpful.
Look at:
XML Editor IntelliSense Features
Schema Cache
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#.