Ejemplo n.º 1
0
 public void CanSetUnknownProperties()
 {
     dynamic delta = new Delta<SimpleMessageA>();
     delta.Data = "Blah";
     delta.SomeUnknown = "yes";
     Assert.Equal(1, delta.UnknownProperties.Count);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns the Greek object for a given Greek name
        /// </summary>
        /// <param name="greek">Greek name</param>
        /// <param name="option">Option object</param>
        /// <returns></returns>
        public static IGreek Create(GreekName greek, IOption option)
        {
            IGreek calculatedGreek = null;

            switch (greek)
            {
                case GreekName.Delta:
                    calculatedGreek = new Delta(option);
                    break;
                case GreekName.Gamma:
                    calculatedGreek = new Gamma(option);
                    break;
                case GreekName.Theta:
                    calculatedGreek = new Theta(option);
                    break;
                case GreekName.Vega:
                    calculatedGreek = new Vega(option);
                    break;
                case GreekName.Rho:
                    calculatedGreek = new Rho(option);
                    break;
                default:
                    break;
            }

            return calculatedGreek;
        }
 public override void Update(Delta delta)
 {
     scriptStartTimer += delta.Time;
     if (scriptStartTimer >= scriptStartTime)
     {
         scriptRunner.Update(delta);
         if (scriptRunner.IsFinished())
             Finish();
     }
 }
 private void updatePlayerInvincibilityFlashing(Delta delta)
 {
     flashTimer += delta.Time;
     if (flashTimer >= flashTime)
     {
         flashTimer = 0.0f;
         alphaFull = !alphaFull;
         playerOverworldEntity.Tint = Color.White * (alphaFull ? 1.0f : 0.6f);
     }
 }
Ejemplo n.º 5
0
        public void CanPatchUnrelatedTypes() {
            dynamic delta = new Delta<SimpleMessageA>();
            delta.Data = "Blah";

            var msg = new SimpleMessageB {
                Data = "Blah2"
            };
            delta.Patch(msg);

            Assert.Equal(delta.Data, msg.Data);
        }
Ejemplo n.º 6
0
        public override void Update(Delta delta)
        {
            handlePlayerMovement(delta);
            foreach (NpcMover npcMover in npcMovers)
                npcMover.Update(delta);

            if (!Overworld.PlayerIsInvincible)
                handleEnemyCollisions();

            Overworld.UpdateInvincibility(delta);
        }
 public override void Update(Delta delta)
 {
     if (scriptRunner == null)
         Finish();
     else
     {
         scriptRunner.Update(delta);
         if (scriptRunner.IsFinished())
             Finish();
     }
 }
 private LogEntry GetEntry(Delta.CertXplorer.Extensibility.Logging.LogEntry entry, string source)
 {
     return new LogEntry()
     {
         Exception = entry.Exception,
         Level = GetLevel(entry.Level),
         Message = entry.Message,
         SourceName = source,
         Tag = entry.Tag,
         TimeStamp = entry.TimeStamp
     };
 }
Ejemplo n.º 9
0
 public PSFDescription GeneratePSF(int maxRadius)
 {
     PSFDescription psf = new PSFDescription();
     psf.deltasByRadius = new Delta[maxRadius + 1][];
     for (int radius = 0; radius < maxRadius + 1; radius++)
     {
         Delta[] deltas = new Delta[2];
         deltas[0] = new Delta(-radius, 0, 1);
         deltas[1] = new Delta(radius + 1, 0, -1);
         psf.deltasByRadius[radius] = deltas;
     }
     return psf;
 }
 public override void Update(Delta delta)
 {
     if (overworldState.Overworld.PlayerIsInvincible)
     {
         updatePlayerInvincibilityFlashing(delta);
         playerInvincibleBefore = true;
     }
     else if (playerInvincibleBefore)
     {
         playerOverworldEntity.Tint = Color.White;
         playerInvincibleBefore = false;
     }
 }
        public override void Update(Delta delta)
        {
            if (overlayAlphaTimer < overlayAlphaTime)
            {
                overlayAlphaTimer += delta.Time;
                if (overlayAlphaTimer > overlayAlphaTime)
                    overlayAlphaTimer = overlayAlphaTime;
            }

            arrowMoveTimer += delta.Time;
            if (arrowMoveTimer >= arrowMoveTime * 2.0f)
                arrowMoveTimer = 0.0f;
        }
 public void TestEmptyPropertiesValues()
 {
     //Arrange
     var simpleObject = new SimpleTestClass();
     var objectUnderTest = new Delta<SimpleTestClass>();
     //Act
     objectUnderTest.AddFilter(t => t.Prop1NotIncluded);
     objectUnderTest.Apply(simpleObject);
     //Assert
     simpleObject.Prop1NotIncluded.ShouldBeNull();
     simpleObject.Prop1.ShouldBeNull();
     simpleObject.Prop2.ShouldBeNull();
 }
 public void Update(PartyMember partyMember, Delta delta)
 {
     if (Finished)
         return;
     ShudderTimer += delta.Time;
     if (ShudderTimer >= ShudderTime)
     {
         ShudderTimer = 0.0f;
         if (++ShudderCounter > ShudderCount)
         {
             partyMember.BattleEntity.Position = PartyMemberStartPosition;
             Finished = true;
         }
     }
 }
Ejemplo n.º 14
0
        public void TestEmptyPropertiesValues()
        {
            //Arrange
            var simpleObject = new SimpleTestClass();
            var objectUnderTest = new Delta<SimpleTestClass>();

            //Act
            objectUnderTest.FilterOut(t => t.Prop1NotIncluded);
            objectUnderTest.ApplySimpleProperties(simpleObject);

            //Assert
            Assert.Null(simpleObject.Prop1NotIncluded);
            Assert.Null(simpleObject.Prop1);
            Assert.Null(simpleObject.Prop2);
        }
 public override void Update(Delta delta)
 {
     if (enemyParty != null) // if before battle
     {
         Time += delta.Time;
         if (Time >= FadeTimeInSeconds)
             PushState(new Encounter(Overworld, enemyParty));
     }
     else
     {
         Time -= delta.Time;
         if (Time <= 0.0f)
             Finish();
     }
 }
 public void Update(PartyMember partyMember, Delta delta)
 {
     particleTimer += delta.Time;
     if (particleTimer >= particleTime)
     {
         particleTimer = 0.0f;
         Rectangle boundingBox = partyMember.BattleEntity.GetBoundingBox();
         float x = boundingBox.X + (boundingBox.Width / 2) + Game1.Random.Next(boundingBox.Width / 2) - (boundingBox.Width / 4);
         float y = boundingBox.Y + (boundingBox.Height / 2) + (Game1.Random.Next(boundingBox.Height / 4) - (boundingBox.Height / 8));
         if (textureData != null)
             Scene.AddEntity(new FloatingParticle(new Vector2(x, y), new Vector2(0.0f, -200.0f), new Vector2(0.3f), 1.4f, textureData));
         else if (text != null)
             Scene.AddEntity(new FloatingText(text, textColor, new Vector2(x, y), 3.0f, true));
     }
 }
Ejemplo n.º 17
0
        public override void EndTurnUpdate(PartyMember partyMember, Delta delta)
        {
            base.EndTurnUpdate(partyMember, delta);
            Fear.UpdateShudder(partyMember, Color.DarkRed, shudderManager, delta);
            doomParticleManager.Update(Inflictor, delta);
            textParticleManager.Update(partyMember, delta);

            if (Inflictor.Alive && shudderManager.Finished)
            {
                if (++turns > durationInTurns)
                {
                    partyMember.DoDamage(partyMember.Health, true);
                    Inflictor = null;
                }
            }
        }
        public override void BeforeActUpdate(ThinkAction thinkAction, Delta delta)
        {
            base.BeforeActUpdate(thinkAction, delta);

            if (!thinkActionActivationDecided)
            {
                if (Game1.Random.Next(100) <= chanceOfEffect)
                    thinkAction.Active = false;
                thinkActionActivationDecided = true;
            }
            else if (thinkAction.Active)
                finished = true;
            else
                updateShockEffect(thinkAction.Actor, delta);

            checkFinish(thinkAction.Actor);
        }
Ejemplo n.º 19
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private java.util.List<difflib.Chunk> getChunksByType(difflib.Delta.TYPE type) throws java.io.IOException
		private IList<Chunk> getChunksByType(Delta.TYPE type)
		{
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.List<difflib.Chunk> listOfChanges = new java.util.ArrayList<difflib.Chunk>();
			IList<Chunk> listOfChanges = new List<Chunk>();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.List<difflib.Delta> deltas = getDeltas();
			IList<Delta> deltas = Deltas;
			foreach (Delta delta in deltas)
			{
				if (delta.Type == type)
				{
					listOfChanges.Add(delta.Revised);
				}
			}
			return listOfChanges;
		}
Ejemplo n.º 20
0
 public static void UpdateShudder(PartyMember partyMember, Color tint, ShudderManager shudderManager, Delta delta)
 {
     shudderManager.Update(partyMember, delta);
     if (shudderManager.Finished)
     {
         partyMember.BattleEntity.Tint = Color.White;
         partyMember.BattleEntity.PauseAnimation = false;
     }
     else
     {
         float shudderPercentage = shudderManager.ShudderTimer / shudderManager.ShudderTime;
         if (shudderManager.ShudderCounter % 2 != 0)
             shudderPercentage = 1.0f - shudderPercentage;
         partyMember.BattleEntity.Position = shudderManager.PartyMemberStartPosition + new Vector2(shudderPercentage * shudderDistance, 0.0f);
         partyMember.BattleEntity.Tint = tint;
         partyMember.BattleEntity.PauseAnimation = true;
     }
 }
        public void SimpleTestOfFunction()
        {
            //Arange
            var simpleObject = new SimpleTestClass();
            var classUnderTest = new Delta<SimpleTestClass>();

            classUnderTest.AddFilter(t => t.Prop1NotIncluded);
            classUnderTest.ObjectPropertyValues = new Dictionary<string, object>()
                                         {
                                           {"Prop2","b"}
                                         };
            //Act
            classUnderTest.Apply(simpleObject);
            //Assert
            simpleObject.Prop2.ShouldNotBeNull();
            simpleObject.Prop2.ShouldEqual("b");
            simpleObject.Prop1NotIncluded.ShouldBeNull();
        }
Ejemplo n.º 22
0
        public override void EndTurnUpdate(PartyMember partyMember, Delta delta)
        {
            base.EndTurnUpdate(partyMember, delta);

            updateTintAlpha(delta);
            particleManager.Update(partyMember, delta);

            if (!incTintAlpha && !damageDone)
            {
                int damage = partyMember.Health / 8;
                partyMember.DoDamage(damage > 0 ? damage : 1, true);
                damageDone = true;
                if (!partyMember.Alive)
                    finished = true;
            }

            partyMember.BattleEntity.Tint = finished ? Color.White : Color.Lerp(Color.White, Color.Purple, tintAlpha);
        }
Ejemplo n.º 23
0
        public override void Update(Delta delta)
        {
            if (destination == entity.Position)
            {
                thinkTime += delta.Time;
                if (thinkTime > thinkDelay)
                {
                    chooseNewDestination(delta);
                    thinkTime = 0.0f;
                }
            }
            else if (entityPositionCloseEnoughToDestination(delta))
            {
                destination = entity.Position;
                entity.Velocity = Vector2.Zero;
            }

            base.Update(delta);
        }
Ejemplo n.º 24
0
        public void SimpleTestOfFunction()
        {
            //Arange
            var simpleObject = new SimpleTestClass();
            var classUnderTest = new Delta<SimpleTestClass>();

            classUnderTest.FilterOut(t => t.Prop1NotIncluded);
            classUnderTest.ObjectPropertyValues = new Dictionary<string, object>()
                                         {
                                           {"Prop2","b"}
                                         };
            //Act
            classUnderTest.ApplySimpleProperties(simpleObject);

            //Assert
            Assert.NotNull(simpleObject.Prop2);
            Assert.Equal(simpleObject.Prop2, "b");
            Assert.Null(simpleObject.Prop1NotIncluded);
        }
        public override void Update(Delta delta)
        {
            if (currentStatusEffectIndex >= partyMember.StatusEffects.Count || !partyMember.Alive)
            {
                Finish();
                return;
            }

            bool statusEffectFinished = false;
            StatusEffect statusEffect = partyMember.StatusEffects[currentStatusEffectIndex];

            StatusEffects.IInflictable inflictable = statusEffect as StatusEffects.IInflictable;
            if (inflictable != null && (inflictable.Inflictor == null || !inflictable.Inflictor.Alive))
            {
                partyMember.StatusEffects.RemoveAt(currentStatusEffectIndex);
                --currentStatusEffectIndex;
                statusEffectFinished = true;
            }

            if (!statusEffectFinished)
            {
                switch (statusEffectEvent)
                {
                case StatusEffectEvent.BeforeAct:
                    if (statusEffect.BeforeActIsFinished())
                        statusEffectFinished = true;
                    else
                        statusEffect.BeforeActUpdate(thinkAction, delta);
                    break;
                case StatusEffectEvent.EndTurn:
                    if (statusEffect.EndTurnIsFinished())
                        statusEffectFinished = true;
                    else
                        statusEffect.EndTurnUpdate(partyMember, delta);
                    break;
                default: break;
                }
            }

            if (statusEffectFinished && partyMember.BattleEntity.AnimationState.Animation.Name == partyMember.GetBattleEntityIdleAnimationName())
                getNextStatusEffect();
        }
Ejemplo n.º 26
0
        public override void Update(Delta delta)
        {
            if (Battle.PlayerParty.Count == 0 || Battle.EnemyParty.Count == 0)
            {
                Finish();
                return;
            }
            else if (currentThinkActionFinished)
            {
                if (allPartyMembersIdle())
                    getNextThinkAction();
                return;
            }

            ThinkAction thinkAction = null;

            if (currentThinkActionType == ThinkActionType.UseItem)
            {
                if (currentThinkActionIndex >= useItemThinkActions.Count)
                {
                    currentThinkActionIndex = 0;
                    statusEffectsCompleteForAction = false;
                    currentThinkActionType = ThinkActionType.Attack;
                    return;
                }

                thinkAction = useItemThinkActions[currentThinkActionIndex];
            }
            else if (currentThinkActionType == ThinkActionType.Attack)
            {
                if (currentThinkActionIndex >= attackThinkActions.Count)
                {
                    Finish();
                    return;
                }

                thinkAction = attackThinkActions[currentThinkActionIndex];
            }

            pushStateForThinkAction(thinkAction);
        }
Ejemplo n.º 27
0
        private void chooseNewDestination(Delta delta)
        {
            const float maxDistance = 200.0f;
            Vector2 originalPosition = entity.Position;

            do
            {
                entity.Position = originalPosition;

                double distance = Game1.Random.NextDouble() * maxDistance;
                double angle = Game1.Random.NextDouble() * MathHelper.TwoPi;
                Vector2 relativePosition = new Vector2((float)(Math.Cos(angle) * distance), (float)(Math.Sin(angle) * distance));
                destination = entity.Position + relativePosition;
                relativePosition.Normalize();
                entity.Velocity = relativePosition * movementVelocity;

                entity.Position += entity.Velocity * delta.Time;
            } while (entityPositionCloseEnoughToDestination(delta));

            entity.Position = originalPosition;
        }
 public override void Update(Delta delta)
 {
     if (currentStatusEffectPartyMemberIndex < currentStatusEffectParty.Count)
     {
         if (currentStatusEffectParty[currentStatusEffectPartyMemberIndex].Alive)
             PushState(new HandleStatusEffects(Battle, StatusEffectEvent.EndTurn, partyMember: currentStatusEffectParty[currentStatusEffectPartyMemberIndex]));
         else
             ++currentStatusEffectPartyMemberIndex;
     }
     else if (currentStatusEffectParty == Battle.PlayerParty)
     {
         currentStatusEffectParty = Battle.EnemyParty;
         currentStatusEffectPartyMemberIndex = 0;
     }
     else if (clockTime < clockHourTransistionTimeInSeconds)
     {
         clockTime += delta.Time;
         Clock.Update(delta.Time / clockHourTransistionTimeInSeconds);
     }
     else
         Finish();
 }
        private LogLevel GetLevel(Delta.CertXplorer.Extensibility.Logging.LogLevel level)
        {
            switch (level)
            {
                case Delta.CertXplorer.Extensibility.Logging.LogLevel.All:
                    return LogLevel.All;
                case Delta.CertXplorer.Extensibility.Logging.LogLevel.Debug:
                    return LogLevel.Debug;
                case Delta.CertXplorer.Extensibility.Logging.LogLevel.Error:
                    return LogLevel.Error;
                case Delta.CertXplorer.Extensibility.Logging.LogLevel.Fatal:
                    return LogLevel.Fatal;
                case Delta.CertXplorer.Extensibility.Logging.LogLevel.Info:
                    return LogLevel.Info;
                case Delta.CertXplorer.Extensibility.Logging.LogLevel.Off:
                    return LogLevel.Off;
                case Delta.CertXplorer.Extensibility.Logging.LogLevel.Verbose:
                    return LogLevel.Verbose;
                case Delta.CertXplorer.Extensibility.Logging.LogLevel.Warning:
                    return LogLevel.Warning;
            }

            return LogLevel.Info; // default
        }
Ejemplo n.º 30
0
 public static Delta InsertPara(this Delta delta, string style)
 {
     return(delta.InsertPara(new JObject(new JProperty("style", style))));
 }
Ejemplo n.º 31
0
 public static Delta InsertOptBreak(this Delta delta, string segRef = null)
 {
     return(delta.InsertEmbed("optbreak", new JObject(), segRef));
 }
Ejemplo n.º 32
0
 // PATCH tables/PostTable/48D68C86-6EA6-4C25-AA33-223FC9A27959
 public Task <PostDTO> PatchPost(string id, Delta <PostDTO> patch)
 {
     return(UpdateAsync(id, patch));
 }
Ejemplo n.º 33
0
 // PATCH tables/TodoItem/48D68C86-6EA6-4C25-AA33-223FC9A27959
 public Task <TodoItem> PatchTodoItem(string id, Delta <TodoItem> patch)
 {
     return(UpdateAsync(id, patch));
 }
Ejemplo n.º 34
0
        public ITestActionResult PatchToAddress(int key, Delta <OpenAddress> address)
        {
            IList <OpenCustomer> customers = CreateCustomers();
            OpenCustomer         customer  = customers.FirstOrDefault(c => c.CustomerId == key);

            if (customer == null)
            {
                return(NotFound());
            }

            // Verify the origin address
            OpenAddress origin = customer.Address;

            VerifyOriginAddress(key, origin);

            address.Patch(origin); // Do patch

            // Verify the patched address
            Assert.Equal("UpdatedStreet", origin.Street);
            Assert.Equal("City " + key, origin.City); // not changed
            Assert.NotNull(origin.DynamicProperties);

            Assert.True(origin.DynamicProperties.Count >= 3); // Including the origin dynamic properties

            KeyValuePair <string, object> dynamicPropertyBirthDay = origin.DynamicProperties.FirstOrDefault(e => e.Key == "BirthDay");

            Assert.Equal(new Date(2016, 1, 29), dynamicPropertyBirthDay.Value);

            string dynamicPropertyToken = origin.DynamicProperties.FirstOrDefault(e => e.Key == "Token")
                                          .Value.ToString().ToUpperInvariant();

            switch (dynamicPropertyToken)
            {
            case "2E724E81-8462-4BA0-B920-DC87A61C8EA3":
                // All changed non-dynamic properties: ["Street"]
                Assert.True(address.GetChangedPropertyNames().Count() == 1);
                break;

            case "9B198CA0-9546-4162-A4C0-14EAA255ACA7":

                // All changed non-dynamic properties: ["Street", "LineB"]
                Assert.True(address.GetChangedPropertyNames().Count() == 2);

                Assert.Null(origin.LineA);

                Assert.NotNull(origin.LineB);
                Assert.Equal("DescriptionB", origin.LineB.Description);

                // Fee is not overwritten.
                Assert.Equal(LineDetails.DefaultValue_Fee, origin.LineB.Fee);
                break;

            case "A4D09554-5551-4B36-A1CB-CFBCDB1F4EAD":

                // All changed non-dynamic properties: ["Street", "LineA", "LineB"]
                Assert.True(address.GetChangedPropertyNames().Count() == 3);

                // --- LineA ---
                Assert.NotNull(origin.LineA);
                Assert.Equal("DescriptionA", origin.LineA.Description);

                // LineA.Fee is left as uninitialized.
                Assert.Equal(LineDetails.UninitializedValue_Fee, origin.LineA.Fee);

                Assert.NotNull(origin.LineA.PhoneInfo);
                Assert.Equal("ContactNameA", origin.LineA.PhoneInfo.ContactName);
                Assert.Equal(7654321, origin.LineA.PhoneInfo.PhoneNumber);

                // --- LineB ---
                Assert.NotNull(origin.LineB);
                Assert.Null(origin.LineB.Description);

                // LineB.Fee is originally initialized for OpenAddress is created for each customer.
                Assert.Equal(LineDetails.DefaultValue_Fee, origin.LineB.Fee);

                Assert.NotNull(origin.LineB.PhoneInfo);
                Assert.Equal("ContactNameB", origin.LineB.PhoneInfo.ContactName);
                Assert.Equal(0, origin.LineB.PhoneInfo.PhoneNumber);
                break;

            case "2D071BD4-E4FB-4639-8024-BBC173850441":
                // All changed non-dynamic properties: ["Street", "LineA"]
                Assert.True(address.GetChangedPropertyNames().Count() == 2);

                // --- LineA ---
                Assert.NotNull(origin.LineA);
                Assert.Equal("LineDetailsWithNewDeepSubNode.", origin.LineA.Description);
                Assert.Equal(LineDetails.UninitializedValue_Fee, origin.LineA.Fee);

                Assert.NotNull(origin.LineA.PhoneInfo);
                Assert.Equal("ContactNameA", origin.LineA.PhoneInfo.ContactName);
                Assert.Equal(0, origin.LineA.PhoneInfo.PhoneNumber);

                Assert.NotNull(origin.LineA.PhoneInfo.Spec);
                Assert.Null(origin.LineA.PhoneInfo.Spec.Make);
                Assert.Equal(6, origin.LineA.PhoneInfo.Spec.ScreenSize);

                // --- LineB ---
                Assert.NotNull(origin.LineB);
                break;

            case "250EFC6E-8FA4-4B68-951C-F1E26DE09D1D":
                Assert.True(origin.DynamicProperties.ContainsKey("Telephone"));
                // Telephone dynamic property
                Phone telephone = origin.DynamicProperties["Telephone"] as Phone;
                Assert.NotNull(telephone);
                Assert.Equal("ContactNameX", telephone.ContactName);
                Assert.Equal(13, telephone.PhoneNumber);

                // Nested complex property
                Assert.NotNull(telephone.Spec);
                Assert.Equal(7, telephone.Spec.ScreenSize);
                break;

            case "40CEEEDE-031C-45CB-9E44-E6017D635814":
                Assert.True(origin.DynamicProperties.ContainsKey("Building"));
                // Building dynamic property
                Building building = origin.DynamicProperties["Building"] as Building;
                Assert.NotNull(building);
                Assert.Equal("BuildingNameY", building.BuildingName);

                // Nested telephone complex dynamic property
                Assert.True(building.DynamicProperties.ContainsKey("Telephone"));
                Phone phone = building.DynamicProperties["Telephone"] as Phone;
                Assert.NotNull(phone);
                Assert.Equal("ContactNameZ", phone.ContactName);
                Assert.Equal(17, phone.PhoneNumber);

                // Nested complex property
                Assert.NotNull(phone.Spec);
                Assert.Equal(5, phone.Spec.ScreenSize);
                break;

            case "3CA243CF-460A-4144-B6EB-F5E1180ABDC8":
                OpenAddress addressInstance = address.GetInstance();
                Assert.NotNull(addressInstance);

                // Complex property
                Assert.NotNull(addressInstance.LineA);
                Assert.NotNull(addressInstance.LineA.PhoneInfo);
                Assert.Equal(7654321, addressInstance.LineA.PhoneInfo.PhoneNumber);

                object lineAValue;
                // Fetch LineA property using TryGetPropertyValue
                Assert.True(address.TryGetPropertyValue("LineA", out lineAValue));
                LineDetails lineA = lineAValue as LineDetails;
                Assert.NotNull(lineA);

                // Nested complex property
                Assert.NotNull(lineA.PhoneInfo);
                Assert.Equal(7654321, lineA.PhoneInfo.PhoneNumber);
                break;

            default:
                // Error
                Assert.True(false, "Unexpected token value " + dynamicPropertyToken);
                break;
            }

            return(Updated(customer));
        }
Ejemplo n.º 35
0
 // PUT: odata/Person(5)
 /// <summary>
 /// Not implemented.
 /// </summary>
 /// <param name="key"></param>
 /// <param name="delta"></param>
 /// <returns></returns>
 public new IHttpActionResult Put([FromODataUri] int key, Delta <Person> delta)
 {
     return(base.Put(key, delta));
 }
Ejemplo n.º 36
0
 public Task <Mark> PatchMark(string id, Delta <Mark> patch)
 {
     validateOwner(id);
     return(UpdateAsync(id, patch));
 }
Ejemplo n.º 37
0
        private async Task <List <Chapter> > UpdateTextDocsAsync(TextInfo text, string paratextId,
                                                                 SortedList <int, IDocument <TextData> > textDocs, ISet <int> chaptersToInclude = null)
        {
            string bookText = _paratextService.GetBookText(_userSecret, paratextId, text.BookNum);
            var    usxDoc   = XDocument.Parse(bookText);
            var    tasks    = new List <Task>();
            Dictionary <int, ChapterDelta> deltas = _deltaUsxMapper.ToChapterDeltas(usxDoc)
                                                    .ToDictionary(cd => cd.Number);
            var        chapters         = new List <Chapter>();
            List <int> chaptersToRemove = textDocs.Keys.Where(c => !deltas.ContainsKey(c)).ToList();

            foreach (KeyValuePair <int, ChapterDelta> kvp in deltas)
            {
                bool addChapter = true;
                if (textDocs.TryGetValue(kvp.Key, out IDocument <TextData> textDataDoc))
                {
                    if (chaptersToInclude == null || chaptersToInclude.Contains(kvp.Key))
                    {
                        Delta diffDelta = textDataDoc.Data.Diff(kvp.Value.Delta);
                        if (diffDelta.Ops.Count > 0)
                        {
                            tasks.Add(textDataDoc.SubmitOpAsync(diffDelta));
                        }
                        textDocs.Remove(kvp.Key);
                    }
                    else
                    {
                        // We are not to update this chapter
                        Chapter existingChapter = text.Chapters.FirstOrDefault(c => c.Number == kvp.Key);
                        if (existingChapter != null)
                        {
                            chapters.Add(existingChapter);
                        }

                        addChapter = false;
                    }
                }
                else if (chaptersToInclude == null || chaptersToInclude.Contains(kvp.Key))
                {
                    textDataDoc = GetTextDoc(text, kvp.Key);
                    async Task createText(int chapterNum, Delta delta)
                    {
                        await textDataDoc.FetchAsync();

                        if (textDataDoc.IsLoaded)
                        {
                            await textDataDoc.DeleteAsync();
                        }
                        await textDataDoc.CreateAsync(new TextData(delta));
                    }

                    tasks.Add(createText(kvp.Key, kvp.Value.Delta));
                }
                else
                {
                    addChapter = false;
                }
                if (addChapter)
                {
                    chapters.Add(new Chapter
                    {
                        Number      = kvp.Key,
                        LastVerse   = kvp.Value.LastVerse,
                        IsValid     = kvp.Value.IsValid,
                        Permissions = { }
                    });
                }
            }
            foreach (KeyValuePair <int, IDocument <TextData> > kvp in textDocs)
            {
                if (chaptersToInclude == null ||
                    chaptersToInclude.Contains(kvp.Key) ||
                    chaptersToRemove.Contains(kvp.Key))
                {
                    tasks.Add(kvp.Value.DeleteAsync());
                }
            }

            await Task.WhenAll(tasks);

            return(chapters);
        }
Ejemplo n.º 38
0
        public new IHttpActionResult Patch([FromODataUri] int key, Delta <Person> delta)
        {
            var person = Repo.AsQueryable().Single(x => x.Id == key);

            return(CurrentUser.IsAdmin || CurrentUser.Id == person.Id ? base.Patch(key, delta) : StatusCode(HttpStatusCode.Forbidden));
        }
Ejemplo n.º 39
0
 // PATCH tables/Tag/48D68C86-6EA6-4C25-AA33-223FC9A27959
 public Task <Tag> PatchTag(string id, Delta <Tag> patch) => UpdateAsync(id, patch);
Ejemplo n.º 40
0
 public Task <Course> PatchCourse(string id, Delta <Course> patch)
 {
     return(UpdateAsync(id, patch));
 }
 // PATCH tables/Travel/48D68C86-6EA6-4C25-AA33-223FC9A27959
 public Task <Travel> PatchTravel(string id, Delta <Travel> patch)
 {
     return(UpdateAsync(id, patch));
 }
 //PUT: odata/BankAccounts(5)
 /// <summary>
 /// Not implemented.
 /// </summary>
 /// <param name="key"></param>
 /// <param name="delta"></param>
 /// <returns></returns>
 public new IActionResult Put([FromODataUri] int key, Delta <BankAccount> delta)
 {
     return(base.Put(key, delta));
 }
Ejemplo n.º 43
0
 // PATCH tables/OpenQuestionAnswer/48D68C86-6EA6-4C25-AA33-223FC9A27959
 public Task <OpenQuestionAnswer> PatchOpenQuestionAnswer(string id, Delta <OpenQuestionAnswer> patch)
 {
     return(UpdateAsync(id, patch));
 }
 public new IActionResult Patch([FromODataUri] int key, Delta <BankAccount> delta)
 {
     return(CurrentUser.IsAdmin ? base.Patch(key, delta) : Unauthorized());
 }
Ejemplo n.º 45
0
        public static Delta InsertChar(this Delta delta, string text, string style, string segRef = null)
        {
            var attributes = new JObject(new JProperty("char", new JObject(new JProperty("style", style))));

            return(delta.InsertText(text, segRef, attributes));
        }
Ejemplo n.º 46
0
 public Task <Notification> PatchNotification(string id, Delta <Notification> patch)
 {
     return(UpdateAsync(id, patch));
 }
Ejemplo n.º 47
0
 private static JObject SerializeDelta(Delta delta)
 {
     return(new JObject(new JProperty("ops", new JArray(delta.Ops))));
 }
        public IActionResult UpdateOrder([ModelBinder(typeof(JsonModelBinder <OrderDto>))] Delta <OrderDto> orderDelta)
        {
            // Here we display the errors if the validation has failed at some point.
            if (!ModelState.IsValid)
            {
                return(Error());
            }

            var currentOrder = _orderApiService.GetOrderById(orderDelta.Dto.Id);

            if (currentOrder == null)
            {
                return(Error(HttpStatusCode.NotFound, "order", "not found"));
            }

            var customer = currentOrder.Customer;

            var shippingRequired = currentOrder.OrderItems.Any(item => !item.Product.IsFreeShipping);

            if (shippingRequired)
            {
                var isValid = true;

                if (!string.IsNullOrEmpty(orderDelta.Dto.ShippingRateComputationMethodSystemName) ||
                    !string.IsNullOrEmpty(orderDelta.Dto.ShippingMethod))
                {
                    var storeId = orderDelta.Dto.StoreId ?? _storeContext.CurrentStore.Id;

                    isValid &= SetShippingOption(orderDelta.Dto.ShippingRateComputationMethodSystemName ?? currentOrder.ShippingRateComputationMethodSystemName,
                                                 orderDelta.Dto.ShippingMethod,
                                                 storeId,
                                                 customer, BuildShoppingCartItemsFromOrderItems(currentOrder.OrderItems.ToList(), customer.Id, storeId));
                }

                if (orderDelta.Dto.ShippingMethod != null)
                {
                    currentOrder.ShippingMethod = orderDelta.Dto.ShippingMethod;
                }
                if (!isValid)
                {
                    return(Error(HttpStatusCode.BadRequest));
                }
            }

            orderDelta.Merge(currentOrder);

            customer.BillingAddress  = currentOrder.BillingAddress;
            customer.ShippingAddress = currentOrder.ShippingAddress;

            _orderService.UpdateOrder(currentOrder);

            CustomerActivityService.InsertActivity("UpdateOrder",
                                                   LocalizationService.GetResource("ActivityLog.UpdateOrder"), currentOrder);

            var ordersRootObject = new OrdersRootObject();

            var placedOrderDto = _dtoHelper.PrepareOrderDTO(currentOrder);


            ordersRootObject.Orders.Add(placedOrderDto);

            var json = JsonFieldsSerializer.Serialize(ordersRootObject, string.Empty);

            return(new RawJsonActionResult(json));
        }
Ejemplo n.º 49
0
 // PATCH tables/ExternalUser/48D68C86-6EA6-4C25-AA33-223FC9A27959
 public Task <ExternalUser> PatchExternalUser(string id, Delta <ExternalUser> patch)
 {
     return(UpdateAsync(id, patch));
 }
        // GET tables/CraftWorker/48D68C86-6EA6-4C25-AA33-223FC9A27959
        //public SingleResult<CraftWorker> GetCraftWorker(string id)
        //{
        //    return Lookup(id);
        //}

        // PATCH tables/CraftWorker/48D68C86-6EA6-4C25-AA33-223FC9A27959
        public Task <CraftWorker> PatchCraftWorker(string id, Delta <CraftWorker> patch)
        {
            return(UpdateAsync(id, patch));
        }
 // PATCH tables/Beacon/48D68C86-6EA6-4C25-AA33-223FC9A27959
 public Task<Beacon> PatchBeacon(string id, Delta<Beacon> patch)
 {
      return UpdateAsync(id, patch);
 }
Ejemplo n.º 52
0
 // PATCH tables/FeedbackData/48D68C86-6EA6-4C25-AA33-223FC9A27959
 public Task <FeedbackData> PatchFeedbackData(string id, Delta <FeedbackData> patch)
 {
     return(UpdateAsync(id, patch));
 }
Ejemplo n.º 53
0
        public static Delta InsertMilestone(this Delta delta, string style, string segRef = null)
        {
            var obj = new JObject(new JProperty("style", style));

            return(delta.InsertEmbed("ms", obj, segRef));
        }
Ejemplo n.º 54
0
 public IHttpActionResult Patch(Delta <Company> item)
 {
     item.Patch(Umbrella);
     return(StatusCode(HttpStatusCode.NoContent));
 }
Ejemplo n.º 55
0
 public Task <ActionResult <ViewUser> > PatchAsync(string id, Delta <UpdateUser> changes)
 {
     return(PatchImplAsync(id, changes));
 }
Ejemplo n.º 56
0
 public override void Update(Delta delta)
 {
     Finish();
 }
        public IActionResult CreateOrder([ModelBinder(typeof(JsonModelBinder <OrderDto>))] Delta <OrderDto> orderDelta)
        {
            // Here we display the errors if the validation has failed at some point.
            if (!ModelState.IsValid)
            {
                return(Error());
            }

            if (orderDelta.Dto.CustomerId == null)
            {
                return(Error());
            }

            // We doesn't have to check for value because this is done by the order validator.
            var customer = CustomerService.GetCustomerById(orderDelta.Dto.CustomerId.Value);

            if (customer == null)
            {
                return(Error(HttpStatusCode.NotFound, "customer", "not found"));
            }

            var shippingRequired = false;

            if (orderDelta.Dto.OrderItems != null)
            {
                var shouldReturnError = AddOrderItemsToCart(orderDelta.Dto.OrderItems, customer, orderDelta.Dto.StoreId ?? _storeContext.CurrentStore.Id);
                if (shouldReturnError)
                {
                    return(Error(HttpStatusCode.BadRequest));
                }

                shippingRequired = IsShippingAddressRequired(orderDelta.Dto.OrderItems);
            }

            if (shippingRequired)
            {
                var isValid = true;

                isValid &= SetShippingOption(orderDelta.Dto.ShippingRateComputationMethodSystemName,
                                             orderDelta.Dto.ShippingMethod,
                                             orderDelta.Dto.StoreId ?? _storeContext.CurrentStore.Id,
                                             customer,
                                             BuildShoppingCartItemsFromOrderItemDtos(orderDelta.Dto.OrderItems.ToList(),
                                                                                     customer.Id,
                                                                                     orderDelta.Dto.StoreId ?? _storeContext.CurrentStore.Id));

                if (!isValid)
                {
                    return(Error(HttpStatusCode.BadRequest));
                }
            }

            var newOrder = _factory.Initialize();

            orderDelta.Merge(newOrder);

            customer.BillingAddress  = newOrder.BillingAddress;
            customer.ShippingAddress = newOrder.ShippingAddress;

            // If the customer has something in the cart it will be added too. Should we clear the cart first?
            newOrder.Customer = customer;

            // The default value will be the currentStore.id, but if it isn't passed in the json we need to set it by hand.
            if (!orderDelta.Dto.StoreId.HasValue)
            {
                newOrder.StoreId = _storeContext.CurrentStore.Id;
            }

            var placeOrderResult = PlaceOrder(newOrder, customer);

            if (!placeOrderResult.Success)
            {
                foreach (var error in placeOrderResult.Errors)
                {
                    ModelState.AddModelError("order placement", error);
                }

                return(Error(HttpStatusCode.BadRequest));
            }

            CustomerActivityService.InsertActivity("AddNewOrder",
                                                   LocalizationService.GetResource("ActivityLog.AddNewOrder"), newOrder);

            var ordersRootObject = new OrdersRootObject();

            var placedOrderDto = _dtoHelper.PrepareOrderDTO(placeOrderResult.PlacedOrder);

            ordersRootObject.Orders.Add(placedOrderDto);

            var json = JsonFieldsSerializer.Serialize(ordersRootObject, string.Empty);

            return(new RawJsonActionResult(json));
        }
 // PATCH tables/StudentGroup/48D68C86-6EA6-4C25-AA33-223FC9A27959
 public Task <StudentGroup> PatchStudentGroup(string id, Delta <StudentGroup> patch)
 {
     return(UpdateAsync(id, patch));
 }
Ejemplo n.º 59
0
		private string[] GetScripts(Action<Delta> action)
		{
			var delta = new Delta(_configuration);

			action(delta);

			var comparator = new RelationalModelComparator(EnumOptions.None);
			var transform = comparator.CompareModels(delta.From, delta.To);

			var renderer = Renderer.GetRenderer(_configuration);
			return CollectionUtils.Map(transform.Render(renderer, new RenderOptions()), (Statement s) => s.Sql).ToArray();
		}
Ejemplo n.º 60
0
        public async Task <IHttpActionResult> Patch(int key, Delta <Currency> model)
        {
            var result = await PartiallyUpdateAsync(key, model, entity => Service.UpdateCurrency(entity));

            return(result);
        }