Esempio n. 1
0
        public static HttpContent AsHttpContent(this IWritable w, string mediaType)
        {
            var content = new PushStreamContent((s, c, tc) => Push(w, s));

            content.Headers.ContentType = new MediaTypeHeaderValue(mediaType);
            return(content);
        }
Esempio n. 2
0
 private static void Push(IWritable writable, Stream stream)
 {
     using (var writer = new StreamWriter(stream, Encoding.UTF8))
     {
         writable.WriteTo(writer);
     }
 }
        /// <summary>
        /// Intercepting the XMLWorker's parser and collecting its interpreted pdf elements.
        /// </summary>        
        public void Add(IWritable htmlElement)
        {
            var writableElement = htmlElement as WritableElement;
            if (writableElement == null)
                return;

            foreach (var element in writableElement.Elements())
            {
                if (element is NoNewLineParagraph)
                {
                    var noNewLineParagraph = element as NoNewLineParagraph;
                    foreach (var item in noNewLineParagraph)
                    {
                        _paragraph.Add(item);
                    }
                }
                else if (element is PdfDiv)
                {
                    var div = element as PdfDiv;
                    foreach (var divChildElement in div.Content)
                    {
                        _paragraph.Add(divChildElement);
                    }
                }
                else
                {
                    _paragraph.Add(element);
                }
            }
        }
Esempio n. 4
0
 static void PrintWriter(IWritable work)
 {
     Console.WriteLine();
     Console.WriteLine($"Name of Work: {work.GetNameOfWork()}");
     Console.WriteLine($"Written By: {work.GetWriter()}");
     Console.WriteLine();
 }
Esempio n. 5
0
        public static void UpdateHealth(Session session, UpdateVital vital, UpdateParameters parameters)
        {
            if (!characterInfo.TryGetValue(session.Character, out CharacterUpdateInfo info))
            {
                return;
            }

            var vitalUpdate = new CharacterUpdateInfo.Vital
            {
                Current = vital.Current,
                Maximum = vital.Maximum
            };

            switch (vital)
            {
            case UpdateHealth _:
                info.Health = vitalUpdate;
                break;

            case UpdateStamina _:
                info.Stamina = vitalUpdate;
                break;

            case UpdateMana _:
                info.Mana = vitalUpdate;
                break;
            }

            IWritable update = BuildUpdate(vital, session.Character.Sequence);

            BroadcastUpdate(session, update);
        }
Esempio n. 6
0
        public static void UpdateInitial(Session session, UpdateInitial initial, UpdateParameters parameters)
        {
            if (!characterInfo.TryGetValue(session.Character, out CharacterUpdateInfo info))
            {
                return;
            }

            info.Level    = (uint)initial.Class6.Level;
            info.Location = initial.InitialUpdate.Location;

            info.Health = new CharacterUpdateInfo.Vital
            {
                Current = (uint)initial.InitialUpdate.CurHealth,
                Maximum = (uint)initial.InitialUpdate.MaxHealth
            };

            info.Stamina = new CharacterUpdateInfo.Vital
            {
                Current = (uint)initial.InitialUpdate.CurStam,
                Maximum = (uint)initial.InitialUpdate.MaxStam
            };

            info.Mana = new CharacterUpdateInfo.Vital
            {
                Current = (uint)initial.InitialUpdate.CurMana,
                Maximum = (uint)initial.InitialUpdate.MaxMana
            };

            IWritable update = BuildUpdate(initial, session.Character.Sequence);

            BroadcastUpdate(session, update);
        }
Esempio n. 7
0
 public SimpleBlock(IWritable head, IEnumerable <ILineObject> body)
 {
     base.Head.Add(head);
     base.Head.Add(new StringWritable("{"));
     base.BodyList.AddRange(body);
     base.Tail.Add(new StringWritable("}"));
 }
 public void Add(IWritable w)
 {
     if (w is WritableElement)
     {
         elements.AddRange(((WritableElement)w).Elements());
     }
 }
Esempio n. 9
0
        public Task SaveAsync(IWritable reference, CancellationToken token)
        {
            var mockRef = (MockMailboxItemReference)reference;

            mockRef.IsSaved = true;
            return(Task.CompletedTask);
        }
Esempio n. 10
0
 public Engine()
 {
     this.heroes      = new List <BaseHero>();
     this.heroFactory = new HeroFactory();
     this.reader      = new Reader();
     this.writer      = new Writer();
 }
