// Helper method to ensure that underlying allocated data is disposed properly.
        private bool DidGetEntityThrow(EntityTemplate template)
        {
            Entity entity = null;

            try
            {
                entity = template.GetEntity();
            }
            catch (InvalidOperationException)
            {
                return(true);
            }
            finally
            {
                if (entity != null)
                {
                    foreach (var id in entity.GetComponentIds())
                    {
                        var data = entity.Get(id);
                        data.Value.SchemaData.Value.Destroy();
                    }
                }
            }

            return(false);
        }
Exemplo n.º 2
0
 /// <summary>
 ///     Constructor to create a CreateEntity command request payload.
 /// </summary>
 /// <param name="template">
 ///     The EntityTemplate object that defines the SpatialOS components on the to-be-created entity.
 /// </param>
 /// <param name="entityId">
 ///     (Optional) The EntityId that the to-be-created entity should take.
 ///     This should only be provided if received as the result of a ReserveEntityIds command.
 /// </param>
 /// <param name="timeoutMillis">
 ///     (Optional) The command timeout in milliseconds. If not specified, will default to 5 seconds.
 /// </param>
 /// <param name="context">
 ///    (Optional) A context object that will be returned with the command response.
 /// </param>
 /// <returns>The CreateEntity command request payload.</returns>
 public Request(EntityTemplate template, EntityId?entityId = null,
                uint?timeoutMillis = null, object context = null)
 {
     Entity        = template.GetEntity();
     EntityId      = entityId;
     TimeoutMillis = timeoutMillis;
     Context       = context;
 }
Exemplo n.º 3
0
 /// <summary>
 ///     Method to create a CreateEntity command request payload.
 /// </summary>
 /// <param name="template">
 ///     The EntityTemplate object that defines the SpatialOS components on the to-be-created entity.
 /// </param>
 /// <param name="entityId">
 ///     (Optional) The EntityId that the to-be-created entity should take.
 ///     This should only be provided if received as the result of a ReserveEntityIds command.
 /// </param>
 /// <param name="timeoutMillis">
 ///     (Optional) The command timeout in milliseconds. If not specified, will default to 5 seconds.
 /// </param>
 /// <param name="context">
 ///    (Optional) A context object that will be returned with the command response.
 /// </param>
 /// <returns>The CreateEntity command request payload.</returns>
 public static Request CreateRequest(EntityTemplate template, EntityId?entityId = null, uint?timeoutMillis = null, Object context = null)
 {
     return(new Request
     {
         Entity = template.GetEntity(),
         EntityId = entityId,
         TimeoutMillis = timeoutMillis,
         Context = context,
         RequestId = CommandRequestIdGenerator.GetNext(),
     });
 }