コード例 #1
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            DA.DisableGapLogic();
            if (DA.Iteration != 0)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning,
                                  "Cannot fetch multiple streams at the same time. This is an explicit guard against possibly unintended behaviour. If you want to get the details of another stream, please use a new component.");
                return;
            }

            string           userId      = null;
            GH_SpeckleStream ghIdWrapper = null;

            DA.DisableGapLogic();
            if (!DA.GetData(0, ref ghIdWrapper))
            {
                return;
            }
            DA.GetData(1, ref userId);
            var idWrapper = ghIdWrapper.Value;
            var account   = string.IsNullOrEmpty(userId)
        ? AccountManager.GetAccounts().FirstOrDefault(a => a.serverInfo.url == idWrapper.ServerUrl) // If no user is passed in, get the first account for this server
        : AccountManager.GetAccounts().FirstOrDefault(a => a.userInfo.id == userId);                // If user is passed in, get matching user in the db

            if (account == null || account.serverInfo.url != idWrapper.ServerUrl)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error,
                                  $"Could not find an account for server ${idWrapper.ServerUrl}. Use the Speckle Manager to add an account.");
                return;
            }

            if (error != null)
            {
                Message = null;
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, error.Message);
                error  = null;
                stream = null;
            }
            else if (stream == null)
            {
                Message = "Fetching";
                // Validation
                string errorMessage = null;
                if (DA.Iteration == 0)
                {
                    Tracker.TrackPageview(Tracker.STREAM_GET);
                }

                if (!ValidateInput(account, idWrapper.StreamId, ref errorMessage))
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, errorMessage);
                    return;
                }

                // Run
                Task.Run(async() =>
                {
                    try
                    {
                        var acc = idWrapper.GetAccount().Result;
                        stream  = idWrapper;
                    }
                    catch (Exception e)
                    {
                        stream = null;
                        error  = e.InnerException ?? e;
                    }
                    finally
                    {
                        Rhino.RhinoApp.InvokeOnUiThread((Action) delegate { ExpireSolution(true); });
                    }
                });
            }
            else
            {
                Message = "Done";
                DA.SetData(0, new GH_SpeckleStream(stream));
                stream = null;
            }
        }
コード例 #2
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            DA.DisableGapLogic();
            GH_SpeckleStream ghSpeckleStream = null;
            string           name            = null;
            string           description     = null;
            bool             isPublic        = false;

            if (!DA.GetData(0, ref ghSpeckleStream))
            {
                return;
            }
            DA.GetData(1, ref name);
            DA.GetData(2, ref description);
            DA.GetData(3, ref isPublic);

            var streamWrapper = ghSpeckleStream.Value;

            if (error != null)
            {
                Message = null;
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, error.Message);
                error = null;
            }
            else if (stream == null)
            {
                if (streamWrapper == null)
                {
                    Message = "";
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Not a stream wrapper!");
                    return;
                }
                Message = "Fetching";
                Task.Run(async() =>
                {
                    var account = streamWrapper.UserId == null ?
                                  AccountManager.GetDefaultAccount() :
                                  AccountManager.GetAccounts().FirstOrDefault(a => a.userInfo.id == streamWrapper.UserId);

                    if (account == null)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Could not find the specified account in this machine. Use the Speckle Manager to add an account, or modify the input stream with your credentials.");
                        return;
                    }

                    var client = new Client(account);
                    var input  = new StreamUpdateInput();
                    try
                    {
                        stream   = await client.StreamGet(streamWrapper.StreamId);
                        input.id = streamWrapper.StreamId;

                        input.name        = name ?? stream.name;
                        input.description = description ?? stream.description;

                        if (stream.isPublic != isPublic)
                        {
                            input.isPublic = isPublic;
                        }

                        await client.StreamUpdate(input);
                    }
                    catch (Exception e)
                    {
                        error = e;
                    }
                    finally
                    {
                        Rhino.RhinoApp.InvokeOnUiThread((Action) delegate { ExpireSolution(true); });
                    }
                });
            }
            else
            {
                stream  = null;
                Message = "Done";
                DA.SetData(0, streamWrapper.StreamId);
            }
        }
