Example #1
0
        void FindStaticMethods(TypePlan typeplan)
        {
            max_staticMethodParCount = 0;
            List <MethodPlan> allStaticCreateMethods = new List <MethodPlan>();
            List <MethodPlan> plans = typeplan.methods;
            int j = plans.Count;

            for (int i = 0; i < j; ++i)
            {
                MethodPlan m = plans[i];
                if (m.metDecl.IsStatic)
                {
                    allStaticCreateMethods.Add(m);
                    if (m.pars.Count > max_staticMethodParCount)
                    {
                        max_staticMethodParCount = m.pars.Count;
                    }
                }
            }
            if (allStaticCreateMethods.Count == 0)
            {
                this.staticMethods = null;
            }
            else
            {
                this.staticMethods = allStaticCreateMethods;
            }
        }
Example #2
0
 int Donner_IndexImage(TypePlan t)
 {
     if (t == TypePlan.DOSSIER)
     {
         return(1);
     }
     if (t == TypePlan.NATIONAL)
     {
         return(2);
     }
     if (t == TypePlan.REGIONAL)
     {
         return(3);
     }
     if (t == TypePlan.TERRITORIAL)
     {
         return(4);
     }
     if (t == TypePlan.LOCAL)
     {
         return(5);
     }
     if (t == TypePlan.TRANSVERSE)
     {
         return(6);
     }
     return(0);
 }
