I have the following code where I am stuck a little bit:
var indexBuilder = Builders<T>.IndexKeys;
if (setting.IsDescending)
indexBuilder.Descending(setting.Column);
else
indexBuilder.Ascending(setting.Column);
var indexOptions = new CreateIndexOptions();
if (setting.IsUnique)
indexOptions.Unique = true;
var model = new CreateIndexModel<T>(indexBuilder, indexOptions);
I got the following error:
Argument 1: cannot convert from 'MongoDB.Driver.IndexKeysDefinitionBuilder' to 'MongoDB.Driver.IndexKeysDefinition'
I am not sure why as I have done the same as it is in official documentation.
You need to create a variable with IndexKeysDefinition<T> and pass it to the CreateIndexModel as below:
IndexKeysDefinition<T> index;
var indexBuilder = Builders<T>.IndexKeys;
if (setting.IsDescending)
index = indexBuilder.Descending(setting.Column);
else
index = indexBuilder.Ascending(setting.Column);
var indexOptions = new CreateIndexOptions();
if (setting.IsUnique)
indexOptions.Unique = true;
var model = new CreateIndexModel<T>(index, indexOptions);
Demo
Related
Using the .Net AWSSDK.EventBridge I created a rule:
var client = new AmazonEventBridgeClient();
string ruleName = "SomeRule";
var putRuleRequest = new Amazon.EventBridge.Model.PutRuleRequest()
{
Name = ruleName,
ScheduleExpression = "rate(10 minutes)",
State = RuleState.ENABLED
}
await client.PutRuleAsync(putRuleRequest);
var target = new Amazon.EventBridge.Model.Target();
target.Arn = "ARN_LAMBDA_FUNCTION";
target.Id = "LAMBDA_FUNCTION_NAME";
target.Input = JsonSerializer.Serialize(new { someId, someDate});
var targetList = new List<Amazon.EventBridge.Model.Target>();
targetList.Add(target);
var putTargetRequest = new Amazon.EventBridge.Model.PutTargetsRequest()
{
Rule = ruleName,
Targets = targetList
};
await client.PutTargetsAsync(putTargetRequest);
The Lambda function is already created so I put the ARN and name on the Target. The idea is that there is one function but multiple rules will call it.
The rule, schedule, and target to the function are created when I run the code but the problem is that the function can't be triggered by the rule. When I edit the rule, update it in the AWS Console without changing anything the trigger works.
What am I missing?
After searching through I found out I was missing the permission for Lambda.
//This line replaces the code above
var putRuleResponse = client.PutRuleAsync(putRuleRequest).Result;
var lp = new Amazon.Lambda.Model.AddPermissionRequest();
lp.FunctionName = FUNCTION_ARN;
lp.Action = "lambda:InvokeFunction";
lp.SourceArn = putRuleResponse.RuleArn;
lp.Principal = "events.amazonaws.com";
lp.StatementId = "SomeStatement";
var lambdaClient = new AmazonLambdaClient();
await lambdaClient.AddPermissionAsync(lp);
I am trying to replicate the post request as given in the doc: https://learn.microsoft.com/en-us/rest/api/azure/devops/git/pushes/create?view=azure-devops-rest-5.0#update_a_file
using the .Net libraries for making an extension.
I have checked that the refUpdate and OldObjectId are correct through trial and error.
changes, item, repo are all defined and not null.
GitPush push = new GitPush();
GitCommit gitCommit = new GitCommit();
GitChange change = new GitChange();
ItemContent content = new ItemContent();
content.Content = changeString;
content.ContentType = ItemContentType.RawText;
change.NewContent = new ItemContent();
change.ChangeType = VersionControlChangeType.Edit;
change.Item = item;
List<GitChange> changes = new List<GitChange>();
changes.Add(change);
gitCommit.Changes = changes;
gitCommit.Comment = "updated app.cpp";
GitRefUpdate refUpdate = new GitRefUpdate();
refUpdate.Name = "refs/heads/dev";
refUpdate.OldObjectId = oldObjectId;
List<GitCommit> commits = new List<GitCommit>();
commits.Add(gitCommit);
List<GitRefUpdate> refUpdates = new List<GitRefUpdate>();
refUpdates.Add(refUpdate);
push.Commits = commits;
push.RefUpdates = refUpdates;
GitPush pushed = gitClient.CreatePushAsync(push, repo.Id).Result;
On the last line the debugger gives the exception that parameter "newPush" is not defined.
I was trying to create a build definition. I tried as below one.
But i do think the code below doesn't create a buildDefinition. Like it asks for BuildDefinitionRef in the code "newBuild["BuildDefinition"] = ;" I am unable to know what exactly to put which reference.
RallyRestApi RestApi = new RallyRestApi("_abcd","https://rally1.rallydev.com");
String workspaceRef = "/workspace/27154845988";
String projectRef = "/project/48152113168";
DynamicJsonObject newBuild = new DynamicJsonObject();
newBuild["Workspace"] = workspaceRef;
newBuild["Duration"] = 0.75;
newBuild["Message"] = "Master 4683 Success";
//newBuild["CreationDate"] = "";
newBuild["Status"] = "FAILURE";
newBuild["Number"] = "4683";
// newBuild["Uri"] = "http://jenkins-build:8080/hudson/view/master/job/master-deploy/4683/";
// newBuild["BuildDefinition"] = ;
If any body has any idea of first how to create the BuildDefinition.
BuildDefinition should be a createable type in WSAPI. You just need to create that first, and then when you're creating your Build object just pass the ref of the created BuildDefinition:
newBuild["BuildDefinition"] = "/builddefinition/12345";
I'd like to know how to create the following XML using SharpKml:
<StyleMap id="msn_placemark_circle">
<Pair>
<key>normal</key>
<styleUrl>#sn_placemark_circle</styleUrl>
</Pair>
<Pair>
<key>highlight</key>
<styleUrl>#sh_placemark_circle_highlight</styleUrl>
</Pair>
</StyleMap>
I've tried several things, but with no success. This is what I have so far:
public static StyleSelector Generate_M_ylw_pushpin3()
{
var stylemap = new StyleMapCollection();
stylemap.Id = "s_ylw-pushpin3";
var normalPair = new Pair();
normalPair.Id = "normal";
normalPair.Selector = StyleGenerator.Generate_s_ylw_pushpin_hl3();
//normalPair.StyleUrl = new Uri(#sh_placemark_circle_highlight); // Exception by .NET
var highlightPair = new Pair();
highlightPair.Id = "highlight";
highlightPair.Selector = StyleGenerator.Generate_s_ylw_pushpin_hl3();
//highlightPair.StyleUrl = new Uri(#sh_placemark_circle_highlight); // Exception by .NET
stylemap.Add(normalPair);
stylemap.Add(highlightPair);
return stylemap;
}
// This code just works fine
public static StyleSelector Generate_s_ylw_pushpin_hl3()
{
var style = new Style();
style.Id = "s_ylw-pushpin_hl3";
var iconStyle = new IconStyle();
iconStyle.Color = Color32.Parse("ff00ff00");
iconStyle.Scale = 1.18182;
iconStyle.Icon = new IconStyle.IconLink(new Uri("http://some/url"));
var labelStyle = new LabelStyle();
labelStyle.Color = Color32.Parse("00ffffff");
style.Icon = iconStyle;
style.Label = labelStyle;
return style;
}
Who knows on how to achieve this?
I've find the answer to my own question:
public static StyleSelector Generate_M_ylw_pushpin3()
{
var stylemap = new StyleMapCollection();
stylemap.Id = "s_ylw-pushpin3";
var normalPair = new Pair();
normalPair.StyleUrl = new Uri("#sh_placemark_circle", UriKind.Relative);
normalPair.State = StyleState.Normal;
var highlightPair = new Pair();
highlightPair.StyleUrl = new Uri("#sh_placemark_circle_highlight", UriKind.Relative);
highlightPair.State = StyleState.Highlight;
stylemap.Add(normalPair);
stylemap.Add(highlightPair);
return stylemap;
}
Martijin added the answer to his own question, which is amazing and helped me get to my solution. Just for an alternative that I believe is slightly more generic I figured I'd drop my solution that I got to thanks to Martijin's answer.
Note: my solution is generating these for a line object to be generated, however this could be used for other styles easily
Creating the style objects for a highlight or normal state. The objects made here are what will be added to the stylemap
Here we just pass in the placemark itself (with some details such as the placemark name, etc., available) and a boolean value as to whether it is a highlight or normal style. My usage is thus:
kmlDom.Style normalStyle = createPlacemarkLineStyle(thisPlacemark, false);
kmlDom.Style highlightStyle = createPlacemarkLineStyle(thisPlacemark, true);
Method:
public kmlDom.Style createPlacemarkLineStyle ( kmlDom.Placemark placemark , bool highlight )
{
kmlDom.Style styleNode = new kmlDom.Style( );
// Add Line Style
kmlDom.LineStyle lineStyle = new kmlDom.LineStyle( );
if( !highlight )
{
styleNode.Id = String.Format( "{0}-normal", placemark.placemarkName );
lineStyle.Color = hexToColor("ff0000ff");
lineStyle.Width = 2;
}
else
{
styleNode.Id = String.Format( "{0}-highlight", placemark.placemarkName );
lineStyle.Color = hexToColor( "ff0000ff" );
lineStyle.Width = 2;
}
styleNode.Line = lineStyle;
return styleNode;
}
Now we create the style selector to be added to the placemark object
Here I pass two style objects and the original placemark object to create the full style map. This is returned to the placemark with a call such as:
thisPlacemark.StyleSelector = createPlacemarkLineStyleMap(placemark, normalStyle, highlightStyle);
Method:
public kmlDom.StyleSelector createPlacemarkLineStyleMap ( kmlDom.Placemark placemark , kmlDom.Style normalStyle , kmlDom.Style highlightStyle )
{
// Set up style map
kmlDom.StyleMapCollection styleMapCollection = new kmlDom.StyleMapCollection( );
styleMapCollection.Id = String.Format( "{0}-stylemap" , placemark.placemarkName );
// Create the normal line pair
kmlDom.Pair normalPair = new kmlDom.Pair();
normalPair.StyleUrl = new Uri(String.Format("#{0}", normalStyle.Id), UriKind.Relative);
normalPair.State = kmlDom.StyleState.Normal;
// Create the highlight line pair
kmlDom.Pair highlightPair = new kmlDom.Pair( );
highlightPair.StyleUrl = new Uri( String.Format( "#{0}" , highlightStyle.Id ) , UriKind.Relative );
highlightPair.State = kmlDom.StyleState.Highlight;
// Attach both pairs to the map
styleMapCollection.Add( normalPair);
styleMapCollection.Add( highlightPair );
return styleMapCollection;
}
Why I have kmlDom, kmlBase, and kmlEngine in front of my object types
** My usings are as follows to separate sharpkml objects from my own internal objects
using kmlBase = SharpKml.Base;
using kmlDom = SharpKml.Dom;
using kmlEngine = SharpKml.Engine;
I have been trying to bring back 20 results of images using the Bing API. Here's the code:
SearchRequest request = new SearchRequest();
request.AppId = APPID;
request.Query = HttpUtility.HtmlEncode(searchQuery);
request.Sources = new SourceType[] { SourceType.Image };
request.Image = new ImageRequest();
request.Image.Count = 20;
request.Image.Filters = new string[1] { "Size:Medium" };
Now everything on here works, including the Image.Filters property. Just not the Count property. Is there a known bug or am I just missing something here?
I'm not sure really sure about this but I think you are missing setting CountSpecified property. Try this
request.Image = new ImageRequest();
request.Image.Offset = 0;
request.Image.Count = 20;
request.Image.CountSpecified = true;
request.Image.Filters = new string[1] { "Size:Medium" };