/// <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
    /// <summary>
    /// Initializes receiver.
    /// </summary>
    /// <param name="restApi">Server address</param>
    /// <param name="apiToken">API token of account</param>
    /// <returns>Task</returns>
    public bool Initialize(string restApi, string apiToken, List<SidSpeckleRecord> receiverStreamInfo,
      Func<string, string, SpeckleInterface.IStreamReceiver> streamReceiverCreationFn, 
      IProgress<MessageEventArgs> loggingProgress, IProgress<string> statusProgress, IProgress<double> percentageProgress)
		{
      StreamReceivers.Clear();

      this.loggingProgress = loggingProgress;
      this.statusProgress = statusProgress;

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

      if (IsInit) return true;

      var startTime = DateTime.Now;
			if (!GSA.IsInit)
			{
        this.loggingProgress.Report(new MessageEventArgs(MessageIntent.Display, MessageLevel.Error, "GSA link not found."));
				return false;
			}

      this.loggingProgress.Report(new MessageEventArgs(MessageIntent.Display, MessageLevel.Information, "Initialising receivers"));

      statusProgress.Report("Reading GSA data into cache");

      UpdateCache();
                                                
      // Create receivers
      statusProgress.Report("Accessing streams");

      //TO DO - expand in the future
      Progress<int> incrementProgress = new Progress<int>();
      //incrementProgress.ProgressChanged += <some function which updates the progressEstimator>
      Progress<int> totalProgress = new Progress<int>();
      //totalProgress.ProgressChanged += <some function which updates the progressEstimator>

      int failedInitialisations = 0;
      foreach (var streamInfo in receiverStreamInfo.Where(r => !string.IsNullOrEmpty(r.StreamId)))
			{
        var streamReceiver = streamReceiverCreationFn(restApi, apiToken);
        if (streamReceiver.InitializeReceiver(streamInfo.StreamId, streamInfo.Bucket, totalProgress, incrementProgress).Result)
        {
          StreamReceivers.Add(streamInfo.StreamId, streamReceiver);
          StreamReceivers[streamInfo.StreamId].UpdateGlobalTrigger += Trigger;
        }
        else
        {
          failedInitialisations++;
        }
			};

      statusProgress.Report("Ready to receive");

      if (failedInitialisations > 0)
      {
        return false;
      }

      IsInit = true;

      TimeSpan duration = DateTime.Now - startTime;
      this.loggingProgress.Report(new MessageEventArgs(MessageIntent.Display, MessageLevel.Information, "Duration of initialisation: " + duration.ToString(@"hh\:mm\:ss")));
      this.loggingProgress.Report(new MessageEventArgs(MessageIntent.Telemetry, MessageLevel.Information, "receive", "initialisation", "duration", duration.ToString(@"hh\:mm\:ss")));

      GSA.App.LocalProxy.SetUnits(GSA.App.Settings.Units);

			return true;
		}