public ActionResult InProgress()
        {
            if (AzureAuthenticationHelper.IsAuthenticated())
            {
                return(this.View());
            }

            return(this.RedirectToAction("Index"));
        }
        public ActionResult Login()
        {
            if (AzureAuthenticationHelper.IsAuthenticated())
            {
                return(this.RedirectToAction("Transfer"));
            }

            return(this.Redirect(AzureAuthenticationHelper.GetAuthString()));
        }
        public ActionResult Tables(string datasetId)
        {
            if (AzureAuthenticationHelper.IsAuthenticated())
            {
                var helper = new PowerBiHelper(AzureAuthenticationHelper.GetSession());
                return(this.View(helper.GetTables(datasetId).Value));
            }

            return(this.RedirectToAction("Index"));
        }
        public ActionResult Transfer(string reportingUrl, string reportingCode, string reportingId, string reportingPassword)
        {
            ServiceHandler.Instance.OverwriteServiceUrl(reportingUrl);
            AzureAuthenticationHelper.SetReportingCredentials(new ReportingCredentials
            {
                ApiId       = reportingId,
                SiteCode    = reportingCode,
                Url         = reportingUrl,
                ApiPassword = reportingPassword
            });

            return(this.RedirectToAction("InProgress"));
        }
        public ActionResult TransferCustomers()
        {
            //return this.Json("Yay", JsonRequestBehavior.AllowGet);
            var credentials = AzureAuthenticationHelper.GetReportingCredentials();

            if (ServiceHandler.Instance.TryAuthenticate(
                    credentials.SiteCode,
                    credentials.ApiId,
                    credentials.ApiPassword))
            {
                var helper       = new PowerBiHelper(AzureAuthenticationHelper.GetSession());
                var customersRaw = ServiceHandler.Instance.Client.GetCustomersRaw(
                    credentials.SiteCode,
                    credentials.ApiId,
                    credentials.ApiPassword,
                    Customer.All,
                    1,
                    AccountManager.All);

                if (customersRaw.OwnerDocument != null)
                {
                    var namespaceManager = new XmlNamespaceManager(customersRaw.OwnerDocument.NameTable);
                    namespaceManager.AddNamespace("tlp", "http://www.timelog.com/XML/Schema/tlp/v4_4");
                    var customers = customersRaw.SelectNodes("tlp:Customer", namespaceManager);

                    if (customers != null)
                    {
                        var tableConstructed = false;
                        var rowsList         = new List <string>();
                        foreach (XmlNode customer in customers)
                        {
                            if (!tableConstructed)
                            {
                                helper.DeleteRows(helper.GetDefaultDatasetId(), "Customers");
                                var tableSchemaJson = helper.BuildTableSchemaJson("Customers", typeof(Customer));
                                helper.UpdateTableSchema(helper.GetDefaultDatasetId(), "Customers", tableSchemaJson);
                                tableConstructed = true;
                            }

                            rowsList.Add(helper.BuildTableRowJson(new Customer(customer, namespaceManager)));
                        }

                        helper.AddRows(helper.GetDefaultDatasetId(), "Customers", rowsList, 100);
                    }
                }

                return(this.Json("Yay", JsonRequestBehavior.AllowGet));
            }

            return(this.Json("Failed", JsonRequestBehavior.AllowGet));
        }
        public ActionResult Transfer()
        {
            if (AzureAuthenticationHelper.IsAuthenticated())
            {
                var helper = new PowerBiHelper(AzureAuthenticationHelper.GetSession());
                this.ViewBag.DatasetStatus = helper.IsDefaultDatasetAvailable() ? "detected" : "created";
                helper.CreateDefaultDataset();

                // helper.AddRow("6ac4bc17-a85d-4f03-bc5a-e73460568d3c", "Customers");
                return(this.View());
            }

            return(this.RedirectToAction("Index"));
        }
        public ActionResult Index()
        {
            if (AzureAuthenticationHelper.IsAuthenticated())
            {
                return(this.RedirectToAction("Transfer"));
            }

            var values = this.Request.QueryString["code"];

            if (values != null)
            {
                string code = values;
                AuthenticationContext ac = new AuthenticationContext(PersonalConfigurationManager.AppSettings["AzureAuthorityUri"]);
                ClientCredential      cc = new ClientCredential(PersonalConfigurationManager.AppSettings["AzureClientId"], PersonalConfigurationManager.AppSettings["AzureKey"]);
                AuthenticationResult  ar = ac.AcquireTokenByAuthorizationCodeAsync(code, new Uri(PersonalConfigurationManager.AppSettings["AzureRedirectUrl"]), cc).Result;

                AzureAuthenticationHelper.SetSession(ar);
                return(this.RedirectToAction("Transfer"));
            }

            return(this.View());
        }
