public bool FindDocument(string name, string colname, out JSONDocument doc)
        {
            bool found = false;
            IList <IJSONDocument> jsonDocuments = new List <IJSONDocument>();

            doc = new JSONDocument();

            if (name != null)
            {
                doc.Key = name.ToLower();
                jsonDocuments.Add(doc);
                IGetOperation getOperation = new GetDocumentsOperation();
                getOperation.Database    = MiscUtil.SYSTEM_DATABASE;
                getOperation.Collection  = colname;
                getOperation.DocumentIds = jsonDocuments;
                IGetResponse response  = _store.GetDocuments(getOperation);
                IDataChunk   dataChunk = response.DataChunk;
                if (dataChunk.Documents.Count != 0)
                {
                    doc   = dataChunk.Documents[0] as JSONDocument;
                    found = true;
                }
                else
                {
                    doc   = null;
                    found = false;
                }
            }
            return(found);
        }
Exemple #2
0
 protected override bool FillNewData(int lastChunkId, ref IDataChunk dataChunk)
 {
     foreach (var rowId in _lastChunkData)
     {
         _store.DeleteDocument(rowId, _context);
     }
     return(base.FillNewData(lastChunkId, ref dataChunk));
 }
Exemple #3
0
 void NotifyWritten(IDataChunk item)
 {
     Interlocked.Exchange(ref currentOffset, item.ActualOffset);
     if (!notifyInProgress)
     {
         notifyInProgress = true;
         _dispatcher.BeginInvoke(new Action(NotifyWrittenDispatched), DispatcherPriority.Background);
     }
 }
 public DistributedDataSet(IDataChunk dataChunk, string shardName, IDBOperation operation, IDataLoader dataLoader, Server readerLocationAddress)
 {
     _shardName     = shardName;
     _dataChunk     = dataChunk;
     _isFixedSize   = dataChunk.IsLastChunk;
     _isExhausted   = false;
     _operation     = operation;
     _dataLoader    = dataLoader;
     _readerAddress = readerLocationAddress;
 }
        private void InsertDataChunk(IDataChunk dataChunk)
        {
            foreach (IJSONDocument jDoc in dataChunk.Documents)
            {
                _dataChunk.Documents.Add(jDoc);
            }

            _dataChunk.ChunkId     = dataChunk.ChunkId;
            _dataChunk.IsLastChunk = dataChunk.IsLastChunk;
        }
Exemple #6
0
        public bool FillDataChunk(int lastChunkId, ref IDataChunk dataChunk)
        {
            UsageStats stats = new UsageStats();

            stats.BeginSample();
            bool check = _lastChunkId == lastChunkId?FillNewData(lastChunkId, ref dataChunk) : FillPreviousData(lastChunkId, ref dataChunk);

            stats.EndSample();
            //if (LoggerManager.Instance.QueryLogger != null)
            //    LoggerManager.Instance.QueryLogger.Debug("GetNextChunk", "QueryID: "+_queryId+
            //        ", Refilling last chunk: " + check + ", Time taken: " + stats.Current);

            return(check);
        }
        public CollectionReader(IDataChunk dataChunk, IStore store, string databaseName, string collectionName)
        {
            _dataChunk = dataChunk;

            if (store != null)
            {
                _store = store;
            }
            else
            {
                throw new ArgumentNullException("store");
            }

            _databaseName   = databaseName;
            _collectionName = collectionName;
        }
        ChunkViewItem CreateChunkView(IDataChunk chunk)
        {
            switch (chunk)
            {
            case Packet tChunk: return(new RawData()
                {
                    Chunk = tChunk, ViewContent = this
                });

            case MessageData tChunk: return(new Message()
                {
                    Chunk = tChunk, ViewContent = this
                });

            default: throw new ArgumentException($"Unsupported chunk type: {chunk.GetType()}", nameof(chunk));
            }
        }
Exemple #9
0
        public void Write(IDataChunk chunk)
        {
            if (chunk is Packet packet)
            {
                Write(packet);
            }
            else if (chunk is MessageData message)
            {
                Write(message);
            }
            else
            {
                throw new InvalidOperationException("Unsupported data type: " + chunk.GetType());
            }

            BaseStream.Flush();
        }
Exemple #10
0
        public void CopyRange(IDataChunk start, IDataChunk end, Func <IDataChunk, byte[]> payload)
        {
            var progressScale = 1.0 / (end.ActualOffset - start.ActualOffset);

            using (var reader = storage.CreateReader())
            {
                ReportProgress(0);

                reader.Position = start.ActualOffset;

                Copy(reader, chunk =>
                {
                    ReportProgress((chunk.ActualOffset - start.ActualOffset) * progressScale);
                    return(chunk.ActualOffset <= end.ActualOffset ? payload(chunk) : null);
                });

                ReportProgress(1);
            }
        }
