Ejemplo n.º 1
0
        /***************************************************/
        /****      BHoM side of Revit_Adapter Push      ****/
        /***************************************************/

        public override List <object> Push(IEnumerable <object> objects, string tag = "", PushType pushType = PushType.AdapterDefault, ActionConfig actionConfig = null)
        {
            //Initialize Revit config
            RevitPushConfig pushConfig = actionConfig as RevitPushConfig;

            //If internal adapter is loaded call it directly
            if (InternalAdapter != null)
            {
                InternalAdapter.RevitSettings = RevitSettings;
                return(InternalAdapter.Push(objects, tag, pushType, pushConfig));
            }

            if (!this.IsValid())
            {
                BH.Engine.Reflection.Compute.RecordError("Revit Adapter is not valid. Please check if it has been set up correctly and activated.");
                return(new List <object>());
            }

            //Reset the wait event
            m_WaitEvent.Reset();

            if (!CheckConnection())
            {
                return(new List <object>());
            }

            //Send data through the socket link
            m_LinkIn.SendData(new List <object>()
            {
                PackageType.Push, objects.ToList(), pushType, pushConfig, RevitSettings
            }, tag);

            //Wait until the return message has been recieved
            if (!m_WaitEvent.WaitOne(TimeSpan.FromMinutes(m_WaitTime)))
            {
                BH.Engine.Reflection.Compute.RecordError("The connection with Revit timed out. If working on a big model, try to increase the max wait time");
            }

            //Grab the return objects from the latest package
            List <object> returnObjs = m_ReturnPackage.ToList();

            //Clear the return list
            m_ReturnPackage.Clear();

            RaiseEvents();

            //Check if the return package contains error message
            if (returnObjs.Count == 1 && returnObjs[0] is string)
            {
                Engine.Reflection.Compute.RecordError(returnObjs[0] as string);
                return(new List <object>());
            }

            //Return the package
            return(returnObjs);
        }
Ejemplo n.º 2
0
        private protected SocketConfiguration()
        {
            Logger = new BasicLogger();

            var adapter = new InternalAdapter();

            Serializer = adapter;
            Encoding   = adapter.Encoding;
            TimeOut    = TimeSpan.FromSeconds(5);
        }
Ejemplo n.º 3
0
        /***************************************************/
        /****      BHoM side of Revit_Adapter Pull      ****/
        /***************************************************/

        public override IEnumerable <object> Pull(IRequest request, PullType pullType = PullType.AdapterDefault, ActionConfig actionConfig = null)
        {
            //Check if request is not null or empty
            if (request == null)
            {
                BH.Engine.Reflection.Compute.RecordError("BHoM objects could not be read because provided IRequest is null or empty.");
                return(new List <object>());
            }
            else if (request is FilterRequest)
            {
                FilterRequest filterRequest = (FilterRequest)request;
                if (filterRequest.Type == null && String.IsNullOrWhiteSpace(filterRequest.Tag) && (filterRequest.Equalities == null || filterRequest.Equalities.Count == 0))
                {
                    BH.Engine.Reflection.Compute.RecordError("BHoM objects could not be read because provided IRequest is null or empty.");
                    return(new List <object>());
                }
            }

            //Initialize Revit config
            RevitPullConfig pullConfig = actionConfig as RevitPullConfig;

            //If internal adapter is loaded call it directly
            if (InternalAdapter != null)
            {
                InternalAdapter.RevitSettings = RevitSettings;
                return(InternalAdapter.Pull(request, pullType, pullConfig));
            }

            if (!this.IsValid())
            {
                BH.Engine.Reflection.Compute.RecordError("Revit Adapter is not valid. Please check if it has been set up correctly and activated.");
                return(new List <object>());
            }

            //Reset the wait event
            m_WaitEvent.Reset();

            if (!CheckConnection())
            {
                return(new List <object>());
            }

            //Send data through the socket link
            m_LinkIn.SendData(new List <object>()
            {
                PackageType.Pull, request, pullType, pullConfig, RevitSettings
            });

            //Wait until the return message has been recieved
            if (!m_WaitEvent.WaitOne(TimeSpan.FromMinutes(m_WaitTime)))
            {
                Engine.Reflection.Compute.RecordError("The connection with Revit timed out. If working on a big model, try to increase the max wait time");
            }

            //Grab the return objects from the latest package
            List <object> returnObjs = new List <object>(m_ReturnPackage);

            //Clear the return list
            m_ReturnPackage.Clear();

            //Raise returned events
            RaiseEvents();

            //Check if the return package contains error message
            if (returnObjs.Count == 1 && returnObjs[0] is string)
            {
                Engine.Reflection.Compute.RecordError(returnObjs[0] as string);
                return(new List <object>());
            }

            //Return the package
            return(returnObjs);
        }