Exemple #1
0
 protected override bool EqualsRDATA(RR rr)
 {
     return(PRIORITY.Equals(((SRV)rr).PRIORITY) &&
            WEIGHT.Equals(((SRV)rr).WEIGHT) &&
            PORT.Equals(((SRV)rr).PORT) &&
            TARGET.Equals(((SRV)rr).TARGET));
 }
Exemple #2
0
        private async Task test(String location, PORT p)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(clientBase);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                // HTTP GET
                HttpResponseMessage response = await client.GetAsync(clientBase + "/api/geo/geocoding/query/" + location);

                if (response.IsSuccessStatusCode)
                {
                    var jsonAsString = await response.Content.ReadAsStringAsync();

                    var g = JsonConvert.DeserializeObject <wrapper>(jsonAsString);
                    Console.WriteLine("{0}\t${1}\t{2}", g.data.day, g.data.displayName, g.data.lat);
                    listBox2.Items.Add(g.data.displayName);
                    listBox1.Items.Add(location);
                    Dwstg d = new Dwstg();
                    var   w = d.PORTs.FirstOrDefault(o => o.PORT_NAME == location);
                    w.TZONE_OFFSET     = g.data.rawOffset / 60 / 60 / 1000;
                    w.LATITUDE         = g.data.lat;
                    w.LONGITUDE        = g.data.lng;
                    w.LAST_MODIFIED_DT = DateTime.Now;
                    await d.SaveChangesAsync();
                }
            }
        }
Exemple #3
0
        private void Create_Server_Click(object sender, EventArgs e)
        {
            host            = new PlayHold_em_host(this);
            mainSock        = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
            host.Pname      = textBox1.Text;
            host.money      = int.Parse(textBox2.Text);
            host.ante       = int.Parse(textBox3.Text);
            host.startmoney = int.Parse(textBox2.Text);
            host.Pnames.Add(textBox1.Text);
            int port;

            if (!int.TryParse(PORT.Text, out port))
            {
                MessageBox.Show("포트 번호가 잘못 입력되었거나 입력되지 않았습니다.");
                PORT.Focus();
                PORT.SelectAll();
                return;
            }

            //클라이언트 연결 요청을 위해 소켓 오픈
            IPEndPoint serverEP = new IPEndPoint(thisAddress, port);

            mainSock.Bind(serverEP);
            mainSock.Listen(10);

            mainSock.BeginAccept(host.AcceptCallback, null);

            host.Show();
            this.Hide();
        }
        static void Main(string[] args)
        {
            SimpleHTTPServer HTTPServ = new SimpleHTTPServer(".", 3801);

            /* File name for received picture */
            const String FILE_NAME = "Received.jpg";

            /* Port for incoming connections */
            const int PORT = 3800;

            /* The IPEndPoint for the server. IP cannot be localhost */
            System.Net.IPEndPoint remoteIpEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Any, PORT);
            Console.WriteLine("Listening for connections on port " + PORT.ToString());

            /* After this amount of time has passed, any connection will be terminated
             * Keep high for high latency networks and vice versa */
            const int TIMEOUT = 1000;

            /* Start listening for connections */
            System.Net.Sockets.TcpListener tcpListener = new System.Net.Sockets.TcpListener(remoteIpEndPoint);
            tcpListener.Start();

            /* Create the listening thread */
            Console.WriteLine("Creating the Child Thread");
            System.Threading.Thread connectThread = new System.Threading.Thread(() => StartConnect(tcpListener, TIMEOUT, FILE_NAME));
            connectThread.Start();

            /* Terminate on keypress */
            Console.ReadKey();
            connectThread.Abort();

            /* Clean up and open the received file */
            tcpListener.Stop();
            System.Diagnostics.Process.Start(FILE_NAME);
        }
