Esempio n. 1
0
    public static bool IntersectsPortalBounds(this IPortableObject ob, Portal portal)
    {
        var oBounds = ob.rb.GetComponent <Collider>().bounds;
        var pBounds = portal.collider.bounds;

        return(pBounds.Intersects(oBounds));
    }
Esempio n. 2
0
 public void Send(IPortableObject viewer, Vector3 offset)     // Todo, Utils: Get transform, rotation, scale, offset multipliers
 {
     viewer.transform.position = this.TransformPosition(viewer.transform.position, offset);
     viewer.transform.rotation = this.TransformRotation(viewer.transform.rotation);
     viewer.down        = this.TransformDirection(viewer.down);
     viewer.rb.velocity = this.TransformDirection(viewer.rb.velocity) * length(viewer.rb.velocity) * (other.transform.lossyScale.x / transform.lossyScale.x);
     viewer.scale       = viewer.scale * (other.transform.lossyScale.x / transform.lossyScale.x);
 }
        /// <summary>
        /// Deserialize a user type instance from a POF stream by reading its
        /// state using the specified <see cref="IPofReader"/> object.
        /// </summary>
        /// <remarks>
        /// An implementation of <b>IPofSerializer</b> is required to follow
        /// the following steps in sequence for reading in an object of a
        /// user type:
        /// <list type="number">
        /// <item>
        /// <description>
        /// If the object is evolvable, the implementation must get the
        /// version by calling <see cref="IPofReader.VersionId"/>.
        /// </description>
        /// </item>
        /// <item>
        /// <description>
        /// The implementation may read any combination of the
        /// properties of the user type by using "read" methods of the
        /// <b>IPofReader</b>, but it must do so in the order of the property
        /// indexes. Additionally, the implementation must call
        /// {@link IPofReader#RegisterIdentity} with the new instance prior
        /// to reading any properties which are user type instances
        /// themselves.
        /// </description>
        /// </item>
        /// <item>
        /// <description>
        /// After all desired properties of the user type have been read,
        /// the implementation must terminate the reading of the user type by
        /// calling <see cref="IPofReader.ReadRemainder"/>.
        /// </description>
        /// </item>
        /// </list>
        /// </remarks>
        /// <param name="pofReader">
        /// The <b>IPofReader</b> with which to read the object's state.
        /// </param>
        /// <returns>
        /// The deserialized user type instance.
        /// </returns>
        /// <exception cref="IOException">
        /// If an I/O error occurs.
        /// </exception>
        public Object Deserialize(IPofReader pofReader)
        {
            try
            {
                IPortableObject po = (IPortableObject)
                                     Activator.CreateInstance(GetTypeForTypeId(pofReader.PofContext, m_nTypeId));

                CacheFactory.Log("Deserializing " + po.GetType(), CacheFactory.LogLevel.Max);

                bool             fEvolvable = po is IEvolvableObject;
                IEvolvableObject et         = fEvolvable ? (IEvolvableObject)po : null;

                int typeId = ((PofStreamReader.UserTypeReader)pofReader).NextPropertyIndex;
                while (typeId > 0)
                {
                    IEvolvable e      = null;
                    IPofReader reader = pofReader.CreateNestedPofReader(typeId);

                    if (fEvolvable)
                    {
                        e             = et.GetEvolvable(typeId);
                        e.DataVersion = reader.VersionId;
                    }

                    po.ReadExternal(reader);

                    Binary binRemainder = reader.ReadRemainder();
                    if (fEvolvable)
                    {
                        e.FutureData = binRemainder;
                    }
                    typeId = ((PofStreamReader.UserTypeReader)pofReader).NextPropertyIndex;
                }

                pofReader.ReadRemainder();
                return(po);
            }
            catch (Exception e)
            {
                String sClass = null;
                try
                {
                    sClass = pofReader.PofContext.GetTypeName(m_nTypeId);
                }
                catch (Exception)
                {
                }

                throw new IOException(
                          "An exception occurred instantiating a IPortableObject"
                          + " user type from a POF stream: type-id=" + m_nTypeId
                          + (sClass == null ? "" : ", class-name=" + sClass)
                          + ", exception=\n" + e, e);
            }
        }
