コード例 #1
0
        private void AddComments(IEntity article, string articleInfo)
        {
            var comments = Regex.Matches(articleInfo, "(?<=text:).*");
            var authors  = Regex.Matches(articleInfo, "(?<=author:).*");

            for (int i = 0; i < comments.Count; i++)
            {
                var comment = new Comment();
                comment.ArticleId = article.Id;
                comment.Text      = comments[i].Value;
                using (var academyEntities = new AcademyEntities())
                {
                    var email = authors[i].Value.TrimEnd('\r');
                    comment.UserId = academyEntities.Users.Single(
                        x => x.Email.Equals(email)).Id;
                }
                using (var context = new EfDataContext())
                {
                    var publicationService = new PublicationService(context);
                    publicationService.Comment(comment);
                    var notificationService = new NotificationService(context);
                    notificationService.NotifyAboutNewComment(comment);
                }
            }
        }
コード例 #2
0
        public void InitialProvisioning_CreatesUser()
        {
            using (var destination =
                       new EfDataContext <DestinationDbContext>(new DestinationDbContext(_dstConnection)) as IDataTarget)
            {
                var dstEntity = new DestinationUser
                {
                    EmailAddress   = "*****@*****.**",
                    SamAccountName = "pesho"
                };

                AsyncTestDelegate @delegate = async() =>
                {
                    Assert.That((await destination.GetProvisioningStatusAsync(dstEntity)).State,
                                Is.EqualTo(ProvisioningState.Inexistent));
                    Assert.That((await destination.ProvisionAsync(dstEntity)).State,
                                Is.EqualTo(ProvisioningState.Created));
                    Assert.That((await destination.GetProvisioningStatusAsync(dstEntity)).State,
                                Is.EqualTo(ProvisioningState.Unmodified));
                };


                Assert.Multiple(@delegate);
            }
        }
コード例 #3
0
ファイル: DataSourceTests.cs プロジェクト: emsidm/EMS
        public void UserAdded_AppearsInContext()
        {
            SourceUser newUser;
            var        srcUser = new SourceUser
            {
                EmailAddress = "*****@*****.**",
                UserName     = "******"
            };

            using (var efContext = new SourceDbContext(_srcConnection))
            {
                efContext.Users.Add(srcUser);
                efContext.SaveChanges();
            }

            using (var source =
                       new EfDataContext <SourceDbContext>(new SourceDbContext(_srcConnection)) as IDataSource)
            {
                newUser = source.Entities <SourceUser>().Single(x => x.EmailAddress == srcUser.EmailAddress);
            }

            Assert.Multiple(() =>
            {
                Assert.That(newUser.Id, Is.EqualTo(srcUser.Id));
                Assert.That(newUser.EmailAddress, Is.EqualTo(srcUser.EmailAddress));
            });
        }
コード例 #4
0
 public LancamentoAnexoRepositorio(EfDataContext efContext, IPeriodoRepositorio periodoRepositorio, ConfigurationHelper configHelper)
 {
     _apiGoogleDriveProxy = new ApiGoogleDriveProxy();
     _efContext           = efContext;
     _periodoRepositorio  = periodoRepositorio;
     _idPastaGoogleDrive  = configHelper.IdPastaGoogleDriveAnexos;
 }
コード例 #5
0
        public async Task Preprovisioned_UpdatesUser()
        {
            using (var destination =
                       new EfDataContext <DestinationDbContext>(new DestinationDbContext(_dstConnection)) as IDataTarget)
            {
                var dstEntity = new DestinationUser
                {
                    EmailAddress   = "*****@*****.**",
                    SamAccountName = "gosho"
                };
                await destination.ProvisionAsync(dstEntity);

                dstEntity.EmailAddress   = "*****@*****.**";
                dstEntity.SamAccountName = "pesho";

                var changedEntity      = dstEntity;
                var provisioningStatus = await destination.ProvisionAsync(changedEntity);

                Assert.Multiple(() =>
                {
                    Assert.That(provisioningStatus.State,
                                Is.EqualTo(ProvisioningState.Updated));
                    Assert.That(provisioningStatus.Entities.First().EmailAddress,
                                Is.EqualTo(dstEntity.EmailAddress));
                }
                                );
            }
        }
