private void TriggerCallback()
 {
     try
     {
         IEnumerable <object> values = ReadData.ReadDataFromDataSources(datasetConfig, datasetConfig.DatasetConfigRows, activConnections, StartedAsService);
         if (values != null)
         {
             dbInterface.Write(values);
         }
     }
     catch (ThreadAbortException ex)
     {
         //ThreadExceptionOccured.Invoke(this, new ThreadExceptionEventArgs(ex));
     }
     catch (Exception ex)
     {
         if (StartedAsService)
         {
             ThreadExceptionOccured.Invoke(this, new ThreadExceptionEventArgs(ex));
         }
         else
         {
             throw;
         }
     }
 }
Exemplo n.º 2
0
        protected void Reader()
        {
            Debug.WriteLine("reader started");

            var result = new List <byte>(BufferSize);
            var buffer = new byte[BufferSize];

            while (true)
            {
                var bytesRead = Stream.Read(buffer, 0, BufferSize);
                if (bytesRead == 0)
                {
                    break;
                }

                for (var i = 0; i < bytesRead; i++)
                {
                    var b = buffer[i];

                    result.Add(b);
                    if (b == _delimiter.Last() && result.ToArray().Reverse().Take(_delimiter.Length).Reverse().ToArray().SequenceEqual(_delimiter))
                    {
                        result.RemoveRange(result.Count - _delimiter.Length, _delimiter.Length);

                        Debug.WriteLine("tcp got data " + result.Count);
                        ReadData?.Invoke(result.ToArray());
                        result.Clear();
                    }
                }
            }

            Debug.WriteLine("reader ended");
        }
Exemplo n.º 3
0
 void Run()
 {
     sb = new StringBuilder();
     re = new ReadData();
     Calc();
     Console.Write(sb.ToString());
 }
        protected override void Seed(TelegramCookingHelper.Classes.Context context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data.

            var readData = new ReadData();

            foreach (var meal in readData.Meals)
            {
                context.Meals.AddOrUpdate(meal);
                context.SaveChanges();
            }

            foreach (var ing in readData.Ingredients)
            {
                context.Ingredients.AddOrUpdate(ing);
                context.SaveChanges();
            }

            foreach (var dish in readData.Dishes)
            {
                dish.MainIngredient = context.Ingredients.First(ing => ing.Name == dish.MainIngredient.Name);
                dish.Meal           = context.Meals.First(m => m.Name == dish.Meal.Name);
                context.Dishes.AddOrUpdate(dish);
                context.SaveChanges();
            }
        }
Exemplo n.º 5
0
        public IActionResult Get()
        {
            var data = new ReadData(() =>
                                    _stockHub.Clients.All.SendAsync("Stock Data", MockData.GetStockData()));

            return(Ok(new { Message = "Request Completed" }));
        }
Exemplo n.º 6
0
        public void GetSurname()
        {
            ReadData dataTest = new ReadData("beidpkcs11.dll");

            dataTest.GetSurname();
            //Assert.AreEqual("SPECIMEN", dataTest.GetSurname());
        }
Exemplo n.º 7
0
        private void SendData()
        {
            while (true)
            {
                Thread.Sleep(1000);

                uint   portNum   = Convert.ToUInt32(portString);
                IntPtr comHandle = InitPort(portNum, 9600, 'N', 8, 1, false);

                readData = ReadDataCallBackFunc;
                CommSetCallBack(readData);

                CommStartR();

                byte   param  = Convert.ToByte(comboboxString);
                Random random = new Random();
                byte   x      = 0x00;
                byte   y      = 0x00;

                byte[] command = { 0x86, x, y, param, 0x00, 0x0a };

                byte[] crc      = CRC16.crc_16(command);
                byte[] sendData = new byte[command.Length + 2];
                command.CopyTo(sendData, 0);
                sendData[sendData.Length - 2] = crc[1];
                sendData[sendData.Length - 1] = crc[0];

                bool isWriteSuccessful = CommSendDataFunction(sendData, 8);

                ClosePort();
            }
        }
