Exemple #1
0
        public static void Sample()
        {
            var instance1 = new iRacingEvents();

            instance1.NewData += instance1_NewData;
            instance1.StartListening();

            var iracingInstance = new iRacingConnection();

            var start = DateTime.Now;

            foreach (var data in iracingInstance.GetDataFeed())
            {
                if (DateTime.Now - start > TimeSpan.FromSeconds(1))
                {
                    break;
                }

                traceMessages.Enqueue(string.Format("Enumerable Data Tick {0}", data.Telemetry.TickCount));
            }

            instance1.StopListening();

            foreach (var m in traceMessages)
            {
                Trace.WriteLine(m);
            }
        }
Exemple #2
0
        private void Watcher_Created(object sender, System.IO.FileSystemEventArgs e)
        {
            Console.WriteLine(e.FullPath + " | " + e.ChangeType);
            creates++;
            string fls = e.FullPath;
            string destFilePath;

            //foreach (string fls in Directory.GetFiles(sourceRootPath))
            //{
            //if (!FileStatusHelper.IsFileOccupied(fls))
            //{
            //FileInfo flinfo = new FileInfo(fls);
            destFilePath = destRootPath + "\\" + e.Name;
            //flinfo.CopyTo(destFilePath, true);  // 测试同步创建完,原目录文件无法删除
            //flinfo = null;

            //FileStream fs = File.Create(destFilePath);
            //fs.Dispose();
            //fs.Close();


            // 创建事件太慢,把要创建的文件放队列,在线程去执行
            //fileQueue.Enqueue(destFilePath);

            fileQueue.Enqueue(new MyFileInfo {
                DestinationPath = destFilePath, ChnageType = e.ChangeType
            });
        }
Exemple #3
0
 void WatchFile()
 {
     watcher      = new FileSystemWatcher();
     watcher.Path = System.IO.Path.Combine(path, "Assets");
     watcher.IncludeSubdirectories = true;
     watcher.Changed += (s, e) =>
     {
         // 这里只处理文件不处理路径
         if (!Directory.Exists(e.FullPath))
         {
             modifyFilePaths.Enqueue(e.FullPath);
             changed = true;
         }
     };
     watcher.Created += (s, e) =>
     {
         modifyFilePaths.Enqueue(e.FullPath);
         changed = true;
     };
     watcher.Deleted += (s, e) =>
     {
         deleteFilePaths.Enqueue(e.FullPath);
         changed = true;
     };
     watcher.Renamed += (s, e) =>
     {
         deleteFilePaths.Enqueue(e.OldFullPath);
         modifyFilePaths.Enqueue(e.FullPath);
         changed = true;
     };
     watcher.EnableRaisingEvents = true;
 }
Exemple #4
0
        // 스레드 측의 수신처리.
        void DispatchReceive()
        {
            // 수신처리.
            try
            {
                byte[] buffer = new byte[MtuSize];

                while (TcpSocket.Poll(0, SelectMode.SelectRead))
                {
                    int recvSize = TcpSocket.Receive(buffer, buffer.Length, SocketFlags.None);
                    if (recvSize == 0)
                    {
                        var closedBuffer = new byte[1];
                        RecvQueue.Enqueue(buffer);

                        DebugPrintFunc("Disconnected recv from client.");
                        Disconnect();
                    }
                    else if (recvSize > 0)
                    {
                        var recvData = new byte[recvSize];
                        Buffer.BlockCopy(buffer, 0, recvData, 0, recvSize);
                        RecvQueue.Enqueue(recvData);
                    }
                }
            }
            catch
            {
                return;
            }
        }
Exemple #5
0
        static void TestCycle(object obj)
        {
            EDSEngine knowledge = ((TheadStartObject)obj).Rules;

            System.Collections.Concurrent.ConcurrentQueue <TraceMessage> messages = ((TheadStartObject)obj).Messages;
            System.Collections.Concurrent.ConcurrentQueue <string>       results  = ((TheadStartObject)obj).Results;
            for (int cnt = 0; cnt < TESTCNT; cnt++)
            {
                ConsoleColor color = (ConsoleColor)r.Next(1, 16); //randomly pick any color but black to show this evaluation start/completion
                string       msg1  = Thread.CurrentThread.ManagedThreadId.ToString() + " - begun " + cnt.ToString() + ": " + testValues[cnt][0].Value + "," + testValues[cnt][1].Value;
                messages.Enqueue(new TraceMessage()
                {
                    Message = msg1, Color = color
                });
                string retval = "";

                Dictionary <string, string> thisState = new Dictionary <string, string>();
                thisState.Add(testValues[cnt][0].Key, testValues[cnt][0].Value);
                thisState.Add(testValues[cnt][1].Key, testValues[cnt][1].Value);

                retval = knowledge.GetFirstTableResult("ReverseTest", "OutColor", thisState);

                string msg2 = Thread.CurrentThread.ManagedThreadId.ToString() + " - complete " + cnt.ToString() + ": " + retval;
                messages.Enqueue(new TraceMessage()
                {
                    Message = msg2, Color = color
                });
                results.Enqueue(retval);
                //write_result(msg);
            }
        }
