Пример #1
0
        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);
        }
Пример #2
0
        public bool CLISender(List <SidSpeckleRecord> savedSenderStreamInfo)
        {
            if (arguments.ContainsKey("sendAllNodes"))
            {
                GSA.App.LocalSettings.SendOnlyMeaningfulNodes = false;
            }

            if (arguments.ContainsKey("resultOnly"))
            {
                GSA.App.LocalSettings.StreamSendConfig = StreamContentConfig.TabularResultsOnly;
            }
            else if (arguments.ContainsKey("result"))
            {
                if (arguments.ContainsKey("separateStreams") || arguments.ContainsKey("resultUnembedded"))
                {
                    GSA.App.LocalSettings.StreamSendConfig = StreamContentConfig.ModelWithTabularResults;
                }
                else
                {
                    GSA.App.LocalSettings.StreamSendConfig = StreamContentConfig.ModelWithEmbeddedResults;
                }
            }
            else
            {
                GSA.App.LocalSettings.StreamSendConfig = StreamContentConfig.ModelOnly;
            }

            if (arguments.ContainsKey("resultInLocalAxis"))
            {
                GSA.App.Settings.ResultInLocalAxis = true;
            }
            if (arguments.ContainsKey("result1DNumPosition"))
            {
                try
                {
                    GSA.App.Settings.Result1DNumPosition = Convert.ToInt32(arguments["result1DNumPosition"]);
                }
                catch { }
            }

            if (GSA.App.LocalSettings.SendResults)
            {
                var results = arguments["result"].Split(new char[] { ',' }).Select(x => x.Replace("\"", ""));
                var reverseResultTypeMap = GSAProxy.ResultTypeStrings.ToDictionary(kvp => kvp.Value, kvp => kvp.Key);
                GSA.GsaApp.Settings.ResultTypes = results.Where(r => reverseResultTypeMap.ContainsKey(r)).Select(r => reverseResultTypeMap[r]).ToList();
                GSA.GsaApp.Proxy.PrepareResults(GSA.GsaApp.Settings.ResultTypes);

                /*
                 * foreach (string r in results)
                 * {
                 * if (Result.NodalResultMap.ContainsKey(r))
                 * {
                 *  GSA.GsaApp.Settings.NodalResults[r] = Result.NodalResultMap[r];
                 * }
                 * else if (Result.Element1DResultMap.ContainsKey(r))
                 * {
                 *  GSA.GsaApp.Settings.Element1DResults[r] = Result.Element1DResultMap[r];
                 * }
                 * else if (Result.Element2DResultMap.ContainsKey(r))
                 * {
                 *  GSA.GsaApp.Settings.Element2DResults[r] = Result.Element2DResultMap[r];
                 * }
                 * else if (Result.MiscResultMap.ContainsKey(r))
                 * {
                 *  GSA.GsaApp.Settings.MiscResults[r] = Result.MiscResultMap[r];
                 * }
                 * }
                 */
            }

            if (arguments.ContainsKey("resultCases"))
            {
                GSA.App.Settings.ResultCases = arguments["resultCases"].Split(new char[] { ',' }).ToList();
            }

            //GSA.GetSpeckleClients(EmailAddress, RestApi);
            var gsaSenderCoordinator = new SenderCoordinator();

            gsaSenderCoordinator.Initialize(RestApi, ApiToken, (savedSenderStreamInfo == null || savedSenderStreamInfo.Count() == 0) ? null : savedSenderStreamInfo,
                                            streamSenderCreationFn, loggingProgress, new Progress <string>(), new Progress <double>(), new Progress <SidSpeckleRecord>(), new Progress <SidSpeckleRecord>());
            gsaSenderCoordinator.Trigger().Wait();
            //The Trigger method creates the senders, so need to wait until that is finished before saving the sender info to the file
            HelperFunctions.SetSidSpeckleRecords(EmailAddress, RestApi, GSA.App.Proxy, null,
                                                 gsaSenderCoordinator.Senders.Keys.Select(k => new SidSpeckleRecord(gsaSenderCoordinator.Senders[k].StreamId, k, gsaSenderCoordinator.Senders[k].ClientId)).ToList());

            gsaSenderCoordinator.Dispose();

            var filePath = arguments["file"];

            if (filePath.StartsWith("."))
            {
                string sCurrentDirectory = AppDomain.CurrentDomain.BaseDirectory;
                filePath = Path.GetFullPath(Path.Combine(sCurrentDirectory, filePath));
            }

            GSA.App.Proxy.SaveAs(filePath);
            GSA.App.Proxy.Close();

            Console.WriteLine("Sending complete");
            return(true);
        }
Пример #3
0
        public static async Task <bool> SendTriggered(SenderCoordinator gsaSenderCoordinator)
        {
            await gsaSenderCoordinator.Trigger();

            return(true);
        }