Пример #1
0
 private void OnDocumentClose(GH_DocumentServer sender, GH_Document doc)
 {
     if (_localReceiverPipe != null)
     {
         _localReceiverPipe.ClosePipe();
         _localReceiverPipe = null;
     }
 }
Пример #2
0
 private void CloseLocalPipe()
 {
     if (_localSenderPipe != null)
     {
         _localSenderPipe.ClosePipe();
         _localSenderPipe = null;
     }
 }
Пример #3
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            try
            {
                string        pipeId = PipeForRevit.PipeIdentifier;
                UIApplication uiApp  = commandData.Application;
                _document = uiApp.ActiveUIDocument.Document;
                PipeForRevit.ActiveDocument = uiApp.ActiveUIDocument.Document;
                Selection sel = uiApp.ActiveUIDocument.Selection;

                Pipe   pipe     = null;
                Action callBack = () => {
                    if (pipe != null)
                    {
                        pipe.ClosePipe();
                    }
                    RevitPipeUtil.ShowMessage("Success", "Pushed data to the pipe.");
                };
                if (PipeDataUtil.IsValidUrl(pipeId))
                {
                    pipe = new MyWebPipe(pipeId, callBack);
                }
                else
                {
                    pipe = new LocalNamedPipe(pipeId, callBack);
                }
                pipe.SetEmitter(this);
                pipe.Update();

                if (GeometryTypeMatch())
                {
                    bool deleteExisting;
                    bool updateGeom = UserDecidedToUpdateGeometry(out deleteExisting);
                    if (updateGeom)
                    {
                        UpdateGeometry(_receivedObjects);
                    }
                    else
                    {
                        _previousIds = AddObjectsToDocument(_receivedObjects, deleteExisting);
                    }
                }
                else
                {
                    _previousIds = AddObjectsToDocument(_receivedObjects, false);
                }

                return(Result.Succeeded);
            }
            catch (Exception e)
            {
                RevitPipeUtil.ShowMessage("Error", "The following error occured. Aborting operation.", e.Message);
                return(Result.Failed);
            }
        }
Пример #4
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            try
            {
                string        pipeId = PipeForRevit.PipeIdentifier;
                UIApplication uiApp  = commandData.Application;
                Document      doc    = uiApp.ActiveUIDocument.Document;
                PipeForRevit.ActiveDocument = uiApp.ActiveUIDocument.Document;
                Selection sel = uiApp.ActiveUIDocument.Selection;

                //List<Reference> pickedCurves = sel.PickObjects(ObjectType.Edge, "Select the curves to send through the pipe or click finish to select" +
                //    "elements").ToList();
                List <Reference> picked = sel.PickObjects(ObjectType.Element, "Select the elements to send through the pipe").ToList();
                _selectedObjects = new List <GeometryObject>();
                Options opt = new Options();
                foreach (var objRef in picked)
                {
                    GeometryElement geom = doc.GetElement(objRef).get_Geometry(opt);
                    _selectedObjects.AddRange(geom.Where((g) => g is Solid || g is Mesh));
                }
                //foreach (var objRef in pickedCurves)
                //{
                //    Edge edge = (Edge)doc.GetElement(objRef).GetGeometryObjectFromReference(objRef);
                //    _selectedObjects.Add(edge);
                //}

                Pipe   pipe     = null;
                Action callBack = () => {
                    if (pipe != null)
                    {
                        pipe.ClosePipe();
                    }
                    RevitPipeUtil.ShowMessage("Success", "Pushed data to the pipe.");
                };
                if (PipeDataUtil.IsValidUrl(pipeId))
                {
                    pipe = new MyWebPipe(pipeId, callBack);
                }
                else
                {
                    pipe = new LocalNamedPipe(pipeId, callBack);
                }
                pipe.SetCollector(this);
                pipe.Update();

                return(Result.Succeeded);
            }
            catch (Exception e)
            {
                RevitPipeUtil.ShowMessage("Error", "The following error occured. Aborting operation.", e.Message);
                return(Result.Failed);
            }
        }
Пример #5
0
        static void Main(string[] args)
        {
            Action finihser = () =>
            {
                Console.WriteLine("The data was received and extracted");
            };
            var senderPipe = new LocalNamedPipe(PIPE_NAME, finihser);

            senderPipe.SetCollector(new TestCollector());
            Console.WriteLine("Ready to serve the data.");
            senderPipe.Update();
            Console.ReadKey();
        }
Пример #6
0
        static void Main(string[] args)
        {
            Action finisher = () =>
            {
                Console.WriteLine("Data transfer finished!.");
            };
            var receiverPipe = new LocalNamedPipe(PIPE_NAME, finisher);

            receiverPipe.SetEmitter(new TestEmitter());

            receiverPipe.Update();
            Console.ReadKey();
        }
Пример #7
0
 private void PullFromLocalPipe(string pipeName)
 {
     if (_localReceiverPipe != null && _localReceiverPipe.Name != pipeName)
     {
         _localReceiverPipe.ClosePipe();
         _localReceiverPipe = null;
     }
     if (_localReceiverPipe == null)
     {
         _localReceiverPipe = new LocalNamedPipe(pipeName);
         _localReceiverPipe.SetEmitter(this);
     }
     _localReceiverPipe.Update();
 }
Пример #8
0
        private void SendViaLocalPipe(string pipeName)
        {
            Action finishingDelegate = () =>
            {
                ClearRuntimeMessages();
                AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "Data Transfer finished");
                ExpireSolution(true);
            };

            AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "waiting for listener...");
            //if(_senderPipe != null) { _senderPipe.ClosePipe(); }
            if (_localSenderPipe != null && _localSenderPipe.Name != pipeName)
            {
                CloseLocalPipe();
            }
            if (_localSenderPipe == null)
            {
                _localSenderPipe = new LocalNamedPipe(pipeName, finishingDelegate);
                _localSenderPipe.SetCollector(this);
            }
            _localSenderPipe.Update();
        }