コード例 #1
0
        /***************************************************/
        /****             Private  Methods              ****/
        /***************************************************/

        private void M_linkOut_DataObservers(oM.Adapters.Socket.DataPackage package)
        {
            //Store the return data
            m_ReturnPackage = package.Data;

            //Store the events
            m_ReturnEvents = package.Events;

            //Set the wait event to allow methods to continue
            m_WaitEvent.Set();
        }
コード例 #2
0
        /***************************************************/

        public void ReturnData(IEnumerable <object> objs)
        {
            oM.Adapters.Socket.DataPackage package = new oM.Adapters.Socket.DataPackage
            {
                Data   = objs.ToList(),
                Events = BH.Engine.Reflection.Query.CurrentEvents(),
                Tag    = ""
            };

            m_LinkOut.SendData(package);
        }
コード例 #3
0
        /***************************************************/

        private bool CheckPackage(oM.Adapters.Socket.DataPackage package)
        {
            if (package.Data.Count == 0)
            {
                ReturnData(new List <string> {
                    "Can't handle empty package."
                });
                return(false);
            }

            PackageType packageType;

            try
            {
                packageType = (PackageType)package.Data[0];
            }
            catch
            {
                ReturnData(new List <string> {
                    "Unrecognized package type."
                });
                return(false);
            }

            int packageSize = 0;

            switch (packageType)
            {
            case PackageType.ConnectionCheck:
                packageSize = 1;
                break;

            case PackageType.Pull:
            case PackageType.Push:
                packageSize = 5;
                break;

            case PackageType.Remove:
                packageSize = 4;
                break;
            }

            if (package.Data.Count != packageSize)
            {
                ReturnData(new List <string> {
                    "Invalid package size for given package type."
                });
                return(false);
            }

            return(true);
        }
コード例 #4
0
        /***************************************************/
        /****           Data observer method            ****/
        /***************************************************/

        private void M_linkIn_DataObservers(oM.Adapters.Socket.DataPackage package)
        {
            BH.Engine.Reflection.Compute.ClearCurrentEvents();

            ExternalEvent eve = null;

            lock (m_PackageLock)
            {
                if (!CheckPackage(package))
                {
                    return;
                }

                PackageType packageType = (PackageType)package.Data[0];

                switch (packageType)
                {
                case PackageType.ConnectionCheck:
                {
                    ReturnData(new List <object>());
                    return;
                }

                case PackageType.Push:
                {
                    //Set the event to raise
                    eve = m_PushEvent;

                    //Clear the previous package list
                    LatestPackage = new List <IObject>();

                    //Add all objects to the list
                    foreach (object obj in package.Data[1] as IEnumerable <object> )
                    {
                        if (obj is IObject)
                        {
                            LatestPackage.Add(obj as IObject);
                        }
                    }

                    // Get push type
                    if (!(package.Data[2] is PushType) && (!(package.Data[2] is int) || (int)package.Data[2] < 0 || (int)package.Data[2] >= Enum.GetNames(typeof(PushType)).Length))
                    {
                        return;
                    }

                    LatestPushType  = (PushType)package.Data[2];
                    LatestConfig    = package.Data[3] as ActionConfig;
                    AdapterSettings = package.Data[4] as RevitSettings;
                    break;
                }

                case PackageType.Pull:
                {
                    //Set the event to raise
                    eve = m_PullEvent;

                    //Clear the previous package list
                    LatestRequest = package.Data[1] as IRequest;

                    // Get pull type
                    if (!(package.Data[2] is PullType) && (!(package.Data[2] is int) || (int)package.Data[2] < 0 || (int)package.Data[2] >= Enum.GetNames(typeof(PullType)).Length))
                    {
                        return;
                    }

                    LatestPullType  = (PullType)package.Data[2];
                    LatestConfig    = package.Data[3] as ActionConfig;
                    AdapterSettings = package.Data[4] as RevitSettings;
                    break;
                }

                case PackageType.Remove:
                {
                    //Set the event to raise
                    eve = m_RemoveEvent;

                    //Clear the previous package list
                    LatestRequest   = package.Data[1] as IRequest;
                    LatestConfig    = package.Data[2] as ActionConfig;
                    AdapterSettings = package.Data[3] as RevitSettings;
                    break;
                }

                case PackageType.UpdateTags:
                {
                    //Set the event to raise
                    eve = m_UpdateTagsEvent;

                    var tuple = package.Data[1] as Tuple <IRequest, string, object>;
                    LatestRequest      = tuple.Item1;
                    LatestKeyValuePair = new KeyValuePair <string, object>(tuple.Item2, tuple.Item3);
                    break;
                }

                default:
                    ReturnData(new List <string> {
                        "Unrecognized package type"
                    });
                    return;
                }

                LatestTag = package.Tag;
            }

            eve.Raise();
        }