Esempio n. 4
0
    void OnTriggerStay(Collider thing)     // Find better way, also modify how camera can get to the actual plane
    {
        IPortableObject ob = thing.GetComponent <IPortableObject>();

        float d = ob.scale / transform.lossyScale.x;

        if (ob != null && transform.InverseTransformPoint(ob.center).z >= -0.5f * d)
        {
            Vector3 localPos = transform.InverseTransformPoint(ob.transform.position);
            ob.transform.position = transform.TransformPoint(new Vector3(localPos.x, localPos.y, 0));             //Hmm

            portal.Send(ob, new Vector3(0, 0, 0.51f * d));
        }
    }
Esempio n. 5
0
        /** <inheritDoc /> */
        public IPortableBuilder Builder(IPortableObject obj)
        {
            IgniteArgumentCheck.NotNull(obj, "obj");

            PortableUserObject obj0 = obj as PortableUserObject;

            if (obj0 == null)
            {
                throw new ArgumentException("Unsupported object type: " + obj.GetType());
            }

            IPortableTypeDescriptor desc = _marsh.Descriptor(true, obj0.TypeId());

            return(Builder0(null, obj0, desc));
        }
Esempio n. 6
0
        public void TestPortableObjectInTask()
        {
            IPortableObject taskArg = ToPortable(Grid1, new PortableTaskArgument(100));

            TestTask task = new TestTask(Grid1, taskArg);

            IPortableObject res = Grid1.Compute().Execute(task, taskArg);

            Assert.NotNull(res);

            Assert.AreEqual(400, res.Field <int>("val"));

            PortableTaskResult resObj = res.Deserialize <PortableTaskResult>();

            Assert.AreEqual(400, resObj.Val);
        }
Esempio n. 7
0
        public void TestAffinityPortable()
        {
            IIgnite g = Ignition.GetIgnite("grid-0");

            ICacheAffinity aff = g.Affinity(null);

            IPortableObject affKey = g.Portables().ToPortable <IPortableObject>(new AffinityTestKey(0, 1));

            IClusterNode node = aff.MapKeyToNode(affKey);

            for (int i = 0; i < 10; i++)
            {
                IPortableObject otherAffKey =
                    g.Portables().ToPortable <IPortableObject>(new AffinityTestKey(i, 1));

                Assert.AreEqual(node.Id, aff.MapKeyToNode(otherAffKey).Id);
            }
        }
Esempio n. 8
0
        public void TestPutLoadPortables()
        {
            var cache = PortableStoreCache <int, Value>();

            cache.Put(1, new Value(1));

            IDictionary map = StoreMap();

            Assert.AreEqual(1, map.Count);

            IPortableObject v = (IPortableObject)map[1];

            Assert.AreEqual(1, v.Field <int>("_idx"));

            cache.LocalEvict(new[] { 1 });

            Assert.AreEqual(0, cache.Size());

            Assert.AreEqual(1, cache.Get(1).Index());

            Assert.AreEqual(1, cache.Size());
        }
        /// <summary>
        /// Initialize the specified (newly instantiated) PortableObject instance
        /// using the specified reader.
        /// </summary>
        /// <param name="portable">The object to initialize.</param>
        /// <param name="reader">
        /// The PofReader with which to read the object's state.
        /// </param>
        public void Initialize(IPortableObject portable, IPofReader reader)
        {
            // set the version identifier
            bool       isEvolvable = portable is IEvolvable;
            IEvolvable evolvable   = null;

            if (isEvolvable)
            {
                evolvable             = (IEvolvable)portable;
                evolvable.DataVersion = reader.VersionId;
            }

            // read the object's properties
            portable.ReadExternal(reader);

            // read any future properties
            Binary remainder = reader.ReadRemainder();

            if (isEvolvable)
            {
                evolvable.FutureData = remainder;
            }
        }
Esempio n. 10
0
 /** <inheritdoc /> */
 public IPortableObject PortableArgAndResultMethod(int arg1, IPortableObject arg2)
 {
     return(_portables.ToPortable <IPortableObject>(arg2.Deserialize <TestPortableClass>()));
 }