Esempio n. 11
0
 /**
  * @param po
  * @throws PipelineException
  */
 private void Write(IWorkerContext context, ProcessObject po) {
     MapContext mp = (MapContext)GetLocalContext(context);
     if (po.ContainsWritable()) {
         Document doc = (Document) mp[DOCUMENT];
         bool continuousWrite = (bool) mp[CONTINUOUS];
         IWritable writable = null;
         while (null != (writable = po.Poll())) {
             if (writable is WritableElement) {
                 foreach (IElement e in ((WritableElement) writable).Elements()) {
                     try {
                         if (!doc.Add(e) && LOG.IsLogging(Level.TRACE)) {
                             LOG.Trace(String.Format(
                                     LocaleMessages.GetInstance().GetMessage(LocaleMessages.ELEMENT_NOT_ADDED),
                                     e.ToString()));
                         }
                     } catch (DocumentException e1) {
                         if (!continuousWrite) {
                             throw new PipelineException(e1);
                         } else {
                             LOG.Error(
                                     LocaleMessages.GetInstance().GetMessage(LocaleMessages.ELEMENT_NOT_ADDED_EXC),
                                     e1);
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 12
0
        /// <summary>Used by child copy constructors.</summary>
        protected internal virtual void Copy(IWritable other)
        {
            lock (this)
            {
                if (other != null)
                {
                    try
                    {
                        var memoryStream = new MemoryStream();
                        var binaryWriter = new BinaryWriter(memoryStream);
                        DataOutputBuffer outputBuffer = new DataOutputBuffer();
                        other.Write(binaryWriter);

                        DataInputBuffer inputBuffer = new DataInputBuffer();
                        inputBuffer.Reset(outputBuffer.GetData(), outputBuffer.GetLength());
                        ReadFields(inputBuffer);
                    }
                    catch (IOException e)
                    {
                        throw new ArgumentException("map cannot be copied: " + e.Message);
                    }
                }
                else
                {
                    throw new ArgumentException("source map cannot be null");
                }
            }
        }
Esempio n. 13
0
        public void Add(IWritable htmlElement)
        {
            WritableElement writableElement = htmlElement as WritableElement;

            if (writableElement == null)
            {
                return;
            }

            foreach (IElement element in writableElement.Elements())
            {
                if (element is PdfDiv)
                {
                    PdfDiv div = element as PdfDiv;
                    foreach (IElement divChildElement in div.Content)
                    {
                        _paragraph.Add(divChildElement);
                    }
                }
                else
                {
                    _paragraph.Add(element);
                }
            }
        }
Esempio n. 14
0
        public async Task Write(string path, WriteFileMode mode, IWritable writable, bool appendGuid, bool createDirectory, CancellationToken cancel)
        {
            if (appendGuid)
            {
                var p = new PosixPath(path);
                if (p.IsEmpty)
                {
                    path = Guid.NewGuid().ToString("N");
                }
                else
                {
                    path = p.FileNameWithoutExtension + Guid.NewGuid().ToString("N") + p.Extension;
                }
            }

            path = this.Graph.ResolvePath(path);

            if (createDirectory)
            {
                var directoryPath = Path.GetDirectoryName(path);
                Directory.CreateDirectory(directoryPath);
            }

            using (var file = Open(path, mode))
            {
                using (writable)
                {
                    await writable.WriteTo(file, cancel).ConfigureAwait(false);
                }
            }
        }
 public Engine()
 {
     this.animals     = new List <IAnimal>();
     this.foodFactory = new FoodFactory();
     this.reader      = new Reader();
     this.writer      = new Writer();
 }
Esempio n. 16
0
 public Engine()
 {
     this.reader        = new ConsoleReader();
     this.writer        = new ConsoleWriter();
     this.playerFactory = new PlayerFactory();
     this.teams         = new List <Team>();
 }
Esempio n. 17
0
        /// <summary>
        /// Intercepting the XMLWorker's parser and collecting its interpreted pdf elements.
        /// </summary>
        public void Add(IWritable htmlElement)
        {
            var writableElement = htmlElement as WritableElement;

            if (writableElement == null)
            {
                return;
            }

            foreach (var element in writableElement.Elements())
            {
                if (element is NoNewLineParagraph)
                {
                    var noNewLineParagraph = element as NoNewLineParagraph;
                    foreach (var item in noNewLineParagraph)
                    {
                        _paragraph.Add(item);
                    }
                }
                else if (element is PdfDiv)
                {
                    var div = element as PdfDiv;
                    foreach (var divChildElement in div.Content)
                    {
                        _paragraph.Add(divChildElement);
                    }
                }
                else
                {
                    _paragraph.Add(element);
                }
            }
        }
Esempio n. 18
0
 /// <summary>Read and return the next value in the file.</summary>
 /// <exception cref="System.IO.IOException"/>
 public virtual IWritable Next(IWritable value)
 {
     lock (this)
     {
         return(Next(key, value) ? value : null);
     }
 }
Esempio n. 19
0
 public void Add(IWritable w)
 {
     if (w is WritableElement)
     {
         elements.AddRange(((WritableElement)w).Elements());
     }
 }
Esempio n. 20
0
 public ApiConnection(HttpState httpState, IPreferences preferences, IWritable logger, bool logVerboseMessages, IOpenApiSearchPathsProvider?openApiSearchPaths = null)
 {
     _httpState          = httpState ?? throw new ArgumentNullException(nameof(httpState));
     _logger             = logger ?? throw new ArgumentNullException(nameof(logger));
     _logVerboseMessages = logVerboseMessages;
     _searchPaths        = openApiSearchPaths ?? new OpenApiSearchPathsProvider(preferences);
 }
Esempio n. 21
0
 public void Value(IWritable value)
 {
     if (currents.TryPeek(out currCurr))
     {
         currCurr.Values.Add(value);
     }
 }
Esempio n. 22
0
 private static void Push(IWritable writable, Stream stream)
 {
     using(var writer = new StreamWriter(stream,Encoding.UTF8))
     {
         writable.WriteTo(writer);
     }
 }
Esempio n. 23
0
 public Engine(IReadable reader, IWritable writer)
 {
     this.reader = reader;
     this.writer = writer;
     heroes      = new List <BaseHero>();
     factory     = new Factory();
 }
Esempio n. 24
0
 /// <exception cref="System.IO.IOException"/>
 public virtual void ReadFields(BinaryReader reader)
 {
     // construct matrix
     values = new IWritable[@in.ReadInt()][];
     for (int i = 0; i < values.Length; i++)
     {
         values[i] = new IWritable[@in.ReadInt()];
     }
     // construct values
     for (int i_1 = 0; i_1 < values.Length; i_1++)
     {
         for (int j = 0; j < values[i_1].Length; j++)
         {
             IWritable value;
             // construct value
             try
             {
                 value = (IWritable)System.Activator.CreateInstance(valueClass);
             }
             catch (InstantiationException e)
             {
                 throw new RuntimeException(e.ToString());
             }
             catch (MemberAccessException e)
             {
                 throw new RuntimeException(e.ToString());
             }
             value.ReadFields(@in);
             // read a value
             values[i_1][j] = value;
         }
     }
 }
Esempio n. 25
0
        /// <summary>Used internally by the netcode to send unconnected messages.</summary>
        private async Task <int> SendAsync(PacketType type, IPEndPoint remote, IWritable message)
        {
            // Buffers allocated by the allocator
            byte[] compress = null;
            Writer writer   = null;

            try {
                // Write message
                writer = new Writer(Allocator, 5);
                message?.Write(writer);
                ArraySegment <byte> packet = new ArraySegment <byte>(writer.Buffer, 5, writer.Position - 5);

                // Create flags
                PacketFlags flags = PacketFlags.None;

                // Compress
                if (Config.Compression)
                {
                    int max = Compressor.MaxCompressedLength(packet.Count) + packet.Offset;
                    compress = Allocator.CreateMessage(max);
                    int len = Compressor.Compress(packet, compress, packet.Offset);
                    if (len <= 0)
                    {
                        throw new InvalidOperationException(string.Format(
                                                                "Compressing {0} bytes returned {1} bytes", packet.Count, len
                                                                ));
                    }
                    else if (len < packet.Count)
                    {
                        packet = new ArraySegment <byte>(compress, packet.Offset, len);
                        flags |= PacketFlags.Compressed;
                    }
                }

                // Write CRC32
                if (Config.CRC32)
                {
                    uint crc32 = CRC32.Compute(packet.Array, packet.Offset, packet.Count);
                    Serializer.Write32(packet.Array, packet.Offset - 4, crc32);
                    packet = new ArraySegment <byte>(packet.Array, packet.Offset - 4, packet.Count + 4);
                    flags |= PacketFlags.Verified;
                }

                // Write header
                packet.Array[packet.Offset - 1] = (byte)(((byte)type) | ((byte)flags));
                packet = new ArraySegment <byte>(packet.Array, packet.Offset - 1, packet.Count + 1);

                // Send
                return(await SendSocketAsync(remote, packet.Array, packet.Offset, packet.Count));
            } catch (Exception exception) {
                // Notify listener about the exception
                Listener.OnHostException(remote, exception);
                throw;
            } finally {
                // Return the allocated buffers back to the allocator
                writer?.Dispose();
                Allocator.ReturnMessage(ref compress);
            }
        }
Esempio n. 26
0
 /// <summary>Return the <code>n</code>th value in the file.</summary>
 /// <exception cref="System.IO.IOException"/>
 public virtual IWritable Get(long n, IWritable value)
 {
     lock (this)
     {
         key.Set(n);
         return(Get(key, value));
     }
 }
Esempio n. 27
0
 /// <summary>
 /// Enqueue broadcast of <see cref="IWritable"/> to all <see cref="Player"/>'s on the map.
 /// </summary>
 public void EnqueueToAll(IWritable message)
 {
     foreach (GridEntity entity in entities.Values)
     {
         Player player = entity as Player;
         player?.Session.EnqueueMessageEncrypted(message);
     }
 }
Esempio n. 28
0
        public override void Write(IWritable buffer)
        {
            // Write the player metadata
            buffer.Writer.WriteVarChar(_Client.Player.UUID.ToString("D"));
            buffer.Writer.WriteVarChar(_Client.Player.Username);

            _Client.ClientState = ClientState.Play;
        }
Esempio n. 29
0
 public static void CloneWritableInto(IWritable dst, IWritable src)
 {
     ReflectionUtils.CopyInCopyOutBuffer buffer = cloneBuffers.Get();
     buffer.outBuffer.Reset();
     src.Write(buffer.outBuffer);
     buffer.MoveData();
     dst.ReadFields(buffer.inBuffer);
 }
Esempio n. 30
0
 public static IWritable Indent(this IWritable writable, string prefix) => GetWritable(o =>
 {
     var lines = writable.ToString().SplitLines().Select(_ => prefix + _);
     foreach (var line in lines)
     {
         o.WriteLine(line);
     }
 });
Esempio n. 31
0
        /*public static void Broadcast(ENet.Packet packet)
         * {
         *  Server.Host.Broadcast(Server.ChannelID, ref packet);
         * }
         *
         * public static void Broadcast(ENet.Packet packet, Peer excludedPeer)
         * {
         *  Server.Host.Broadcast(Server.ChannelID, ref packet, excludedPeer);
         * }*/

        public static void Broadcast(ServerPacketType serverPacketType, IWritable message, Peer[] peers, PacketFlags packetFlags = PacketFlags.Reliable)
        {
            var serverPacket = new ServerPacket(serverPacketType, message);
            var packet       = default(ENet.Packet);

            packet.Create(serverPacket.Data, packetFlags);
            Server.Host.Broadcast(Server.ChannelID, ref packet, peers);
        }
Esempio n. 32
0
 virtual public void Add(IWritable w)
 {
     if (w is WritableElement)
     {
         IList <IElement> elements = ((WritableElement)w).Elements();
         // do something with the lists of elements
     }
 }
Esempio n. 33
0
 /// <summary>
 /// Broadcast <see cref="IWritable"/> to all members.
 /// </summary>
 public void BroadcastMessage(IWritable message)
 {
     foreach (CharacterObject character in members.Values)
     {
         Session session = NetworkManager.FindSessionByCharacter(character);
         session?.EnqueueMessage(message);
     }
 }
        /// <summary>
        /// Intercepting the XMLWorker's parser and collecting its interpreted pdf elements.
        /// </summary>        
        public void Add(IWritable htmlElement)
        {
            var writableElement = htmlElement as WritableElement;
            if (writableElement == null)
                return;

            foreach (var element in writableElement.Elements())
            {
                _paragraph.Add(element);
            }
        }
        /// <summary>
        /// Intercepting the XMLWorker's parser and collecting its interpreted pdf elements.
        /// </summary>        
        public void Add(IWritable htmlElement)
        {
            var writableElement = htmlElement as WritableElement;
            if (writableElement == null)
                return;

            foreach (var element in writableElement.Elements())
            {
                fixNestedTablesRunDirection(element);
                _paragraph.Add(element);
            }
        }
 virtual public void Add(IWritable w) {
     elementList.AddRange(((WritableElement) w).Elements());
 }
Esempio n. 37
0
 /**
  * Add a writable.
  * @param writable the writable to add
  */
 public void Add(IWritable writable) {
     queue.Enqueue(writable);
 }
Esempio n. 38
0
 public HtmlElem WithContent(IWritable w)
 {
     _content.Add(w);
     return this;
 }
 virtual public void Add(IWritable w) {
     if (w is WritableElement) {
         IList<IElement> elements = ((WritableElement) w).Elements();
         // do something with the lists of elements
     }
 }
        private static IWritable GenerateSemesterCheckBoxes(CurricularUnit fuc)
        {
            var quant = CurricularUnit.Maxsemesters;

            var ret = new IWritable[quant];

            var semester = fuc == null ? 0 : fuc.Semester;

            for (int i = 0; i != quant; i++)
                ret[i] = Li(InputCheckBox("" + i, "" + i, (semester & (0x01 << i)) == (0x01 << i)), Text(string.Format(" {0}º Semestre", i+1)) );

            return Div("input", Ul("inputs-list", ret));
        }
        private static IWritable GenerateMandatoryRadioButtons(CurricularUnit fuc)
        {
            var ret = new IWritable[2];

            ret[0] = Li(InputRadioButton("tipoObrig", "obrigatoria", (fuc == null ? true : fuc.Mandatory)), Text("Obrigatória"));
            ret[1] = Li(InputRadioButton("tipoObrig", "opcional", (fuc == null ? false : !fuc.Mandatory)), Text("Opcional"));

            return Div("input", Ul("inputs-list", ret));
        }
        private static IWritable GeneratePrecedencesCheckBoxes(CurricularUnit uc)
        {
            var ucs = RepositoryLocator.Get<string, CurricularUnit>().GetAll();

            if (uc != null)
                ucs = ucs.Where(c => !c.Key.Equals(uc.Key)); //Para não considerar a própria UC

            var ret = new IWritable[ucs.Count()];

            int i = 0;
            foreach(var cUnit in ucs)
                ret[i++] = Li(InputCheckBox(cUnit.Key, cUnit.Key, (uc != null && uc.Precedence.Contains(cUnit))), Text(string.Format(" {0}", cUnit.Key)));

            return Div("input", Ul("inputs-list", ret));
        }
Esempio n. 43
0
        private void btnStop_Click(object sender, EventArgs e)
        {
            if (_soundOut != null)
                _soundOut.Dispose();

            _waveIn.Dispose();
            if(_writer is IDisposable)
                ((IDisposable)_writer).Dispose();

            _waveIn = null;
            _writer = null;
            _soundOut = null;

            btnStart.Enabled = deviceslist.SelectedItems.Count > 0;
            btnStop.Enabled = false;
        }
Esempio n. 44
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            if (deviceslist.SelectedItems.Count <= 0)
                return;

            SaveFileDialog sfd = new SaveFileDialog();
            sfd.Filter = "WAV (*.wav)|*.wav";
            sfd.Title = "Speichern";
            sfd.FileName = String.Empty;
            if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                _waveIn = new WaveInEvent(new WaveFormat(44100, 16, _selectedDevice.Channels));
                _waveIn.Device = deviceslist.SelectedItems[0].Index;

                _waveIn.Initialize();
                _waveIn.Start();

                var waveInToSource = new SoundInSource(_waveIn);

                _source = waveInToSource;
                var notifyStream = new SingleBlockNotificationStream(_source);
                notifyStream.SingleBlockRead += OnNotifyStream_SingleBlockRead;

                _source = notifyStream.ToWaveSource(16);
                _writerBuffer = new byte[_source.WaveFormat.BytesPerSecond];

                _writer = new WaveWriter(File.OpenWrite(sfd.FileName), _source.WaveFormat);
                waveInToSource.DataAvailable += OnNewData;

                btnStart.Enabled = false;
                btnStop.Enabled = true;
            }
        }
Esempio n. 45
0
 public static byte[] ToArray(IWritable obj)
 {
     MemoryStream stm = new MemoryStream();
     obj.Write(new BinaryWriter(stm));
     //!!!new BinaryFormatter().Serialize(stm,obj);
     return stm.ToArray();
 }
 public void Add(IWritable w) {
     lst.Add(w);
 }