Update Default Root Object of Cloud front Distribution in C# - c#

I have a simple C# windows forms app. What I am trying to accomplish is modify the Default Root Object of one of my Cloud front Distributions. I can't seem to find any related articles that describes how this is accomplished. Please help

After alot of trial and error Here's the C# code to update an AWS cloud front distribution. You will need AWS's new modularized assemblies. AWSSKD.Core v3 & AWSSDK.Cloudfront.
First you need to get the current Distribution for 2 reasons. Mostly for validation you'll need to grab the Etag and Caller Reference. Etag to var and Caller Reference to string.
var client2 = new AmazonCloudFrontClient();
var tag = client2.GetDistributionConfig(new GetDistributionConfigRequest
{
Id = "YOURDISTID"
}).ETag;
string cf = client2.GetDistributionConfig(new GetDistributionConfigRequest
{
Id = "YOURDISTID"
}).DistributionConfig.CallerReference;
client2.Dispose();
Next you will need to make a update to the distribution. What I have below is the minimally required to update a distribution (Pretty much Everything you see in the AWS console when editing a distribution.
Take notice of where tag variable and cf string are used. If the Etag's do not match you will get 400 bad request back.
var client = new AmazonCloudFrontClient();
client.UpdateDistribution(new UpdateDistributionRequest
{
Id = "YOURDISTID",
DistributionConfig = new DistributionConfig
{
WebACLId = "",
HttpVersion = "http2",
IsIPV6Enabled = true,
DefaultRootObject = "maintenance.html",
CacheBehaviors = new CacheBehaviors {
Quantity = 0,
},
Restrictions = new Restrictions {
GeoRestriction = new GeoRestriction
{
Quantity = 0,
RestrictionType = "none"
}
},
CustomErrorResponses = new CustomErrorResponses {
Quantity = 0
},
ViewerCertificate = new ViewerCertificate {
SSLSupportMethod = "sni-only",
ACMCertificateArn = "YOUR_IMPORTED_CERT_ARN",
MinimumProtocolVersion = "TLSv1.1_2016"
},
Enabled = true,
Comment = "Maintenance",
Origins = new Origins
{
Items = new List<Origin>() {
new Origin(){Id = "S3-example.example.com", DomainName = "example.example.com.s3.amazonaws.com", S3OriginConfig = new S3OriginConfig(){ OriginAccessIdentity = "" }, OriginPath = "", CustomHeaders = new CustomHeaders{ Quantity = 0 } }
},
Quantity = 1
},
Logging = new Amazon.CloudFront.Model.LoggingConfig
{
Bucket = "example.example.com.s3.amazonaws.com",
IncludeCookies = false,
Enabled = false,
Prefix = ""
},
PriceClass = "PriceClass_All",
Aliases = new Aliases
{
Quantity = 1,
Items = list
},
CallerReference = cf,
DefaultCacheBehavior = new DefaultCacheBehavior
{
ForwardedValues = new ForwardedValues
{
QueryString = false,
QueryStringCacheKeys = new QueryStringCacheKeys {
Quantity = 0
},
Headers = new Headers {
Quantity = 0
},
Cookies = new CookiePreference
{
Forward = "none"
}
},
AllowedMethods = new AllowedMethods {
Quantity = 2,
Items = httpmeth,
CachedMethods = new CachedMethods
{
Quantity = 2,
Items = httpmeth
}
},
DefaultTTL = 86400,
Compress = false,
MaxTTL = 31536000,
TargetOriginId = "S3-example.example.com",
LambdaFunctionAssociations = new LambdaFunctionAssociations {
Quantity = 0
},
ViewerProtocolPolicy = "allow-all",
MinTTL = 0,
SmoothStreaming = false,
TrustedSigners = new TrustedSigners
{
Enabled = false,
Quantity = 0,
},
}
},
IfMatch = tag
});
client.Dispose();
If you have issues with ACMCertificationARN not being found in the reference Assembly chances are you are using the old v2 AWSSDK. Remove\Uninstall it. Get the latest Nuget Package for AWSSKD.Core & AWSSDK.CloudFront
Nuget Package Manager Console Install:
Install-Package AWSSDK.Core -Version 3.3.21.17
Install-Package AWSSDK.CloudFront -Version 3.3.6.3

Related

How can i disable series animation in highchart tree map?

I wrote the following code to disable the series animation :
Animation = new Animation{Enabled = false},
But after runing my application , the problem still persists.
My code to display the treemap is as follows:
#{ var chartOptions =
new Highcharts
{
Title = new Title
{
Text = ""
},
Credits = new Credits
{
Enabled = false
},
Series = new List<Series>
{
new TreemapSeries
{
Animation = new Animation{Enabled = false},
LayoutAlgorithm = TreemapSeriesLayoutAlgorithm.Squarified,
AlternateStartingDirection = true,
Levels = new List<TreemapSeriesLevels>
{
new TreemapSeriesLevels
{
Level = 1,
LayoutAlgorithm = TreemapSeriesLevelsLayoutAlgorithm.Squarified,
DataLabels = new TreemapSeriesDataLabels()
{
Enabled = true,
Align = TreemapSeriesDataLabelsAlign.Left,
VerticalAlign = TreemapSeriesDataLabelsVerticalAlign.Top
}
}
},
Data = #ViewBag.resultGreen
,
}
}
};
chartOptions.ID = "chart";
chartOptions.PlotOptions.Series.Animation.Enabled = false;
var renderer = new HighchartsRenderer(chartOptions);
}
#Html.Raw(renderer.RenderHtml())
How can i solve this problems?
I tried to solve this problem by the link below:
How to disable animations on Highcharts Dotnet C# MVC?
The provided answer in the mentioned thread looks to be related to DotNet.Highcharts. If you use the official Highcharts .NET wrapper use the AnimationBool option:
new TreemapSeries
{
AnimationBool = false,
...
}
API Reference:
https://dotnet.highcharts.com/Help/Highcharts/html/class_highsoft_1_1_web_1_1_mvc_1_1_charts_1_1_treemap_series.html#a3b53a65560c6917e7ee52e1779335b2e