コード例 #3
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            DA.DisableGapLogic();
            if (DA.Iteration != 0)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning,
                                  "Cannot fetch multiple streams at the same time. This is an explicit guard against possibly unintended behaviour. If you want to get the details of another stream, please use a new component.");
                return;
            }

            string           accountId   = null;
            GH_SpeckleStream ghIdWrapper = null;

            DA.DisableGapLogic();
            DA.GetData(0, ref ghIdWrapper);
            DA.GetData(1, ref accountId);
            var account = string.IsNullOrEmpty(accountId) ? AccountManager.GetDefaultAccount() :
                          AccountManager.GetAccounts().FirstOrDefault(a => a.userInfo.id == accountId);

            var idWrapper = ghIdWrapper.Value;

            if (account == null)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Could not find default account in this machine. Use the Speckle Manager to add an account.");
                return;
            }

            Params.Input[1].AddVolatileData(new GH_Path(0), 0, account.userInfo.id);

            if (error != null)
            {
                Message = null;
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, error.Message);
                error  = null;
                stream = null;
            }
            else if (stream == null)
            {
                Message = "Fetching";
                // Validation
                string errorMessage = null;
                if (!ValidateInput(account, idWrapper.StreamId, ref errorMessage))
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, errorMessage);
                    return;
                }

                // Run
                Task.Run(async() =>
                {
                    try
                    {
                        //Exists?
                        var client        = new Client(account);
                        var result        = await client.StreamGet(idWrapper.StreamId);
                        stream            = new StreamWrapper(result.id, account.userInfo.id, account.serverInfo.url);
                        stream.BranchName = idWrapper.BranchName;
                        stream.ObjectId   = idWrapper.ObjectId;
                        stream.CommitId   = idWrapper.CommitId;
                    }
                    catch (Exception e)
                    {
                        stream = null;
                        error  = e;
                    }
                    finally
                    {
                        Rhino.RhinoApp.InvokeOnUiThread((Action) delegate { ExpireSolution(true); });
                    }
                });
            }
            else
            {
                Message = "Done";
                DA.SetData(0, new GH_SpeckleStream(stream));
                stream = null;
            }
        }
コード例 #4
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            DA.DisableGapLogic();
            GH_SpeckleStream ghSpeckleStream = null;
            string           name            = null;
            string           description     = null;
            bool             isPublic        = false;

            if (DA.Iteration == 0)
            {
                Tracker.TrackPageview(Tracker.STREAM_UPDATE);
            }

            if (!DA.GetData(0, ref ghSpeckleStream))
            {
                return;
            }
            DA.GetData(1, ref name);
            DA.GetData(2, ref description);
            DA.GetData(3, ref isPublic);

            var streamWrapper = ghSpeckleStream.Value;

            if (error != null)
            {
                Message = null;
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, error.Message);
                error = null;
            }
            else if (stream == null)
            {
                if (streamWrapper == null)
                {
                    Message = "";
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Not a stream wrapper!");
                    return;
                }
                Message = "Fetching";
                Task.Run(async() =>
                {
                    try
                    {
                        var account = streamWrapper.GetAccount().Result;
                        var client  = new Client(account);
                        var input   = new StreamUpdateInput();
                        stream      = await client.StreamGet(streamWrapper.StreamId);
                        input.id    = streamWrapper.StreamId;

                        input.name        = name ?? stream.name;
                        input.description = description ?? stream.description;

                        if (stream.isPublic != isPublic)
                        {
                            input.isPublic = isPublic;
                        }

                        await client.StreamUpdate(input);
                    }
                    catch (Exception e)
                    {
                        error = e.InnerException ?? e;
                    }
                    finally
                    {
                        Rhino.RhinoApp.InvokeOnUiThread((Action) delegate { ExpireSolution(true); });
                    }
                });
            }
            else
            {
                stream  = null;
                Message = "Done";
                DA.SetData(0, streamWrapper.StreamId);
            }
        }