예제 #1
0
        private void ExecuteAndCatchErrors(ODataRequest request, ODataResponse response, Action action)
        {
            try
            {
                action();
            }
            catch (Exception ex)
            {
                request.WriteToLog(this.Logger, LogLevel.Verbose);
                response.WriteToLog(this.Logger, LogLevel.Verbose);

#if !SILVERLIGHT
                if (this.Synchronizer != null)
                {
                    EntitySet entitySet;
                    if (request.Uri.TryGetExpectedEntitySet(out entitySet))
                    {
                        try
                        {
                            SyncHelpers.ExecuteActionAndWait(c => this.Synchronizer.SynchronizeEntireEntitySet(c, entitySet.Name));
                        }
                        catch (Exception syncException)
                        {
                            this.Logger.WriteLine(LogLevel.Error, "Failed to synchronize set '{0}'", entitySet.Name);
                            this.Logger.WriteLine(LogLevel.Error, syncException.ToString());
                        }
                    }
                }
#endif

                throw new AssertionFailedException("Failed to deserialize response body", ex);
            }
        }
예제 #2
0
        private void VerifyQueryResult(ODataRequest request, ODataResponse response, FunctionSegment functionSegment, IVerifyServiceActionQueryResult verifyServiceQueryResult)
        {
            EntitySet expectedBindingEntitySet = null;
            var       actionLessUri            = ConstructODataUriWithoutActionInformation(this.entityModelSchema.GetDefaultEntityContainer().EntitySets, request.Uri);
            bool      entitySetFound           = actionLessUri.TryGetExpectedEntitySet(out expectedBindingEntitySet);

            ExceptionUtilities.Assert(entitySetFound, "EntitySet not found for Uri {0}", actionLessUri.ToString());

            // SDP never applies for actions
            var preActionQueryValueResult = this.ODataUriEvaluator.Evaluate(actionLessUri, true, false);

            IDictionary <string, QueryValue> queryValueParametersLookup = new Dictionary <string, QueryValue>();

            if (request.Body != null)
            {
                queryValueParametersLookup = this.CreateQueryValueParameters(request, functionSegment, queryValueParametersLookup);
            }

            var            expected           = verifyServiceQueryResult.GetExpectedQueryValue(preActionQueryValueResult, queryValueParametersLookup.Values.ToArray());
            HttpStatusCode expectedStatusCode = CalculateExpectedStatusCode(functionSegment);

            string expectedETag = null;

            SyncHelpers.ExecuteActionAndWait(c => this.Synchronizer.SynchronizeEntireEntitySet(c, expectedBindingEntitySet.Name));

            expectedETag = this.VerifyExpected(request, response, expected, expectedStatusCode, expectedETag);

            ETagHeaderVerifier etagHeaderVerifier = new ETagHeaderVerifier();

            etagHeaderVerifier.Verify(expectedETag, request, response);
        }
예제 #3
0
        /// <summary>
        /// Gets the pre and post update representations of the entity updated by the given request
        /// </summary>
        /// <param name="request">The request</param>
        /// <param name="beforeUpdate">The entity before the update</param>
        /// <param name="afterUpdate">The entity after the update</param>
        public void GetUpdatedEntity(ODataRequest request, out QueryStructuralValue beforeUpdate, out QueryStructuralValue afterUpdate)
        {
            ExceptionUtilities.CheckArgumentNotNull(request, "request");
            ExceptionUtilities.Assert(this.requestsBegun.Contains(request), "Cannot use GetUpdatedEntity before calling Begin");
            ExceptionUtilities.Assert(request.GetEffectiveVerb().IsUpdateVerb(), "Cannot use GetUpdatedEntity on non update requests");

            KeyValuePair <QueryStructuralValue, QueryStructuralValue> beforeAndAfter;

            if (!this.updatedEntityCache.TryGetValue(request, out beforeAndAfter))
            {
                var entityUri = request.Uri.ScopeToEntity();
                var entity    = (QueryStructuralValue)this.Evaluator.Evaluate(entityUri, false, false);

                beforeUpdate = this.QueryValueCopier.PerformDeepCopy(entity);

                SyncHelpers.ExecuteActionAndWait(c => this.Synchronizer.SynchronizeEntity(c, entity));

                afterUpdate = entity;

                beforeAndAfter = new KeyValuePair <QueryStructuralValue, QueryStructuralValue>(beforeUpdate, afterUpdate);
                this.updatedEntityCache[request] = beforeAndAfter;
            }
            else
            {
                beforeUpdate = beforeAndAfter.Key;
                afterUpdate  = beforeAndAfter.Value;
            }
        }
