Ejemplo n.º 1
0
        public static Dictionary <string, object> Receive(StreamWrapper stream, CancellationToken cancellationToken,
                                                          Action <ConcurrentDictionary <string, int> > onProgressAction = null, Action <string, Exception> onErrorAction = null,
                                                          Action <int> onTotalChildrenCountKnown = null)
        {
            var account = stream.GetAccount().Result;
            //

            var    client = new Client(account);
            Commit commit = null;

            if (stream.Type == StreamWrapperType.Stream || stream.Type == StreamWrapperType.Branch)
            {
                stream.BranchName = string.IsNullOrEmpty(stream.BranchName) ? "main" : stream.BranchName;

                try
                {
                    var branch = client.BranchGet(cancellationToken, stream.StreamId, stream.BranchName, 1).Result;
                    if (!branch.commits.items.Any())
                    {
                        throw new SpeckleException("No commits found.");
                    }

                    commit = branch.commits.items[0];
                }
                catch
                {
                    throw new SpeckleException("No branch found with name " + stream.BranchName);
                }
            }
            else if (stream.Type == StreamWrapperType.Commit)
            {
                try
                {
                    commit = client.CommitGet(cancellationToken, stream.StreamId, stream.CommitId).Result;
                }
                catch (Exception ex)
                {
                    Utils.HandleApiExeption(ex);
                    return(null);
                }
            }
            else if (stream.Type == StreamWrapperType.Object)
            {
                commit = new Commit()
                {
                    referencedObject = stream.ObjectId, id = Guid.NewGuid().ToString()
                };
            }

            if (commit == null)
            {
                throw new SpeckleException("Could not get commit.");
            }

            if (cancellationToken.IsCancellationRequested)
            {
                return(null);
            }

            var transport = new ServerTransport(account, stream.StreamId);
            var @base     = Operations.Receive(
                commit.referencedObject,
                cancellationToken,
                remoteTransport: transport,
                onProgressAction: onProgressAction,
                onErrorAction: onErrorAction,
                onTotalChildrenCountKnown: onTotalChildrenCountKnown,
                disposeTransports: true
                ).Result;

            try
            {
                client.CommitReceived(new CommitReceivedInput
                {
                    streamId          = stream.StreamId,
                    commitId          = commit?.id,
                    message           = commit?.message,
                    sourceApplication = Applications.DynamoRevit
                }).Wait();
            }
            catch
            {
                // Do nothing!
            }

            if (cancellationToken.IsCancellationRequested)
            {
                return(null);
            }

            var converter = new BatchConverter();
            var data      = converter.ConvertRecursivelyToNative(@base);

            return(new Dictionary <string, object> {
                { "data", data }, { "commit", commit }
            });
        }
Ejemplo n.º 2
0
        public static Dictionary <string, object> Receive(StreamWrapper stream, CancellationToken cancellationToken,
                                                          Action <ConcurrentDictionary <string, int> > onProgressAction = null, Action <string, Exception> onErrorAction = null,
                                                          Action <int> onTotalChildrenCountKnown = null)
        {
            Core.Credentials.Account account = stream.GetAccount();
            stream.BranchName = string.IsNullOrEmpty(stream.BranchName) ? "main" : stream.BranchName;

            var    client = new Client(account);
            Commit commit = null;

            if (string.IsNullOrEmpty(stream.CommitId))
            {
                var res        = client.StreamGet(cancellationToken, stream.StreamId).Result;
                var mainBranch = res.branches.items.FirstOrDefault(b => b.name == stream.BranchName);
                if (mainBranch == null)
                {
                    Log.CaptureAndThrow(new Exception("No branch found with name " + stream.BranchName));
                }

                if (!mainBranch.commits.items.Any())
                {
                    throw new Exception("No commits found.");
                }

                commit = mainBranch.commits.items[0];
            }
            else
            {
                commit = client.CommitGet(cancellationToken, stream.StreamId, stream.CommitId).Result;
            }

            if (commit == null)
            {
                throw new Exception("Could not get commit.");
            }

            if (cancellationToken.IsCancellationRequested)
            {
                return(null);
            }

            var transport = new ServerTransport(account, stream.StreamId);
            var @base     = Operations.Receive(
                commit.referencedObject,
                cancellationToken,
                remoteTransport: transport,
                onProgressAction: onProgressAction,
                onErrorAction: onErrorAction,
                onTotalChildrenCountKnown: onTotalChildrenCountKnown
                ).Result;

            if (cancellationToken.IsCancellationRequested)
            {
                return(null);
            }

            var converter = new BatchConverter();
            var data      = converter.ConvertRecursivelyToNative(@base);

            return(new Dictionary <string, object> {
                { "data", data }, { "commit", commit }
            });
        }
Ejemplo n.º 3
0
        public static Dictionary <string, object> Receive(StreamWrapper stream, CancellationToken cancellationToken,
                                                          Action <ConcurrentDictionary <string, int> > onProgressAction = null, Action <string, Exception> onErrorAction = null,
                                                          Action <int> onTotalChildrenCountKnown = null)
        {
            var account = stream.GetAccount().Result;

            stream.BranchName = string.IsNullOrEmpty(stream.BranchName) ? "main" : stream.BranchName;

            var    client = new Client(account);
            Commit commit = null;

            if (stream.Type == StreamWrapperType.Stream || stream.Type == StreamWrapperType.Branch)
            {
                List <Branch> branches;
                try
                {
                    branches = client.StreamGetBranches(cancellationToken, stream.StreamId).Result;
                }
                catch (Exception ex)
                {
                    Utils.HandleApiExeption(ex);
                    return(null);
                }

                var branch = branches.FirstOrDefault(b => b.name == stream.BranchName);
                if (branch == null)
                {
                    throw new SpeckleException("No branch found with name " + stream.BranchName);
                }

                if (!branch.commits.items.Any())
                {
                    throw new SpeckleException("No commits found.");
                }

                commit = branch.commits.items[0];
            }
            else if (stream.Type == StreamWrapperType.Commit)
            {
                try
                {
                    commit = client.CommitGet(cancellationToken, stream.StreamId, stream.CommitId).Result;
                }
                catch (Exception ex)
                {
                    Utils.HandleApiExeption(ex);
                    return(null);
                }
            }
            else if (stream.Type == StreamWrapperType.Object)
            {
                commit = new Commit()
                {
                    referencedObject = stream.ObjectId, id = Guid.NewGuid().ToString()
                };
            }

            if (commit == null)
            {
                throw new SpeckleException("Could not get commit.");
            }

            if (cancellationToken.IsCancellationRequested)
            {
                return(null);
            }

            var transport = new ServerTransport(account, stream.StreamId);
            var @base     = Operations.Receive(
                commit.referencedObject,
                cancellationToken,
                remoteTransport: transport,
                onProgressAction: onProgressAction,
                onErrorAction: onErrorAction,
                onTotalChildrenCountKnown: onTotalChildrenCountKnown
                ).Result;

            if (cancellationToken.IsCancellationRequested)
            {
                return(null);
            }

            var converter = new BatchConverter();
            var data      = converter.ConvertRecursivelyToNative(@base);

            return(new Dictionary <string, object> {
                { "data", data }, { "commit", commit }
            });
        }