Ejemplo n.º 1
0
 public void Write(RedisClient client, PipeStream stream)
 {
     if (ValueBuffer != null)
     {
         stream.Write(ValueBuffer, 0, ValueBuffer.Length);
     }
     else if (Serialize && DataFormater != null)
     {
         DataFormater.SerializeObject(Value, client, stream);
     }
     else
     {
         string value = Value as string;
         if (value == null)
         {
             value = Value.ToString();
         }
         if (mBuffer == null)
         {
             mBuffer = new byte[1024 * 1024];
         }
         int len  = Encoding.UTF8.GetBytes(value, 0, value.Length, mBuffer, 0);
         var data = GetBodyHeaderLenData(len);
         if (data != null)
         {
             stream.Write(data, 0, data.Length);
         }
         else
         {
             stream.Write($"${len}\r\n");
         }
         stream.Write(mBuffer, 0, len);
     }
     stream.Write(LineBytes, 0, 2);
 }
Ejemplo n.º 2
0
 public IList <Q> Execute()
 {
     try
     {
         IList <Q> list  = new List <Q>();
         string    query = queryMap.CurrentQuery;
         queryMap.CurrentQuery = queryMap.Query;
         using (IDbCommand command = CreateCommand(query))
         {
             using (IDataReader reader = command.ExecuteReader())
             {
                 while (reader.Read())
                 {
                     Q entity = Activator.CreateInstance(queryMap.Type) as Q;
                     foreach (var keyValueColumn in queryMap.ColumnNames)
                     {
                         var          value    = reader[keyValueColumn.Key];
                         PropertyInfo property = queryMap.Type.GetProperty(keyValueColumn.Key);
                         property.SetValue(entity, DataFormater.ParseToData(property, value));
                     }
                     list.Add(entity);
                 }
                 reader.Close();
                 reader.Dispose();
                 command.Dispose();
             }
         }
         return(list);
     }
     catch
     {
         throw;
     }
 }
Ejemplo n.º 3
0
        IList <V> Execute(string sql)
        {
            try
            {
                IList <V> list = Activator.CreateInstance(typeof(List <>).MakeGenericType(viewQuery.ViewMap.Type)) as IList <V>;
                using (IDbCommand command = CreateCommand(sql))
                {
                    using (IDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            V entity = Activator.CreateInstance(viewQuery.ViewMap.Type) as V;
                            foreach (var keyValueColumn in viewQuery.ViewMap.ColumnNames)
                            {
                                var          value    = reader[keyValueColumn.Key];
                                PropertyInfo property = viewQuery.ViewMap.Type.GetProperty(keyValueColumn.Key);
                                property.SetValue(entity, DataFormater.ParseToData(property, value));
                            }
                            list.Add(entity);
                        }
                        reader.Close();
                        reader.Dispose();
                        command.Dispose();
                    }
                }

                return(list);
            }
            catch
            {
                throw;
            }
        }
Ejemplo n.º 4
0
 public bool Save(T entity)
 {
     try
     {
         string sql = Persist.Insert(entity);
         using (IDbCommand command = CreateCommand(sql))
         {
             if (command.ExecuteNonQuery() > 0)
             {
                 if (!string.IsNullOrEmpty(Query.EntityMap.PrimaryKeyName))
                 {
                     if (Query.EntityMap.IsAutoincrement)
                     {
                         command.CommandText = "SELECT LAST_INSERT_ID() AS Id;";
                         string       res      = command.ExecuteScalar() + "";
                         int          id       = int.Parse(res);
                         PropertyInfo property = Query.EntityMap.Type.GetProperty(Query.EntityMap.PrimaryKeyName);
                         property.SetValue(entity, DataFormater.ParseToData(property, id));
                     }
                 }
                 command.Dispose();
                 return(true);
             }
             else
             {
                 command.Dispose();
                 return(false);
             }
         }
     }
     catch
     {
         throw;
     }
 }
