Пример #1
0
        public static string ToSpeckleQuery(SpeckleRequest speckleRequest)
        {
            string speckleQuery = "";

            if (!string.IsNullOrEmpty(speckleRequest.SpeckleQuery))
            {
                return(speckleRequest.SpeckleQuery); // just return the included SpeckleQuery.
            }
            else
            {
                // Do the conversion.
                if (speckleRequest.Limit != null)
                {
                    speckleQuery += $"&limit={speckleRequest.Limit}";
                }

                if (speckleRequest.SpeckleHash != null)
                {
                    speckleQuery += $"&hash={string.Join(",", speckleRequest.SpeckleHash)}";
                }

                if (speckleRequest.SpeckleGUIDs != null)
                {
                    speckleQuery += $"&id={string.Join(",", speckleRequest.SpeckleGUIDs)}";
                }
            }

            return(speckleQuery);
        }
Пример #2
0
        public override IEnumerable <object> Pull(IRequest request, PullType pullType = PullType.AdapterDefault, ActionConfig actionConfig = null)
        {
            // If the request exists, make sure it's a SpeckleRequest
            SpeckleRequest speckleRequest = request as SpeckleRequest;

            if (request != null && request.GetType() != typeof(FilterRequest) && speckleRequest == null)
            {
                Engine.Reflection.Compute.RecordError($"SpeckleAdapter supports only {typeof(SpeckleRequest).Name}.");
                return(new List <object>());
            }

            ResponseObject response     = null;
            string         speckleQuery = "";

            if (speckleRequest != null)
            {
                speckleQuery = Speckle.Convert.ToSpeckleQuery(speckleRequest);
            }

            // Download the objects.
            response = SpeckleClient.StreamGetObjectsAsync(SpeckleClient.Stream.StreamId, speckleQuery).Result;

            // Conversion configuration.
            bool storeSpeckleId = true;

            // Extract the configuations from the ActionConfig.
            // In this case, only SpecklePullConfig contains an option.
            SpecklePullConfig config = actionConfig as SpecklePullConfig;

            if (config != null)
            {
                storeSpeckleId = config.StoreSpeckleId;
            }

            List <object> converted = Speckle.Convert.FromSpeckle(response.Resources, storeSpeckleId);

            return(converted);
        }