Exemple #1
0
 private static DataSet ConvertToDataSet(string path)
 {
     using (FileStream testStream = File.Open(path, FileMode.Open, FileAccess.Read))
     {
         var reader = new DataSetReader(testStream);
         return(reader.AsDataSet());
     }
 }
        public override global::System.Data.DataSet Clone()
        {
            DataSetReader cln = ((DataSetReader)(base.Clone()));

            cln.InitVars();
            cln.SchemaSerializationMode = this.SchemaSerializationMode;
            return(cln);
        }
Exemple #3
0
 private void Initialize()
 {
     this.fileHelper         = new FileHelper();
     this.headerTypeHelper   = new HeaderTypeHelper();
     this.excelReader        = new ExcelReader();
     this.dataSetReader      = new DataSetReader();
     this.sampleValidator    = new SampleValidator();
     this.sampleDtoConverter = new SampleDtoConverter();
 }
        protected async Task <DataTableRows> ExecuteProcedureOrSqlAsync(string sql, CommandType ct, params SqlParameter[] parameters)
        {
            foreach (var sqlParameter in parameters.Where(p => p.Value == null && p.SqlDbType != SqlDbType.Structured))
            {
                sqlParameter.Value = DBNull.Value;
            }

            using (var sqlCon = new SqlConnection(_dbConnStr))
            {
                await sqlCon.OpenAsync();

                var executeTask = Task.Run(async() =>
                {
                    using (var cmd = CreateCommand(sql, sqlCon, ct, parameters))
                    {
                        try
                        {
                            using (var reader = new DataSetReader(cmd))
                            {
                                return(await reader.GetRowsAsync().ConfigureAwait(false));
                            }
                        }
                        finally
                        {
                            Commit();
                            //Release the parameters to allow reuse in case of deadlock
                            cmd.Parameters.Clear();
                        }
                    }
                });

                var attemptNo = 0;
                for (int failSafe = 0; failSafe < DeadlockRetryCount + 1; ++failSafe)
                {
                    try
                    {
                        return(await executeTask);
                    }
                    catch (SqlException e)
                    {
                        if (e.Number == 1205 && attemptNo++ < DeadlockRetryCount)
                        {
                            OnDeadlockDetected?.Invoke(this, null);
                            Thread.Sleep(DeadlockRetryDelayMs);
                        }
                        else
                        {
                            Rollback();
                            throw;
                        }
                    }
                }
            }
            // Should never reach this point
            throw new Exception("INTERNAL ERROR - SQL retry failsafe activated");
        }
        public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(global::System.Xml.Schema.XmlSchemaSet xs)
        {
            DataSetReader ds = new DataSetReader();

            global::System.Xml.Schema.XmlSchemaComplexType type     = new global::System.Xml.Schema.XmlSchemaComplexType();
            global::System.Xml.Schema.XmlSchemaSequence    sequence = new global::System.Xml.Schema.XmlSchemaSequence();
            global::System.Xml.Schema.XmlSchemaAny         any      = new global::System.Xml.Schema.XmlSchemaAny();
            any.Namespace = ds.Namespace;
            sequence.Items.Add(any);
            type.Particle = sequence;
            global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable();
            if (xs.Contains(dsSchema.TargetNamespace))
            {
                global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream();
                global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream();
                try {
                    global::System.Xml.Schema.XmlSchema schema = null;
                    dsSchema.Write(s1);
                    for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext();)
                    {
                        schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current));
                        s2.SetLength(0);
                        schema.Write(s2);
                        if ((s1.Length == s2.Length))
                        {
                            s1.Position = 0;
                            s2.Position = 0;
                            for (; ((s1.Position != s1.Length) &&
                                    (s1.ReadByte() == s2.ReadByte()));)
                            {
                                ;
                            }
                            if ((s1.Position == s1.Length))
                            {
                                return(type);
                            }
                        }
                    }
                }
                finally {
                    if ((s1 != null))
                    {
                        s1.Close();
                    }
                    if ((s2 != null))
                    {
                        s2.Close();
                    }
                }
            }
            xs.Add(dsSchema);
            return(type);
        }
