/// <summary>
 ///     <para>Reads an object from the store.</para>
 /// </summary>
 /// <typeparam name="T">
 ///     <para>The type of the object.</para>
 /// </typeparam>
 /// <param name="keySpace">
 ///     <para>The key space of the entry.</para>
 /// </param>
 /// <param name="key">
 ///     <para>The key of the entry.</para>
 /// </param>
 /// <param name="creator">
 ///     <para>Delegate that provides an empty instance for
 ///		deserialization.</para>
 /// </param>
 /// <returns>
 ///     <para>A <see cref="StorageEntry{T}"/> containing the entry.</para>
 /// </returns>
 public StorageEntry <T> Get <T>(DataBuffer keySpace, StorageKey key, Func <T> creator)
 {
     if (Storage.StreamsData)
     {
         var data = Storage.GetBuffer(keySpace, key);
         if (data == null)
         {
             return(StorageEntry <T> .NotFound);
         }
         DataBuffer buffer = data;
         using (var stream = new MemoryStream(data, false))
         {
             return(GetCore(buffer, stream, creator()));
         }
     }
     else
     {
         using (var item = StreamPool.GetItem())
         {
             DataBuffer buffer;
             var        stream = GetStream(item, keySpace, key, out buffer);
             if (stream == null)
             {
                 return(StorageEntry <T> .NotFound);
             }
             return(GetCore(buffer, stream, creator()));
         }
     }
 }
 /// <summary>
 ///     <para>Deletes an object from the store by version.</para>
 /// </summary>
 /// <param name="keySpace">
 ///     <para>The key space of the entry.</para>
 /// </param>
 /// <param name="key">
 ///     <para>The key of the entry.</para>
 /// </param>
 /// <param name="updated">
 ///     <para>The last updated <see cref="DateTime"/> of the version to be deleted. If the entry's last updated date is not newer than this value, then the entry will be deleted, otherwise not.</para>
 /// </param>
 /// <returns>
 ///     <para>
 ///         <see langword="true"/> if the entry was deleted; otherwise <see langword="false"/>. The entry is deleted if it existed prior and was as old or older than <paramref name="updated"/>.</para>
 /// </returns>
 public bool DeleteVersion(DataBuffer keySpace, StorageKey key, DateTime updated)
 {
     using (var item = StreamPool.GetItem())
     {
         var stream = item.Item;
         if (stream.Capacity < sizeof(long))
         {
             stream.Capacity = sizeof(long);
         }
         var buffer = GetReadBuffer(stream);
         buffer = buffer.Restrict(sizeof(long));
         var len = Storage.Get(keySpace, key, sizeof(long), buffer);
         if (len < 0)
         {
             return(false);
         }
         var seg          = buffer.ByteArraySegmentValue;
         var ticks        = BitConverter.ToInt64(seg.Array, seg.Offset);
         var entryUpdated = new DateTime(ticks);
         if (entryUpdated <= updated)
         {
             return(Storage.Delete(keySpace, key));
         }
         return(false);
     }
 }
Esempio n. 3
0
    public override void RunOnAwake()
    {
        base.RunOnAwake();
        ResourceStream newStream = StreamPool.getStream(initialValue, initialState, initialColor);

        this.animColor = newStream._streamColor;
        this.Stream    = newStream;
        this.PassStream();
    }
Esempio n. 4
0
    public override void ManageStream()
    {
        if (this.Stream.GetState != this.StreamprocessingType)
        {
            StreamPool.returnStream(this.Stream);
            this.ChangeState = runningState.incorrectInput;
            return;
        }

        //  myAnimator.setAnimState(this);
        this.PassStream();
    }
 /// <summary>
 ///     <para>Writes an object to the store.</para>
 /// </summary>
 /// <typeparam name="T">
 ///     <para>The type of the object.</para>
 /// </typeparam>
 /// <param name="keySpace">
 ///     <para>The key space of the entry.</para>
 /// </param>
 /// <param name="key">
 ///     <para>The key of the entry.</para>
 /// </param>
 /// <param name="entry">
 ///     <para>The entry to write.</para>
 /// </param>
 public void Put <T>(DataBuffer keySpace, StorageKey key, StorageEntry <T> entry)
 {
     AddKeySpaceInfo <T>(keySpace);
     using (var item = StreamPool.GetItem())
     {
         var stream = item.Item;
         stream.Write(BitConverter.GetBytes(entry.Expires.Ticks), 0, sizeof(long));
         stream.Write(BitConverter.GetBytes(entry.Updated.Ticks), 0, sizeof(long));
         Serializer.Serialize(stream, entry.Instance);
         Storage.Put(keySpace, key, GetWriteBuffer(stream));
     }
 }