Exemple #5
0
        static void Main(string[] args)
        {
            var serverIp = args[0];

            var port = Int32.Parse(args[1]);

#if !(ClientAO)
            // Server Activated Objects
            var remoteObject = (RemotableObjects.RemoteClass)Activator.GetObject(
                typeof(RemotableObjects.RemoteClass),
                string.Format("tcp://{0}:{1}/{2}", serverIp, PORT.ToString(), APP_NAME));
#else
            // Client Activated Objects
            RemotingConfiguration.RegisterActivatedClientType(
                typeof(RemotableObjects.RemoteClass),
                string.Format("tcp://{0}:{1}/{2}", serverIp, port.ToString(), APP_NAME));
            var remoteObject = new RemotableObjects.RemoteClass();
#endif

            var info = GetInitData();
            if (remoteObject.Init(info) == null)
            {
                return;
            }


            while (true)
            {
                string command = remoteObject.GetCommand();
                if (command == null)
                {
                    break;
                }

                if (command.Length > 0)
                {
                    int iSpace = command.IndexOf(' ');

                    string fileName  = string.Empty;
                    string arguments = string.Empty;

                    if (iSpace == -1)
                    {
                        fileName = command;
                    }
                    else
                    {
                        fileName  = command.Substring(0, iSpace);
                        arguments = command.Substring(iSpace + 1);
                    }

                    Process.Start(fileName, arguments);
                }

                Thread.Sleep(1000);
            }

            remoteObject.Terminate();
        }
Exemple #6
0
 public override string ToString(int namePadding)
 {
     // _sip._tcp.example.com. 86400 IN SRV 0 5 5060 sipserver.example.com.
     return(String.Join(" ", new string[] {
         Base.ToString(namePadding),
         PRIORITY.ToString(),
         WEIGHT.ToString(),
         PORT.ToString(),
         TARGET.ToString()
     }));
 }
Exemple #7
0
        private void Enter_Server_Click(object sender, EventArgs e)
        {
            mainSock     = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
            client       = new PlayHold_em_client(this);
            client.Pname = textBox1.Text;
            client.money = int.Parse(textBox2.Text);
            if (mainSock.Connected)
            {
                MessageBox.Show("이미 연결되어 있습니다!");
                return;
            }

            int port;

            if (!int.TryParse(PORT.Text, out port))
            {
                MessageBox.Show("포트 번호가 잘못 입력되었거나 입력되지 않았습니다.");
                PORT.Focus();
                PORT.SelectAll();
                return;
            }

            try { mainSock.Connect(IP.Text, port); }
            catch (Exception ex)
            {
                MessageBox.Show("연결에 실패했습니다!\n오류 내용: {0}", ex.Message);
                return;
            }

            AsyncObject obj = new AsyncObject(4096);

            obj.WorkingSocket = mainSock;
            mainSock.BeginReceive(obj.Buffer, 0, obj.BufferSize, 0, client.DataReceived, obj);

            //MessageBox.Show("서버에 입장 중입니다.");
            client.Show(); //클라이언트창오픈
            this.Hide();
        }
Exemple #8
0
        private void Form1_Load(object sender, EventArgs e)
        {
            Text = $"{Settings.Version} // NYAN CAT";

            PortsFrm portsFrm = new PortsFrm();

            portsFrm.ShowDialog();

            Methods.FadeIn(this, 5);
            Settings.Port     = portsFrm.textPorts.Text;
            Settings.Password = portsFrm.textPassword.Text;
            Settings.aes256   = new Aes256(Settings.Password);

            string[] P = Settings.Port.Split(',');
            foreach (var PORT in P)
            {
                if (!string.IsNullOrWhiteSpace(PORT))
                {
                    listener = new Listener();
                    Thread thread = new Thread(new ParameterizedThreadStart(listener.Connect));
                    thread.Start(Convert.ToInt32(PORT.ToString().Trim()));
                }
            }
        }
Exemple #9
0
 UdpClient receivingUdpClient = new UdpClient(PORT NUMBER);
