private static Point GetCursorPosition()
        {
            GetCursorPos(out POINT cursorScreenPosition);

            double widthInDevicePixels = SplashLoading.GetSystemMetrics(SplashLoading.SM_CXSCREEN);
            double widthInDIP          = SystemParameters.WorkArea.Right; // Device independent pixels.
            double scalingFactor       = widthInDIP / widthInDevicePixels;

            var ptMouse = new System.Windows.Point(cursorScreenPosition.X * scalingFactor, cursorScreenPosition.Y * scalingFactor);

            return(ptMouse);
        }
Ejemplo n.º 2
0
        protected override void OnStartup(StartupEventArgs e)
        {
#if DEBUG
            System.Diagnostics.Debugger.Launch();
#endif

            // Store request to access options
            InitializeOptionRequested();

            // Read configuration
            var result = Parser.Default.ParseArguments <Options>(e.Args)
                         .WithNotParsed(errors => ShowMessage("Invalid configuration, check the pbitool.json file\n" + String.Join(";", from err in errors select err.ToString())))
                         .WithParsed(options => AppOptions = options);

            bool            disableTelemetry = (AppOptions.Telemetry == false);
            TelemetryHelper th = new TelemetryHelper(disableTelemetry);

            try
            {
                string serverName       = ((App)Application.Current).AppOptions?.Server;
                string databaseName     = ((App)Application.Current).AppOptions?.Database;
                bool   goodMsOlapDriver = ModelHelper.HasMsOlapDriver();
                if (!goodMsOlapDriver)
                {
                    th.TrackEvent(EV_MSOLAP_NOTFOUND);
                    if (ShowMessageQuestion($"Excel needs a component called MSOLAP driver to connect to Power BI. The MSOLAP driver might be missing or not updated on this device. Therefore, Excel might not connect to Power BI. You can install the updated Microsoft MSOLAP driver from this link: {MSOLAP_DRIVER_URL} \n\nClick YES if you want to download the updated MSOLAP driver and install it.\nClick NO to continue without any update.") == MessageBoxResult.Yes)
                    {
                        try
                        {
                            th.TrackEvent(EV_MSOLAP_SETUP);
                            UpdateMsOlapDriver();
                        }
                        catch (Exception ex)
                        {
                            // Send any exception to Telemetry
                            th.TrackException(ex);
                            ShowMessage($"Error running MSOLAP update: {ex.Message}");
                        }
                    }
                }
                // We use the default "Model" string if the MSOLAP driver is not available - if this happens, the previous warning helps understanding possible issues
                string cubeName = goodMsOlapDriver ? ModelHelper.GetModelName(serverName, databaseName, th) : "Model";
                if (serverName != null && databaseName != null)
                {
                    try
                    {
                        if (string.IsNullOrEmpty(cubeName))
                        {
                            ShowMessage("Power BI has an empty model or it is connected to an unkonwn external dataset. You cannot connect Excel.");
                            th.TrackEvent(EV_MODEL_NOT_AVAILABLE);
                        }
                        else if (ExcelHelper.IsExcelAvailable())
                        {
                            // TODO: Manage options requested
                            if (OptionsRequested)
                            {
                                // TODO request action / configuration to users
                            }

                            var splashScreen = new SplashLoading();
                            try
                            {
                                this.MainWindow = splashScreen;
                                splashScreen.Show();

                                bool excelStarted = ExcelHelper.CreateInstanceWithPivotTableViaInterop(serverName, databaseName, cubeName, out string excelVersion, (ex) => th.TrackException(ex));
                                if (excelStarted)
                                {
                                    th.TrackEvent(EV_RUNEXCEL, new (string propertyName, string propertyValue)[] { ("RunType", "Interop"), ("ExcelVersion", excelVersion) });
                                }