Exemplo n.º 8
0
        public void GetCertificateLabels()
        {
            ReadData      dataTest = new ReadData("beidpkcs11.dll");
            List <string> labels   = dataTest.GetCertificateLabels();

            Assert.IsTrue(labels.Contains("Authentication"), "Find Authentication certificate");
        }
Exemplo n.º 9
0
        public void GetDateOfBirth()
        {
            ReadData dataTest = new ReadData("beidpkcs11.dll");

            dataTest.GetDateOfBirth();
            //Assert.AreEqual("01 JAN 1971", dataTest.GetDateOfBirth());
        }
Exemplo n.º 10
0
        public Dictionary <string, byte[]> GetAllDataByte()
        {
            ReadData dataTest = new ReadData("beidpkcs11.dll");

            return(dataTest.GetAllDataByte());
            //Assert.AreEqual("SPECIMEN", dataTest.GetSurname());
        }
Exemplo n.º 11
0
        protected override async Task <ReadData> ReadBuffer(byte[] managedBuffer)
        {
            while (true)
            {
                ReadData readData = await ReadBufferInternal(managedBuffer);

                if (readData.eof && blobIndex >= 0 && blobIndex < NumberOfBlobs)
                {
                    // this is a multi-blob read; open the next one
                    await OpenBlob();

                    if (readData.nRead > 0)
                    {
                        readData.eof = false;
                        // we read some data; return it now
                        return(readData);
                    }

                    // otherwise go around the loop again and read some data from the next blob
                }
                else
                {
                    return(readData);
                }
            }
        }
Exemplo n.º 12
0
        public List <Transaction> Sales()
        {
            Console.WriteLine(1);
            IGetAll readObject = new ReadData();

            return(readObject.GetAllTransactions());
        }
Exemplo n.º 13
0
 private Task ReadFile(FileSystemInfo myFile)
 {
     return(Task.Run(() => ReadData.Add(new FileClientContents
     {
         FileName = myFile.Name,
         FileContents = FileReader.ReadFileToString(myFile.FullName)
     })));
 }
Exemplo n.º 14
0
 //バイナリ書き込み
 void WriteBinary(BinaryWriter writer)
 {
     writer.Write(MagicID);
     writer.Write(Version);
     ReadData.Write(writer);
     config.Write(writer);
     GalleryData.Write(writer);
 }
Exemplo n.º 15
0
 public void SaveDataButton()
 {
     SavePosition();
     SaveEvents();
     AssetDatabase.Refresh();
     PlayerEventTrack.EventData    = ReadData.Read("Saved_data");
     PlayerEventTrack.PositionData = ReadData.Read("Position_data");
 }
Exemplo n.º 16
0
        public void ConvertTest()
        {
            string s;

            s = ReadData.Convert("11.11,22.22");
            //Assert.AreEqual("11,11 22,22", s);
            Assert.AreEqual("X: 11,11Y: 22,22", s);
        }
        /// <summary>
        /// Metoda dodaje dane to lisy zamówieñ
        /// </summary>
        private void TestData()
        {
            string pathApplication = Directory.GetCurrentDirectory();
            string pathDirectory   = pathApplication.Remove(pathApplication.IndexOf(@"t\bin\D") + 1);
            string pathFile        = System.IO.Path.Combine(pathDirectory, @"TestFiles\z.csv");

            ReadData.CsvToList(pathFile);
        }
Exemplo n.º 18
0
 public void GetPhotoFile()
 {
     ReadData dataTest = new ReadData("beidpkcs11.dll");
     byte[] photoFile = dataTest.GetPhotoFile();
     Bitmap photo = new Bitmap(new MemoryStream(photoFile));
     Assert.AreEqual(140, photo.Width);
     Assert.AreEqual(200, photo.Height);
 }
Exemplo n.º 19
0
 //バイナリ書き込み
 void WriteBinary(BinaryWriter writer)
 {
     writer.Write(MagicID);
     writer.Write(Version);
     ReadData.Write(writer);
     Engine.Config.Write(writer);
     GalleryData.Write(writer);
     Engine.Param.WriteSystemData(writer);
 }
