Exemplo n.º 1
0
        private void MainServerForm_Load(object sender, EventArgs e)
        {
            TraceOps.LoadLog();
            try
            {
                _name = "Server";

                Services.PrepareSetService(_port);
                Services.SetService(typeof(ConnectionTable));
                Services.SetService(typeof(MessageQueue));

                _connectionTable = ConnectionTable.GetRemote("localhost", _port);
                _messageQueue    = MessageQueue.GetRemote("localhost", _port);

                _taskManager       = new TaskManager(ref _messageQueue, ref _name);
                _taskManager.Task += TaskManagerOnTask;

                var ci = new ConnectionTable.ClientInformation(_name);
                ci.SetGroup("server");
                ci.SetIp(NetworkOps.GetIpString(HashOps.GetFqdn()));
                ci.SetPort(_port);
                _connectionTable.Set(_name, ci);

                LoadClientsTable();
                LoadPlugIns();
            }
            catch (Exception ex)
            {
                TraceOps.Out(ex.Message);
            }
        }
Exemplo n.º 2
0
        public void Init()
        {
            var prefs = MockRepository.GenerateStub <IPreferenceSet>();

            prefs.Stub(x => x.Get <bool>(Preference.UseProxy)).Return(false).Repeat.Any();
            _net = new NetworkOps(prefs);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes the database.
        /// </summary>
        private void InitializeDb()
        {
            try {
                using (var ts = new TransactionScope(TransactionScopeOption.RequiresNew,
                                                     new TransactionOptions()
                {
                    IsolationLevel = IsolationLevel.ReadUncommitted
                })) {
                    using (var context = new MetaFSDB()) {
                        // Create basic categories
                        if (!context.Categories.Any())
                        {
                            context.Categories.AddRange(GetBasicCategories());
                        }

                        // Create basic object types
                        if (!context.ObjectTypes.Any())
                        {
                            context.ObjectTypes.AddRange(GetBasicObjectTypes());
                        }

                        // Register PC
                        SelectedMac = NetworkOps.GetMacAddress();

                        var registeredPc = context.RegisteredPCs.FirstOrDefault(x => x.PCName.Equals(Environment.MachineName,
                                                                                                     StringComparison.OrdinalIgnoreCase));
                        if (registeredPc == null)
                        {
                            registeredPc = new RegisteredPC()
                            {
                                MacAddress = SelectedMac,
                                IsEnabled  = true,
                                PCName     = Environment.MachineName
                            };
                            context.RegisteredPCs.Add(registeredPc);
                        }
                        else
                        {
                            registeredPc.MacAddress = SelectedMac;
                            context.RegisteredPCs.Attach(registeredPc);
                            var entry = context.Entry(registeredPc);
                            entry.Property(e => e.MacAddress).IsModified = true;
                        }

                        context.SaveChanges();

                        PcIdentifier = registeredPc.PCId;
                        MachineName  = registeredPc.PCName;
                    }
                    ts.Complete();
                }
            } catch (Exception ex) {
                Logger.LogError(ex);
            }
        }
Exemplo n.º 4
0
        private void Register()
        {
            var ci = _connectionTable.Get(_name);

            //TODO Demo
            ci.SetApplicationNames("");
            ci.SetIp(NetworkOps.GetIpString(HashOps.GetFqdn()));
            ci.SetPort(9091);

            _connectionTable.Set(_name, ci);
        }
Exemplo n.º 5
0
 private void LoadConnections(Connections connections)
 {
     foreach (Connection connection in connections.ConnectionList)
     {
         if (connection.name != "Server" && connection.ip != "unknown" && connection.port != 0)
         {
             IPHostEntry he  = Dns.GetHostEntry(connection.ip);
             var         dns = he.AddressList[1].ToString();
             var         ip  = NetworkOps.GetIpString(dns);
             NetworkOps.SetUpClientConnectionConfig(ip, connection.port, _ip, _port);
         }
     }
 }
Exemplo n.º 6
0
        private void newConnectionToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            _newConnectionForm = new ConnectionForm()
            {
                TopLevel = true
            };
            if (_newConnectionForm.ShowDialog() == DialogResult.OK)
            {
                var ip   = NetworkOps.GetIpString(_newConnectionForm.textBoxUri.Text);
                var port = NetworkOps.GetPort(_newConnectionForm.textBoxPort.Text);

                var connected = NetworkOps.SetUpClientConnectionConfig(ip, port, _ip, _port);
                if (!connected)
                {
                    MessageBox.Show("Cannot establish connection to network. Please try again.\r\n");
                }
            }
        }