Example #3
0
        internal void Alter(int id)
        {
            TypePlan type = typeBusiness.GetById(id);
            Dictionary <string, string> originalValues = GenerateDictionaries.generateTypeDictionary(type.Id, type.Name, type.Description);

            Console.WriteLine("Se não hover necessidade de alteração de algum campo deixe-o vazio...");
            Console.WriteLine($"Nome atual:{type.Name}");
            Console.WriteLine("Novo nome:");
            var name = Console.ReadLine();

            Console.WriteLine($"Descrição:{type.Description}");
            Console.WriteLine("Nova descrição:");
            var description = Console.ReadLine();
            Dictionary <string, string> updatedValues = GenerateDictionaries.generateTypeDictionary(type.Id,
                                                                                                    String.IsNullOrEmpty(name) ? type.Name : name,
                                                                                                    String.IsNullOrEmpty(description) ? type.Description : description);

            try
            {
                typeBusiness.Update(originalValues, updatedValues);
                TypeList = typeBusiness.Read();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Example #4
0
 public IActionResult Update([Bind("Id,Name")] TypePlan type)
 {
     if (ModelState.IsValid)
     {
         _typePlanRepository.Update(type);
         return(Ok());
     }
     return(BadRequest());
 }
Example #5
0
 public IActionResult Create([FromBody] TypePlan type)
 {
     if (ModelState.IsValid)
     {
         var result     = typeRepository.Create(type);
         var lastResult = result ? typeRepository.GetLastInserted() : null;
         var uri        = Url.Action("Get", new { id = lastResult.Id });
         return(Created(uri, lastResult));
     }
     return(BadRequest());
 }
Example #6
0
 public IActionResult Insert([Bind("Name")] TypePlan type)
 {
     if (ModelState.IsValid)
     {
         var result   = _typePlanRepository.Insert(type);
         var lastType = result ? _typePlanRepository.GetLastInserted() : null;
         var uri      = Url.Action("Get", new { id = lastType.Id, Version = "1.0" });
         return(Created(uri, lastType));
     }
     return(BadRequest());
 }
Example #7
0
        void GenerateCsCode(CodeStringBuilder stbuilder)
        {
            CodeStringBuilder   codeBuilder = new CodeStringBuilder();
            CodeTypeDeclaration orgDecl     = this.OriginalDecl;
            TypePlan            _typeTxInfo = orgDecl.TypePlan;

            //
            AddComment(orgDecl.LineComments, codeBuilder);

            //for cef, if enum class end with flags_t
            //we add FlagsAttribute to this enum type

            if (orgDecl.Name.EndsWith("flags_t"))
            {
                codeBuilder.AppendLine("[Flags]");
            }

            codeBuilder.AppendLine("public enum " + orgDecl.Name + enum_base + "{");
            //transform enum
            int i = 0;

            foreach (FieldPlan fieldTx in _typeTxInfo.fields)
            {
                if (i > 0)
                {
                    codeBuilder.AppendLine(",");
                }
                i++;
                CodeFieldDeclaration codeFieldDecl = fieldTx.fieldDecl;
                //
                AddComment(codeFieldDecl.LineComments, codeBuilder);
                //
                if (codeFieldDecl.InitExpression != null)
                {
                    string initExpr = codeFieldDecl.InitExpression.ToString();
                    //cef specific
                    if (initExpr == "UINT_MAX")
                    {
                        codeBuilder.Append(codeFieldDecl.Name + "=uint.MaxValue");
                    }
                    else
                    {
                        codeBuilder.Append(codeFieldDecl.Name + "=" + codeFieldDecl.InitExpression.ToString());
                    }
                }
                else
                {
                    codeBuilder.Append(codeFieldDecl.Name);
                }
            }
            codeBuilder.AppendLine("}");
            //
            stbuilder.Append(codeBuilder.ToString());
        }
Example #8
0
 public bool Insert(TypePlan type)
 {
     using (IDbConnection db = new SqlConnection(ConnectionString))
     {
         if (db.State == ConnectionState.Closed)
         {
             db.Open();
         }
         int result = db.Execute(@"INSERT INTO type_plans(name,description)
                     VALUES(@NAME, @DESCRIPTION)", type);
         return(result > 0);
     }
 }
Example #9
0
        public TypePlan GetForId(int id)
        {
            TypePlan type = new TypePlan();

            using (IDbConnection db = new SqlConnection(ConnectionString))
            {
                if (db.State == ConnectionState.Closed)
                {
                    db.Open();
                }
                type = db.QueryFirst <TypePlan>("SELECT * FROM type_plans WHERE id = @Id", new { Id = id });
            }
            return(type);
        }
Example #10
0
        /// <summary>
        /// Parse a method from the XML file.
        /// </summary>
        /// <param name="methodNode">The node where the method data is found.</param>
        private void ParseMethod(XmlNode methodNode)
        {
            // Keep track of the number of methods read and processed.
            this.MethodCount++;

            // Extract the assembly and type information from the method node.  These are used to locate an object containing the
            // method.  That is, the server will use 'System.Reflection' to load an assembly with the 'assembly' name, load and
            // instantiate an object of 'type', then call the named method with the parameters listed.
            AssemblyPlan assembly = this.batch.Assemblies.Add(methodNode.Attributes["assembly"].Value);
            TypePlan     type     = assembly.Types.Add(methodNode.Attributes["type"].Value);

            // Create a method from the XML data and add it to the transaction.
            this.transaction.Methods.Add(type, LoadMethod(methodNode));
        }
Example #11
0
        public TypePlan GetForName(string name)
        {
            TypePlan type = new TypePlan();

            using (IDbConnection db = new SqlConnection(ConnectionString))
            {
                if (db.State == ConnectionState.Closed)
                {
                    db.Open();
                }
                type = db.QueryFirst <TypePlan>("SELECT * FROM type_plans WHERE name LIKE '%@Name%'",
                                                new { Name = name });
                return(type);
            }
        }
Example #12
0
        public void Create(string name, string description)
        {
            if (String.IsNullOrEmpty(name))
            {
                throw new Exception("Nome não pode ser nulo");
            }
            TypePlan type = new TypePlan();

            type.Name        = name;
            type.Description = description;
            var result = dao.Insert(type);

            if (result)
            {
                Console.WriteLine("Tipo inserido com sucesso");
            }
            else
            {
                throw new Exception("Tipo não pode ser inserido...");
            }
        }
Example #13
0
        /// <summary>
        /// Execute a command batch and synchronizes the client data model with the newer records from the server.
        /// </summary>
        public static void Execute(Batch batch)
        {
            // This 'try' block will insure that the mutual exclusion locks are released.
            try
            {
                // Make sure only one thread at a time tries to refresh the data model.
                ClientMarketData.clientDataMutex.WaitOne();

                // Switching credentials without exiting the application will force the data model to be cleared and the row
                // counting to begin at zero again.  That is, it effectively resets the client data model.
                if (ClientMarketData.isReset)
                {
                    ClientMarketData.isReset    = false;
                    ClientMarketData.rowVersion = 0;
                    ClientMarketData.Clear();
                }

                // IMPORTANT CONCEPT: The rowVersion keeps track of the state of the client in-memory database. The server
                // returns a value for us to use on the next cycle.
                long rowVersion = ClientMarketData.rowVersion;

                // IMPORTANT CONCEPT:  Executing the 'GetClientMarketData' with a rowVersion returns to the client a DataSet
                // with only records that are the same age or younger than the rowVersion. This reduces the traffic on the
                // network to include only the essential records.  We are also merging it with the current ClientMarketData,
                // which adds new records and records that were deleted by the server.
                AssemblyPlan    assembly            = batch.Assemblies.Add("Server Market Data");
                TypePlan        type                = assembly.Types.Add("MarkThree.Guardian.Server.ServerMarketData");
                TransactionPlan transaction         = batch.Transactions.Add();
                MethodPlan      method              = transaction.Methods.Add(type, "Reconcile");
                Parameter       rowVersionParameter = method.Parameters.Add(new InputParameter("rowVersion", rowVersion));

                // Execute the the command to get the incremental changes from the server.
                WebTransactionProtocol.Execute(batch);

                // This is the updated data model information returned from the server.
                ArrayList reconciledData = (ArrayList)method.Parameters.Return.Value;

                // Optimization: Don't merge the results if there's nothing to merge.
                if (reconciledData != null)
                {
                    // IMPORTANT CONCEPT: Since the results will still be on the server if the client misses a refresh
                    // cycle, we take the attitude that thBzis update process doesn't have to wait for locks. That is, if we
                    // can't get all the tables locked quickly, we'll just wait until the next refresh period to get the
                    // results. This effectively prevents deadlocking on the client. Make sure all the tables are locked
                    // before populating them.
                    foreach (TableLock tableLock in ClientMarketData.TableLocks)
                    {
                        tableLock.AcquireWriterLock(ClientTimeout.LockWait);
                    }

                    // IMPORTANT CONCEPT: This broadcast can be used to set up conditions for the data event handlers. Often,
                    // optimizing algorithms will be used to consolidate the results of a merge.  This will allow the event
                    // driven logic to clear previous results and set up initial states for handling the bulk update of data.
                    ClientMarketData.OnBeginMerge(typeof(ClientMarketData));

                    // IMPORANT CONCEPT:  Once all the write locks have been obtained, we can merge the results.  This will
                    // trigger the events associated with the tables for updated and deleted rows.  Note that this 'Merge'
                    // method has different characteristics than the original one provided by Microsoft (that is, this one
                    // works).
                    ClientMarketData.rowVersion = MarketData.Merge(reconciledData);

                    // IMPORTANT CONCEPT: When the merge is complete, this will broadcast an event which allows optimization code
                    // to consolidate the results, examine the changed values and update reports based on the changed data.
                    ClientMarketData.OnEndMerge(typeof(ClientMarketData));
                }
            }
            finally
            {
                // No matter what happens above, we need to release the locks acquired above.
                foreach (TableLock tableLock in ClientMarketData.TableLocks)
                {
                    if (tableLock.IsWriterLockHeld)
                    {
                        tableLock.ReleaseWriterLock();
                    }
                }

                // Other threads can now request a refresh of the data model.
                ClientMarketData.clientDataMutex.ReleaseMutex();
            }

            // Throw a specialized exception if the server returned any errors in the Batch structure.
            if (batch.HasExceptions)
            {
                throw new BatchException(batch);
            }
        }
Example #14
0
        /// <summary>
        /// Marshals the data needed refuse a chance to negotiate a trade.
        /// </summary>
        /// <param name="parameter">The thread initialization data.</param>
        private void DeclineNegotiationThread(object parameter)
        {
            // Extract the thread parameters
            int matchId = (int)parameter;

            // This batch, if succesfully constructed, will be sent to the server to deline the negotiation.
            Batch batch = new Batch();

            try
            {
                // Lock the tables.
                System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked);
                ClientMarketData.MatchLock.AcquireReaderLock(ClientTimeout.LockWait);
                ClientMarketData.OrderTypeLock.AcquireReaderLock(ClientTimeout.LockWait);
                ClientMarketData.SecurityLock.AcquireReaderLock(ClientTimeout.LockWait);
                ClientMarketData.WorkingOrderLock.AcquireReaderLock(ClientTimeout.LockWait);

                // Find the Match record.
                ClientMarketData.MatchRow matchRow = ClientMarketData.Match.FindByMatchId(matchId);

                // Construct a command decline the negotiation.
                AssemblyPlan    assembly    = batch.Assemblies.Add("Core Service");
                TypePlan        type        = assembly.Types.Add("MarkThree.Guardian.Core.Negotiation");
                TransactionPlan transaction = batch.Transactions.Add();
                MethodPlan      method      = transaction.Methods.Add(type, "Insert");
                method.Parameters.Add(new InputParameter("matchId", matchId));
                method.Parameters.Add(new InputParameter("quantity", 0.0m));
                method.Parameters.Add(new InputParameter("statusCode", Status.Declined));
            }
            catch (Exception exception)
            {
                // Write the error and stack trace out to the debug listener
                EventLog.Error("{0}, {1}", exception.Message, exception.StackTrace);

                // This indicates that the batch shouldn't be executed.
                batch = null;
            }
            finally
            {
                // Release the locks.
                if (ClientMarketData.MatchLock.IsReaderLockHeld)
                {
                    ClientMarketData.MatchLock.ReleaseReaderLock();
                }
                if (ClientMarketData.OrderTypeLock.IsReaderLockHeld)
                {
                    ClientMarketData.OrderTypeLock.ReleaseReaderLock();
                }
                if (ClientMarketData.SecurityLock.IsReaderLockHeld)
                {
                    ClientMarketData.SecurityLock.ReleaseReaderLock();
                }
                if (ClientMarketData.WorkingOrderLock.IsReaderLockHeld)
                {
                    ClientMarketData.WorkingOrderLock.ReleaseReaderLock();
                }
                System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked);
            }

            // If the command batch was built successfully, then execute it.
            if (batch != null)
            {
                try
                {
                    // Call the web server to rename the object on the database.  Note that this method must be called when there
                    // are no locks to prevent deadlocking.  That is why it appears in it's own 'try/catch' block.
                    ClientMarketData.Execute(batch);
                }
                catch (BatchException batchException)
                {
                    // Write any server generated error messages to the event log.
                    foreach (Exception exception in batchException.Exceptions)
                    {
                        EventLog.Error("{0}, {1}", exception.Message, exception.StackTrace);
                    }
                }
            }
        }
Example #15
0
        public override void GenerateCode(CefCodeGenOutput output)
        {
            _cppHeaderExportFuncAuto            = output._cppHeaderExportFuncAuto;
            _cppHeaderInternalForExportFuncAuto = output._cppHeaderInternalForExportFuncAuto;


            //cpp
            CodeTypeDeclaration orgDecl         = this.OriginalDecl;
            CodeTypeDeclaration implTypeDecl    = this.ImplTypeDecl;
            CodeStringBuilder   totalTypeMethod = new CodeStringBuilder();

            if (implTypeDecl.Name.Contains("CppToC"))
            {
                _typePlan = orgDecl.TypePlan;
            }
            else
            {
                _typePlan = implTypeDecl.TypePlan;
            }

            //-----------------------------------------------------------------------
            List <MethodPlan> callToDotNetMets  = new List <MethodPlan>();
            CodeStringBuilder const_methodNames = new CodeStringBuilder();
            int maxPar = 0;
            int j      = _typePlan.methods.Count;

            for (int i = 0; i < j; ++i)
            {
                MethodPlan metTx = _typePlan.methods[i];
                metTx.CppMethodSwitchCaseName = orgDecl.Name + "_" + metTx.Name + "_" + (i + 1);
                //-----------------
                CodeMethodDeclaration codeMethodDecl = metTx.metDecl;
                if (codeMethodDecl.IsAbstract || codeMethodDecl.IsVirtual)
                {
                    callToDotNetMets.Add(metTx);
                }
                //-----------------

                if (metTx.pars.Count > maxPar)
                {
                    maxPar = metTx.pars.Count;
                }
                const_methodNames.AppendLine("const int " + metTx.CppMethodSwitchCaseName + "=" + (i + 1) + ";");
            }
            totalTypeMethod.AppendLine(const_methodNames.ToString());
            //-----------------------------------------------------------------------
            if (callToDotNetMets.Count > 0)
            {
                GenerateCppImplNamespace(orgDecl, callToDotNetMets, output._cppCode);
            }
            //-----------------------------------------------------------------------

            //C# part
            CsStructModuleCodeGen structModuleCodeGen = new CsStructModuleCodeGen();

            if (callToDotNetMets.Count > 0)
            {
                structModuleCodeGen.GenerateCsStructClass(orgDecl, callToDotNetMets, output._csCode, false);
            }

            //back to cpp again...
            CppToCsMethodArgsClassGen cppMetArgClassGen = new CppToCsMethodArgsClassGen();
            //------------------------------------------------------------------
            CodeStringBuilder cppArgClassStBuilder = new CodeStringBuilder();

            cppArgClassStBuilder.AppendLine("namespace " + orgDecl.Name + "Ext{");
            for (int i = 0; i < j; ++i)
            {
                MethodPlan met = _typePlan.methods[i];
                cppMetArgClassGen.GenerateCppMethodArgsClass(met, cppArgClassStBuilder);
            }
            cppArgClassStBuilder.AppendLine("}");
            _cppHeaderExportFuncAuto.Append(cppArgClassStBuilder.ToString());
            //------------------------------------------------------------------
        }
Example #16
0
        void GenerateCppCode(CodeStringBuilder stbuilder)
        {
#if DEBUG
            _dbug_cpp_count++;
#endif
            //
            //create switch table for C#-interop
            //
            CodeTypeDeclaration orgDecl      = this.OriginalDecl;
            CodeTypeDeclaration implTypeDecl = this.ImplTypeDecl;
            TypePlan            typeTxInfo   = implTypeDecl.Name.Contains("CppToC") ? orgDecl.TypePlan : implTypeDecl.TypePlan;
            //
            FindStaticMethods(orgDecl.TypePlan);
            //



            CppHandleCsMethodRequestCodeGen cppHandlerReqCodeGen = new CppHandleCsMethodRequestCodeGen();
            cppHandlerReqCodeGen.GenerateCppCode(this, orgDecl, implTypeDecl, this.UnderlyingCType, stbuilder);

            string namespaceName = orgDecl.Name + "Ext";
            int    j             = cppHandlerReqCodeGen.callToDotNetMets.Count;


            if (j > 0)
            {
                CodeStringBuilder const_methodNames = new CodeStringBuilder();
                //check if method has duplicate name or not
                //----------
                Dictionary <string, MethodPlan> uniqueNames = new Dictionary <string, MethodPlan>();
                foreach (MethodPlan met in cppHandlerReqCodeGen.callToDotNetMets)
                {
                    MethodPlan existingMet;
                    if (uniqueNames.TryGetValue(met.Name, out existingMet))
                    {
                        string met_capi_name = FindCApiName(met.metDecl);
                        string met_capi_nameOfExistingMet = FindCApiName(existingMet.metDecl);
                        if (met_capi_nameOfExistingMet == null && met_capi_name == null)
                        {
                            throw new NotSupportedException();
                        }
                        //rename both if possible
                        existingMet.HasDuplicatedMethodName = true;
                        if (met_capi_nameOfExistingMet != null)
                        {
                            existingMet.NewOverloadName = met_capi_nameOfExistingMet;
                        }
                        else
                        {
                            existingMet.NewOverloadName = existingMet.Name;
                        }
                        //
                        met.HasDuplicatedMethodName = true;
                        if (met_capi_name != null)
                        {
                            met.NewOverloadName = met_capi_name;
                        }
                        else
                        {
                            met.NewOverloadName = met.Name;
                        }
                    }
                    else
                    {
                        uniqueNames.Add(met.Name, met);
                    }
                }
                //-----------------------
                for (int i = 0; i < j; ++i)
                {
                    MethodPlan met = cppHandlerReqCodeGen.callToDotNetMets[i];
                    if (met.HasDuplicatedMethodName)
                    {
                        const_methodNames.AppendLine("const int " + namespaceName + "_" + met.NewOverloadName + "_" + (i + 1) + "=" + (i + 1) + ";");
                    }
                    else
                    {
                        const_methodNames.AppendLine("const int " + namespaceName + "_" + met.Name + "_" + (i + 1) + "=" + (i + 1) + ";");
                    }
                }



                //--------------
                CppInstanceImplCodeGen instanceImplCodeGen = new CppInstanceImplCodeGen();
                instanceImplCodeGen.GenerateCppImplClass(this,
                                                         typeTxInfo,
                                                         cppHandlerReqCodeGen.callToDotNetMets,
                                                         orgDecl,
                                                         stbuilder);
                cpp_callToDotNetMets = cppHandlerReqCodeGen.callToDotNetMets;
                //-----------------------------------------------------------
                CppToCsMethodArgsClassGen cppMetArgClassGen = new CppToCsMethodArgsClassGen();
                //
                CodeStringBuilder cppArgClassStBuilder = new CodeStringBuilder();
                cppArgClassStBuilder.AppendLine("namespace " + namespaceName + "{");

                for (int i = 0; i < j; ++i)
                {
                    MethodPlan met = cppHandlerReqCodeGen.callToDotNetMets[i];
                    cppMetArgClassGen.GenerateCppMethodArgsClass(met, cppArgClassStBuilder);
                }
                cppArgClassStBuilder.AppendLine("}");
                //----------------------------------------------
                _output._cppHeaderExportFuncAuto.Append(cppArgClassStBuilder.ToString());
                //----------------------------------------------
                //InternalHeaderForExportFunc.h
                CodeStringBuilder internalHeader = _output._cppHeaderInternalForExportFuncAuto;
                internalHeader.AppendLine("namespace " + namespaceName);
                internalHeader.AppendLine("{");
                internalHeader.AppendLine("const int _typeName=" + "CefTypeName_" + orgDecl.Name + ";");
                internalHeader.AppendLine(const_methodNames.ToString());
                internalHeader.AppendLine("}");
                //----------------------------------------------
            }
            if (staticMethods != null)
            {
                CppHandleCsMethodRequestCodeGen cppHandlerReqCodeGen2 = new CppHandleCsMethodRequestCodeGen();
                cppHandlerReqCodeGen2.GenerateCppCodeStatic(staticMethods, orgDecl, implTypeDecl, stbuilder);


                CodeStringBuilder const_methodNames = new CodeStringBuilder();
                //check if method has duplicate name or not

                for (int i = 0; i < j; ++i)
                {
                    MethodPlan met = cppHandlerReqCodeGen.callToDotNetMets[i];
                    const_methodNames.AppendLine("const int " + namespaceName + "_" + met.Name + "_" + (i + 1) + "=" + (i + 1) + ";");
                }

                //create static method for cpp type
                //in this version we don't create an custom impl of the class
                //-----------------------------------------------------------
                CppToCsMethodArgsClassGen cppMetArgClassGen = new CppToCsMethodArgsClassGen();
                //
                CodeStringBuilder cppArgClassStBuilder = new CodeStringBuilder();
                cppArgClassStBuilder.AppendLine("namespace " + namespaceName + "{");

                j = staticMethods.Count;
                for (int i = 0; i < j; ++i)
                {
                    MethodPlan met = staticMethods[i];
                    cppMetArgClassGen.GenerateCppMethodArgsClass(met, cppArgClassStBuilder);
                }
                cppArgClassStBuilder.AppendLine("}");
                //----------------------------------------------
                //generate cpp class
            }
        }
Example #17
0
        static int Main(string[] args)
        {
            // If this flag is set during the processing of the file, the program will exit with an error code.
            bool hasErrors = false;

            try
            {
                // Defaults
                batchSize     = 100;
                assemblyName  = "External Service";
                nameSpaceName = "MarkThree.Quasar.External";

                // The command line parser is driven by different states that are triggered by the flags read.  Unless a flag has been
                // read, the command line parser assumes that it's reading the file name from the command line.
                argumentState = ArgumentState.FileName;

                // Parse the command line for arguments.
                foreach (string argument in args)
                {
                    // Decode the current argument into a state change (or some other action).
                    if (argument == "-a")
                    {
                        argumentState = ArgumentState.Assembly; continue;
                    }
                    if (argument == "-b")
                    {
                        argumentState = ArgumentState.BatchSize; continue;
                    }
                    if (argument == "-n")
                    {
                        argumentState = ArgumentState.NameSpace; continue;
                    }
                    if (argument == "-i")
                    {
                        argumentState = ArgumentState.FileName; continue;
                    }

                    // The parsing state will determine which variable is read next.
                    switch (argumentState)
                    {
                    case ArgumentState.Assembly:
                        assemblyName = argument;
                        break;

                    case ArgumentState.BatchSize:
                        batchSize = Convert.ToInt32(argument);
                        break;

                    case ArgumentState.FileName:
                        fileName = argument;
                        break;

                    case ArgumentState.NameSpace:
                        nameSpaceName = argument;
                        break;
                    }

                    // The default state is to look for the input file name on the command line.
                    argumentState = ArgumentState.FileName;
                }

                // Throw a usage message back at the user if no file name was given.
                if (fileName == null)
                {
                    throw new Exception("Usage: Loader.Algorithm -i <FileName>");
                }

                // Open up the file containing all the broker.
                BrokerReader brokerReader = new BrokerReader(fileName);

                // Loading the database involves creating a batch of commands and sending them off as a transaction.  This gives
                // the server a chance to pipeline a large chunk of processing, without completely locking up the server for the
                // entire set of data.  This will construct a header for the command batch which gives information about which
                // assembly contains the class that is used to load the data.
                Batch           batch           = new Batch();
                TransactionPlan transactionPlan = batch.Transactions.Add();
                AssemblyPlan    assemblyPlan    = batch.Assemblies.Add(assemblyName);
                TypePlan        typePlan        = assemblyPlan.Types.Add(string.Format("{0}.{1}", nameSpaceName, "Broker"));

                // Read the file until an EOF is reached.
                while (true)
                {
                    // This counter keeps track of the number of records sent.  When the batch is full, it's sent to the server to be
                    // executed as a single transaction.
                    int batchCounter = 0;

                    // Read the next broker from the input stream.  A 'null' is returned when we've read past the end of file.
                    Broker broker = brokerReader.ReadBroker();
                    if (broker != null)
                    {
                        // Create a new method from the type information and the name found in the XML file.
                        MethodPlan methodPlan = new MethodPlan("Load");

                        // Construct a call to the 'Load' method to populate the broker record.
                        methodPlan.Parameters.Add(new InputParameter("brokerId", broker.Symbol));
                        methodPlan.Parameters.Add(new InputParameter("name", broker.Name));
                        methodPlan.Parameters.Add(new InputParameter("symbol", broker.Symbol));

                        // Create a method from the XML data and add it to the transaction.
                        transactionPlan.Methods.Add(typePlan, methodPlan);
                    }

                    // This will check to see if it's time to send the batch.  A batch is sent when the 'batchSize' has been
                    // reached, or if the last record has just been converted into a command.
                    if (++batchCounter % batchSize == 0 || broker == null)
                    {
                        WebTransactionProtocol.Execute(batch);

                        batch           = new Batch();
                        transactionPlan = batch.Transactions.Add();
                        assemblyPlan    = batch.Assemblies.Add(assemblyName);
                        typePlan        = assemblyPlan.Types.Add(string.Format("{0}.{1}", nameSpaceName, "Broker"));
                    }

                    // If the end of file was reached, break out of the loop and exit the application.
                    if (broker == null)
                    {
                        break;
                    }
                }
            }
            catch (BatchException batchException)
            {
                foreach (Exception exception in batchException.Exceptions)
                {
                    Console.WriteLine(exception.Message);
                }
                hasErrors = true;
            }
            catch (Exception exception)
            {
                // Show the system error and exit with an error.
                Console.WriteLine(exception.Message);
                hasErrors = true;
            }

            // Any errors will cause an abnormal exit.
            if (hasErrors)
            {
                return(1);
            }

            // Write a status message when a the file is loaded successfully.
            Console.WriteLine(String.Format("{0} Data: Brokers, Loaded", DateTime.Now.ToString("u")));

            // If we reached here, the file was imported without issue.
            return(0);
        }
Example #18
0
        /// <summary>
        /// Begins the task of applying the changes in the form to the data model.
        /// </summary>
        private void PostThread(object parameter)
        {
            // Extract the parameters from the threads parameter.
            object[]    parameters  = (object[])parameter;
            bool        exitDialog  = (bool)parameters[0];
            SourceOrder sourceOrder = (SourceOrder)parameters[1];

            // This batch will collect the information needed to execute a complex transaction on the server.  The first part of
            // the batch sets up the transaction: the assembly where the types and methods are found.  It also sets up a
            // transaction for a complex operation. In this case, the transaction is not that complex, just a single method to be
            // executed.
            Batch           batch       = new Batch();
            AssemblyPlan    assembly    = batch.Assemblies.Add("Trading Service");
            TypePlan        type        = assembly.Types.Add("MarkThree.Guardian.Trading.SourceOrder");
            TransactionPlan transaction = batch.Transactions.Add();
            MethodPlan      methodPlan  = transaction.Methods.Add(type, "Insert");

            // These are the parameters used to create a Source Order.  The Working Order will be created implicitly.
            methodPlan.Parameters.Add(new InputParameter("blotterId", this.blotter.BlotterId));
            methodPlan.Parameters.Add(new InputParameter("isBrokerMatch", sourceOrder.IsBrokerMatch));
            methodPlan.Parameters.Add(new InputParameter("isHedgeMatch", sourceOrder.IsHedgeMatch));
            methodPlan.Parameters.Add(new InputParameter("isInstitutionMatch", sourceOrder.IsInstitutionMatch));
            methodPlan.Parameters.Add(new InputParameter("submissionTypeCode", SubmissionType.UsePeferences));
            if (sourceOrder.MaximumVolatility != DBNull.Value)
            {
                methodPlan.Parameters.Add(new InputParameter("maximumVolatility", sourceOrder.MaximumVolatility));
            }
            if (sourceOrder.NewsFreeTime != DBNull.Value)
            {
                methodPlan.Parameters.Add(new InputParameter("newsFreeTime", sourceOrder.NewsFreeTime));
            }
            methodPlan.Parameters.Add(new InputParameter("orderedQuantity", sourceOrder.Quantity));
            methodPlan.Parameters.Add(new InputParameter("orderTypeCode", sourceOrder.OrderTypeCode));
            methodPlan.Parameters.Add(new InputParameter("priceTypeCode", PriceType.Market));
            methodPlan.Parameters.Add(new InputParameter("securityId", sourceOrder.SecurityId));
            methodPlan.Parameters.Add(new InputParameter("settlementId", sourceOrder.SettlementId));
            if (sourceOrder.StartTime != DBNull.Value)
            {
                methodPlan.Parameters.Add(new InputParameter("startTime", sourceOrder.StartTime));
            }
            if (sourceOrder.StopTime != DBNull.Value)
            {
                methodPlan.Parameters.Add(new InputParameter("stopTime", sourceOrder.StopTime));
            }
            methodPlan.Parameters.Add(new InputParameter("timeInForceCode", TimeInForce.Day));

            // This will execute the command on the server and return any exceptions.
            BatchException batchException = null;

            try
            {
                // Execute the batch.
                ClientMarketData.Execute(batch);
            }
            catch (BatchException exception)
            {
                // Any exceptions will be captured here and passed on to the foreground.
                batchException = exception;
            }

            // Call the foreground thread with the results of executing the batch on the server.  Also, in some cases the dialog is
            // going to be dismissed when the server data model has finished updating successfully.  Pass on the flag to the
            // foreground that will indicate whether the form is closed once the results are processed.
            BeginInvoke(this.postEndDelegate, new object[] { exitDialog, batchException });
        }
Example #19
0
        private void DeclineTrade(object parameter)
        {
            bool       isBatchValid = true;
            Batch      batch        = new Batch();
            MethodPlan method       = null;

            try
            {
                // Lock the tables.
                System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked);
                ClientMarketData.MatchLock.AcquireReaderLock(ClientTimeout.LockWait);
                ClientMarketData.OrderTypeLock.AcquireReaderLock(ClientTimeout.LockWait);
                ClientMarketData.SecurityLock.AcquireReaderLock(ClientTimeout.LockWait);
                ClientMarketData.WorkingOrderLock.AcquireReaderLock(ClientTimeout.LockWait);

                // Find the Match record.
                ClientMarketData.MatchRow matchRow = ClientMarketData.Match.FindByMatchId(this.matchId);

                AssemblyPlan    assembly    = batch.Assemblies.Add("Core Service");
                TypePlan        type        = assembly.Types.Add("MarkThree.Guardian.Core.Negotiation");
                TransactionPlan transaction = batch.Transactions.Add();
                method = transaction.Methods.Add(type, "Insert");
                method.Parameters.Add(new InputParameter("matchId", matchId));
                method.Parameters.Add(new InputParameter("quantity", 0.0m));
                method.Parameters.Add(new InputParameter("statusCode", Status.Declined));
            }
            catch (Exception exception)
            {
                // Write the error and stack trace out to the debug listener
                EventLog.Error("{0}, {1}", exception.Message, exception.StackTrace);

                // This indicates that the batch shouldn't be executed.
                isBatchValid = false;
            }
            finally
            {
                // Release the locks.
                if (ClientMarketData.MatchLock.IsReaderLockHeld)
                {
                    ClientMarketData.MatchLock.ReleaseReaderLock();
                }
                if (ClientMarketData.OrderTypeLock.IsReaderLockHeld)
                {
                    ClientMarketData.OrderTypeLock.ReleaseReaderLock();
                }
                if (ClientMarketData.SecurityLock.IsReaderLockHeld)
                {
                    ClientMarketData.SecurityLock.ReleaseReaderLock();
                }
                if (ClientMarketData.WorkingOrderLock.IsReaderLockHeld)
                {
                    ClientMarketData.WorkingOrderLock.ReleaseReaderLock();
                }
                System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked);
            }

            // If the command batch was built successfully, then execute it.  If any part of it should fail, cancel the edit and
            // display the server errors.
            if (isBatchValid)
            {
                try
                {
                    // Call the web server to rename the object on the database.  Note that this method must be called when there
                    // are no locks to prevent deadlocking.  That is why it appears in it's own 'try/catch' block.
                    ClientMarketData.Execute(batch);

                    this.negotiationId = (int)method.Parameters.Return.Value;
                }
                catch (BatchException batchException)
                {
                    // Display each error in the batch.
                    foreach (Exception exception in batchException.Exceptions)
                    {
                        Invoke(new MessageDelegate(ShowMessage), exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
Example #20
0
        /// <summary>
        /// Moves a child object from one parent to another.
        /// </summary>
        /// <param name="parameter">An array consiting of the target parent, the current parent and the child to be moved.</param>
        private void MoveChild(object parameter)
        {
            // Extract the objects selected by the drag-and-drop operation.
            object[] parameters = (object[])parameter;
            MarkThree.Guardian.Object toObject    = (MarkThree.Guardian.Object)parameters[0];
            MarkThree.Guardian.Object fromObject  = (MarkThree.Guardian.Object)parameters[1];
            MarkThree.Guardian.Object childObject = (MarkThree.Guardian.Object)parameters[2];

            try
            {
                // Lock the tables needed for this operation.
                System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked);
                ClientMarketData.ObjectLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.ObjectTreeLock.AcquireReaderLock(CommonTimeout.LockWait);

                // It's critical that circular references aren't created, either by accident or design.  First, find the object
                // record associated with the destination node.
                ClientMarketData.ObjectRow parentRow = ClientMarketData.Object.FindByObjectId(toObject.ObjectId);
                if (parentRow == null)
                {
                    throw new Exception("This object has been deleted");
                }

                // This is the object that is being dragged.  Find the row
                ClientMarketData.ObjectRow childRow = ClientMarketData.Object.FindByObjectId(childObject.ObjectId);
                if (childRow == null)
                {
                    throw new Exception("This object has been deleted");
                }

                // This will remove the possibility of a circular relationship.
                if (MarkThree.Guardian.Relationship.IsChildObject(childRow, parentRow))
                {
                    Invoke(new MessageDelegate(ShowMessage), Properties.Resources.CircularReferenceError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            catch (Exception exception)
            {
                // Write the error and stack trace out to the debug listener
                EventLog.Error("{0}, {1}", exception.Message, exception.StackTrace);
            }
            finally
            {
                // Release table locks.
                if (ClientMarketData.ObjectLock.IsReaderLockHeld)
                {
                    ClientMarketData.ObjectLock.ReleaseReaderLock();
                }
                if (ClientMarketData.ObjectTreeLock.IsReaderLockHeld)
                {
                    ClientMarketData.ObjectTreeLock.ReleaseReaderLock();
                }
                System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked);
            }

            // Any commands created below will be constructed in this object and sent to the server for execution.
            bool  isBatchValid = true;
            Batch batch        = new Batch();

            // If we made it here, the drag-and-drop is interpreted as a command to move a child from one parent to another.
            try
            {
                // Lock the tables needed for this operation.
                System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked);
                ClientMarketData.ObjectLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.ObjectTreeLock.AcquireReaderLock(CommonTimeout.LockWait);

                // Extract the primary identifiers from the user interface nodes.
                // This is the object that is being dragged.  Find the row
                ClientMarketData.ObjectRow childRow = ClientMarketData.Object.FindByObjectId(childObject.ObjectId);
                if (childRow == null)
                {
                    throw new Exception("This object has been deleted");
                }

                // Find the object in the data model and make sure it still exists.
                ClientMarketData.ObjectTreeRow objectTreeRow = null;
                foreach (ClientMarketData.ObjectTreeRow innerObjectTreeRow in childRow.GetObjectTreeRowsByObjectObjectTreeChildId())
                {
                    if (innerObjectTreeRow.ParentId == fromObject.ObjectId)
                    {
                        objectTreeRow = innerObjectTreeRow;
                    }
                }
                if (objectTreeRow == null)
                {
                    throw new Exception("This relationship has been deleted by someone else.");
                }

                // Moving a child object from one parent to another must be accomplished as a transaction.  Otherwise, an
                // orhpan object will be created if the operation fails midway through.
                TransactionPlan transaction = batch.Transactions.Add();
                AssemblyPlan    assembly    = batch.Assemblies.Add("Core Service");
                TypePlan        type        = assembly.Types.Add("MarkThree.Guardian.Core.ObjectTree");

                // Construct a command delete the old parent relation.
                MethodPlan deleteObjectTree = transaction.Methods.Add(type, "Update");
                deleteObjectTree.Parameters.Add(new InputParameter("objectTreeId", objectTreeRow.ObjectTreeId));
                deleteObjectTree.Parameters.Add(new InputParameter("parentId", toObject.ObjectId));
                deleteObjectTree.Parameters.Add(new InputParameter("childId", childObject.ObjectId));
                deleteObjectTree.Parameters.Add(new InputParameter("rowVersion", objectTreeRow.RowVersion));
            }
            catch (Exception exception)
            {
                // Write the error and stack trace out to the debug listener
                EventLog.Error("{0}, {1}", exception.Message, exception.StackTrace);

                // This indicates that the batch shouldn't be executed.
                isBatchValid = false;
            }
            finally
            {
                // Release table locks.
                if (ClientMarketData.ObjectLock.IsReaderLockHeld)
                {
                    ClientMarketData.ObjectLock.ReleaseReaderLock();
                }
                if (ClientMarketData.ObjectTreeLock.IsReaderLockHeld)
                {
                    ClientMarketData.ObjectTreeLock.ReleaseReaderLock();
                }
                System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked);
            }

            // If the command batch was built successfully, then execute it.
            if (isBatchValid)
            {
                try
                {
                    // Call the web server to rename the object on the database.  Note that this method must be called when there are
                    // no locks to prevent deadlocking.  That is why it appears in it's own 'try/catch' block.
                    ClientMarketData.Execute(batch);
                }
                catch (BatchException batchException)
                {
                    // Display each error in the batch.
                    foreach (Exception exception in batchException.Exceptions)
                    {
                        MessageBox.Show(exception.Message, "Guardian Error");
                    }
                }
            }
        }
Example #21
0
        /// <summary>
        /// Rename the object.
        /// </summary>
        /// <param name="parameters">The object to be renamed.</param>
        private void RenameObject(object parameter)
        {
            // Extract the thread arguments
            object[] parameters = (object[])parameter;
            TreeNode treeNode   = (TreeNode)parameters[0];
            string   name       = (string)parameters[1];

            // Extract the object that is associated with the TreeView node.
            MarkThree.Guardian.Object commonObject = (MarkThree.Guardian.Object)treeNode.Tag;

            // This command batch is constructed below and sent to the server for execution.  Note that the batch is designed to
            // live beyond the block of code that locks the data model.  This is to prevent the data model from being locked while
            // a relatively long server database operation is underway.
            bool  isBatchValid = true;
            Batch batch        = new Batch();

            try
            {
                // Lock the table
                System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked);
                ClientMarketData.ObjectLock.AcquireReaderLock(CommonTimeout.LockWait);

                // Find the object in the data model and make sure it still exists.
                ClientMarketData.ObjectRow objectRow = ClientMarketData.Object.FindByObjectId(commonObject.ObjectId);
                if (objectRow == null)
                {
                    throw new Exception("This object has been deleted.");
                }

                // Construct a command to rename the object.
                AssemblyPlan    assembly    = batch.Assemblies.Add("Core Service");
                TypePlan        type        = assembly.Types.Add("MarkThree.Guardian.Core.Object");
                TransactionPlan transaction = batch.Transactions.Add();
                MethodPlan      method      = transaction.Methods.Add(type, "Update");
                method.Parameters.Add(new InputParameter("rowVersion", objectRow.RowVersion));
                method.Parameters.Add(new InputParameter("objectId", objectRow.ObjectId));
                method.Parameters.Add(new InputParameter("name", name));
            }
            catch (Exception exception)
            {
                // This serves as an indication that the batch couldn't be constructed.
                isBatchValid = false;

                // Write the error and stack trace out to the debug listener
                EventLog.Error("{0}, {1}", exception.Message, exception.StackTrace);
            }
            finally
            {
                // Release table locks.
                if (ClientMarketData.ObjectLock.IsReaderLockHeld)
                {
                    ClientMarketData.ObjectLock.ReleaseReaderLock();
                }
                System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked);
            }

            // If the command batch was built successfully, then execute it.  If any part of it should fail, cancel the edit and
            // display the server errors.
            if (isBatchValid)
            {
                try
                {
                    // Call the web server to rename the object on the database.  Note that this method must be called when there
                    // are no locks to prevent deadlocking.  That is why it appears in it's own 'try/catch' block.
                    ClientMarketData.Execute(batch);
                }
                catch (BatchException batchException)
                {
                    // Display each error in the batch.
                    foreach (Exception exception in batchException.Exceptions)
                    {
                        Invoke(new MessageDelegate(ShowMessage), exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
Example #22
0
        /// <summary>
        /// Read, parse and load the stylesheet into the middle tier.
        /// </summary>
        public void Load()
        {
            // If this flag is set during the processing of the file, the program will exit with an error code.
            this.HasErrors = false;

            // If the user wants to specify a new URL and certificate, then prompt for the connection info the next time a
            // WebTransactionProtocol sends off a batch.
            if (this.ForceLogin)
            {
                WebTransactionProtocol.IsUrlPrompted        = true;
                WebTransactionProtocol.IsCredentialPrompted = true;
            }

            // Load up an XML document with the contents of the file specified on the command line.
            XmlDocument stylesheet = new XmlDocument();

            stylesheet.Load(this.FileName);

            // The XML document has several nodes that need to be read -- and then removed -- that contain attributes of the
            // stylesheet.  These nodes can be found easily using the XSL Path functions which need a namespace manager to sort out
            // the tag prefixes.
            XmlNamespaceManager namespaceManager = new XmlNamespaceManager(stylesheet.NameTable);

            namespaceManager.AddNamespace("xsl", "http://www.w3.org/1999/XSL/Transform");
            namespaceManager.AddNamespace("mts", "urn:schemas-markthreesoftware-com:stylesheet");

            // The spreadhseet source has several nodes which contain information about how the data in the XML document should be
            // loaded into the server, such as the stylesheet identifier, the name and the stylesheet style.  They are found at
            // this node.  After these information nodes have been read, they are removed from the stylesheet source.
            XmlNode stylesheetNode = stylesheet.SelectSingleNode("xsl:stylesheet", namespaceManager);

            if (stylesheetNode == null)
            {
                throw new Exception("Syntax Error: missing stylesheet declaration.");
            }

            // Find the StylesheetId node.
            XmlNode StylesheetIdNode = stylesheetNode.SelectSingleNode("mts:stylesheetId", namespaceManager);

            if (StylesheetIdNode == null)
            {
                throw new Exception("Syntax Error: missing StylesheetId declaration.");
            }

            // Find the StylesheetStyle node.
            XmlNode stylesheetTypeCodeNode = stylesheetNode.SelectSingleNode("mts:stylesheetTypeCode", namespaceManager);

            if (stylesheetTypeCodeNode == null)
            {
                throw new Exception("Syntax Error: missing StylesheetStyle declaration.");
            }

            // Find the name node.
            XmlNode nameNode = stylesheetNode.SelectSingleNode("mts:name", namespaceManager);

            if (nameNode == null)
            {
                throw new Exception("Syntax Error: missing name declaration.");
            }

            // Extract the data from the XML nodes.
            this.StylesheetId       = StylesheetIdNode.InnerText;
            this.StylesheetTypeCode = stylesheetTypeCodeNode.InnerText;
            this.StylesheetName     = nameNode.InnerText;

            // Remove the stylesheet nodes from the XSL spreadsheet before loading it into the server.
            stylesheetNode.RemoveChild(StylesheetIdNode);
            stylesheetNode.RemoveChild(stylesheetTypeCodeNode);
            stylesheetNode.RemoveChild(nameNode);

            // Create a command to load the stylesheet from the data loaded from the file.
            Batch           batch       = new Batch();
            TransactionPlan transaction = batch.Transactions.Add();
            AssemblyPlan    assembly    = batch.Assemblies.Add(this.Assembly);
            TypePlan        type        = assembly.Types.Add(this.Type);
            MethodPlan      method      = transaction.Methods.Add(type, this.Method);

            method.Parameters.Add(new InputParameter("stylesheetId", this.StylesheetId));
            method.Parameters.Add(new InputParameter("stylesheetTypeCode", this.StylesheetTypeCode));
            method.Parameters.Add(new InputParameter("name", this.StylesheetName));
            method.Parameters.Add(new InputParameter("text", stylesheet.InnerXml));

            try
            {
                // Create a new web client that will serve as the connection point to the server and call the web services to execute
                // the command batch.
                WebTransactionProtocol.Execute(batch);
            }
            catch (BatchException)
            {
                foreach (MethodPlan batchMethod in transaction.Methods)
                {
                    foreach (Exception exception in batchMethod.Exceptions)
                    {
                        Console.WriteLine(String.Format("{0}: {1}", method.Parameters["StylesheetId"].Value, exception.Message));
                    }
                }

                this.HasErrors = true;
            }
        }
Example #23
0
        public void GenerateBridge(string cefSrcFolder)
        {
            string cefDir = cefSrcFolder;
            List <CodeCompilationUnit> totalCuList_capi = new List <CodeCompilationUnit>();
            List <CodeCompilationUnit> totalCuList      = new List <CodeCompilationUnit>();
            List <CodeCompilationUnit> test_cpptoc_List = new List <CodeCompilationUnit>();
            //-----------------------------
            {
                //cpptoc folder
                string   libcef_dll_folder = cefDir + @"\libcef_dll";
                string[] onlyCppFiles      = System.IO.Directory.GetFiles(libcef_dll_folder + @"\cpptoc", "*.cc");
                //we skip some files
                Dictionary <string, bool> skipFiles = CreateSkipFiles(new string[] {
                    "base_ref_counted_cpptoc.cc",
                    "base_scoped_cpptoc.cc"
                });
                int j = onlyCppFiles.Length;

                for (int i = 0; i < j; ++i)
                {
                    if (skipFiles.ContainsKey(System.IO.Path.GetFileName(onlyCppFiles[i])))
                    {
                        continue;
                    }
                    CodeCompilationUnit cu = ParseCppFile(onlyCppFiles[i]);
                    test_cpptoc_List.Add(cu);

                    //
                    CppToCsImplCodeGen cppToCsImplCodeGen = new CppToCsImplCodeGen();
                    string             onlyFileName       = System.IO.Path.GetFileName(cu.Filename);
                    if (onlyFileName == "v8interceptor_cpptoc.cc")
                    {
                        continue;
                    }


                    //cppToCsImplCodeGen.PatchCppMethod(cu, cefDir + @"\libcef_dll\cpptoc\" + onlyFileName, cefDir + @"\cpptoc");
                    cppToCsImplCodeGen.PatchCppMethod(cu, null, libcef_dll_folder + @"\cpptoc");
                }
            }
            //-----------------------------

            //-----------------------------
            {
                //cef capi
                string[] onlyHeaderFiles            = System.IO.Directory.GetFiles(cefDir + @"\include\capi", "*.h");
                Dictionary <string, bool> skipFiles = CreateSkipFiles(new string[0]);
                int j = onlyHeaderFiles.Length;
                for (int i = 0; i < j; ++i)
                {
                    if (skipFiles.ContainsKey(System.IO.Path.GetFileName(onlyHeaderFiles[i])))
                    {
                        continue;
                    }
                    CodeCompilationUnit cu = Parse(onlyHeaderFiles[i]);
                    totalCuList_capi.Add(cu);
                }
            }
            {
                //cef capi/views
                string[] onlyHeaderFiles            = System.IO.Directory.GetFiles(cefDir + @"\include\capi\views", "*.h");
                Dictionary <string, bool> skipFiles = CreateSkipFiles(new string[0]);
                int j = onlyHeaderFiles.Length;
                for (int i = 0; i < j; ++i)
                {
                    if (skipFiles.ContainsKey(System.IO.Path.GetFileName(onlyHeaderFiles[i])))
                    {
                        continue;
                    }
                    CodeCompilationUnit cu = Parse(onlyHeaderFiles[i]);
                    totalCuList_capi.Add(cu);
                }
            }


            {
                //include/internal
                totalCuList.Add(Parse(cefDir + @"\include\internal\cef_types.h"));
                totalCuList.Add(Parse(cefDir + @"\include\internal\cef_types_wrappers.h"));
                totalCuList.Add(Parse(cefDir + @"\include\internal\cef_win.h")); //for windows
            }


            {
                //include folder
                string[] onlyHeaderFiles            = System.IO.Directory.GetFiles(cefDir + @"\include\", "*.h");
                Dictionary <string, bool> skipFiles = CreateSkipFiles(new string[0]);

                int j = onlyHeaderFiles.Length;
                for (int i = 0; i < j; ++i)
                {
                    if (skipFiles.ContainsKey(System.IO.Path.GetFileName(onlyHeaderFiles[i])))
                    {
                        continue;
                    }

                    CodeCompilationUnit cu = Parse(onlyHeaderFiles[i]);
                    totalCuList.Add(cu);
                }
            }

            //c to cpp
            {
                string[] onlyHeaderFiles            = System.IO.Directory.GetFiles(cefDir + @"\libcef_dll\ctocpp", "*.h");
                Dictionary <string, bool> skipFiles = CreateSkipFiles(new string[0]);

                int j = onlyHeaderFiles.Length;
                for (int i = 0; i < j; ++i)
                {
                    if (skipFiles.ContainsKey(System.IO.Path.GetFileName(onlyHeaderFiles[i])))
                    {
                        continue;
                    }
                    CodeCompilationUnit cu = Parse(onlyHeaderFiles[i]);
                    totalCuList.Add(cu);
                }
            }

            //cpp to c
            {
                string[] onlyHeaderFiles            = System.IO.Directory.GetFiles(cefDir + @"\libcef_dll\cpptoc", "*.h");
                Dictionary <string, bool> skipFiles = CreateSkipFiles(new string[0]);

                int j = onlyHeaderFiles.Length;
                for (int i = 0; i < j; ++i)
                {
                    if (skipFiles.ContainsKey(System.IO.Path.GetFileName(onlyHeaderFiles[i])))
                    {
                        continue;
                    }
                    CodeCompilationUnit cu = Parse(onlyHeaderFiles[i]);
                    totalCuList.Add(cu);
                }
            }

            //
            CefTypeCollection cefTypeCollection = new CefTypeCollection();

            cefTypeCollection.RootFolder = cefDir;
            cefTypeCollection.SetTypeSystem(totalCuList);



            //
            TypeTranformPlanner txPlanner = new TypeTranformPlanner();

            txPlanner.CefTypeCollection = cefTypeCollection;


            Dictionary <string, CefTypeTx> allTxPlans         = new Dictionary <string, CefTypeTx>();
            List <CefHandlerTx>            handlerPlans       = new List <CefHandlerTx>();
            List <CefCallbackTx>           callbackPlans      = new List <CefCallbackTx>();
            List <CefInstanceElementTx>    instanceClassPlans = new List <CefInstanceElementTx>();
            List <CefEnumTx>    enumTxPlans  = new List <CefEnumTx>();
            List <CefCStructTx> cstructPlans = new List <CefCStructTx>();
            //--

            //--
            int             typeName       = 1;
            List <TypePlan> typeTxInfoList = new List <TypePlan>();


            foreach (CodeTypeDeclaration typedecl in cefTypeCollection._v_instanceClasses)
            {
                //eg. CefApp, CefBrowser, CefCommandLine, CefFrame
                CefInstanceElementTx instanceClassPlan = new CefInstanceElementTx(typedecl);
                instanceClassPlans.Add(instanceClassPlan);
                allTxPlans.Add(typedecl.Name, instanceClassPlan);
                TypePlan typeTxPlan = txPlanner.MakeTransformPlan(typedecl);
                instanceClassPlan.CsInterOpTypeNameId = typeTxPlan.CsInterOpTypeNameId = typeName++;
                typedecl.TypePlan = typeTxPlan;
                typeTxInfoList.Add(typeTxPlan);
            }


            foreach (CodeTypeDeclaration typedecl in cefTypeCollection._v_handlerClasses)
            {
                //eg. CefDisplayHandler, CefDownloadHandler
                CefHandlerTx handlerPlan = new CefHandlerTx(typedecl);
                handlerPlans.Add(handlerPlan);
                allTxPlans.Add(typedecl.Name, handlerPlan);
                TypePlan typeTxPlan = txPlanner.MakeTransformPlan(typedecl);
                handlerPlan.CsInterOpTypeNameId = typeTxPlan.CsInterOpTypeNameId = typeName++;
                typedecl.TypePlan = typeTxPlan;
                typeTxInfoList.Add(typeTxPlan);
            }
            foreach (CodeTypeDeclaration typedecl in cefTypeCollection._v_callBackClasses)
            {
                //eg. CefAuthenCallback, CefPdfCallback
                CefCallbackTx callbackPlan = new CefCallbackTx(typedecl);
                callbackPlans.Add(callbackPlan);
                allTxPlans.Add(typedecl.Name, callbackPlan);
                ////
                TypePlan typeTxPlan = txPlanner.MakeTransformPlan(typedecl);
                callbackPlan.CsInterOpTypeNameId = typeTxPlan.CsInterOpTypeNameId = typeName++;
                typedecl.TypePlan = typeTxPlan;
                typeTxInfoList.Add(typeTxPlan);
            }
            //
            foreach (CodeTypeDeclaration typedecl in cefTypeCollection._enumClasses)
            {
                CefEnumTx enumTxPlan = new CefEnumTx(typedecl);
                enumTxPlans.Add(enumTxPlan);
                allTxPlans.Add(typedecl.Name, enumTxPlan);
                TypePlan typeTxPlan = txPlanner.MakeTransformPlan(typedecl);
                enumTxPlan.CsInterOpTypeNameId = typeTxPlan.CsInterOpTypeNameId = typeName++;
                typedecl.TypePlan = typeTxPlan;
            }

            List <CodeTypeDeclaration> notFoundAbstractClasses = new List <CodeTypeDeclaration>();

            foreach (CodeTypeDeclaration typedecl in cefTypeCollection.cToCppClasses)
            {
                TypePlan typeTxPlan = txPlanner.MakeTransformPlan(typedecl);
                typeTxPlan.CsInterOpTypeNameId = typeName++;
                typedecl.TypePlan = typeTxPlan;

                //cef -specific
                TemplateTypeSymbol3 baseType0 = (TemplateTypeSymbol3)typedecl.BaseTypes[0].ResolvedType;
                //add information to our model
                SimpleTypeSymbol abstractType      = (SimpleTypeSymbol)baseType0.Item1;
                SimpleTypeSymbol underlying_c_type = (SimpleTypeSymbol)baseType0.Item2;

                CefTypeTx found;
                if (!allTxPlans.TryGetValue(abstractType.Name, out found))
                {
                    notFoundAbstractClasses.Add(typedecl);
                    continue;
                }
                found.UnderlyingCType = underlying_c_type;
                found.ImplTypeDecl    = typedecl;

                abstractType.CefTxPlan = found;
                ////[chrome] cpp<-to<-c  <--- ::::: <--- c-interface-to[external - user - lib] ....
            }
            foreach (CodeTypeDeclaration typedecl in cefTypeCollection.cppToCClasses)
            {
                //callback, handle, visitor etc
                TypePlan typeTxPlan = txPlanner.MakeTransformPlan(typedecl);
                typeTxPlan.CsInterOpTypeNameId = typeName++;
                typedecl.TypePlan = typeTxPlan;
                //cef -specific
                TemplateTypeSymbol3 baseType0         = (TemplateTypeSymbol3)typedecl.BaseTypes[0].ResolvedType;
                SimpleTypeSymbol    abstractType      = (SimpleTypeSymbol)baseType0.Item1;
                SimpleTypeSymbol    underlying_c_type = (SimpleTypeSymbol)baseType0.Item2;
                CefTypeTx           found;
                if (!allTxPlans.TryGetValue(abstractType.Name, out found))
                {
                    notFoundAbstractClasses.Add(typedecl);
                    continue;
                }

                found.UnderlyingCType  = underlying_c_type;
                found.ImplTypeDecl     = typedecl;
                abstractType.CefTxPlan = found;

                ////[chrome]  cpp->to->c  ---> ::::: ---> c-interface-to [external-user-lib] ....
                ////eg. handlers and callbacks
            }
            //--------
            foreach (CodeTypeDeclaration typedecl in cefTypeCollection._plainCStructs)
            {
                //create raw type
                if (!typedecl.Name.EndsWith("Traits") &&
                    typedecl.Name.StartsWith("_"))
                {
                    //
                    CefCStructTx cstructTx = new CefCStructTx(typedecl);
                    cstructPlans.Add(cstructTx);
                    TypePlan typeTxPlan = txPlanner.MakeTransformPlan(typedecl);
                    cstructTx.CsInterOpTypeNameId = typeTxPlan.CsInterOpTypeNameId = typeName++;
                    typedecl.TypePlan             = typeTxPlan;
                    //
                    typeTxInfoList.Add(typeTxPlan);
                }
                else
                {
                }
            }

            //--------
            //code gen

            List <CefTypeTx> customImplClasses = new List <CefTypeTx>();
            StringBuilder    cppCodeStBuilder  = new StringBuilder();

            AddCppBuiltInBeginCode(cppCodeStBuilder);

            CodeStringBuilder cppHeaderInternalForExportFunc = new CodeStringBuilder();

            cppHeaderInternalForExportFunc.AppendLine(
                "//MIT, 2017, WinterDev\r\n" +
                "//AUTOGEN");


            foreach (TypePlan txinfo in typeTxInfoList)
            {
                cppHeaderInternalForExportFunc.AppendLine("const int CefTypeName_" + txinfo.TypeDecl.Name + " = " + txinfo.CsInterOpTypeNameId.ToString() + ";");
            }


            StringBuilder csCodeStBuilder = new StringBuilder();

            AddCsCodeHeader(csCodeStBuilder);
            CefCodeGenOutput codeGenOutput = null;

            foreach (CefTypeTx tx in enumTxPlans)
            {
                codeGenOutput = new CefCodeGenOutput();
                tx.GenerateCode(codeGenOutput);
                //get cs output
                csCodeStBuilder.Append(codeGenOutput._csCode.ToString());
            }
            csCodeStBuilder.Append("}"); //close namespace
            //save to file
            System.IO.File.WriteAllText("CefEnums.cs", csCodeStBuilder.ToString());

            //-------------------------
            CodeStringBuilder cppHeaderExportFuncAuto = new CodeStringBuilder();

            cppHeaderExportFuncAuto.AppendLine("//AUTOGEN");
            //-------------------------

            //cef instance is quite large
            //so we spit the code gen into 2 sections
            int instance_count = instanceClassPlans.Count;
            int mid            = instance_count / 2;

            {
                //1st part
                csCodeStBuilder = new StringBuilder();
                AddCsCodeHeader(csCodeStBuilder);
                //-------------------------
                for (int cc = 0; cc < mid; ++cc)
                {
                    CefInstanceElementTx tx = instanceClassPlans[cc];
                    codeGenOutput = new CefCodeGenOutput();
                    tx.GenerateCode(codeGenOutput);
                    //----------------------------------------------------
                    cppCodeStBuilder.AppendLine();
                    cppCodeStBuilder.AppendLine("// " + tx.OriginalDecl.ToString());
                    cppCodeStBuilder.Append(codeGenOutput._cppCode.ToString());
                    cppCodeStBuilder.AppendLine();
                    //----------------------------------------------------
                    csCodeStBuilder.AppendLine();
                    csCodeStBuilder.AppendLine("// " + tx.OriginalDecl.ToString());
                    csCodeStBuilder.Append(codeGenOutput._csCode.ToString());
                    csCodeStBuilder.AppendLine();
                    //--------------------------------------------

                    cppHeaderExportFuncAuto.Append(codeGenOutput._cppHeaderExportFuncAuto.ToString());
                    cppHeaderInternalForExportFunc.Append(codeGenOutput._cppHeaderInternalForExportFuncAuto.ToString());
                    //----------
                    if (tx.CppImplClassNameId > 0)
                    {
                        customImplClasses.Add(tx);
                    }
                }
                csCodeStBuilder.Append("}");
                //save to file
                System.IO.File.WriteAllText("CefInstances_P1.cs", csCodeStBuilder.ToString());
                //-------------------------
            }
            {
                //2nd part
                //1st part
                csCodeStBuilder = new StringBuilder();
                AddCsCodeHeader(csCodeStBuilder);

                for (int cc = mid; cc < instance_count; ++cc)
                {
                    CefInstanceElementTx tx = instanceClassPlans[cc];
                    codeGenOutput = new CefCodeGenOutput();
                    tx.GenerateCode(codeGenOutput);
                    //----------------------------------------------------
                    cppCodeStBuilder.AppendLine();
                    cppCodeStBuilder.AppendLine("// " + tx.OriginalDecl.ToString());
                    cppCodeStBuilder.Append(codeGenOutput._cppCode.ToString());
                    cppCodeStBuilder.AppendLine();
                    //----------------------------------------------------
                    csCodeStBuilder.AppendLine();
                    csCodeStBuilder.AppendLine("// " + tx.OriginalDecl.ToString());
                    csCodeStBuilder.Append(codeGenOutput._csCode.ToString());
                    csCodeStBuilder.AppendLine();
                    //--------------------------------------------

                    cppHeaderExportFuncAuto.Append(codeGenOutput._cppHeaderExportFuncAuto.ToString());
                    cppHeaderInternalForExportFunc.Append(codeGenOutput._cppHeaderInternalForExportFuncAuto.ToString());
                    //----------
                    if (tx.CppImplClassNameId > 0)
                    {
                        customImplClasses.Add(tx);
                    }
                }
                csCodeStBuilder.Append("}");
                //save to file
                System.IO.File.WriteAllText("CefInstances_P2.cs", csCodeStBuilder.ToString());
                //-------------------------
            }



            csCodeStBuilder = new StringBuilder();
            AddCsCodeHeader(csCodeStBuilder);
            foreach (CefCallbackTx tx in callbackPlans)
            {
                codeGenOutput = new CefCodeGenOutput();
                tx.GenerateCode(codeGenOutput);

                cppCodeStBuilder.Append(codeGenOutput._cppCode.ToString());
                csCodeStBuilder.Append(codeGenOutput._csCode.ToString());
                //----------
                cppHeaderExportFuncAuto.Append(codeGenOutput._cppHeaderExportFuncAuto.ToString());
                cppHeaderInternalForExportFunc.Append(codeGenOutput._cppHeaderInternalForExportFuncAuto.ToString());
                //----------
                if (tx.CppImplClassNameId > 0)
                {
                    customImplClasses.Add(tx);
                }
            }
            csCodeStBuilder.Append("}");
            //save to file
            System.IO.File.WriteAllText("CefCallbacks.cs", csCodeStBuilder.ToString());
            //-------------------------
            csCodeStBuilder = new StringBuilder();
            AddCsCodeHeader(csCodeStBuilder);
            foreach (CefHandlerTx tx in handlerPlans)
            {
                codeGenOutput = new CefCodeGenOutput();
                tx.GenerateCode(codeGenOutput);

                cppCodeStBuilder.Append(codeGenOutput._cppCode.ToString());
                csCodeStBuilder.Append(codeGenOutput._csCode.ToString());
                //----------
                cppHeaderExportFuncAuto.Append(codeGenOutput._cppHeaderExportFuncAuto.ToString());
                cppHeaderInternalForExportFunc.Append(codeGenOutput._cppHeaderInternalForExportFuncAuto.ToString());
                //----------
            }
            csCodeStBuilder.Append("}");
            //save to file
            System.IO.File.WriteAllText("CefHandlers.cs", csCodeStBuilder.ToString());
            //-------------------------
            csCodeStBuilder = new StringBuilder();
            AddCsCodeHeader(csCodeStBuilder);
            foreach (CefCStructTx tx in cstructPlans)
            {
                codeGenOutput = new CefCodeGenOutput();
                tx.GenerateCode(codeGenOutput);
                csCodeStBuilder.Append(codeGenOutput._csCode.ToString());
            }
            csCodeStBuilder.Append("}");
            //save to file
            System.IO.File.WriteAllText("CefPlainCStructs.cs", csCodeStBuilder.ToString());
            //-------------------------
            csCodeStBuilder = new StringBuilder();
            AddCsCodeHeader(csCodeStBuilder);
            CsNativeHandlerSwitchTableCodeGen csNativeHandlerSwitchTableCodeGen = new CsNativeHandlerSwitchTableCodeGen();

            csNativeHandlerSwitchTableCodeGen.GenerateCefNativeRequestHandlers(handlerPlans, csCodeStBuilder);
            //cs...
            csCodeStBuilder.AppendLine("}");
            System.IO.File.WriteAllText("CefApiSwitchTables.cs", csCodeStBuilder.ToString());
            //--------
            //cpp
            CppSwicthTableCodeGen cppSwitchTableCodeGen = new CppSwicthTableCodeGen();

            cppSwitchTableCodeGen.CreateCppSwitchTableForInstanceMethods(cppCodeStBuilder, instanceClassPlans);
            cppSwitchTableCodeGen.CreateCppSwitchTableForStaticMethods(cppCodeStBuilder, instanceClassPlans);
            //
            CppInstanceMethodCodeGen instanceMetCodeGen = new CppInstanceMethodCodeGen();

            instanceMetCodeGen.CreateCppNewInstanceMethod(cppCodeStBuilder, customImplClasses);
            //--------
            cppCodeStBuilder.AppendLine("/////////////////////////////////////////////////");
            //
        }
Example #24
0
        void GenerateCppCode(CodeStringBuilder stbuilder)
        {
#if DEBUG
            _dbug_cpp_count++;
#endif
            //
            //create switch table for C#-interop
            //
            CodeTypeDeclaration orgDecl      = this.OriginalDecl;
            CodeTypeDeclaration implTypeDecl = this.ImplTypeDecl;
            _typePlan = orgDecl.TypePlan;
            //-----------------------------------------------------------------------
            List <MethodPlan> onEventMethods = new List <MethodPlan>();

            int j      = _typePlan.methods.Count;
            int maxPar = 0;
            for (int i = 0; i < j; ++i)
            {
                MethodPlan metTx = _typePlan.methods[i];
                if (metTx.metDecl.IsVirtual)
                {
                    //this method need a callback to .net side (.net-side event listener)
                    if (metTx.metDecl.Name.StartsWith("On"))
                    {
                        onEventMethods.Add(metTx);
                    }
                }
                metTx.CppMethodSwitchCaseName = orgDecl.Name + "_" + metTx.Name + "_" + (i + 1);
                if (metTx.pars.Count > maxPar)
                {
                    maxPar = metTx.pars.Count;
                }
            }

            MaxMethodParCount = maxPar;
            //----------
            CppHandleCsMethodRequestCodeGen cppHandleCsMetCodeGen2 = new CppHandleCsMethodRequestCodeGen();
            cppHandleCsMetCodeGen2.PrepareInstanceCallFromCppToCsMethodName(
                this,
                orgDecl,
                ImplTypeDecl,
                this.UnderlyingCType);
            //
            cppHandleCsMetCodeGen2.GenerateCppCode(
                this,
                orgDecl,
                ImplTypeDecl,
                this.UnderlyingCType,
                stbuilder
                );

            //----------
            if (onEventMethods.Count > 0)
            {
                //the callback need some method to call to C# side
                var eventListenerCodeGen = new CppEventListenerInstanceImplCodeGen();
                eventListenerCodeGen.GenerateCppImplClass(
                    this,
                    _typePlan,
                    orgDecl,
                    onEventMethods,
                    stbuilder);
            }
        }