Exemple #6
0
        void ProcessClient(Bluetooth.BluetoothClient client)
        {
            var stream = client.GetStream();

            while (true)
            {
                var buffer = new byte[Message.HeaderSize];
                if (stream.Read(buffer, 0, Message.HeaderSize) > 0 && isRunning)
                {
                    var message = new MessageInfo(buffer);
                    switch (message.Type)
                    {
                    case MessageType.MoveScreen:
                    case MessageType.MouseButton:
                    case MessageType.MouseWheel:
                    case MessageType.MouseMove:
                    case MessageType.KeyPress:
                        messages.Enqueue(message);
                        break;

                    case MessageType.Clipboard:
                        messages.Enqueue(MessagePacket.Parse(message, stream));
                        break;

                    case MessageType.CheckIn:
                        CheckInMessage checkIn = new CheckInMessage(MessagePacket.Parse(message, stream));
                        ScreenConfig(stream);
                        messages.Enqueue(checkIn);
                        break;
                    }
                    messageHandle.Set();
                }
            }
        }
        public bool GetSerialPorts(Context context)
        {
            InitReceiver(context);

            if (devices == null || devices.Count == 0)
            { // Not previous devices detected
                devices = new List <UsbDeviceStatus>();
                foreach (UsbDevice device in GetPossibleSerialPorts(context))
                {
                    devices.Add(new UsbDeviceStatus(device));
                }

                if (devices.Count == 0)
                {
                    return(false);
                }

                foreach (UsbDeviceStatus deviceStatus in devices)
                {
                    queuedPermissions.Enqueue(CreateUsbPermission(context, deviceStatus));
                }

                if (!processingPermission)
                {
                    LaunchPermission();
                }
            }
            else
            { // Previous devices detected and maybe pending permissions intent launched
                List <UsbDeviceStatus> newDevices = new List <UsbDeviceStatus>();

                foreach (UsbDevice device in GetPossibleSerialPorts(context))
                {
                    if (!devices.Contains(new UsbDeviceStatus(device)))
                    {
                        newDevices.Add(new UsbDeviceStatus(device));
                    }
                }

                if (newDevices.Count == 0)
                {
                    return(false);
                }

                foreach (UsbDeviceStatus deviceStatus in newDevices)
                {
                    queuedPermissions.Enqueue(CreateUsbPermission(context, deviceStatus));
                }

                devices.AddRange(newDevices);

                if (!processingPermission)
                {
                    LaunchPermission();
                }
            }

            return(true);
        }
Exemple #8
0
        public virtual JsonResult SyncData(string EventName, UpdateServiceFromAppModel model)
        {
            model.Responses = model.Responses ?? Enumerable.Empty <MoodResponseUpdateModel>();
            Event evnt = null;

            try
            {
                if (string.IsNullOrEmpty(EventName))
                {
                    throw new ArgumentException("Invalid event");
                }
                if (model == null)
                {
                    throw new ArgumentException("Invalid model");
                }

                this.logger.Info("App", string.Format("Request to sync data - {0}", model.rid));

                var syncTimestamp = DateTime.UtcNow;

                evnt = db.Get <Event>().FirstOrDefault(e => e.Name.Equals(EventName, StringComparison.InvariantCultureIgnoreCase));

                var responder = evnt.AddResponder(new Guid(model.rid), model.reg, model.apn);

                var lastSync = responder.LastSync < model.LastUpdate ? responder.LastSync : model.LastUpdate;

                // NB: assume new set will commit fine on the background queue.
                // If a failure occurs, it will be picked up on the next (or later) sync, and trigger a full "recovery" sync.
                var resError = model.ResTotal != (responder.Responses.Count() + model.Responses.Count());

                responder.LastSync = syncTimestamp;

                db.SaveChanges();

                if (model.Responses.Any())
                {
                    responseSubmissionQueue.Enqueue(new MoodResponseWorkItem
                    {
                        EventName     = EventName,
                        ResponderId   = model.rid,
                        Region        = model.reg,
                        DeviceId      = model.apn,
                        MoodResponses = model.Responses
                    });

                    backgroundTaskFactory.StartNew(ProcessQueuedMoodResponseWorkItems);
                }

                return(Json(GetServiceUpdates(evnt, true, resError, lastSync, syncTimestamp, responder.ForceReset)));
            }
            catch (Exception ex)
            {
                logger.Error("App", ex, "Failed sync from app" + (model == null ? " - model is null" : string.Empty));

                return(Json(GetServiceUpdates(evnt, false, false, model.LastUpdate, DateTime.UtcNow, false)));
            }
        }
Exemple #9
0
        /// <summary>
        /// Enqueues a command to be send to IGS.
        /// </summary>
        /// <param name="command">The single-line command.</param>
        public void MakeUnattendedRequest(string command)
        {
            IgsRequest request = new IgsRequest(command)
            {
                Unattended = true
            };

            _outgoingRequests.Enqueue(request);
            ExecuteRequestFromQueue();
        }
        private void OnEnter(Message msg, Protocols.EnterKey enter)
        {
            LockInfo info = new LockInfo();

            info.RequestMessage = msg;
            info.Key            = enter.Key;
            info.Owner          = enter.Owner;
            info.Type           = ProcessType.Enter;
            mLockInfoQueue.Enqueue(info);
        }
Exemple #11
0
 private void AppendContextsToRegister(IEnumerable <string> contexts)
 {
     foreach (var context in contexts)
     {
         if (!contextsToRegister.Contains(context))
         {
             contextsToRegister.Enqueue(context);
         }
     }
 }
Exemple #12
0
 static public void Write(string msg, LOG_LEVEL logLevel       = LOG_LEVEL.TRACE,
                          [CallerFilePath] string fileName     = "",
                          [CallerMemberName] string methodName = "",
                          [CallerLineNumber] int lineNumber    = 0)
 {
     if (출력가능_로그레벨 <= logLevel)
     {
         logMsgQueue.Enqueue(string.Format("{0}:{1}| {2}", DateTime.Now, methodName, msg));
     }
 }
        public static void ServerStart(int ServerID, int Port)
        {
            var msg = new InnerMsg()
            {
                Type = InnerMsgType.SERVER_START
            };

            msg.Value1 = string.Format("{0}_{1}", ServerID, Port);

            msgQueue.Enqueue(msg);
        }