Esempio n. 11
0
 /** <inheritdoc /> */
 public TestPortableClass PortableArgMethod(int arg1, IPortableObject arg2)
 {
     return(arg2.Deserialize <TestPortableClass>());
 }
        /// <summary>
        /// Serialize a user type instance to a POF stream by writing its
        /// state using the specified <see cref="IPofWriter"/> object.
        /// </summary>
        /// <remarks>
        /// An implementation of <b>IPofSerializer</b> is required to follow
        /// the following steps in sequence for writing out an object of a
        /// user type:
        /// <list type="number">
        /// <item>
        /// <description>
        /// If the object is evolvable, the implementation must set the
        /// version by calling <see cref="IPofWriter.VersionId"/>.
        /// </description>
        /// </item>
        /// <item>
        /// <description>
        /// The implementation may write any combination of the properties of
        /// the user type by using the "write" methods of the
        /// <b>IPofWriter</b>, but it must do so in the order of the property
        /// indexes.
        /// </description>
        /// </item>
        /// <item>
        /// <description>
        /// After all desired properties of the user type have been written,
        /// the implementation must terminate the writing of the user type by
        /// calling <see cref="IPofWriter.WriteRemainder"/>.
        /// </description>
        /// </item>
        /// </list>
        /// </remarks>
        /// <param name="pofWriter">
        /// The <b>IPofWriter</b> with which to write the object's state.
        /// </param>
        /// <param name="o">
        /// The object to serialize.
        /// </param>
        /// <exception cref="IOException">
        /// If an I/O error occurs.
        /// </exception>
        public void Serialize(IPofWriter pofWriter, Object o)
        {
            if (!(o is IPortableObject))
            {
                throw new IOException("Class [" + o.GetType() +
                                      "] does not implement a IPortableObject interface");
            }

            IPortableObject  po         = (IPortableObject)o;
            bool             fEvolvable = o is IEvolvableObject;
            IEvolvableObject et         = fEvolvable ? (IEvolvableObject)o : null;

            try
            {
                CacheFactory.Log("Serializing " + o.GetType(), CacheFactory.LogLevel.Max);

                IPofContext       ctx     = pofWriter.PofContext;
                IEnumerable <int> typeIds = GetTypeIds(o, ctx);

                foreach (int typeId in typeIds)
                {
                    IEvolvable e = null;
                    if (fEvolvable)
                    {
                        e = et.GetEvolvable(typeId);
                    }

                    IPofWriter writer = pofWriter.CreateNestedPofWriter(typeId, typeId);
                    if (fEvolvable)
                    {
                        writer.VersionId = Math.Max(e.DataVersion, e.ImplVersion);
                    }

                    Type type = GetTypeForTypeId(ctx, typeId);
                    if (type != null)
                    {
                        po.WriteExternal(writer);
                    }

                    writer.WriteRemainder(fEvolvable ? e.FutureData : null);
                }

                pofWriter.WriteRemainder(null);
            }
            catch (Exception e)
            {
                String sClass = null;
                try
                {
                    sClass = pofWriter.PofContext.GetTypeName(m_nTypeId);
                }
                catch (Exception)
                {
                }

                String sActual = null;
                try
                {
                    sActual = o.GetType().FullName;
                }
                catch (Exception)
                {
                }

                throw new IOException(
                          "An exception occurred writing a IPortableObject"
                          + " user type to a POF stream: type-id=" + m_nTypeId
                          + (sClass == null ? "" : ", class-name=" + sClass)
                          + (sActual == null ? "" : ", actual class-name=" + sActual)
                          + ", exception=" + e, e);
            }
        }
Esempio n. 13
0
 public void WriteToSlots(IPortableObject portableObject)
 {
     portableObject.Serialize(this);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="IgniteException"/> class.
 /// </summary>
 /// <param name="info">Serialization information.</param>
 /// <param name="ctx">Streaming context.</param>
 protected ServiceInvocationException(SerializationInfo info, StreamingContext ctx)
     : base(info, ctx)
 {
     _portableCause = (IPortableObject)info.GetValue(KeyPortableCause, typeof(IPortableObject));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ServiceInvocationException"/> class.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="portableCause">The portable cause.</param>
 public ServiceInvocationException(string message, IPortableObject portableCause)
     : base(message)
 {
     _portableCause = portableCause;
 }