当前位置: 首页>>代码示例>>C#>>正文


C# PatchRequest类代码示例

本文整理汇总了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
        }
开发者ID:GHLabs,项目名称:PayPal-NET-SDK,代码行数:60,代码来源:CreditCardUpdate.aspx.cs

示例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);
		}		
开发者ID:925coder,项目名称:ravendb,代码行数:29,代码来源:Patching.cs

示例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;
        }
开发者ID:tutsplus,项目名称:paypal-integration,代码行数:29,代码来源:PayPalSubscriptionsService.cs

示例4: Apply

		public RavenJObject Apply(PatchRequest[] patch)
		{
			foreach (var patchCmd in patch)
			{
				Apply(patchCmd);
			}
			return document;
		}
开发者ID:neiz,项目名称:ravendb,代码行数:8,代码来源:JsonPatcher.cs

示例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 };
			});
		}
开发者ID:jtmueller,项目名称:ravendb,代码行数:8,代码来源:DatabaseBulkOperations.cs

示例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 };
			});
		}
开发者ID:bbqchickenrobot,项目名称:ravendb,代码行数:8,代码来源:DatabaseBulkOperations.cs

示例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);
 }
开发者ID:Cephei,项目名称:Apistry,代码行数:8,代码来源:UsersController.cs

示例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);
		}
开发者ID:neiz,项目名称:ravendb,代码行数:9,代码来源:JsonPatcher.cs

示例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);
 }
开发者ID:randacc,项目名称:ravendb,代码行数:9,代码来源:PatchActions.cs

示例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);
        }
开发者ID:malevolence,项目名称:PayPalTesting,代码行数:51,代码来源:PlansController.cs

示例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);
		}
开发者ID:925coder,项目名称:ravendb,代码行数:15,代码来源:Patching.cs

示例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));
				}
			}
		}
开发者ID:kpantos,项目名称:ravendb,代码行数:46,代码来源:JsonPatcher.cs

示例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);
				}
			}
		}
开发者ID:kblooie,项目名称:ravendb,代码行数:42,代码来源:JsonPatcher.cs

示例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;
            }
        }
开发者ID:ruanzx,项目名称:PayPal-NET-SDK,代码行数:42,代码来源:AgreementTest.cs

示例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");
        }
开发者ID:malevolence,项目名称:PayPalTesting,代码行数:20,代码来源:PlansController.cs


注:本文中的PatchRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。