예제 #4
0
        public MyFracturedPiece()
            : base()
        {
            //EntityId = MyEntityIdentifier.AllocateId();

            //TODO: Synchronize through manager to avoid performance hits
            SyncFlag = true;

            base.PositionComp           = new MyFracturePiecePositionComponent();
            base.Render                 = new MyRenderComponentFracturedPiece();
            base.Render.NeedsDraw       = true;
            base.Render.PersistentFlags = MyPersistentEntityFlags2.Enabled;
            AddDebugRenderComponent(new MyFracturedPieceDebugDraw(this));
            UseDamageSystem = false;
            NeedsUpdate     = MyEntityUpdateEnum.EACH_10TH_FRAME | MyEntityUpdateEnum.EACH_100TH_FRAME;
#if !XB1 // !XB1_SYNC_NOREFLECTION
            SyncType = SyncHelpers.Compose(this);
#else // XB1
            SyncType = new SyncType(new List <SyncBase>());
            m_fallSoundShouldPlay = SyncType.CreateAndAddProp <bool>();
            m_fallSoundString     = SyncType.CreateAndAddProp <string>();
#endif // XB1
            m_fallSoundShouldPlay.Value     = false;
            m_fallSoundString.Value         = "";
            m_fallSoundString.ValueChanged += (x) => SetFallSound();
        }
예제 #5
0
        public MySyncedBlock()
        {
#if !XB1 // !XB1_SYNC_NOREFLECTION
            SyncType = SyncHelpers.Compose(this);
#else // XB1
            SyncType = new SyncType(new List <SyncBase>());
#endif // XB1
        }
예제 #6
0
 public MyFloatingObject()
 {
     this.WasRemovedFromWorld   = false;
     this.m_soundEmitter        = new MyEntity3DSoundEmitter(this, false, 1f);
     this.m_lastTimePlayedSound = MySandboxGame.TotalGamePlayTimeInMilliseconds;
     base.Render   = new MyRenderComponentFloatingObject();
     this.SyncType = SyncHelpers.Compose(this, 0);
 }
        public static void ExecuteUriAndCompareSync <TResult>(this IClientQueryResultComparer linqToAstoriaResultComparer, IQueryable <TResult> query, string uriString, QueryValue expectedValue, DataServiceContext dataContext, ExpectedClientErrorBaseline clientExpectedError)
        {
#if !SILVERLIGHT
            SyncHelpers.ExecuteActionAndWait(c => linqToAstoriaResultComparer.ExecuteUriAndCompare <TResult>(c, false, query, uriString, expectedValue, dataContext, clientExpectedError));
#else
            throw new TaupoInvalidOperationException("Cannot execute in Silverlight");
#endif
        }