コード例 #6
0
        public void InitialiseDb(DbConfiguration dbConfig, DeploymentConfiguration deployConfig)
        {
            Console.WriteLine("Connecting to the Database...");

            SqlConnection connection = new SqlConnection(dbConfig.GetConnectionString());

            try
            {
                EfDataContext efContext = new EfDataContext(connection);
                if (deployConfig.CreateAdmin)
                {
                    if (string.IsNullOrWhiteSpace(deployConfig.AdminPassword))
                    {
                        Console.WriteLine("An Administrator password was not specified.");
                        Console.WriteLine("Skipping admin creation because of this.");
                    }
                    else
                    {
                        //create an admin user
                    }
                }
            }
            catch (SqlException se)
            {
                Exit(1, "A problem occured whilst querying the Database:\n" + se.Message);
            }

            //more stuff here
        }
コード例 #7
0
 protected virtual void Dispose(bool disposing)
 {
     if (_Db != null)
     {
         _Db.Dispose();
         _Db = null;
     }
 }
コード例 #8
0
        //internal ILogger _logger;

        public GenericDbAccess(EfDataContext db)
        {
            _db = db;

            // Set up any global mapper mappings we have
            ApplyGlobalMappings();

            // Call into the virtual implementation (If there is one) in the derived class
            // to set custom mapster mappings for that class
            ApplyCustomMappings();
        }
コード例 #9
0
ファイル: DataSourceTests.cs プロジェクト: emsidm/EMS
        public void UserNotInDb_ReturnsEmpty()
        {
            bool exists;

            using (var source =
                       new EfDataContext <SourceDbContext>(new SourceDbContext(_srcConnection)) as IDataSource)
            {
                exists = source.Entities <SourceUser>().Any(x => x.EmailAddress == "*****@*****.**");
            }

            Assert.That(exists, Is.False);
        }
コード例 #10
0
ファイル: Program.cs プロジェクト: vbogretsov/academy
 private static void TestChildDisciplines()
 {
     using (IDataContext context = new EfDataContext())
     {
         var storage     = context.DisciplineStorage;
         var disciplines = SelectDisciplines(storage);
         var allChildren = storage.Get(disciplines.Select(x => x.Id));
         foreach (var discipline in allChildren)
         {
             Console.WriteLine(discipline.Name);
         }
     }
 }
コード例 #11
0
ファイル: Program.cs プロジェクト: polkduran/NowCoding
        static void Main(string[] args)
        {
            var file = "mydb.db";

            File.Delete(file);
            Func <SqliteConnectionStringBuilder> getCon = () => new SqliteConnectionStringBuilder {
                ["Filename"] = file
            };

            var con = getCon();

            con.Mode = SqliteOpenMode.ReadWriteCreate;
            using (var db = new EfDataContext(con.ConnectionString))
            {
                db.Database.Migrate();
            }

            var con1 = getCon();

            con1.Mode = SqliteOpenMode.ReadOnly;
            using (var db1 = new EfDataContext(con1.ConnectionString))
            {
                // db1.Database.BeginTransaction();
                var dogs = db1.Dogs.ToList();

                var con2 = getCon();
                con2.Mode = SqliteOpenMode.ReadWrite;

                using (var db2 = new EfDataContext(con2.ConnectionString))
                {
                    db2.Database.BeginTransaction();
                    var dog1 = new Dog {
                        Name = "Minus"
                    };
                    db2.Dogs.Add(dog1);
                    db2.SaveChanges();
                    db2.Database.CommitTransaction();
                }
            }
        }
コード例 #12
0
        public ServiceFeedback AddBlog(Blog model)
        {
            using (var context = new EfDataContext())
            {
                if (model.ID == new Guid())
                {
                    model.ID = Guid.NewGuid();
                }
                if (model.CreationDate == new DateTime())
                {
                    model.CreationDate = DateTime.Now;
                }
                context.Blogs.Add(model);
                context.SaveChanges();
            }

            return(new ServiceFeedback
            {
                Message = "Success",
                Status = 200
            });
        }
