/// <summary> /// Sets the context data within the logical thread. /// </summary> /// <param name="contextData">The context data.</param> /// <remarks></remarks> public static void SetContext(RequestContextData contextData) { long tenantId = -1; var tenantName = string.Empty; if (contextData != null && contextData.Tenant != null) { var tenant = contextData.Tenant; tenantId = tenant.Id; tenantName = tenant.HaveName ? tenant.Name : TenantHelper.GetTenantName(tenantId); // don't trigger a name fetch } var userName = string.Empty; if (contextData != null && contextData.Identity != null) { userName = contextData.Identity.Name; } // Set the diagnostics context for logging purposes DiagnosticsRequestContext.SetContext(tenantId, tenantName, userName); // Set the default request context data in the logical context CallContext.SetData(ContextKey, contextData); ActualUserRequestContext.SetContext(contextData); }
/// <summary> /// Sets the context to the specified tenant. /// This context is not compatible with the legacy resource model. /// </summary> /// <param name="tenantName">The tenant name.</param> /// <remarks></remarks> public static void SetTenantAdministratorContext(string tenantName) { RequestContext.SetSystemAdministratorContext(); var tenant = TenantHelper.Find(tenantName); RequestContext.SetTenantAdministratorContext(tenant.Id); }
public async Task <JsonResult> EditCustomer(string tenantUid, string title, string firstname, string lastname, string gender, string day, string month, string year, string country, string countrycode, string timezone, string odds, string language, string username, string customerGuid, string customerToken, string address1 = "", string address2 = "", string address3 = "", string town = "", string county = "", string postalcode = "", string notify = "true") { var customer = new EditCustomer { Username = username, Fields = new Models.EditCustomer.EditFields { CountryCode = countrycode, DOB = !string.IsNullOrEmpty(day) ? $"{year}-{month}-{day}" : string.Empty, FirstName = firstname, LastName = lastname, Gender = gender, LanguageCode = language, OddsDisplay = odds, TimeZoneCode = timezone, Title = title, AddressLine1 = address1, AddressLine2 = address2, AddressLine3 = address3, County = county, Town = town, Country = country, PostCode = postalcode, NotificationComPref = notify } }; var origin = TenantHelper.GetCurrentTenantUrl(contentService, tenantUid); var key = ApiKeyCache.GetByTenantUid(tenantUid); var authorization = await new Authorization().GetAuthorizationAsync(key); var response = await apiService.EditCustomerAsync(customer, tenantUid, origin, customerToken); return(Json(response, JsonRequestBehavior.DenyGet)); }
public async Task <JsonResult> RefreshToken(string tenantUid, string token) { var origin = TenantHelper.GetCurrentTenantUrl(contentService, tenantUid); var response = (LoginResponseContent)await apiService.RefreshTokenAsync(tenantUid, origin, token); return(Json(response, JsonRequestBehavior.AllowGet)); }
public async Task <JsonResult> GetHubConnectionAsync(string userId, string tenantUid, string customerToken) { var origin = TenantHelper.GetCurrentTenantUrl(contentService, tenantUid); var response = await apiService.GetHubConnectionAsync(userId, origin, customerToken); return(Json(response, JsonRequestBehavior.DenyGet)); }
public void GetDefaultTenantName() { string tenantName = TenantHelper.GetTenantName(RequestContext.TenantId); long tenantId = TenantHelper.GetTenantId(tenantName); Assert.AreEqual(tenantId, RequestContext.TenantId); }
public string DisableTenant(string tenantUid) { var tenantNode = TenantHelper.GetCurrentTenantHome(contentService, tenantUid.ToString()); if (tenantNode == null) { throw new TenantException(ExceptionCode.TenantNotFound.CodeToString(), ExceptionCode.TenantNotFound, tenantUid.ToString()); } if (tenantNode.GetValue <string>("tenantStatus").Equals(DISABLED)) { throw new TenantException(ExceptionCode.TenantAlreadyDisabled.CodeToString(), ExceptionCode.TenantAlreadyDisabled, tenantUid); } try { tenantNode.SetValue("tenantStatus", DISABLED); contentService.Save(tenantNode); contentService.Unpublish(tenantNode); ConnectorContext.AuditService.Add(AuditType.Unpublish, -1, tenantNode.Id, "Content Node", $"ContentNode for {tenantUid} has been disabled"); return(tenantUid.ToString()); } catch (Exception ex) { logger.Error(typeof(HomeContentNode), ex.Message); logger.Error(typeof(HomeContentNode), ex.StackTrace); throw; } }
public void GenerateReport(StringBuilder reportBuilder) { foreach (var ta in TenantActioners) { reportBuilder.AppendLine($" Tenant: {TenantHelper.GetTenantName(ta.Key)}, State: {ta.Value.State}, Running {ta.Value.RunningTaskCount}/{ta.Value.MaxConcurrency}"); } }
/// <summary> /// Exports the tenant. /// </summary> /// <remarks> /// This is the entry point for export requests that come via PlatformConfigure. c.f. EntityXmlExporter.GenerateXml. /// </remarks> /// <param name="tenantName">Name of the tenant.</param> /// <param name="entityId">Root entity to export.</param> /// <param name="packagePath">The package path.</param> /// <param name="exportSettings">Export settings.</param> /// <param name="context">The context.</param> public static void ExportEntity(string tenantName, long entityId, string packagePath, IProcessingContext context = null) { if (string.IsNullOrEmpty(tenantName)) { throw new ArgumentNullException(nameof(tenantName)); } if (string.IsNullOrEmpty(packagePath)) { throw new ArgumentNullException(nameof(packagePath)); } if (context == null) { context = new ProcessingContext( ); } context.Report.StartTime = DateTime.Now; long tenantId = TenantHelper.GetTenantId(tenantName, true); ///// // Create source to load app data from tenant ///// using (IDataTarget target = FileManager.CreateDataTarget(Format.XmlVer2, packagePath)) { var exporter = ( EntityXmlExporter )Factory.EntityXmlExporter; exporter.ExportEntity(tenantId, new[] { entityId }, target, context, false); } context.Report.EndTime = DateTime.Now; }
public Tenant GetCurrentTenant(HttpContext context) { // Get Tenant by Domain Tenant tenant = TenantHelper.GetAllTenants().Where(t => t.Domain == context.Request.Host.Host).FirstOrDefault(); return(tenant); }
private static void AddTenant(BusinessDbContext context) { if (context.Tenants.Any()) { return; } var edition = context.Editions.FirstOrDefault(x => x.Name == StaticEdition.Deluxe); context.Tenants.Add(new Tenant() { Id = Guid.NewGuid().ToString(), Created = DateTime.Now, Modified = DateTime.Now, IsActive = true, Active = true, ConnectionString = null, EditionId = edition?.Id, IsInTrialPeriod = false, Name = StaticTenant.Host, TenancyName = TenantHelper.BuildTenancyName(StaticTenant.Host), SubscriptionEndTime = DateTime.Today.AddYears(100), Url = $"http://{StaticTenant.Host.ToLower()}" + $".datacrud.com" }); context.SaveChanges(); }
public override TokenParser ProvisionObjects(Tenant tenant, ProvisioningHierarchy hierarchy, string sequenceId, TokenParser parser, ApplyConfiguration configuration) { using (var scope = new PnPMonitoredScope(this.Name)) { if (hierarchy.Tenant != null) { TenantHelper.ProcessCdns(tenant, hierarchy.Tenant, parser, scope, MessagesDelegate); parser = TenantHelper.ProcessApps(tenant, hierarchy.Tenant, hierarchy.Connector, parser, scope, configuration, MessagesDelegate); try { parser = TenantHelper.ProcessWebApiPermissions(tenant, hierarchy.Tenant, parser, scope, MessagesDelegate); } catch (ServerUnauthorizedAccessException ex) { scope.LogError(ex.Message); } parser = TenantHelper.ProcessSiteScripts(tenant, hierarchy.Tenant, hierarchy.Connector, parser, scope, MessagesDelegate); parser = TenantHelper.ProcessSiteDesigns(tenant, hierarchy.Tenant, parser, scope, MessagesDelegate); parser = TenantHelper.ProcessStorageEntities(tenant, hierarchy.Tenant, parser, scope, configuration, MessagesDelegate); parser = TenantHelper.ProcessThemes(tenant, hierarchy.Tenant, parser, scope, MessagesDelegate); parser = TenantHelper.ProcessUserProfiles(tenant, hierarchy.Tenant, parser, scope, MessagesDelegate); // So far we do not provision CDN settings // It will come in the near future // NOOP on CDN } } return(parser); }
/// <summary> /// Start a workflow and and wait for it to complete or pause. /// </summary> /// <returns></returns> public WorkflowRun RunWorkflow(WorkflowStartEvent startEvent) { if (startEvent.Workflow == null) { throw new ArgumentException($"{nameof(startEvent)} missing mandatory field Workflow."); } // deny workflow run when tenant is disabled if (TenantHelper.IsDisabled()) { EventLog.Application.WriteWarning("Workflow run denied, tenant is disabled. \"{0\"({1})", startEvent.Workflow.Name, startEvent.Workflow.Id); return(null); } using (Profiler.Measure("WorkflowRunner.Instance.RunWorkflow")) { using (new SecurityBypassContext()) { if (startEvent.Workflow.WfNewerVersion != null) { throw new ArgumentException("Attempted to run a workflow that is not the newest version."); } // create a wf run then pass into the workflow var run = new WorkflowRunDeferred(startEvent.Workflow, startEvent.Trigger) { RunTrace = startEvent.Trace, ParentRun = startEvent.ParentRun }; return(ProcessWorkflowInContext(run, startEvent)); } } }
public async Task <JsonResult> GetCustomerSummaryAsync(string tenantUid, string customerToken) { var origin = TenantHelper.GetCurrentTenantUrl(contentService, tenantUid); var response = await apiService.GetCustomerSummaryAsync(tenantUid, origin, LoginSession.DecodeJwtToken(customerToken)); return(Json(response, JsonRequestBehavior.DenyGet)); }
public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation) { web.EnsureProperty(w => w.Url); using (var scope = new PnPMonitoredScope(this.Name)) { if (template.Tenant != null) { using (var tenantContext = web.Context.Clone(web.GetTenantAdministrationUrl())) { var tenant = new Tenant(tenantContext); TenantHelper.ProcessCdns(tenant, template.Tenant, parser, scope, MessagesDelegate); parser = TenantHelper.ProcessApps(tenant, template.Tenant, template.Connector, parser, scope, applyingInformation, MessagesDelegate); try { parser = TenantHelper.ProcessWebApiPermissions(tenant, template.Tenant, parser, scope, MessagesDelegate); } catch (ServerUnauthorizedAccessException ex) { scope.LogError(ex.Message); } parser = TenantHelper.ProcessSiteScripts(tenant, template.Tenant, template.Connector, parser, scope, MessagesDelegate); parser = TenantHelper.ProcessSiteDesigns(tenant, template.Tenant, parser, scope, MessagesDelegate); parser = TenantHelper.ProcessStorageEntities(tenant, template.Tenant, parser, scope, applyingInformation, MessagesDelegate); parser = TenantHelper.ProcessThemes(tenant, template.Tenant, parser, scope, MessagesDelegate); } } } return(parser); }
public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation) { web.EnsureProperty(w => w.Url); using (var scope = new PnPMonitoredScope(this.Name)) { if (template.Tenant != null) { using (var tenantContext = web.Context.Clone(web.GetTenantAdministrationUrl())) { var tenant = new Tenant(tenantContext); TenantHelper.ProcessCdns(tenant, template.Tenant, parser, scope, MessagesDelegate); parser = TenantHelper.ProcessApps(tenant, template.Tenant, template.Connector, parser, scope, applyingInformation, MessagesDelegate); parser = TenantHelper.ProcessWebApiPermissions(tenant, template.Tenant, parser, scope, MessagesDelegate); parser = TenantHelper.ProcessSiteScripts(tenant, template.Tenant, template.Connector, parser, scope, MessagesDelegate); parser = TenantHelper.ProcessSiteDesigns(tenant, template.Tenant, parser, scope, MessagesDelegate); parser = TenantHelper.ProcessStorageEntities(tenant, template.Tenant, parser, scope, applyingInformation, MessagesDelegate); parser = TenantHelper.ProcessThemes(tenant, template.Tenant, parser, scope, MessagesDelegate); } // So far we do not provision CDN settings // It will come in the near future // NOOP on CDN } } return(parser); }
public async Task <JsonResult> Deposit(Deposit deposit, string tenantUid) { var origin = TenantHelper.GetCurrentTenantUrl(contentService, tenantUid); var token = Request.Cookies["token"].Value; if (deposit.PaymentIdentifier == "BTC") { var response = (DepositBitcoinResponseContent)await _transactionService.DepositBitcoin(tenantUid, token, origin, deposit); return(Json(response)); } else { var response = (DepositPerfectMoneyResponseContent)await _transactionService.Deposit(tenantUid, token, origin, deposit); string value; var hasValue = deposit.Parameters.TryGetValue("Amount", out value); if (hasValue) { Session["t_amount"] = value; } Session["t_name"] = deposit.PaymentSystemName; Session["t_id"] = response?.Payload?.TransactionId; Session["t_date"] = DateTime.Now.ToString(); return(Json(response)); } }
public string CreateTenantCompany(string tenantId, string tenantName, string email, string phoneNumber) { var id = Guid.NewGuid().ToString(); Company company = new Company() { Active = true, Created = DateTime.Now, CreatedBy = null, Modified = null, ModifiedBy = null, Id = id, Name = tenantName, TenantId = tenantId, Email = email, IsEmailConfirmed = false, IsPhoneConfirmed = false, Phone = phoneNumber, Web = TenantHelper.GetTenantBaseUrl(tenantName.ToTenancyName()) }; _companyRepository.CreateAsHost(company); _companyRepository.Commit(); CreateTenantCompanySettings(tenantId, company); return(id); }
/// <summary> /// Reverts the range. /// </summary> /// <param name="fromTransactionId">From transaction identifier.</param> /// <param name="toTransactionId">To transaction identifier.</param> /// <param name="tenantId">The tenant identifier.</param> public static void RevertRange(long fromTransactionId, long toTransactionId, long tenantId = -1) { try { using (DatabaseContext ctx = DatabaseContext.GetContext( )) { using (IDbCommand command = ctx.CreateCommand("spRevertRange", CommandType.StoredProcedure)) { ctx.AddParameter(command, "@fromTransactionId", DbType.Int64, fromTransactionId); ctx.AddParameter(command, "@toTransactionId", DbType.Int64, toTransactionId); if (tenantId >= 0) { ctx.AddParameter(command, "@tenantId", DbType.Int64, tenantId); } command.ExecuteNonQuery( ); } } } finally { if (tenantId >= 0) { TenantHelper.Invalidate(tenantId); } } }
/// <summary> /// Deploys the application asynchronously. /// </summary> /// <param name="state">The state.</param> private void DeployAsynchronous(object state) { var package = state as Package; var context = new RoutedProcessingContext(message => BusyMessage = message, message => BusyMessage = message, message => BusyMessage = message, message => BusyMessage = message); if (package != null) { var tenantId = package.SelectedTenant.EntityId; using (new TenantAdministratorContext(0)) { AppManager.UpgradeApp(tenantId, package.AppVerId, context); } using (new TenantAdministratorContext(tenantId)) { TenantHelper.Invalidate(new EntityRef(tenantId)); } } IsBusy = false; System.Windows.Application.Current.Dispatcher.Invoke(LoadPackages); }
public async Task <JsonResult> VerifyMobileValidateSMS2(string tenantUid, string mobile, string code, string language, string token) { var origin = TenantHelper.GetCurrentTenantUrl(contentService, tenantUid); var response = await verificationService.ValidateSmsVerificationCodeAsync(tenantUid, origin, mobile, code, token); return(Json(response, JsonRequestBehavior.DenyGet)); }
public ActionResult TotalCodeCasinoPageTemplate() { var model = GetModel <GamePageViewModel>(CurrentPage); if (Request.QueryString["gameId"] != null) { var origin = TenantHelper.GetCurrentTenantUrl(contentService, model.TenantUid); var gameId = int.Parse(Request.QueryString["gameId"].ToString()); var key = ApiKeyCache.GetByTenantUid(model.TenantUid); var authorization = GetAuthorization(key); var games = apiService.GetGameDataAnonymousArray(model.TenantUid, origin, authorization: authorization.AccessToken); var game = games.SingleOrDefault(x => x.GameId == gameId); if (game != null) { model.HasDemoMode = game.DemoEnabled; model.GameUrl = game.Url; } } else { model.Slider = CurrentPage.Value <IEnumerable <IPublishedElement> >("gameSlider") .Select(x => new SliderItem { Image = x.HasValue("sliderItemImage") ? x.GetProperty("sliderItemImage").Value <IPublishedContent>().Url : string.Empty, ButtonLabel = x.HasValue("sliderItemButtonLabel") ? x.GetProperty("sliderItemButtonLabel").GetValue().ToString() : string.Empty, Title = x.HasValue("sliderItemTitle") ? x.GetProperty("sliderItemTitle").GetValue().ToString() : string.Empty, Subtitle = x.HasValue("sliderItemSubtitle") ? x.GetProperty("sliderItemSubtitle").GetValue().ToString() : string.Empty, Url = x.HasValue("sliderItemUrl") ? x.GetProperty("sliderItemUrl").GetValue().ToString() : string.Empty, })?.ToList(); } model.Category = "casino"; return(CurrentTemplate(model)); }
public void TestGetMissingDependencies_Missing( ) { Solution appA = new Solution { Name = "appA" }; Solution appB = new Solution { Name = "appB" }; Solution appC = new Solution { Name = "appC" }; ApplicationDependency aDependsOnB = new ApplicationDependency { Name = "appA depends on appB", DependentApplication = appA, DependencyApplication = appB }; appA.DependentApplicationDetails.Add(aDependsOnB); appA.Save( ); ApplicationDependency bDependsOnC = new ApplicationDependency { Name = "appB depends on appC", DependentApplication = appB, DependencyApplication = appC }; appB.DependentApplicationDetails.Add(bDependsOnC); appB.Save( ); AppManager.PublishApp(RunAsDefaultTenant.DefaultTenantName, "appA"); AppManager.PublishApp(RunAsDefaultTenant.DefaultTenantName, "appB"); long tenantId = TenantHelper.CreateTenant("ABC"); AppManager.DeployApp("ABC", Applications.CoreApplicationId.ToString("B")); Guid appAUpgradeId = Entity.GetUpgradeId(appA.Id); using (new GlobalAdministratorContext( )) { AppPackage appPackage = SystemHelper.GetLatestPackageByGuid(appAUpgradeId); var applicationDependencies = SolutionHelper.GetMissingPackageDependencies(appPackage.Id, tenantId); Assert.AreEqual(1, applicationDependencies.Count); DependencyFailure dependency = applicationDependencies[0]; Assert.AreEqual(DependencyFailureReason.Missing, dependency.Reason); } }
public string CreateUser(TenantUser tenant) { var tenantNode = TenantHelper.GetCurrentTenantHome(ConnectorContext.ContentService, tenant.TenantUId.ToString()); var group = userGroupService.GetUserGroup(tenant.Group); userGroupService.CreateUser(tenant); return(tenant.AssignedUmbracoUserId.ToString()); }
public async Task <JsonResult> CloseTicket(CloseTicketModel ticket, string tenantUid) { var token = Request.Cookies["token"].Value; var origin = TenantHelper.GetCurrentTenantUrl(_contentService, tenantUid); var response = await _ticketService.CloseTicket(tenantUid, token, origin, ticket); return(Json(response)); }
public async Task <JsonResult> WithdrawBitcoin(WithdrawBitcoin withdrawBitcoin, string tenantUid) { var origin = TenantHelper.GetCurrentTenantUrl(contentService, tenantUid); var token = Request.Cookies["token"].Value; var response = (WithdrawResponseContent)await _transactionService.WithdrawBitcoin(tenantUid, token, origin, withdrawBitcoin); return(Json(response)); }
public async Task <JsonResult> BonusTransaction(BonusTransaction bonusTransaction, string tenantUid) { var origin = TenantHelper.GetCurrentTenantUrl(contentService, tenantUid); var token = Request.Cookies["token"].Value; var response = (BonusTransactionResponseContent)await _transactionHistoryService.BonusTransaction(tenantUid, token, origin, bonusTransaction); return(Json(response)); }
public async Task <JsonResult> GetGameGrid(string tenantUid, string category = "", string subCategory = "", string provider = "", string keyword = "", string languageCode = "") { var origin = TenantHelper.GetCurrentTenantUrl(contentService, tenantUid); var key = ApiKeyCache.GetByTenantUid(tenantUid); var authorization = await new Authorization().GetAuthorizationAsync(key); var response = await _gameService.GetGameDataAnonymousArrayAsync(tenantUid, origin, category, subCategory, provider, keyword, languageCode, authorization.AccessToken); return(Json(response, JsonRequestBehavior.DenyGet)); }
public async Task <JsonResult> GetCards(string tenantUid) { var origin = TenantHelper.GetCurrentTenantUrl(_contentService, tenantUid); var token = Request.Cookies["token"].Value; var response = await _cardService.GetCards(tenantUid, token, origin); return(Json(response, JsonRequestBehavior.AllowGet)); }
public async Task <JsonResult> VerifyMobileValidateSMS(string tenantUid, string mobile, string code, string language) { var origin = TenantHelper.GetCurrentTenantUrl(contentService, tenantUid); var key = ApiKeyCache.GetByTenantUid(tenantUid); var authorization = await new Authorization().GetAuthorizationAsync(key); var response = await verificationService.ValidateSmsVerificationCodeAsync(tenantUid, origin, mobile, code, authorization.AccessToken); return(Json(response, JsonRequestBehavior.DenyGet)); }