public static async Task <bool> SendInitial(TabCoordinator coordinator, SenderCoordinator gsaSenderCoordinator, IProgress <SidSpeckleRecord> streamCreationProgress, IProgress <SidSpeckleRecord> streamDeletionProgress, IProgress <MessageEventArgs> loggingProgress, IProgress <string> statusProgress, IProgress <double> percentageProgress) { GSA.App.Settings.TargetLayer = coordinator.SenderTab.TargetLayer; GSA.App.Settings.StreamSendConfig = coordinator.SenderTab.StreamContentConfig; GSA.App.LocalSettings.Result1DNumPosition = coordinator.SenderTab.AdditionalPositionsFor1dElements; //end points (2) plus additional var resultsToSend = coordinator.SenderTab.ResultSettings.ResultSettingItems.Where(rsi => rsi.Selected).ToList(); if (resultsToSend != null && resultsToSend.Count() > 0 && !string.IsNullOrEmpty(coordinator.SenderTab.LoadCaseList)) { //Prepare the cache for the ability to parse the load case string var initialData = GSA.App.Proxy.GetGwaData(GSA.App.LocalCache.KeywordsForLoadCaseExpansion, false); for (int i = 0; i < initialData.Count(); i++) { var applicationId = (string.IsNullOrEmpty(initialData[i].ApplicationId)) ? null : initialData[i].ApplicationId; GSA.App.Cache.Upsert( initialData[i].Keyword, initialData[i].Index, initialData[i].GwaWithoutSet, streamId: initialData[i].StreamId, applicationId: applicationId, gwaSetCommandType: initialData[i].GwaSetType); } var resultCases = GSA.App.LocalCache.ExpandLoadCasesAndCombinations(coordinator.SenderTab.LoadCaseList); if (resultCases != null && resultCases.Count() > 0) { percentageProgress.Report(5); loggingProgress.Report(new MessageEventArgs(MessageIntent.Display, MessageLevel.Information, "Resolved load cases")); GSA.App.Settings.ResultCases = resultCases; GSA.App.Settings.ResultTypes = resultsToSend.Select(rts => rts.ResultType).ToList(); if (GSA.App.LocalSettings.SendResults && resultCases.Count() > 0) { GSA.App.LocalProxy.PrepareResults(GSA.App.Settings.ResultTypes, GSA.App.LocalSettings.Result1DNumPosition + 2); loggingProgress.Report(new MessageEventArgs(MessageIntent.Display, MessageLevel.Information, "Extracted results")); } } } coordinator.SenderTab.SetDocumentName(GSA.App.Proxy.GetTitle()); var messenger = new ProgressMessenger(loggingProgress); Func <string, string, SpeckleInterface.IStreamSender> streamSenderCreationFn = ((url, token) => new SpeckleInterface.StreamSender(url, token, messenger)); gsaSenderCoordinator.Initialize(coordinator.Account.ServerUrl, coordinator.Account.Token, coordinator.SenderTab.SenderSidRecords, streamSenderCreationFn, loggingProgress, statusProgress, percentageProgress, streamCreationProgress, streamDeletionProgress); await gsaSenderCoordinator.Trigger(); coordinator.WriteStreamInfo(); return(true); }
public static bool Receive(TabCoordinator coordinator, ReceiverCoordinator gsaReceiverCoordinator, IProgress <SidSpeckleRecord> streamCreationProgress, IProgress <MessageEventArgs> loggingProgress, IProgress <string> statusProgress, IProgress <double> percentageProgress) { GSA.App.Settings.TargetLayer = coordinator.ReceiverTab.TargetLayer; GSA.App.Settings.Units = UnitEnumToString(coordinator.ReceiverTab.CoincidentNodeUnits); GSA.App.Settings.CoincidentNodeAllowance = coordinator.ReceiverTab.CoincidentNodeAllowance; var messenger = new ProgressMessenger(loggingProgress); coordinator.ReceiverTab.StreamListToSidRecords(); Func <string, string, SpeckleInterface.IStreamReceiver> streamReceiverCreationFn = ((url, token) => new SpeckleInterface.StreamReceiver(url, token, messenger)); if (!gsaReceiverCoordinator.Initialize(coordinator.Account.ServerUrl, coordinator.Account.Token, coordinator.ReceiverTab.ReceiverSidRecords, streamReceiverCreationFn, loggingProgress, statusProgress, percentageProgress)) { return(false); } gsaReceiverCoordinator.Trigger(null, null); //Unlike for sending, the command itself doesn't dispose of the (receiver) coordinator here, as in the case of continuous mode it needs to persist as it needs //a constant web socket connection coordinator.WriteStreamInfo(); return(true); }
public static bool OpenFile(TabCoordinator coordinator, IProgress <MessageEventArgs> loggingProgress) { var openFileDialog = new OpenFileDialog(); if (openFileDialog.ShowDialog() == true) { try { GSA.App.Proxy.OpenFile(openFileDialog.FileName, true); } catch (Exception ex) { loggingProgress.Report(new MessageEventArgs(MessageIntent.Display, MessageLevel.Error, "Unable to load " + openFileDialog.FileName + " - refer to logs for more information")); loggingProgress.Report(new MessageEventArgs(MessageIntent.TechnicalLog, MessageLevel.Error, ex, "Unable to load file")); return(false); } if (!string.IsNullOrEmpty(openFileDialog.FileName)) { coordinator.FilePath = openFileDialog.FileName; } coordinator.FileStatus = GsaLoadedFileType.ExistingFile; return(true); } else { return(false); } }
public static bool NewFile(TabCoordinator coordinator, IProgress <MessageEventArgs> loggingProgress) { GSA.App.Proxy.NewFile(true); coordinator.ReceiverTab.ReceiverSidRecords.Clear(); coordinator.SenderTab.SenderSidRecords.Clear(); loggingProgress.Report(new MessageEventArgs(MessageIntent.Display, MessageLevel.Information, "Created new file.")); return(true); }
public static bool SaveFile(TabCoordinator coordinator) { if (coordinator.FileStatus == GsaLoadedFileType.NewFile) { OpenFileDialog openFileDialog = new OpenFileDialog(); if (openFileDialog.ShowDialog() == true) { GSA.App.Proxy.SaveAs(openFileDialog.FileName); } } else if (coordinator.FileStatus == GsaLoadedFileType.ExistingFile) { GSA.App.Proxy.SaveAs(coordinator.FilePath); } return(true); }
public static async Task <bool> CloneStream(TabCoordinator coordinator, string streamId, IProgress <MessageEventArgs> loggingProgress) { var messenger = new ProgressMessenger(loggingProgress); var clonedStreamId = await SpeckleInterface.SpeckleStreamManager.CloneStream(coordinator.Account.ServerUrl, coordinator.Account.Token, streamId, messenger); return(!string.IsNullOrEmpty(clonedStreamId)); /* * if (string.IsNullOrEmpty(clonedStreamId)) * { * loggingProgress.Report(new MessageEventArgs(MessageIntent.Display, MessageLevel.Error, "Unable to clone " + streamId)); * return false; * } * loggingProgress.Report(new MessageEventArgs(MessageIntent.Display, MessageLevel.Information, "Cloned to: " + clonedStreamId)); * return true; */ }
public static async Task <bool> CompleteLogin(TabCoordinator coordinator, SpeckleAccountForUI accountCandidate, IProgress <MessageEventArgs> loggingProgress) { var messenger = new ProgressMessenger(loggingProgress); var accountName = await SpeckleInterface.SpeckleStreamManager.GetClientName(accountCandidate.ServerUrl, accountCandidate.Token, messenger); if (string.IsNullOrEmpty(accountName)) { return(false); } else { accountCandidate.Update(accountName); } if (accountCandidate != null && accountCandidate.IsValid) { var streamData = await SpeckleInterface.SpeckleStreamManager.GetStreams(accountCandidate.ServerUrl, accountCandidate.Token, messenger); if (streamData == null) { return(false); } coordinator.Account = accountCandidate; coordinator.ServerStreamList.StreamListItems.Clear(); foreach (var sd in streamData) { coordinator.ServerStreamList.StreamListItems.Add(new StreamListItem(sd.StreamId, sd.Name)); } //This is used to generate URLs for objects and add them to the error context stored in error messages (generated by kits) in the log GSA.App.LocalSettings.ServerAddress = coordinator.Account.ServerUrl; loggingProgress.Report(new MessageEventArgs(MessageIntent.Display, MessageLevel.Information, "Logged into account at: " + coordinator.Account.ServerUrl)); return(true); } else { return(false); } }
public static async Task <bool> RenameStream(TabCoordinator coordinator, string streamId, string newStreamName, IProgress <MessageEventArgs> loggingProgress) { var messenger = new ProgressMessenger(loggingProgress); var changed = await SpeckleInterface.SpeckleStreamManager.UpdateStreamName(coordinator.Account.ServerUrl, coordinator.Account.Token, streamId, newStreamName, messenger); return(changed); /* * if (changed) * { * coordinator.SenderTab.ChangeSidRecordStreamName(streamId, newStreamName); * loggingProgress.Report(new MessageEventArgs(MessageIntent.Display, MessageLevel.Information, "Changed name of the stream to " + newStreamName)); * return true; * } * loggingProgress.Report(new MessageEventArgs(MessageIntent.Display, MessageLevel.Information, "Unable to change the name of the stream to " + newStreamName)); * return false; */ }
public static async Task <bool> InitialLoad(TabCoordinator coordinator, IProgress <MessageEventArgs> loggingProgress) { coordinator.Init(); try { //This will throw an exception if there is no default account var account = LocalContext.GetDefaultAccount(); if (account == null) { return(false); } return(await CompleteLogin(coordinator, new SpeckleAccountForUI(account.RestApi, account.Email, account.Token), loggingProgress)); } catch { loggingProgress.Report(new MessageEventArgs(MessageIntent.Display, MessageLevel.Information, "No default account found - press the Login button to login/select an account")); return(false); } }
public static async Task <bool> ReadSavedStreamInfo(TabCoordinator coordinator, IProgress <MessageEventArgs> loggingProgress) { if (coordinator.FileStatus == GsaLoadedFileType.ExistingFile && coordinator.Account != null && coordinator.Account.IsValid) { var retrieved = coordinator.RetrieveSavedSidStreamRecords(); if (retrieved) { if (coordinator.ReceiverTab.ReceiverSidRecords.Count() > 0) { var messenger = new ProgressMessenger(loggingProgress); var invalidSidRecords = new List <SidSpeckleRecord>(); //Since the buckets are stored in the SID tags, but not the stream names, get the stream names foreach (var r in coordinator.ReceiverTab.ReceiverSidRecords) { var basicStreamData = await SpeckleInterface.SpeckleStreamManager.GetStream(coordinator.Account.ServerUrl, coordinator.Account.Token, r.StreamId, messenger); if (basicStreamData == null) { invalidSidRecords.Add(r); } else if (!string.IsNullOrEmpty(basicStreamData.Name)) { r.SetName(basicStreamData.Name); } } invalidSidRecords.ForEach(r => coordinator.ReceiverTab.RemoveSidSpeckleRecord(r)); coordinator.ReceiverTab.SidRecordsToStreamList(); loggingProgress.Report(new MessageEventArgs(MessageIntent.Display, MessageLevel.Information, "Found streams from the same server stored in file for receiving: " + string.Join(", ", coordinator.ReceiverTab.ReceiverSidRecords.Select(r => r.StreamId)))); } if (coordinator.SenderTab.SenderSidRecords.Count() > 0) { var messenger = new ProgressMessenger(loggingProgress); var invalidSidRecords = new List <SidSpeckleRecord>(); //Since the buckets are stored in the SID tags, but not the stream names, get the stream names foreach (var r in coordinator.SenderTab.SenderSidRecords) { var basicStreamData = await SpeckleInterface.SpeckleStreamManager.GetStream(coordinator.Account.ServerUrl, coordinator.Account.Token, r.StreamId, messenger); if (basicStreamData == null) { invalidSidRecords.Add(r); } else if (!string.IsNullOrEmpty(basicStreamData.Name)) { r.SetName(basicStreamData.Name); } } invalidSidRecords.ForEach(r => coordinator.SenderTab.RemoveSidSpeckleRecord(r)); coordinator.SenderTab.SidRecordsToStreamList(); loggingProgress.Report(new MessageEventArgs(MessageIntent.Display, MessageLevel.Information, "Found streams from the same server stored in file for sending: " + string.Join(", ", coordinator.SenderTab.SenderSidRecords.Select(r => r.StreamId)))); } } return(retrieved); } return(true); }
public static async Task <bool> GetStreamList(TabCoordinator coordinator, SpeckleAccountForUI account, IProgress <MessageEventArgs> loggingProgress) { return(await CompleteLogin(coordinator, account, loggingProgress)); }