Stripe - how add connected account on the subscription (application fee amount)?

I try add subscription method to my project where customer can subscription product from other user. But i have problem because when i use it:
LineItems = new List<SessionLineItemOptions>
{
new SessionLineItemOptions
{
Price = "{{PRICE_ID}}",
Quantity = 1,
},
},
Mode = "subscription",
SuccessUrl = "https://example.com/success",
CancelUrl = "https://example.com/cancel",
PaymentIntentData = new SessionPaymentIntentDataOptions
{
ApplicationFeeAmount = 123,
},
};
var requestOptions = new RequestOptions
{
StripeAccount = "{{CONNECTED_ACCOUNT_ID}}",
};
var service = new SessionService();
Session session = service.Create(options, requestOptions);
But I have error „You can not pass payment_intent_data in subscription mode".
Can i add application fee amount with linked account to subscription? Is payment usually the only option?
PS. I create my product like this:
var options = new ProductCreateOptions
{
Name = "new product",
DefaultPriceData = new ProductDefaultPriceDataOptions
{
UnitAmount = price,
Currency = "pln"
},
Expand = new List<string> { "default_price" }
};
var requestOptions = new RequestOptions
{
StripeAccount = stripeAccountId,
};
_productService.Create(options, requestOptions);
You'd use https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-subscription_data-application_fee_percent instead.
var options = new Stripe.Checkout.SessionCreateOptions
{
...
SubscriptionData = new Stripe.Checkout.SessionSubscriptionDataOptions
{
ApplicationFeePercent = 10
},
};
...

Setting the IGNITE_SQL_MERGE_TABLE_MAX_SIZE setting while starting Apache Ignite

