Example #1
0
        static ObjectInfo RetrieveInfo(StateServerKey key)
        {
            // Tells the server that operations performed with this key shouldn't reset timeouts:
            var mgtKey = key;

            mgtKey.IsManagementKey = true;
            // ScaleOut 5.5 (and higher) fixes key structs to be immutable. Use this line instead:
            //var mgtKey = key.ToManagementKey();

            // Retrieve metadata info from the SOSS service:
            DataAccessor       da  = DataAccessor.CreateDataAccessor(mgtKey, lockWhenReading: false);
            ReadMetadataResult res = da.ReadMetadata(ReadOptions.ObjectMayBeLocked | ReadOptions.ObjectMayNotExist);

            if (res.Status == StateServerResult.ObjectNotFound)
            {
                // Object was removed/expired between the time of initial key retrieval and metadata retrieval.
                return(null);
            }

            ExtendedObjectMetadata meta = res.Metadata;

            ObjectInfo objInfo = new ObjectInfo()
            {
                Key         = key,
                SizeInBytes = meta.ObjectSize
            };

            // TODO: If we need to capture a custom property/field on the object itself, add a reference
            // to its assembly (so it can be deserialized) and then retrieve the object here. Once we have
            // an instance of it, any properties we're interested in can be added on as a new property of
            // the ObjectInfo we're returning.
            // For example:

            /*
             * try
             * {
             *  MyClass myObject = (MyClass)da.ReadObject(false);
             *  if (myObject != null)
             *  {
             *      ret.InterestingProperty = myObject.InterestingProperty;
             *  }
             * }
             * catch
             * {
             * }
             */

            return(objInfo);
        }