Exemple #14
0
 public ClientManager()
 {
     for (var i = 0; i < Constants.MAXCLIENTS; i++)
     {
         Ids.Enqueue(i);
     }
     _TimeoutTimer          = new System.Timers.Timer();
     _TimeoutTimer.Interval = 5000;//every 5 seconds check to possibly remove a server that is in a reserved state but has never completed the connection, or viewers who have not connected either
     _TimeoutTimer.Elapsed += _TimeoutTimer_Elapsed;
     _TimeoutTimer.Start();
 }
Exemple #15
0
        protected void Build()
        {
            while (true)
            {
                _lock.WaitOne();

                for (int i = 0; i < 50; i++)
                {
                    nodes.Enqueue(new Node <T>(this, Order, false, IsClustered, Clustered_Data_Size));
                }

                _lock.Reset();
            }
        }
 private void LaunchSimpleClient(LaunchItem launchItem)
 {
     if (_worker.IsBusy)
     {
         lblWorkerProgress.Content = "Launcher In Use";
     }
     else
     {
         Properties.Settings.Default.Save();
         _launchConcurrentQueue.Enqueue(launchItem);
         EnableInterface(false);
         btnCancel.IsEnabled = true;
         _launchWorker.LaunchQueue(_launchConcurrentQueue, _clientExeLocation);
     }
 }
Exemple #17
0
        public void TestEmpty()
        {
            var value = string.Empty;
            var len   = BitConverter.GetBytes(value.Length);
            var data  = Encoding.UTF8.GetBytes(value);

            var s         = ObjectExtension.Combine(len, data);
            var usertoken = new System.Collections.Concurrent.ConcurrentQueue <byte[]>();
            var protocol  = new Never.Sockets.AsyncArgs.Connection.DataProtocol();

            usertoken.Enqueue(s);
            usertoken.Enqueue(Encoding.UTF8.GetBytes("hello world"));
            var next = protocol.From(usertoken);
            var tip  = Encoding.UTF8.GetString(next);
        }
        } // End Sub CloseConnection

        protected void ProfilerThread(object state)
        {
            try
            {
                while (!this.m_NeedStop && this.m_Rdr.TraceIsActive)
                {
                    ProfilerEvent evt = this.m_Rdr.Next();
                    if (evt != null)
                    {
                        // lock (this)
                        m_events.Enqueue(evt);
                    } // End if (evt != null)
                }     // Whend
            }
            catch (System.Exception e)
            {
                // lock (this)
                // {
                if (!this.m_NeedStop && this.m_Rdr.TraceIsActive)
                {
                    System.Console.WriteLine($"Error: {e.Message}\n{e.StackTrace}");
                }
                // } // End lock
            } // End Catch
        }     // End Sub ProfilerThread
Exemple #19
0
        void FileShareMessageReceived(ObjectBusMessage message)
        {
            FileShareMessage fileShareMessace = (FileShareMessage)message;

            files.Enqueue(fileShareMessace);
            mre_fileReceived.Set();
        }
Exemple #20
0
        protected void OnAdd(object obj, NotifierEventArgs e)
        {
            if (!string.IsNullOrEmpty(e.DisplayRecord.character) && e.DisplayRecord.character.Equals("engage") && CanShow(e.DisplayRecord))
            {
                if (mostRecentQueue.Count >= 10)
                {
                    VmosoTileDisplayRecord recentDisplayRecord;
                    mostRecentQueue.TryDequeue(out recentDisplayRecord);
                }

                mostRecentQueue.Enqueue(e.DisplayRecord);
            }

            if (currentNotifier == null)
            {
                VmosoNotifierTile ui = new VmosoNotifierTile(top, e.DisplayRecord, expectedSize, Session);
                currentNotifier    = ui;
                ui.OnShownStatus  += new EventHandler(OnShownHandler);
                ui.OnHiddenStatus += new EventHandler(OnHiddenStatus);
                VmosoTileDisplayRecord immediateDisplayRecord;
                notifierQueue.TryDequeue(out immediateDisplayRecord);
                notifierCounter++;
                ui.ShowMessage();
            }
        }
Exemple #21
0
        protected async Task <bool> WaitForJobsAsync()
        {
            try
            {
                var builds = await this.Queue.WaitForJobsAsync(this.AgentOptions.AgentIdentifier, this.Logger);

                await this.Logger.LogInfoAsync($"{builds.Count()} projects were received from the build queue for processing.");

                foreach (var queueEntry in builds)
                {
                    _localQueue.Enqueue(new LocalQueuedJob()
                    {
                        QueueEntry         = queueEntry,
                        RevisionIdentifier = queueEntry.RevisionIdentifier,
                        Configuration      = await this.Repository.GetProject(queueEntry.ProjectID),
                        Output             = new ProjectLogger(this.Repository, queueEntry.BuildQueueID, MessageSeverity.Debug)
                    });
                }

                return(true);
            }
            catch (Exception ex)
            {
                await this.Logger.LogErrorAsync(ex.Message);
            }

            return(false);
        }
 private void _Message(byte[] data)
 {
     foreach (var b in data)
     {
         _Reads.Enqueue(b);
     }
 }
        private void RunGPUProteinDigest(DBOptions options, List <Protein> Proteins, Queries listOfQueries)
        {
            List <double> precursorMasses = new List <double>(listOfQueries.Count);

            //double[] precursors = new double[listOfQueries.Count];
            for (int i = 0; i < listOfQueries.Count; i++)
            {
                precursorMasses.Add(listOfQueries[i].precursor.Mass - Constants.WATER_MONOISOTOPIC_MASS);
            }
            //precursors[i] = listOfQueries[i].precursor.Mass - Constants.WATER_MONOISOTOPIC_MASS;
            precursorMasses.Sort();

            //for each protein, build matrix of mass
            int nbProteins = 0;

            Trinity_Gpu.ProteinDigest pg = new Trinity_Gpu.ProteinDigest(precursorMasses.ToArray(), options.MaximumPeptideLength, options.MinimumPeptideLength);
            foreach (Protein protein in Proteins)
            {
                double[] proteinMasses = GetMasses(protein.BaseSequence);

                foreach (Trinity_Gpu.ProteinPrecursorMatch match in pg.Execute(proteinMasses, options.precursorMassTolerance.Value, options.MaximumPeptideMass))//TODO compute correct tolerance window
                {
                    CumulMatch.Enqueue(new Tuple <Peptide, int>(new Peptide(protein, match.proteinStartPos, match.proteinEndPos, 0), match.firstQueryIndex));
                    //yield return new Tuple<Peptide, int> new Peptide(protein, match.proteinStartPos, match.proteinEndPos, 0);//TODO add modifications
                }

                nbProteins++;
            }
            pg.Dispose();
        }