コード例 #13
0
        private void CreateArticle(string articleFile, StreamWriter writer)
        {
            string articleInfo = File.ReadAllText(articleFile, Encoding.GetEncoding(1251));
            var    article     = new Article();

            article.Title = GetInfoField(articleInfo, "title");
            writer.WriteLine("Title: {0}", article.Title);
            article.Text   = GetInfoField(articleInfo, "description");
            article.Source = GetInfoField(articleInfo, "source");
            var authors = GetInfoField(articleInfo, "users").Split(',');

            article.Authors = new List <User>();
            foreach (var author in authors)
            {
                article.Authors.Add(new User {
                    Email = author.TrimEnd('\r')
                });
            }
            var disciplineIds = GetDisciplines(GetInfoField(articleInfo, "disciplines").Split(','));

            article.Disciplines = new List <Discipline>();
            foreach (var disciplineId in disciplineIds)
            {
                article.Disciplines.Add(new Discipline()
                {
                    Id = disciplineId
                });
            }
            using (var dataContext = new EfDataContext())
            {
                var publicationService = new PublicationService(dataContext);
                publicationService.Publish(article);
                var notificationService = new NotificationService(dataContext);
                notificationService.NotifyAboutNewArticle(article);
            }
            AddComments(article, articleInfo);
        }
コード例 #14
0
ファイル: HomeController.cs プロジェクト: enesbburgaz/e-yama
 public HomeController(EfDataContext context)
 {
     _context = context;
 }
コード例 #15
0
 public ShippersRepository(EfDataContext context)
 {
     _efDataContext = context ?? throw new ArgumentNullException(nameof(context));
     DbSet          = _efDataContext.Shippers;
 }
コード例 #16
0
 public AnexoRepositorio(EfDataContext efContext)
 {
     _googleDriveUtil = new GoogleDriveUtil();
     _efContext       = efContext;
 }
コード例 #17
0
 public LancamentoRepositorio(EfDataContext efContext)
 {
     _efContext = efContext;
 }
コード例 #18
0
 public List <Blog> GetBlogs()
 {
     using var context = new EfDataContext();
     return(context.Blogs.Select(row => row).OrderBy(e => e.CreationDate).ToList());
 }
コード例 #19
0
 public UsuarioRepositorio(EfDataContext efContext)
 {
     _efContext = efContext;
 }
コード例 #20
0
 public CategoriaRepositorio(EfDataContext efContext)
 {
     _efContext = efContext;
 }
コード例 #21
0
 public CityRepository(EfDataContext context) : base(context)
 {
     _context = context;
 }
