public static UrlString BuildUrl(PageUrlOptions options) { Verify.ArgumentNotNull(options, "options"); Verify.ArgumentCondition(options.UrlType != UrlType.Undefined, "options", "Url type is undefined"); return(BuildUrl(options.UrlType, options)); }
public NotLoadedInlineFunction(IInlineFunction functionInfo, StringInlineFunctionCreateMethodErrorHandler errors) { Verify.ArgumentCondition(errors.HasErrors, "errors", "No errors information provided"); _function = functionInfo; _errors = errors; }
public List <T> AddNew <T>(IEnumerable <T> dataset, DataProviderContext dataProviderContext) where T : class, IData { SqlDataTypeStore sqlDataTypeStore = TryGetsqlDataTypeStore(typeof(T)); if (sqlDataTypeStore == null) { throw new InvalidOperationException(string.Format("The interface '{0}' has not been configures", typeof(T).FullName)); } var resultDataset = new List <T>(); using (var dataContext = CreateDataContext()) { foreach (IData data in dataset) { Verify.ArgumentCondition(data != null, "dataset", "Data set may not contain nulls"); IData newData = sqlDataTypeStore.AddNew(data, dataProviderContext, dataContext); (newData as IEntity).Commit(); CheckConstraints(newData); resultDataset.Add((T)newData); } SubmitChanges(dataContext); } return(resultDataset); }
/// <exclude /> public static IQueryable <IPage> GetChildren(this IPage page) { Verify.ArgumentNotNull(page, "page"); Verify.ArgumentCondition(page.DataSourceId.ExistsInStore, "page", "The given data have not been added yet"); return(GetChildren(page.Id)); }
/// <exclude /> public ParameterProfile( string name, Type type, bool isRequired, BaseValueProvider fallbackValueProvider, WidgetFunctionProvider widgetFunctionProvider, string label, HelpDefinition helpDefinition, bool hideInSimpleView) { Verify.ArgumentNotNull(name, "name"); Verify.ArgumentNotNull(type, "type"); Verify.ArgumentNotNull(fallbackValueProvider, "fallbackValueProvider"); Verify.ArgumentCondition(!label.IsNullOrEmpty(), "label", "label may not be null or an empty string"); Verify.ArgumentNotNull(helpDefinition, "helpDefinition"); this.Name = name; this.Type = type; this.IsRequired = isRequired && (!type.IsGenericType || type.GetGenericTypeDefinition() != typeof(NullableDataReference <>)); this.FallbackValueProvider = fallbackValueProvider; _widgetFunctionProvider = widgetFunctionProvider; this.Label = label; this.HelpDefinition = helpDefinition; this.HideInSimpleView = hideInSimpleView; }
public static IRelativeRouteToPredicateMapper GetPredicateMapper(Type dataType) { Verify.ArgumentNotNull(dataType, "dataType"); Verify.ArgumentCondition(dataType.IsInterface && typeof(IData).IsAssignableFrom(dataType), "dataType", "The data type have to an interface, inheriting {0}".FormatWith(typeof(IData).FullName)); var mappings = dataType .GetAllProperties() .SelectMany(prop => prop .GetCustomAttributes().OfType <RouteSegmentAttribute>() .Select(attr => new { Attribute = attr, attr.Order, Property = prop, Mapper = attr.BuildMapper(prop) })) .OrderBy(a => a.Order) .Select(a => new PropertyUrlMapping { Attribute = a.Attribute, Property = a.Property, Mapper = a.Mapper }) .ToArray(); if (!mappings.Any()) { return(null); } foreach (var mapping in mappings) { Verify.IsNotNull(mapping.Mapper, "An attribute of type '{0}' returned a null mapper", mapping.Attribute.GetType().FullName); } var targetType = typeof(DataTypeRelativeRouteToPredicateMapper <>).MakeGenericType(dataType); var constructor = targetType.GetConstructor(new[] { typeof(PropertyUrlMapping[]) }); return((IRelativeRouteToPredicateMapper)constructor.Invoke(new object[] { mappings })); }
/// <exclude /> public static List <KeyValuePair> GetLocalization(string providerName) { Verify.ArgumentNotNullOrEmpty(providerName, "providerName"); Verify.ArgumentCondition(!providerName.Contains(','), "providerName", "providerName may not contain ','"); if (providerName == "XmlStringResourceProvider") { providerName = "Composite.Management"; } IDictionary <string, string> translations = ResourceProviderPluginFacade.GetAllStrings(providerName); if (translations == null) { Log.LogVerbose(LogTitle, "Missing localization section: '{0}'".FormatWith(providerName)); return(new List <KeyValuePair>()); } List <KeyValuePair> result = new List <KeyValuePair>(); foreach (KeyValuePair <string, string> pair in translations) { result.Add(new KeyValuePair(pair.Key, pair.Value)); } return(result); }
/// <exclude /> public static Control Render(this IPage page, IEnumerable <IPagePlaceholderContent> placeholderContents, FunctionContextContainer functionContextContainer) { Verify.ArgumentNotNull(page, "page"); Verify.ArgumentNotNull(functionContextContainer, "functionContextContainer"); Verify.ArgumentCondition(functionContextContainer.XEmbedableMapper is XEmbeddedControlMapper, "functionContextContainer", $"Unknown or missing XEmbedableMapper on context container. Use {nameof(GetPageRenderFunctionContextContainer)}()."); CurrentPage = page; using (GlobalInitializerFacade.CoreIsInitializedScope) { string url = PageUrls.BuildUrl(page); using (TimerProfilerFacade.CreateTimerProfiler(url ?? "(no url)")) { var cultureInfo = page.DataSourceId.LocaleScope; System.Threading.Thread.CurrentThread.CurrentCulture = cultureInfo; System.Threading.Thread.CurrentThread.CurrentUICulture = cultureInfo; XEmbeddedControlMapper mapper = (XEmbeddedControlMapper)functionContextContainer.XEmbedableMapper; XDocument document = TemplateInfo.GetTemplateDocument(page.TemplateId); ResolvePlaceholders(document, placeholderContents); Control c = Render(document, functionContextContainer, mapper, page); return(c); } } }
private static void PageTemplate_Changed(object sender, DataEventArgs dataEventArgs) { var pageTemplate = dataEventArgs.Data as IXmlPageTemplate; Verify.ArgumentCondition(pageTemplate != null, "dataEventArgs", "Data is null or has an incorrect data type."); PageTemplateCache.Remove(pageTemplate.Id); }
public IQueryable <S> CreateQuery <S>(Expression expression) { Verify.ArgumentNotNull(expression, "expression"); Verify.ArgumentCondition(typeof(IQueryable <S>).IsAssignableFrom(expression.Type), "expression", "Incorrect expression type"); return(new DataFacadeQueryable <S>(_sources, expression)); }
public MvcFunction(ControllerDescriptor controllerDescriptor) { Verify.ArgumentNotNull(controllerDescriptor, "controllerDescriptor"); var attribute = controllerDescriptor.GetCustomAttributes(false).OfType <MvcFunctionAttribute>().SingleOrDefault(); Verify.ArgumentCondition(attribute != null, "controllerDescriptor", String.Format("Controller '{0} is missing the '{1}' attribute", controllerDescriptor.ControllerType.Name, typeof(MvcFunctionAttribute).Name)); _controllerDescriptor = controllerDescriptor; var c1FunctionsType = typeof(C1FunctionsController); var baseType = _controllerDescriptor.ControllerType.BaseType; Verify.ArgumentCondition(baseType != null, "controllerDescriptor", String.Format("Controller '{0} needs to have a basetype", controllerDescriptor.ControllerType.Name)); Verify.ArgumentCondition(c1FunctionsType.IsAssignableFrom(baseType), "controllerDescriptor", String.Format("Controller '{0} needs to inherit from '{1}'", controllerDescriptor.ControllerType.Name, c1FunctionsType.Name)); if (baseType.IsGenericType) { var typeArguments = baseType.GetGenericArguments(); _modelType = typeArguments[0]; } Namespace = String.IsNullOrEmpty(attribute.Namespace) ? _controllerDescriptor.ControllerType.Namespace : attribute.Namespace; Name = String.IsNullOrEmpty(attribute.Name) ? _controllerDescriptor.ControllerName : attribute.Name; Description = attribute.Description ?? String.Empty; }
public MvcPageTemplateDescriptor(Type type) { var attribute = type.GetCustomAttribute <MvcTemplateAttribute>(false); Verify.ArgumentCondition(attribute != null, "type", String.Format("Type '{0}' doesn't have the required '{1}' attribute", type.FullName, typeof(MvcTemplateAttribute).FullName)); var title = attribute.Title; if (String.IsNullOrEmpty(title)) { title = type.Name; } var viewName = attribute.ViewName; if (String.IsNullOrEmpty(viewName)) { viewName = title; } Dictionary <string, PropertyInfo> typeInfo; _placeholderDescriptions = ResolvePlaceholderDescriptors(type, out _defaultPlaceholderId, out typeInfo); TypeInfo = new Tuple <Type, Dictionary <string, PropertyInfo> >(type, typeInfo); ViewName = viewName; Id = Guid.Parse(attribute.Id); Title = title; }
/// <exclude /> public static Guid GetParentId(this IPage page) { Verify.ArgumentNotNull(page, "page"); Verify.ArgumentCondition(page.DataSourceId.ExistsInStore, "page", "The given data have not been added yet"); return(PageManager.GetParentId(page.Id)); }
/// <summary> /// Registers a global data url mapper for the specified type. /// </summary> /// <param name="dataType">The data type.</param> /// <param name="dataUrlMapper">The data url mapper.</param> public static void RegisterGlobalDataUrlMapper(Type dataType, IDataUrlMapper dataUrlMapper) { Verify.ArgumentCondition(dataType.IsInterface && typeof(IData).IsAssignableFrom(dataType), "dataType", "The data type should be an interface inheriting Composite.Data.IData"); _globalDataUrlMappers[dataType] = dataUrlMapper; }
IFunctionProvider IAssembler <IFunctionProvider, FunctionProviderData> .Assemble(IBuilderContext context, FunctionProviderData objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache) { var data = objectConfiguration as UserControlFunctionProviderData; Verify.ArgumentCondition(data != null, "objectConfiguration", "Expected configuration to be of type " + typeof(UserControlFunctionProviderData).Name); return(new UserControlFunctionProvider(data.Name, data.Directory)); }
public static void SetUserGroupPermissionDefinition(UserGroupPermissionDefinition userGroupPermissionDefinition) { Verify.ArgumentNotNull(userGroupPermissionDefinition, "userGroupPermissionDefinition"); Verify.ArgumentCondition(!userGroupPermissionDefinition.SerializedEntityToken.IsNullOrEmpty(), "userGroupPermissionDefinition", "SerializedEntityToken is empty"); Verify.ArgumentCondition(userGroupPermissionDefinition.UserGroupId != Guid.Empty, "userGroupPermissionDefinition", "Is Guid.Empty"); _resourceLocker.Resources.Plugin.SetUserGroupPermissionDefinition(userGroupPermissionDefinition); }
/// <exclude /> public DataSourceId CreateDataSourceId(IDataId dataId, Type interfaceType) { Verify.ArgumentNotNull(dataId, "dataId"); Verify.ArgumentNotNull(interfaceType, "interfaceType"); Verify.ArgumentCondition(typeof(IData).IsAssignableFrom(interfaceType), "interfaceType", "The interface type '{0}' does not inherit the interface '{1}'".FormatWith(interfaceType, typeof(IData))); return(new DataSourceId(dataId, _providerName, interfaceType, DataScopeManager.MapByType(interfaceType), LocalizationScopeManager.MapByType(interfaceType))); }
/// <summary> /// Sets the field's value to a random base64 string value of the specified length. /// </summary> /// <param name="length">The length of a generated random string. Allowed range is [3..22].</param> /// <param name="checkCollisions">When set to 2, the inserted value will be checked for a collision.</param> public DefaultFieldRandomStringValueAttribute(int length = 8, bool checkCollisions = false) { Verify.ArgumentCondition(length >= 3, "length", "Minimum allowed length is 3 characters"); Verify.ArgumentCondition(length <= 22, "length", "Maximum allowed length is 22 characters, which is an equivalent to a Guid value"); Length = length; CheckCollisions = checkCollisions; }
internal static void DeleteFile(IFile file) { Verify.ArgumentNotNull(file, "file"); Verify.ArgumentCondition(file is FileSystemFileBase, "file", "The type '{0}' does not inherit the class '{1}'".FormatWith(file.GetType(), typeof(FileSystemFileBase))); var baseFile = file as FileSystemFileBase; DeleteFile(baseFile.SystemPath); }
internal static void WriteFileToDisk(IFile file) { Verify.ArgumentNotNull(file, "file"); Verify.ArgumentCondition(file is FileSystemFileBase, "file", "The type '{0}' does not inherit the class '{1}'".FormatWith(file.GetType(), typeof(FileSystemFileBase))); var baseFile = file as FileSystemFileBase; baseFile.CommitChanges(); }
public Stream GetNewWriteStream(IFile file) { Verify.ArgumentNotNull(file, "file"); Verify.ArgumentCondition(file is FileSystemFileBase, "file", "The type '{0}' does not inherit the class '{1}'".FormatWith(file.GetType(), typeof(FileSystemFileBase))); var baseFile = file as FileSystemFileBase; return(baseFile.GetNewWriteStream()); }
/// <exclude /> public DataSourceId CreateDataSourceId(IDataId dataId, Type interfaceType, DataScopeIdentifier dataScopeIdentifier, CultureInfo cultureInfo) { Verify.ArgumentNotNull(dataId, "dataId"); Verify.ArgumentNotNull(interfaceType, "interfaceType"); Verify.ArgumentNotNull(dataScopeIdentifier, "dataScopeIdentifier"); Verify.ArgumentNotNull(cultureInfo, "cultureInfo"); Verify.ArgumentCondition(typeof(IData).IsAssignableFrom(interfaceType), "interfaceType", "The interface type '{0}' does not inherit the interface '{1}'".FormatWith(interfaceType, typeof(IData))); return(new DataSourceId(dataId, _providerName, interfaceType, dataScopeIdentifier, cultureInfo)); }
/// <exclude /> public void AddHookies(IEnumerable <EntityToken> hooks) { Verify.ArgumentNotNull(hooks, "hooks"); IEnumerable <EntityToken> resolvedHooks = hooks.Evaluate(); Verify.ArgumentCondition(!resolvedHooks.Contains(null), "hooks", "The collection contains one or more null values"); _hooks.AddRange(resolvedHooks); }
/// <exclude /> public static IDataReference BuildDataReference(Type referencedType, object keyValue) { Verify.ArgumentNotNull(keyValue, "keyValue"); Verify.ArgumentNotNull(referencedType, "referencedType"); Verify.ArgumentCondition(typeof(IData).IsAssignableFrom(referencedType), "referencedType", "The referenced type must implement IData"); Type genericReferenceType = typeof(DataReference <>).MakeGenericType(new Type[] { referencedType }); return((IDataReference)Activator.CreateInstance(genericReferenceType, new object[] { keyValue })); }
/// <exclude /> public PageUrl(PublicationScope publicationScope, CultureInfo locale, Guid pageId, PageUrlType urlType) { Verify.ArgumentNotNull(locale, "locale"); Verify.ArgumentCondition(pageId != Guid.Empty, "pageId", "PageId should not be an empty guid."); this.PublicationScope = publicationScope; Locale = locale; PageId = pageId; UrlType = urlType; }
/// <exclude /> public static int GetLocalOrdering(this IPage page) { Verify.ArgumentNotNull(page, "page"); Verify.ArgumentCondition(page.DataSourceId.ExistsInStore, "page", "The given data have not been added yet"); using (new DataScope(DataScopeIdentifier.Administrated)) { return(PageManager.GetLocalOrdering(page.Id)); } }
/// <exclude /> public PageUrlOptions(string dataScopeIdentifierName, CultureInfo locale, Guid pageId, UrlType urlType) { Verify.ArgumentNotNullOrEmpty(dataScopeIdentifierName, "dataScopeIdentifierName"); Verify.ArgumentNotNull(locale, "locale"); Verify.ArgumentCondition(pageId != Guid.Empty, "pageId", "PageId should not be an empty guid."); DataScopeIdentifierName = dataScopeIdentifierName; Locale = locale; PageId = pageId; UrlType = urlType; }
/// <exclude /> public override AncestorResult GetParentEntityToken(EntityToken ownEntityToken, Type parentInterfaceOfInterest, TreeNodeDynamicContext dynamicContext) { if (this.ParentFilteringHelpers == null) { throw new InvalidOperationException(string.Format("Failed to find parent, are you missing a parent filter for the type '{0}'", this.InterfaceType)); } ParentFilterHelper helper; if (this.ParentFilteringHelpers.TryGetValue(parentInterfaceOfInterest, out helper) == false) { // We cant find the interface of interest directly, so we will give 'some' parent entity token // by using 'one' of our own parent id filters helper = this.ParentFilteringHelpers.First().Value; } DataEntityToken dataEntityToken = (DataEntityToken)ownEntityToken; IData data = dataEntityToken.Data; Verify.ArgumentCondition(data != null, "ownEntityToken", "Failed to get data"); object parentFieldValue = helper.ParentReferencedPropertyInfo.GetValue(data, null); ParameterExpression parameterExpression = Expression.Parameter(helper.ParentIdFilterNode.ParentFilterType, "data"); Expression expression = Expression.Equal( ExpressionHelper.CreatePropertyExpression(helper.ParentRefereePropertyName, parameterExpression), Expression.Constant(parentFieldValue, helper.ParentReferencedPropertyInfo.PropertyType) ); Expression whereExpression = ExpressionHelper.CreateWhereExpression( DataFacade.GetData(helper.ParentIdFilterNode.ParentFilterType).Expression, parameterExpression, expression ); IData parentDataItem = ExpressionHelper.GetCastedObjects <IData>(helper.ParentIdFilterNode.ParentFilterType, whereExpression) .FirstOrDefault(); Verify.IsNotNull(parentDataItem, "Failed to get parent data item. Check if there's a broken parent reference."); DataEntityToken parentEntityToken = parentDataItem.GetDataEntityToken(); TreeNode parentTreeNode = this.ParentNode; var dataElementsTreeNode = parentTreeNode as DataElementsTreeNode; while (dataElementsTreeNode == null || dataElementsTreeNode.InterfaceType != parentEntityToken.InterfaceType) { parentTreeNode = parentTreeNode.ParentNode; } return(new AncestorResult(parentTreeNode, parentEntityToken)); }
private RouteValueDictionary SetupConstraints() { var constraints = new RouteValueDictionary(); if (!String.IsNullOrEmpty(Page)) { Guid pageId; if (Guid.TryParse(Page, out pageId)) { constraints.Add("pageId", new C1PageRouteConstraint(pageId)); } } if (!String.IsNullOrEmpty(PageTemplates)) { var templates = PageTemplates.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); var templateIds = new List <Guid>(); foreach (var template in templates) { var templateId = ResolveTemplate(template); Verify.ArgumentCondition(templateId.HasValue, "PageTemplates", String.Format("Template '{0}' not found", template)); templateIds.Add(templateId.Value); } if (templateIds.Any()) { constraints.Add("templates", new C1PageTemplateRouteConstraint(templateIds)); } } if (!String.IsNullOrEmpty(PageType)) { var typeId = ResolveType(PageType); Verify.ArgumentCondition(typeId.HasValue, "PageType", String.Format("Pagetype '{0}' not found", PageType)); constraints.Add("type", new C1PageTypeRouteConstraint(typeId.Value)); } if (!String.IsNullOrEmpty(Suffix)) { constraints.Add("pathinfo", new C1PathInfoRouteConstraint(Suffix)); } if (Reason != RenderingReason.Undefined) { constraints.Add("reason", new C1RenderingReasonConstraint(Reason)); } return(constraints); }
public void Delete(IEnumerable <DataSourceId> dataSourceIds) { Verify.ArgumentNotNull(dataSourceIds, "dataSourceIds"); CheckTransactionNotInAbortedState(); using (XmlDataProviderDocumentCache.CreateEditingContext()) { var validated = new Dictionary <DataSourceId, FileRecord>(); // verify phase foreach (DataSourceId dataSourceId in dataSourceIds) { Verify.ArgumentCondition(dataSourceId != null, nameof(dataSourceIds), "The enumeration may not contain null values"); XmlDataTypeStore dataTypeStore = _xmlDataTypeStoresContainer.GetDataTypeStore(dataSourceId.InterfaceType); var dataScope = dataSourceId.DataScopeIdentifier; var culture = dataSourceId.LocaleScope; var type = dataSourceId.InterfaceType; var dataId = dataSourceId.DataId; var dataTypeStoreScope = dataTypeStore.GetDataScope(dataScope, culture, type); if (dataTypeStore.Helper._DataIdType != dataId.GetType()) { throw new ArgumentException("Only data ids from this provider is allowed to be deleted on on the provider"); } var fileRecord = GetFileRecord(dataTypeStore, dataTypeStoreScope); var index = fileRecord.RecordSet.Index; if (!index.ContainsKey(dataId)) { throw new ArgumentException($"Cannot delete a data item, no data element corresponds to the given data id: '{dataId.Serialize(null)}'; Type: '{type}'; DataScope: '{dataScope}'; Culture: '{culture}'", nameof(dataSourceIds)); } validated.Add(dataSourceId, fileRecord); } // commit phase foreach (var dataSourceId in validated.Keys) { FileRecord fileRecord = validated[dataSourceId]; fileRecord.RecordSet.Index.Remove(dataSourceId.DataId); fileRecord.Dirty = true; } XmlDataProviderDocumentCache.SaveChanges(); SubscribeToTransactionRollbackEvent(); } }