public ReceiveComponent() : base("Receive", "Receive", "Receive data from a Speckle server", "Speckle 2",
                                  "   Send/Receive")
 {
     BaseWorker = new ReceiveComponentWorker(this);
     Attributes = new ReceiveComponentAttributes(this);
     SetDefaultKitAndConverter();
 }
        public ReceiveComponent() : base("Receive", "Receive", "Receive data from a Speckle server", ComponentCategories.PRIMARY_RIBBON,
                                         ComponentCategories.SEND_RECEIVE)
        {
            Tracker.TrackPageview(Tracker.RECEIVE_ADDED);

            BaseWorker = new ReceiveComponentWorker(this);
            Attributes = new ReceiveComponentAttributes(this);
        }
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            if (RunCount == 1)
            {
                CreateCancelationToken();
                ParseInput(DA);
                if (InputType == "Invalid")
                {
                    return;
                }
            }

            if (InPreSolve)
            {
                Tracker.TrackPageview("receive", "sync");

                var task = Task.Run(async() =>
                {
                    var acc                       = await StreamWrapper?.GetAccount();
                    var client                    = new Client(acc);
                    var remoteTransport           = new ServerTransport(acc, StreamWrapper?.StreamId);
                    remoteTransport.TransportName = "R";

                    var myCommit = await ReceiveComponentWorker.GetCommit(StreamWrapper, client, (level, message) =>
                    {
                        AddRuntimeMessage(level, message);
                    }, CancelToken);

                    if (myCommit == null)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Couldn't get the commit");
                        return(null);
                    }

                    var TotalObjectCount = 1;

                    var ReceivedObject = Operations.Receive(
                        myCommit.referencedObject,
                        source.Token,
                        remoteTransport,
                        new SQLiteTransport {
                        TransportName = "LC"
                    },                                  // Local cache!
                        null,
                        null,
                        count => TotalObjectCount = count,
                        disposeTransports: true
                        ).Result;

                    try
                    {
                        await client.CommitReceived(new CommitReceivedInput
                        {
                            streamId          = StreamWrapper.StreamId,
                            commitId          = myCommit.id,
                            message           = myCommit.message,
                            sourceApplication = Applications.Grasshopper
                        });
                    }
                    catch
                    {
                        // Do nothing!
                    }

                    return(ReceivedObject);
                }, source.Token);
                TaskList.Add(task);
                return;
            }

            if (source.IsCancellationRequested)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Run out of time!");
            }
            else if (!GetSolveResults(DA, out Speckle.Core.Models.Base @base))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Not running multithread");
            }
            else
            {
                if (@base == null)
                {
                    return;
                }
                ReceivedObjectId = @base.id;

                //the active document may have changed
                Converter?.SetContextDocument(RhinoDoc.ActiveDoc);
                var data = Extras.Utilities.ConvertToTree(Converter, @base);

                DA.SetDataTree(0, data);
            }
        }