/// <summary>
        /// Updates or inserts a stream in the local cache.
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="restApi"></param>
        public static void AddOrUpdateStream(SpeckleStream stream, string restApi)
        {
            LocalContext.Init();
            var bytes        = SpeckleCore.Converter.getBytes(stream.ToJson());
            var combinedHash = Converter.getMd5Hash(stream._id + restApi);

            var cacheRes = Database.Table <CachedStream>().Where(existing => existing.CombinedHash == combinedHash).ToList();

            if (cacheRes.Count >= 1)
            {
                var toUpdate = cacheRes[0];
                toUpdate.Bytes     = bytes;
                toUpdate.UpdatedOn = DateTime.Now;
                Database.Update(toUpdate);
            }
            else
            {
                var toCache = new CachedStream()
                {
                    CombinedHash = combinedHash,
                    Bytes        = bytes,
                    RestApi      = restApi,
                    StreamId     = stream.StreamId,
                    AddedOn      = DateTime.Now,
                    UpdatedOn    = DateTime.Now
                };
                Database.Insert(toCache);
            }
            //throw new NotImplementedException();
        }
        public static int GetNumberOfObjects(this SpeckleApiClient speckleApiClient)
        {
            SpeckleStream stream = speckleApiClient.Stream;

            if (stream.Layers != null)
            {
                return((int)stream.Layers.Select(x => x.ObjectCount).Sum());
            }
            else
            {
                return(stream.Objects != null ? stream.Objects.Count : 0);
            }
        }
Example #3
0
 public SpeckleStream ToSpeckle()
 {
     return(SpeckleStream.FromJson(SpeckleCore.Converter.getObjFromBytes(this.Bytes) as string)); // ((SpeckleCore.Converter.getObjFromBytes( this.Bytes ) as SpeckleStream;
 }