示例#8
0
        public string GetOAuthTokenFromAad(ICostMonitoringSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            var auth = settings.Authentication;

            if (auth == null)
            {
                throw new InvalidOperationException("Authentication settings not found");
            }

            var resources = settings.Resources;

            if (resources == null)
            {
                throw new InvalidOperationException("Resources settings not found");
            }

            return(AzureAuthenticationHelper.GetOAuthTokenFromAAD(auth.AadLoginUrl, auth.TenantId, resources.BaseUrl, auth.RedirectUrl, auth.ApplicationId, auth.ApplicationSecret));
        }
        public ActionResult TransferWorkUnits()
        {
            return(this.Json("Yay", JsonRequestBehavior.AllowGet));

            var credentials = AzureAuthenticationHelper.GetReportingCredentials();

            if (ServiceHandler.Instance.TryAuthenticate(
                    credentials.SiteCode,
                    credentials.ApiId,
                    credentials.ApiPassword))
            {
                var helper       = new PowerBiHelper(AzureAuthenticationHelper.GetSession());
                var workUnitsRaw = ServiceHandler.Instance.Client.GetWorkUnitsRaw(
                    credentials.SiteCode,
                    credentials.ApiId,
                    credentials.ApiPassword,
                    WorkUnit.All,
                    Employee.All,
                    Allocation.All,
                    Task.All,
                    Project.All,
                    Department.All,
                    DateTime.Now.AddMonths(-6).ToString(),
                    DateTime.Now.ToString());

                if (workUnitsRaw.OwnerDocument != null)
                {
                    var namespaceManager = new XmlNamespaceManager(workUnitsRaw.OwnerDocument.NameTable);
                    namespaceManager.AddNamespace("tlp", "http://www.timelog.com/XML/Schema/tlp/v4_4");
                    var workUnits = workUnitsRaw.SelectNodes("tlp:WorkUnit", namespaceManager);

                    if (workUnits != null)
                    {
                        var tableConstructed = false;
                        var rowsList         = new List <string>();
                        foreach (XmlNode workUnit in workUnits)
                        {
                            if (!tableConstructed)
                            {
                                try
                                {
                                    helper.DeleteRows(helper.GetDefaultDatasetId(), "WorkUnits");
                                }
                                catch (Exception)
                                {
                                    // Ignore. Probably first request
                                    throw new Exception("PowerBI table definition out of sync. Please delete entire dataset and try transferring again.");
                                }

                                var tableSchemaJson = helper.BuildTableSchemaJson("WorkUnits", typeof(WorkUnit));
                                helper.UpdateTableSchema(helper.GetDefaultDatasetId(), "WorkUnits", tableSchemaJson);
                                tableConstructed = true;
                            }

                            rowsList.Add(helper.BuildTableRowJson(new WorkUnit(workUnit, namespaceManager)));
                        }

                        helper.AddRows(helper.GetDefaultDatasetId(), "WorkUnits", rowsList, 100);
                    }
                }

                return(this.Json("Yay", JsonRequestBehavior.AllowGet));
            }

            return(this.Json("Failed", JsonRequestBehavior.AllowGet));
        }