Exemple #24
0
        /// <summary>
        /// Método Web Service para colocar mensagens na fila de envio aos constroladores da rede
        /// </summary>
        public bool EnviaRequisicao(string CodigoControlador, string CodigoDispositivo, string NovoValor, out string Mensagem)
        {
            Mensagem = string.Empty;

            try
            {
                #region Monta Mensagem
                MensagemDispositivo objMensagem = new MensagemDispositivo();

                // Monta Header
                objMensagem._Header             = new MensagemDispositivo.Header();
                objMensagem._Header.ID_Sender   = Service._configuradorGeral.IdServidor;
                objMensagem._Header.ID_Receiver = CodigoControlador;

                // Monta Command
                objMensagem._Command = new MensagemDispositivo.Command();
                objMensagem._Command.ID_Dispositivo = CodigoDispositivo;
                objMensagem._Command.Disp_Value     = NovoValor;
                #endregion

                // Coloca na Fila para envio
                cqMsgEnvio.Enqueue(objMensagem);
                return(true);
            }
            catch (Exception exc)
            {
                Mensagem = "Erro ao montar requisição de envio ao controlador. Consulte o log para maiores detalhes.";
                controlLog.Insere(Biblioteca.Modelo.Log.LogTipo.Erro, "Erro ao montar requisição de envio ao controlador. (EnviaRequisicao)", exc);
                return(false);
            }
        }
Exemple #25
0
        static void DoConcurrentQueue()
        {
            var ShapeQueue = new System.Collections.Concurrent.ConcurrentQueue <int>();

            for (int i = 0; i < 1000; i++)
            {
                ShapeQueue.Enqueue(i);
            }

            int count = 0;

            for (int i = 0; i < 10; i++)
            {
                System.Threading.ThreadPool.QueueUserWorkItem((o) =>
                {
                    //lock ((ShapeQueue as ICollection).SyncRoot)
                    {
                        int outint;
                        while (ShapeQueue.TryDequeue(out outint))
                        {
                            Console.WriteLine(System.Threading.Interlocked.Increment(ref count));
                            Console.WriteLine(outint);
                        }
                    }
                });
            }
        }
        /// <summary>
        /// Enqueues the <paramref name="command"/> to be sent over Telnet to the IGS SERVER,
        /// then asynchronously receives the entirety of the server's response to this command.
        /// </summary>
        /// <param name="command">The command to send over Telnet.</param>
        /// <returns></returns>
        internal async Task <IgsResponse> MakeRequestAsync(string command)
        {
            IgsRequest request = new IgsRequest(command);

            _outgoingRequests.Enqueue(request);
            ExecuteRequestFromQueue();
            IgsResponse lines = await request.GetAllLines();

            lock (_mutex)
            {
                Debug.Assert(_requestInProgress == request);
                _requestInProgress = null;
            }
            ExecuteRequestFromQueue();
            return(lines);
        }
Exemple #27
0
 /// <summary>
 /// 添加需要访问的数据单元
 /// </summary>
 /// <param name="bsData"></param>
 public void AddNetList(ProDriver.Auxiliary.HZZHComBaseData bsData)
 {
     lock (_syncObj)
     {
         _netQueue.Enqueue(bsData);
     }
 }
        public void WebSocketServer_NewMessageReceived(WebSocketSession session, string e)
        {
            string file_Path = e;

            //if (!file_Paths.Contains(file_Path))
            file_Paths.Enqueue(file_Path);
        }
Exemple #29
0
        [Ignore]    // temporarily ignore test
        public void brutalEUSESTest()
        {
            var failures = new System.Collections.Concurrent.ConcurrentQueue <string>();

            var mwb = MockWorkbook.standardMockWorkbook();

            var formulas = System.IO.File.ReadAllLines(@"..\..\TestData\formulas_distinct.txt");

            System.Threading.Tasks.Parallel.ForEach(formulas, f =>
            {
                try
                {
                    Parcel.parseFormula(f, mwb.Path, mwb.WorkbookName, mwb.worksheetName(1));
                }
                catch (Exception e)
                {
                    if (e is AST.IndirectAddressingNotSupportedException)
                    {
                        // OK
                    }
                    else if (e is AST.ParseException)
                    {
                        System.Diagnostics.Debug.WriteLine("Fail: " + f);
                        failures.Enqueue(f);
                    }
                }
            });

            Assert.AreEqual(0, failures.Count());
            if (failures.Count > 0)
            {
                String.Join("\n", failures);
            }
        }