Exemple #6
0
        /*
         * CONSTRUCTORS
         */
        public MultilayerNeuralNetwork(Layer[] layers, DataSetReader dataSet, double eta, int maxEpochs)
        {
            if (layers[layers.Length - 1].nodes != dataSet.classes)
            {
                throw new ArgumentOutOfRangeException("Output layer's neurons and dataset classes must have the same length ");
            }

            this.layer     = layers;
            this.dataSet   = dataSet;
            this.eta       = eta;
            this.maxEpochs = maxEpochs;
        }
Exemple #7
0
        private void AssertDataSetIsNotEmpty(string fileName)
        {
            DataSet result = null;
            string  path   = GetResourceFilePath(fileName);

            using (FileStream testStream = File.Open(path, FileMode.Open, FileAccess.Read))
            {
                var reader = new DataSetReader(testStream);
                result = reader.AsDataSet();
            }

            Assert.IsNotNull(result);
            Assert.Greater(result.Tables.Count, 0);
        }
 public void UpdateDataSource(DataSetReader Changerows)
 {
     try
     {
         conn.Open();
         da.Update(Changerows);
     }
     catch (System.Exception E)
     {
         this.ErrorHandle(E);
     }
     finally
     {
         conn.Close();
     }
 }
        public void UpdateDataSet()
        {
            this.BindingContext[this.objDataSetReader, "Reader"].EndCurrentEdit();
            DataSetReader objDataSetTemp = new DataSetReader();

            objDataSetTemp = (DataSetReader)(this.objDataSetReader.GetChanges());
            try
            {
                this.UpdateDataSource(objDataSetTemp);
                this.objDataSetReader.Merge(objDataSetTemp);
                this.objDataSetReader.AcceptChanges();
            }
            catch (System.Exception E)
            {
                this.ErrorHandle(E);
            }
        }
Exemple #10
0
        static void Main(string[] args)
        {
            string partyOrNotPath = "./data/PartyOrNot.csv";
            string playOrNotPath  = "./data/ToPlayOrNotToPlay.csv";

            DataSetReader dataSetReader = new DataSetReader(playOrNotPath, "yes", ",", true, 4);
            //DataSetReader dataSetReader = new DataSetReader(partyOrNotPath, "party", ";", true, 3);

            DataSet dataSet = dataSetReader.GetDataSet();

            DecisionTree decisionTree = new DecisionTree(dataSet);

            //Console.WriteLine(dataSet.ToString());

            decisionTree.PrintPretty();

            Console.ReadKey();
        }
        private void FillDataSet(DataSetReader dataset, string sqlQuery)
        {
            dataset.EnforceConstraints = false;
            try
            {
                da.SelectCommand.CommandText = sqlQuery;
                conn.Open();
                da.Fill(dataset);
            }
            catch (System.Exception E)
            {
                this.ErrorHandle(E);
            }

            finally
            {
                dataset.EnforceConstraints = true;
                conn.Close();
            }
        }
Exemple #12
0
        public void TestRead()
        {
            DataSetReader dsr = new DataSetReader(FILENAME, DATA_SIZE, TEST_SIZE);

            int             counter = 0;
            List <double[]> result  = new List <double[]>();

            while (true)
            {
                // In testing, create new buffer for each iteration.
                double[] dataBuffer = new double[DATA_SIZE];
                double[] testBuffer = new double[TEST_SIZE];

                if (!dsr.Read(dataBuffer, testBuffer))
                {
                    break;
                }
                ++counter;
            }
            Assert.AreEqual(3, counter);
        }
Exemple #13
0
        public void TestWrite()
        {
            double[] dataBuffer = new double[] { 1.5, 2.399, 3.1234, 4.0555, 5.01111 };
            double[] testBuffer = new double[] { 6.0 };

            DataSetWriter dwr = new DataSetWriter(FILENAME, false, 5, 1);

            for (int i = 0; i < 3; ++i)
            {
                dwr.Write(dataBuffer, testBuffer, testBuffer);
            }
            dwr.Close();

            DataSetReader dsr = new DataSetReader(FILENAME, 5, 1);

            for (; dsr.Read(dataBuffer, testBuffer);)
            {
                ;
            }

            Assert.AreEqual(3, dsr.Count);
        }
        private void LoadDataSet(string sqlQuery)
        {
            DataSetReader objDataSetTemp = new DataSetReader();

            try
            {
                this.FillDataSet(objDataSetTemp, sqlQuery);
            }
            catch (System.Exception E)
            {
                // 在此处添加错误处理代码。
                this.ErrorHandle(E);
            }
            try
            {
                this.objDataSetReader.Clear();                //清空当前数据集
                this.objDataSetReader.Merge(objDataSetTemp);  //合并数据集
            }
            catch (System.Exception E)
            {
                // 在此处添加错误处理代码。
                this.ErrorHandle(E);
            }
        }
