public override void EnterXppclass([NotNull] XP.XppclassContext context) { ClassEntities.Push(CreateClassEntities()); var info = AddClassInfo(context.Id.GetText()); info.Entity = context; _currentClass = info; }
public SelectClassFromAssembliesView(ClassEntities classEntities, String sourceCommandName, String xamlFileClassName) { if (classEntities == null) { throw new ArgumentNullException(nameof(classEntities)); } if (sourceCommandName == null) { throw new ArgumentNullException(nameof(sourceCommandName)); } var classEntitiesCollectionView = CollectionViewSource.GetDefaultView(classEntities) as CollectionView; if (classEntitiesCollectionView == null) { throw new NullReferenceException(); } // ReSharper disable PossibleNullReferenceException classEntitiesCollectionView.GroupDescriptions.Clear(); // ReSharper restore PossibleNullReferenceException classEntitiesCollectionView.SortDescriptions.Clear(); classEntitiesCollectionView.GroupDescriptions.Add(new PropertyGroupDescription("AssemblyName")); classEntitiesCollectionView.GroupDescriptions.Add(new PropertyGroupDescription("NamespaceName")); classEntitiesCollectionView.SortDescriptions.Add(new SortDescription("AssemblyName", ListSortDirection.Ascending)); classEntitiesCollectionView.SortDescriptions.Add(new SortDescription("NamespaceName", ListSortDirection.Ascending)); classEntitiesCollectionView.SortDescriptions.Add(new SortDescription("ClassName", ListSortDirection.Ascending)); InitializeComponent(); this.tvObjects.ItemsSource = classEntitiesCollectionView.Groups; this.tbCommandCaption.Text = String.Concat("For ", sourceCommandName); this.tvObjects.SelectedItemChanged += tvObjects_SelectedItemChanged; this.lbViewModels.SelectionChanged += LbViewModels_SelectionChanged; this.lbViewModels.ItemsSource = classEntities.Where(x => x.ClassName.ToLower().EndsWith("viewmodel")).OrderBy(x => x.ClassName).ToList(); foreach (ClassEntity item in this.lbViewModels.Items) { if (item.ClassName.StartsWith(xamlFileClassName)) { this.lbViewModels.SelectedItem = item; break; } } }
public void OnAuthorization(AuthorizationContext filterContext) { if (filterContext.HttpContext.Session != null) { var user = filterContext.HttpContext.Session["user"]?.ToString(); if (!string.IsNullOrWhiteSpace(user)) { return; } var cookie = filterContext.HttpContext.Request.Cookies?["user"]; if (!string.IsNullOrEmpty(cookie?.Value)) { throw new UnauthorizedException(); } var content = cookie?.Value.DecryptQueryString(); ClassEntities db = new ClassEntities(); if (!db.Users.Any(u => u.Account == content)) { throw new UnauthorizedException(); } } }
static DatabaseAccessor() { entities = new ClassEntities(); entities.Database.Connection.Open(); }
void ReflectClasses(AssemblyDefinition asy, ProjectType projectFrameworkType, String projectFrameworkVersion, ClassEntities classEntities, ActiveProject activeProject) { if (asy == null) { throw new ArgumentNullException(nameof(asy)); } if (classEntities == null) { throw new ArgumentNullException(nameof(classEntities)); } if (!Enum.IsDefined(typeof(ProjectType), projectFrameworkType)) { throw new InvalidEnumArgumentException(nameof(projectFrameworkType), (int)projectFrameworkType, typeof(ProjectType)); } if (string.IsNullOrWhiteSpace(projectFrameworkVersion)) { throw new ArgumentException("Value cannot be null or white space.", nameof(projectFrameworkVersion)); } if (!Enum.IsDefined(typeof(ActiveProject), activeProject)) { throw new InvalidEnumArgumentException(nameof(activeProject), (int)activeProject, typeof(ActiveProject)); } foreach (TypeDefinition type in asy.MainModule.GetTypes()) { if ((type.IsPublic || (activeProject == ActiveProject.Yes && type.IsNotPublic && !type.IsNestedPrivate)) && type.IsClass && !type.IsAbstract && !type.Name.StartsWith("<") && !type.Name.Contains("AnonymousType") && type.Name != "AssemblyInfo" && !type.Name.StartsWith("__")) { var previouslyLoaded = false; foreach (var classEntity in classEntities) { if (type.Name == classEntity.ClassName && type.Namespace == classEntity.NamespaceName && asy.Name.Name == classEntity.AssemblyName) { previouslyLoaded = true; break; } } if (!previouslyLoaded) { if (type.BaseType == null || type.BaseType.Name != "MulticastDelegate") { classEntities.Add(new ClassEntity(asy, type, projectFrameworkType, projectFrameworkVersion)); } } } } }
public TypeReflectorResult SelectClassFromAllReferencedAssemblies(Project sourceProject, String xamlFileClassName, String sourceCommandName, ProjectType projectFrameworkType, String projectFrameworkVersion) { if (sourceProject == null) { throw new ArgumentNullException(nameof(sourceProject)); } if (string.IsNullOrWhiteSpace(sourceCommandName)) { throw new ArgumentException("Value cannot be null or white space.", nameof(sourceCommandName)); } if (!Enum.IsDefined(typeof(ProjectType), projectFrameworkType)) { throw new InvalidEnumArgumentException(nameof(projectFrameworkType), (int)projectFrameworkType, typeof(ProjectType)); } if (projectFrameworkType == ProjectType.Silverlight) { SetSilverlightInstallPath(); } var assemblyPath = AssemblyAssistant.GetAssemblyPath(sourceProject); if (String.IsNullOrWhiteSpace(assemblyPath)) { DialogAssistant.ShowInformationMessage("The project associated with the selected file is either not vb, cs or is blacklisted.", "Invalid Project"); return(null); } if (!File.Exists(assemblyPath)) { DialogAssistant.ShowInformationMessage("Project assembly is missing, please 'build' your solution.", "Unbuilt Project"); return(null); } var resolver = new DefaultAssemblyResolver(); resolver.AddSearchDirectory(Path.GetDirectoryName(assemblyPath)); if (projectFrameworkType == ProjectType.Silverlight) { resolver.AddSearchDirectory(_silverlightAssembliesPath); } var reader = new ReaderParameters { AssemblyResolver = resolver }; var classEntities = new ClassEntities(); var sourceProjectPath = Path.GetDirectoryName(assemblyPath); var sourceAssemblyDefinition = AssemblyDefinition.ReadAssembly(assemblyPath, reader); var assembliesToLoad = new Hashtable(); //load up all referenced assemblies for above assemblyPath foreach (AssemblyNameReference assemblyReference in sourceAssemblyDefinition.MainModule.AssemblyReferences) { if (!AssemblyAssistant.SkipLoadingAssembly(assemblyReference.Name)) { var assemblyFullPath = GetAssemblyFullPath(sourceProjectPath, assemblyReference.Name); if (!String.IsNullOrWhiteSpace(assemblyFullPath) && !assembliesToLoad.ContainsKey(assemblyFullPath.ToLower(CultureInfo.InvariantCulture))) { assembliesToLoad.Add(assemblyFullPath.ToLower(CultureInfo.InvariantCulture), String.Empty); } } } //load up all assemblies referenced in the project but that are not loaded yet. foreach (var projectReference in GetProjectReferences(sourceProject)) { if (!assembliesToLoad.ContainsKey(projectReference)) { assembliesToLoad.Add(projectReference.ToLower(), String.Empty); } } ReflectClasses(sourceAssemblyDefinition, projectFrameworkType, projectFrameworkVersion, classEntities, ActiveProject.Yes); foreach (var asyPath in assembliesToLoad.Keys) { var asyResolver = new DefaultAssemblyResolver(); asyResolver.AddSearchDirectory(Path.GetDirectoryName(assemblyPath)); if (projectFrameworkType == ProjectType.Silverlight) { resolver.AddSearchDirectory(_silverlightAssembliesPath); } var asyReader = new ReaderParameters { AssemblyResolver = asyResolver }; ReflectClasses(AssemblyDefinition.ReadAssembly(asyPath.ToString(), asyReader), projectFrameworkType, projectFrameworkVersion, classEntities, ActiveProject.No); } var listOfConverters = new List <String>(); listOfConverters.AddRange(classEntities.Where(x => x.ClassName.ToLower().EndsWith("converter")).Select(n => n.ClassName).ToList()); var view = new SelectClassFromAssembliesView(classEntities, sourceCommandName, xamlFileClassName); var result = view.ShowDialog(); if (result.HasValue && result.Value && view.SelectedClassEntity != null) { LoadPropertyInformation(view.SelectedClassEntity.TypeDefinition, view.SelectedClassEntity, assembliesToLoad, projectFrameworkType); return(new TypeReflectorResult(view.SelectedClassEntity, listOfConverters)); } return(null); }
public override void ExitFoxclass([NotNull] XP.FoxclassContext context) { var fieldNames = new List <String>(); var members = _pool.Allocate <MemberDeclarationSyntax>(); var generated = ClassEntities.Pop(); var mods = context.Modifiers?.GetList <SyntaxToken>() ?? TokenListWithDefaultVisibility(); context.Data.Partial = mods.Any((int)SyntaxKind.PartialKeyword); var baseTypes = _pool.AllocateSeparated <BaseTypeSyntax>(); var baseType = context.BaseType?.Get <TypeSyntax>(); if (baseType != null) { baseTypes.Add(_syntaxFactory.SimpleBaseType(baseType)); } if (generated.Members.Count > 0) { members.AddRange(generated.Members); } if (generated.VoProperties != null) { foreach (var vop in generated.VoProperties.Values) { var prop = GenerateVoProperty(vop, context); if (prop != null) { members.Add(prop); } } } // Collect list of FieldNames from clsvarscontext to prevent generating properties twice foreach (var mCtx in context._Members) { if (mCtx is XP.FoxclsvarsContext fcfc) { var mem = fcfc.Member; foreach (var v in mem._Vars) { fieldNames.Add(v.GetText().ToLower()); } var list = mem.CsNode as List <MemberDeclarationSyntax>; if (list != null) { foreach (var m1 in list) { members.Add(m1); } } } } // Do this after VOProps generation because GenerateVOProperty sets the members // for Access & Assign to NULL ConstructorDeclarationSyntax ctor = null; foreach (var mCtx in context._Members) { if (mCtx is XP.FoxclsvarinitContext cvi) { var fld = cvi.Member.F.Name.GetText(); if (!fieldNames.Contains(fld.ToLower())) { if (mCtx.CsNode != null) { members.Add(mCtx.Get <MemberDeclarationSyntax>()); } } else { // field is declared and initialized. No need to generate a second property or field. } } else if (mCtx is XP.FoximplementsContext fic) { var clause = fic.Member as XP.FoximplementsclauseContext; var type = clause.Type.Get <TypeSyntax>(); if (baseTypes.Count > 0) { baseTypes.AddSeparator(SyntaxFactory.MakeToken(SyntaxKind.CommaToken)); } baseTypes.Add(_syntaxFactory.SimpleBaseType(type)); } else if (mCtx is XP.FoxclsmethodContext cmc) { if (cmc.Member.CsNode is MemberDeclarationSyntax mds) { members.Add(mds); } } else if (mCtx is XP.FoxaddobjectContext fac) { var prop = fac.Get <MemberDeclarationSyntax>(); members.Add(prop); } else { if (mCtx.CsNode is MemberDeclarationSyntax mds) { members.Add(mds); if (mds is ConstructorDeclarationSyntax) { ctor = mds as ConstructorDeclarationSyntax; } } } } generated.Free(); if (ctor != null) { var newlist = members.ToList(); members.Clear(); foreach (var mem in newlist) { if (mem != ctor) { members.Add(mem); } } ctor = createConstructor(context, members, fieldNames, ctor); members.Add(ctor); } else { ctor = createConstructor(context, members, fieldNames, null); members.Add(ctor); } MemberDeclarationSyntax m = _syntaxFactory.ClassDeclaration( attributeLists: context.Attributes?.GetList <AttributeListSyntax>() ?? EmptyList <AttributeListSyntax>(), modifiers: mods, keyword: SyntaxFactory.MakeToken(SyntaxKind.ClassKeyword), identifier: context.Id.Get <SyntaxToken>(), typeParameterList: context.TypeParameters?.Get <TypeParameterListSyntax>(), baseList: _syntaxFactory.BaseList(SyntaxFactory.MakeToken(SyntaxKind.ColonToken), baseTypes), constraintClauses: MakeList <TypeParameterConstraintClauseSyntax>(context._ConstraintsClauses), openBraceToken: SyntaxFactory.MakeToken(SyntaxKind.OpenBraceToken), members: members, closeBraceToken: SyntaxFactory.MakeToken(SyntaxKind.CloseBraceToken), semicolonToken: null); _pool.Free(members); _pool.Free(baseTypes); if (context.Namespace != null) { m = AddNameSpaceToMember(context.Namespace, m); } else { m = (MemberDeclarationSyntax)CheckTypeName(context, "CLASS", m); } context.Put(m); if (context.Data.Partial) { GlobalEntities.NeedsProcessing = true; } }
public override void ExitFoxmethod([NotNull] XP.FoxmethodContext context) { context.SetSequencePoint(context.T.Start, context.end.Stop); var idName = context.Id.Get <SyntaxToken>(); var mods = context.Modifiers?.GetList <SyntaxToken>() ?? DefaultMethodModifiers(false, false, context.TypeParameters != null); var isExtern = mods.Any((int)SyntaxKind.ExternKeyword); var isAbstract = mods.Any((int)SyntaxKind.AbstractKeyword); var hasNoBody = isExtern || isAbstract; var mName = idName.Text; if (mName.EndsWith("_ACCESS", StringComparison.OrdinalIgnoreCase)) { mName = mName.Substring(0, mName.Length - "_ACCESS".Length); } else if (mName.EndsWith("_ASSIGN", StringComparison.OrdinalIgnoreCase)) { mName = mName.Substring(0, mName.Length - "_ASSIGN".Length); } idName = SyntaxFactory.MakeIdentifier(mName); bool isAccessAssign = this.isAccessAssign(context.RealType); var attributes = context.Attributes?.GetList <AttributeListSyntax>() ?? EmptyList <AttributeListSyntax>(); bool hasExtensionAttribute = false; if (isAccessAssign) { var vomods = _pool.Allocate(); vomods.Add(SyntaxFactory.MakeToken(SyntaxKind.PrivateKeyword)); if (mods.Any((int)SyntaxKind.StaticKeyword)) { vomods.Add(SyntaxFactory.MakeToken(SyntaxKind.StaticKeyword)); } if (mods.Any((int)SyntaxKind.UnsafeKeyword)) { vomods.Add(SyntaxFactory.MakeToken(SyntaxKind.UnsafeKeyword)); } mods = vomods.ToList <SyntaxToken>(); _pool.Free(vomods); } if (!isExtern) { isExtern = hasDllImport(attributes); hasNoBody = hasNoBody || isExtern; } if (isExtern && !mods.Any((int)SyntaxKind.ExternKeyword)) { // Add Extern Keyword to modifiers var m1 = _pool.Allocate(); m1.AddRange(mods); if (!m1.Any((int)SyntaxKind.ExternKeyword)) { m1.Add(SyntaxFactory.MakeToken(SyntaxKind.ExternKeyword)); } mods = m1.ToList <SyntaxToken>(); _pool.Free(m1); } var parameters = context.ParamList?.Get <ParameterListSyntax>() ?? EmptyParameterList(); var body = hasNoBody ? null : context.StmtBlk.Get <BlockSyntax>(); var returntype = context.Type?.Get <TypeSyntax>(); if (returntype == null) { if (context.RealType == XP.ASSIGN) { returntype = VoidType(); } else // method and access { returntype = _getMissingType(); returntype.XNode = context; } } else { returntype.XVoDecl = true; } var oldbody = body; ImplementClipperAndPSZ(context, ref attributes, ref parameters, ref body, ref returntype); if (body != oldbody) { context.StmtBlk.Put(body); } if (context.RealType == XP.ASSIGN) { // Assign does not need a return. // So do not add missing returns returntype = VoidType(); } else if (context.StmtBlk != null && !hasNoBody) { body = AddMissingReturnStatement(body, context.StmtBlk, returntype); } MemberDeclarationSyntax m = _syntaxFactory.MethodDeclaration( attributeLists: attributes, modifiers: mods, returnType: returntype, explicitInterfaceSpecifier: null, identifier: idName, typeParameterList: context.TypeParameters?.Get <TypeParameterListSyntax>(), parameterList: parameters, constraintClauses: MakeList <TypeParameterConstraintClauseSyntax>(context._ConstraintsClauses), body: body, expressionBody: null, // TODO: (grammar) expressionBody methods semicolonToken: (!hasNoBody && context.StmtBlk != null) ? null : SyntaxFactory.MakeToken(SyntaxKind.SemicolonToken)); if (hasExtensionAttribute) { m = m.WithAdditionalDiagnostics(new SyntaxDiagnosticInfo(ErrorCode.ERR_ExplicitExtension)); } bool separateMethod = false; context.Put(m); if (isAccessAssign && !separateMethod) { if (context.Data.HasClipperCallingConvention && context.CallingConvention != null) { m = m.WithAdditionalDiagnostics(new SyntaxDiagnosticInfo( ErrorCode.ERR_NoClipperCallingConventionForAccessAssign)); } context.Put(m); ClassEntities.Peek().AddVoPropertyAccessor(context, context.RealType, idName); } }
public override void EnterFoxclass([NotNull] XP.FoxclassContext context) { ClassEntities.Push(CreateClassEntities()); }
public override void ExitXppclassvars([NotNull] XP.XppclassvarsContext context) { // add class vars to current class // use the current visibility saved with declMethodVis // IS and IN are not supported, so produce warning // include [SHARED], [READONLY] [ASSIGNMENT HIDDEN | PROTECTED | EXPORTED] and [NOSAVE] modifiers // on top of the visibility modifier // The [Readonly] clause and [Assignment] clause are not supported yet // In as future build we will create a private backing Ivar and // Create a property with Getter and Setter with property visibility // to emulate the possible combinations of [ReadOnly] and Assignment and Visibility // The following table lists what should be done // ========================================================================. // | Visibility | // Assignment | Hidden | Protected | Exported | // ========================================================================. // Hidden | pri Get/pri Set | pro Get pri Set | pub Get pri Set | // Protected | | pro Get pro Set | pub Get pro Set | // Exported | - | | pub Get pub Set | // ========================================================================. // // The Readonly clause does something similar as the ASSIGNMENT. // For the following visibilities this results in: // Private Readonly is useless // Protected Readonly creates a Protected Getter and a hidden/Private Setter // Exported/Public ReadOnly creates a Public Getter and a Protected Setter // var varList = _pool.AllocateSeparated <VariableDeclaratorSyntax>(); // Check to see if the variables have not been also declared as property // when they are we do not generate variables var varType = context.DataType?.Get <TypeSyntax>() ?? _getMissingType(); varType.XVoDecl = true; var fieldList = new List <FieldDeclarationSyntax>(); var attributeLists = _pool.Allocate <AttributeListSyntax>(); if (context.Nosave != null) { GenerateAttributeList(attributeLists, SystemQualifiedNames.NonSerialized); } foreach (var id in context._Vars) { varList.Clear(); var name = id.GetText(); var variable = GenerateVariable(id.Get <SyntaxToken>()); varList.Add(variable); // calculate modifiers // each field is added separately so we can later decide which field to keep and which one to delete when they are duplicated by a var modifiers = decodeXppMemberModifiers(context.Visibility, false, context.Modifiers?._Tokens); if (varList.Count > 0) { var decl = _syntaxFactory.VariableDeclaration( type: varType, variables: varList); var fdecl = _syntaxFactory.FieldDeclaration( attributeLists: attributeLists, modifiers: modifiers, declaration: decl, semicolonToken: SyntaxFactory.MakeToken(SyntaxKind.SemicolonToken)); ClassEntities.Peek().Members.Add(fdecl); fieldList.Add(fdecl); } } context.PutList(MakeList <FieldDeclarationSyntax>(fieldList)); _pool.Free(varList); _pool.Free(attributeLists); }
public override void ExitXppclass([NotNull] XP.XppclassContext context) { context.SetSequencePoint(context.C, context.e.Stop); var members = _pool.Allocate <MemberDeclarationSyntax>(); var generated = ClassEntities.Pop(); var mods = context.Modifiers?.GetList <SyntaxToken>() ?? TokenListWithDefaultVisibility(); XP.DatatypeContext basetype = null; if (generated.Members.Count > 0) // inline methods, properties and fields { members.AddRange(generated.Members); } if (context.Modifiers != null) { if (context.Modifiers._Tokens.Any(t => t.Type == XP.STATIC)) { context.Data.HasStatic = true; } } // check if all declared methods have been implemented // and if so, then add the methods to the members list string className = context.Id.GetText(); if (context._BaseTypes.Count == 1) { basetype = context._BaseTypes[0]; } XppClassInfo thisClass = FindClassInfo(className); if (thisClass == null || thisClass.Entity != context) { context.AddError(new ParseErrorData(context, ErrorCode.ERR_ParserError, "Could not locate ClassInfo for class " + className)); return; } generated.Free(); var baseTypes = _pool.AllocateSeparated <BaseTypeSyntax>(); var baseType = basetype.Get <TypeSyntax>(); if (baseType != null) { baseTypes.Add(_syntaxFactory.SimpleBaseType(baseType)); } foreach (var iCtx in context._Implements) { if (baseTypes.Count > 0) { baseTypes.AddSeparator(SyntaxFactory.MakeToken(SyntaxKind.CommaToken)); } baseTypes.Add(_syntaxFactory.SimpleBaseType(iCtx.Get <TypeSyntax>())); } MemberDeclarationSyntax m = _syntaxFactory.ClassDeclaration( attributeLists: context.Attributes?.GetList <AttributeListSyntax>() ?? EmptyList <AttributeListSyntax>(), modifiers: mods, keyword: SyntaxFactory.MakeToken(SyntaxKind.ClassKeyword), identifier: context.Id.Get <SyntaxToken>(), typeParameterList: null, baseList: _syntaxFactory.BaseList(SyntaxFactory.MakeToken(SyntaxKind.ColonToken), baseTypes), constraintClauses: null, openBraceToken: SyntaxFactory.MakeToken(SyntaxKind.OpenBraceToken), members: members, closeBraceToken: SyntaxFactory.MakeToken(SyntaxKind.CloseBraceToken), semicolonToken: null); _pool.Free(members); _pool.Free(baseTypes); context.Put(m); _currentClass = null; }