Exemplo n.º 20
0
 public void IntegrityFails()
 {
     ReadData dataTest = new ReadData("beidpkcs11.dll");
     Integrity integrityTest = new Integrity();
     byte[] idFile = dataTest.GetIdFile();
     byte[] idSignatureFile = dataTest.GetIdSignatureFile();
     byte[] certificateRRN = null;
     Assert.False(integrityTest.Verify(idFile, idSignatureFile, certificateRRN));
 }
Exemplo n.º 21
0
 public void IntegrityIdentityFileWrongSignature()
 {
     ReadData dataTest = new ReadData("beidpkcs11.dll");
     Integrity integrityTest = new Integrity();
     byte[] idFile = dataTest.GetIdFile();
     byte[] idSignatureFile = dataTest.GetAddressSignatureFile();
     byte[] certificateRRN = dataTest.GetCertificateRNFile();
     Assert.False(integrityTest.Verify(idFile, idSignatureFile, certificateRRN));
 }
Exemplo n.º 22
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (lblEmpID.Text == "" && lblEmpName.Text == "")
                {
                    string display = "Please Select Emplyee From The List to Calculate Salary Breakups!";
                    ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + display + "');", true);
                    Button2.Enabled = false;
                }


                string   myString = lblName.Text;
                ReadData r        = new ReadData();
                if (r.FindString(myString) == true)
                {
                    lblWhatHappened.ForeColor = System.Drawing.Color.Red;
                    lblWhatHappened.Text      = "Record Already Exists";
                    Button2.Enabled           = false;
                    Button3.Enabled           = false;
                }
                else
                {
                    lblWhatHappened.ForeColor = System.Drawing.Color.DarkGreen;
                    lblWhatHappened.Text      = "Available To Record!";
                    Button2.Enabled           = true;
                    Button3.Enabled           = true;
                    Button1.Enabled           = false;
                    Button2.Enabled           = true;
                    string empname    = lblName.Text;
                    string empno      = lblID.Text;
                    float  basic      = Convert.ToInt32(txtCalculateSalary.Text);
                    float  hra        = Convert.ToInt32(basic * 0.4);
                    float  da         = Convert.ToInt32(basic * 0.6);
                    float  gross      = Convert.ToInt32(basic + hra + da);
                    float  pf         = Convert.ToInt32(gross * 0.13);
                    float  tax        = Convert.ToInt32(gross * 0.2);
                    float  deductions = Convert.ToInt32(pf + tax);
                    float  netsalary  = Convert.ToInt32(gross - deductions);


                    lblEmpBasic.Text   = basic.ToString();;
                    lblHRA.Text        = hra.ToString();
                    lblDA.Text         = da.ToString();
                    lblGross.Text      = gross.ToString();
                    lblPF.Text         = pf.ToString();
                    lblTax.Text        = tax.ToString();
                    lblDeductions.Text = deductions.ToString();
                    lblTotal.Text      = netsalary.ToString();
                }
            }
            catch (SqlException myex)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + myex + "');", true);
                Button2.Enabled = false;
            }
        }
Exemplo n.º 23
0
        public ReadDataTest()
        {
            var serviceProvider = new ServiceCollection()
                                  .AddLogging()
                                  .BuildServiceProvider();
            var loggerFactor = serviceProvider.GetService <ILoggerFactory>();

            _ReadData = new ReadData(loggerFactor);
        }
Exemplo n.º 24
0
 public void GetCertificateRNFile()
 {
     ReadData dataTest = new ReadData("beidpkcs11.dll");
     byte[] certificateRNFile = dataTest.GetCertificateRNFile();
     X509Certificate certificateRN;
     Assert.DoesNotThrow(delegate { certificateRN = new X509Certificate(certificateRNFile); });
     certificateRN = new X509Certificate(certificateRNFile);
     Assert.True(certificateRN.Issuer.Contains("Root"));
 }