Exemple #30
0
 protected virtual void OnDataReceive(DataFrame data)
 {
     if (DataReceive != null)
     {
         WSReceiveArgs e = new WSReceiveArgs();
         e.Client = this;
         e.Frame  = data;
         DataReceive(this, e);
     }
     else
     {
         lock (mLockReceive)
         {
             if (mReceiveCompletionSource != null)
             {
                 var result = mReceiveCompletionSource;
                 mReceiveCompletionSource = null;
                 Task.Run(() => result.Success(data));
             }
             else
             {
                 mDataFrames.Enqueue(data);
             }
         }
     }
 }
Exemple #31
0
        public void Bug_ConcurrentMerge()
        {
            const int reps = 1000;
            var source = Enumerable.Range(0, reps).ToObservable();

            var resultQueue = new System.Collections.Concurrent.ConcurrentQueue<int>();
            var r = new Random();

            source.Select(i => Observable.Create<Unit>(o =>
            {
                resultQueue.Enqueue(i);
                System.Threading.Tasks.Task.Factory.StartNew(
                    () =>
                    {
                        Thread.Sleep(r.Next(10));
                        o.OnCompleted();
                    });
                return () => { };
            })).Merge(3).ForEach(_ => { });

            Assert.IsTrue(Enumerable.Range(0, reps).ToList().SequenceEqual(resultQueue.ToList()));
        }