Esempio n. 6
0
 public void StopRunning()
 {
     animState = runningState.notRunning;
     myState   = runningState.notRunning;
     //animColor = streamColor.notSet;
     if (myStream != null)
     {
         StreamPool.returnStream(myStream);
         myStream = null;
     }
     ManageAnimator();
 }
Esempio n. 7
0
        /// <summary>
        /// Creates instance of EJDB.
        /// </summary>
        /// <param name="library"></param>
        public Database(Library library)
        {
            _functions     = library.Functions.Database;
            DatabaseHandle = new DatabaseHandle(library);

            Library    = library;
            StreamPool = new StreamPool();

            Serializer = new JsonSerializer
            {
                NullValueHandling = NullValueHandling.Ignore,
                ContractResolver  = NejdbContractResolver.Instance,
            };
            Serializer.Converters.Add(ObjectIdConverter.Instance);
        }
Esempio n. 8
0
    public override void ManageStream()
    {
        if (this.Stream.GetState != this.StreamprocessingType)
        {
            StreamPool.returnStream(this.Stream);
            this.ChangeState = runningState.incorrectInput;
            return;
        }

        StreamModifier myMod = new StreamModifier(myMultiplier);

        this.Stream.AddModifier = myMod;


        //  myAnimator.setAnimState(this);
        this.PassStream();
    }
Esempio n. 9
0
    public override void ManageStream()
    {
        if (this.Stream.GetState != this.StreamprocessingType)
        {
            StreamPool.returnStream(this.Stream);
            this.ChangeState = runningState.incorrectInput;
            return;
        }


        //  base.ManageStream();
        isRecivingStream = true;
        ResourceStream myStream      = this.Stream;
        float          myStreamValue = myStream.GetStreamValue();

        ResourceManager.rManager.curResource += myStreamValue;
        StreamPool.returnStream(this.Stream);
        //Destroy (myStream); //This is temp until I set up object pooling
        // Debug.LogError("Should be better");
    }
 /// <summary>
 ///     <para>Gets the expiration time of an object.</para>
 /// </summary>
 /// <param name="keySpace">
 ///     <para>The key space of the entry.</para>
 /// </param>
 /// <param name="key">
 ///     <para>The key of the entry.</para>
 /// </param>
 /// <returns>
 ///     <para>A <see cref="Nullable{DateTime}"/> containing the expiration time if found; otherwise <see langword="null"/>.</para>
 /// </returns>
 public DateTime?GetExpires(DataBuffer keySpace, StorageKey key)
 {
     using (var item = StreamPool.GetItem())
     {
         var stream = item.Item;
         if (stream.Capacity < sizeof(long))
         {
             stream.Capacity = sizeof(long);
         }
         var buffer = GetReadBuffer(stream);
         buffer = buffer.Restrict(sizeof(long));
         var len = Storage.Get(keySpace, key, 0, buffer);
         if (len < 0)
         {
             return(null);
         }
         var seg   = buffer.ByteArraySegmentValue;
         var ticks = BitConverter.ToInt64(seg.Array, seg.Offset);
         return(new DateTime(ticks));
     }
 }
Esempio n. 11
0
    public void PassStream()
    {
        //   Debug.Log(this.transform.name + "Is passing OBJ");

        myNeighbors.Clear();
        MyNeighborOutPut.Clear();
        for (int output = 0; output < myOutputs.Count; output++)
        {
            // Debug.Log(myOutputs[output]);
            if (myParent.GetNeighbor(myOutputs[output]) != null)
            {
                if (myInputs.Contains(myOutputs[output]))
                {
                    myInputs.Remove(myOutputs[output]);
                }
                myNeighbors.Add(myParent.GetNeighbor(myOutputs [output]));
                MyNeighborOutPut.Add(myOutputs [output]);
                // .ReceiveStream(myStream, myOutputs[output]);

                // return;
            }
        }
        //Debug.Log (myStream.currentValue);
        //myStream.currentValue = myStream.currentValue / myNeighbors.Count + 1;
        //Debug.Log (myStream.currentValue + " : " + myNeighbors.Count);
        if (myNeighbors.Count > 0)
        {
            myState = runningState.running;
            for (int neighbor = 0; neighbor < myNeighbors.Count; neighbor++)
            {
                myNeighbors [neighbor].ReceiveStream(myStream, MyNeighborOutPut [neighbor]);
            }
        }
        else
        {
            StreamPool.returnStream(this.Stream);
            myState = runningState.incorrectOutput;
        }
        ManageAnimator();
    }