Exemplo n.º 7
0
        private void notifyIcon_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                var btext = "No network connection";
                try
                {
                    btext = NetworkOps.GetIpString(HashOps.GetFqdn());
                }
                catch (Exception)
                {
                    btext = "No network connection";
                }


                notifyIcon.ShowBalloonTip(1000, "Pace Configuration", btext, ToolTipIcon.None);
            }

            if (e.Button == MouseButtons.Right)
            {
                MethodInfo mi = typeof(NotifyIcon).GetMethod("ShowContextMenu", BindingFlags.Instance | BindingFlags.NonPublic);
                mi.Invoke(notifyIcon, null);
            }
        }
Exemplo n.º 8
0
        public void Init()
        {
            _mocks = new MockRepository();

             var prefs = _mocks.DynamicMock<IPreferenceSet>();
             Expect.Call(prefs.Get<bool>(Preference.UseProxy)).Return(false).Repeat.Any();
             _net = new NetworkOps(prefs);
        }
Exemplo n.º 9
0
 public void Init()
 {
    var prefs = MockRepository.GenerateStub<IPreferenceSet>();
    prefs.Stub(x => x.Get<bool>(Preference.UseProxy)).Return(false).Repeat.Any();
    _net = new NetworkOps(prefs);
 }
Exemplo n.º 10
0
        private void ConfigTasks()
        {
            try
            {
                Byte[] data;
                String responseData = String.Empty;
                var    server       = new TcpListener(IPAddress.Any, _port);
                server.Start();

                while (_running)
                {
                    Thread.Sleep(Threshold);
                    while (!server.Pending())
                    {
                        Thread.Sleep(Threshold);
                    }

                    TcpClient     client = server.AcceptTcpClient();
                    NetworkStream stream = client.GetStream();

                    IPEndPoint remoteIpEndPoint = client.Client.RemoteEndPoint as IPEndPoint;
                    IPEndPoint localIpEndPoint  = client.Client.LocalEndPoint as IPEndPoint;

                    if (remoteIpEndPoint != null)
                    {
                        TraceOps.Out(remoteIpEndPoint.Address + " : " + remoteIpEndPoint.Port);
                    }
                    if (localIpEndPoint != null)
                    {
                        TraceOps.Out(localIpEndPoint.Address + " : " + localIpEndPoint.Port);
                    }


                    while (client.Connected)
                    {
                        Thread.Sleep(Threshold);
                        data = new Byte[1024];
                        var connectIp   = "";
                        var connectPort = 0;

                        Int32 bytes = stream.Read(data, 0, data.Length);
                        responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes);
                        if (responseData != "")
                        {
                            if (responseData.IndexOf("<PORT>", StringComparison.Ordinal) > 0)
                            {
                                connectPort = Convert.ToInt32(NetworkOps.GetValue("PORT", responseData));
                                TraceOps.Out("Recived PORT: " + connectPort);
                            }
                            if (responseData.IndexOf("<IP>", StringComparison.Ordinal) > 0)
                            {
                                connectIp = NetworkOps.GetValue("IP", responseData);
                                connectIp = NetworkOps.GetIpString(connectIp);
                                TraceOps.Out("Recived IP: " + connectIp);
                            }

                            if (responseData.IndexOf("</XML>", StringComparison.Ordinal) > 0)
                            {
                                stream.Close();
                                client.Close();

                                if (connectIp != "" && connectPort != 0 && remoteIpEndPoint != null)
                                {
                                    var e = new ChangedEventArgs(remoteIpEndPoint.Address.ToString(), connectPort);
                                    OnChanged(e);
                                }
                                TraceOps.Out("Recived End");
                            }
                        }
                    }

                    TraceOps.Out("Close Stream and TCP Connection");

                    if (client.Connected)
                    {
                        stream.Close();
                        client.Close();
                    }
                }
                server.Stop();
            }
            catch (Exception exception)
            {
                TraceOps.Out(exception.ToString());
            }
        }