Exemple #11
0
        public void Write(IDataChunk chunk, byte[] data)
        {
            var par = _doc.addParagraph();

            par.setText(_encoding.GetString(data));

            if (chunk is Packet packet)
            {
                if (packet.Flow == TrafficFlow.Inbound)
                {
                    par.DefaultCharFormat.FgColor = _inFg;
                    par.DefaultCharFormat.BgColor = _inBg;
                }
                if (packet.Flow == TrafficFlow.Outbound)
                {
                    par.DefaultCharFormat.FgColor = _outFg;
                    par.DefaultCharFormat.BgColor = _outBg;
                }
            }
        }
Exemple #12
0
        /// <summary>
        /// Thread-safe append chunk to file.
        /// </summary>
        public void Write(IDataChunk item)
        {
            lock (_syncObject)
            {
                if (!CanWrite)
                {
                    throw new InvalidOperationException("Not writable.");
                }

                item.SequenceNumber = SequenceCounter++;

                writer.Write(item);

                ChunkCount++;
                Interlocked.Exchange(ref writerPosition, writerStream.Position);
                Interlocked.Exchange(ref writerLinesCountApprox, 0 /* TODO */);

                NotifyWritten(item);
            }
        }
Exemple #13
0
        //public bool IsClosed()
        //{
        //    return _disposed || _documentIndex >= _dataChunk.Documents.Count;
        //}

        public void GetNextChunk()
        {
            _isFirstChunk = false;
            GetChunkOperation getChunkOperation = new GetChunkOperation();

            getChunkOperation.Database    = _databaseName;//_database.DatabaseName
            getChunkOperation.Collection  = _collectionName;
            getChunkOperation.ReaderUID   = _dataChunk.ReaderUID;
            getChunkOperation.LastChunkId = _dataChunk.ChunkId;
            getChunkOperation.QueryString = _dataChunk.QueryString;
            getChunkOperation.DoCaching   = _dataChunk.DoCaching;

            // GetChunkResponse getChunkResponse = (GetChunkResponse)_database.ExecutionMapper.GetDataChunk(getChunkOperation);
            GetChunkResponse getChunkResponse = (GetChunkResponse)_store.GetDataChunk(getChunkOperation);

            if (!getChunkResponse.IsSuccessfull)
            {
                throw new Exception("Operation failed Error Code " + getChunkResponse.ErrorCode);
            }
            _dataChunk = (DataChunk)getChunkResponse.DataChunk;
        }
Exemple #14
0
        private int _numOfRequiredDocuments;    // Only required number of documents are returned by to the client

        public IterativeOperation(IList <ISet> sets, List <IDataCombiner> combiners, IDataSelector dataSelector, IComparer comparer)
        {
            _lastReaderId    = null;
            _lastSentChunkId = -1;
            _dataSelector    = dataSelector;
            IList <ISet> setsToBeRemoved = new List <ISet>();

            foreach (var set in sets)
            {
                if (set.IsFixedSize == true && set.GetTopElement() == null)
                {
                    setsToBeRemoved.Add(set);
                    set.DisposeReader();
                }
            }

            ListUtilMethods.RemoveMultipleItemsFromList(sets, setsToBeRemoved);

            _dataSelector.Initialize(sets, combiners, comparer);
            _lastSentDataChunk = null;
            _autoChunkId       = -1;
        }
Exemple #15
0
        public void Write(IDataChunk chunk, byte[] data)
        {
            const int microseconds = 1_000_000;

            if (chunk is Packet packet)
            {
                foreach (var raw in _encoder.BuildPacket(packet))
                {
                    if (disposed)
                    {
                        break;
                    }
                    var unixUs = packet.Timestamp.UtcDateTime.GetUnixMicroSeconds();
                    if (unixUs <= lastMicroseconds)
                    {
                        unixUs = lastMicroseconds + 1;                             // every packet should have unique timestamp and increment sequentially
                    }
                    _pcap.WritePacket(new PcapPacket(unixUs / microseconds, unixUs % microseconds, raw));
                    lastMicroseconds = unixUs;
                }
            }
        }
