public void IntegrationTest() { var referenceMixinContext1 = MixinContextObjectMother.Create(mixinType: typeof(BT1Mixin1)); var referenceMixinContext2 = MixinContextObjectMother.Create(mixinType: typeof(BT1Mixin2)); var referenceClassContext = new ClassContext(typeof(BaseType1), new[] { referenceMixinContext1, referenceMixinContext2 }, new[] { typeof(DateTime) }); var serializer = new CodeGenerationClassContextSerializer(); referenceClassContext.Serialize(serializer); var expression = serializer.GetConstructorInvocationExpression(); var compiledExpression = Expression.Lambda <Func <ClassContext> > (expression).Compile(); var result = compiledExpression(); Assert.That(result, Is.EqualTo(referenceClassContext)); }
static void Main(string[] args) { using (var db = new ClassContext()) { ///db.Add(new Instructor { InstructorId = "A00948735", Name = "Phil Weier" }); // db.SaveChanges(); // Console.Read(); foreach (Instructor instructor in db.Instructors) { Console.WriteLine(instructor.InstructorId + ": " + instructor.Name); } Console.ReadLine(); } }
public void ClassContextInheritance_BaseAndTypeDefinition_FromSameConfiguration() { MixinConfiguration configuration = new MixinConfigurationBuilder(null) .ForClass <DerivedGenericTargetClass <int> > ().AddMixin(typeof(NullMixin4)) .ForClass(typeof(DerivedGenericTargetClass <>)).AddMixin(typeof(NullMixin)) .ForClass(typeof(GenericTargetClass <int>)).AddMixin(typeof(NullMixin2)) .ForClass(typeof(GenericTargetClass <int>)).AddMixin(typeof(NullMixin3)) .BuildConfiguration(); ClassContext derivedContext = configuration.GetContext(typeof(DerivedGenericTargetClass <int>)); Assert.That(derivedContext.Mixins.Count, Is.EqualTo(4)); Assert.That(derivedContext.Mixins.ContainsKey(typeof(NullMixin)), Is.True); Assert.That(derivedContext.Mixins.ContainsKey(typeof(NullMixin2)), Is.True); Assert.That(derivedContext.Mixins.ContainsKey(typeof(NullMixin3)), Is.True); Assert.That(derivedContext.Mixins.ContainsKey(typeof(NullMixin4)), Is.True); }
public void Add(ClassName classname) { //设置上下文生存期 using (var db = new ClassContext()) { //向上下文Class数据集添加一个实体(改变实体状态为添加) db.ClassNames.Add(classname); //或者将实体状态为添加 //db.Entry(classname).State = EntityState.Added; //保存状态改变 db.SaveChanges(); } }
public ClassContext @class() { ClassContext _localctx = new ClassContext(Context, State); EnterRule(_localctx, 2, RULE_class); int _la; try { EnterOuterAlt(_localctx, 1); { State = 27; Match(CLASS); State = 28; Match(TYPE); State = 31; ErrorHandler.Sync(this); _la = TokenStream.LA(1); if (_la==INHERITS) { { State = 29; Match(INHERITS); State = 30; Match(TYPE); } } State = 33; Match(T__1); State = 39; ErrorHandler.Sync(this); _la = TokenStream.LA(1); while (_la==ID) { { { State = 34; feature(); State = 35; Match(T__0); } } State = 41; ErrorHandler.Sync(this); _la = TokenStream.LA(1); } State = 42; Match(T__2); } } catch (RecognitionException re) { _localctx.exception = re; ErrorHandler.ReportError(this, re); ErrorHandler.Recover(this, re); } finally { ExitRule(); } return _localctx; }
public void GetClassContext_Dependencies() { ClassContext context = new ClassContextBuilder(typeof(int)) .AddMixin(typeof(object)).OfKind(MixinKind.Extending).WithDependencies(typeof(double), typeof(bool)) .AddMixin(typeof(string)).OfKind(MixinKind.Extending).WithDependencies(typeof(bool)) .AddMixin(typeof(int)).OfKind(MixinKind.Extending) .BuildClassContext(); ConcreteMixedTypeAttribute attribute = CreateAttribute(context); ClassContext regeneratedContext = attribute.GetClassContext(); Assert.That(regeneratedContext.Mixins.Count, Is.EqualTo(3)); Assert.That(regeneratedContext.Mixins[typeof(object)].ExplicitDependencies, Is.EqualTo(new object[] { typeof(double), typeof(bool) })); Assert.That(regeneratedContext.Mixins[typeof(string)].ExplicitDependencies, Is.EqualTo(new object[] { typeof(bool) })); Assert.That(regeneratedContext.Mixins[typeof(int)].ExplicitDependencies, Is.Empty); }
public void SetUp() { _configuredClassContext1 = ClassContextObjectMother.Create(typeof(BaseType1), typeof(NullMixin)); _configuredClassContext2 = ClassContextObjectMother.Create(typeof(NullTarget), typeof(NullMixin)); _genericClassContext = ClassContextObjectMother.Create(typeof(GenericTargetClass <>), typeof(NullMixin)); _interfaceClassContext = ClassContextObjectMother.Create(typeof(IBaseType2), typeof(NullMixin)); var classContexts = new ClassContextCollection(_configuredClassContext1, _configuredClassContext2, _genericClassContext, _interfaceClassContext); _configuration = new MixinConfiguration(classContexts); _configuredTypeDiscoveryServiceStub = CreateTypeDiscoveryServiceStub( _configuredClassContext1.Type, _configuredClassContext2.Type, _genericClassContext.Type, _interfaceClassContext.Type); }
//private void getallcustomers() //{ // using (ClassContext ccx = new ClassContext()) // { // List<ClassCustomer> listcustomer = ccx.classCustomer.ToList() as List<ClassCustomer>; // foreach (ClassCustomer classCustomer in listcustomer) // { // listcustomer.Add(classCustomer); // } // } //} public void Makedatabase() { try { using (ClassContext ctx = new ClassContext()) { ctx.Database.CreateIfNotExists(); } } catch (DbEntityValidationException ex) { foreach (var t in ex.EntityValidationErrors) { MessageBox.Show(t.ValidationErrors.First().ErrorMessage); } } }
private List <ClassContext> GetParentClassContexts() { var parentClassContexts = new List <ClassContext> (); ClassContext current = MixinConfiguration; while (current != null && current.Type.BaseType != null) { ClassContext parent = Mixins.MixinConfiguration.ActiveConfiguration.GetContext(current.Type.BaseType); if (parent != null) { parentClassContexts.Add(parent); } current = parent; } parentClassContexts.Reverse(); // first base is first return(parentClassContexts); }
public PersistentMixinFinder(Type type, bool includeInherited) { ArgumentUtility.CheckNotNull("type", type); Type = type; _includeInherited = includeInherited; _mixinConfiguration = GetMixinConfigurationForDomainObjectType(type); // never null if (Type.BaseType != null) { _parentClassContext = GetMixinConfigurationForDomainObjectType(Type.BaseType); // never null } if (IncludeInherited) { _allParentClassContexts = GetParentClassContexts(); } }
public void BuildContext_Suppression() { var classContextBuilder = new ClassContextBuilder(_parentBuilderMock, typeof(BaseType2)); classContextBuilder.AddMixins <BT1Mixin1, BT1Mixin2> (); classContextBuilder.SuppressMixins(typeof(IBT1Mixin1), typeof(BT5Mixin1), typeof(BT3Mixin3 <,>)); var inheritedContext = ClassContextObjectMother.Create(typeof(BaseType2), typeof(BT3Mixin1), typeof(BT3Mixin3 <IBaseType33, IBaseType33>)); var parentContext = ClassContextObjectMother.Create(typeof(BaseType2), typeof(BT5Mixin1), typeof(BT5Mixin2)); ClassContext builtContext = classContextBuilder.BuildClassContext(new[] { inheritedContext, parentContext }); Assert.That(builtContext.Mixins.Count, Is.EqualTo(3)); Assert.That(builtContext.Mixins.ContainsKey(typeof(BT3Mixin1)), Is.True); Assert.That(builtContext.Mixins.ContainsKey(typeof(BT5Mixin2)), Is.True); Assert.That(builtContext.Mixins.ContainsKey(typeof(BT1Mixin2)), Is.True); }
public void CompileName(ClassContext classContext, bool isStatic) { if (TypeToken == null || NameToken == null) { TrueAnalyed = false; return; } IsStatic = isStatic; this.ClassContext = classContext; var symbols = ClassContext.Symbols; TypeName = TypeToken.GetText(); PropertyName = NameToken.GetText(); PropertyGcl = classContext.SearchType(TypeName); if (PropertyGcl != null) { PropertyType = PropertyGcl.ForType; } else { errorf("没有找到类型'{0}'", TypeName); } if (ClassContext.ClassSymbol.PropertyDict.ContainsKey(PropertyName)) { error("属性'" + PropertyName + "'已经存在"); return; } if (PropertyType == null) { error("属性类型'" + TypeName + "'不存在"); return; } PropertySymbol = new SymbolDefProperty(PropertyName, PropertyType, isStatic); symbols.AddSafe(PropertySymbol); ClassContext.ClassSymbol.PropertyDict.Add(PropertyName, PropertySymbol); var classBuilder = ClassContext.EmitContext.CurrentTypeBuilder; GenerateName(classBuilder, IsStatic); AnalyBody(classContext); }
public void AnalyName() { ZPropertyCompiling = new ZCPropertyInfo(); PropertyName = Raw.NameToken.Text; if (ClassContext.ContainsPropertyName(PropertyName))// (ParentProperties.dict.ContainsKey(PropertyName)) { this.ParentProperties.ASTClass.FileContext.Errorf(Raw.NameToken.Position, "'{0}'重复", PropertyName); IsExists = true; } else { //ParentProperties.dict.Add(PropertyName, Raw.NameToken); ZPropertyCompiling.ZPropertyZName = PropertyName; ClassContext.AddMember(ZPropertyCompiling); //AnalyType(); //PropertyItems.Add(name); } }
public void GetWithInheritance_Inheritance_FromBaseType() { ClassContext inherited1 = _collectionWithObjectAndString.GetWithInheritance(typeof(ClassContextCollectionTest)); Assert.That(inherited1, Is.Not.Null); Assert.That(inherited1.Type, Is.EqualTo(typeof(ClassContextCollectionTest))); Assert.That(inherited1.Mixins.ContainsKey(typeof(NullMixin2)), Is.True); ClassContext inherited2 = _collectionWithObjectAndString.GetWithInheritance(typeof(ClassContextCollectionTest)); Assert.That(inherited2, Is.EqualTo(inherited1)); ClassContext inherited3 = _collectionWithObjectAndString.GetWithInheritance(typeof(int)); Assert.That(inherited3, Is.Not.Null); Assert.That(inherited3.Type, Is.EqualTo(typeof(int))); Assert.That(inherited3.Mixins.ContainsKey(typeof(NullMixin2)), Is.True); }
TKTProcDesc searchNewProc(ClassContext classContext, TKTProcDesc expProcDesc) { var procArray = ClassContextHelper.SearchProc(classContext, expProcDesc); if (procArray.Length == 1) { return(procArray[0]); } else if (procArray.Length > 1) { error("找到多个过程,不能确定是属于哪一个简略使用的类型的过程"); } else if (procArray.Length == 0) { //error("没有找到对应的过程'" + this.ToCode() + "'"); } return(null); }
private static void deleteCourseAppRealDisconected() { Course course; //primeiro a busca do que desejo remover using (var context = new ClassContext()) { context.Database.Log = Console.WriteLine; course = context.Course.FirstOrDefault(); } //aqui faz a remoção using (var context = new ClassContext()) { context.Database.Log = Console.WriteLine; context.Entry(course).State = EntityState.Deleted; context.SaveChanges(); } }
/// <summary> /// Builds a class context with the data collected so far for the <see cref="TargetType"/> that inherits from other contexts. /// </summary> /// <param name="inheritedContexts">A collection of <see cref="ClassContext"/> instances the newly built context should inherit mixin data from.</param> /// <returns>A <see cref="ClassContext"/> for the <see cref="TargetType"/> holding all mixin configuration data collected so far.</returns> public virtual ClassContext BuildClassContext(IEnumerable <ClassContext> inheritedContexts) { var mixinContexts = MixinContextBuilders.Select(mixinContextBuilder => mixinContextBuilder.BuildMixinContext()); var classContext = new ClassContext(_targetType, mixinContexts, ComposedInterfaces); classContext = ApplyInheritance(classContext, inheritedContexts); classContext = classContext.SuppressMixins(SuppressedMixins); try { classContext = classContext.ApplyMixinDependencies(_mixinDependencies.Select(kvp => new MixinDependencySpecification(kvp.Key, kvp.Value))); } catch (InvalidOperationException ex) { var message = string.Format("The mixin dependencies configured for type '{0}' could not be processed: {1}", TargetType, ex.Message); throw new ConfigurationException(message, ex); } return(classContext); }
private static void searchCourse() { //primeira coisa na busca sempre logo abrir conexao using (var context = new ClassContext()) { //retornar a tabela curso forma de lista var query = context.Course.ToList(); foreach (var item in query) { Console.WriteLine(item.id); Console.WriteLine(item.Name); Console.WriteLine(item.Author); Console.WriteLine(item.AuthorId); Console.WriteLine(item.Evaluation); Console.WriteLine("\n"); } } }
public void DuplicateTypesAreIgnored() { MixinConfiguration configuration = new DeclarativeConfigurationBuilder(null) .AddType(typeof(BaseType1)) .AddType(typeof(BaseType1)) .AddType(typeof(BT1Mixin1)) .AddType(typeof(BT1Mixin1)) .AddType(typeof(BT1Mixin2)) .AddType(typeof(BT1Mixin2)) .BuildConfiguration(); ClassContext classContext = configuration.GetContext(typeof(BaseType1)); Assert.That(classContext.Mixins.Count, Is.EqualTo(2)); Assert.That(classContext.Mixins.ContainsKey(typeof(BT1Mixin1)), Is.True); Assert.That(classContext.Mixins.ContainsKey(typeof(BT1Mixin2)), Is.True); }
private static void searchCourseFirstList(int idAuthor) { using (var context = new ClassContext()) { var query = context.Course.Where(c => c.AuthorId == idAuthor) .OrderBy(n => n.Name) //ordenação .Skip(2) //para qual posição desejo pegar .Take(1) .FirstOrDefault(); //.ToList(); Console.WriteLine(query.Name); //foreach (var item in query) //{ // Console.WriteLine(item.Name); //} } }
public List <IGcl> searchType(string typeName, ClassContext classContext) { List <IGcl> list = new List <IGcl>(); var refTypes = classContext.ProjectContext.TKTTypes; var libWords = classContext.ProjectContext.LibWords; foreach (var type in refTypes) { if (type.IsPublic && type.Name == typeName) { var gcl = GclUtil.Load(type, getWordDict(libWords, type)); if (gcl != null) { list.Add(gcl); } } } return(list); }
public void ApplyMixinDependencies() { var originalMixinContext1 = MixinContextObjectMother.Create(mixinType: typeof(string), explicitDependencies: new[] { typeof(int) }); var originalMixinContext2 = MixinContextObjectMother.Create(mixinType: typeof(DateTime), explicitDependencies: new[] { typeof(double) }); var originalMixinContext3 = MixinContextObjectMother.Create(mixinType: typeof(object), explicitDependencies: new[] { typeof(decimal) }); var originalClassContext = ClassContextObjectMother.Create(typeof(NullTarget), originalMixinContext1, originalMixinContext2, originalMixinContext3); var dependencies = new[] { new MixinDependencySpecification(typeof(string), new[] { typeof(int), typeof(float), typeof(long) }), new MixinDependencySpecification(typeof(object), new[] { typeof(byte) }), new MixinDependencySpecification(typeof(string), new[] { typeof(Enum) }) }; var result = originalClassContext.ApplyMixinDependencies(dependencies); Assert.That(result, Is.Not.EqualTo(originalClassContext)); var expectedResult = new ClassContext( originalClassContext.Type, new[] { new MixinContext( originalMixinContext1.MixinKind, originalMixinContext1.MixinType, originalMixinContext1.IntroducedMemberVisibility, new[] { typeof(int), typeof(float), typeof(long), typeof(Enum) }, originalMixinContext1.Origin), originalMixinContext2, new MixinContext( originalMixinContext3.MixinKind, originalMixinContext3.MixinType, originalMixinContext3.IntroducedMemberVisibility, new[] { typeof(decimal), typeof(byte) }, originalMixinContext3.Origin) }, originalClassContext.ComposedInterfaces); Assert.That(result, Is.EqualTo(expectedResult)); Assert.That(originalClassContext.Mixins[typeof(string)].ExplicitDependencies, Has.No.Member(typeof(float)), "Original is not changed"); }
public static TKTProcDesc[] SearchSuppleProc(ClassContext context, TKTProcDesc procDesc) { var symbols = context.Symbols; //1.寻找当前CLASS内的PROC var method = context.ClassSymbol.SearchProc(procDesc); if (method != null) { return new TKTProcDesc[] { method } } ; //2.寻找简略使用的PROC var directProcArray = SearchDirectProc(context, procDesc); if (directProcArray.Length > 0) { return(directProcArray); } return(new TKTProcDesc[] { }); }
public static bool CadastrarAdm(AdmModel adm) { using (var ctx = new ClassContext()) { List <AdmModel> admin = ctx.Administrador.Where(p => p.Nome.Equals(adm.Nome, StringComparison.CurrentCultureIgnoreCase) || p.Email.Equals(adm.Email, StringComparison.CurrentCultureIgnoreCase)).ToList(); if (admin.Count == 0) { ctx.Administrador.Add(adm); ctx.SaveChanges(); return(true); } return(false); } //noticia.Add(not); }
//A busca usando o find ajuda na eficiencia do código, pois depois que é achado //na primeira busca que é feito é salvo na memória, aí quando é feito novamente a //segundo busca é procurado primeiramente na memória e se não encontrado é feita a //busca no banco e isso deixamais rápido a aplicação... private static void searchUsingFindCourse() { var keyVal = 2; using (var context = new ClassContext()) { context.Database.Log = Console.WriteLine; //Faz a busca ultilizando o find que é pela a chave, 1º na memoria, 2º Faz no DB var query = context.Course.Find(keyVal); Console.WriteLine(query.Name); //Como essa chave já foi buscada ele já encontra na memória e pega as informações dela var query2 = context.Course.Find(keyVal); Console.WriteLine(query2.Name + "\n\n"); //aqui mesmo já tenha encontrado na memória essa chave, é feito uma busca no DB var query3 = context.Course.Where(c => c.id == keyVal).FirstOrDefault(); Console.WriteLine(query3.Name); } }
public void Analy(ImportContext context, ClassContext classContext, Dictionary <string, PackageModel> importNames) { Symbols = classContext.Symbols; checkAddTKTSystemPackage(); foreach (var item in this.Packages) { var PackageModel = item.Analy(); if (PackageModel != null) { if (importNames.ContainsKey(PackageModel.FullName)) { errorf("'{0}'已经声明使用过", PackageModel.FullName); } else { loadPackage(PackageModel.FullName, classContext); } } } }
public void AlterarContato(ContatoModel con) { using (var ctx = new ClassContext()) { ContatoModel contato = ctx.Contato.Where(n => n.IDContato == con.IDContato).First(); contato.NomeContato = con.NomeContato; contato.EmailContato = con.NomeContato; contato.Mensagem = con.NomeContato; ctx.SaveChanges(); } //noticia.Where(n => n.IDNoticia == not.IDNoticia) // .ToList() // .ForEach(s => // { // s.Titulo = not.Titulo; // s.Descricao = not.Descricao; // }); }
public void BuildContext_SuppressedInheritance() { ClassContext inheritedContext = new ClassContextBuilder(typeof(BaseType2)) .AddMixin(typeof(BT3Mixin1)) .AddComposedInterface(typeof(BT1Mixin2)) .BuildClassContext(); _classBuilder.Clear(); _classBuilder.AddMixins <BT1Mixin1, BT1Mixin2> (); _classBuilder.AddComposedInterfaces <IBT6Mixin1, IBT6Mixin2> (); ClassContext builtContext = _classBuilder.BuildClassContext(new[] { inheritedContext }); Assert.That(builtContext.Mixins.Count, Is.EqualTo(2)); Assert.That(builtContext.Mixins.ContainsKey(typeof(BT1Mixin1)), Is.True); Assert.That(builtContext.Mixins.ContainsKey(typeof(BT1Mixin2)), Is.True); Assert.That(builtContext.ComposedInterfaces.Count, Is.EqualTo(2)); Assert.That(builtContext.ComposedInterfaces, Has.Member(typeof(IBT6Mixin1))); Assert.That(builtContext.ComposedInterfaces, Has.Member(typeof(IBT6Mixin2))); }
public void ClassContextInheritance_WithOverrides_FromSameConfiguration() { MixinConfiguration configuration = new MixinConfigurationBuilder(null) .ForClass(typeof(NullTarget)).AddMixin(typeof(NullMixin)) .ForClass(typeof(GenericTargetClass <>)).AddMixin(typeof(NullMixin)) .ForClass <DerivedNullTarget> ().AddMixin(typeof(DerivedNullMixin)) .ForClass <GenericTargetClass <int> > ().AddMixin(typeof(DerivedNullMixin)) .BuildConfiguration(); ClassContext derivedContext1 = configuration.GetContext(typeof(DerivedNullTarget)); Assert.That(derivedContext1.Mixins.Count, Is.EqualTo(1)); Assert.That(derivedContext1.Mixins.ContainsKey(typeof(DerivedNullMixin)), Is.True); Assert.That(derivedContext1.Mixins.ContainsKey(typeof(NullMixin)), Is.False); ClassContext derivedContext2 = configuration.GetContext(typeof(GenericTargetClass <int>)); Assert.That(derivedContext2.Mixins.Count, Is.EqualTo(1)); Assert.That(derivedContext2.Mixins.ContainsKey(typeof(DerivedNullMixin)), Is.True); Assert.That(derivedContext2.Mixins.ContainsKey(typeof(NullMixin)), Is.False); }
public void AlterarNoticia(NoticiasModel not) { using (var ctx = new ClassContext()) { NoticiasModel noticia = ctx.Noticia.Where(n => n.IDNoticia == not.IDNoticia).First(); noticia.Titulo = not.Titulo; noticia.Descricao = not.Descricao; noticia.Imagem = not.Imagem; noticia.DataNoticia = not.DataNoticia; ctx.SaveChanges(); } //noticia.Where(n => n.IDNoticia == not.IDNoticia) // .ToList() // .ForEach(s => // { // s.Titulo = not.Titulo; // s.Descricao = not.Descricao; // }); }