Exemple #10
0
        private void ConnectButton_Click(object sender, EventArgs e)
        {
            string clientId = DateTime.Now.ToString();

            CliendID.Text = clientId;

            if (IPADDR.Text.Length == 0)
            {
                MessageBox.Show("请输入服务器地址!");
                return;
            }

            if (PORT.Text.Length == 0)
            {
                MessageBox.Show("端口号为空,请输入端口号!");
                return;
            }

            if (!IPCheck(IPADDR.Text))
            {
                if (!domainnameToip(IPADDR.Text))
                {
                    MessageBox.Show("IP或域名格式不正确!");
                    IPADDR.Text = string.Empty;
                    IPADDR.Focus();
                    return;
                }
            }

            int port = Convert.ToInt32(PORT.Text);

            if (port > 65535)
            {
                MessageBox.Show("端口号超过65535,请输入正确端口号!");
                PORT.Text = string.Empty;
                PORT.Focus();
                return;
            }

            string username = "******";
            string password = "******";

            string[] topics = new string[1];
            if (Sub.Text.Length != 0)
            {
                topics[0] = Sub.Text;
            }
            else
            {
                topics[0] = "+";
                Sub.Text  = "+";
            }

            byte[] qosLevels = { MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE };

            try
            {
                if (string.Compare(ConnectButton.Text, "connect") == 0)
                {
                    //单向SSL通信
                    client = new MqttClient(IPADDR.Text, port, false, null, null, MqttSslProtocols.None);
                    //消息接受
                    client.MqttMsgPublishReceived += new MqttClient.MqttMsgPublishEventHandler(messageReceive);
                    //连接Broker
                    client.ConnectionClosed += new MqttClient.ConnectionClosedEventHandler(ConnectState);

                    client.Connect(clientId, username, password);

                    client.Subscribe(topics, qosLevels);


                    ConnectFlag            = true;
                    Sub.Enabled            = false;
                    PORT.Enabled           = false;
                    IPADDR.Enabled         = false;
                    DeviceID.Enabled       = true;
                    FilePath.Enabled       = true;
                    CliendID.Enabled       = false;
                    PubTopic.Enabled       = true;
                    UpgradeButton.Enabled  = true;
                    FileButton.Enabled     = true;
                    FilePushButton.Enabled = true;
                    ConnectButton.Text     = "disconnect";
                    return;
                }
                else
                {
                    client.Disconnect();
                    Sub.Enabled            = true;
                    ConnectFlag            = false;
                    PORT.Enabled           = true;
                    IPADDR.Enabled         = true;
                    DeviceID.Enabled       = false;
                    CliendID.Enabled       = true;
                    FilePath.Enabled       = false;
                    FileButton.Enabled     = false;
                    FilePushButton.Enabled = false;

                    PubTopic.Enabled      = false;
                    UpgradeButton.Enabled = false;
                    ConnectButton.Text    = "connect";
                    return;
                }
            }
            catch (System.Exception)
            {
                MessageBox.Show("MQTT服务器连接失败,请重新连接!");

                PORT.Enabled           = true;
                IPADDR.Enabled         = true;
                CliendID.Enabled       = true;
                FilePath.Enabled       = false;
                FileButton.Enabled     = false;
                FilePushButton.Enabled = false;
                ConnectButton.Text     = "connect";
                return;
            }
        }