Exemple #16
0
        /// <summary>
        /// if last chunk not recieved by client simply send the stored data again
        /// </summary>
        /// <param name="lastChunkId"></param>
        /// <param name="dataChunk"></param>
        protected bool FillPreviousData(int lastChunkId, ref IDataChunk dataChunk)
        {
            foreach (long rowId in _lastChunkData)
            {
                IJSONDocument jsonDocument = _store.GetDocument(rowId, _context);
                if (jsonDocument != null)
                {
                    jsonDocument = _transform.Transform(jsonDocument);
                    if (jsonDocument != null)
                    {
                        dataChunk.Documents.Add(jsonDocument);
                    }
                }
            }

            dataChunk.IsLastChunk = _isLastChunk;

            dataChunk.ChunkId   = lastChunkId + 1;
            _lastChunkId        = lastChunkId + 1;
            dataChunk.ReaderUID = _id;

            return(true);
        }
Exemple #17
0
        /// <summary>
        /// Returns the DataChunk that will be sent to the client, who requested for it, inside the Response
        /// </summary>
        /// <param name="chunkId"></param>
        /// <param name="numOfRequiredDocuments"></param>
        /// <returns></returns>
        internal IDataChunk GetDataChunk(int chunkId, int numOfRequiredDocuments)
        {
            if (chunkId != _lastSentChunkId)    // If last Chunk was not received properly at client end
            {
                if (_lastSentDataChunk == null)
                {
                    throw new Exception("Invalid ChunkId");
                }
                return(_lastSentDataChunk);
            }

            _numOfRequiredDocuments = numOfRequiredDocuments;

            IDataChunk dataChunk = new DataChunk();

            _autoChunkId++;
            dataChunk.ChunkId = _autoChunkId;

            for (int i = 0; i < numOfRequiredDocuments; i++)
            {
                if (_dataSelector.MoveNext())
                {
                    ISetElement element = (ISetElement)_dataSelector.Current;
                    dataChunk.Documents.Add((IJSONDocument)element.Value);
                }
                else
                {
                    dataChunk.IsLastChunk = true;
                    return(dataChunk);
                }
            }

            _lastSentChunkId   = dataChunk.ChunkId;
            _lastSentDataChunk = dataChunk;
            return(dataChunk);
        }
 protected virtual void OnStreamDataAdded(IAdaptiveMediaPlugin mediaPlugin, IMediaStream stream,
                                          IDataChunk dataChunk)
 {
     try
     {
         if (stream.AvailableTracks.Count() > 0)
         {
             IMediaTrack track = stream.AvailableTracks.First();
             ActiveAdaptiveMediaPlugin.DownloadStreamData(track, dataChunk);
             SendLogEntry(KnownLogEntryTypes.StreamDataAdded,
         extendedProperties: new Dictionary<string, object> { { "StreamName", stream.Name } });
         }
     }
     catch (Exception err)
     {
         string message = string.Format(SilverlightMediaFrameworkResources.GenericErrorOccurredLogMessage,
                                        "OnStreamDataAdded", err.Message);
         SendLogEntry(KnownLogEntryTypes.GeneralErrorOccurred, LogLevel.Error, message);
     }
 }
 public DataReceivedInfo(byte[] Data, IDataChunk DataChunk, IDictionary <string, string> StreamAttributes)
 {
     this.Data             = Data;
     this.DataChunk        = DataChunk;
     this.StreamAttributes = StreamAttributes;
 }
 public MediaDrmSetupDecryptorCompletedEventArgs(Guid keyId, IDataChunk dataChunk, Exception error, bool cancelled, object userState) : base(error, cancelled, userState)
 {
     KeyId = keyId;
     DataChunk = dataChunk;
 }
