Beispiel #1
0
        /*
         *  /// <summary>
         *  /// Add a new design to a sitemodel
         *  /// </summary>
         *  /// <param name="SiteModelID"></param>
         *  /// <param name="designDescriptor"></param>
         *  public void Add(long SiteModelID, DesignDescriptor designDescriptor, BoundingWorldExtent3D extents)
         *  {
         *      mutableNonSpatialCache.Invoke(CacheKey(SiteModelID),
         *                                    new AddDesignProcessor(),
         *                                    new Design(SiteModelID, designDescriptor, extents));
         *  }
         */

        /// <summary>
        /// Add a new design to a sitemodel
        /// </summary>
        /// <param name="SiteModelID"></param>
        /// <param name="designDescriptor"></param>
        /// <param name="extents"></param>
        /// <param name="DesignID"></param>
        public void AddDirect(Guid SiteModelID, DesignDescriptor designDescriptor, BoundingWorldExtent3D extents, out Guid DesignID)
        {
            // This should be done under a lock on the cache key. For now, we will live with the race condition...

            INonSpatialAffinityKey cacheKey = VSS.TRex.Designs.Storage.Designs.CacheKey(SiteModelID);

            DesignID = Guid.NewGuid();

            // Get the designs, creating it if it does not exist
            IDesigns designList = new TRex.Designs.Storage.Designs();

            try
            {
                designList.FromBytes(MutableNonSpatialCache.Get(cacheKey));
            }
            catch (KeyNotFoundException)
            {
                // Swallow exception, the list will be empty
            }

            // Add the new design, generating a random ID from a GUID
            designList.AddDesignDetails(DesignID, designDescriptor, extents);

            // Put the list back into the cache with the new entry
            MutableNonSpatialCache.Put(cacheKey, designList.ToBytes());
        }
Beispiel #2
0
        /*
         * /// <summary>
         * /// Remove a given design from a site model
         * /// </summary>
         * /// <param name="SiteModelID"></param>
         * /// <param name="DesignID"></param>
         * /// <returns></returns>
         * public bool Remove(long SiteModelID, long DesignID)
         * {
         * try
         * {
         *     return MutableNonSpatialCache.Invoke(TRex.Designs.Storage.Designs.CacheKey(SiteModelID),
         *                                          new RemoveDesignProcessor(),
         *                                          DesignID);
         * }
         * catch (KeyNotFoundException)
         * {
         *     return false;
         * }
         * }
         */

        /// <summary>
        /// Remove a given design from a site model
        /// </summary>
        /// <param name="SiteModelID"></param>
        /// <param name="DesignID"></param>
        /// <returns></returns>
        public bool RemoveDirect(Guid SiteModelID, Guid DesignID)
        {
            // TODO: This should be done under a lock on the cache key. For now, we will live with the race condition
            try
            {
                INonSpatialAffinityKey cacheKey = TRex.Designs.Storage.Designs.CacheKey(SiteModelID);

                // Get the designs, creating it if it does not exist
                IDesigns designList = new TRex.Designs.Storage.Designs();
                designList.FromBytes(MutableNonSpatialCache.Get(cacheKey));

                // Remove the design
                bool result = designList.RemoveDesign(DesignID);

                // Put the list back into the cache with the new entry
                if (result)
                {
                    MutableNonSpatialCache.Put(cacheKey, designList.ToBytes());
                }

                return(result);
            }
            catch (KeyNotFoundException)
            {
                return(false);
            }
        }
Beispiel #3
0
        public IDesigns List(Guid SiteModelID)
        {
            Log.LogInformation($"Listing designs from {TRex.Designs.Storage.Designs.CacheKey(SiteModelID)}");

            try
            {
                IDesigns designList = new TRex.Designs.Storage.Designs();
                designList.FromBytes(MutableNonSpatialCache.Get(TRex.Designs.Storage.Designs.CacheKey(SiteModelID)));

                return(designList);
            }
            catch (KeyNotFoundException)
            {
                return(null);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Finds a given design in a site model
        /// </summary>
        /// <param name="SiteModelID"></param>
        /// <param name="DesignID"></param>
        /// <returns></returns>
        public IDesign FindDirect(Guid SiteModelID, Guid DesignID)
        {
            try
            {
                INonSpatialAffinityKey cacheKey = TRex.Designs.Storage.Designs.CacheKey(SiteModelID);

                // Get the designs, creating it if it does not exist
                IDesigns designList = new TRex.Designs.Storage.Designs();
                designList.FromBytes(MutableNonSpatialCache.Get(cacheKey));

                // Find the design and return it
                return(designList.Count == 0 ? null : designList.Locate(DesignID));
            }
            catch (KeyNotFoundException)
            {
                return(null);
            }
        }