Exemplo n.º 25
0
        static void Main(string[] args)
        {
            ReadData  data;
            Heuristic heuristic;

            data      = new ReadData("../../data/input/stations.txt", "../../data/input/students_di_s.txt", "../../data/input/Buses.txt", "../../data/input/distance.txt");
            heuristic = new Heuristic(data.School, data.Stations, data.Buses);

            heuristic.Mode      = 1;
            heuristic.Limittime = 1800;
            heuristic.StartTime = 21600;
            heuristic.Run();
            heuristic.PrintSolution();

            data           = new ReadData("../../data/input/stations.txt", "../../data/input/students_di_s.txt", "../../data/input/Buses.txt", "../../data/input/distance.txt");
            heuristic      = new Heuristic(data.School, data.Stations, data.Buses);
            heuristic.Mode = 3;
            // heuristic.ReSet();
            heuristic.Limittime = 1800;
            heuristic.StartTime = 21600;
            heuristic.Run();
            heuristic.PrintSolution();
            // heuristic.PrintFileSolution("Solution_Arrival_06h");

            //data = new ReadData("../../data/input/stations.txt", "../../data/input/students_ve_s.txt", "../../data/input/Buses.txt", "../../data/input/distance.txt");
            //heuristic = new Heuristic(data.School, data.Stations, data.Buses);
            //heuristic.Mode = 2;
            //heuristic.Limittime = 1800;
            //heuristic.StartTime = 41400;
            //heuristic.Run();
            //heuristic.PrintSolution();
            //heuristic.PrintFileSolution("Solution_Back_11h30");


            //data = new ReadData("../../data/input/stations.txt", "../../data/input/students_di_c.txt", "../../data/input/Buses.txt", "../../data/input/distance.txt");
            //heuristic = new Heuristic(data.School, data.Stations, data.Buses);
            //heuristic.Mode = 1;
            //heuristic.Limittime = 1800;
            //heuristic.StartTime = 43200;
            //heuristic.Mode = 1;
            //heuristic.Run();
            //heuristic.PrintSolution();
            //heuristic.PrintFileSolution("Solution_Arrival_12h");

            //data = new ReadData("../../data/input/stations.txt", "../../data/input/students_ve_c.txt", "../../data/input/Buses.txt", "../../data/input/distance.txt");
            //heuristic = new Heuristic(data.School, data.Stations, data.Buses);
            //heuristic.Mode = 2;
            //heuristic.Limittime = 1800;
            //heuristic.StartTime = 58680;
            //heuristic.Run();
            //heuristic.PrintSolution();
            //heuristic.PrintFileSolution("Solution_Back_16h30");
            // Route f = new Route();
            // f.Show();
            Console.ReadKey();
        }
Exemplo n.º 26
0
        /// <summary>
        /// 获取解析结果
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        private async Task <T> GetRespond <T>(int time = 5) where T : ReceiveFrameBase, new()
        {
            var res2 = Task.Factory.StartNew <T>(new Func <T>(delegate
            {
                int count              = 0;
                List <byte> buffer     = new List <byte>();
                SerialPort.ReadTimeout = 200;
                Label:
                try
                {
                    byte[] data2 = new byte[2048];
                    count++;
                    Thread.Sleep(100);
                    var read = SerialPort.Read(data2, 0, data2.Length);
                    if (read > 0)
                    {
                        var receive = data2.Take(read).ToArray();
                        buffer.AddRange(receive);
                        ReadData?.Invoke(receive, BitConverter.ToString(buffer.ToArray()));
                        RXContainer receiveFrameBase = new RXContainer(buffer.ToArray());
                        var res = receiveFrameBase.GetFrame <T>();
                        if (res.Item2)
                        {
                            return(res.Item1);
                        }
                        else
                        {
                            if (count > time)
                            {
                                return(null);
                            }
                            goto Label;
                        }
                    }
                    else
                    {
                        if (count > time)
                        {
                            return(null);
                        }
                        goto Label;
                    }
                }
                catch (Exception err)
                {
                    Debug.WriteLine(err);
                    if (count > time)
                    {
                        return(null);
                    }
                    goto Label;
                }
            }));

            return(await res2);
        }
