コード例 #1
0
        /// <summary>
        /// Initializes sender.
        /// </summary>
        /// <param name="restApi">Server address</param>
        /// <param name="apiToken">API token of account</param>
        /// <returns>Task</returns>
        public void Initialize(string restApi, string apiToken, List <SidSpeckleRecord> savedSenderStreamInfo, Func <string, string, IStreamSender> gsaSenderCreator,
                               IProgress <MessageEventArgs> loggingProgress, IProgress <string> statusProgress, IProgress <double> percentageProgress,
                               IProgress <SidSpeckleRecord> streamCreationProgress, IProgress <SidSpeckleRecord> streamDeletionProgress)
        {
            if (IsInit)
            {
                return;
            }

            if (!GSA.IsInit)
            {
                this.loggingProgress.Report(new MessageEventArgs(SpeckleGSAInterfaces.MessageIntent.Display, SpeckleGSAInterfaces.MessageLevel.Error, "GSA link not found."));
                return;
            }

            this.loggingProgress        = loggingProgress;
            this.statusProgress         = statusProgress;
            this.streamCreationProgress = streamCreationProgress;
            this.streamDeletionProgress = streamDeletionProgress;
            this.restApi               = restApi;
            this.apiToken              = apiToken;
            this.gsaSenderCreator      = gsaSenderCreator;
            this.savedSenderSidRecords = savedSenderStreamInfo;
            this.documentName          = Path.GetFileNameWithoutExtension(GSA.App.Proxy.FilePath);
            this.documentTitle         = Path.GetFileNameWithoutExtension(GSA.App.Proxy.GetTitle());

            // Since this is sending, just use whatever is set in the opened GSA file
            GSA.App.Settings.Units = GSA.App.Proxy.GetUnits();

            //Read properties in the opened GSA file
            var baseProps = GetBaseProperties();

            if (!Enum.TryParse(baseProps["units"].ToString(), true, out basePropertyUnits))
            {
                basePropertyUnits = BasePropertyUnits.Millimetres;
            }
            this.tolerance      = Math.Round((double)baseProps["tolerance"], 8);
            this.angleTolerance = Math.Round((double)baseProps["angleTolerance"], 6);

            this.progressEstimator = new ProgressEstimator(percentageProgress, WorkPhase.CacheRead, 3, WorkPhase.CacheUpdate, 1, WorkPhase.Conversion, 20, WorkPhase.ApiCalls, 3);

            Senders.Clear();

            var startTime = DateTime.Now;

            IsInit = true;

            return;
        }
コード例 #2
0
        public async Task <bool> InitializeSender(string documentName, string streamName, BasePropertyUnits units, double tolerance, double angleTolerance,
                                                  IProgress <int> totalProgress, IProgress <int> incrementProgress)
        {
            this.totalProgress     = totalProgress;
            this.incrementProgress = incrementProgress;

            tryCatchWithEvents(() =>
            {
                var streamToCreate = new SpeckleStream()
                {
                    BaseProperties = CreateBaseProperties(units, tolerance, angleTolerance), Name = streamName
                };
                var streamResponse = apiClient.StreamCreateAsync(streamToCreate, timeoutMillisecondsOverride: apiTimeoutOverride).Result;
                apiClient.Stream   = streamResponse.Resource;
                apiClient.StreamId = apiClient.Stream.StreamId;
            },
                               "", "Unable to create stream on the server");

            tryCatchWithEvents(() =>
            {
                var clientResponse = apiClient.ClientCreateAsync(new AppClient()
                {
                    DocumentName = documentName,
                    DocumentType = "GSA",
                    Role         = "Sender",
                    StreamId     = this.StreamId,
                    Online       = true,
                }, timeoutMillisecondsOverride: apiTimeoutOverride).Result;
                apiClient.ClientId = clientResponse.Resource._id;
            }, "", "Unable to create client on the server");

            await InitialiseUser();

            ConnectWebSocket();

            return(true);
        }