Exemple #32
0
        ///  <summary>
        ///  Reads data from the ADS1298 device and produces data frames to be sent live to clients.
        ///  </summary>
        internal void ReadDataLive()
        {
            const UInt32 maxBufferSize = 62208;				// Optimal buffer value
            const UInt32 maxBufferDelay = 15;               // Maximum buffer delay in milliseconds

            UInt32 bufferSize;
            UInt32 bytesRead = 0;
            UInt32 sampleFreq;

            UInt32 frameCounter = 0;                      // frame sequence number relative to the beginning of the data acquisition
            UInt32 frameDiff;                             // Difference to calculate the frames in the current package
            UInt32 nPackets = 0;                          //Debug variable to show the numbers of frames generated

            Byte[] readBuffer;
            Byte[] writeBuffer = new Byte[USB_PACKET_SIZE];
            Boolean success = false, sendSuccess = true;

            // Select a optimal buffer size (not extending the consts above)
            WinUsbDevice myWinUsb = new WinUsbDevice();
            Stopwatch myStopwatch = new Stopwatch();
            long ticksBegin, ticksEnd;
            double timeStamp, timeDelta;

            sampleFreq = (UInt32)(HR ? DR_VALUE_HR : DR_VALUE_LP);

            //bufferSize = (UInt32)((sampleFreq * DATALENGTH * (UInt32)((myWinUsb.pipeTimeout<maxBufferDelay) ? myWinUsb.pipeTimeout : maxBufferDelay )* 0.75) / 1000);

            //The buffer size is solely determined by the maximum buffer delay that we choose to allow.
            bufferSize = (UInt32) (DATALENGTH * sampleFreq * maxBufferDelay / 1000);
            bufferSize = bufferSize > maxBufferSize ? maxBufferSize : bufferSize;

            readBuffer = new Byte[bufferSize];
            _packetQueue = new System.Collections.Concurrent.ConcurrentQueue<RawDataPacket>();
            RawDataPacket finalPacket;

            try
            {
                winUsbDev.FlushPipe(PIPE_DATA_IN);

                // Send start-command to ADS device.
                writeBuffer[0] = CMD_START;
                success = winUsbDev.SendBulkData(PIPE_COMMAND_OUT, ref writeBuffer, (UInt32)writeBuffer.Length);       // Send start-command to ADS device.

                if (success)
                {
                    myStopwatch.Reset();
                    myStopwatch.Start();
                    do
                    {
                        // Read some data.
                        ticksBegin = myStopwatch.ElapsedTicks;
                        winUsbDev.ReadBulkData(PIPE_DATA_IN, bufferSize, ref readBuffer, ref bytesRead, ref success);
                        ticksEnd = myStopwatch.ElapsedTicks;

                        timeStamp = (double)ticksBegin / (double)Stopwatch.Frequency;
                        timeDelta = (double)(ticksEnd - ticksBegin) / (double)Stopwatch.Frequency;

                        // Get a proper frame index for our newly read frames
                        // This frame index is 24-bit wide, so at 2000 samples/sec it will
                        // overflow and get back to 0 every 8388 seconds

                        frameDiff=0;

                        for (UInt32 i = 0; i < bytesRead; i += DATALENGTH)
                        {
                            frameCounter = frameCounter & 0x00ffffff;
                            readBuffer[i] = (Byte) ((frameCounter & 0x00ff0000) >> 16);
                            readBuffer[i+1] = (Byte) ((frameCounter & 0x0000ff00) >> 8);
                            readBuffer[i+2] = (Byte) (frameCounter & 0x000000ff);
                            frameCounter++;
                            frameDiff++;
                        }

                            //Here we can create a packet and add it to the frame collection
                            _packetQueue.Enqueue(new RawDataPacket(readBuffer, (Int32)bytesRead, sampleFreq, NumberOfChannels, DATALENGTH, frameDiff, timeStamp, timeDelta));

                        nPackets++;

                        //We have read a new packet, so we make our listeners aware of it
                        OnNewPacket(EventArgs.Empty);

                        sendSuccess &= success;
                    }
                    while (processingData && bytesRead != 0);

                    //Now we send a special duplicate packet indicating there will be no more packets coming
                    finalPacket=new RawDataPacket(readBuffer, (Int32)bytesRead, sampleFreq, NumberOfChannels, DATALENGTH, frameDiff,timeStamp,timeDelta);
                    finalPacket.lastPacket = true;
                    _packetQueue.Enqueue(finalPacket);

                    OnNewPacket(EventArgs.Empty);

                    //DEBUG
                    Console.Out.WriteLine("{0} packets processed.", nPackets);
                    //DEBUG/
                }
                if (sendSuccess)
                {
                    writeBuffer[0] = CMD_STOP;
                    success = winUsbDev.SendBulkData(PIPE_COMMAND_OUT, ref writeBuffer, (UInt32)writeBuffer.Length);   // Send stop-command to ADS device.
                }
            }
            catch (ThreadAbortException)
            {
                throw;
            }

            finally
            {
                writeBuffer[0] = CMD_STOP;
                winUsbDev.SendBulkData(PIPE_COMMAND_OUT, ref writeBuffer, (UInt32)writeBuffer.Length);					// Send stop-command to ADS device.
                winUsbDev.ReadBulkData(PIPE_DATA_IN, bufferSize, ref readBuffer, ref bytesRead, ref success);		// Read the samples after we stopped the reading process.
            }
        }
        public RegionData LoadBackup(string file)
        {
            if (!File.Exists(file))
                return null;

            var stream = ArchiveHelpers.GetStream(file);
            if (stream == null)
                return null;

            GZipStream m_loadStream = new GZipStream(stream, CompressionMode.Decompress);
            TarArchiveReader reader = new TarArchiveReader(m_loadStream);
            List<uint> foundLocalIDs = new List<uint>();
            RegionData regiondata = new RegionData();
            regiondata.Init();

            byte[] data;
            string filePath;
            TarArchiveReader.TarEntryType entryType;
            System.Collections.Concurrent.ConcurrentQueue<byte[]> groups =
                new System.Collections.Concurrent.ConcurrentQueue<byte[]>();
            //Load the archive data that we need
            while ((data = reader.ReadEntry(out filePath, out entryType)) != null)
            {
                if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY == entryType)
                    continue;

                if (filePath.StartsWith("parcels/"))
                {
                    //Only use if we are not merging
                    LandData parcel = new LandData();
                    OSD parcelData = OSDParser.DeserializeLLSDBinary(data);
                    parcel.FromOSD((OSDMap) parcelData);
                    if (parcel.OwnerID != UUID.Parse("05948863-b678-433e-87a4-e44d17678d1d"))
                        //The default owner of the 'default' region
                        regiondata.Parcels.Add(parcel);
                }
                else if (filePath.StartsWith("newstyleterrain/"))
                {
                    regiondata.Terrain = data;
                }
                else if (filePath.StartsWith("newstylerevertterrain/"))
                {
                    regiondata.RevertTerrain = data;
                }
                else if (filePath.StartsWith("newstylewater/"))
                {
                    regiondata.Water = data;
                }
                else if (filePath.StartsWith("newstylerevertwater/"))
                {
                    regiondata.RevertWater = data;
                }
                else if (filePath.StartsWith("entities/"))
                {
                    groups.Enqueue(data);
                }
                else if (filePath.StartsWith("regioninfo/"))
                {
                    RegionInfo info = new RegionInfo();
                    info.FromOSD((OSDMap) OSDParser.DeserializeLLSDBinary(data));
                    regiondata.RegionInfo = info;
                }
                data = null;
            }
            m_loadStream.Close();
            m_loadStream = null;

            int threadCount = groups.Count > 16 ? 16 : groups.Count;
            System.Threading.Thread[] threads = new System.Threading.Thread[threadCount];
            for (int i = 0; i < threadCount; i++)
            {
                threads[i] = new System.Threading.Thread(() =>
                                                             {
                                                                 byte[] groupData;
                                                                 while (groups.TryDequeue(out groupData))
                                                                 {
                                                                     MemoryStream ms = new MemoryStream(groupData);
                                                                     ISceneEntity sceneObject =
                                                                         SceneEntitySerializer.SceneObjectSerializer
                                                                                              .FromXml2Format(ref ms,
                                                                                                              null);
                                                                     ms.Close();
                                                                     ms = null;
                                                                     data = null;
                                                                     if (sceneObject != null)
                                                                     {
                                                                         foreach (
                                                                             ISceneChildEntity part in
                                                                                 sceneObject.ChildrenEntities())
                                                                         {
                                                                             lock (foundLocalIDs)
                                                                             {
                                                                                 if (
                                                                                     !foundLocalIDs.Contains(
                                                                                         part.LocalId))
                                                                                     foundLocalIDs.Add(part.LocalId);
                                                                                 else
                                                                                     part.LocalId = 0;
                                                                                         //Reset it! Only use it once!
                                                                             }
                                                                         }
                                                                         regiondata.Groups.Add(
                                                                             sceneObject as SceneObjectGroup);
                                                                     }
                                                                 }
                                                             });
                threads[i].Start();
            }
            for (int i = 0; i < threadCount; i++)
                threads[i].Join();

            foundLocalIDs.Clear();

            return regiondata;
        }
Exemple #34
0
        public void brutalEUSESTest()
        {
            var failures = new System.Collections.Concurrent.ConcurrentQueue<string>();

            var mwb = MockWorkbook.standardMockWorkbook();

            var formulas = System.IO.File.ReadAllLines(@"..\..\TestData\formulas_distinct.txt");

            System.Threading.Tasks.Parallel.ForEach(formulas, f =>
            {
                try
                {
                    Parcel.parseFormula(f, mwb.Path, mwb.WorkbookName, mwb.worksheetName(1));
                }
                catch (Exception e)
                {
                    if (e is AST.IndirectAddressingNotSupportedException)
                    {
                        // OK
                    }
                    else if (e is AST.ParseException)
                    {
                        System.Diagnostics.Debug.WriteLine("Fail: " + f);
                        failures.Enqueue(f);
                    }
                }
            });

            Assert.AreEqual(0, failures.Count());
            if (failures.Count > 0)
            {
                String.Join("\n", failures);
            }
        }