Exemplo n.º 27
0
 public void GetCertificateRootFile()
 {
     ReadData dataTest = new ReadData("beidpkcs11.dll");
     byte[] certificateFile = dataTest.GetCertificateRootFile();
     X509Certificate certificateRoot;
     Assert.DoesNotThrow(delegate { certificateRoot = new X509Certificate(certificateFile); });
     certificateRoot = new X509Certificate(certificateFile);
     Assert.AreEqual(certificateRoot.Subject, certificateRoot.Issuer, "Should be a self-signed root certificate");
     Assert.True(certificateRoot.Subject.Contains("Root"));
 }
Exemplo n.º 28
0
        public void setReports()
        {
            String driverpath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            r1     = new ExtentHtmlReporter(driverpath + "\\" + "testresults.html");
            extent = new ExtentReports();
            extent.AttachReporter(r1);
            extent.AddSystemInfo("Opering System", "Windows 10");
            ReadData.setData(driverpath);
        }
 public void ValidityAuthenticationChain()
 {
     ReadData dataTest = new ReadData("beidpkcs11.dll");
     Integrity integrityTest = new Integrity();
     List<byte[]> caCerts = new List<byte[]>();
     caCerts.Add(dataTest.GetCertificateCAFile());
     Assert.True(integrityTest.CheckCertificateChain(
         caCerts,
         dataTest.GetCertificateAuthenticationFile()));
 }
Exemplo n.º 30
0
        public void GetPhotoFile()
        {
            ReadData dataTest = new ReadData("beidpkcs11.dll");

            byte[] photoFile = dataTest.GetPhotoFile();
            Bitmap photo     = new Bitmap(new MemoryStream(photoFile));

            Assert.AreEqual(140, photo.Width);
            Assert.AreEqual(200, photo.Height);
        }
Exemplo n.º 31
0
        public void IntegrityFails()
        {
            ReadData  dataTest      = new ReadData("beidpkcs11.dll");
            Integrity integrityTest = new Integrity();

            byte[] idFile          = dataTest.GetIdFile();
            byte[] idSignatureFile = dataTest.GetIdSignatureFile();
            byte[] certificateRRN  = null;
            Assert.False(integrityTest.Verify(idFile, idSignatureFile, certificateRRN));
        }
Exemplo n.º 32
0
        public void IntegrityIdentityFileWrongCertificate()
        {
            ReadData  dataTest      = new ReadData("beidpkcs11.dll");
            Integrity integrityTest = new Integrity();

            byte[] idFile          = dataTest.GetIdFile();
            byte[] idSignatureFile = dataTest.GetIdSignatureFile();
            byte[] certificateRoot = dataTest.GetCertificateRootFile();
            Assert.False(integrityTest.Verify(idFile, idSignatureFile, certificateRoot));
        }
Exemplo n.º 33
0
        public MainWindow()
        {
            InitializeComponent();

            fullPath = System.IO.Path.GetFullPath("./resources"); // in Signature.WPF/bin/Debug/resources
            rd       = new ReadData();

            ShowData();
            ReadPDF();
        }
Exemplo n.º 34
0
        public void IntegrityIdentityFile()
        {
            ReadData  dataTest      = new ReadData("beidpkcs11.dll");
            Integrity integrityTest = new Integrity();

            byte[] idFile          = dataTest.GetIdFile();
            byte[] idSignatureFile = dataTest.GetIdSignatureFile();
            byte[] certificateRRN  = dataTest.GetCertificateRNFile();
            Assert.IsTrue(integrityTest.Verify(idFile, idSignatureFile, certificateRRN));
        }
Exemplo n.º 35
0
        public Dao Fetch(Guid id, Type type, IDbConnection connection, IDbTransaction transaction)
        {
            // todo [kk]: check that type is derived from PersistenceModel

            var tableName = GetTableName(type);

            CreateTableIfNotExists(tableName, connection, transaction);

            var text = $@"SELECT [Data] FROM [{tableName}] WHERE Id = @id";
            var data = ReadData(connection, transaction, text, ("id", Id2Str(id)));

            if (data == null || data.Count == 0)
            {
                return(null);
            }

            var model = Json.Deserialize(data.Single(), type) as Dao;

            return(model);
        }
        public void ValidityAuthenticationChain()
        {
            ReadData      dataTest      = new ReadData("beidpkcs11D.dll");
            Integrity     integrityTest = new Integrity();
            List <byte[]> caCerts       = new List <byte[]>();

            caCerts.Add(dataTest.GetCertificateCAFile());
            Assert.True(integrityTest.CheckCertificateChain(
                            caCerts,
                            dataTest.GetCertificateAuthenticationFile()));
        }
