示例#1
0
        /// <summary>
        /// This method will be executed for moving to the next, previous or current step, basically searches the step in the list.
        /// </summary>
        /// <param name="stepFlow">The direction flow of the Guide, can be BACKWARD, FORWARD or CURRENT</param>
        /// <param name="CurrentStepSequence">This parameter is the current Step sequence</param>
        internal void CalculateStep(GuideFlow stepFlow, int CurrentStepSequence)
        {
            Step resultStep     = null;
            int  stepFlowOffSet = Convert.ToInt32(stepFlow);
            var  possibleSteps  = (from step in GuideSteps where step.Sequence == CurrentStepSequence + stepFlowOffSet select step);

            if (possibleSteps != null && possibleSteps.Count() > 0)
            {
                //This section validates if the Current Step can be several ones, so we need to get the one validated
                //Means that there only one possible Current Steps
                if (possibleSteps.Count() == 1)
                {
                    resultStep = possibleSteps.FirstOrDefault();
                }
                //Means that there are several posible current Steps then we need to take the one validated
                else
                {
                    foreach (var step in possibleSteps)
                    {
                        step.ExecutePreValidation();
                    }

                    resultStep = possibleSteps.FirstOrDefault(x => x.PreValidationIsOpenFlag);
                }
                if (resultStep != null)
                {
                    SetLibraryViewVisible(resultStep.ShowLibrary);
                    CurrentStep = resultStep;
                }
            }
        }
        /// <summary>
        /// This method will be executed when passing from Step 2 to Step 3 in the Packages guide, so it will show the TermsOfUse Window in case it was not accepted yet
        /// </summary>
        /// <param name="stepInfo"></param>
        /// <param name="uiAutomationData"></param>
        /// <param name="enableFunction"></param>
        /// <param name="currentFlow"></param>
        internal static void ExecuteTermsOfServiceFlow(Step stepInfo, StepUIAutomation uiAutomationData, bool enableFunction, GuideFlow currentFlow)
        {
            CurrentExecutingStep = stepInfo;

            if (stepInfo.ExitGuide != null)
            {
                exitGuide = stepInfo.ExitGuide;
            }

            //When enableFunction = true, means we want to show the TermsOfUse Window (this is executed in the UIAutomation step in the Show() method)
            if (enableFunction)
            {
                //If the TermsOfService is not accepted yet it will show the TermsOfUseView otherwise it will show the PackageManagerSearchView
                stepInfo.DynamoViewModelStep.ShowPackageManagerSearch(null);
                Window ownedWindow = Guide.FindWindowOwned(stepInfo.HostPopupInfo.WindowName, stepInfo.MainWindow as Window);

                foreach (var handler in uiAutomationData.AutomaticHandlers)
                {
                    if (ownedWindow == null)
                    {
                        return;
                    }
                    UIElement element = Guide.FindChild(ownedWindow, handler.HandlerElement);

                    //When the Accept button is pressed in the TermsOfUseView then we need to move to the next Step
                    if (element != null)
                    {
                        ManageEventHandler(element, handler.HandlerElementEvent, handler.ExecuteMethod);
                    }
                }
            }
            //When enableFunction = false, means we are hiding (closing) the TermsOfUse Window due that we are moving to the next Step or we are exiting the Guide
            else
            {
                Window ownedWindow = Guide.FindWindowOwned(stepInfo.HostPopupInfo.WindowName, stepInfo.MainWindow as Window);
                if (ownedWindow == null)
                {
                    return;
                }

                //Tries to close the TermsOfUseView or the PackageManagerSearchView if they were opened previously
                Guide.CloseWindowOwned(stepInfo.HostPopupInfo.WindowName, stepInfo.MainWindow as Window);
            }
        }
        /// <summary>
        /// This method will be opening the SideBar Package Details (or closing it when enableFunction = false)
        /// </summary>
        /// <param name="stepInfo">Information about the Step</param>
        /// <param name="uiAutomationData">Information about UI Automation that is being executed</param>
        /// <param name="enableFunction">Variable used to know if we are executing the automation or undoing changes</param>
        /// <param name="currentFlow">Current Guide Flow</param>
        internal static void ExecuteViewDetailsSideBar(Step stepInfo, StepUIAutomation uiAutomationData, bool enableFunction, GuideFlow currentFlow)
        {
            const string packageDetailsName      = "Package Details";
            const string closeButtonName         = "CloseButton";
            const string packageSearchWindowName = "PackageSearch";

            CurrentExecutingStep = stepInfo;
            var stepMainWindow       = stepInfo.MainWindow as Window;
            var packageDetailsWindow = Guide.FindChild(stepMainWindow, stepInfo.HostPopupInfo.HostUIElementString) as UserControl;

            if (enableFunction)
            {
                //This section will open the Package Details Sidebar
                PackageManagerSearchView packageManager = Guide.FindWindowOwned(packageSearchWindowName, stepMainWindow) as PackageManagerSearchView;
                if (packageManager == null)
                {
                    return;
                }
                PackageManagerSearchViewModel packageManagerViewModel = packageManager.DataContext as PackageManagerSearchViewModel;

                //If the results in the PackageManagerSearch are null then we cannot open the Package Detail tab
                if (packageManagerViewModel == null || packageManagerViewModel.SearchResults.Count == 0)
                {
                    return;
                }

                //We take the first result from the PackageManagerSearch
                PackageManagerSearchElementViewModel packageManagerSearchElementViewModel = packageManagerViewModel.SearchResults[0];
                if (packageManagerSearchElementViewModel == null)
                {
                    return;
                }

                if (packageDetailsWindow == null)
                {
                    packageManagerViewModel.ViewPackageDetailsCommand.Execute(packageManagerSearchElementViewModel.Model);
                }

                //The PackageDetails sidebar is using events when is being shown then we need to execute those events before setting the Popup.PlacementTarget.
                //otherwise the sidebar will not be present (and we don't have host for the Popup) and the Popup will be located out of the Dynamo window
                CurrentExecutingStep.MainWindow.Dispatcher.Invoke(DispatcherPriority.Background, new Action(delegate { }));
            }
            else
            {
                //This section will close the Package Details Sidebar (just in case is still opened),
                //due that the sidebar (UserControl) is inserted inside a TabItem the only way to close is by using the method dynamoView.CloseExtensionTab
                var dynamoView = (stepMainWindow as DynamoView);
                if (packageDetailsWindow == null)
                {
                    return;
                }
                //In order to close the Package Details tab we need first to get the Tab, then get the Close button and finally call the event to close it
                TabItem tabitem = dynamoView.ExtensionTabItems.OfType <TabItem>().SingleOrDefault(n => n.Header.ToString() == packageDetailsName);
                if (tabitem == null)
                {
                    return;
                }
                //Get the Close button from the PackageDetailsView
                Button closeButton = Guide.FindChild(tabitem, closeButtonName) as Button;
                if (closeButton == null)
                {
                    return;
                }
                dynamoView.CloseExtensionTab(closeButton, null);
            }
        }
        /// <summary>
        /// This method will be used to subscribe a method to the Button.Click event of the ViewDetails button located in the PackageManagerSearch Window
        /// </summary>
        /// <param name="stepInfo">Information about the Step</param>
        /// <param name="uiAutomationData">Information about UI Automation that is being executed</param>
        /// <param name="enableFunction">Variable used to know if we are executing the automation or undoing changes</param>
        /// <param name="currentFlow">Current Guide Flow</param>
        internal static void SubscribeViewDetailsEvent(Step stepInfo, StepUIAutomation uiAutomationData, bool enableFunction, GuideFlow currentFlow)
        {
            CurrentExecutingStep = stepInfo;
            PackageManagerSearchView packageManager = Guide.FindWindowOwned(stepInfo.HostPopupInfo.WindowName, stepInfo.MainWindow as Window) as PackageManagerSearchView;

            if (packageManager == null)
            {
                return;
            }
            Button foundElement = Guide.FindChild(packageManager, stepInfo.HostPopupInfo.HighlightRectArea.WindowElementNameString) as Button;

            if (foundElement == null)
            {
                return;
            }
            if (enableFunction)
            {
                foundElement.Click += ViewDetails_Click;
            }
            else
            {
                foundElement.Click -= ViewDetails_Click;
            }
        }
        /// <summary>
        /// This method will subcribe the menu "Packages->Search for a Package" MenuItem to the Next event so when is pressed we will moved to the next Step
        /// </summary>
        /// <param name="stepInfo">Information about the Step</param>
        /// <param name="uiAutomationData">Information about UI Automation that is being executed</param>
        /// <param name="enableFunction">Variable used to know if we are executing the automation or undoing changes</param>
        /// <param name="currentFlow">Current Guide Flow</param>
        internal static void SubscribeSearchForPackagesOption(Step stepInfo, StepUIAutomation uiAutomationData, bool enableFunction, GuideFlow currentFlow)
        {
            CurrentExecutingStep = stepInfo;

            //We try to find the WindowElementNameString (in this case the MenuItem) in the DynamoView VisualTree
            var foundUIElement = Guide.FindChild(CurrentExecutingStep.MainWindow, CurrentExecutingStep.HostPopupInfo.HighlightRectArea.WindowElementNameString) as MenuItem;

            if (foundUIElement == null)
            {
                return;
            }
            if (enableFunction)
            {
                //Executed then Showing the Step
                foundUIElement.Click += SearchForPackage_Click;
            }
            else
            {
                //Just executed when exiting the Guide or when passing to the next Step
                foundUIElement.Click -= SearchForPackage_Click;
            }
        }
        /// <summary>
        /// This method will be used to open the PackageManagerSearchView and search for a specific Package
        /// </summary>
        /// <param name="stepInfo">Step information</param>
        /// <param name="uiAutomationData">Specific UI Automation step that is being executed</param>
        /// <param name="enableFunction">it says if the functionality should be enabled or disabled</param>
        /// <param name="currentFlow">The current flow of the Guide can be FORWARD or BACKWARD</param>
        internal static void ExecutePackageSearch(Step stepInfo, StepUIAutomation uiAutomationData, bool enableFunction, GuideFlow currentFlow)
        {
            CurrentExecutingStep = stepInfo;
            //We try to find the PackageManagerSearchView window
            Window ownedWindow = Guide.FindWindowOwned(stepInfo.HostPopupInfo.WindowName, stepInfo.MainWindow as Window);

            if (enableFunction)
            {
                //We need to check if the PackageManager search is already open if that is the case we don't need to open it again
                if (ownedWindow != null)
                {
                    return;
                }
                stepInfo.DynamoViewModelStep.ShowPackageManagerSearch(null);

                PackageManagerSearchView packageManager = Guide.FindWindowOwned(stepInfo.HostPopupInfo.WindowName, stepInfo.MainWindow as Window) as PackageManagerSearchView;
                if (packageManager == null)
                {
                    return;
                }
                PackageManagerSearchViewModel packageManagerViewModel = packageManager.DataContext as PackageManagerSearchViewModel;
                if (packageManagerViewModel == null)
                {
                    return;
                }

                //Due that we need to search the Autodesk Sample package after the initial search is completed
                //we need to subscribe to the PropertyChanged event so we will know when the SearchState property is equal to Results (meaning that got results)
                packageManagerViewModel.PropertyChanged += PackageManagerViewModel_PropertyChanged;
            }
            else
            {
                PackageManagerSearchView packageManager = Guide.FindWindowOwned(stepInfo.HostPopupInfo.WindowName, stepInfo.MainWindow as Window) as PackageManagerSearchView;
                if (packageManager == null)
                {
                    return;
                }
                PackageManagerSearchViewModel packageManagerViewModel = packageManager.DataContext as PackageManagerSearchViewModel;
                if (packageManagerViewModel == null)
                {
                    return;
                }

                //Depending of the SetUp done in the Guides Json we will make the Clean Up or not, for example there are several Steps that use the PackageManagerSearchView then we won't close it

                //The Guide is moving to FORWARD and the ExecuteCleanUpForward = false, then we don't need to close the PackageManagerSearchView
                if (uiAutomationData.ExecuteCleanUpForward && currentFlow == GuideFlow.FORWARD)
                {
                    ClosePackageManager(packageManager);
                }

                //The Guide is moving to FORWARD and the ExecuteCleanUpForward = false, then we don't need to close the PackageManagerSearchView
                if (uiAutomationData.ExecuteCleanUpBackward && currentFlow == GuideFlow.BACKWARD)
                {
                    ClosePackageManager(packageManager);
                }

                //The currentFlow = GuideFlow.CURRENT when exiting the Guide
                if (currentFlow == GuideFlow.CURRENT)
                {
                    ClosePackageManager(packageManager);
                }
            }
        }
        /// <summary>
        /// This method will be executed when passing from Step 6 to Step 7 in the Packages guide, so it will subscribe the install button event
        /// </summary>
        /// <param name="stepInfo"></param>
        /// <param name="uiAutomationData"></param>
        /// <param name="enableFunction"></param>
        /// <param name="currentFlow"></param>
        internal static void ExecuteInstallPackagesFlow(Step stepInfo, StepUIAutomation uiAutomationData, bool enableFunction, GuideFlow currentFlow)
        {
            CurrentExecutingStep = stepInfo;
            Window ownedWindow = Guide.FindWindowOwned(stepInfo.HostPopupInfo.WindowName, stepInfo.MainWindow as Window);


            if (enableFunction)
            {
                if (ownedWindow != null)
                {
                    viewModel = ownedWindow.DataContext as PackageManagerSearchViewModel;
                }

                Button buttonElement = Guide.FindChild(ownedWindow, stepInfo.HostPopupInfo.HostUIElementString) as Button;
                viewModel.PackageManagerClientViewModel.Downloads.CollectionChanged += Downloads_CollectionChanged;
            }
            else
            {
                //Tries to close the TermsOfUseView or the PackageManagerSearchView if they were opened previously
                Guide.CloseWindowOwned(stepInfo.HostPopupInfo.WindowName, stepInfo.MainWindow as Window);
            }
        }
        /// <summary>
        /// This method will call a js function that will scroll down until the bottom of the page
        /// </summary>
        internal static void LibraryScrollToBottom(Step stepInfo, StepUIAutomation uiAutomationData, bool enableFunction, GuideFlow currentFlow)
        {
            CurrentExecutingStep = stepInfo;
            if (uiAutomationData == null)
            {
                return;
            }
            string jsFunctionName = uiAutomationData.JSFunctionName;

            //Create the array for the paramateres that will be sent to the WebBrowser.InvokeScript Method
            object[] parametersInvokeScript = new object[] { jsFunctionName, new object[] { } };
            //Execute the JS function with the provided parameters
            ResourceUtilities.ExecuteJSFunction(CurrentExecutingStep.MainWindow, CurrentExecutingStep.HostPopupInfo, parametersInvokeScript);
        }
        /// <summary>
        /// This method will calculate the Popup location based in a item from the Library
        /// </summary>
        internal static void CalculateLibraryItemLocation(Step stepInfo, StepUIAutomation uiAutomationData, bool enableFunction, GuideFlow currentFlow)
        {
            CurrentExecutingStep = stepInfo;
            if (uiAutomationData == null)
            {
                return;
            }
            var jsFunctionName = uiAutomationData.JSFunctionName;

            object[] jsParameters = new object[] { uiAutomationData.JSParameters[0] };
            //Create the array for the paramateres that will be sent to the WebBrowser.InvokeScript Method
            object[] parametersInvokeScript = new object[] { jsFunctionName, jsParameters };
            //Execute the JS function with the provided parameters
            var returnedObject = ResourceUtilities.ExecuteJSFunction(CurrentExecutingStep.MainWindow, CurrentExecutingStep.HostPopupInfo, parametersInvokeScript);

            if (returnedObject == null)
            {
                return;
            }
            //Due that the returned object is a json then we get the values from the json
            JObject json   = JObject.Parse(returnedObject.ToString());
            double  top    = Convert.ToDouble(json["client"]["top"].ToString());
            double  bottom = Convert.ToDouble(json["client"]["bottom"].ToString());
            //We calculate the Vertical location taking the average position "(top + bottom) / 2" and the height of the popup
            double verticalPosition = (top + bottom) / 2 - CurrentExecutingStep.Height / 2;

            CurrentExecutingStep.UpdatePopupVerticalPlacement(verticalPosition);
        }
        /// <summary>
        /// This method will subscribe the Next button from the Step8 Popup for clicking the Package already installed (then it will be expanded).
        /// </summary>
        /// <param name="stepInfo">Information about the Step</param>
        /// <param name="uiAutomationData">Specific UI Automation step that is being executed</param>
        /// <param name="enableFunction">it says if the functionality should be enabled or disabled</param>
        /// <param name="currentFlow">The current flow of the Guide can be FORWARD or BACKWARD</param>
        internal static void SubscribeNextButtonClickEvent(Step stepInfo, StepUIAutomation uiAutomationData, bool enableFunction, GuideFlow currentFlow)
        {
            CurrentExecutingStep = stepInfo;
            //if there is not handler then the function should return
            if (uiAutomationData.AutomaticHandlers == null || uiAutomationData.AutomaticHandlers.Count == 0)
            {
                return;
            }
            //Due that only one handler was configured we get the first one
            var automaticHandler = uiAutomationData.AutomaticHandlers.FirstOrDefault();
            //Find the NextButton inside the Popup
            var nextbuttonFound = Guide.FindChild((CurrentExecutingStep.StepUIPopup as PopupWindow).mainPopupGrid, automaticHandler.HandlerElement) as Button;

            if (nextbuttonFound == null)
            {
                return;
            }
            //Add or Remove the handler assigned to the Button.Click
            ManageEventHandler(nextbuttonFound, automaticHandler.HandlerElementEvent, automaticHandler.ExecuteMethod, enableFunction);
        }
 internal static void EnableNextButton(Step stepInfo, StepUIAutomation uiAutomationData, bool enableFunction, GuideFlow currentFlow)
 {
     if (searchPackagesLoaded)
     {
         var nextButton = Guide.FindChild((CurrentExecutingStep.StepUIPopup as PopupWindow).mainPopupGrid, uiAutomationData.ElementName) as Button;
         if (nextButton != null)
         {
             nextButton.IsEnabled = true;
         }
     }
 }
        /// <summary>
        /// This method will be executed when packages search window is opened, so it can identify the close button of the window
        /// </summary>
        /// <param name="stepInfo"></param>
        /// <param name="uiAutomationData"></param>
        /// <param name="enableFunction"></param>
        /// <param name="currentFlow"></param>
        internal static void ExecuteClosePackagesSearch(Step stepInfo, StepUIAutomation uiAutomationData, bool enableFunction, GuideFlow currentFlow)
        {
            if (enableFunction)
            {
                CurrentExecutingStep = stepInfo;

                if (stepInfo.ExitGuide != null)
                {
                    exitGuide = stepInfo.ExitGuide;
                }

                Window ownedWindow = Guide.FindWindowOwned(stepInfo.HostPopupInfo.WindowName, stepInfo.MainWindow as Window);

                foreach (var handler in uiAutomationData.AutomaticHandlers)
                {
                    if (ownedWindow == null)
                    {
                        return;
                    }

                    CloseButtonSearchPackages        = Guide.FindChild(ownedWindow, handler.HandlerElement) as Button;
                    CloseButtonSearchPackages.Click += CloseButton_Click;
                }
            }
            else
            {
                if (CloseButtonSearchPackages != null)
                {
                    CloseButtonSearchPackages.Click -= CloseButton_Click;
                }
            }
        }
示例#13
0
 internal void HideCurrentStep(int CurrentStepSequence, GuideFlow currentFlow)
 {
     CurrentStep.Hide(currentFlow);
     GuideBackgroundElement.ClearHighlightSection();
 }