Exemple #35
0
        public void TransformStream(Stream a_stream, long a_length = -1)
        {
            Debug.Assert((a_length == -1 || a_length > 0));

            if (a_stream.CanSeek)
            {
                if (a_length > -1)
                {
                    if (a_stream.Position + a_length > a_stream.Length)
                        throw new IndexOutOfRangeException();
                }

                if (a_stream.Position >= a_stream.Length)
                    return;
            }

            System.Collections.Concurrent.ConcurrentQueue<byte[]> queue =
                new System.Collections.Concurrent.ConcurrentQueue<byte[]>();
            System.Threading.AutoResetEvent data_ready = new System.Threading.AutoResetEvent(false);
            System.Threading.AutoResetEvent prepare_data = new System.Threading.AutoResetEvent(false);

            Task reader = Task.Factory.StartNew(() =>
            {
                long total = 0;

                for (; ; )
                {
                    byte[] data = new byte[BUFFER_SIZE];
                    int readed = a_stream.Read(data, 0, data.Length);

                    if ((a_length == -1) && (readed != BUFFER_SIZE))
                        data = data.SubArray(0, readed);
                    else if ((a_length != -1) && (total + readed >= a_length))
                        data = data.SubArray(0, (int)(a_length - total));

                    total += data.Length;

                    queue.Enqueue(data);
                    data_ready.Set();

                    if (a_length == -1)
                    {
                        if (readed != BUFFER_SIZE)
                            break;
                    }
                    else if (a_length == total)
                        break;
                    else if (readed != BUFFER_SIZE)
                        throw new EndOfStreamException();

                    prepare_data.WaitOne();
                }
            });

            Task hasher = Task.Factory.StartNew((obj) =>
            {
                IHash h = (IHash)obj;
                long total = 0;

                for (; ; )
                {
                    data_ready.WaitOne();

                    byte[] data;
                    queue.TryDequeue(out data);

                    prepare_data.Set();

                    total += data.Length;

                    if ((a_length == -1) || (total < a_length))
                    {
                        h.TransformBytes(data, 0, data.Length);
                    }
                    else
                    {
                        int readed = data.Length;
                        readed = readed - (int)(total - a_length);
                        h.TransformBytes(data, 0, data.Length);
                    }

                    if (a_length == -1)
                    {
                        if (data.Length != BUFFER_SIZE)
                            break;
                    }
                    else if (a_length == total)
                        break;
                    else if (data.Length != BUFFER_SIZE)
                        throw new EndOfStreamException();
                }
            }, this);

            reader.Wait();
            hasher.Wait();
        }
