public MultiPermissionsItems(IBlockBuilder blockBuilder, int appId, IEntity item, ILog parentLog) : base(blockBuilder, appId, parentLog) { Items = new List <IEntity> { item }; }
public DynamicEntity(IEntity entity, string[] dimensions, int compatibility, IBlockBuilder blockBuilder) { SetEntity(entity); Dimensions = dimensions; CompatibilityLevel = compatibility; BlockBuilder = blockBuilder; }
/// <inheritdoc /> /// <summary> /// The class constructor, can optionally take a dictionary to reference with, otherwise creates a new one /// </summary> public LookUpCmsBlock(string name, IBlockBuilder blockBuilder) : base(name, new Dictionary <string, string> { { QueryConstants.ParamsShowDraftKey, blockBuilder.UserMayEdit.ToString() } }) { BlockBuilder = blockBuilder; }
internal BlockBuilder(IBlockBuilder rootBlockBuilder, IBlock cb, ILog parentLog) : base("Sxc.BlkBld", parentLog, $"get CmsInstance for a:{cb?.AppId} cb:{cb?.ContentBlockId}") { // the root block is the main container. If there is none yet, use this, as it will be the root RootBuilder = rootBlockBuilder ?? this; Block = cb; }
public Node(NodeOptions options, IBlockBuilder blockBuilder, ILoggerFactory loggerFactory, IPeerChannel channel) { this.options = options; this.logger = loggerFactory.CreateLogger <Node>(); logger.LogInformation($"Configuración del nodo:\n" + $"NodeId: {options.NodeId}\n" + $"NodeName: {options.NodeName}\n" + $"NodePublicUrl: {options.NodePublicUrl}\n" + $"PeerUrl: {options.PeerUrl}\n" + $"MinerAddress: {options.MinerAddress}\n" + $"BlockchainDificulty: {options.BlockchainDificulty}"); Host = new Peer { Id = options.NodeId, Name = options.NodeName, PublicUrl = options.NodePublicUrl }; Peers = new Peers(this, channel, loggerFactory.CreateLogger <Peers>()); Blockchain = new Blockchain(new Miner(AddressRewards), blockBuilder, options.BlockchainDificulty); var path = "genesis.block"; Blockchain.LoadGenesisBlock(path); pendings = new Dictionary <string, BlockItem>(); }
public Blockchain(Miner miner, IBlockBuilder blockBuilder, byte dificulty) { this.miner = miner ?? throw new ArgumentNullException(nameof(miner)); this.blockBuilder = blockBuilder ?? throw new ArgumentNullException(nameof(blockBuilder)); this.dificulty = dificulty; trunk = new List <Block>(); }
public RowBlockBuilder <TPointer> SetField(int index, IBlockBuilder block) { BlockOffset field = Table.Layout.GetField(index); using (MemoryStream stream = new MemoryStream(_data, (int)field.Start, (int)field.Length, true, false)) block.WriteTo(stream); return(this); }
public AdamAppContext(ITenant tenant, IApp app, IBlockBuilder blockBuilder, int compatibility, ILog parentLog) : base("Adm.ApCntx", parentLog, "starting") { Tenant = tenant; _app = app; AppRuntime = new AppRuntime(app, blockBuilder?.UserMayEdit ?? false, null); BlockBuilder = blockBuilder; CompatibilityLevel = compatibility; EnvironmentFs = Factory.Resolve <IEnvironmentFileSystem>(); }
/// <summary> /// Standard constructor /// </summary> /// <param name="blockBuilder">CMS Block which is used in this code.</param> /// <param name="compatibility">compatibility level - changes behaviour if level 9 or 10</param> /// <param name="parentLog">parent logger for logging what's happening</param> public DnnDynamicCode(IBlockBuilder blockBuilder, int compatibility = 10, ILog parentLog = null) : base(blockBuilder, new DnnTenant(null), compatibility, parentLog ?? blockBuilder?.Log) { // Init things than require module-info or similar, but not 2sxc var instance = blockBuilder?.Container; Dnn = new DnnContext(instance); Link = new DnnLinkHelper(Dnn); }
public BlockDispatcher( IBlockBuilder blockBuilder, IDispatcher <Block> dispatcher, ILineReader lineReader) { this.blockBuilder = blockBuilder; this.dispatcher = dispatcher; this.lineReader = lineReader; }
protected bool CompleteInit(IBlockBuilder rootBuilder, IBlockIdentifier blockId, int blockNumberUnsureIfNeeded) { var wrapLog = Log.Call <bool>(); ParentId = Context.Module.Id; ContentBlockId = blockNumberUnsureIfNeeded; Log.Add($"parent#{ParentId}, content-block#{ContentBlockId}, z#{ZoneId}, a#{AppId}"); // 2020-09-04 2dm - new change, moved BlockBuilder up so it's never null - may solve various issues // but may introduce new ones BlockBuilder = new BlockBuilder(rootBuilder, this, Log); // If specifically no app found, end initialization here // Means we have no data, and no BlockBuilder if (AppId == AppConstants.AppIdNotFound || AppId == Eav.Constants.NullId) { DataIsMissing = true; return(wrapLog("stop: app & data are missing", true)); } // If no app yet, stop now with BlockBuilder created if (AppId == Eav.Constants.AppIdEmpty) { var msg = $"stop a:{AppId}, container:{Context.Module.Id}, content-group:{Configuration?.Id}"; return(wrapLog(msg, true)); } Log.Add("Real app specified, will load App object with Data"); // Get App for this block Log.Add("About to create app"); App = Context.ServiceProvider.Build <App>() .PreInit(Context.Site) .Init(this, Context.ServiceProvider.Build <AppConfigDelegate>().Init(Log).BuildForNewBlock(Context, this), Log); Log.Add("App created"); // note: requires EditAllowed, which isn't ready till App is created var cms = Context.ServiceProvider.Build <CmsRuntime>().Init(App, Context.UserMayEdit, Log); Configuration = cms.Blocks.GetOrGeneratePreviewConfig(blockId); // handle cases where the content group is missing - usually because of incomplete import if (Configuration.DataIsMissing) { DataIsMissing = true; App = null; return(wrapLog($"DataIsMissing a:{AppId}, container:{Context.Module.Id}, content-group:{Configuration?.Id}", true)); } // use the content-group template, which already covers stored data + module-level stored settings View = new BlockViewLoader(Log).PickView(this, Configuration.View, Context, cms); return(wrapLog($"ok a:{AppId}, container:{Context.Module.Id}, content-group:{Configuration?.Id}", true)); }
private void writeCell(IBlockBuilder bb, ExcelReportCell cell, int colSpan) { var b = bb.Add(cell.Value) .HAlign(cell.Alignment) .Style(string.IsNullOrEmpty(cell.StyleName) ? GamePlanReportStyles.DataCellStyle.Name : cell.StyleName) .ColSpan(colSpan); if (cell.AlternateBackground) { b.Background(Color.FromArgb(0xF5, 0xF5, 0xF5)); } }
internal static IBlockDataSource ForContentGroupInSxc(IBlockBuilder blockBuilder, IView view, ILookUpEngine configurationProvider, ILog parentLog, int instanceId = 0) { var log = new Log("DS.CreateV", parentLog, "will create view data source"); var showDrafts = blockBuilder.UserMayEdit; log.Add($"mid#{instanceId}, draft:{showDrafts}, template:{view?.Name}"); // Get ModuleDataSource var dsFactory = new DataSource(log); var initialSource = dsFactory.GetPublishing(blockBuilder.Block, showDrafts, configurationProvider); var moduleDataSource = dsFactory.GetDataSource <CmsBlock>(initialSource); moduleDataSource.InstanceId = instanceId; moduleDataSource.OverrideView = view; moduleDataSource.UseSxcInstanceContentGroup = true; // If the Template has a Data-Pipeline, use an empty upstream, else use the ModuleDataSource created above var viewDataSourceUpstream = view?.Query == null ? moduleDataSource : null; log.Add($"use pipeline upstream:{viewDataSourceUpstream != null}"); var viewDataSource = dsFactory.GetDataSource <Block>(blockBuilder.Block, viewDataSourceUpstream, configurationProvider); // Take Publish-Properties from the View-Template if (view != null) { viewDataSource.Publish.Enabled = view.PublishData; viewDataSource.Publish.Streams = view.StreamsToPublish; log.Add($"use template, & pipe#{view.Query?.Id}"); // Append Streams of the Data-Pipeline (this doesn't require a change of the viewDataSource itself) if (view.Query != null) { log.Add("Generate query"); var query = new Query(blockBuilder.App.ZoneId, blockBuilder.App.AppId, view.Query.Entity, configurationProvider, showDrafts, viewDataSource, parentLog); log.Add("attaching"); viewDataSource.Out = query.Out; //// build the query and attach it to the view-data-source //new QueryBuilder(parentLog) // .BuildQuery(view.Query, configurationProvider, /*paramsLookUp*/null , viewDataSource, showDrafts); } } else { log.Add("no template override"); } return(viewDataSource); }
public static IBlock NativeValueToBlock(IType type, object obj) { if (obj != null && obj.GetType() != type.GetJavaType()) { throw new ArgumentException($"Object {obj.ToString()} does not match type {type.GetJavaType()}."); } IBlockBuilder BlockBuilder = type.CreateBlockBuilder(new BlockBuilderStatus(), 1); TypeUtils.WriteNativeValue(type, BlockBuilder, obj); return(BlockBuilder.Build()); }
protected DynamicCodeRoot(IBlockBuilder blockBuilder, ITenant tenant, int compatibility, ILog parentLog) : base("Sxc.AppHlp", parentLog ?? blockBuilder?.Log) { if (blockBuilder == null) { return; } BlockBuilder = blockBuilder; _tenant = tenant; CompatibilityLevel = compatibility; App = blockBuilder.App; Data = blockBuilder.Block.Data; Edit = new InPageEditingHelper(blockBuilder, Log); }
// todo: try to cache the result of settings-stored in a static variable, this full check // todo: shouldn't have to happen every time /// <summary> /// Returns true if the Portal HomeDirectory Contains the 2sxc Folder and this folder contains the web.config and a Content folder /// </summary> public void EnsureTenantIsConfigured(IBlockBuilder blockBuilder, HttpServerUtility server, string controlPath) { var sexyFolder = new DirectoryInfo(server.MapPath(blockBuilder.Block.Tenant.SxcPath)); var contentFolder = new DirectoryInfo(Path.Combine(sexyFolder.FullName, Constants.ContentAppName)); var webConfigTemplate = new FileInfo(Path.Combine(sexyFolder.FullName, Settings.WebConfigFileName)); if (!(sexyFolder.Exists && webConfigTemplate.Exists && contentFolder.Exists)) { // configure it var tm = new TemplateHelpers(blockBuilder.App); tm.EnsureTemplateFolderExists(Settings.TemplateLocations.PortalFileSystem); } ; }
internal BlockBuilder(IBlockBuilder rootBlockBuilder, IBlock cb, IContainer container, IEnumerable <KeyValuePair <string, string> > urlParams, ILog parentLog) : base("Sxc.BlkBld", parentLog, $"get CmsInstance for a:{cb?.AppId} cb:{cb?.ContentBlockId}") { EnvFac = Factory.Resolve <IEnvironmentFactory>(); Environment = EnvFac.Environment(parentLog); // the root block is the main container. If there is none yet, use this, as it will be the root RootBuilder = rootBlockBuilder ?? this; Block = cb; Container = container; // keep url parameters, because we may need them later for view-switching and more Parameters = urlParams; }
protected MultiPermissionsApp(IBlockBuilder blockBuilder, int zoneId, int appId, ILog parentLog) : base("Api.Perms", parentLog) { var wrapLog = Log.Call($"..., appId: {appId}, ..."); BlockBuilder = blockBuilder; var tenant = new DnnTenant(PortalSettings.Current); var environment = Factory.Resolve <IEnvironmentFactory>().Environment(Log); var contextZoneId = environment.ZoneMapper.GetZoneId(tenant.Id); App = new App(tenant, zoneId, appId, ConfigurationProvider.Build(blockBuilder, true), false, Log); SamePortal = contextZoneId == zoneId; PortalForSecurityCheck = SamePortal ? PortalSettings.Current : null; wrapLog($"ready for z/a:{zoneId}/{appId} t/z:{tenant.Id}/{contextZoneId} same:{SamePortal}"); }
/// <summary> /// Generate a delegate which will be used to build the configuration based on a new sxc-instance /// </summary> internal static Func <App, IAppDataConfiguration> Build(IBlockBuilder blockBuilder, bool useExistingConfig) { return(appToUse => { // the module id var envInstanceId = blockBuilder.Container.Id; // check if we'll use the config already on the sxc-instance, or generate a new one var config = useExistingConfig ? blockBuilder.Block.Data.Configuration.LookUps : GetConfigProviderForModule(envInstanceId, appToUse as IApp, blockBuilder); // return results return new AppDataConfiguration(blockBuilder.UserMayEdit, blockBuilder.Environment.PagePublishing.IsEnabled(envInstanceId), config); }); }
/// <summary> /// Initializes the object and performs all the initial security checks /// </summary> public AdamSecureState(IBlockBuilder blockBuilder, int appId, string contentType, string field, Guid guid, bool usePortalRoot, ILog log) : base(blockBuilder, appId, contentType, log) { // only do checks on field/guid if it's actually accessing that, if it's on the portal root, don't. if (!usePortalRoot) { Field = field; Guid = guid; } var firstChecker = PermissionCheckers.First().Value; var userMayAdminSomeFiles = firstChecker.UserMay(GrantSets.WritePublished); UserMayAdminSiteFiles = firstChecker.GrantedBecause == Conditions.EnvironmentGlobal || firstChecker.GrantedBecause == Conditions.EnvironmentInstance; UserIsRestricted = !(usePortalRoot ? UserMayAdminSiteFiles : userMayAdminSomeFiles); Log.Add($"AdamSecureState - field:{field}, guid:{guid}, adminSome:{userMayAdminSomeFiles}, restricted:{UserIsRestricted}"); SecurityChecks.ThrowIfAccessingRootButNotAllowed(usePortalRoot, UserIsRestricted); Log.Add("check if feature enabled"); if (UserIsRestricted && !Feats.Enabled(FeaturesForRestrictedUsers)) { throw Http.PermissionDenied( $"low-permission users may not access this - {Feats.MsgMissingSome(FeaturesForRestrictedUsers)}"); } PrepCore(App, guid, field, usePortalRoot); if (string.IsNullOrEmpty(contentType) || string.IsNullOrEmpty(field)) { return; } Attribute = Definition(appId, contentType, field); if (!FileTypeIsOkForThisField(out var exp)) { throw exp; } }
/// <inheritdoc /> public void Init(IBlockBuilder blockBuilder, Purpose purpose, ILog parentLog) { BlockBuilder = blockBuilder; var view = BlockBuilder.View; Log.LinkTo(parentLog); var root = TemplateHelpers.GetTemplatePathRoot(view.Location, blockBuilder.App); var subPath = view.Path; string templatePath = null; if (enablePolymorphism) { templatePath = TryToFindPolymorphPath(root, view, subPath); } if (templatePath == null) { templatePath = VirtualPathUtility.Combine(root + "/", subPath); } // Throw Exception if Template does not exist if (!File.Exists(HostingEnvironment.MapPath(templatePath))) { // todo: change to some kind of "rendering exception" throw new SexyContentException("The template file '" + templatePath + "' does not exist."); } Template = view; TemplatePath = templatePath; App = blockBuilder.App; DataSource = blockBuilder.Block.Data; Purpose = purpose; // check common errors CheckExpectedTemplateErrors(); // check access permissions - before initializing or running data-code in the template CheckTemplatePermissions(blockBuilder.Block.Tenant); // Run engine-internal init stuff Init(); }
/// <summary> /// Write a native value object to the current entry of {@code blockBuilder}. /// /// TODO: Add in slice logic /// </summary> /// <param name="type"></param> /// <param name="blockBuilder"></param> /// <param name="value"></param> public static void WriteNativeValue(IType type, IBlockBuilder blockBuilder, object value) { if (value == null) { blockBuilder.AppendNull(); } else if (type.GetJavaType() == typeof(bool)) { type.WriteBoolean(blockBuilder, (bool)value); } else if (type.GetJavaType() == typeof(double)) { type.WriteDouble(blockBuilder, (double)value); } else if (type.GetJavaType() == typeof(long)) { type.WriteLong(blockBuilder, (long)value); } else if (type.GetJavaType() == typeof(Slice)) { Slice Slice = (Slice)value; if (value is byte[]) { //Slice = Slices.WrappedBuffer((byte[]) value); } else if (value is string) { //Slice = Slices.Utf8Slice((string)value); } else { Slice = (Slice)value; } type.WriteSlice(blockBuilder, Slice, 0, Slice.Size); } else { type.WriteObject(blockBuilder, value); } }
/// <summary> /// Retrieve the appId - either based on the parameter, or if missing, use context /// Note that this will fail, if both appPath and context are missing /// </summary> /// <returns></returns> internal IAppIdentity GetAppIdFromPathOrContext(string appPath, IBlockBuilder blockBuilder) { var wrapLog = Log.Call($"{appPath}, ...", message: "detect app from query string parameters"); // try to override detection based on additional zone/app-id in urls var appId = GetAppIdentityFromQueryAppZone(); if (appId == null) { Log.Add($"auto detect app and init eav - path:{appPath}, context null: {blockBuilder == null}"); appId = appPath == null || appPath == "auto" ? new AppIdentity( blockBuilder?.Block?.ZoneId ?? throw new ArgumentException("try to get app-id from context, but none found"), blockBuilder.Block.AppId // not nullable any more 2019-11-09 ?? 0 /*, Log*/) : GetCurrentAppIdFromPath(appPath); } wrapLog(appId.LogState()); return(appId); }
public ClientInfoContentGroup(IBlockBuilder blockBuilder, bool isCreated) { IsCreated = isCreated; IsContent = blockBuilder.Block.IsContentApp; Id = blockBuilder.Block.Configuration?.Id ?? 0; Guid = blockBuilder.Block.Configuration?.Guid ?? Guid.Empty; AppId = blockBuilder.Block.AppId;// 2019-11-09, Id not nullable any more // ?? 0; AppUrl = blockBuilder.App?.Path ?? "" + "/"; AppSettingsId = (blockBuilder.App?.Settings?.Entity?.Attributes?.Count > 0) ? blockBuilder.App?.Settings?.EntityId : null; // the real id (if entity exists), 0 (if entity missing, but type has fields), or null (if not available) AppResourcesId = (blockBuilder.App?.Resources?.Entity?.Attributes?.Count > 0) ? blockBuilder.App?.Resources?.EntityId : null; // the real id (if entity exists), 0 (if entity missing, but type has fields), or null (if not available) HasContent = blockBuilder.View != null && (blockBuilder.Block.Configuration?.Exists ?? false); ZoneId = blockBuilder.Block.ZoneId; // 2019-11-09, Id not nullable any more // ?? 0; TemplateId = blockBuilder.View?.Id ?? 0; TemplateEdition = blockBuilder.View?.Edition; QueryId = blockBuilder.View?.Query?.Id; // will be null if not defined ContentTypeName = blockBuilder.View?.ContentType ?? ""; IsList = blockBuilder.Block.Configuration?.View?.UseForList ?? false; // isCreated && ((sxc.BlockConfiguration?.Content?.Count ?? 0) > 1); SupportsAjax = blockBuilder.Block.IsContentApp || (blockBuilder.App?.Configuration?.EnableAjax ?? false); }
public MultiPermissionsTypes(IBlockBuilder blockBuilder, int appId, IEnumerable <string> contentTypes, ILog parentLog) : base(blockBuilder, appId, parentLog) => ContentTypes = contentTypes;
public MultiPermissionsTypes(IBlockBuilder blockBuilder, int appId, string contentType, ILog parentLog) : this(blockBuilder, appId, new [] { contentType }, parentLog) { }
public void AppendTo(IBlock block, int position, IBlockBuilder blockBuilder) { throw new NotImplementedException(); }
public void WriteObject(IBlockBuilder blockBuilder, object value) { throw new InvalidOperationException(this.GetType().Name); }
public void WriteSlice(IBlockBuilder blockBuilder, Slice value, int offset, int length) { throw new InvalidOperationException(this.GetType().Name); }
public void WriteDouble(IBlockBuilder blockBuilder, double value) { throw new InvalidOperationException(this.GetType().Name); }
private Block BuildBlock(IBlockBuilder builder, int start, StringRange document, out int newPosition) { try { return builder.Build(start, document, out newPosition); } catch (Exception x) { throw new ParsingException("Parser failed to parse block. See exception details for more info.", x) { BuilderType = builder.GetType(), Position = start, Content = new StringRange(document.Document, start, document.End) }; } }