예제 #8
0
        /// <summary>
        /// Executes SaveChanges on the specified context and with specified options and verifies the results.
        /// </summary>
        /// <param name="verifier">The verifier to use for verification.</param>
        /// <param name="contextData">The data for the context.</param>
        /// <param name="context">The context to verify SaveChanges on.</param>
        /// <param name="options">The options for saving changes.</param>
        /// <returns>The response from SaveChanges</returns>
        public static DSClient.DataServiceResponse VerifySaveChanges(this ISaveChangesVerifier verifier, DataServiceContextData contextData, DSClient.DataServiceContext context, SaveChangesOptions?options)
        {
            ExceptionUtilities.CheckArgumentNotNull(verifier, "verifier");
            ExceptionUtilities.CheckArgumentNotNull(contextData, "contextData");
            ExceptionUtilities.CheckArgumentNotNull(context, "context");

            DSClient.DataServiceResponse response = null;
            SyncHelpers.ExecuteActionAndWait(c1 => verifier.VerifySaveChanges(c1, contextData, context, options, (c2, r) => { response = r; c2.Continue(); }));
            return(response);
        }
예제 #9
0
        public MyTerminalBlock()
        {
            CustomName            = new StringBuilder();
            DetailedInfo          = new StringBuilder();
            CustomInfo            = new StringBuilder();
            CustomNameWithFaction = new StringBuilder();

            SyncType = SyncHelpers.Compose(this);
            SyncType.PropertyChanged += sync => RaisePropertiesChanged();
        }
예제 #10
0
        public void Append(object obj)
        {
            var num = m_properties.Count;

            SyncHelpers.Compose(obj, m_properties.Count, m_properties);
            for (int i = num; i < m_properties.Count; i++)
            {
                m_properties[i].ValueChanged += m_registeredHandlers;
            }
        }
예제 #11
0
        public MyFloatingObject()
        {
            WasRemovedFromWorld   = false;
            m_soundEmitter        = new MyEntity3DSoundEmitter(this);
            m_lastTimePlayedSound = MySandboxGame.TotalGamePlayTimeInMilliseconds;
            Render = new Components.MyRenderComponentFloatingObject();

            SyncType = SyncHelpers.Compose(this);

            Amount.ValueChanged += (x) => { Item.Amount = Amount.Value; UpdateInternalState(); };
        }
예제 #12
0
 public MyAutomaticRifleGun()
 {
     NeedsUpdate      = MyEntityUpdateEnum.EACH_FRAME;
     Render.NeedsDraw = true;
     m_gunBase        = new MyGunBase();
     m_soundEmitter   = new MyEntity3DSoundEmitter(this);
     (PositionComp as MyPositionComponent).WorldPositionChanged = WorldPositionChanged;
     this.Render = new MyRenderComponentAutomaticRifle();
     SyncType    = SyncHelpers.Compose(this);
     SyncType.Append(m_gunBase);
 }
예제 #13
0
        public void Append(object obj)
        {
#if !UNSHAPER_TMP
            //++m_TotalCount;
            //System.Diagnostics.Debug.Print(m_TotalCount.ToString());

            var num = m_properties.Count;
            SyncHelpers.Compose(obj, m_properties.Count, m_properties);
            for (int i = num; i < m_properties.Count; i++)
            {
                m_properties[i].ValueChanged += m_registeredHandlers;
            }
#endif
        }
예제 #14
0
        /// <summary>
        /// Executes SaveChanges on the specified context and with specified options and verifies the results.
        /// </summary>
        /// <param name="verifier">The verifier to use for verification.</param>
        /// <param name="contextData">The data for the context.</param>
        /// <param name="context">The context to verify SaveChanges on.</param>
        /// <param name="options">The options for saving changes.</param>
        /// <returns>The response from SaveChanges</returns>
        public static DSClient.DataServiceResponse VerifySaveChanges(this ISaveChangesVerifier verifier, DataServiceContextData contextData, DSClient.DataServiceContext context, SaveChangesOptions? options)
        {
#if SILVERLIGHT
            throw new TaupoNotSupportedException("Not supported in Silverlight");
#else
            ExceptionUtilities.CheckArgumentNotNull(verifier, "verifier");
            ExceptionUtilities.CheckArgumentNotNull(contextData, "contextData");
            ExceptionUtilities.CheckArgumentNotNull(context, "context");

            DSClient.DataServiceResponse response = null;
            SyncHelpers.ExecuteActionAndWait(c1 => verifier.VerifySaveChanges(c1, contextData, context, options, (c2, r) => { response = r; c2.Continue(); }));
            return response;
#endif
        }