Exemplo n.º 37
0
        public void GetIdFile()
        {
            ReadData dataTest = new ReadData("beidpkcs11.dll");
            byte[] idFile = dataTest.GetIdFile();
            int i = 0;

            // poor man's tlv parser...
            // we'll check the first two tag fields (01 and 02)
            Assert.AreEqual(0x01, idFile[i++]); // Tag
            i += idFile[i];                     // Length - skip value
            i++;
            Assert.AreEqual(0x02, idFile[i]); // Tag
        }
Exemplo n.º 38
0
 public void IntegrityAddressFile()
 {
     ReadData dataTest = new ReadData("beidpkcs11.dll");
     Integrity integrityTest = new Integrity();
     byte[] addressFile = trimRight(dataTest.GetAddressFile());
     byte[] idSignatureFile = dataTest.GetIdSignatureFile();
     byte[] concatFiles = new byte[addressFile.Length + idSignatureFile.Length];
     Array.Copy(addressFile, 0, concatFiles, 0, addressFile.Length);
     Array.Copy(idSignatureFile, 0, concatFiles, addressFile.Length, idSignatureFile.Length);
     byte[] addressSignatureFile = dataTest.GetAddressSignatureFile();
     byte[] certificateRRN = dataTest.GetCertificateRNFile();
     Assert.True(integrityTest.Verify(concatFiles, addressSignatureFile, certificateRRN));
 }
Exemplo n.º 39
0
 public void SignSignature()
 {
     // Sign
     Sign signTest = new Sign("beidpkcs11.dll");
     byte[] testdata = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
     byte[] signeddata = signTest.DoSign(testdata, "Signature");
     Assert.IsNotNull(signeddata);
     // Verification
     ReadData dataTest = new ReadData("beidpkcs11.dll");
     Integrity integrityTest = new Integrity();
     Assert.False(integrityTest.Verify(testdata, signeddata,
         dataTest.GetCertificateAuthenticationFile()));
     Assert.True(integrityTest.Verify(testdata, signeddata,
         dataTest.GetCertificateSignatureFile()));
 }
Exemplo n.º 40
0
        public void StoreCertificateRNFile()
        {
            ReadData dataTest = new ReadData("beidpkcs11.dll");
            byte[] certificateRNFile = dataTest.GetCertificateRNFile();
            X509Certificate2 certificateRN = new X509Certificate2(certificateRNFile);

            X509Store mystore = new X509Store(StoreName.My);
            mystore.Open(OpenFlags.ReadWrite);
            mystore.Add(certificateRN);
        }
Exemplo n.º 41
0
 public void GetSlotDescription()
 {
     ReadData dataTest = new ReadData("beidpkcs11.dll");
     Assert.AreEqual("ACS CCID USB Reader 0", dataTest.GetSlotDescription());
 }
Exemplo n.º 42
0
 public void GetSurname()
 {
     ReadData dataTest = new ReadData("beidpkcs11.dll");
     dataTest.GetSurname();
     //Assert.AreEqual("SPECIMEN", dataTest.GetSurname());
 }
Exemplo n.º 43
0
 public void GetTokenInfoLabel()
 {
     ReadData dataTest = new ReadData("beidpkcs11.dll");
     Assert.AreEqual("BELPIC", dataTest.GetTokenInfoLabel().Trim());
 }