I am getting a query exception SQL Error [1] [50000]: General error: "class org.apache.ignite.IgniteException: Fetched result set was too large. IGNITE_SQL_MERGE_TABLE_MAX_SIZE(10000) should be increased.
I am running Ignite embedded within my .net application
Unable to identify how to change this setting in the ignite configuration when starting ignite within a .net application
igniteConfiguration = new IgniteConfiguration
{
DataStorageConfiguration = new DataStorageConfiguration
{
StoragePath = storagePath,
DefaultDataRegionConfiguration = new DataRegionConfiguration
{
Name = "Default_Region",
PersistenceEnabled = true,
InitialSize = 100L * 1024L * 1024L,
MaxSize = 500L * 1024L * 1024L,
MetricsRateTimeInterval = TimeSpan.FromMinutes(5)
}
},
AuthenticationEnabled = true,
Logger = new IgniteLog4NetLogger(log),
ConsistentId = hostname,
IgniteInstanceName = hostname,
ClientMode = false,
JvmOptions = new[] { "-Xms512m", "-Xmx512m" },
BinaryConfiguration = new Apache.Ignite.Core.Binary.BinaryConfiguration(new Type[]
{
typeof(XYZ),
}),
MetricsLogFrequency = TimeSpan.FromMinutes(5),
};
You can set the option using JvmOptions property, as shown in the example below:
igniteConfiguration = new IgniteConfiguration
{
...
JvmOptions = new[] { "-Xms512m", "-Xmx512m", "-DIGNITE_SQL_MERGE_TABLE_MAX_SIZE=10000" },
...
};
Also, you can find additional details regarding .NET configuration options here.

Creating a bulk delete job in Dynamics 365 using the api results in an error saying synchronous bulk delete is not supported for the entity

I'm trying to create a bulk delete job in Dynamics 365 using the web api. As reference I've used the following web pages:
https://learn.microsoft.com/en-us/dynamics365/customer-engagement/web-api/bulkdelete?view=dynamics-ce-odata-9
Unable to call the BulkDelete action from Microsoft Dynamics CRM WebAPI
I'm using api-version 9.1.
I've gotten most of it to work and have removed quite a few validation errors, so I know I'm on the right track. However, now I get the following error message: "The Entity bookableresourcebooking does not support Synchronous Bulk Delete".
When I try to create the same bulk delete job manually in Dynamics, no errors occur.
Can anyone help me resolve this error?
The relevant code I'm using:
var relativeUrl = "BulkDelete()";
var bulkDelete = new BulkDeleteRequest("Delete all future bookings");
var querySet = new QuerySet();
querySet.EntityName = "bookableresourcebooking";
querySet.Distinct = false;
var conditionStarttimeGreaterEqualToday = new Condition();
conditionStarttimeGreaterEqualToday.AttributeName = "starttime";
conditionStarttimeGreaterEqualToday.Operator = "OnOrAfter";
conditionStarttimeGreaterEqualToday.Values = new List<ValueClass>();
conditionStarttimeGreaterEqualToday.Values.Add(new ValueClass(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day).ToUniversalTime().ToString("o"), "System.DateTime"));
var conditionVoltooidOpEmpty = new Condition();
conditionVoltooidOpEmpty.AttributeName = "new_voltooidop";
conditionVoltooidOpEmpty.Operator = "Null";
conditionVoltooidOpEmpty.Values = new List<ValueClass>();
querySet.Criteria = new Criteria();
querySet.Criteria.FilterOperator = "And";
querySet.Criteria.Conditions.Add(conditionStarttimeGreaterEqualToday);
querySet.Criteria.Conditions.Add(conditionVoltooidOpEmpty);
bulkDelete.QuerySet.Add(querySet);
await _crmClient.PostCRMData(relativeUrl, JsonConvert.SerializeObject(bulkDelete)); //Dependency injected httpclient.
Extra info:
bookableresourcebooking is a standard entity that comes with Field Service
new_voltooidop up is a custom datetime field I've added to this entity
We have to make this job asynchronous and for that we have to pass RunNow: false. Then this error will disappear.
I have tested this working code in CRM REST Builder. But this is JS equivalent.
var parameters = {};
var queryset1 = {
EntityName: "account",
ColumnSet: {
AllColumns: true
},
Distinct: false,
};
queryset1["#odata.type"] = "Microsoft.Dynamics.CRM.QueryExpression";
parameters.QuerySet = [queryset1];
parameters.JobName = "arun test";
parameters.SendEmailNotification = false;
var torecipients1 = {};
torecipients1.activitypartyid = "00000000-0000-0000-0000-000000000000"; //Delete if creating new record
torecipients1["#odata.type"] = "Microsoft.Dynamics.CRM.activityparty";
parameters.ToRecipients = [torecipients1];
var ccrecipients1 = {};
ccrecipients1.activitypartyid = "00000000-0000-0000-0000-000000000000"; //Delete if creating new record
ccrecipients1["#odata.type"] = "Microsoft.Dynamics.CRM.activityparty";
parameters.CCRecipients = [ccrecipients1];
parameters.RecurrencePattern = "FREQ=DAILY;";
parameters.StartDateTime = JSON.stringify(new Date("05/07/2021 13:30:00").toISOString());
parameters.RunNow = false;
var bulkDeleteRequest = {
QuerySet: parameters.QuerySet,
JobName: parameters.JobName,
SendEmailNotification: parameters.SendEmailNotification,
ToRecipients: parameters.ToRecipients,
CCRecipients: parameters.CCRecipients,
RecurrencePattern: parameters.RecurrencePattern,
StartDateTime: parameters.StartDateTime,
RunNow: parameters.RunNow,
getMetadata: function() {
return {
boundParameter: null,
parameterTypes: {
"QuerySet": {
"typeName": "Collection(mscrm.QueryExpression)",
"structuralProperty": 4
},
"JobName": {
"typeName": "Edm.String",
"structuralProperty": 1
},
"SendEmailNotification": {
"typeName": "Edm.Boolean",
"structuralProperty": 1
},
"ToRecipients": {
"typeName": "Collection(mscrm.activityparty)",
"structuralProperty": 4
},
"CCRecipients": {
"typeName": "Collection(mscrm.activityparty)",
"structuralProperty": 4
},
"RecurrencePattern": {
"typeName": "Edm.String",
"structuralProperty": 1
},
"StartDateTime": {
"typeName": "Edm.DateTimeOffset",
"structuralProperty": 1
},
"RunNow": {
"typeName": "Edm.Boolean",
"structuralProperty": 1
}
},
operationType: 0,
operationName: "BulkDelete"
};
}
};
Xrm.WebApi.online.execute(bulkDeleteRequest).then(
function success(result) {
if (result.ok) {
var results = JSON.parse(result.responseText);
}
},
function(error) {
Xrm.Utility.alertDialog(error.message);
}
);