Exemple #15
0
        public void TestReadValidData()
        {
            DataSetReader dsr = new DataSetReader(FILENAME, DATA_SIZE, TEST_SIZE);

            double[] dataBuffer = new double[DATA_SIZE];
            double[] testBuffer = new double[TEST_SIZE];
            bool     success    = dsr.Read(dataBuffer, testBuffer);

            Assert.IsTrue(success);

            double[] targetData = new double[] { 5.1000, 3.5000, 1.4000, 0.2000 };
            double[] targetTest = new double[] { 1 };

            Assert.AreEqual(targetData.Length, dataBuffer.Length);
            Assert.AreEqual(targetTest.Length, testBuffer.Length);
            for (int i = 0; i < targetData.Length; ++i)
            {
                Assert.AreEqual(targetData[i], dataBuffer[i], "Mismatch read data at " + (i + 1));
            }
            for (int i = 0; i < targetTest.Length; ++i)
            {
                Assert.AreEqual(targetTest[i], testBuffer[i], "Mismatch read test at " + (i + 1));
            }
        }
            public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedTableSchema(global::System.Xml.Schema.XmlSchemaSet xs)
            {
                global::System.Xml.Schema.XmlSchemaComplexType type     = new global::System.Xml.Schema.XmlSchemaComplexType();
                global::System.Xml.Schema.XmlSchemaSequence    sequence = new global::System.Xml.Schema.XmlSchemaSequence();
                DataSetReader ds = new DataSetReader();

                global::System.Xml.Schema.XmlSchemaAny any1 = new global::System.Xml.Schema.XmlSchemaAny();
                any1.Namespace       = "http://www.w3.org/2001/XMLSchema";
                any1.MinOccurs       = new decimal(0);
                any1.MaxOccurs       = decimal.MaxValue;
                any1.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax;
                sequence.Items.Add(any1);
                global::System.Xml.Schema.XmlSchemaAny any2 = new global::System.Xml.Schema.XmlSchemaAny();
                any2.Namespace       = "urn:schemas-microsoft-com:xml-diffgram-v1";
                any2.MinOccurs       = new decimal(1);
                any2.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax;
                sequence.Items.Add(any2);
                global::System.Xml.Schema.XmlSchemaAttribute attribute1 = new global::System.Xml.Schema.XmlSchemaAttribute();
                attribute1.Name       = "namespace";
                attribute1.FixedValue = ds.Namespace;
                type.Attributes.Add(attribute1);
                global::System.Xml.Schema.XmlSchemaAttribute attribute2 = new global::System.Xml.Schema.XmlSchemaAttribute();
                attribute2.Name       = "tableTypeName";
                attribute2.FixedValue = "ReaderDataTable";
                type.Attributes.Add(attribute2);
                type.Particle = sequence;
                global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable();
                if (xs.Contains(dsSchema.TargetNamespace))
                {
                    global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream();
                    global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream();
                    try {
                        global::System.Xml.Schema.XmlSchema schema = null;
                        dsSchema.Write(s1);
                        for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext();)
                        {
                            schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current));
                            s2.SetLength(0);
                            schema.Write(s2);
                            if ((s1.Length == s2.Length))
                            {
                                s1.Position = 0;
                                s2.Position = 0;
                                for (; ((s1.Position != s1.Length) &&
                                        (s1.ReadByte() == s2.ReadByte()));)
                                {
                                    ;
                                }
                                if ((s1.Position == s1.Length))
                                {
                                    return(type);
                                }
                            }
                        }
                    }
                    finally {
                        if ((s1 != null))
                        {
                            s1.Close();
                        }
                        if ((s2 != null))
                        {
                            s2.Close();
                        }
                    }
                }
                xs.Add(dsSchema);
                return(type);
            }
 public BackPropagation(Layer[] layers, DataSetReader dataSet, double eta, int maxEpochs)
     : base(layers, dataSet, eta, maxEpochs)
 {
     //Nothing here.
 }