Exemplo n.º 44
0
        private async Task DataLoop(bool errorState)
        {
            var managedBuffer = new byte[bufferSize];
            var readData = new ReadData { eof = false, nRead = 0 };

            while ((!readData.eof) || errorState)
            {
                log.LogInformation("Waiting for buffer");
                var buffer = await queue.Dequeue();
                if (buffer == null)
                {
                    // we were interrupted, and have returned all the necessary buffers
                    return;
                }

                if (errorState)
                {
                    client.DiscardBuffer(buffer);
                }
                else
                {
                    try
                    {
                        if (buffer.size != bufferSize)
                        {
                            throw new ApplicationException("Mismatched buffer sizes " + buffer.size + " != " + bufferSize);
                        }

                        if (buffer.offset == -1)
                        {
                            buffer.offset = offset;
                        }
                        else if (buffer.offset != offset)
                        {
                            throw new ApplicationException("Buffer offset " + buffer.offset + " expected " + offset);
                        }

                        log.LogInformation("Waiting for buffer read");

                        Task<ReadData> timeout = Task.Delay(SafetyTimeout).ContinueWith((t) => new ReadData());
                        Task<ReadData> reads = await Task.WhenAny(timeout, ReadBuffer(managedBuffer));
                        if (reads == timeout)
                        {
                            throw new ApplicationException("Excessive timeout on read operation");
                        }
                        readData = reads.Result;

                        log.LogInformation("Got buffer read " + readData.nRead);

                        buffer.size = readData.nRead;
                        Marshal.Copy(managedBuffer, 0, buffer.storage, readData.nRead);

                        log.LogInformation("Returning to client");

                        client.ReceiveData(buffer, readData.eof);

                        offset += (long) buffer.size;
                    }
                    catch (Exception e)
                    {
                        SendError(e, ErrorType.IO);
                        client.DiscardBuffer(buffer);
                        errorState = true;
                    }
                }
            }
        }
Exemplo n.º 45
0
      /// <summary>
      /// Begin an asynchronous read operation
      /// </summary>
      /// <param name="callback">Callback method to call when read operation completes</param>
      /// <param name="state">State object</param>
      /// <returns>An <see cref="System.IAsyncResult"/> object</returns>
      public IAsyncResult BeginRead(AsyncCallback callback, object state)
      {
         byte[] bytes = AllocateBuffer();
         ReadData rd = new ReadData(callback, state, bytes);
         
         // only put a callback if the caller wants one.
         AsyncCallback myCallback = null;
         if ( callback != null )
            myCallback = new AsyncCallback(OnAsyncReadDone);

         IAsyncResult result = _topStream.BeginRead(
            bytes, 0, bytes.Length, myCallback,rd
            );
         return new WrappedAsyncResult(result, bytes);
      }
Exemplo n.º 46
0
 public void GetDateOfBirth()
 {
     ReadData dataTest = new ReadData("beidpkcs11.dll");
     Assert.AreEqual("01 JAN 1971", dataTest.GetDateOfBirth());
 }
Exemplo n.º 47
0
 public void GetCertificateLabels()
 {
     ReadData dataTest = new ReadData("beidpkcs11.dll");
     List<string> labels = dataTest.GetCertificateLabels();
     //Assert.True(labels.Contains("Authentication"),"Find Authentication certificate");
 }
Exemplo n.º 48
0
        /// <summary>
        /// в случае совпадения контрольной суммы последний байт равен 1
        /// </summary>
        /// <param name="size"></param>
        /// <returns></returns>
        private ReadData ReadBufferFromPort(byte size)
        {
            Thread.Sleep(_config.IntervalSleepTime);

            ReadData readData = new ReadData();

            byte[] readBuffer = new byte[size];

            try
            {
                _serialPort.Read(readBuffer, 0, size);
                _lastRespondedController = _currentDoorNumber;
            }
            catch (Exception exception)
            {
                _logger.Error("error read operation from method {0}\n port = {1} \n controller = {2} \n" + exception, _currentMethodName, _serialPort.PortName, _currentDoorNumber);
                readData.IsValid = false;
                readData.Buffer = new byte[0];
                return readData;
            }

            byte[] buffer = new byte[readBuffer.Length - 1];
            Array.Copy(readBuffer, buffer, readBuffer.Length - 1);

            if (GetCheckSum(buffer) == readBuffer[readBuffer.Length - 1])
            {
                readData.IsValid = true;
                readData.Buffer = buffer;
            }
            else
            {
                readData.IsValid = false;
                readData.Buffer = new byte[0];
            }

            return readData;
        }