InMemoryConnection Elasticsearch jsonSerializationException in nest version 6.x

With NEST version 6.x and NEST.JSonSerializer version 6.x, I am getting JSONSerialization exception, with inMemory elasticsearch for unit test.
I tried with Nest and JsonSersializer versions 7.x, and it was working fine. But my production server has 6.x versions, so I need to run the test on 6.x NEST Client.
var response = new
{
took = 1,
timed_out = false,
_shards = new
{
total = 2,
successful = 2,
failed = 0
},
hits = new
{
total = new { value = 25 },
max_score = 1.0,
hits = Enumerable.Range(1, 25).Select(i => (object)new
{
_index = "project",
_type = "project",
_id = $"Project {i}",
_score = 1.0,
_source = new { name = $"Project {i}" }
}).ToArray()
}
};
var responseBytes = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(response));
var connection = new InMemoryConnection(responseBytes, 200);
var connectionPool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
var settings = new ConnectionSettings(connectionPool,connection).DefaultIndex("project");
settings.DisableDirectStreaming();
var client = new ElasticClient(settings);
var searchResponse = client.Search<Project>(s => s.MatchAll());
Expected output: response from inMemory elasticsearch
Getting Error:
JsonSerializationException: Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Int64' because the type requires a JSON primitive value (e.g. string, number, boolean, null) to deserialize correctly.
Schema of total part in the response body changed between versions 6.x and 7.x of elasticsearch. If you want to make your response body working with NEST 6.x you will need to change total part from
..
total = new { value = 25 },
..
to
..
total = 25,
..
Full example:
var response = new
{
took = 1,
timed_out = false,
_shards = new
{
total = 2,
successful = 2,
failed = 0
},
hits = new
{
total = 25,
max_score = 1.0,
hits = Enumerable.Range(1, 25).Select(i => (object)new
{
_index = "project",
_type = "project",
_id = $"Project {i}",
_score = 1.0,
_source = new { name = $"Project {i}" }
}).ToArray()
}
};
Hope that helps.

Categories