Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
M

mjeeves

@mjeeves
About
Posts
6
Topics
2
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • reading memory stream in byte chunks
    M mjeeves

    sure enough _memoryStream.Read(readChunkSize, 0, 4); fixed part of the problem and also changing the Write message as below fixed the issue. but I want to use BinaryReader since I'm using BinaryWriter the behavior I'm seeing is I can consecutively call ReadByte and it will read each byte in turn without me having to define position within the stream, which I don't understand. so how do is use BinaryReader to read specific blocks of bytes, 2->6, and 7->19 thanks Madaxe

    public void WriteMessage(string message)
    {
    WriteNextChunckSize(message.Length);
    byte[] byteArray = Encoding.UTF8.GetBytes(message);
    BinaryWriter.Write(byteArray);
    }

    C# performance help

  • reading memory stream in byte chunks
    M mjeeves

    I want to create a memory stream as follows [1byte][4bytes][n bytes][4 bytes][n bytes][4 bytes][n bytes] ....ect my first stream consisted of [0][12][Hello World.] _packetWriter.WriteOpCode((byte)opCode); _packetWriter.WriteMessage("Hello World."); _client.Client.Send(_packetWriter.GetPacketBytes()); when I read it back I get the following, and when I look at the byte arrays I'm seeing some bytes from the previous chunk 10/09/2022 11:39:00 : Opcode Found With Value 0 10/09/2022 11:39:00 : Chunk Found With Value 12 10/09/2022 11:39:00 : Message Found With Value Hello Worl can anybody help thanks madaxe

    public class PacketWriter : BinaryWriter
    {
    public MemoryStream MemoryStream;
    public BinaryWriter BinaryWriter;

        public PacketWriter()
        {
            MemoryStream = new MemoryStream();
            BinaryWriter = new BinaryWriter(MemoryStream);
        }
        public void WriteOpCode(byte opCode)
        {
            MemoryStream.WriteByte(opCode);
        }
    
        public void WriteNextChunckSize(int chunkSize)
        {
            BinaryWriter.Write((Int32)chunkSize);
        }
    
        public void WriteMessage(string message)
        {
            WriteNextChunckSize(message.Length);
            BinaryWriter.Write(message);
        }
        public byte\[\] GetPacketBytes()
        {
            return MemoryStream.ToArray();
        }
    }
    

    public class PacketReader : BinaryReader
    {
    private NetworkStream _memoryStream;
    public PacketReader(NetworkStream memoryStream) : base(memoryStream)
    {
    _memoryStream = memoryStream;
    }

        public int ReadOpCode()
        {
            return \_memoryStream.ReadByte();
        }
    
        public string ReadMessage(int chunkSize)
        {
            byte\[\] readMessage;
            readMessage = new byte\[chunkSize\];
            \_memoryStream.Read(readMessage, 0, chunkSize);
            var message = Encoding.ASCII.GetString(readMessage);
            return message;
        }
        public int ReadChunkSize()
        {
            byte\[\] readChunkSize;
            readChunkSize = new byte\[4\];
            \_memoryStream.Read(readChunkSize, 0, 3);
            return BitConverter.ToInt32(readChunkSize, 0);
        }
    }
    
    C# performance help

  • Using Dependency Property's to Affect Non WPF Property's
    M mjeeves

    So I have three last issues, thanks for all the help 1) if I use the usercontrol name "Name="WaitTickerCustomControl" then the Custom Control disappears in the Main Window odd. 2) The directly Bound dependency property are bound but nothing updates 3) The Indirectly Bound property's only affect the third ticker odd... Thanks for the help im learning alot. Madaxe XAML Custom Control

    WPF wpf csharp performance announcement

  • Create a Multi-Layer Data Model from a MySQL Query
    M mjeeves

    here is another example data set, i want to go one more level down and group by username and EventTime, but i don't know how to expand the linq, plus i will have to remove the time stamp from the event dattime

    namespace ConsoleApp3
    {
    class Program
    {
    static void Main(string[] args)
    {
    List SignInReports = new List();
    SignInReports.Add(new SignInReport { UserName = "Bob", EventName = "SignIn", EventTime = new DateTime(2020,1,18,6,0,0) });
    SignInReports.Add(new SignInReport { UserName = "Bob", EventName = "SignOut", EventTime = new DateTime(2020, 1, 18, 10, 0, 0) });
    SignInReports.Add(new SignInReport { UserName = "Bob", EventName = "SignIn", EventTime = new DateTime(2020, 1, 18, 11, 30, 0) });
    SignInReports.Add(new SignInReport { UserName = "Bob", EventName = "SignOut", EventTime = new DateTime(2020, 1, 18, 16, 30, 0) });
    SignInReports.Add(new SignInReport { UserName = "Charlie", EventName = "SignIn", EventTime = new DateTime(2020, 1, 18, 6, 0, 0) });
    SignInReports.Add(new SignInReport { UserName = "Charlie", EventName = "SignOut", EventTime = new DateTime(2020, 1, 18, 15, 30, 0) });
    SignInReports.Add(new SignInReport { UserName = "Charlie", EventName = "SignIn", EventTime = new DateTime(2020, 1, 19, 6, 30, 0) });
    SignInReports.Add(new SignInReport { UserName = "Charlie", EventName = "SignOut", EventTime = new DateTime(2020, 1, 19, 17, 45, 0) });

            IEnumerable SignInData = SignInReports.GroupBy(u => u.UserName)
                                                  .Select(group => new SignInReportGrouping {   UserName = group.Key, 
                                                                                                SignInReports = group.ToList() })
                                                  .ToList();
        }
    }
    
    public class SignInReport
    {
        public string UserName { get; set; }
        public string EventName { get; set; }
        public DateTime EventTime { get; set; }
    }
    
    public class SignInReportGrouping
    {
        public string UserName { get; set; }
        public IEnumerable SignInReportDay { get; set; }
    }
    
    public class SignInReportDay
    {
        public IEnumerable SignInReports { get; set; }
    }
    

    }

    C# json csharp database mysql linq

  • Create a Multi-Layer Data Model from a MySQL Query
    M mjeeves

    I found this one example is this the best method / approach?

    namespace ConsoleApp3
    {
    class Program
    {
    static void Main(string[] args)
    {
    List CustomerList = new List();
    CustomerList.Add(new Customer { ID = 1, Name = "One", GroupID = 1 });
    CustomerList.Add(new Customer { ID = 2, Name = "Two", GroupID = 1 });
    CustomerList.Add(new Customer { ID = 3, Name = "Three", GroupID = 2 });
    CustomerList.Add(new Customer { ID = 4, Name = "Four", GroupID = 1 });
    CustomerList.Add(new Customer { ID = 5, Name = "Five", GroupID = 3 });
    CustomerList.Add(new Customer { ID = 6, Name = "Six", GroupID = 3 });

            IEnumerable CustomerGroupings = CustomerList.GroupBy(u => u.GroupID)
                                                  .Select(group => new CustomerGrouping { GroupID = group.Key, Customers = group.ToList() })
                                                  .ToList();
        }
    }
    
    public class Customer
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public int GroupID { get; set; }
    }
    
    public class CustomerGrouping
    {
        public int GroupID { get; set; }
        public IEnumerable Customers { get; set; }
    }
    
    C# json csharp database mysql linq

  • Create a Multi-Layer Data Model from a MySQL Query
    M mjeeves

    I have the following table, i can join this table to others to build a bigger dataset but I only wnat to run one query to get the data and then build a data model shown below. I can build a Single model but i want to do more like a JSON serialization. Can anybody show me a LINQ or other method that would be efficient and could be expanded to use generics? Thanks Madaxe School Class Student Bakers 19A Bob Bakers 19A Jim Bakers 17A Gary Bakers 17A Stuart DataClass IEnumerable Schools SchoolClass IEnumerable Classes StudentClass

    C# json csharp database mysql linq
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups