本文整理汇总了C#中PatchRequest类的典型用法代码示例。如果您正苦于以下问题:C# PatchRequest类的具体用法?C# PatchRequest怎么用?C# PatchRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PatchRequest类属于命名空间,在下文中一共展示了PatchRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RunSample
protected override void RunSample()
{
// ### Api Context
// Pass in a `APIContext` object to authenticate
// the call and to send a unique request id
// (that ensures idempotency). The SDK generates
// a request id if you do not pass one explicitly.
// See [Configuration.cs](/Source/Configuration.html) to know more about APIContext.
var apiContext = Configuration.GetAPIContext();
// A resource representing a credit card that can be used to fund a payment.
var card = new CreditCard()
{
expire_month = 11,
expire_year = 2018,
number = "4877274905927862",
type = "visa"
};
#region Track Workflow
//--------------------
this.flow.AddNewRequest("Create credit card", card);
//--------------------
#endregion
// Creates the credit card as a resource in the PayPal vault. The response contains an 'id' that you can use to refer to it in the future payments.
var createdCard = card.Create(apiContext);
#region Track Workflow
//--------------------
this.flow.RecordResponse(createdCard);
//--------------------
#endregion
// Create a `PatchRequest` that will define the fields to be updated in the credit card resource.
var patchRequest = new PatchRequest
{
new Patch
{
op = "replace",
path = "/expire_month",
value = 12
}
};
#region Track Workflow
//--------------------
this.flow.AddNewRequest("Update credit card", patchRequest);
//--------------------
#endregion
// Update the credit card.
var updatedCard = createdCard.Update(apiContext, patchRequest);
#region Track Workflow
//--------------------
this.flow.RecordResponse(updatedCard);
//--------------------
#endregion
}
示例2: CanConvertToAndFromJsonWithNestedPatchRequests
public void CanConvertToAndFromJsonWithNestedPatchRequests()
{
var patch = new PatchRequest
{
Name = "Comments",
Type = PatchCommandType.Modify,
Position = 0,
Nested = new[]
{
new PatchRequest
{
Name = "AuthorId",
Type = PatchCommandType.Set,
Value = "authors/456"
},
new PatchRequest
{
Name = "AuthorName",
Type = PatchCommandType.Set,
Value = "Tolkien"
},
}
};
var jsonPatch = patch.ToJson();
var backToPatch = PatchRequest.FromJson(jsonPatch);
Assert.Equal(patch.Name, backToPatch.Name);
Assert.Equal(patch.Nested.Length, backToPatch.Nested.Length);
}
示例3: CreateBillingPlan
public static Plan CreateBillingPlan(string name, string description, string baseUrl)
{
var returnUrl = baseUrl + "/Home/SubscribeSuccess";
var cancelUrl = baseUrl + "/Home/SubscribeCancel";
// Plan Details
var plan = CreatePlanObject("Test Plan", "Plan for Tuts+", returnUrl, cancelUrl,
PlanInterval.Month, 1, (decimal)19.90, trial: true, trialLength: 1, trialPrice: 0);
// PayPal Authentication tokens
var apiContext = PayPalConfiguration.GetAPIContext();
// Create plan
plan = plan.Create(apiContext);
// Activate the plan
var patchRequest = new PatchRequest()
{
new Patch()
{
op = "replace",
path = "/",
value = new Plan() { state = "ACTIVE" }
}
};
plan.Update(apiContext, patchRequest);
return plan;
}
示例4: Apply
public RavenJObject Apply(PatchRequest[] patch)
{
foreach (var patchCmd in patch)
{
Apply(patchCmd);
}
return document;
}
示例5: UpdateByIndex
public RavenJArray UpdateByIndex(string indexName, IndexQuery queryToUpdate, PatchRequest[] patchRequests, bool allowStale)
{
return PerformBulkOperation(indexName, queryToUpdate, allowStale, (docId, tx) =>
{
var patchResult = database.ApplyPatch(docId, null, patchRequests, tx);
return new { Document = docId, Result = patchResult };
});
}
示例6: UpdateByIndex
public RavenJArray UpdateByIndex(string indexName, IndexQuery queryToUpdate, PatchRequest[] patchRequests, BulkOperationOptions options = null)
{
return PerformBulkOperation(indexName, queryToUpdate, options, (docId, tx) =>
{
var patchResult = database.Patches.ApplyPatch(docId, null, patchRequests, tx);
return new { Document = docId, Result = patchResult };
});
}
示例7: PatchUser
public HttpResponseMessage PatchUser(Int32 userId, PatchRequest<UserDto> patchRequest)
{
return GetUsersFromCache()
.Bind(users => GetUserById(userId)
.Bind(user => patchRequest.Patch(user))
.Let(patchResult => UpdateUserCollection(users)))
.ToHttpResponseMessage(Request, HttpStatusCode.NoContent);
}
示例8: RenameProperty
private void RenameProperty(PatchRequest patchCmd, string propName, RavenJToken property)
{
EnsurePreviousValueMatchCurrentValue(patchCmd, property);
if (property == null)
return;
document[patchCmd.Value.Value<string>()] = property;
document.Remove(propName);
}
示例9: ApplyPatch
public PatchResultData ApplyPatch(string docId, Etag etag, PatchRequest[] patchDoc,
TransactionInformation transactionInformation, bool debugMode = false)
{
if (docId == null)
throw new ArgumentNullException("docId");
return ApplyPatchInternal(docId, etag, transactionInformation,
jsonDoc => new JsonPatcher(jsonDoc.ToJson()).Apply(patchDoc),
() => null, () => null, debugMode);
}
示例10: Create
public ActionResult Create(BillingPlan billingPlan)
{
if (ModelState.IsValid)
{
var apiContext = Common.GetApiContext();
var plan = new Plan();
plan.description = billingPlan.Description;
plan.name = billingPlan.Name;
plan.type = billingPlan.PlanType;
plan.merchant_preferences = new MerchantPreferences
{
initial_fail_amount_action = "CANCEL",
max_fail_attempts = "3",
cancel_url = "http://localhost:50728/plans",
return_url = "http://localhost:50728/plans"
};
plan.payment_definitions = new List<PaymentDefinition>();
var paymentDefinition = new PaymentDefinition();
paymentDefinition.name = "Standard Plan";
paymentDefinition.amount = new Currency { currency = "USD", value = billingPlan.Amount.ToString() };
paymentDefinition.frequency = billingPlan.Frequency.ToString();
paymentDefinition.type = "REGULAR";
paymentDefinition.frequency_interval = "1";
if (billingPlan.NumberOfCycles.HasValue)
{
paymentDefinition.cycles = billingPlan.NumberOfCycles.Value.ToString();
}
plan.payment_definitions.Add(paymentDefinition);
var created = plan.Create(apiContext);
if (created.state == "CREATED")
{
var patchRequest = new PatchRequest();
patchRequest.Add(new Patch { path = "/", op = "replace", value = new Plan() { state = "ACTIVE" } });
created.Update(apiContext, patchRequest);
}
TempData["success"] = "Billing plan created.";
return RedirectToAction("Index");
}
AddDropdowns();
return View(billingPlan);
}
示例11: CanConvertToAndFromJsonWithEmptyNestedPatchRequests
public void CanConvertToAndFromJsonWithEmptyNestedPatchRequests()
{
var patch = new PatchRequest
{
Name = "Comments",
Type = PatchCommandType.Modify,
Position = 0,
Nested = new PatchRequest[] { }
};
var jsonPatch = patch.ToJson();
var backToPatch = PatchRequest.FromJson(jsonPatch);
Assert.Equal(patch.Name, backToPatch.Name);
Assert.Equal(patch.Nested.Length, backToPatch.Nested.Length);
}
示例12: Apply
private void Apply(PatchRequest patchCmd)
{
if (patchCmd.Name == null)
throw new InvalidOperationException("Patch property must have a name property");
foreach (var result in document.SelectTokenWithRavenSyntaxReturningFlatStructure( patchCmd.Name ))
{
var token = result.Item1;
var parent = result.Item2;
switch (patchCmd.Type)
{
case PatchCommandType.Set:
SetProperty(patchCmd, patchCmd.Name, token);
break;
case PatchCommandType.Unset:
RemoveProperty(patchCmd, patchCmd.Name, token, parent);
break;
case PatchCommandType.Add:
AddValue(patchCmd, patchCmd.Name, token);
break;
case PatchCommandType.Insert:
InsertValue(patchCmd, patchCmd.Name, token);
break;
case PatchCommandType.Remove:
RemoveValue(patchCmd, patchCmd.Name, token);
break;
case PatchCommandType.Modify:
// create snapshot of property
token.EnsureCannotBeChangeAndEnableSnapshotting();
token = token.CreateSnapshot();
document[patchCmd.Name] = token;
ModifyValue(patchCmd, patchCmd.Name, token);
break;
case PatchCommandType.Inc:
IncrementProperty(patchCmd, patchCmd.Name, token);
break;
case PatchCommandType.Copy:
CopyProperty(patchCmd, token);
break;
case PatchCommandType.Rename:
RenameProperty(patchCmd, patchCmd.Name, token);
break;
default:
throw new ArgumentException(string.Format("Cannot understand command: '{0}'", patchCmd.Type));
}
}
}
示例13: Apply
private void Apply(PatchRequest patchCmd)
{
if (patchCmd.Name == null)
throw new InvalidOperationException("Patch property must have a name property");
foreach (var result in document.SelectTokenWithRavenSyntaxReturningFlatStructure( patchCmd.Name ))
{
var token = result.Item1;
var parent = result.Item2;
switch (patchCmd.Type)
{
case PatchCommandType.Set:
SetProperty(patchCmd, patchCmd.Name, token as RavenJValue);
break;
case PatchCommandType.Unset:
RemoveProperty(patchCmd, patchCmd.Name, token, parent);
break;
case PatchCommandType.Add:
AddValue(patchCmd, patchCmd.Name, token);
break;
case PatchCommandType.Insert:
InsertValue(patchCmd, patchCmd.Name, token);
break;
case PatchCommandType.Remove:
RemoveValue(patchCmd, patchCmd.Name, token);
break;
case PatchCommandType.Modify:
ModifyValue(patchCmd, patchCmd.Name, token);
break;
case PatchCommandType.Inc:
IncrementProperty(patchCmd, patchCmd.Name, token);
break;
case PatchCommandType.Copy:
CopyProperty(patchCmd, patchCmd.Name, token);
break;
case PatchCommandType.Rename:
RenameProperty(patchCmd, patchCmd.Name, token);
break;
default:
throw new ArgumentException("Cannot understand command: " + patchCmd.Type);
}
}
}
示例14: AgreementCreateTest
public void AgreementCreateTest()
{
try
{
var apiContext = TestingUtil.GetApiContext();
this.RecordConnectionDetails();
// Create a new plan.
var plan = PlanTest.GetPlan();
var createdPlan = plan.Create(apiContext);
this.RecordConnectionDetails();
// Activate the plan.
var patchRequest = new PatchRequest()
{
new Patch()
{
op = "replace",
path = "/",
value = new Plan() { state = "ACTIVE" }
}
};
createdPlan.Update(apiContext, patchRequest);
this.RecordConnectionDetails();
// Create an agreement using the activated plan.
var agreement = GetAgreement();
agreement.plan = new Plan() { id = createdPlan.id };
agreement.shipping_address = null;
var createdAgreement = agreement.Create(apiContext);
this.RecordConnectionDetails();
Assert.IsNull(createdAgreement.id);
Assert.IsNotNull(createdAgreement.token);
Assert.AreEqual(agreement.name, createdAgreement.name);
}
catch(ConnectionException)
{
this.RecordConnectionDetails(false);
throw;
}
}
示例15: Activate
public ActionResult Activate(string id)
{
if (!string.IsNullOrEmpty(id))
{
var apiContext = Common.GetApiContext();
var plan = Plan.Get(apiContext, id);
if (plan != null && plan.state == "CREATED")
{
var patchRequest = new PatchRequest();
var tempPlan = new Plan();
tempPlan.state = "ACTIVE";
patchRequest.Add(new Patch { path = "/", op = "replace", value = tempPlan });
plan.Update(apiContext, patchRequest);
TempData["success"] = "Plan activated";
}
}
return RedirectToAction("Index");
}