Ejemplo n.º 5
0
        void FillEntities(object entity)
        {
            Type       type = entity.GetType();
            IEntityMap entityMap;

            Cfg.Configuration.Mappings.TryGetValue(type.Name, out entityMap);
            foreach (var keyValuePair in entityMap.Entities)
            {
                if (CurrentType != keyValuePair.Value.Type && !keyValuePair.Value.Type.IsEnum)
                {
                    IEntityMap foreignEntity = keyValuePair.Value;
                    object     obj           = type.GetProperty(keyValuePair.Key).GetValue(entity);
                    if (obj != null)
                    {
                        if (!string.IsNullOrEmpty(foreignEntity.PrimaryKeyName))
                        {
                            object id  = foreignEntity.Type.GetProperty(foreignEntity.PrimaryKeyName).GetValue(obj);
                            string sql = foreignEntity.ForeignSelect + "WHERE _this." + foreignEntity.PrimaryKeyName + " = " + DataFormater.ParseToSQL(id) + ";";
                            foreach (var keyValue in foreignEntity.Entities)
                            {
                                IEntityMap map = keyValue.Value;
                                using (IDbCommand command = CreateCommand(sql))
                                {
                                    using (IDataReader reader = command.ExecuteReader())
                                    {
                                        if (reader.Read())
                                        {
                                            object o = Activator.CreateInstance(map.Type);
                                            foreach (var kv in map.ColumnNames)
                                            {
                                                string propertyName = kv.Key;
                                                var    value        = reader[keyValue.Key + "." + propertyName];
                                                propertyName = propertyName.Replace(keyValue.Key + ".", "");
                                                PropertyInfo property = map.Type.GetProperty(propertyName);
                                                property.SetValue(o, DataFormater.ParseToData(property, value));
                                            }

                                            foreignEntity.Type.GetProperty(keyValue.Key).SetValue(obj, o);
                                            reader.Close();
                                            reader.Dispose();
                                            command.Dispose();
                                            FillEntities(o);
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                        }
                    }
                }
                else
                {
                    // la entidad es del mismo tipo que T
                }
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Méthode appelant l'envoi de résultats à tous les clients connectés
 /// </summary>
 /// <param name="input">Objet de trasnfert contenant les résultats</param>
 private void SendDataToAllClients(DataInput input)
 {
     DataFormater.Serialize(input);
     /* Multi Client */
     foreach (var node in Clients)
     {
         SendData(node.Value, input);
     }
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Métode appelant l'envoi de données à tous les noeuds connectés
 /// </summary>
 /// <param name="input">Objet de trasnfert contenant les données</param>
 public void SendDataToAllNodes(DataInput input)
 {
     DataFormater.Serialize(input);
     /* Multi Client */
     foreach (var node in Nodes)
     {
         SendData(node.Value, input);
     }
 }
Ejemplo n.º 8
0
        static bool LoadANN(string annfilePath, DataFormater dfr)
        {
            bool finalresult = false;

            if (Equals(dfr, null))
            {
                Console.WriteLine("No data !!!");
            }

            var ann = new NeuralNetworkEngineEO();

            bool loaded = ann.LoadNeuralNetwork(annfilePath);

            Console.WriteLine("ANN loading = {0}", loaded);

            if (Object.Equals(ann, null))
            {
                Console.WriteLine("I can not open Neural network file !!!");
            }
            var learning_out = ann.Compute(dfr.TrainingInput);
            var testing_out  = ann.Compute(dfr.TestingInput);


            string filePath = string.Format("C:\\SSL\\ANN_Results_at_{0}.csv", DateTime.Now.Minute.ToString());

            using (FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate))
            {
                using (StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.UTF8))
                {
                    System.Text.StringBuilder strb = new System.Text.StringBuilder();

                    strb.AppendLine("Learning_Outputs;");

                    for (int i = 0; i < learning_out.Length; i++)
                    {
                        strb.Append(learning_out[i][0]).AppendLine(";");
                    }

                    strb.AppendLine("*****************************************;");
                    strb.AppendLine("Testing_Outputs;");

                    for (int i = 0; i < testing_out.Length; i++)
                    {
                        strb.Append(testing_out[i][0]).AppendLine(";");
                    }

                    sw.Write(strb.ToString());
                    sw.Flush();
                    sw.Close();
                    fs.Close();
                    finalresult = true;
                }
            }

            return(finalresult);
        }
Ejemplo n.º 9
0
 public T Find(object id)
 {
     try
     {
         Type type = typeof(T);
         CurrentType = type;
         T      entity = null;
         string sql    = Query.Find(id);
         using (IDbCommand command = CreateCommand(sql))
         {
             using (IDataReader reader = command.ExecuteReader())
             {
                 if (reader.Read())
                 {
                     entity = Activator.CreateInstance(type) as T;
                     foreach (var keyValueColumn in Query.EntityMap.ColumnNames)
                     {
                         var          value    = reader["_this." + keyValueColumn.Key];
                         PropertyInfo property = type.GetProperty(keyValueColumn.Key);
                         property.SetValue(entity, DataFormater.ParseToData(property, value));
                     }
                     foreach (var keyValuePair in Query.EntityMap.Entities)
                     {
                         object obj = Activator.CreateInstance(keyValuePair.Value.Type);
                         foreach (var keyValueColumn in keyValuePair.Value.ColumnNames)
                         {
                             var          value    = reader[keyValuePair.Key + "." + keyValueColumn.Key];
                             PropertyInfo property = keyValuePair.Value.Type.GetProperty(keyValueColumn.Key);
                             property.SetValue(obj, DataFormater.ParseToData(property, value));
                         }
                         Query.EntityMap.Type.GetProperty(keyValuePair.Key).SetValue(entity, obj);
                     }
                 }
                 reader.Close();
                 reader.Dispose();
                 command.Dispose();
             }
         }
         if (entity != null)
         {
             FillEntities(entity);
             FillCollections(entity);
         }
         return(entity);
     }
     catch
     {
         throw;
     }
 }
Ejemplo n.º 10
0
        public V UniqueResult()
        {
            V entity = default(V);

            try
            {
                if (string.IsNullOrEmpty(currentQuery))
                {
                    currentQuery = viewQuery.ViewMap.Query + " LIMIT 1;";
                }
                else
                {
                    currentQuery += " LIMIT 1;";
                }
                string sql = currentQuery;
                currentQuery = null;
                using (IDbCommand command = CreateCommand(sql))
                {
                    using (IDataReader reader = command.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            entity = Activator.CreateInstance(viewQuery.ViewMap.Type) as V;
                            foreach (var keyValueColumn in viewQuery.ViewMap.ColumnNames)
                            {
                                var          value    = reader[keyValueColumn.Key];
                                PropertyInfo property = viewQuery.ViewMap.Type.GetProperty(keyValueColumn.Key);
                                property.SetValue(entity, DataFormater.ParseToData(property, value));
                            }
                        }
                        reader.Close();
                        reader.Dispose();
                        command.Dispose();
                    }
                }
                return(entity);
            }
            catch
            {
                throw;
            }
        }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello SVR!");

            //string file = @"C:\Users\SD\Documents\Dataset_ANN_SVR\DataSet_Ex.csv";
            //string file = @"C:\Users\SD\Documents\Dataset_ANN_SVR\DataSet_Exemple.csv";

            //string file = @"C:\Users\SD\Documents\Dataset_ANN_SVR\DataSet_ExempleSinX.csv";

            //QC_Sidi_Aissa SSL :
            //string file = @"C:\Users\SD\Documents\Dataset_ANN_SVR\QC_Sidi_Aissa.csv";

            //Beni-Bahdel_Dame_3Q :
            //string file = @"C:\Users\SD\Documents\Dataset_ANN_SVR\Beni-Bahdel_Dame_3Q.csv";

            //Station_Ain_El_Assel_Dataset_Pf(Q) :
            string file = @"C:\Users\SD\Documents\Dataset_ANN_SVR\Station_Ain_El_Assel_Dataset_Pf(Q).csv";

            LoadData(file);

            df = new DataFormater(DataSet);
            df.TrainingPourcentage = 70;

            df.Format(6, 0, 1, 2, 3, 4, 5);

            Console.WriteLine("LearnIn = {0}, LearnOut = {1}, TestIn = {2}, TestOut = {3}", df.TrainingInput.Length, df.TrainingOutput.Length, df.TestingInput.Length, df.TestingOutput.Length);


            if (!Equals(df.TrainingInput, null))
            {
                Console.WriteLine("Training = {0}", df.TrainingInput.Length);
            }

            // Luanch EOSVR with EOAlgo params.
            int n    = 5;
            int kmax = 1;

            LaunchEOSVR(n, kmax);
        }
Ejemplo n.º 12
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello SVR & ANN!");

            // //string file = @"C:\Users\SD\Documents\Dataset_ANN_SVR\DataSet_Ex.csv";
            // //string file = @"C:\Users\SD\Documents\Dataset_ANN_SVR\DataSet_Exemple.csv";

            //string file = @"C:\Users\SD\Documents\Dataset_ANN_SVR\DataSet_ExempleSinX.csv";

            // //QC_Sidi_Aissa SSL :
            //string file = @"C:\Users\SD\Documents\Dataset_ANN_SVR\QC_Sidi_Aissa.csv";
            //string file = @"C:\Users\SD\Documents\Dataset_ANN_SVR\QC_Sidi_Aissa_Standards.csv";

            // //Beni-Bahdel_Dame_3Q :
            // //string file = @"C:\Users\SD\Documents\Dataset_ANN_SVR\Beni-Bahdel_Dame_3Q.csv";

            // //Station_Ain_El_Assel_Dataset_Pf(Q) :
            // //string file = @"C:\Users\SD\Documents\Dataset_ANN_SVR\Station_Ain_El_Assel_Dataset_Pf(Q).csv";
            //string file = @"C:\Users\SD\Documents\Dataset_ANN_SVR\Station_Ain_El_Assel_Dataset_Pf(Q)_Standard.csv";
            // string file = @"C:\Users\SD\Documents\Dataset_ANN_SVR\Station_Ain_El_Assel_Dataset_1_Standard.csv";

            ////QC_Sidi_Aissa SSL :
            //string file = @"C:\SSL\QC_Sidi_Aissa.csv";
            // string file = @"C:\Users\SD\Documents\Dataset_ANN_SVR\QC_Sidi_Aissa_Standards.csv";


            string file = string.Empty;

            while (file == string.Empty || System.IO.File.Exists(file) == false)
            {
                Console.WriteLine("Saisir le nom de fichier des données (dans le dossier : C:\\SSL) (n'oublier pas de standardiser les données)");
                fileName = Console.ReadLine();
                file     = string.Format("C:\\SSL\\{0}.csv", fileName.Trim());
            }

            LoadData(file);

            df = new DataFormater(DataSet);
            df.TrainingPourcentage = 70;

            df.Format(1, 0);

            // Console.WriteLine("LearnIn = {0}, LearnOut = {1}, TestIn = {2}, TestOut = {3}",df.TrainingInput.Length, df.TrainingOutput.Length, df.TestingInput.Length, df.TestingOutput.Length );

            //if (!Equals(df.TrainingInput, null)) { Console.WriteLine("Training = {0}", df.TrainingInput.Length); }

            // // Luanch EOSVR with EOAlgo params.

            Console.WriteLine("Would you compute using EXISTING ANN ???? (type y if YES)");
            string answer = Console.ReadLine().Trim();

            if (Equals(answer, "y") || Equals(answer, "Y"))
            {
                Console.WriteLine("Saisir le chemin complet de fichier du réseau.");
                fileName = Console.ReadLine();
                bool saved = LoadANN(fileName, df);
                Console.WriteLine("Computation & saving operations : {0}", saved);
            }
            else
            {
                int n = 2;

                int kmax = 2;

                Console.WriteLine("Saisir la taille de la population de recherche < N > (nombre entier > 1):");

                if (!int.TryParse(Console.ReadLine(), out n))
                {
                    n = 2;
                }

                Console.WriteLine("Saisir le nombre d'itérations < Kmax > (nombre entier > 0):");

                if (!int.TryParse(Console.ReadLine(), out kmax))
                {
                    kmax = 2;
                }

                Console.WriteLine("Computation by : N = {0}, Kmax={1}", n, kmax);

                Console.WriteLine("Voulez-vous lancer le EO-SVR ?(if YES , type y; n if NO):");

                var ans = Console.ReadLine();

                if (ans == "y" || ans == "yes")
                {
                    LaunchEOSVR(n, kmax);

                    Console.WriteLine("_______________________________________________________________________");
                }

                Console.WriteLine("Voulez-vous lancer le EO-ANN ?(if YES , type y; n if NO):");

                ans = Console.ReadLine();

                if (ans == "y" || ans == "yes")
                {
                    Console.WriteLine("Choisir l'algorithme d'apprentissage (0 : Backpropagation, 1 : Levenberg-Marquardt)");

                    int learnAlgo = int.Parse(Console.ReadLine());
                    if (learnAlgo == 0 || learnAlgo == 1)
                    {
                        LaunchANNEO(df, n, kmax, learnAlgo);
                    }

                    //LaunchANN(df.TrainingInput, df.TrainingOutput);
                }

                Console.WriteLine("Taper f pour fermer");
                string cmd = Console.ReadLine();
                while (cmd != "f")
                {
                    Console.WriteLine("Taper f pour fermer");
                    cmd = Console.ReadLine();
                }
            }
        }
Ejemplo n.º 13
0
        static void LaunchANNEO(DataFormater dfr, int n, int kmax, int learnAlgo)
        {
            int minHLNeurones = 1;
            int maxHLNeurones = 15;
            int kminL         = 40;
            int kmaxL         = 200;

            if (learnAlgo == 0)
            {
                kminL = 10000;
                kmaxL = 21000;
            }

            var ranges = new List <MonoObjectiveEOALib.Range>
            {
                new MonoObjectiveEOALib.Range("Activation Function", 0.9, 2.1),
                new MonoObjectiveEOALib.Range("Alpha of Activation Function", 0.1, 10),
                new MonoObjectiveEOALib.Range("Learning rate", 0.05, 0.1),
                new MonoObjectiveEOALib.Range("Momentum/Ajustement", 10, 12),
                new MonoObjectiveEOALib.Range("Learning Err", 0.001, 0.01),
                new MonoObjectiveEOALib.Range("Max Iteration (Kmax)", kminL, kmaxL),
                new MonoObjectiveEOALib.Range("Hiden Layer Number", 1, 5),
                new MonoObjectiveEOALib.Range("Layer 1 Nodes count", minHLNeurones, maxHLNeurones),
                new MonoObjectiveEOALib.Range("Layer 2 Nodes count", minHLNeurones, maxHLNeurones),
                new MonoObjectiveEOALib.Range("Layer 3 Nodes count", minHLNeurones, maxHLNeurones),
                new MonoObjectiveEOALib.Range("Layer 4 Nodes count", minHLNeurones, maxHLNeurones),
                new MonoObjectiveEOALib.Range("Layer 5 Nodes count", minHLNeurones, maxHLNeurones),
                new MonoObjectiveEOALib.Range("Layer 6 Nodes count", minHLNeurones, maxHLNeurones)
            };

            EANN annEo = new EANN(dfr.TrainingInput, dfr.TrainingOutput, dfr.TestingInput, dfr.TestingOutput);

            annEo.Learning_Algorithm = (LearningAlgorithmEnum)learnAlgo;// LearningAlgorithmEnum.LevenbergMarquardtLearning;

            annEo.SearchRanges = ranges;

            annEo.MaxOptimizationIterations = kmax;
            annEo.PopulationSize            = n;

            annEo.LearnEO();

            Console.WriteLine("EO-ANN :-> Best learning scroe = {0} ; EO-ANN :-> Best testing score = {1}", annEo.BestLearningScore, annEo.BestTestingScore);

            foreach (var itm in annEo.BestChart)
            {
                Console.WriteLine(itm);
            }

            SaveResults(annEo, string.Format("C:\\SSL\\Results_ANN_{0}.txt", fileName.Trim()));

            //double[][] xy = new double[][]
            // {
            //   new double []{ 0.8},
            //   new double []{0.16},
            //   new double []{0.24},
            //   new double []{0.35},
            //   new double []{0.25}
            // };

            //double[][] xy = new double[][]
            //{
            //   new double []{0.8, 0.12},
            //   new double []{0.16, 0.10},
            //   new double []{0.24, 0.26},
            //   new double []{0.35, 0.10},
            //   new double []{0.25, 0.12}
            //};

            //var z = annEo.Compute(xy);

            //if (Equals(z, null)) { return; }
            //foreach (double value in z)
            //{
            //    Console.WriteLine("z = {0}", Math.Round(value, 3));
            //}
        }
Ejemplo n.º 14
0
        /// <summary>
        /// LUA结构支持
        /// </summary>
        /// <returns></returns>
        public override void GetLuaStruct(StringBuilder code)
        {
            base.GetLuaStruct(code);
            int idx;

            if (!string.IsNullOrWhiteSpace(PropertyName))
            {
                code.AppendLine($@"['PropertyName'] = '{PropertyName.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['PropertyName'] = nil,");
            }

            code.AppendLine($@"['IsCaption'] ={(IsCaption.ToString().ToLower())},");

            if (!string.IsNullOrWhiteSpace(Alias))
            {
                code.AppendLine($@"['Alias'] = '{Alias.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['Alias'] = nil,");
            }

            if (!string.IsNullOrWhiteSpace(Group))
            {
                code.AppendLine($@"['Group'] = '{Group.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['Group'] = nil,");
            }

            code.AppendLine($@"['CreateIndex'] ={(CreateIndex.ToString().ToLower())},");

            code.AppendLine($@"['IsPrimaryKey'] ={(IsPrimaryKey.ToString().ToLower())},");

            code.AppendLine($@"['IsExtendKey'] ={(IsExtendKey.ToString().ToLower())},");

            code.AppendLine($@"['IsIdentity'] ={(IsIdentity.ToString().ToLower())},");

            code.AppendLine($@"['IsGlobalKey'] ={(IsGlobalKey.ToString().ToLower())},");

            code.AppendLine($@"['UniqueIndex'] ={UniqueIndex},");

            code.AppendLine($@"['IsRequired'] ={(IsRequired.ToString().ToLower())},");

            code.AppendLine($@"['IsUserReadOnly'] ={(IsUserReadOnly.ToString().ToLower())},");

            code.AppendLine($@"['IsMemo'] ={(IsMemo.ToString().ToLower())},");


            code.AppendLine($@"['DenyClient'] ={(DenyClient.ToString().ToLower())},");

            if (!string.IsNullOrWhiteSpace(Prefix))
            {
                code.AppendLine($@"['Prefix'] = '{Prefix.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['Prefix'] = nil,");
            }

            if (!string.IsNullOrWhiteSpace(Suffix))
            {
                code.AppendLine($@"['Suffix'] = '{Suffix.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['Suffix'] = nil,");
            }

            if (!string.IsNullOrWhiteSpace(InputType))
            {
                code.AppendLine($@"['InputType'] = '{InputType.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['InputType'] = nil,");
            }

            if (!string.IsNullOrWhiteSpace(ComboBoxUrl))
            {
                code.AppendLine($@"['ComboBoxUrl'] = '{ComboBoxUrl.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['ComboBoxUrl'] = nil,");
            }

            code.AppendLine($@"['IsMoney'] ={(IsMoney.ToString().ToLower())},");

            if (!string.IsNullOrWhiteSpace(GridAlign))
            {
                code.AppendLine($@"['GridAlign'] = '{GridAlign.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['GridAlign'] = nil,");
            }

            if (!string.IsNullOrWhiteSpace(DataFormater))
            {
                code.AppendLine($@"['DataFormater'] = '{DataFormater.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['DataFormater'] = nil,");
            }

            code.AppendLine($@"['DenyClient'] ={(DenyClient.ToString().ToLower())},");

            code.AppendLine($@"['GridDetails'] ={(GridDetails.ToString().ToLower())},");

            code.AppendLine($@"['NoneGrid'] ={(NoneGrid.ToString().ToLower())},");

            code.AppendLine($@"['NoneDetails'] ={(NoneDetails.ToString().ToLower())},");

            if (!string.IsNullOrWhiteSpace(GridDetailsCode))
            {
                code.AppendLine($@"['GridDetailsCode'] = '{GridDetailsCode.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['GridDetailsCode'] = nil,");
            }

            if (!string.IsNullOrWhiteSpace(CppType))
            {
                code.AppendLine($@"['CppType'] = '{CppType.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['CppType'] = nil,");
            }

            if (CppTypeObject != null)
            {
                code.AppendLine($@"['CppTypeObject'] ='{CppTypeObject}',");
            }

            if (!string.IsNullOrWhiteSpace(CppName))
            {
                code.AppendLine($@"['CppName'] = '{CppName.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['CppName'] = nil,");
            }

            if (!string.IsNullOrWhiteSpace(CppLastType))
            {
                code.AppendLine($@"['CppLastType'] = '{CppLastType.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['CppLastType'] = nil,");
            }

            code.AppendLine($@"['IsIntDecimal'] ={(IsIntDecimal.ToString().ToLower())},");

            if (!string.IsNullOrWhiteSpace(CsType))
            {
                code.AppendLine($@"['CsType'] = '{CsType.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['CsType'] = nil,");
            }

            if (!string.IsNullOrWhiteSpace(CustomType))
            {
                code.AppendLine($@"['CustomType'] = '{CustomType.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['CustomType'] = nil,");
            }

            if (!string.IsNullOrWhiteSpace(LastCsType))
            {
                code.AppendLine($@"['LastCsType'] = '{LastCsType.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['LastCsType'] = nil,");
            }

            if (EnumConfig != null)
            {
                code.AppendLine($@"['EnumConfig'] = {EnumConfig.GetLuaStruct()},");
            }

            code.AppendLine($@"['IsCompute'] ={(IsCompute.ToString().ToLower())},");

            if (!string.IsNullOrWhiteSpace(ComputeGetCode))
            {
                code.AppendLine($@"['ComputeGetCode'] = '{ComputeGetCode.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['ComputeGetCode'] = nil,");
            }

            if (!string.IsNullOrWhiteSpace(ComputeSetCode))
            {
                code.AppendLine($@"['ComputeSetCode'] = '{ComputeSetCode.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['ComputeSetCode'] = nil,");
            }

            code.AppendLine($@"['IsMiddleField'] ={(IsMiddleField.ToString().ToLower())},");

            code.AppendLine($@"['InnerField'] ={(InnerField.ToString().ToLower())},");

            code.AppendLine($@"['IsSystemField'] ={(IsSystemField.ToString().ToLower())},");

            code.AppendLine($@"['IsInterfaceField'] ={(IsInterfaceField.ToString().ToLower())},");

            if (!string.IsNullOrWhiteSpace(Initialization))
            {
                code.AppendLine($@"['Initialization'] = '{Initialization.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['Initialization'] = nil,");
            }

            if (!string.IsNullOrWhiteSpace(EmptyValue))
            {
                code.AppendLine($@"['EmptyValue'] = '{EmptyValue.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['EmptyValue'] = nil,");
            }

            code.AppendLine($@"['DenyScope'] ='{DenyScope}',");

            code.AppendLine($@"['Nullable'] ={(Nullable.ToString().ToLower())},");

            if (!string.IsNullOrWhiteSpace(Max))
            {
                code.AppendLine($@"['Max'] = '{Max.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['Max'] = nil,");
            }

            if (!string.IsNullOrWhiteSpace(Min))
            {
                code.AppendLine($@"['Min'] = '{Min.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['Min'] = nil,");
            }

            code.AppendLine($@"['UniqueString'] ={(UniqueString.ToString().ToLower())},");

            if (!string.IsNullOrWhiteSpace(ColumnName))
            {
                code.AppendLine($@"['ColumnName'] = '{ColumnName.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['ColumnName'] = nil,");
            }

            code.AppendLine($@"['DbNullable'] ={(DbNullable.ToString().ToLower())},");

            if (!string.IsNullOrWhiteSpace(DbType))
            {
                code.AppendLine($@"['DbType'] = '{DbType.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['DbType'] = nil,");
            }

            code.AppendLine($@"['Precision'] ={Datalen},");

            if (!string.IsNullOrWhiteSpace(ArrayLen))
            {
                code.AppendLine($@"['ArrayLen'] = '{ArrayLen.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['ArrayLen'] = nil,");
            }

            code.AppendLine($@"['Scale'] ={Scale},");

            code.AppendLine($@"['DbIndex'] ={DbIndex},");

            code.AppendLine($@"['Unicode'] ={(Unicode.ToString().ToLower())},");

            code.AppendLine($@"['FixedLength'] ={(FixedLength.ToString().ToLower())},");

            code.AppendLine($@"['IsBlob'] ={(IsBlob.ToString().ToLower())},");

            if (!string.IsNullOrWhiteSpace(StorageProperty))
            {
                code.AppendLine($@"['StorageProperty'] = '{StorageProperty.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['StorageProperty'] = nil,");
            }

            code.AppendLine($@"['DbInnerField'] ={(DbInnerField.ToString().ToLower())},");

            code.AppendLine($@"['NoStorage'] ={(NoStorage.ToString().ToLower())},");

            code.AppendLine($@"['KeepStorageScreen'] ='{KeepStorageScreen}',");

            code.AppendLine($@"['CustomWrite'] ={(CustomWrite.ToString().ToLower())},");

            code.AppendLine($@"['IsLinkField'] ={(IsLinkField.ToString().ToLower())},");

            if (!string.IsNullOrWhiteSpace(LinkTable))
            {
                code.AppendLine($@"['LinkTable'] = '{LinkTable.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['LinkTable'] = nil,");
            }

            code.AppendLine($@"['IsLinkKey'] ={(IsLinkKey.ToString().ToLower())},");

            code.AppendLine($@"['IsLinkCaption'] ={(IsLinkCaption.ToString().ToLower())},");

            code.AppendLine($@"['IsUserId'] ={(IsUserId.ToString().ToLower())},");

            if (!string.IsNullOrWhiteSpace(LinkField))
            {
                code.AppendLine($@"['LinkField'] = '{LinkField.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['LinkField'] = nil,");
            }

            code.AppendLine($@"['IsCustomCompute'] ={(IsCustomCompute.ToString().ToLower())},");

            code.AppendLine($@"['CanGet'] ={(CanGet.ToString().ToLower())},");

            code.AppendLine($@"['CanSet'] ={(CanSet.ToString().ToLower())},");

            if (!string.IsNullOrWhiteSpace(AccessType))
            {
                code.AppendLine($@"['AccessType'] = '{AccessType.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['AccessType'] = nil,");
            }

            code.AppendLine($@"['ReadOnly'] ={(ReadOnly.ToString().ToLower())},");

            code.AppendLine($@"['CanInput'] ={(CanUserInput.ToString().ToLower())},");

            if (!string.IsNullOrWhiteSpace(ExtendRole))
            {
                code.AppendLine($@"['ExtendRole'] = '{ExtendRole.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['ExtendRole'] = nil,");
            }

            if (!string.IsNullOrWhiteSpace(ValueSeparate))
            {
                code.AppendLine($@"['ValueSeparate'] = '{ValueSeparate.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['ValueSeparate'] = nil,");
            }

            if (!string.IsNullOrWhiteSpace(ArraySeparate))
            {
                code.AppendLine($@"['ArraySeparate'] = '{ArraySeparate.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['ArraySeparate'] = nil,");
            }

            code.AppendLine($@"['ExtendArray'] ={(ExtendArray.ToString().ToLower())},");

            code.AppendLine($@"['IsKeyValueArray'] ={(IsKeyValueArray.ToString().ToLower())},");

            code.AppendLine($@"['IsRelation'] ={(IsRelation.ToString().ToLower())},");

            if (!string.IsNullOrWhiteSpace(ExtendPropertyName))
            {
                code.AppendLine($@"['ExtendPropertyName'] = '{ExtendPropertyName.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['ExtendPropertyName'] = nil,");
            }

            if (!string.IsNullOrWhiteSpace(ExtendClassName))
            {
                code.AppendLine($@"['ExtendClassName'] = '{ExtendClassName.ToLuaString()}',");
            }
            else
            {
                code.AppendLine($@"['ExtendClassName'] = nil,");
            }

            code.AppendLine($@"['ExtendClassIsPredestinate'] ={(ExtendClassIsPredestinate.ToString().ToLower())},");

            code.AppendLine($@"['IsRelationField'] ={(IsRelationField.ToString().ToLower())},");

            code.AppendLine($@"['IsRelationValue'] ={(IsRelationValue.ToString().ToLower())},");

            code.AppendLine($@"['IsRelationArray'] ={(IsRelationArray.ToString().ToLower())},");

            code.AppendLine($@"['IsExtendArray'] ={(IsExtendArray.ToString().ToLower())},");

            code.AppendLine($@"['IsExtendValue'] ={(IsExtendValue.ToString().ToLower())},");
        }
Ejemplo n.º 15
0
        public T UniqueResult()
        {
            try
            {
                Type type = typeof(T);
                CurrentType = type;
                T entity = null;
                if (string.IsNullOrEmpty(currentQuery))
                {
                    currentQuery = Query.EntityMap.Select;
                }
                string sql = currentQuery + " LIMIT 1;";
                using (IDbCommand command = CreateCommand(sql))
                {
                    using (IDataReader reader = command.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            entity = Activator.CreateInstance(type) as T;
                            foreach (var keyValueColumn in Query.EntityMap.ColumnNames)
                            {
                                var          value    = reader["_this." + keyValueColumn.Key];
                                PropertyInfo property = type.GetProperty(keyValueColumn.Key);
                                property.SetValue(entity, DataFormater.ParseToData(property, value));
                            }
                            foreach (var keyValuePair in Query.EntityMap.Entities)
                            {
                                if (keyValuePair.Value.Type.IsEnum)
                                {
                                    var value = reader[keyValuePair.Key + "." + keyValuePair.Value.PrimaryKeyName];

                                    if (Enum.IsDefined(keyValuePair.Value.Type, value))
                                    {
                                        Enum @enum = (Enum)Enum.Parse(keyValuePair.Value.Type, value + "");
                                        Query.EntityMap.Type.GetProperty(keyValuePair.Key).SetValue(entity, @enum);
                                    }
                                    else
                                    {
                                        throw new Exception("El tipo enum [" + keyValuePair.Value.Type + "] no tiene definido el valor [" + value + "].");
                                    }
                                }
                                else
                                {
                                    object obj = Activator.CreateInstance(keyValuePair.Value.Type);
                                    foreach (var keyValueColumn in keyValuePair.Value.ColumnNames)
                                    {
                                        var          value    = reader[keyValuePair.Key + "." + keyValueColumn.Key];
                                        PropertyInfo property = keyValuePair.Value.Type.GetProperty(keyValueColumn.Key);
                                        property.SetValue(obj, DataFormater.ParseToData(property, value));
                                    }
                                    Query.EntityMap.Type.GetProperty(keyValuePair.Key).SetValue(entity, obj);
                                }
                            }
                        }
                        reader.Close();
                        reader.Dispose();
                        command.Dispose();
                    }
                }
                if (entity != null)
                {
                    FillEntities(entity);
                    FillCollections(entity);
                }
                return(entity);
            }
            catch
            {
                throw;
            }
        }
Ejemplo n.º 16
0
        IList <T> Execute(string sql)
        {
            try
            {
                Type type = Query.EntityMap.Type;
                CurrentType = type;
                IList <T> list = Activator.CreateInstance(typeof(List <>).MakeGenericType(type)) as IList <T>;
                using (IDbCommand command = CreateCommand(sql))
                {
                    using (IDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            T entity = Activator.CreateInstance(type) as T;
                            foreach (var keyValueColumn in Query.EntityMap.ColumnNames)
                            {
                                var          value    = reader["_this." + keyValueColumn.Key];
                                PropertyInfo property = type.GetProperty(keyValueColumn.Key);
                                property.SetValue(entity, DataFormater.ParseToData(property, value));
                            }
                            foreach (var keyValuePair in Query.EntityMap.Entities)
                            {
                                if (keyValuePair.Value.Type.IsEnum)
                                {
                                    var value = reader[keyValuePair.Key + "." + keyValuePair.Value.PrimaryKeyName];

                                    if (Enum.IsDefined(keyValuePair.Value.Type, value))
                                    {
                                        Enum @enum = (Enum)Enum.Parse(keyValuePair.Value.Type, value + "");
                                        Query.EntityMap.Type.GetProperty(keyValuePair.Key).SetValue(entity, @enum);
                                    }
                                    else
                                    {
                                        throw new Exception("El tipo enum [" + keyValuePair.Value.Type + "] no tiene definido el valor [" + value + "].");
                                    }
                                }
                                else
                                {
                                    object obj = Activator.CreateInstance(keyValuePair.Value.Type);
                                    foreach (var keyValueColumn in keyValuePair.Value.ColumnNames)
                                    {
                                        var          value    = reader[keyValuePair.Key + "." + keyValueColumn.Key];
                                        PropertyInfo property = keyValuePair.Value.Type.GetProperty(keyValueColumn.Key);
                                        property.SetValue(obj, DataFormater.ParseToData(property, value));
                                    }
                                    Query.EntityMap.Type.GetProperty(keyValuePair.Key).SetValue(entity, obj);
                                }
                            }
                            list.Add(entity);
                        }
                        reader.Close();
                        reader.Dispose();
                        command.Dispose();
                    }
                }
                foreach (var obj in list)
                {
                    FillEntities(obj);
                }
                return(list);
            }
            catch
            {
                throw;
            }
        }