예제 #15
0
        public MyFloatingObject()
        {
            WasRemovedFromWorld   = false;
            m_soundEmitter        = new MyEntity3DSoundEmitter(this);
            m_lastTimePlayedSound = MySandboxGame.TotalGamePlayTimeInMilliseconds;
            Render = new Components.MyRenderComponentFloatingObject();

#if !XB1 // !XB1_SYNC_NOREFLECTION
            SyncType = SyncHelpers.Compose(this);
#else // XB1
            SyncType = new SyncType(new List <SyncBase>());
            Amount   = SyncType.CreateAndAddProp <MyFixedPoint>();
#endif // XB1

            Amount.ValueChanged += (x) => { Item.Amount = Amount.Value; UpdateInternalState(); };
        }
예제 #16
0
        private QueryValue SynchronizeAndEvaluate(ODataUri entityUri, QueryStructuralValue beforeSync, bool synchronizeEntireSet)
        {
            var entityType = beforeSync.Type as QueryEntityType;

            ExceptionUtilities.CheckObjectNotNull(entityType, "Structural value was not an entity type");

            // if an entity was deleted, synchronize the entire set. Otherwise just synchronize the entity
            if (synchronizeEntireSet)
            {
                SyncHelpers.ExecuteActionAndWait(c => this.Synchronizer.SynchronizeEntireEntitySet(c, entityType.EntitySet.Name));
            }
            else
            {
                SyncHelpers.ExecuteActionAndWait(c => this.Synchronizer.SynchronizeEntity(c, beforeSync));
            }

            return(this.Evaluator.Evaluate(entityUri, false, false));
        }
예제 #17
0
        public static void SaveException(String message, Exception exception, String extraStackTrace = null)
        {
            if (!Initialized)
            {
                return;
            }

            try
            {
                var log      = GetLog(message, exception, extraStackTrace);
                var filename = String.Format("crash{0}.log", DateTime.UtcNow.ToString("s").Replace(":", "-"));
                SyncHelpers.WriteFile(CrashFolderPath, filename, log, Encoding.UTF8);
            }
            catch
            {
                // Swallow exceptions during saving a previous exception
            }
        }
예제 #18
0
        public MyAutomaticRifleGun()
        {
            NeedsUpdate      = MyEntityUpdateEnum.EACH_FRAME;
            Render.NeedsDraw = true;
#if XB1 // XB1_SYNC_NOREFLECTION
            SyncType  = new SyncType(new List <SyncBase>());
            m_gunBase = new MyGunBase(SyncType);
#else // !XB1
            m_gunBase = new MyGunBase();
#endif // !XB1
            m_soundEmitter = new MyEntity3DSoundEmitter(this);
            (PositionComp as MyPositionComponent).WorldPositionChanged = WorldPositionChanged;
            this.Render = new MyRenderComponentAutomaticRifle();
#if !XB1 // !XB1_SYNC_NOREFLECTION
            SyncType = SyncHelpers.Compose(this);
            SyncType.Append(m_gunBase);
#endif // !XB1
        }
