コード例 #1
0
        //  This solution requires a timeout set on the HTTPClient
        public async static Task <ForgeRestResponse> Retry_ALT_APPROACH(int numberOfRetry, int timeDelay, Func <Dictionary <string, string>, Task <ForgeRestResponse> > function, Dictionary <string, string> parameters)
        {
            NLogger.LogText($"Entered Retry for function {function.Method.Name}");

            int counter = 1;

            while (counter <= numberOfRetry)
            {
                var functionCallTask = await function(parameters);


                if (functionCallTask.IsSuccessStatusCode())
                {
                    //var checkIfSuceeded = functionCallTask.Wait(ConfigUtilities.GetAsyncHTTPCallWaitTime());

                    NLogger.LogText("Exit Retry sucessfully");

                    return(functionCallTask);
                }
                else
                {
                    NLogger.LogText($"Failed attempt number {counter.ToString()}");
                    //Thread.Sleep(timeDelay);
                    await Task.Delay(timeDelay);
                }

                counter++;
            }

            NLogger.LogText("Exit Retry with error");

            throw new Exception("HTTP invocation failed");
        }
コード例 #2
0
        public static string GetProject()
        {
            NLogger.LogText("Entered GetProject method");

            var value = doc.SelectSingleNode("/Configuration/key[@name='BIM360']/key[@name='Project']/@value").Value;

            NLogger.LogText("GetProject - Project {proj}: ", value);

            return(value);
        }
コード例 #3
0
        public static string GetHub()
        {
            NLogger.LogText("Entered GetHub method");

            var value = doc.SelectSingleNode("/Configuration/key[@name='BIM360']/key[@name='HUB']/@value").Value;

            NLogger.LogText("GetHub - Hub {hub}: ", value);

            return(value);
        }
コード例 #4
0
        //  This solution requires a timeout set as Task.Delay
        public async static Task <ForgeRestResponse> Retry(int numberOfRetry, int timeDelay, Func <Dictionary <string, string>, Task <ForgeRestResponse> > function, Dictionary <string, string> parameters)
        {
            NLogger.LogText($"Entered Retry for function {function.Method.Name}");

            var asyncHTTPCallWaitTime = ConfigUtilities.GetAsyncHTTPCallWaitTime();
            int counter = 1;
            int timeDel = timeDelay;

            NLogger.LogText($"Number of retries: {numberOfRetry}");
            NLogger.LogText($"Time to wait between retries of HTTP calls: {timeDelay} ms");
            NLogger.LogText($"Time to wait for HTTP Call: {asyncHTTPCallWaitTime} ms");

            while (counter <= numberOfRetry)
            {
                NLogger.LogText($"Attempt number {counter.ToString()}");

                //  Call function and create a Delay task
                var functionCallTask = function(parameters);
                var timeoutTask      = Task.Delay(asyncHTTPCallWaitTime);

                //  Get the first task which finishes
                var completedTask = await Task.WhenAny(functionCallTask, timeoutTask);

                //  Based on which one finishes before, go along or retry
                if (completedTask == functionCallTask)
                {
                    var ret = await functionCallTask;

                    NLogger.LogText($"Suceeded attempt number {counter.ToString()}");
                    NLogger.LogText("Exit Retry sucessfully");

                    return(ret);
                }
                else
                {
                    NLogger.LogText($"Failed attempt number {counter.ToString()} - HTTP Call timed-out");
                    //Thread.Sleep(timeDelay);
                    await Task.Delay(timeDel);

                    timeDel = timeDel + timeDel;
                }

                counter++;
            }

            NLogger.LogText("Exit Retry with error");

            throw new Exception("HTTP invocation failed");
        }
コード例 #5
0
        public static void LoadConfig()
        {
            NLogger.LogText("Entered LoadConfig");

            try
            {
                var folderBaseLine = Utility.GetFolderBaseline();
                var configPath     = System.IO.Path.Combine(folderBaseLine, "Configuration\\Config.xml");

                doc.Load(configPath);

                NLogger.LogText("Exit LoadConfig success");
            }
            catch (Exception ex)
            {
                NLogger.LogError(ex);
                NLogger.LogText("Exit LoadConfig");
            }
        }
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            NLogger.Initialize();

            NLogger.LogText("Entered Execute method");

            ConfigUtilities.LoadConfig();
            LanguageHandler.Init();

            uiapp = commandData.Application;
            doc   = uiapp.ActiveUIDocument.Document;

            revElementHandler = new RevitElementsHandler(uiapp);
            revFilterHandler  = new RevitFiltersHandler();
            IList <Element> selectedElements = new List <Element>();

            try
            {
                var win = CheckOpened("Offsite Panel");

                if (win != null)
                {
                    //elementWindow = win;
                    //elementWindow.Show();
                    //elementWindow.Focus();

                    win.Close();
                }

                elementWindow = new OffsiteForm(selectedElements, uiapp, RevitElementSelectionMode.FromFilters);
                elementWindow.Show();

                NLogger.LogText("Exit Execute method with Success");
            }
            catch (Exception ex)
            {
                NLogger.LogError(ex);
                NLogger.LogText("Exit Execute method with Error");
            }

            return(Result.Succeeded);
        }
コード例 #7
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            NLogger.Initialize();

            NLogger.LogText("Entered Execute method");

            ConfigUtilities.LoadConfig();
            LanguageHandler.Init();

            uiapp = commandData.Application;
            doc   = uiapp.ActiveUIDocument.Document;

            revElementHandler = new RevitElementsHandler(uiapp);
            revFilterHandler  = new RevitFiltersHandler();
            IList <Element> selectedElements = new List <Element>();

            //  Handle multi-element selection
            Selection sel = uiapp.ActiveUIDocument.Selection;

            try
            {
                NLogger.LogText("Performing selection in Revit");

                var pickedrefs = sel.PickObjects(ObjectType.Element, "Please select an element");

                NLogger.LogText("Selection performed in Revit");

                foreach (var pickedref in pickedrefs)
                {
                    selectedElements.Add(doc.GetElement(pickedref));
                }

                //  TODO: DETERMINE IF SAME FAMILY OR NOT
                //  Handle selected elements info extraction



                var elStructureList   = revElementHandler.ProcessElements(selectedElements);
                var filteredElStrList = revFilterHandler.FilterElements(elStructureList);

                //  Extract all Revit Families for selected Revit elements
                var fileredElStrRevitFamilies = Utility.GetFamilyTypes(filteredElStrList);

                if (fileredElStrRevitFamilies.Count > 1)
                {
                    //MessageBox.Show("Selected elements belong to more than one family. They have to be part of a unique family.");
                    MessageBox.Show(LanguageHandler.GetString("msgBox_SelMultipleRevFam"));
                }
                else
                {
                    var win = CheckOpened("Offsite Panel");

                    if (win != null)
                    {
                        //elementWindow = win;
                        //elementWindow.Show();
                        //elementWindow.Focus();

                        win.Close();
                    }

                    elementWindow = new OffsiteForm(selectedElements, uiapp, RevitElementSelectionMode.FromView);
                    elementWindow.Show();
                }

                NLogger.LogText("Exit Execute method with Success");
            }
            catch (UIRelevantException ex)
            {
                MessageBox.Show(ex.Message);
            }
            catch (Exception ex)
            {
                NLogger.LogError(ex);
                NLogger.LogText("Exit Execute method with Error");
            }

            return(Result.Succeeded);
        }