コード例 #22
0
ファイル: EfProvider.cs プロジェクト: jrgcubano/zetbox
        protected override void Load(ContainerBuilder moduleBuilder)
        {
            base.Load(moduleBuilder);

            // As we are using the concrete Assembly baseDir in our connection string, this should not be needed anymore
            //var serverAssembly = Assembly.Load(ServerAssembly);
            //if (serverAssembly == null)
            //    throw new InvalidOperationException("Unable to load Zetbox.Objects.EfImpl Assembly, no Entity Framework Metadata will be loaded");

            //// force-load a few assemblies to the reflection-only context so the DAL provider can find them
            //// this uses the AssemblyLoader directly because Assembly.ReflectionOnlyLoad doesn't go through all
            //// the moves of resolving AssemblyNames to files. See http://stackoverflow.com/questions/570117/
            //var reflectedInterfaceAssembly = AssemblyLoader.ReflectionOnlyLoadFrom(Zetbox.API.Helper.InterfaceAssembly);
            //if (reflectedInterfaceAssembly == null)
            //    throw new InvalidOperationException("Unable to load Zetbox.Objects Assembly for reflection, no Entity Framework Metadata will be loaded");
            //var reflectedServerAssembly = AssemblyLoader.ReflectionOnlyLoadFrom(EfProvider.ServerAssembly);
            //if (reflectedServerAssembly == null)
            //    throw new InvalidOperationException("Unable to load Zetbox.Objects.EfImpl Assembly for reflection, no Entity Framework Metadata will be loaded");

            moduleBuilder
                .Register(c =>
                {
                    // EF's meta data initialization is not thread-safe
                    lock (_lock)
                    {
                        return new EfDataContext(
                            c.Resolve<IMetaDataResolver>(),
                            null,
                            c.Resolve<ZetboxConfig>(),
                            c.Resolve<Func<IFrozenContext>>(),
                            c.Resolve<InterfaceType.Factory>(),
                            c.Resolve<EfImplementationType.EfFactory>(),
                            c.Resolve<IPerfCounter>()
                            );
                    }
                })
                .As<IZetboxServerContext>()
                .OnActivated(args =>
                {
                    var manager = args.Context.Resolve<IEfActionsManager>();
                    manager.Init(args.Context.Resolve<IFrozenContext>());
                })
                .InstancePerDependency();

            moduleBuilder
                .Register((c, p) =>
                {
                    // EF's meta data initialization is not thread-safe
                    lock (_lock)
                    {
                        var param = p.OfType<ConstantParameter>().FirstOrDefault();
                        return new EfDataContext(
                            c.Resolve<IMetaDataResolver>(),
                            param != null ? (Zetbox.App.Base.Identity)param.Value : c.Resolve<IIdentityResolver>().GetCurrent(),
                            c.Resolve<ZetboxConfig>(),
                            c.Resolve<Func<IFrozenContext>>(),
                            c.Resolve<InterfaceType.Factory>(),
                            c.Resolve<EfImplementationType.EfFactory>(),
                            c.Resolve<IPerfCounter>()
                            );
                    }
                })
                .As<IZetboxContext>()
                .OnActivated(args =>
                {
                    var manager = args.Context.Resolve<IEfActionsManager>();
                    manager.Init(args.Context.Resolve<IFrozenContext>());
                })
                .InstancePerDependency();

            moduleBuilder
                .Register(c =>
                {
                    // EF's meta data initialization is not thread-safe
                    lock (_lock)
                    {
                        var result = new EfDataContext(
                            c.Resolve<CachingMetaDataResolver>(),
                            null,
                            c.Resolve<ZetboxConfig>(),
                            c.Resolve<Func<IFrozenContext>>(),
                            c.Resolve<InterfaceType.Factory>(),
                            c.Resolve<EfImplementationType.EfFactory>(),
                            c.Resolve<IPerfCounter>()
                            );
                        return result;
                    }
                })
                .As<IReadOnlyZetboxContext>()
                .OnActivated(args =>
                {
                    var manager = args.Context.Resolve<IEfActionsManager>();
                    manager.Init(args.Context.Resolve<IFrozenContext>());
                })
                .InstancePerDependency();

            moduleBuilder
                .Register(c => new EfServerObjectHandlerFactory())
                .As(typeof(IServerObjectHandlerFactory));

            moduleBuilder.RegisterType<EfImplementationType>();
        }
コード例 #23
0
 public PessoaRepositorio(EfDataContext efContext)
 {
     _efContext = efContext;
 }
コード例 #24
0
 public List <BlogEntry> GetBlogEntriesSortAsc()
 {
     using var context = new EfDataContext();
     return(context.BlogEntries.Select(row => row).OrderBy(e => e.EntryDate).ToList());
 }
コード例 #25
0
 public List <User> GetAllUsers()
 {
     using var context = new EfDataContext();
     return(context.Users.Select(row => row).ToList());
 }
コード例 #26
0
ファイル: PeriodoRepositorio.cs プロジェクト: wbuback/bufunfa
 public PeriodoRepositorio(EfDataContext efContext)
 {
     _efContext = efContext;
 }