예제 #19
0
        /// <summary>
        /// Gets the entity inserted by the given request.
        /// </summary>
        /// <param name="request">The request</param>
        /// <param name="response">The response</param>
        /// <returns>The inserted entity</returns>
        public QueryStructuralValue GetInsertedEntity(ODataRequest request, ODataResponse response)
        {
            ExceptionUtilities.CheckArgumentNotNull(request, "request");
            ExceptionUtilities.CheckArgumentNotNull(response, "response");
            ExceptionUtilities.Assert(this.requestsBegun.Contains(request), "Cannot use GetInsertedEntity before calling Begin");
            ExceptionUtilities.Assert(request.GetEffectiveVerb() == HttpVerb.Post, "Cannot use GetInsertedEntity on non POST requests");

            QueryStructuralValue insertedEntity;

            if (!this.insertedEntityCache.TryGetValue(request, out insertedEntity))
            {
                EntitySet entitySet;
                ExceptionUtilities.Assert(request.Uri.TryGetExpectedEntitySet(out entitySet), "Could not infer entity set from URI");

                var entitySetUri = new ODataUri(new EntitySetSegment(entitySet));

                var beforeSync = this.Evaluator.Evaluate(entitySetUri, false, false) as QueryCollectionValue;
                ExceptionUtilities.CheckObjectNotNull(beforeSync, "Could not evaluate entity set '{0}' before syncing", entitySet.Name);

                // create a shallow copy
                beforeSync = beforeSync.Type.CreateCollectionWithValues(beforeSync.Elements);

                SyncHelpers.ExecuteActionAndWait(c => this.Synchronizer.SynchronizeEntireEntitySet(c, entitySet.Name));

                var afterSync = this.Evaluator.Evaluate(entitySetUri, false, false) as QueryCollectionValue;
                ExceptionUtilities.CheckObjectNotNull(afterSync, "Could not evaluate entity set '{0}' after syncing", entitySet.Name);

                // TODO: handle deep insert (using location header or response payload)
                var newElements = afterSync.Elements.Except(beforeSync.Elements).OfType <QueryStructuralValue>().ToList();
                this.insertedEntityCache[request] = insertedEntity = newElements.Single();

                // update the parent entity, if there is one
                var segments = request.Uri.Segments;
                var lastNavigationSegment = segments.OfType <NavigationSegment>().LastOrDefault();
                if (lastNavigationSegment != null)
                {
                    var segmentsBeforeNavigation = segments.TakeWhile(t => t != lastNavigationSegment);
                    var parentEntity             = (QueryStructuralValue)this.Evaluator.Evaluate(new ODataUri(segmentsBeforeNavigation), false, false);
                    SyncHelpers.ExecuteActionAndWait(c => this.Synchronizer.SynchronizeEntity(c, parentEntity));
                }
            }

            return(insertedEntity);
        }
예제 #20
0
        public MyFracturedPiece()
            : base()
        {
            //EntityId = MyEntityIdentifier.AllocateId();

            //TODO: Synchronize through manager to avoid performance hits
            SyncFlag = true;

            base.PositionComp           = new MyFracturePiecePositionComponent();
            base.Render                 = new MyRenderComponentFracturedPiece();
            base.Render.NeedsDraw       = true;
            base.Render.PersistentFlags = MyPersistentEntityFlags2.Enabled;
            AddDebugRenderComponent(new MyFracturedPieceDebugDraw(this));
            UseDamageSystem                 = false;
            NeedsUpdate                     = MyEntityUpdateEnum.EACH_10TH_FRAME;
            SyncType                        = SyncHelpers.Compose(this);
            m_fallSoundShouldPlay.Value     = false;
            m_fallSoundString.Value         = "";
            m_fallSoundString.ValueChanged += (x) => SetFallSound();
        }
예제 #21
0
 public MySyncedBlock()
 {
     SyncType = SyncHelpers.Compose(this);
 }
예제 #22
0
 public static void ExecuteUriAndCompareSync <TResult>(this IClientQueryResultComparer linqToAstoriaResultComparer, IQueryable <TResult> query, string uriString, QueryValue expectedValue, DataServiceContext dataContext, ExpectedClientErrorBaseline clientExpectedError)
 {
     SyncHelpers.ExecuteActionAndWait(c => linqToAstoriaResultComparer.ExecuteUriAndCompare <TResult>(c, false, query, uriString, expectedValue, dataContext, clientExpectedError));
 }
예제 #23
0
 public MySyncedBlock()
 {
     this.SyncType = SyncHelpers.Compose(this, 0);
 }