Exemple #11
0
        //****************************************************************************
        //メソッド名:OutByte(指定ポートにバイト単位での出力)
        //引数:引数�@ ポート名("P0"、"P1"・・・"P7")引数�A出力値(0x00〜0xFF)
        //戻り値:正常0、異常1
        //****************************************************************************
        public int OutByte(PORT pName, byte Data)
        {
            int flag = 0;

            //ポートの特定と出力データバッファの更新
            switch (pName)
            {
            case PORT.P0:
                this.Port      = EPX64R_PORT0;
                this.p0Outdata = Data;
                break;

            case PORT.P1:
                this.Port      = EPX64R_PORT1;
                this.p1Outdata = Data;
                break;

            case PORT.P2:
                this.Port      = EPX64R_PORT2;
                this.p2Outdata = Data;
                break;

            case PORT.P3:
                this.Port      = EPX64R_PORT3;
                this.p3Outdata = Data;
                break;

            case PORT.P4:
                this.Port      = EPX64R_PORT4;
                this.p4Outdata = Data;
                break;

            case PORT.P5:
                this.Port      = EPX64R_PORT5;
                this.p5Outdata = Data;
                break;

            case PORT.P6:
                this.Port      = EPX64R_PORT6;
                this.p6Outdata = Data;
                break;

            case PORT.P7:
                this.Port      = EPX64R_PORT7;
                this.p7Outdata = Data;
                break;

            default:
                return(1);   //ポート名間違えたら異常とする
            }

            //データの出力
            flag = EPX64R.EPX64R_OutputPort(this.hDevice, this.Port, Data);
            if (flag != EPX64R.EPX64R_OK)
            {
                EPX64R.EPX64R_Close(this.hDevice);   // Device Close
                //MessageBox.Show("EPX64R_OutputPort() Error");
                return(1);
            }

            return(0);
        }
Exemple #12
0
        //****************************************************************************
        //メソッド名:OutBit(指定ポートにビット単位での出力)
        //引数:引数�@ ポート名("P00"、"P01"・・・"P07")引数�A出力値(H:0/ L: 1)
        //戻り値:正常0、異常1
        //****************************************************************************
        public int OutBit(PORT pName, BIT bName, OUT data)
        {
            //ポートの特定
            byte PortOutData = 0;

            switch (pName)
            {
            case PORT.P0:
                this.Port   = EPX64R_PORT0;
                PortOutData = this.p0Outdata;
                break;

            case PORT.P1:
                this.Port   = EPX64R_PORT1;
                PortOutData = this.p1Outdata;
                break;

            case PORT.P2:
                this.Port   = EPX64R_PORT2;
                PortOutData = this.p2Outdata;
                break;

            case PORT.P3:
                this.Port   = EPX64R_PORT3;
                PortOutData = this.p3Outdata;
                break;

            case PORT.P4:
                this.Port   = EPX64R_PORT4;
                PortOutData = this.p4Outdata;
                break;

            case PORT.P5:
                this.Port   = EPX64R_PORT5;
                PortOutData = this.p5Outdata;
                break;

            case PORT.P6:
                this.Port   = EPX64R_PORT6;
                PortOutData = this.p6Outdata;
                break;

            case PORT.P7:
                this.Port   = EPX64R_PORT7;
                PortOutData = this.p7Outdata;
                break;

            default:
                return(1);
            }

            //ビットの特定
            byte Temp = 0;
            int  Num  = 0;

            switch (bName)
            {
            case BIT.b0:
                Num = 0; Temp = 0xFE;
                break;

            case BIT.b1:
                Num = 1; Temp = 0xFD;
                break;

            case BIT.b2:
                Num = 2; Temp = 0xFB;
                break;

            case BIT.b3:
                Num = 3; Temp = 0xF7;
                break;

            case BIT.b4:
                Num = 4; Temp = 0xEF;
                break;

            case BIT.b5:
                Num = 5; Temp = 0xDF;
                break;

            case BIT.b6:
                Num = 6; Temp = 0xBF;
                break;

            case BIT.b7:
                Num = 7; Temp = 0x7F;
                break;
            }


            //データの出力
            byte Data = 0;

            switch (data)
            {
            case OUT.H:
                Data = 1;
                break;

            case OUT.L:
                Data = 0;
                break;
            }


            byte OutputValue = (byte)((PortOutData & Temp) | (Data << Num));//byteでキャストしないと怒られる
            int  flag        = EPX64R.EPX64R_OutputPort(this.hDevice, Port, OutputValue);

            if (flag != EPX64R.EPX64R_OK)
            {
                EPX64R.EPX64R_Close(this.hDevice);   // Device Close
                //MessageBox.Show("EPX64R_OutputPort() Error");
                return(1);
            }

            switch (pName)
            {
            case PORT.P0:
                this.p0Outdata = OutputValue;
                break;

            case PORT.P1:
                this.p1Outdata = OutputValue;
                break;

            case PORT.P2:
                this.p2Outdata = OutputValue;
                break;

            case PORT.P3:
                this.p3Outdata = OutputValue;
                break;

            case PORT.P4:
                this.p4Outdata = OutputValue;
                break;

            case PORT.P5:
                this.p5Outdata = OutputValue;
                break;

            case PORT.P6:
                this.p6Outdata = OutputValue;
                break;

            case PORT.P7:
                this.p7Outdata = OutputValue;
                break;
            }
            return(0);
        }