Ejemplo n.º 17
0
 void FillCollections(object entity)
 {
     try
     {
         Type       type = entity.GetType();
         IEntityMap entityMap;
         Cfg.Configuration.Mappings.TryGetValue(type.Name, out entityMap);
         if (string.IsNullOrEmpty(entityMap.PrimaryKeyName))
         {
         }
         else
         {
             object id = type.GetProperty(entityMap.PrimaryKeyName).GetValue(entity);
             foreach (var keyValuePair in entityMap.Collections)
             {
                 IEntityMap itemMap = keyValuePair.Value;
                 string     sql;
                 entityMap.CollectionSelect.TryGetValue(keyValuePair.Key, out sql);
                 IList collection = Activator.CreateInstance(typeof(List <>).MakeGenericType(itemMap.Type)) as IList;
                 type.GetProperty(keyValuePair.Key).SetValue(entity, collection);
                 foreach (var kvf in itemMap.ForeignKeys)
                 {
                     if (sql.Contains("{" + kvf.Key + "}"))
                     {
                         sql = sql.Replace("{" + kvf.Key + "}", DataFormater.ParseToSQL(id) + "");
                         using (IDbCommand command = CreateCommand(sql))
                         {
                             using (IDataReader reader = command.ExecuteReader())
                             {
                                 while (reader.Read())
                                 {
                                     object item = Activator.CreateInstance(itemMap.Type);
                                     foreach (var keyValueColumn in itemMap.ColumnNames)
                                     {
                                         var          value    = reader[keyValuePair.Key + "." + keyValueColumn.Key];
                                         PropertyInfo property = itemMap.Type.GetProperty(keyValueColumn.Key);
                                         property.SetValue(item, DataFormater.ParseToData(property, value));
                                     }
                                     foreach (var keyValue in itemMap.Entities)
                                     {
                                         IEntityMap compositeEntity = keyValue.Value;
                                         if (compositeEntity.Type != CurrentType)
                                         {
                                             object obj = Activator.CreateInstance(compositeEntity.Type);
                                             foreach (var keyValueColumn in compositeEntity.ColumnNames)
                                             {
                                                 var          value    = reader[keyValue.Key + "." + keyValueColumn.Key];
                                                 PropertyInfo property = compositeEntity.Type.GetProperty(keyValueColumn.Key);
                                                 property.SetValue(obj, DataFormater.ParseToData(property, value));
                                             }
                                             itemMap.Type.GetProperty(keyValue.Key).SetValue(item, obj);
                                         }
                                         else
                                         {
                                             itemMap.Type.GetProperty(kvf.Key).SetValue(item, entity);
                                         }
                                     }
                                     collection.Add(item);
                                 }
                                 reader.Close();
                                 reader.Dispose();
                                 command.Dispose();
                             }
                         }
                     }
                 }
             }
         }
     }
     catch
     {
         throw;
     }
 }
