Esempio n. 1
0
        public void WritePlugin(string fileName)
        {
            XmlTextWriter xtw = new XmlTextWriter(new FileStream(fileName, FileMode.Create), Encoding.ASCII)
            {
                Formatting = Formatting.Indented
            };

            xtw.WriteStartElement("plugin");
            xtw.WriteAttributeString("class", TagClass);
            xtw.WriteAttributeString("headersize", HeaderSize.ToString());
            foreach (mRevision revision in Revisions)
            {
                xtw.WriteStartElement("revision");
                xtw.WriteAttributeString("author", revision.Author);
                xtw.WriteAttributeString("version", revision.Version.ToString());
                xtw.WriteString(revision.Description);
                xtw.WriteEndElement();
            }
            foreach (mValue value2 in ValueList)
            {
                WriteNode(xtw, value2);
            }
            xtw.WriteEndElement();
            xtw.Close();
        }
Esempio n. 2
0
        public void WritePlugin(string fileName)
        {
            //Initialize our XmlTextWriter
            XmlTextWriter xtw = new XmlTextWriter(new FileStream(fileName, FileMode.Create), System.Text.Encoding.ASCII);

            //Set our formatting to indent
            xtw.Formatting = Formatting.Indented;

            //Write our plugin header start attribute
            xtw.WriteStartElement("plugin");

            //Write our attribute strings
            xtw.WriteAttributeString("class", TagClass);

            //Write our author
            xtw.WriteAttributeString("author", Author);

            //Write our version
            xtw.WriteAttributeString("version", Version.ToString());

            //Write our headersize
            xtw.WriteAttributeString("headersize", HeaderSize.ToString());

            //Loop for each revision
            foreach (mRevision revision in Revisions)
            {
                //Write our start element
                xtw.WriteStartElement("revision");

                //Write our author
                xtw.WriteAttributeString("author", revision.Author);

                //Write our version
                xtw.WriteAttributeString("version", revision.Version.ToString());

                //Write our description
                xtw.WriteString(revision.Description);

                //Write our end element
                xtw.WriteEndElement();
            }

            //Loop for each value in the ValueList
            foreach (mValue val in ValueList)
            {
                //Write our node
                WriteNode(xtw, val);
            }

            //Write our end element
            xtw.WriteEndElement();

            //Close our writer
            xtw.Close();
        }
        protected override string Header(HeaderSize size, string text)
        {
            if (size <= 0)
            {
                throw new ArgumentException("Header type must be 1-6.");
            }

            var h = new string('#', (int)size);

            return($"{h} {text.Trim()}\n\n");
        }
Esempio n. 4
0
 public static void ReadServertData(IAsyncResult ar) //Socket read/recevie
 {
     try
     {
         if (!TcpClient.Connected || !IsConnected)
         {
             IsConnected = false;
             return;
         }
         int recevied = SslClient.EndRead(ar);
         if (recevied > 0)
         {
             Offset     += recevied;
             HeaderSize -= recevied;
             if (HeaderSize == 0)
             {
                 HeaderSize = BitConverter.ToInt32(Buffer, 0);
                 Debug.WriteLine("/// Plugin Buffersize " + HeaderSize.ToString() + " Bytes  ///");
                 if (HeaderSize > 0)
                 {
                     Offset = 0;
                     Buffer = new byte[HeaderSize];
                     while (HeaderSize > 0)
                     {
                         int rc = SslClient.Read(Buffer, (int)Offset, (int)HeaderSize);
                         if (rc <= 0)
                         {
                             IsConnected = false;
                             return;
                         }
                         Offset     += rc;
                         HeaderSize -= rc;
                         if (HeaderSize < 0)
                         {
                             IsConnected = false;
                             return;
                         }
                     }
                     Thread thread = new Thread(new ParameterizedThreadStart(Packet.Read));
                     thread.Start(Buffer);
                     Offset     = 0;
                     HeaderSize = 4;
                     Buffer     = new byte[HeaderSize];
                 }
                 else
                 {
                     HeaderSize = 4;
                     Buffer     = new byte[HeaderSize];
                     Offset     = 0;
                 }
             }
             else if (HeaderSize < 0)
             {
                 IsConnected = false;
                 return;
             }
             SslClient.BeginRead(Buffer, (int)Offset, (int)HeaderSize, ReadServertData, null);
         }
         else
         {
             IsConnected = false;
             return;
         }
     }
     catch
     {
         IsConnected = false;
         return;
     }
 }
        internal static string CreateHeaderTitle(string text, HeaderSize headerSize = HeaderSize.H1)
        {
            var htmlTag = headerSize.ToString();

            return($"<{htmlTag}>{text}</{htmlTag}>");
        }
Esempio n. 6
0
        public void ReadClientData(IAsyncResult ar)
        {
            try
            {
                if (!TcpClient.Connected)
                {
                    Disconnected();
                    return;
                }
                else
                {
                    int recevied = SslClient.EndRead(ar);
                    if (recevied > 0)
                    {
                        HeaderSize -= recevied;
                        Offset     += recevied;
                        switch (ClientBufferRecevied)
                        {
                        case false:
                        {
                            if (HeaderSize == 0)
                            {
                                HeaderSize = BitConverter.ToInt32(ClientBuffer, 0);
                                if (HeaderSize > 0)
                                {
                                    ClientBuffer = new byte[HeaderSize];
                                    Debug.WriteLine("/// Server Buffersize " + HeaderSize.ToString() + " Bytes  ///");
                                    Offset = 0;
                                    ClientBufferRecevied = true;
                                }
                            }
                            else if (HeaderSize < 0)
                            {
                                Disconnected();
                                return;
                            }
                            break;
                        }

                        case true:
                        {
                            lock (Settings.LockReceivedSendValue)
                                Settings.ReceivedValue += recevied;
                            BytesRecevied += recevied;
                            if (HeaderSize == 0)
                            {
                                ThreadPool.QueueUserWorkItem(new Packet
                                    {
                                        client = this,
                                        data   = ClientBuffer,
                                    }.Read, null);
                                Offset               = 0;
                                HeaderSize           = 4;
                                ClientBuffer         = new byte[HeaderSize];
                                ClientBufferRecevied = false;
                            }
                            else if (HeaderSize < 0)
                            {
                                Disconnected();
                                return;
                            }
                            break;
                        }
                        }
                        SslClient.BeginRead(ClientBuffer, (int)Offset, (int)HeaderSize, ReadClientData, null);
                    }
                    else
                    {
                        Disconnected();
                        return;
                    }
                }
            }
            catch
            {
                Disconnected();
                return;
            }
        }