Exemple #21
0
        /// <summary>
        /// Get New Data according to chunk size From Store and Fill data Chunk
        /// Stores New Data Locally also in case chunk not recieve by user next time can send from local
        /// </summary>
        /// <param name="lastChunkId"></param>
        /// <param name="dataChunk"></param>
        protected virtual bool FillNewData(int lastChunkId, ref IDataChunk dataChunk)
        {
            int  count = 0;
            bool check = false;

            _lastChunkData.Clear();

            if (_lastElementCheck)
            {
                IJSONDocument jsonDocument = _store.GetDocument(_lastElement, _context);
                if (jsonDocument != null)
                {
                    jsonDocument = _transform.Transform(jsonDocument);
                    if (jsonDocument != null)
                    {
                        dataChunk.Documents.Add(jsonDocument);
                        _lastChunkData.Add(_lastElement);
                        count++;
                    }
                }

                _lastElementCheck = false;
            }

            while (_enumerator.MoveNext())
            {
                if (check)
                {
                    check             = false;
                    _lastElement      = _enumerator.Current;      ////To Save Round Trip in case Data Chunk fills and Data also finish so that can make the existing chunk as last chunk
                    _lastElementCheck = true;
                    break;
                }

                IJSONDocument jsonDocument = _store.GetDocument(_enumerator.Current, _context);
                if (jsonDocument != null)
                {
                    jsonDocument = _transform.Transform(jsonDocument);
                    if (jsonDocument != null)
                    {
                        dataChunk.Documents.Add(jsonDocument);
                        _lastChunkData.Add(_enumerator.Current);
                        count++;
                    }
                }

                if (count == _chunkSize)
                {
                    check = true;
                }
            }

            if (count < _chunkSize || check)
            {
                dataChunk.IsLastChunk = true;
                _isLastChunk          = true;
            }
            else
            {
                dataChunk.IsLastChunk = false;
            }

            dataChunk.ReaderUID = _id;
            dataChunk.ChunkId   = lastChunkId + 1;
            _lastChunkId        = lastChunkId + 1;

            return(true);
        }
        /// <summary>
        /// Downloads the chunk of data that is part of the specified track and has the specified timestamp id.
        /// </summary>
        /// <param name="track">the track that contains the data to be downloaded.</param>
        /// <param name="chunk">the chunk to be downloaded.</param>
        public void DownloadStreamData(IMediaTrack track, IDataChunk chunk)
        {
#if !WINDOWS_PHONE
            var mediaTrack = track as MediaTrack;

            if (mediaTrack != null)
            {
                _chunkDownloadManager.AddRequest(mediaTrack, chunk.Timestamp);
            }
#endif
        }
 public DataReceivedInfo(byte[] Data, IDataChunk DataChunk, IDictionary<string, string> StreamAttributes) 
 {
     this.Data = Data;
     this.DataChunk = DataChunk;
     this.StreamAttributes = StreamAttributes;
 }
        public static IDataChunk[] ReadFrom(string fileName, Type type, object[] args)
        {
            ArrayList list;

            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }
            if (fileName == string.Empty)
            {
                throw new ArgumentException("fileName");
            }
            if (!File.Exists(fileName))
            {
                throw new FileNotFoundException(Powerasp.Enterprise.Core.SR.FileNotFound, fileName);
            }
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            FileStream   input  = null;
            BinaryReader reader = null;

            if (args == null)
            {
                args = new object[0];
            }
            Type[]          types       = ReflectionUtil.ConvertTo(args);
            ConstructorInfo constructor = type.GetConstructor(types);

            if (constructor == null)
            {
                throw new ArgumentException("type");
            }
            try
            {
                input  = File.OpenRead(fileName);
                reader = new BinaryReader(input);
                list   = new ArrayList();
                while (input.Position != input.Length)
                {
                    IDataChunk chunk = constructor.Invoke(args) as IDataChunk;
                    if (chunk == null)
                    {
                        throw new InvalidCastException("");
                    }
                    chunk.ReadData(reader);
                    list.Add(chunk);
                }
            }
            finally
            {
                if (reader != null)
                {
                    try
                    {
                        reader.Close();
                    }
                    catch
                    {
                    }
                    reader = null;
                }
                if (input != null)
                {
                    try
                    {
                        input.Close();
                    }
                    catch
                    {
                    }
                    input = null;
                }
            }
            return((IDataChunk[])list.ToArray(typeof(IDataChunk)));
        }
        public void Load()
        {
            IDataChunk dataChunk = _dataLoader.LoadData(this);

            InsertDataChunk(dataChunk);
        }
 public MediaDrmSetupDecryptorCompletedEventArgs(Guid keyId, IDataChunk dataChunk, Exception error, bool cancelled, object userState) : base(error, cancelled, userState)
 {
     KeyId     = keyId;
     DataChunk = dataChunk;
 }
 private void MediaPlugin_StreamDataAdded(IAdaptiveMediaPlugin mediaPlugin, IMediaStream stream,
                                          IDataChunk dataChunk)
 {
     Dispatcher.BeginInvoke(() => OnStreamDataAdded(mediaPlugin, stream, dataChunk));
 }
Exemple #28
0
 protected void WriteChunk(IDataChunk chunk)
 {
     Session.WriteChunk(chunk);
 }
        private void MediaPlugin_DownloadStreamDataFailed(IAdaptiveMediaPlugin mediaPlugin, IMediaTrack track,
                                                          IDataChunk dataChunk, Exception error)
        {
            string message = string.Format(SilverlightMediaFrameworkResources.GenericErrorOccurredLogMessage,
                                           "MediaPlugin_DownloadStreamDataFailed", error.Message);

            SendLogEntry(KnownLogEntryTypes.DownloadStreamDataFailed, LogLevel.Error, message);
        }