Ejemplo n.º 1
0
        /// <summary>
        /// main function to collect the connectors from the code.
        /// </summary>
        public static SortedList <string, TypeDeclaration> GetConnectors(string AOutputPath, string AModuleName)
        {
            if (!ConnectorsByModule.ContainsKey(AModuleName))
            {
                // get all csharp files that might hold implementations of remotable classes
                List <CSParser> CSFiles = null;

                if (AOutputPath.Contains("ICT/Petra/Plugins"))
                {
                    // search for connectors in the directory of the plugin
                    CSFiles = CSParser.GetCSFilesForDirectory(Path.GetFullPath(AOutputPath + "/../Server"),
                                                              SearchOption.AllDirectories);
                }
                else if (Directory.Exists(CSParser.ICTPath + "/Petra/Server/lib/M" + AModuleName))
                {
                    // any class in the module can contain a connector
                    CSFiles = CSParser.GetCSFilesForDirectory(CSParser.ICTPath + "/Petra/Server/lib/M" + AModuleName,
                                                              SearchOption.AllDirectories);
                }
                else if (AModuleName == "ServerAdmin")
                {
                    CSFiles = CSParser.GetCSFilesForDirectory(CSParser.ICTPath + "/Petra/Server/app/Core",
                                                              SearchOption.AllDirectories);
                }
                else
                {
                    CSFiles = new List <CSParser>();
                }

                ConnectorsByModule.Add(AModuleName, GetConnectors(CSFiles));
            }

            return(ConnectorsByModule[AModuleName]);
        }
        private static void InsertConstructors(ProcessTemplate template, TypeDeclaration t)
        {
            // foreach constructor create a method
            List <ConstructorDeclaration> constructors = CSParser.GetConstructors(t);

            if (constructors.Count == 0)
            {
                // will cause compile error if the constructor is missing, because it is not implementing the interface completely
                throw new Exception("missing a connector constructor in " + t.Name + "; details: " + t.ToString());
            }

            // find constructor and copy the parameters
            foreach (ConstructorDeclaration m in constructors)
            {
                ProcessTemplate methodSnippet = ClientRemotingClassTemplate.GetSnippet("METHOD");

                methodSnippet.SetCodelet("METHODNAME", t.Name.Substring(1, t.Name.Length - 1 - "UIConnector".Length));
                methodSnippet.SetCodelet("RETURNTYPE", CSParser.GetImplementedInterface(t));

                string ParameterDefinition = string.Empty;
                string ActualParameters    = string.Empty;

                AutoGenerationTools.FormatParameters(m.Parameters, out ActualParameters, out ParameterDefinition);

                methodSnippet.SetCodelet("PARAMETERDEFINITION", ParameterDefinition);
                methodSnippet.SetCodelet("ACTUALPARAMETERS", ActualParameters);
                methodSnippet.SetCodelet("RETURN", "return ");

                template.InsertSnippet("METHODSANDPROPERTIES", methodSnippet);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// return all classes in a given namespace that implement the interface
        /// </summary>
        /// <param name="ACSFiles"></param>
        /// <param name="AInterfaceName"></param>
        /// <param name="ANamespace">namespace name on the server</param>
        /// <returns></returns>
        private List <TypeDeclaration> GetClassesThatImplementInterface(
            List <CSParser> ACSFiles, String AInterfaceName, String ANamespace)
        {
            List <TypeDeclaration> ClassList = new List <TypeDeclaration>();

            // find all classes in that server namespace, eg. Ict.Petra.Server.MPartner.Extracts.UIConnectors
            List <TypeDeclaration> ConnectorClasses = CSParser.GetClassesInNamespace(ACSFiles, ANamespace);

            foreach (TypeDeclaration t in ConnectorClasses)
            {
                if ((t.BaseTypes.Count == 0) && ANamespace.EndsWith("WebConnectors"))
                {
                    ClassList.Add(t);
                    continue;
                }

                foreach (ICSharpCode.NRefactory.Ast.TypeReference ti in t.BaseTypes)
                {
                    if (ti.Type == AInterfaceName)
                    {
                        ClassList.Add(t);
                        break;
                    }
                }
            }

            return(ClassList);
        }
Ejemplo n.º 4
0
        static private void WriteWebConnector(string connectorname, TypeDeclaration connectorClass, ProcessTemplate Template)
        {
            List <string> MethodNames = new List <string>();

            foreach (MethodDeclaration m in CSParser.GetMethods(connectorClass))
            {
                if (TCollectConnectorInterfaces.IgnoreMethod(m.Attributes, m.Modifier))
                {
                    continue;
                }

                string connectorNamespaceName = ((NamespaceDeclaration)connectorClass.Parent).Name;

                if (!FUsingNamespaces.ContainsKey(connectorNamespaceName))
                {
                    FUsingNamespaces.Add(connectorNamespaceName, connectorNamespaceName);
                }

                ProcessTemplate snippet = Template.GetSnippet("WEBCONNECTOR");

                InsertWebConnectorMethodCall(snippet, connectorClass, m, ref MethodNames);

                Template.InsertSnippet("WEBCONNECTORS", snippet);
            }
        }
Ejemplo n.º 5
0
        private static ProcessTemplate GenerateUIConnector(ProcessTemplate ATemplate, TypeDeclaration connectorClass, string interfacename)
        {
            ProcessTemplate snippet = ATemplate.GetSnippet("UICONNECTORCLASS");

            snippet.SetCodelet("UICONNECTORINTERFACE", interfacename);
            snippet.SetCodelet("UICONNECTORCLASSNAME", connectorClass.Name);
            snippet.SetCodelet("CONSTRUCTORS", string.Empty);

            int constructorCounter = 0;

            foreach (ConstructorDeclaration m in CSParser.GetConstructors(connectorClass))
            {
                if (TCollectConnectorInterfaces.IgnoreMethod(m.Attributes, m.Modifier))
                {
                    continue;
                }

                constructorCounter++;

                ProcessTemplate snippetConstructor = ATemplate.GetSnippet("UICONNECTORCONSTRUCTOR");

                string ParameterDefinition = string.Empty;
                string ActualParameters    = string.Empty;

                AutoGenerationTools.FormatParameters(m.Parameters, out ActualParameters, out ParameterDefinition);

                snippetConstructor.SetCodelet("PARAMETERDEFINITION", ParameterDefinition);
                snippetConstructor.SetCodelet("UICONNECTORCLASSNAME", connectorClass.Name);
                snippetConstructor.SetCodelet("ACTUALPARAMETERS", ActualParameters);
                snippetConstructor.SetCodelet("ADDACTUALPARAMETERS", string.Empty);

                foreach (ParameterDeclarationExpression p in m.Parameters)
                {
                    if (((ParameterModifiers.Ref & p.ParamModifier) > 0) || ((ParameterModifiers.Out & p.ParamModifier) > 0))
                    {
                        throw new Exception("we do not support ref or out parameters in UIConnector constructor calls! " + connectorClass.Name);
                    }

                    snippetConstructor.AddToCodelet("ADDACTUALPARAMETERS",
                                                    "ActualParameters.Add(\"" + p.ParameterName + "\", " +
                                                    p.ParameterName + ");" + Environment.NewLine);
                }

                string methodname = m.Name;

                if (constructorCounter > 1)
                {
                    methodname += constructorCounter.ToString();
                }

                snippetConstructor.SetCodelet("METHODNAME", methodname);

                snippet.InsertSnippet("CONSTRUCTORS", snippetConstructor);
            }

            InsertMethodsAndProperties(snippet, connectorClass);

            return(snippet);
        }
Ejemplo n.º 6
0
        void ImplementWebConnector(
            SortedList <string, TypeDeclaration> connectors,
            ProcessTemplate ATemplate, string AFullNamespace)
        {
            string ConnectorNamespace = AFullNamespace.
                                        Replace("Instantiator.", string.Empty);

            List <TypeDeclaration> ConnectorClasses = TCollectConnectorInterfaces.FindTypesInNamespace(connectors, ConnectorNamespace);

            ConnectorNamespace = ConnectorNamespace.
                                 Replace("Ict.Petra.Shared.", "Ict.Petra.Server.");

            ATemplate.SetCodelet("CLIENTOBJECTFOREACHUICONNECTOR", string.Empty);

            foreach (TypeDeclaration connectorClass in ConnectorClasses)
            {
                foreach (MethodDeclaration m in CSParser.GetMethods(connectorClass))
                {
                    if (TCollectConnectorInterfaces.IgnoreMethod(m.Attributes, m.Modifier))
                    {
                        continue;
                    }

                    ProcessTemplate snippet = ATemplate.GetSnippet("WEBCONNECTORMETHOD");

                    string ParameterDefinition = string.Empty;
                    string ActualParameters    = string.Empty;

                    AutoGenerationTools.FormatParameters(m.Parameters, out ActualParameters, out ParameterDefinition);

                    snippet.InsertSnippet("CHECKUSERMODULEPERMISSIONS",
                                          CreateModuleAccessPermissionCheck(
                                              ATemplate,
                                              connectorClass.Name,
                                              m));

                    string returntype = AutoGenerationTools.TypeToString(m.TypeReference, "");

                    snippet.SetCodelet("RETURN", returntype != "void" ? "return " : string.Empty);

                    snippet.SetCodelet("METHODNAME", m.Name);
                    snippet.SetCodelet("ACTUALPARAMETERS", ActualParameters);
                    snippet.SetCodelet("PARAMETERDEFINITION", ParameterDefinition);
                    snippet.SetCodelet("RETURNTYPE", returntype);
                    snippet.SetCodelet("WEBCONNECTORCLASS", connectorClass.Name);

                    if (!UsingConnectorNamespaces.Contains(ConnectorNamespace))
                    {
                        UsingConnectorNamespaces.Add(ConnectorNamespace);
                    }

                    ATemplate.InsertSnippet("REMOTEDMETHODS", snippet);
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// use CSParser to parse the Server files
        /// </summary>
        /// <param name="tn"></param>
        /// <param name="AOutputPath"></param>
        private void WriteInterfaces(TNamespace tn, String AOutputPath)
        {
            String OutputFile = AOutputPath + Path.DirectorySeparatorChar + tn.Name + ".Interfaces-generated.cs";

            // open file
            Console.WriteLine("working on file " + OutputFile);

            ProcessTemplate Template = new ProcessTemplate(FTemplateDir + Path.DirectorySeparatorChar +
                                                           "ClientServerGlue" + Path.DirectorySeparatorChar +
                                                           "Interface.cs");

            // load default header with license and copyright
            Template.SetCodelet("GPLFILEHEADER", ProcessTemplate.LoadEmptyFileComment(FTemplateDir));

            Template.AddToCodelet("USINGNAMESPACES", AddNamespacesFromYmlFile(AOutputPath, tn.Name));

            // get all csharp files that might hold implementations of remotable classes
            List <CSParser> CSFiles = null;

            if (AOutputPath.Contains("ICT/Petra/Plugins"))
            {
                // search for webconnectors in the directory of the plugin
                CSFiles = CSParser.GetCSFilesForDirectory(Path.GetFullPath(AOutputPath + "/../Server"),
                                                          SearchOption.AllDirectories);
            }
            else if (Directory.Exists(CSParser.ICTPath + "/Petra/Server/lib/M" + tn.Name))
            {
                // any class in the module can contain a webconnector
                CSFiles = CSParser.GetCSFilesForDirectory(CSParser.ICTPath + "/Petra/Server/lib/M" + tn.Name,
                                                          SearchOption.AllDirectories);
            }
            else
            {
                CSFiles = new List <CSParser>();
            }

            SortedList InterfaceNames = GetInterfaceNamesFromImplementation(CSFiles);

            Template.SetCodelet("INTERFACES", string.Empty);
            WriteNamespaces(Template, tn, InterfaceNames, CSFiles);

            if (Template.FCodelets["INTERFACES"].Length == 0)
            {
                Template.InsertSnippet("INTERFACES", Template.GetSnippet("DUMMYINTERFACE"));
            }

            Template.FinishWriting(OutputFile, ".cs", true);
        }
Ejemplo n.º 8
0
        private static void ImplementWebConnector(
            SortedList <string, TypeDeclaration> connectors,
            ProcessTemplate ATemplate, string AFullNamespace)
        {
            string ConnectorNamespace = AFullNamespace.
                                        Replace("Instantiator.", string.Empty);

            List <TypeDeclaration> ConnectorClasses = TCollectConnectorInterfaces.FindTypesInNamespace(connectors, ConnectorNamespace);

            ConnectorNamespace = ConnectorNamespace.
                                 Replace(".Shared.", ".Server.");

            foreach (TypeDeclaration connectorClass in ConnectorClasses)
            {
                List <string> MethodNames = new List <string>();

                foreach (MethodDeclaration m in CSParser.GetMethods(connectorClass))
                {
                    if (TCollectConnectorInterfaces.IgnoreMethod(m.Attributes, m.Modifier))
                    {
                        continue;
                    }

                    ProcessTemplate snippet;

                    if (FCompileForStandalone)
                    {
                        if (!FUsingNamespaces.ContainsKey(ConnectorNamespace))
                        {
                            FUsingNamespaces.Add(ConnectorNamespace, ConnectorNamespace);
                        }

                        snippet = ATemplate.GetSnippet("WEBCONNECTORMETHODSTANDALONE");
                    }
                    else
                    {
                        snippet = ATemplate.GetSnippet("WEBCONNECTORMETHODREMOTE");
                    }

                    InsertMethodCall(snippet, connectorClass, m, ref MethodNames);

                    ATemplate.InsertSnippet("CONNECTORMETHODS", snippet);
                }
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// parse the namespaces from an XmlDocument
        /// </summary>
        public static TNamespace ParseFromDirectory(string AServerLibPath)
        {
            TNamespace NamespaceRoot = new TNamespace();

            List <CSParser> CSFiles = CSParser.GetCSFilesForDirectory(AServerLibPath, SearchOption.AllDirectories);

            foreach (CSParser file in CSFiles)
            {
                foreach (NamespaceDeclaration namespaceDecl in file.GetNamespaces())
                {
                    if (namespaceDecl.Name.EndsWith("Connectors"))
                    {
                        string name = namespaceDecl.Name.Substring("Ict.Petra.Server.".Length + 1);
                        FindOrCreateNamespace(NamespaceRoot, name);
                    }
                }
            }

            return(NamespaceRoot);
        }
Ejemplo n.º 10
0
        public void SaveLinkedScripts()
        {
            for (int i = 0; i < this._linkedScripts.Count; i++)
            {
                string path = Application.dataPath;
                path += "/../output/scripts/";
                Directory.CreateDirectory(path);
                path += this._linkedScripts[i].name + ".new.ts";
                if (File.Exists(path))
                {
                    File.Delete(path);
                }

                CSParser parser = new CSParser();
                CSEntity entity = parser.Parse(this._linkedScripts[i].text);

                StreamWriter writer = new StreamWriter(path);
                // writer.Write(entity.recursivelyWriteAsDebug());
                writer.Write(entity.writeAsTypescript());
                writer.Close();
            }
        }
Ejemplo n.º 11
0
        public bool Translate()
        {
            try
            {
                StringBuilder sBuilder = new StringBuilder();

                var files = Directory.EnumerateFiles(inputPath, "*.cs", SearchOption.AllDirectories);
                foreach (string path in files)
                {
                    CSParser parser = new CSParser(path);
                    string   script = GenerateScript(parser.CodeTree, ref exportableObjects);

                    for (int i = 0; i < exportableObjects.Count; i++)
                    {
                        sBuilder.Append(exportableObjects[i]);
                    }
                    sBuilder.Append(Environment.NewLine);
                    sBuilder.Append(script);
                    sBuilder.Append("End;");
                    sBuilder.Append(Environment.NewLine);

                    string outputFilePath = parser.CodeTree.Children[1].Target;
                    outputFilePath = outputFilePath.Replace('.', '\\');
                    outputPath     = @"F:\Steam\steamapps\common\Original War\mods\" + outputFilePath + "\\" + new FileInfo(path).Name.Substring(0, new FileInfo(path).Name.LastIndexOf('.')) + ".src";

                    string output = sBuilder.ToString();
                    using (StreamWriter writer = File.CreateText(outputPath))
                    {
                        writer.Write(output);
                    }
                }

                return(true);
            }
            catch (Exception e)
            { Console.Write(e); }
            return(false);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// main function to collect the connectors from the code.
        /// </summary>
        public static SortedList <string, TypeDeclaration> GetConnectors(string AModuleName)
        {
            if (!ConnectorsByModule.ContainsKey(AModuleName))
            {
                // get all csharp files that might hold implementations of remotable classes
                List <CSParser> CSFiles = null;

                if (Directory.Exists(CSParser.ICTPath + "/Petra/Server/lib/M" + AModuleName))
                {
                    // any class in the module can contain a connector
                    CSFiles = CSParser.GetCSFilesForDirectory(CSParser.ICTPath + "/Petra/Server/lib/M" + AModuleName,
                                                              SearchOption.AllDirectories);
                }
                else
                {
                    CSFiles = new List <CSParser>();
                }

                ConnectorsByModule.Add(AModuleName, GetConnectors(CSFiles));
            }

            return(ConnectorsByModule[AModuleName]);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// write the interfaces for the Connectors
        /// parses the instantiator files
        /// Although the instantiators are generated from the interfaces, they might contain ManualCode regions with specific functions
        /// </summary>
        /// <param name="ATemplate"></param>
        /// <param name="AMethodsAlreadyWritten"></param>
        /// <param name="AInstantiatorClasses">all instantiator classes that implement the interface</param>
        /// <param name="AInterfaceName"></param>
        /// <param name="AInterfaceNamespace"></param>
        /// <param name="AServerNamespace">for the comment in the autogenerated code</param>
        /// <returns></returns>
        private bool WriteInstantiatorMethods(
            ProcessTemplate ATemplate,
            StringCollection AMethodsAlreadyWritten,
            List <TypeDeclaration> AInstantiatorClasses, String AInterfaceName, String AInterfaceNamespace, String AServerNamespace)
        {
            foreach (TypeDeclaration t in AInstantiatorClasses)
            {
                // there should only be one class, eg. TSubscriptionsCacheableNamespace
                foreach (MethodDeclaration m in CSParser.GetMethods(t))
                {
                    // copy all public methods that are not constructor, destructor, or InitializeLifetimeService
                    // and that are not created yet
                    if ((m.Name != "InitializeLifetimeService") &&
                        ((m.Modifier & Modifiers.Public) != 0) &&
                        !AMethodsAlreadyWritten.Contains(m.Name))
                    {
                        ATemplate.AddToCodelet("CONTENT",
                                               "/// <summary>auto generated from Instantiator (" + AServerNamespace + "." + t.Type + ")</summary>" + Environment.NewLine);
                        string MethodDeclaration = AutoGenerationTools.TypeToString(m.TypeReference, "") + " " + m.Name + "(";
                        int    align             = MethodDeclaration.Length;

                        bool firstParameter = true;

                        foreach (ParameterDeclarationExpression p in m.Parameters)
                        {
                            AutoGenerationTools.AddParameter(ref MethodDeclaration, ref firstParameter, align, p.ParameterName, p.ParamModifier,
                                                             AutoGenerationTools.TypeToString(p.TypeReference, ""));
                        }

                        MethodDeclaration += ");";
                        ATemplate.AddToCodelet("CONTENT", MethodDeclaration + Environment.NewLine);
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 14
0
        public void Parse(bool parseMethodBodies)
        {
            try
            {
                lock (FParseLock)
                {
                    FParserResults = CSParser.Parse(TextContent, parseMethodBodies);

                    var filename           = Location.LocalPath;
                    var oldCompilationUnit = FParseInfo.MostRecentCompilationUnit;
                    var projectContent     = GetProjectContent();

                    var visitor = new NRefactoryASTConvertVisitor(projectContent);
                    visitor.Specials = FParserResults.Specials;
                    visitor.VisitCompilationUnit(FParserResults.CompilationUnit, null);

                    var newCompilationUnit = visitor.Cu;
                    newCompilationUnit.ErrorsDuringCompile = FParserResults.HasErrors;
                    newCompilationUnit.FileName            = filename;

                    UpdateFoldingRegions(newCompilationUnit, FParserResults);
                    AddCommentTags(newCompilationUnit, FParserResults);

                    // Remove information from lastCompilationUnit and add information from newCompilationUnit.
                    projectContent.UpdateCompilationUnit(oldCompilationUnit, newCompilationUnit, filename);
                    FParseInfo.SetCompilationUnit(newCompilationUnit);
                }
            }
            catch (Exception e)
            {
                Shell.Instance.Logger.Log(e);
            } finally
            {
                FParsingDone.Set();
            }
        }
Ejemplo n.º 15
0
 public CSParserResults Parse(bool parseMethodBodies)
 {
     return(CSParser.Parse(TextContent, parseMethodBodies));
 }
Ejemplo n.º 16
0
        static private void WriteUIConnector(string connectorname, TypeDeclaration connectorClass, ProcessTemplate Template)
        {
            List <string> MethodNames = new List <string>();

            foreach (ConstructorDeclaration m in CSParser.GetConstructors(connectorClass))
            {
                if (TCollectConnectorInterfaces.IgnoreMethod(m.Attributes, m.Modifier))
                {
                    continue;
                }

                string connectorNamespaceName = ((NamespaceDeclaration)connectorClass.Parent).Name;

                if (!FUsingNamespaces.ContainsKey(connectorNamespaceName))
                {
                    FUsingNamespaces.Add(connectorNamespaceName, connectorNamespaceName);
                }

                ProcessTemplate snippet = Template.GetSnippet("UICONNECTORCONSTRUCTOR");

                snippet.SetCodelet("UICONNECTORCLASS", connectorClass.Name);
                snippet.SetCodelet("CHECKUSERMODULEPERMISSIONS", "// TODO CHECKUSERMODULEPERMISSIONS");

                PrepareParametersForMethod(snippet, null, m.Parameters, m.Name, ref MethodNames);

                Template.InsertSnippet("UICONNECTORS", snippet);
            }

            // foreach public method create a method
            foreach (MethodDeclaration m in CSParser.GetMethods(connectorClass))
            {
                if (TCollectConnectorInterfaces.IgnoreMethod(m.Attributes, m.Modifier))
                {
                    continue;
                }

                ProcessTemplate snippet = Template.GetSnippet("UICONNECTORMETHOD");

                snippet.SetCodelet("METHODNAME", m.Name);
                snippet.SetCodelet("UICONNECTORCLASS", connectorClass.Name);
                snippet.SetCodelet("CHECKUSERMODULEPERMISSIONS", "// TODO CHECKUSERMODULEPERMISSIONS");

                PrepareParametersForMethod(snippet, m.TypeReference, m.Parameters, m.Name, ref MethodNames);

                if (snippet.FCodelets["PARAMETERDEFINITION"].Length > 0)
                {
                    snippet.AddToCodeletPrepend("PARAMETERDEFINITION", ", ");
                }

                Template.InsertSnippet("UICONNECTORS", snippet);
            }

            // foreach public property create a method
            foreach (PropertyDeclaration p in CSParser.GetProperties(connectorClass))
            {
                if (TCollectConnectorInterfaces.IgnoreMethod(p.Attributes, p.Modifier))
                {
                    continue;
                }

                string propertytype = p.TypeReference.ToString();

                // check if the parametertype is not a generic type, eg. dictionary or list
                if (!propertytype.Contains("<"))
                {
                    propertytype = propertytype == "string" || propertytype == "String" ? "System.String" : propertytype;
                    propertytype = propertytype == "bool" || propertytype == "Boolean" ? "System.Boolean" : propertytype;

                    if (propertytype.Contains("UINT") || propertytype.Contains("unsigned"))
                    {
                        propertytype = propertytype.Contains("UInt32") || propertytype == "unsigned int" ? "System.UInt32" : propertytype;
                        propertytype = propertytype.Contains("UInt16") || propertytype == "unsigned short" ? "System.UInt16" : propertytype;
                        propertytype = propertytype.Contains("UInt64") || propertytype == "unsigned long" ? "System.UInt64" : propertytype;
                    }
                    else
                    {
                        propertytype = propertytype.Contains("Int32") || propertytype == "int" ? "System.Int32" : propertytype;
                        propertytype = propertytype.Contains("Int16") || propertytype == "short" ? "System.Int16" : propertytype;
                        propertytype = propertytype.Contains("Int64") || propertytype == "long" ? "System.Int64" : propertytype;
                    }

                    propertytype = propertytype.Contains("Decimal") || propertytype == "decimal" ? "System.Decimal" : propertytype;
                }

                bool BinaryReturn = !((propertytype == "System.Int64") || (propertytype == "System.Int32") || (propertytype == "System.Int16") ||
                                      (propertytype == "System.String") || (propertytype == "System.Boolean"));

                string EncodedType      = propertytype;
                string EncodeReturnType = string.Empty;
                string ActualValue      = "AValue";

                if (BinaryReturn)
                {
                    EncodedType      = "System.String";
                    EncodeReturnType = "THttpBinarySerializer.SerializeObject";
                    ActualValue      = "(" + propertytype + ")THttpBinarySerializer.DeserializeObject(AValue)";
                }

                ProcessTemplate propertySnippet = Template.GetSnippet("UICONNECTORPROPERTY");
                propertySnippet.SetCodelet("UICONNECTORCLASS", connectorClass.Name);
                propertySnippet.SetCodelet("ENCODEDTYPE", EncodedType);
                propertySnippet.SetCodelet("PROPERTYNAME", p.Name);

                if (p.HasGetRegion)
                {
                    if (p.TypeReference.ToString().StartsWith("I"))
                    {
                        if (p.TypeReference.ToString() == "IAsynchronousExecutionProgress")
                        {
                            FContainsAsynchronousExecutionProgress = true;
                        }

                        // return the ObjectID of the Sub-UIConnector
                        propertySnippet.InsertSnippet("GETTER", Template.GetSnippet("GETSUBUICONNECTOR"));
                        propertySnippet.SetCodelet("ENCODEDTYPE", "System.String");
                    }
                    else
                    {
                        propertySnippet.SetCodelet("GETTER",
                                                   "return {#ENCODERETURNTYPE}((({#UICONNECTORCLASS})FUIConnectors[ObjectID]).{#PROPERTYNAME});");
                        propertySnippet.SetCodelet("ENCODERETURNTYPE", EncodeReturnType);
                    }
                }

                if (p.HasSetRegion)
                {
                    propertySnippet.SetCodelet("SETTER", "true");
                    propertySnippet.SetCodelet("ACTUALPARAMETERS", ActualValue);
                }

                Template.InsertSnippet("UICONNECTORS", propertySnippet);
            }
        }
Ejemplo n.º 17
0
        void ImplementUIConnector(
            SortedList <string, TypeDeclaration> connectors,
            ProcessTemplate ATemplate, string AFullNamespace)
        {
            string ConnectorNamespace = AFullNamespace.
                                        Replace("Instantiator.", string.Empty);

            List <TypeDeclaration> ConnectorClasses = TCollectConnectorInterfaces.FindTypesInNamespace(connectors, ConnectorNamespace);

            ConnectorNamespace = ConnectorNamespace.
                                 Replace("Ict.Petra.Shared.", "Ict.Petra.Server.");

            ATemplate.SetCodelet("CLIENTOBJECTFOREACHUICONNECTOR", string.Empty);

            foreach (TypeDeclaration connectorClass in ConnectorClasses)
            {
                foreach (ConstructorDeclaration m in CSParser.GetConstructors(connectorClass))
                {
                    if (TCollectConnectorInterfaces.IgnoreMethod(m.Attributes, m.Modifier))
                    {
                        continue;
                    }

                    ProcessTemplate snippet = ATemplate.GetSnippet("UICONNECTORMETHOD");

                    string ParameterDefinition = string.Empty;
                    string ActualParameters    = string.Empty;

                    AutoGenerationTools.FormatParameters(m.Parameters, out ActualParameters, out ParameterDefinition);

                    string methodname = m.Name.Substring(1);

                    if (methodname.EndsWith("UIConnector"))
                    {
                        methodname = methodname.Substring(0, methodname.LastIndexOf("UIConnector"));
                    }

                    snippet.SetCodelet("METHODNAME", methodname);
                    snippet.SetCodelet("PARAMETERDEFINITION", ParameterDefinition);
                    snippet.SetCodelet("ACTUALPARAMETERS", ActualParameters);
                    snippet.SetCodelet("UICONNECTORINTERFACE", CSParser.GetImplementedInterface(connectorClass));
                    snippet.SetCodelet("UICONNECTORCLIENTREMOTINGCLASS", connectorClass.Name + "Remote");
                    snippet.SetCodelet("UICONNECTORCLASS", connectorClass.Name);

                    if (!UsingConnectorNamespaces.Contains(ConnectorNamespace))
                    {
                        UsingConnectorNamespaces.Add(ConnectorNamespace);
                    }

                    ATemplate.InsertSnippet("REMOTEDMETHODS", snippet);
                }

                List <TypeDeclaration> tempList = new List <TypeDeclaration>();
                tempList.Add(connectorClass);

                ATemplate.InsertSnippet("CLIENTOBJECTFOREACHUICONNECTOR",
                                        TCreateClientRemotingClass.AddClientRemotingClass(
                                            FTemplateDir,
                                            connectorClass.Name + "Remote",
                                            CSParser.GetImplementedInterface(connectorClass),
                                            tempList
                                            ));
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// write the interfaces for the Connectors
        /// parses the connector files
        /// </summary>
        /// <param name="ATemplate">template that the code should be added to</param>
        /// <param name="AMethodsAlreadyWritten">a string list of method names that have been written</param>
        /// <param name="AConnectorClasses">all connector classes that implement the interface</param>
        /// <param name="AInterfaceName">the name of the interface we are writing to; it ends with ConnectorsNamespace</param>
        /// <param name="AInterfaceNamespace"></param>
        /// <param name="AServerNamespace">for the comment in the autogenerated code</param>
        /// <returns></returns>
        private bool WriteConnectorConstructors(
            ProcessTemplate ATemplate,
            ref StringCollection AMethodsAlreadyWritten,
            List <TypeDeclaration> AConnectorClasses, String AInterfaceName, String AInterfaceNamespace, String AServerNamespace)
        {
            string ServerNamespace = AInterfaceNamespace.Replace("Ict.Petra.Shared.Interfaces", "Ict.Petra.Server");

            foreach (TypeDeclaration t in AConnectorClasses)
            {
                string ConnectorClassName = t.Name;

                // cacheable will not work yet; careful: when building MethodName, connectorName does not have a plural s
                // but that cacheable constructor is not needed anyways???

                if (ConnectorClassName.StartsWith("T") &&
                    (ConnectorClassName.EndsWith("UIConnector") ||
                     ConnectorClassName.EndsWith("LogicConnector") ||
                     ConnectorClassName.EndsWith("Lookup") ||
                     ConnectorClassName.EndsWith("Reader")))
                {
                    // create a method for the interface, that returns the interface that the connector class is derived from,
                    // and takes the parameters from the constructor of the connector class
                    // it is named: remove first character T and trailing UIConnector/LogicConnector from the name of the connector class

                    // get the connector name from the namespace
                    StringCollection namespaceList = StringHelper.StrSplit(ServerNamespace, ".");

                    // connectorName eg. UIConnectors, LogicConnectors, ServerLookups, Cacheable
                    string connectorName = namespaceList[namespaceList.Count - 1];
                    string MethodName    = ConnectorClassName.Substring(1,
                                                                        ConnectorClassName.Length - 1 - (connectorName.Length - 1));
                    string MethodType = "";

                    foreach (TypeReference ti in t.BaseTypes)
                    {
                        // problem, eg. in MCommon, TOfficeSpecificDataLabelsUIConnector implements 2 interfaces
                        if ((ti.Type != "TConfigurableMBRObject") &&
                            (ti.Type == AInterfaceName))
                        {
                            MethodType = ti.Type;
                        }
                    }

                    if (MethodType.Length == 0)
                    {
                        // no valid interface has been derived; eg. Hospitality not finished yet
                        continue;
                    }

                    List <ConstructorDeclaration> constructors = CSParser.GetConstructors(t);

                    if (constructors.Count == 0)
                    {
                        // will cause compile error if the constructor is missing, because it is not implementing the interface completely
                        throw new Exception("missing a connector constructor in " + ServerNamespace + "." + ConnectorClassName);

//                    WriteLine("/// <summary>auto generated - there was no Connector constructor (" + ServerNamespace + "." + ConnectorClassName + ")</summary>");
//                    AMethodsAlreadyWritten.Add(MethodName);
//                    string MethodDeclaration = MethodType + " " + MethodName + "();";
//                    WriteLine(MethodDeclaration);
                    }
                    else
                    {
                        // find constructor and copy the parameters
                        foreach (ConstructorDeclaration m in constructors)
                        {
                            ATemplate.AddToCodelet(
                                "CONTENT",
                                "/// <summary>auto generated from Connector constructor (" + ServerNamespace + "." + ConnectorClassName + ")</summary>" +
                                Environment.NewLine);
                            AMethodsAlreadyWritten.Add(MethodName);
                            string MethodDeclaration = MethodType + " " + MethodName + "(";
                            int    align             = MethodDeclaration.Length;
                            bool   firstParameter    = true;

                            foreach (ParameterDeclarationExpression p in m.Parameters)
                            {
                                AutoGenerationTools.AddParameter(ref MethodDeclaration,
                                                                 ref firstParameter,
                                                                 align,
                                                                 p.ParameterName,
                                                                 p.ParamModifier,
                                                                 p.TypeReference.Type);
                            }

                            MethodDeclaration += ");";
                            ATemplate.AddToCodelet("CONTENT", MethodDeclaration + Environment.NewLine);
                        }
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// write the interfaces for the methods that need to be reflected
        /// check connector files
        /// </summary>
        /// <param name="ATemplate"></param>
        /// <param name="AMethodsAlreadyWritten">write methods only once</param>
        /// <param name="AConnectorClasses">the classes that are implementing the methods</param>
        /// <param name="AInterfaceName">the interface that is written at the moment</param>
        /// <param name="AInterfaceNamespace">only needed to shorten the type names to improve readability</param>
        /// <param name="AServerNamespace">for the comment in the autogenerated code</param>
        /// <returns></returns>
        private bool WriteConnectorMethods(
            ProcessTemplate ATemplate,
            ref StringCollection AMethodsAlreadyWritten,
            List <TypeDeclaration> AConnectorClasses, String AInterfaceName, String AInterfaceNamespace, String AServerNamespace)
        {
            foreach (TypeDeclaration t in AConnectorClasses)
            {
                string ConnectorClassName = t.Name;

                foreach (PropertyDeclaration p in CSParser.GetProperties(t))
                {
                    if (TCollectConnectorInterfaces.IgnoreMethod(p.Attributes, p.Modifier))
                    {
                        continue;
                    }

                    if (!p.GetRegion.Block.ToString().Contains("TCreateRemotableObject"))
                    {
                        TLogging.Log("Warning: properties in UIConnectors must use the class TCreateRemotableObject: " +
                                     AServerNamespace + "." + t.Name + "." + p.Name);
                    }

                    // don't write namespace hierarchy here
                    if (p.TypeReference.Type.IndexOf("Namespace") == -1)
                    {
                        String returnType = AutoGenerationTools.TypeToString(p.TypeReference, AInterfaceNamespace);

                        // this interface got implemented somewhere on the server
                        ProcessTemplate snippet = ATemplate.GetSnippet("CONNECTORPROPERTY");
                        snippet.SetCodelet("CONNECTORCLASSNAME", ConnectorClassName);
                        snippet.SetCodelet("SERVERNAMESPACE", AServerNamespace);
                        snippet.SetCodelet("TYPE", returnType);
                        snippet.SetCodelet("NAME", p.Name);

                        if (p.HasGetRegion)
                        {
                            snippet.SetCodelet("GETTER", "true");
                        }

                        if (p.HasSetRegion)
                        {
                            snippet.SetCodelet("SETTER", "true");
                        }

                        ATemplate.InsertSnippet("CONTENT", snippet);
                    }
                }

                foreach (MethodDeclaration m in CSParser.GetMethods(t))
                {
                    string MethodName = m.Name;

                    if (TCollectConnectorInterfaces.IgnoreMethod(m.Attributes, m.Modifier))
                    {
                        continue;
                    }

                    String formattedMethod = "";
                    String returnType      = AutoGenerationTools.TypeToString(m.TypeReference, AInterfaceNamespace);

                    int align = (returnType + " " + m.Name).Length + 1;

                    // this interface got implemented somewhere on the server
                    formattedMethod = "/// <summary> auto generated from Connector method(" + AServerNamespace + "." + ConnectorClassName +
                                      ")</summary>" + Environment.NewLine;
                    formattedMethod += returnType + " " + m.Name + "(";

                    bool firstParameter = true;

                    foreach (ParameterDeclarationExpression p in m.Parameters)
                    {
                        if (!firstParameter)
                        {
                            ATemplate.AddToCodelet("CONTENT", formattedMethod + "," + Environment.NewLine);
                            formattedMethod = new String(' ', align);
                        }

                        firstParameter = false;
                        String parameterType = AutoGenerationTools.TypeToString(p.TypeReference, "");

                        if ((p.ParamModifier & ParameterModifiers.Ref) != 0)
                        {
                            formattedMethod += "ref ";
                        }
                        else if ((p.ParamModifier & ParameterModifiers.Out) != 0)
                        {
                            formattedMethod += "out ";
                        }

                        formattedMethod += parameterType + " " + p.ParameterName;
                    }

                    formattedMethod += ");";
                    AMethodsAlreadyWritten.Add(MethodName);
                    ATemplate.AddToCodelet("CONTENT", formattedMethod + Environment.NewLine);
                }
            }

            return(true);
        }
Ejemplo n.º 20
0
        private static void ImplementUIConnector(
            SortedList <string, TypeDeclaration> connectors,
            ProcessTemplate ATemplate, string AFullNamespace)
        {
            string ConnectorNamespace = AFullNamespace.
                                        Replace("Instantiator.", string.Empty);

            List <TypeDeclaration> ConnectorClasses = TCollectConnectorInterfaces.FindTypesInNamespace(connectors, ConnectorNamespace);

            ConnectorNamespace = ConnectorNamespace.
                                 Replace(".Shared.", ".Server.");

            foreach (TypeDeclaration connectorClass in ConnectorClasses)
            {
                foreach (ConstructorDeclaration m in CSParser.GetConstructors(connectorClass))
                {
                    if (TCollectConnectorInterfaces.IgnoreMethod(m.Attributes, m.Modifier))
                    {
                        continue;
                    }

                    ProcessTemplate snippet;

                    FModuleHasUIConnector = true;

                    if (FCompileForStandalone)
                    {
                        if (!FUsingNamespaces.ContainsKey(ConnectorNamespace))
                        {
                            FUsingNamespaces.Add(ConnectorNamespace, ConnectorNamespace);
                        }

                        snippet = ATemplate.GetSnippet("UICONNECTORMETHODSTANDALONE");
                    }
                    else
                    {
                        snippet = ATemplate.GetSnippet("UICONNECTORMETHODREMOTE");
                    }

                    string ParameterDefinition = string.Empty;
                    string ActualParameters    = string.Empty;

                    AutoGenerationTools.FormatParameters(m.Parameters, out ActualParameters, out ParameterDefinition);

                    string methodname = m.Name.Substring(1);

                    if (methodname.EndsWith("UIConnector"))
                    {
                        methodname = methodname.Substring(0, methodname.LastIndexOf("UIConnector"));
                    }

                    string interfacename = CSParser.GetImplementedInterface(connectorClass);
                    snippet.SetCodelet("METHODNAME", methodname);
                    snippet.SetCodelet("PARAMETERDEFINITION", ParameterDefinition);
                    snippet.SetCodelet("ACTUALPARAMETERS", ActualParameters);
                    snippet.SetCodelet("UICONNECTORINTERFACE", interfacename);
                    snippet.SetCodelet("UICONNECTORCLASSNAME", connectorClass.Name);

                    snippet.SetCodelet("UICONNECTORCLASS", string.Empty);

                    if (!FCompileForStandalone)
                    {
                        if (!FUIConnectorsAdded.Contains(connectorClass.Name))
                        {
                            FUIConnectorsAdded.Add(connectorClass.Name);

                            snippet.InsertSnippet("UICONNECTORCLASS",
                                                  GenerateUIConnector(ATemplate, connectorClass, interfacename));
                        }
                    }

                    ATemplate.InsertSnippet("CONNECTORMETHODS", snippet);
                }
            }
        }
Ejemplo n.º 21
0
        private static void InsertMethodsAndProperties(ProcessTemplate template, TypeDeclaration t)
        {
            List <string> MethodNames = new List <string>();

            // foreach public method create a method
            foreach (MethodDeclaration m in CSParser.GetMethods(t))
            {
                if (TCollectConnectorInterfaces.IgnoreMethod(m.Attributes, m.Modifier))
                {
                    continue;
                }

                ProcessTemplate methodSnippet = template.GetSnippet("UICONNECTORMETHOD");

                InsertMethodCall(methodSnippet, t, m, ref MethodNames);

                template.InsertSnippet("METHODSANDPROPERTIES", methodSnippet);
            }

            // foreach public property create a method
            foreach (PropertyDeclaration p in CSParser.GetProperties(t))
            {
                if (TCollectConnectorInterfaces.IgnoreMethod(p.Attributes, p.Modifier))
                {
                    continue;
                }

                ProcessTemplate propertySnippet = template.GetSnippet("UICONNECTORPROPERTY");

                string type = AutoGenerationTools.TypeToString(p.TypeReference, string.Empty);
                propertySnippet.SetCodelet("NAME", p.Name);
                propertySnippet.SetCodelet("TYPE", type);

                string expectedreturntype = GetExpectedReturnType(0, AutoGenerationTools.TypeToString(p.TypeReference, string.Empty));

                propertySnippet.SetCodelet("EXPECTEDRETURNTYPE", expectedreturntype);

                if (p.HasGetRegion)
                {
                    if (type.StartsWith("I"))
                    {
                        propertySnippet.SetCodelet(
                            "GETTER",
                            "return new T" + type.Substring(
                                1) +
                            "(\"M{#TOPLEVELMODULE}\", THttpConnector.ReadUIConnectorProperty(FObjectID, \"M{#TOPLEVELMODULE}\", \"{#UICONNECTORCLASSNAME}\", \"{#NAME}\", \"System.String\").ToString());");
                    }
                    else
                    {
                        propertySnippet.SetCodelet(
                            "GETTER",
                            "return ({#TYPE}) THttpConnector.ReadUIConnectorProperty(FObjectID, \"M{#TOPLEVELMODULE}\", \"{#UICONNECTORCLASSNAME}\", \"{#NAME}\", \"{#EXPECTEDRETURNTYPE}\");");
                    }
                }

                if (p.HasSetRegion)
                {
                    propertySnippet.SetCodelet("SETTER", "yes");
                }

                template.InsertSnippet("METHODSANDPROPERTIES", propertySnippet);
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// this will return a SortedList, the key is the interface name,
        /// and the value is the type definition of the class that implements that interface;
        /// connectors are identified namespace ending with Connectors
        /// </summary>
        private static SortedList <string, TypeDeclaration> GetConnectors(List <CSParser> ACSFiles)
        {
            SortedList <string, TypeDeclaration> Result = new SortedList <string, TypeDeclaration>();

            foreach (CSParser CSFile in ACSFiles)
            {
                foreach (TypeDeclaration t in CSFile.GetClasses())
                {
                    if (t.UserData.ToString().EndsWith("Connectors"))
                    {
                        string Interface = CSParser.GetImplementedInterface(t);

                        if (Interface.Length > 0)
                        {
                            string ServerNamespace = t.UserData.ToString();
                            string ServerNamespaceWithClassName = ServerNamespace + "." + t.Name;
                            string key = ServerNamespaceWithClassName + ":" + Interface;

                            if (Result.ContainsKey(ServerNamespaceWithClassName))
                            {
                                // there is already the other part of the partial class

                                TypeDeclaration partialType = Result[ServerNamespaceWithClassName];

                                Result.Remove(ServerNamespaceWithClassName);

                                foreach (INode child in partialType.Children)
                                {
                                    t.AddChild(child);
                                }
                            }

                            Result.Add(key, t);

                            if (TLogging.DebugLevel > 1)
                            {
                                // TLogging.Log("adding new Connector " + key);
                            }
                        }
                        // either a webconnector, or a partial class
                        else
                        {
                            // web connectors don't derive from an interface, because the methods are static

                            string ServerNamespace = t.UserData.ToString();
                            string key             = ServerNamespace + "." + t.Name;

                            if (Result.ContainsKey(key))
                            {
                                // partial class
                                foreach (INode child in t.Children)
                                {
                                    Result[key].AddChild(child);
                                }
                            }
                            else if (t.Name.EndsWith("UIConnector"))
                            {
                                // this could be the partial class of a UIConnector
                                // try to find a key that starts with this type
                                bool foundType = false;

                                foreach (string k in Result.Keys)
                                {
                                    if (k.StartsWith(key + ":"))
                                    {
                                        foundType = true;

                                        foreach (INode child in t.Children)
                                        {
                                            Result[k].AddChild(child);
                                        }
                                    }
                                }

                                if (!foundType)
                                {
                                    Result.Add(key, t);
                                }
                            }
                            else
                            {
                                Result.Add(key, t);
                            }

                            if (TLogging.DebugLevel > 1)
                            {
                                // TLogging.Log("adding new Connector " + key);
                            }
                        }
                    }
                }
            }

            return(Result);
        }
Ejemplo n.º 23
0
        private static void ProcessFile(CSParser AParsedFile, ref Dictionary <string, ErrCodeInfo> AErrorCodes)
        {
            ErrCodeInfo     ErrCodeDetails = null;
            string          ErrCodeValue;
            string          ShortDescription = String.Empty;
            string          LongDescription  = String.Empty;
            ErrCodeCategory ErrCodeCat;

            foreach (TypeDeclaration t in AParsedFile.GetClasses())
            {
                foreach (object child in t.Children)
                {
                    if (child is INode)
                    {
                        INode node = (INode)child;
                        Type  type = node.GetType();

                        if (type.Name == "FieldDeclaration")
                        {
                            FieldDeclaration fd = (FieldDeclaration)node;

                            foreach (VariableDeclaration vd in fd.Fields)
                            {
                                foreach (AttributeSection attrSection in fd.Attributes)
                                {
                                    foreach (ICSharpCode.NRefactory.Ast.Attribute attr in attrSection.Attributes)
                                    {
                                        LongDescription = String.Empty;

                                        if (attr.Name == "ErrCodeAttribute")
                                        {
                                            ErrCodeValue = ((PrimitiveExpression)vd.Initializer).Value.ToString();

                                            if (ErrCodeValue.EndsWith("V"))
                                            {
                                                ErrCodeCat = ErrCodeCategory.Validation;
                                            }
                                            else if (ErrCodeValue.EndsWith("N"))
                                            {
                                                ErrCodeCat = ErrCodeCategory.NonCriticalError;
                                            }
                                            else
                                            {
                                                ErrCodeCat = ErrCodeCategory.Error;
                                            }

//                                        TLogging.Log("");
//                                        TLogging.Log("");
//                                        TLogging.Log("");
//                                        TLogging.Log(vd.Name + " = " + ((PrimitiveExpression)vd.Initializer).Value.ToString());

                                            foreach (Expression e in attr.PositionalArguments)
                                            {
//                                            TLogging.Log("ShortDescription: " + ShortDescription);
                                                ShortDescription = ((PrimitiveExpression)e).Value.ToString();
                                            }

                                            foreach (Expression e in attr.NamedArguments)
                                            {
                                                if (((NamedArgumentExpression)e).Name == "FullDescription")
                                                {
                                                    LongDescription = ExpressionToString(((NamedArgumentExpression)e).Expression);
                                                }

//                                            TLogging.Log("NamedArgumentExpression Name: " + LongDescription);
                                            }

                                            ErrCodeDetails = new ErrCodeInfo(ErrCodeValue, t.Name, vd.Name,
                                                                             ShortDescription, LongDescription,
                                                                             String.Empty, String.Empty, ErrCodeCat, String.Empty, false);

                                            AErrorCodes.Add(ErrCodeValue, ErrCodeDetails);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        private static void InsertMethodsAndProperties(ProcessTemplate template, TypeDeclaration t)
        {
            // foreach public method create a method
            foreach (MethodDeclaration m in CSParser.GetMethods(t))
            {
                if (TCollectConnectorInterfaces.IgnoreMethod(m.Attributes, m.Modifier))
                {
                    continue;
                }

                ProcessTemplate methodSnippet = ClientRemotingClassTemplate.GetSnippet("METHOD");

                string returntype = AutoGenerationTools.TypeToString(m.TypeReference, string.Empty);

                methodSnippet.SetCodelet("METHODNAME", m.Name);
                methodSnippet.SetCodelet("RETURNTYPE", returntype);

                string ParameterDefinition = string.Empty;
                string ActualParameters    = string.Empty;

                AutoGenerationTools.FormatParameters(m.Parameters, out ActualParameters, out ParameterDefinition);

                methodSnippet.SetCodelet("PARAMETERDEFINITION", ParameterDefinition);
                methodSnippet.SetCodelet("ACTUALPARAMETERS", ActualParameters);

                if (returntype != "void")
                {
                    methodSnippet.SetCodelet("RETURN", "return ");
                }
                else
                {
                    methodSnippet.SetCodelet("RETURN", string.Empty);
                }

                template.InsertSnippet("METHODSANDPROPERTIES", methodSnippet);
            }

            // foreach public method create a method
            foreach (PropertyDeclaration p in CSParser.GetProperties(t))
            {
                if (TCollectConnectorInterfaces.IgnoreMethod(p.Attributes, p.Modifier))
                {
                    continue;
                }

                ProcessTemplate propertySnippet = ClientRemotingClassTemplate.GetSnippet("PROPERTY");

                propertySnippet.SetCodelet("NAME", p.Name);
                propertySnippet.SetCodelet("TYPE", AutoGenerationTools.TypeToString(p.TypeReference, string.Empty));

                if (p.HasGetRegion)
                {
                    propertySnippet.SetCodelet("GETTER", "yes");
                }

                if (p.HasSetRegion)
                {
                    propertySnippet.SetCodelet("SETTER", "yes");
                }

                template.InsertSnippet("METHODSANDPROPERTIES", propertySnippet);
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Creates a HTML file that contains central documentation of the Error Codes that are used throughout OpenPetra code
        /// </summary>
        public static bool Execute(string ACSharpPath, string ATemplateFilePath, string AOutFilePath)
        {
            Dictionary <string, ErrCodeInfo> ErrorCodes = new Dictionary <string, ErrCodeInfo>();
            CSParser parsedFile          = new CSParser(ACSharpPath + "/ICT/Common/ErrorCodes.cs");
            string   ErrCodeCategoryNice = String.Empty;

            TLogging.Log("Creating HTML documentation of OpenPetra Error Codes...");

            ProcessFile(parsedFile, ref ErrorCodes);
            parsedFile = new CSParser(ACSharpPath + "/ICT/Petra/Shared/ErrorCodes.cs");
            ProcessFile(parsedFile, ref ErrorCodes);
            parsedFile = new CSParser(ACSharpPath + "/ICT/Common/Verification/StringChecks.cs");
            ProcessFile(parsedFile, ref ErrorCodes);

            ProcessTemplate t = new ProcessTemplate(ATemplateFilePath);

            Dictionary <string, ProcessTemplate> snippets = new Dictionary <string, ProcessTemplate>();

            snippets.Add("GENC", t.GetSnippet("TABLE"));
            snippets["GENC"].SetCodelet("TABLEDESCRIPTION", "GENERAL (<i>Ict.Common* Libraries only</i>)");
            snippets.Add("GEN", t.GetSnippet("TABLE"));
            snippets["GEN"].SetCodelet("TABLEDESCRIPTION", "GENERAL (across the OpenPetra application)");
            snippets.Add("PARTN", t.GetSnippet("TABLE"));
            snippets["PARTN"].SetCodelet("TABLEDESCRIPTION", "PARTNER Module");
            snippets.Add("PERS", t.GetSnippet("TABLE"));
            snippets["PERS"].SetCodelet("TABLEDESCRIPTION", "PERSONNEL Module");
            snippets.Add("FIN", t.GetSnippet("TABLE"));
            snippets["FIN"].SetCodelet("TABLEDESCRIPTION", "FINANCE Module");
            snippets.Add("CONF", t.GetSnippet("TABLE"));
            snippets["CONF"].SetCodelet("TABLEDESCRIPTION", "CONFERENCE Module");
            snippets.Add("FINDEV", t.GetSnippet("TABLE"));
            snippets["FINDEV"].SetCodelet("TABLEDESCRIPTION", "FINANCIAL DEVELOPMENT Module");
            snippets.Add("SYSMAN", t.GetSnippet("TABLE"));
            snippets["SYSMAN"].SetCodelet("TABLEDESCRIPTION", "SYSTEM MANAGER Module");

            foreach (string snippetkey in snippets.Keys)
            {
                snippets[snippetkey].SetCodelet("ABBREVIATION", snippetkey);
                snippets[snippetkey].SetCodelet("ROWS", string.Empty);
            }

            foreach (string code in ErrorCodes.Keys)
            {
                foreach (string snippetkey in snippets.Keys)
                {
                    if (code.StartsWith(snippetkey + "."))
                    {
                        ProcessTemplate row = t.GetSnippet("ROW");
                        row.SetCodelet("CODE", code);

                        ErrCodeInfo ErrCode = ErrorCodes[code];

                        switch (ErrCode.Category)
                        {
                        case ErrCodeCategory.NonCriticalError:
                            ErrCodeCategoryNice = "Non-critical Error";
                            break;

                        default:
                            ErrCodeCategoryNice = ErrCode.Category.ToString("G");
                            break;
                        }

                        row.AddToCodelet("SHORTDESCRIPTION", (ErrCode.ShortDescription));
                        row.AddToCodelet("FULLDESCRIPTION", (ErrCode.FullDescription));
                        row.AddToCodelet("ERRORCODECATEGORY", (ErrCodeCategoryNice));
                        row.AddToCodelet("DECLARINGCLASS", (ErrCode.ErrorCodeConstantClass));

                        snippets[snippetkey].InsertSnippet("ROWS", row);
                    }
                }
            }

            foreach (string snippetkey in snippets.Keys)
            {
                t.InsertSnippet("TABLES", snippets[snippetkey]);
            }

            return(t.FinishWriting(AOutFilePath, ".html", true));
        }