コード例 #1
0
ファイル: BrowseTakePropertyInfo.cs プロジェクト: koav/Rhetos
        internal static IList<IConceptInfo> CreateNewConcepts(
            BrowseDataStructureInfo browse, string path, string newPropertyName,
            IEnumerable<IConceptInfo> existingConcepts, IConceptInfo errorContext)
        {
            var newConcepts = new List<IConceptInfo>();

            ValueOrError<PropertyInfo> sourceProperty = GetSelectedPropertyByPath(browse, path, existingConcepts);
            if (sourceProperty.IsError)
                return null; // Creating the browse property may be delayed for other macro concepts to generate the needed properties. If this condition is not resolved, the CheckSemantics function below will throw an exception.

            if (!IsValidIdentifier(newPropertyName))
                throw new DslSyntaxException(string.Format(
                    "Invalid format of {0}: Property name '{1}' is not a valid identifier. Specify a valid name before the path to override the generated name.",
                    errorContext.GetUserDescription(),
                    newPropertyName));

            var cloneMethod = typeof(object).GetMethod("MemberwiseClone", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            var browseProperty = (PropertyInfo)cloneMethod.Invoke(sourceProperty.Value, null);
            browseProperty.DataStructure = browse;
            browseProperty.Name = newPropertyName;

            var browsePropertySelector = new BrowseFromPropertyInfo { PropertyInfo = browseProperty, Path = path };

            return new IConceptInfo[] { browseProperty, browsePropertySelector };
        }
コード例 #2
0
        protected static string RepositoryFunctionsSnippet(BrowseDataStructureInfo info)
        {
            return string.Format(
            @"        public static IQueryable<{0}.{1}> Compute(IQueryable<{2}.{3}> source)
            {{
            return
                from item in source
                select new {0}.{1}
                {{
                    ID = item.ID,
                    Base = item,
                    " + BrowsePropertiesTag.Evaluate(info) + @"
                }};
            }}

            ", info.Module.Name, info.Name, info.Source.Module.Name, info.Source.Name);
        }
コード例 #3
0
 protected static string QuerySnippet(BrowseDataStructureInfo info)
 {
     return string.Format(
         @"return Compute(_domRepository.{0}.{1}.Query());",
         info.Source.Module.Name, info.Source.Name);
 }
コード例 #4
0
ファイル: BrowseTakePropertyInfo.cs プロジェクト: koav/Rhetos
 internal static void CheckSemantics(BrowseDataStructureInfo browse, string path, IEnumerable<IConceptInfo> concepts, IConceptInfo errorContext)
 {
     var property = GetSelectedPropertyByPath(browse, path, concepts);
     if (property.IsError)
         throw new DslSyntaxException("Invalid format of " + errorContext.GetUserDescription() + ": " + property.Error);
 }
コード例 #5
0
ファイル: BrowseTakePropertyInfo.cs プロジェクト: koav/Rhetos
        private static ValueOrError<PropertyInfo> GetSelectedPropertyByPath(BrowseDataStructureInfo browse, string path, IEnumerable<IConceptInfo> existingConcepts)
        {
            if (path.Contains(" "))
                return ValueOrError.CreateError("The path contains a space character.");

            if (string.IsNullOrEmpty(path))
                return ValueOrError.CreateError("The path is empty.");

            var propertyNames = path.Split('.');
            var referenceNames = propertyNames.Take(propertyNames.Count() - 1).ToArray();
            var lastPropertyName = propertyNames[propertyNames.Count() - 1];

            ValueOrError<DataStructureInfo> selectedDataStructure = browse.Source;
            foreach (var referenceName in referenceNames)
            {
                selectedDataStructure = NavigateToNextDataStructure(selectedDataStructure.Value, referenceName, existingConcepts);
                if (selectedDataStructure.IsError)
                    return ValueOrError.CreateError(selectedDataStructure.Error);
            }

            PropertyInfo selectedProperty = existingConcepts.OfType<PropertyInfo>()
                .Where(p => p.DataStructure == selectedDataStructure.Value && p.Name == lastPropertyName)
                .SingleOrDefault();

            if (selectedProperty == null && lastPropertyName == "ID")
                return new GuidPropertyInfo { DataStructure = selectedDataStructure.Value, Name = "ID" };

            if (selectedProperty == null)
                return ValueOrError.CreateError("There is no property '" + lastPropertyName + "' on " + selectedDataStructure.Value.GetUserDescription() + ".");

            return selectedProperty;
        }