Exemple #36
0
        public static void ExecuteMain(string nick, IndexArgumentSetup setup, Action prepare_db)
        {
            var dbname = String.Format ("DB.{0}", Path.GetFileName(setup.DATABASE));
            setup.BINARY_DATABASE = dbname;

            prepare_db ();

            SpaceGenericIO.Load (setup.BINARY_DATABASE);
            var arglist = new System.Collections.Concurrent.ConcurrentQueue<String> ();
            arglist.Enqueue ("--save");
            arglist.Enqueue (String.Format ("Tab.ExactIndexes.{0}.{1}.qarg={2}.json", nick, Path.GetFileName (setup.QUERIES), setup.QARG));

            arglist.Enqueue (Indexes.ExecuteSeq (setup, nick));
            var actionlist = new List<Action> ();

            if (setup.ExecuteNANNI) {
                actionlist.Add (() => {
                    foreach (var resname in Indexes.ExecuteNANNI(setup, nick)) {
                        arglist.Enqueue(resname);
                    }
                });
            }
            if (setup.ExecuteTNANNI) {
                actionlist.Add (() => {
                    arglist.Enqueue(Indexes.ExecuteTNANNI(setup, nick));
                });
            }
            if (setup.ExecuteDNANNI) {
                actionlist.Add (() => {
                    arglist.Enqueue(Indexes.ExecuteDNANNI(setup, nick));
                });
            }

            if (setup.ExecuteSAT) {
                actionlist.Add (() => {
                    var resname = Indexes.ExecuteSAT (setup, nick);
                    arglist.Enqueue (resname);
                });
            }
            if (setup.ExecuteSATDistal) {
                actionlist.Add (() => {
                    var resname = Indexes.ExecuteSATDistal (setup, nick);
                    arglist.Enqueue (resname);
                });
            }
            if (setup.ExecuteSATRandom) {
                actionlist.Add (() => {
                    var resname = Indexes.ExecuteSATRandom (setup, nick);
                    arglist.Enqueue(resname);
                });
            }

            if (setup.ExecuteVPT) {
                actionlist.Add (() => {
                    var resname = Indexes.ExecuteVPT (setup, nick);
                    arglist.Enqueue (resname);
                });
            }

            // arglist.Add (Indexes.ExecuteVPTX (setup, nick));
            //arglist.Add (Indexes.ExecuteMILCv3 (setup, nick));

            foreach (var bsize in setup.LC) {
                var _bsize = bsize;
                actionlist.Add (() => {
                    var resname = Indexes.ExecuteLC (setup, nick, _bsize);
                    arglist.Enqueue(resname);
                });
            }

            foreach (var numGroups in setup.MANNI) {
                var _numGroups = numGroups;
                actionlist.Add (() => {
                    var resname = Indexes.ExecuteMANNI (setup, nick, _numGroups);
                    arglist.Enqueue(resname);
                });
                actionlist.Add (() => {
                    var resname = Indexes.ExecuteTMANNI (setup, nick, _numGroups);
                    arglist.Enqueue(resname);
                });
                actionlist.Add (() => {
                    var resname = Indexes.ExecuteDMANNI (setup, nick, _numGroups);
                    arglist.Enqueue(resname);
                });
                //arglist.Add (Indexes.ExecuteMILCv2 (setup, nick, numGroups));
            }

            foreach (var numGroups in setup.EPT) {
                var _numGroups = numGroups;
                actionlist.Add (() => {
                    var resname = Indexes.ExecuteEPTA (setup, nick, _numGroups);
                    arglist.Enqueue (resname);
                });
                // arglist.Add (Indexes.ExecuteEPT (setup, nick, numGroups));
            }

            foreach (var numPivs in setup.BNC) {
                var _numPivs = numPivs;
                actionlist.Add (() => {
                    var resname = Indexes.ExecuteBNCInc (setup, nick, _numPivs);
                    arglist.Enqueue (resname);
                });
            }

            foreach (var numPivs in setup.KVP) {
                var _numPivs = numPivs;
                actionlist.Add (() => {
                    var resname = Indexes.ExecuteKVP (setup, nick, _numPivs, setup.KVP_Available);
                    arglist.Enqueue (resname);
                });
            }

            foreach (var numPivs in setup.SPA) {
                var _numPivs = numPivs;
                actionlist.Add (() => {
                    var resname = Indexes.ExecuteSpaghetti (setup, nick, _numPivs);
                    arglist.Enqueue (resname);
                });
            }

            foreach (var numPivs in setup.LAESA) {
                var _numPivs = numPivs;
                actionlist.Add (() => {
                    var resname = Indexes.ExecuteLAESA (setup, nick, _numPivs);
                    arglist.Enqueue (resname);
                });
            }

            foreach (var alpha in setup.SSS) {
                var _alpha = alpha;
                actionlist.Add (() => {
                    var resname = Indexes.ExecuteSSS (setup, nick, _alpha, setup.SSS_max);
                    arglist.Enqueue (resname);
                });
            }

            if (setup.SPAWN == 1) {
                foreach (var action in actionlist) {
                    action.Invoke ();
                }
            } else {
                LongParallel.ForEach (actionlist, (a) => a.Invoke (), setup.SPAWN);
            }
            if (setup.ExecuteSearch) {
                Commands.Check (arglist);
            }
        }
        protected virtual void ReadBackup(IScene scene)
        {
            MainConsole.Instance.Debug("[FileBasedSimulationData]: Reading file for " + scene.RegionInfo.RegionName);
            List<uint> foundLocalIDs = new List<uint>();
            var stream = ArchiveHelpers.GetStream((m_loadDirectory == "" || m_loadDirectory == "/")
                                                      ? m_fileName
                                                      : Path.Combine(m_loadDirectory, m_fileName));
            if(stream == null)
                return;

            GZipStream m_loadStream = new GZipStream(stream, CompressionMode.Decompress);
            TarArchiveReader reader = new TarArchiveReader(m_loadStream);

            byte[] data;
            string filePath;
            TarArchiveReader.TarEntryType entryType;
            System.Collections.Concurrent.ConcurrentQueue<byte[]> groups = new System.Collections.Concurrent.ConcurrentQueue<byte[]>();
            //Load the archive data that we need
            while ((data = reader.ReadEntry(out filePath, out entryType)) != null)
            {
                if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY == entryType)
                    continue;

                if (filePath.StartsWith("parcels/"))
                {
                    //Only use if we are not merging
                    LandData parcel = new LandData();
                    OSD parcelData = OSDParser.DeserializeLLSDBinary(data);
                    parcel.FromOSD((OSDMap) parcelData);
                    m_parcels.Add(parcel);
                }
                else if (filePath.StartsWith("terrain/"))
                {
                    m_oldstyleterrain = data;
                }
                else if (filePath.StartsWith("revertterrain/"))
                {
                    m_oldstylerevertTerrain = data;
                }
                else if (filePath.StartsWith("newstyleterrain/"))
                {
                    m_terrain = data;
                }
                else if (filePath.StartsWith("newstylerevertterrain/"))
                {
                    m_revertTerrain = data;
                }
                else if (filePath.StartsWith("newstylewater/"))
                {
                    m_water = data;
                }
                else if (filePath.StartsWith("newstylerevertwater/"))
                {
                    m_revertWater = data;
                }
                else if (filePath.StartsWith("entities/"))
                {
                    groups.Enqueue(data);
                }
                data = null;
            }
            m_loadStream.Close();
            m_loadStream = null;

            int threadCount = groups.Count > 16 ? 16 : groups.Count;
            System.Threading.Thread[] threads = new System.Threading.Thread[threadCount];
            for (int i = 0; i < threadCount; i++)
            {
                threads[i] = new System.Threading.Thread(() =>
                    {
                        byte[] groupData;
                        while(groups.TryDequeue(out groupData))
                        {
                            MemoryStream ms = new MemoryStream(groupData);
                            SceneObjectGroup sceneObject = SceneObjectSerializer.FromXml2Format(ref ms, scene);
                            ms.Close();
                            ms = null;
                            data = null;
                            if (sceneObject != null)
                            {
                                foreach (ISceneChildEntity part in sceneObject.ChildrenEntities())
                                {
                                    lock (foundLocalIDs)
                                    {
                                        if (!foundLocalIDs.Contains(part.LocalId))
                                            foundLocalIDs.Add(part.LocalId);
                                        else
                                            part.LocalId = 0; //Reset it! Only use it once!
                                    }
                                }
                                m_groups.Add(sceneObject);
                            }
                        }
                    });
                threads[i].Start();
            }
            for (int i = 0; i < threadCount; i++)
                threads[i].Join();


            foundLocalIDs.Clear();
            GC.Collect();
        }