Exemple #13
0
        //****************************************************************************
        //メソッド名:ReadInputData(指定ポートのデータを取り込む)
        //引数:ポート名("P0"、"P1"・・・"P7")
        //戻り値:取り込んだデータ正常0、異常1
        //****************************************************************************
        public bool ReadInputData(PORT pName)
        {
            try
            {
                switch (pName)
                {
                case PORT.P0:
                    this.Port = EPX64R.EPX64R_PORT0;     // PORT0
                    break;

                case PORT.P1:
                    this.Port = EPX64R.EPX64R_PORT1;     // PORT1
                    break;

                case PORT.P2:
                    this.Port = EPX64R.EPX64R_PORT2;     // PORT2
                    break;

                case PORT.P3:
                    this.Port = EPX64R.EPX64R_PORT3;     // PORT3
                    break;

                case PORT.P4:
                    this.Port = EPX64R.EPX64R_PORT4;     // PORT4
                    break;

                case PORT.P5:
                    this.Port = EPX64R.EPX64R_PORT5;     // PORT5
                    break;

                case PORT.P6:
                    this.Port = EPX64R.EPX64R_PORT6;     // PORT6
                    break;

                case PORT.P7:
                    this.Port = EPX64R.EPX64R_PORT7;     // PORT7
                    break;

                default:
                    break;
                }

                // Input
                this.Status = EPX64R.EPX64R_InputPort(this.hDevice, this.Port, ref this.InputValue);
                if (Status != EPX64R.EPX64R_OK)
                {
                    //MessageBox.Show("EPX64R_InputPort() Error");
                    EPX64R.EPX64R_Close(hDevice);   // Device Close
                    return(false);
                }

                switch (pName)
                {
                case PORT.P0:
                    this.P0InputData = this.InputValue;
                    break;

                case PORT.P1:
                    this.P1InputData = this.InputValue;
                    break;

                case PORT.P2:
                    this.P2InputData = this.InputValue;
                    break;

                case PORT.P3:
                    this.P3InputData = this.InputValue;
                    break;

                case PORT.P4:
                    this.P4InputData = this.InputValue;
                    break;

                case PORT.P5:
                    this.P5InputData = this.InputValue;
                    break;

                case PORT.P6:
                    this.P6InputData = this.InputValue;
                    break;

                case PORT.P7:
                    this.P7InputData = this.InputValue;
                    break;
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemple #14
0
        //****************************************************************************
        //メソッド名:ReadInputData(指定ポートのデータを取り込む)
        //引数:ポート名("P0"、"P1"・・・"P7")
        //戻り値:取り込んだデータ正常0、異常1
        //****************************************************************************
        public bool ReadInputData(PORT pName)
        {
            try
            {
                switch (pName)
                {
                case PORT.P0:
                    this.Port = EPX64S_PORT0;     // PORT0
                    break;

                case PORT.P1:
                    this.Port = EPX64S_PORT1;     // PORT1
                    break;

                case PORT.P2:
                    this.Port = EPX64S_PORT2;     // PORT2
                    break;

                case PORT.P3:
                    this.Port = EPX64S_PORT3;     // PORT3
                    break;

                case PORT.P4:
                    this.Port = EPX64S_PORT4;     // PORT4
                    break;

                case PORT.P5:
                    this.Port = EPX64S_PORT5;     // PORT5
                    break;

                case PORT.P6:
                    this.Port = EPX64S_PORT6;     // PORT6
                    break;

                case PORT.P7:
                    this.Port = EPX64S_PORT7;     // PORT7
                    break;

                default:
                    break;
                }

                // Input
                foreach (var i in Enumerable.Range(1, 2))
                {
                    this.Status = EPX64S_InputPort(this.hDevice, this.Port, ref this.InputValue);
                    if (Status == EPX64S_OK)
                    {
                        break;
                    }
                    if (i == 2)
                    {
                        return(false);
                    }
                }

                switch (pName)
                {
                case PORT.P0:
                    this.P0InputData = this.InputValue;
                    break;

                case PORT.P1:
                    this.P1InputData = this.InputValue;
                    break;

                case PORT.P2:
                    this.P2InputData = this.InputValue;
                    break;

                case PORT.P3:
                    this.P3InputData = this.InputValue;
                    break;

                case PORT.P4:
                    this.P4InputData = this.InputValue;
                    break;

                case PORT.P5:
                    this.P5InputData = this.InputValue;
                    break;

                case PORT.P6:
                    this.P6InputData = this.InputValue;
                    break;

                case PORT.P7:
                    this.P7InputData = this.InputValue;
                    break;
                }
                return(true);
            }
            catch
            {
                this.Status = EPX64S.EPX64S_COMMUNICATION_ERROR;
                return(false);
            }
        }
Exemple #15
0
        //****************************************************************************
        //メソッド名:OutByte(指定ポートにバイト単位での出力)
        //引数:引数�@ ポート名("P0"、"P1"・・・"P7")引数�A出力値(0x00〜0xFF)
        //戻り値:正常0、異常1
        //****************************************************************************
        public bool OutByte(PORT pName, byte Data)
        {
            try
            {
                //ポートの特定と出力データバッファの更新
                switch (pName)
                {
                case PORT.P0:
                    this.Port      = EPX64S_PORT0;
                    this.p0Outdata = Data;
                    break;

                case PORT.P1:
                    this.Port      = EPX64S_PORT1;
                    this.p1Outdata = Data;
                    break;

                case PORT.P2:
                    this.Port      = EPX64S_PORT2;
                    this.p2Outdata = Data;
                    break;

                case PORT.P3:
                    this.Port      = EPX64S_PORT3;
                    this.p3Outdata = Data;
                    break;

                case PORT.P4:
                    this.Port      = EPX64S_PORT4;
                    this.p4Outdata = Data;
                    break;

                case PORT.P5:
                    this.Port      = EPX64S_PORT5;
                    this.p5Outdata = Data;
                    break;

                case PORT.P6:
                    this.Port      = EPX64S_PORT6;
                    this.p6Outdata = Data;
                    break;

                case PORT.P7:
                    this.Port      = EPX64S_PORT7;
                    this.p7Outdata = Data;
                    break;

                default:
                    break;
                }

                //データの出力
                this.Status = EPX64S_OutputPort(this.hDevice, this.Port, Data);
                return((Status == EPX64S_OK) ? true : false);
            }
            catch
            {
                this.Status = EPX64S.EPX64S_COMMUNICATION_ERROR;
                return(false);
            }
        }
Exemple #16
0
        //****************************************************************************
        //メソッド名:OutBit(指定ポートにビット単位での出力)
        //引数:引数�@ ポート名("P00"、"P01"・・・"P07")引数�A出力値(H:0/ L: 1)
        //戻り値:bool
        //****************************************************************************
        public bool OutBit(PORT pName, BIT bName, OUT data)
        {
            byte buffOutData = 0; //現時点で出力しているデータ

            try
            {
                //ポートの特定
                switch (pName)
                {
                case PORT.P0:
                    this.Port   = EPX64S_PORT0;
                    buffOutData = this.p0Outdata;
                    break;

                case PORT.P1:
                    this.Port   = EPX64S_PORT1;
                    buffOutData = this.p1Outdata;
                    break;

                case PORT.P2:
                    this.Port   = EPX64S_PORT2;
                    buffOutData = this.p2Outdata;
                    break;

                case PORT.P3:
                    this.Port   = EPX64S_PORT3;
                    buffOutData = this.p3Outdata;
                    break;

                case PORT.P4:
                    this.Port   = EPX64S_PORT4;
                    buffOutData = this.p4Outdata;
                    break;

                case PORT.P5:
                    this.Port   = EPX64S_PORT5;
                    buffOutData = this.p5Outdata;
                    break;

                case PORT.P6:
                    this.Port   = EPX64S_PORT6;
                    buffOutData = this.p6Outdata;
                    break;

                case PORT.P7:
                    this.Port   = EPX64S_PORT7;
                    buffOutData = this.p7Outdata;
                    break;

                default:
                    break;
                }

                //ビットの特定
                byte Temp = 0;
                int  Num  = 0;

                switch (bName)
                {
                case BIT.b0:
                    Num = 0; Temp = 0xFE;
                    break;

                case BIT.b1:
                    Num = 1; Temp = 0xFD;
                    break;

                case BIT.b2:
                    Num = 2; Temp = 0xFB;
                    break;

                case BIT.b3:
                    Num = 3; Temp = 0xF7;
                    break;

                case BIT.b4:
                    Num = 4; Temp = 0xEF;
                    break;

                case BIT.b5:
                    Num = 5; Temp = 0xDF;
                    break;

                case BIT.b6:
                    Num = 6; Temp = 0xBF;
                    break;

                case BIT.b7:
                    Num = 7; Temp = 0x7F;
                    break;
                }


                //データの出力
                byte Data = 0;
                switch (data)
                {
                case OUT.H:
                    Data = 1;
                    break;

                case OUT.L:
                    Data = 0;
                    break;
                }

                //指定ビット以外はそのままにして出力データを決定する
                byte OutputValue = (byte)((buffOutData & Temp) | (Data << Num));//byteでキャストしないと怒られる

                //出力データバッファの更新
                switch (pName)
                {
                case PORT.P0:
                    this.p0Outdata = OutputValue;
                    break;

                case PORT.P1:
                    this.p1Outdata = OutputValue;
                    break;

                case PORT.P2:
                    this.p2Outdata = OutputValue;
                    break;

                case PORT.P3:
                    this.p3Outdata = OutputValue;
                    break;

                case PORT.P4:
                    this.p4Outdata = OutputValue;
                    break;

                case PORT.P5:
                    this.p5Outdata = OutputValue;
                    break;

                case PORT.P6:
                    this.p6Outdata = OutputValue;
                    break;

                case PORT.P7:
                    this.p7Outdata = OutputValue;
                    break;
                }

                //データ出力
                this.Status = EPX64S_OutputPort(this.hDevice, Port, OutputValue);
                return((Status == EPX64S_OK) ? true : false);
            }
            catch
            {
                this.Status = EPX64S.EPX64S_COMMUNICATION_ERROR;
                return(false);
            }
        }
Exemple #17
0
        public int fAddSocketAddress(string sLayer4_Protocol, string sIPAddress, int iPortValue)
        {
            //TODO: Deprecate or use is_source, is_destination (legacy from NDDM)

            //XORCISMModel.NETWORKCONNECTION NetConnect = new NETWORKCONNECTION();

            #region Layer4
            //Make sure we have the Layer 4 "Transport Layer" in the Database
            int iProtoLayer4ID = XModel.OSILAYER.Where(o => o.OSILayerName == "Transport Layer").Select(o => o.OSILayerID).FirstOrDefault();  //Hardcoded
            if (iProtoLayer4ID <= 0)
            {
                //TODO Create the OSILAYER
            }
            #endregion Layer4
            //Retrieve the Layer4_ProtocolID
            int iLayer4ProtocolID = XModel.PROTOCOL.Where(o => o.ProtocolName == sLayer4_Protocol && o.OSILayerID == iProtoLayer4ID).Select(o => o.ProtocolID).FirstOrDefault();
            if (iLayer4ProtocolID <= 0)
            {
                //TODO ERROR
            }


            //Add the Address IP/Hostname
            #region AddAddress
            XORCISMModel.ADDRESS IPAddress = new ADDRESS();
            int iAddressID = 0;
            try
            {
                //Get the ipv4-addr (CybOX) CategoryID (compatibility with Asset Identification)
                int iAddCat = 0;
                iAddCat = XModel.ADDRESSCATEGORY.Where(o => o.AddressCategoryName == "ipv4-addr").Select(o => o.AddressCategoryID).FirstOrDefault();    //Hardcoded
                IPAddress.AddressCategoryID = iAddCat;

                //Check if already exists. TODO: same organisation? See ASSETADDRESS
                iAddressID = XModel.ADDRESS.Where(o => o.Address_Value == sIPAddress).Select(o => o.AddressID).FirstOrDefault();
                if (iAddressID <= 0)
                {
                    IPAddress.Address_Value = sIPAddress;
                    //TODO check if country... retrievable
                    //IPAddress.is_source = true;
                    //IPAddSource.is_destination=false;
                    XModel.ADDRESS.Add(IPAddress);
                    XModel.SaveChanges();
                    iAddressID = IPAddress.AddressID;
                }
            }
            catch (Exception exAddAddress)
            {
                Console.WriteLine("Exception exAddAddress: " + exAddAddress.Message + " " + exAddAddress.InnerException);
            }
            #endregion AddAddress

            //Add the Port
            #region AddPort
            int iPortID = XModel.PORT.Where(o => o.Port_Value == iPortValue && o.ProtocolID == iProtoLayer4ID).Select(o => o.PortID).FirstOrDefault();
            if (iPortID <= 0)
            {
                try
                {
                    XORCISMModel.PORT PortSource = new PORT();
                    //TODO check if already exists
                    PortSource.ProtocolID = iProtoLayer4ID;
                    PortSource.Port_Value = iPortValue;
                    //PortSource.VocabularyID=;
                    XModel.PORT.Add(PortSource);
                    XModel.SaveChanges();
                    iPortID = PortSource.PortID;
                }
                catch (Exception exAddPort)
                {
                    Console.WriteLine("Exception exAddPort: " + exAddPort.Message + " " + exAddPort.InnerException);
                }
            }
            #endregion AddPort

            //Add the SocketAddress
            int iSocketAddressID = 0;
            iSocketAddressID = XModel.SOCKETADDRESS.Where(o => o.AddressID == iAddressID && o.PortID == iPortID).Select(o => o.SocketAddressID).FirstOrDefault();
            try
            {
                XORCISMModel.SOCKETADDRESS oSockAddress = new SOCKETADDRESS();
                oSockAddress.AddressID   = iAddressID;
                oSockAddress.PortID      = iPortID;
                oSockAddress.CreatedDate = DateTimeOffset.Now;
                oSockAddress.timestamp   = DateTimeOffset.Now;
                oSockAddress.isEncrypted = false;
                XModel.SOCKETADDRESS.Add(oSockAddress);
                XModel.SaveChanges();
                iSocketAddressID = oSockAddress.SocketAddressID;
            }
            catch (Exception exAddSocketAddress)
            {
                Console.WriteLine("Exception exAddSocketAddress: " + exAddSocketAddress.Message + " " + exAddSocketAddress.InnerException);
            }

            return(iSocketAddressID);
        }