예제 #1
0
        private void SendAlert()
        {
            byte[] buff = new byte[m_request_hdr.data_length];
            string tmp;

            string[] data;
            string   product;
            string   version;
            string   alert;
            string   file;
            uint     len;

            ReadData(buff, (int)m_request_hdr.data_length);
            tmp  = Byte2Str(buff, 0, (int)m_request_hdr.data_length);
            data = tmp.Split(SEP);
            if (data.Length != 2)
            {
                SendHeader(0, STATUS_ERR | ERR_INVALID_COUNT, tmp);
                return;
            }
            product = data[0];
            version = data[1];

            if (string.IsNullOrEmpty(product))
            {
                SendHeader(0, STATUS_ERR | ERR_INVALID_NAME, "product is empty");
                return;
            }
            if (string.IsNullOrEmpty(version))
            {
                SendHeader(0, STATUS_ERR | ERR_INVALID_NAME, "version is empty");
                return;
            }

            try
            {
                CRelease.GetAlert(product, version, out file, out len);
            }
            catch (Exception ex)
            {
                SendHeader(0, STATUS_ERR | ERR_EXCEPTION, ex.Message);
                return;
            }

            if (len <= 0)
            {
                SendHeader(0, STATUS_OK, null);
            }
            else
            {
                SendHeader(len, STATUS_ERR | ERR_ALERT, null);
                m_sock.SendFile(file);
            }

            Broadcast(who() + " asks for Alert");
        }
예제 #2
0
        private void SendFileList()
        {
            byte[] buff = new byte[m_request_hdr.data_length];
            string tmp;

            string[] data;
            string   product;
            string   version;
            string   all;

            ReadData(buff, (int)m_request_hdr.data_length);
            tmp  = Byte2Str(buff, 0, (int)m_request_hdr.data_length);
            data = tmp.Split(SEP);
            if (data.Length != 2)
            {
                SendHeader(0, STATUS_ERR | ERR_INVALID_COUNT, tmp);
                return;
            }
            product = data[0];
            version = data[1];

            if (string.IsNullOrEmpty(product))
            {
                SendHeader(0, STATUS_ERR | ERR_INVALID_NAME, "product is empty");
                return;
            }
            if (string.IsNullOrEmpty(version))
            {
                SendHeader(0, STATUS_ERR | ERR_INVALID_NAME, "version is empty");
                return;
            }

            try
            {
                data = CRelease.GetFileList(product, version);
            }
            catch (Exception ex)
            {
                SendHeader(0, STATUS_ERR | ERR_EXCEPTION, ex.Message);
                return;
            }

            if (data.Length == 0)
            {
                SendHeader(0, STATUS_ERR | ERR_EMPTY, product + " | " + version);
                return;
            }

            all = string.Join(SEP.ToString(), data);

            SendHeader((uint)all.Length, STATUS_OK, null);
            m_sock.Send(Encoding.ASCII.GetBytes(all));

            Broadcast(who() + " asks for file list");
        }
예제 #3
0
        private void SendFile()
        {
            byte[] buff = new byte[m_request_hdr.data_length];
            string tmp;

            string[] data;
            string   product;
            string   version;
            string   file;
            string   filename;
            uint     len;

            ReadData(buff, (int)m_request_hdr.data_length);
            tmp  = Byte2Str(buff, 0, (int)m_request_hdr.data_length);
            data = tmp.Split(SEP);
            if (data.Length != 3)
            {
                SendHeader(0, STATUS_ERR | ERR_INVALID_COUNT, tmp);
                return;
            }
            product = data[0];
            version = data[1];
            file    = data[2];

            if (string.IsNullOrEmpty(product))
            {
                SendHeader(0, STATUS_ERR | ERR_INVALID_NAME, "product is empty");
                return;
            }
            if (string.IsNullOrEmpty(version))
            {
                SendHeader(0, STATUS_ERR | ERR_INVALID_NAME, "version is empty");
                return;
            }
            if (string.IsNullOrEmpty(file))
            {
                SendHeader(0, STATUS_ERR | ERR_INVALID_NAME, "file is empty");
                return;
            }

            try
            {
                CRelease.GetFileInfo(product, version, file, out filename, out len);
            }
            catch (Exception ex)
            {
                SendHeader(0, STATUS_ERR | ERR_EXCEPTION, ex.Message);
                return;
            }

            SendHeader((uint)len, STATUS_OK, null);
            m_sock.SendFile(filename);

            Broadcast(who() + " downloads file " + file);
        }
예제 #4
0
        private void SendVersions()
        {
            byte [] buff = new byte[m_request_hdr.data_length];
            string  product;

            string [] versions;
            string    all;

            ReadData(buff, (int)m_request_hdr.data_length);
            product = Byte2Str(buff, 0, (int)m_request_hdr.data_length);

            if (string.IsNullOrEmpty(product))
            {
                SendHeader(0, STATUS_ERR | ERR_INVALID_NAME, "product is empty");
                return;
            }

            try
            {
                versions = CRelease.GetVersions(product);
            }
            catch (Exception ex)
            {
                SendHeader(0, STATUS_ERR | ERR_EXCEPTION, ex.Message);
                return;
            }

            if (versions.Length == 0)
            {
                SendHeader(0, STATUS_ERR | ERR_EMPTY, product);
                return;
            }

            all = string.Join(SEP.ToString(), versions);

            SendHeader((uint)all.Length, STATUS_OK, null);
            m_sock.Send(Encoding.ASCII.GetBytes(all));

            Broadcast(who() + " asks for versions");
        }