Ejemplo n.º 18
0
 public IQuery <Q> SetParameterValue(string name, object value)
 {
     queryMap.CurrentQuery = queryMap.CurrentQuery.Replace(name, DataFormater.ParseToSQL(value));
     return(this);
 }
Ejemplo n.º 19
0
 public BaseDL()
 {
     dataFormater = new DataFormater();
 }
Ejemplo n.º 20
0
        public App()
            : base()
        {
            _connection   = new Test.TestConnection();
            _portSettings = new PortSettings();
            _dataFormater = new HexDataFormater();

            _dataFlowController = new DataFlowController(_connection.Send);
            _dataFlowController.OnEventuallyDataRecieved = DisplayEventuallyRecievedData;
            _connection.OnDataRecieved = _dataFlowController.OnDataRecieved;

            _window = new MainWindow();
            _window.PortComboBox.ItemsSource       = PortSettings.GetPortNames();
            _window.PortComboBox.SelectedIndex     = 0;
            _window.PortComboBox.SelectionChanged += (sender, args) =>
            {
                var selected = _window.PortComboBox.SelectedItem;
                if (selected != null)
                {
                    _portSettings.PortName = (string)selected;
                }
            };

            _window.BaudRateComboBox.ItemsSource   = PortSettings.GetCommonBaudRates();
            _window.BaudRateComboBox.SelectedIndex = 0;

            _window.ParityComboBox.ItemsSource   = Enum.GetValues(typeof(Parity));
            _window.ParityComboBox.SelectedIndex = 0;

            _window.DataBitsComboBox.ItemsSource   = new int[] { 1, 2, 4, 8, 16 };
            _window.DataBitsComboBox.SelectedIndex = 0;

            _window.StopBitsComboBox.ItemsSource   = Enum.GetValues(typeof(StopBits));
            _window.StopBitsComboBox.SelectedIndex = 0;

            _window.TimeOutMSComboBox.ItemsSource   = new int[] { 100, 200, 500, 1000 };
            _window.TimeOutMSComboBox.SelectedIndex = 0;

            //Adding modules to modules menu
            foreach (var module in LoadModules())
            {
                _window.ModulesMenu.AddModuleButton("module", () =>
                {
                    _window.ContentStackPanel.Children.Clear();
                    _window.ContentStackPanel.Children.Add(module.GetPanel());
                });

                module.Send = (data, length, onRecieved) =>
                {
                    var dataPair = new DataFlowPair();
                    dataPair.SetSent(_dataFormater.ToString(data, length));

                    if (onRecieved != null)
                    {
                        _dataFlowController.Send(data, length, (d, l) =>
                        {
                            onRecieved(data, length);
                            dataPair.SetRecieved(_dataFormater.ToString(d, l));
                        });
                    }
                    else
                    {
                        _dataFlowController.Send(data, length);
                    }

                    _window.DataFlowPanel.Children.Add(dataPair);
                };
            }
            _window.Show();
        }
Ejemplo n.º 21
0
 public static bool IsNotNull <TSource>(this TSource source)
 {
     return(!DataFormater.IsNull(source));
 }
Ejemplo n.º 22
0
 public static bool IsMobile(this string mobile)
 {
     return(DataFormater.IsMobile(mobile));
 }