Пример #1
0
 protected override void OnModelCreating(IModelAccessor modelAccessor)
 {
     modelAccessor.ConnectionString = "Data Source=localhost;Initial Catalog=Test;Integrated Security=True;";
     modelAccessor.UseEntityFramework(modelBuilder =>
     {
         modelBuilder.Entity <ModuleConfig>().HasKey(x => new { x.IdModule });
     });
 }
Пример #2
0
 /// <summary>
 /// Предоставляет доступ к процессу создания модели в EntityFramework через делегат <paramref name="modelBuilderDelegate"/>.
 /// </summary>
 public static void UseEntityFramework(this IModelAccessor modelAccessor, Action <DbModelBuilder> modelBuilderDelegate)
 {
     if (modelAccessor is Internal.ModelAccessorInternal modelAccessorInternal)
     {
         modelAccessorInternal.ModelBuilderDelegate = modelBuilderDelegate;
     }
     else
     {
         throw new InvalidOperationException("This can be used only for EF context.");
     }
 }
Пример #3
0
 /// <summary> Implements <see cref="IModelDefinitionManager.GetAccessors"/> </summary>
 public IModelAccessor GetAccessor(string Ident)
 {
     lock (syncObj)
     {
         IModelAccessor ret = null;
         if (ModelAccessorByIdent != null)
         {
             ModelAccessorByIdent.TryGetValue(Ident, out ret);
         }
         return(ret);
     }
 }
Пример #4
0
        public static IModelAccessorGroup CreateInstance(ModelDefinitionManager parent, XmlModelAccessorGroup definition)
        {
            if (definition == null)
            {
                return(null);
            }

            ModelAccessorGroup group = new ModelAccessorGroup();

            try
            {
                if (string.IsNullOrEmpty(definition.Name))
                {
                    throw new EtkException("'Name' is mandatory");
                }

                group.Parent      = parent;
                group.Name        = definition.Name.EmptyIfNull().Trim();
                group.Description = definition.Description.EmptyIfNull().Trim();

                if (definition.Accessors != null)
                {
                    foreach (XmlModelAccessor xmlAccessor in definition.Accessors)
                    {
                        //IModelAccessor accessor = CreateModelAccessors(modelAccessorDefinition);
                        IModelAccessor accessor = ModelAccessor.CreateInstance(group, xmlAccessor);
                        if (accessor != null)
                        {
                            group.accessors.Add(accessor);

                            if (parent.ModelAccessorByIdent.ContainsKey(accessor.Ident))
                            {
                                Logger.Instance.LogFormat(LogType.Warn, "The model accessor '{0}' is declared more than once.", accessor.Ident);
                            }
                            parent.ModelAccessorByIdent[accessor.Ident] = accessor;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new EtkException($"Cannot create 'Model Accessor Group' '{definition.Name.EmptyIfNull()}': {ex.Message}");
            }
            return(group);
        }
Пример #5
0
        public ModelLinkProperty(ModelType parent, XmlModelLinkProperty xmlLinkProperty)
        {
            try
            {
                Parent      = parent;
                Name        = xmlLinkProperty.Name.EmptyIfNull().Trim();
                Description = xmlLinkProperty.Description.EmptyIfNull().Trim();
                string accessorName = xmlLinkProperty.Accessor.EmptyIfNull().Trim();

                if (parent == null)
                {
                    throw new EtkException("'Parent Type' is not defined");
                }
                if (string.IsNullOrEmpty(Name))
                {
                    throw new EtkException("'Name' cannot be null or empty");
                }
                if (string.IsNullOrEmpty(accessorName))
                {
                    throw new EtkException("'Accessor' cannot be null or empty");
                }
                IModelAccessor accessor = Parent.Parent.GetAccessor(accessorName);
                if (accessor == null)
                {
                    throw new EtkException($"Cannot find the 'Accessor' '{accessorName}'");
                }

                LinkedModelAccessor = accessor;
                IsACollection       = LinkedModelAccessor.ReturnTypeIsACollection;

                IEnumerable <string> keys = null;
                if (!string.IsNullOrEmpty(xmlLinkProperty.Keys))
                {
                    keys = xmlLinkProperty.Keys.Split(',').Select(k => k.Trim()).Where(k => string.IsNullOrEmpty(k));
                }
            }
            catch (Exception ex)
            {
                throw new EtkException($"Linked Property '{Name.EmptyIfNull()}' creation failed: {ex.Message}");
            }
        }
Пример #6
0
 /// <summary>
 /// —м. <see cref="UnitOfWorkBase.OnModelCreating(IModelAccessor)"/>.
 /// </summary>
 protected virtual void OnModelCreatingCustom(IModelAccessor modelAccessor)
 {
 }
Пример #7
0
 /// <summary>
 /// </summary>
 protected sealed override void OnModelCreating(IModelAccessor modelAccessor)
 {
     modelAccessor.ConnectionString = ConnectionString;
     OnModelCreatingCustom(modelAccessor);
     modelAccessor.ConnectionString = ConnectionString;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandLineServiceProvider" /> class.
 /// </summary>
 /// <param name="modelAccessor">The model accessor.</param>
 public CommandLineServiceProvider(IModelAccessor modelAccessor) => _modelAccessor = modelAccessor;