コード例 #27
0
ファイル: EfProvider.cs プロジェクト: daszat/zetbox
        protected override void Load(ContainerBuilder moduleBuilder)
        {
            base.Load(moduleBuilder);

            moduleBuilder
                .Register(c =>
                {
                    // EF's meta data initialization is not thread-safe
                    lock (_lock)
                    {
                        var cfg = c.Resolve<ZetboxConfig>();
                        return new EfDataContext(
                            c.Resolve<IMetaDataResolver>(),
                            null,
                            cfg,
                            c.Resolve<Func<IFrozenContext>>(),
                            c.Resolve<InterfaceType.Factory>(),
                            c.Resolve<EfImplementationType.EfFactory>(),
                            c.Resolve<IPerfCounter>(),
                            c.ResolveNamed<ISqlErrorTranslator>(cfg.Server.GetConnectionString(Zetbox.API.Helper.ZetboxConnectionStringKey).SchemaProvider),
                            c.Resolve<IEnumerable<IZetboxContextEventListener>>()
                            );
                    }
                })
                .As<IZetboxServerContext>()
                .OnActivated(args =>
                {
                    var manager = args.Context.Resolve<IEfActionsManager>();
                    manager.Init(args.Context.Resolve<IFrozenContext>());
                })
                .InstancePerDependency();

            moduleBuilder
                .Register((c, p) =>
                {
                    // EF's meta data initialization is not thread-safe
                    lock (_lock)
                    {
                        var param = p.OfType<ConstantParameter>().FirstOrDefault();
                        var cfg = c.Resolve<ZetboxConfig>();
                        return new EfDataContext(
                            c.Resolve<IMetaDataResolver>(),
                            param != null ? (ZetboxPrincipal)param.Value : c.Resolve<IPrincipalResolver>().GetCurrent(),
                            cfg,
                            c.Resolve<Func<IFrozenContext>>(),
                            c.Resolve<InterfaceType.Factory>(),
                            c.Resolve<EfImplementationType.EfFactory>(),
                            c.Resolve<IPerfCounter>(),
                            c.ResolveNamed<ISqlErrorTranslator>(cfg.Server.GetConnectionString(Zetbox.API.Helper.ZetboxConnectionStringKey).SchemaProvider),
                            c.Resolve<IEnumerable<IZetboxContextEventListener>>()
                            );
                    }
                })
                .As<IZetboxContext>()
                .OnActivated(args =>
                {
                    var manager = args.Context.Resolve<IEfActionsManager>();
                    manager.Init(args.Context.Resolve<IFrozenContext>());

                    ZetboxContextEventListenerHelper.OnCreated(args.Context.Resolve<IEnumerable<IZetboxContextEventListener>>(), args.Instance);
                })
                .InstancePerDependency();

            moduleBuilder
                .Register(c =>
                {
                    // EF's meta data initialization is not thread-safe
                    lock (_lock)
                    {
                        var cfg = c.Resolve<ZetboxConfig>();
                        var result = new EfDataContext(
                            c.Resolve<CachingMetaDataResolver>(),
                            null,
                            cfg,
                            c.Resolve<Func<IFrozenContext>>(),
                            c.Resolve<InterfaceType.Factory>(),
                            c.Resolve<EfImplementationType.EfFactory>(),
                            c.Resolve<IPerfCounter>(),
                            c.ResolveNamed<ISqlErrorTranslator>(cfg.Server.GetConnectionString(Zetbox.API.Helper.ZetboxConnectionStringKey).SchemaProvider),
                            c.Resolve<IEnumerable<IZetboxContextEventListener>>()
                            );
                        return result;
                    }
                })
                .As<IReadOnlyZetboxContext>()
                .OnActivated(args =>
                {
                    var manager = args.Context.Resolve<IEfActionsManager>();
                    manager.Init(args.Context.Resolve<IFrozenContext>());

                    ZetboxContextEventListenerHelper.OnCreated(args.Context.Resolve<IEnumerable<IZetboxContextEventListener>>(), args.Instance);
                })
                .InstancePerDependency();

            moduleBuilder
                .Register(c => new EfServerObjectHandlerFactory(c.ResolveOptional<Zetbox.API.Server.Fulltext.LuceneSearchDeps>()))
                .As<IServerObjectHandlerFactory>();

            moduleBuilder.RegisterType<EfImplementationType>();

            moduleBuilder.RegisterModule((Autofac.Module)Activator.CreateInstance(Type.GetType("Zetbox.Objects.EfModule, Zetbox.Objects.EfImpl", true)));
        }
コード例 #28
0
 public BaseRepository(EfDataContext Db)
 {
     _Db = Db;
 }
コード例 #29
0
 public ProductController(EfDataContext context)
 {
     _context = context;
 }
コード例 #30
0
 public CategoryViewComponent(EfDataContext context)
 {
     _context = context;
 }
コード例 #31
0
 public AgendamentoRepositorio(EfDataContext efContext)
 {
     _efContext = efContext;
 }
コード例 #32
0
ファイル: Users.cs プロジェクト: vonwenm/blazor.jwttest
 public Users(EfDataContext db) : base(db)
 {
 }