コード例 #1
0
        private void _connectionBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            bool retryTcpConnection =
                (this.ServiceTransport == ServiceTransport.BinaryHttps &&
                 !String.IsNullOrEmpty(Config.Current.TcpServerName) &&
                 DateTime.Now > _nextTcpConnectionAttemptTime);

            if (!this.IsConnected ||
                retryTcpConnection)
            {
                e.Result = false;

                try
                {
                    if (!String.IsNullOrEmpty(Config.Current.TcpServerName))
                    {
                        ServerSettings serverSettings = new ServerSettings();
                        serverSettings.ServerName = Config.Current.TcpServerName;
                        serverSettings.Port       = Config.Current.TcpPort;
                        serverSettings.Transport  = ServiceTransport.NetTcp;

                        ServiceChannelFactories.Initialize(serverSettings, true);

                        using (CoreServiceAgent coreAgent = new CoreServiceAgent())
                        {
                            coreAgent.EnsureEventListener(EventGroup.RecordingEvents, _eventsServiceBaseUrl, Constants.EventListenerApiVersion);
                        }
                        lock (_connectionLock)
                        {
                            _serviceTransport = serverSettings.Transport;
                            _isConnected      = true;
                        }
                        _nextTcpConnectionAttemptTime = DateTime.MaxValue;
                        e.Result = true;
                    }
                    else
                    {
                        ConnectOverHttps();
                        e.Result = true;
                    }
                }
                catch
                {
                    try
                    {
                        ConnectOverHttps();
                        e.Result = true;
                    }
                    catch
                    {
                        this.IsConnected = false;
                    }
                }
            }
            else
            {
                e.Result = this.IsConnected;
            }
        }
コード例 #2
0
ファイル: ConnectForm.cs プロジェクト: rob-opsi/ARGUS-TV
        private void _okButton_Click(object sender, EventArgs e)
        {
            try
            {
                _serverSettings.ServerName = _serverTextBox.Text.Trim();
                ServiceTransport transport = ServiceTransport.Http;
                if (_transportComboBox.SelectedIndex == 1)
                {
                    transport = ServiceTransport.Https;
                }
                _serverSettings.Transport                = transport;
                _serverSettings.Port                     = (int)_portNumericUpDown.Value;
                _serverSettings.WakeOnLan.Enabled        = _useWolCheckBox.Checked;
                _serverSettings.WakeOnLan.TimeoutSeconds = (int)_wolSecondsNumericUpDown.Value;

                bool doConnect = true;

                if (_serverSettings.Transport == ServiceTransport.Https)
                {
                    using (LogonForm logonForm = new LogonForm())
                    {
                        logonForm.UserName       = _serverSettings.UserName;
                        logonForm.Password       = _serverSettings.Password;
                        doConnect                = (DialogResult.OK == logonForm.ShowDialog(this));
                        _savePassword            = logonForm.SavePassword;
                        _serverSettings.UserName = logonForm.UserName;
                        _serverSettings.Password = logonForm.Password;
                    }
                }

                if (doConnect)
                {
                    try
                    {
                        Cursor.Current = Cursors.WaitCursor;
                        Proxies.Initialize(_serverSettings, true);

                        if (_saveAsProfileCheckBox.Checked)
                        {
                            _profileName = _profileNameTextBox.Text.Trim();
                        }
                        else
                        {
                            _profileName = null;
                        }
                        this.DialogResult = DialogResult.OK;
                        this.Close();
                    }
                    finally
                    {
                        Cursor.Current = Cursors.Default;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, null, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #3
0
        public async Task <IActionResult> AjouterTransport(TransportExtViewModel model)
        {
            string idx = userManager.GetUserId(User);

            ViewBag.id = userManager.GetUserId(User);
            string uniqueFileName = null;

            if (ModelState.IsValid)
            {
                if (model.Images != null)
                {
                    // The image must be uploaded to the images folder in wwwroot
                    // To get the path of the wwwroot folder we are using the inject
                    // HostingEnvironment service provided by ASP.NET Core
                    string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "Files");
                    // To make sure the file name is unique we are appending a new
                    // GUID value and and an underscore to the file name
                    uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Images.FileName;
                    string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                    // Use CopyTo() method provided by IFormFile interface to
                    // copy the file to wwwroot/images folder
                    model.Images.CopyTo(new FileStream(filePath, FileMode.Create));
                }
                var transport = new ServiceTransport
                {
                    NbrPlaces = model.NbrPlaces,

                    Load   = model.Load,
                    Region = model.Region,

                    Image            = uniqueFileName,
                    ReservationPrive = model.TypeTransport,
                    TypeTransport    = model.TypeTransport,
                    Fournisseur      = fournisseurService.GetFournisseurById(userManager.GetUserId(User)).Result
                };

                await transportExtService.Ajout(transport);

                return(RedirectToAction("Index", "Home"));
            }

            return(View(model));
        }
コード例 #4
0
 private void ConnectOverHttps()
 {
     if (!String.IsNullOrEmpty(Config.Current.HttpsServerName))
     {
         ServerSettings serverSettings = new ServerSettings();
         serverSettings.ServerName = Config.Current.HttpsServerName;
         serverSettings.Port       = Config.Current.HttpsPort;
         serverSettings.UserName   = Config.Current.UserName;
         serverSettings.Password   = Config.Current.Password;
         serverSettings.Transport  = ServiceTransport.BinaryHttps;
         if (ServiceChannelFactories.Initialize(serverSettings, false))
         {
             lock (_connectionLock)
             {
                 _serviceTransport             = serverSettings.Transport;
                 _isConnected                  = true;
                 _nextTcpConnectionAttemptTime = DateTime.Now.AddMinutes(_retryTcpConnectionMinutes);
             }
         }
     }
 }
コード例 #5
0
        private void _connectionBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            bool retryTcpConnection =
                (this.ServiceTransport == ServiceTransport.BinaryHttps
                && !String.IsNullOrEmpty(Config.Current.TcpServerName)
                && DateTime.Now > _nextTcpConnectionAttemptTime);
            if (!this.IsConnected
                || retryTcpConnection)
            {
                e.Result = false;

                try
                {
                    if (!String.IsNullOrEmpty(Config.Current.TcpServerName))
                    {
                        ServerSettings serverSettings = new ServerSettings();
                        serverSettings.ServerName = Config.Current.TcpServerName;
                        serverSettings.Port = Config.Current.TcpPort;
                        serverSettings.Transport = ServiceTransport.NetTcp;

                        ServiceChannelFactories.Initialize(serverSettings, true);

                        using (CoreServiceAgent coreAgent = new CoreServiceAgent())
                        {
                            coreAgent.EnsureEventListener(EventGroup.RecordingEvents, _eventsServiceBaseUrl, Constants.EventListenerApiVersion);
                        }
                        lock (_connectionLock)
                        {
                            _serviceTransport = serverSettings.Transport;
                            _isConnected = true;
                        }
                        _nextTcpConnectionAttemptTime = DateTime.MaxValue;
                        e.Result = true;
                    }
                    else
                    {
                        ConnectOverHttps();
                        e.Result = true;
                    }
                }
                catch
                {
                    try
                    {
                        ConnectOverHttps();
                        e.Result = true;
                    }
                    catch
                    {
                        this.IsConnected = false;
                    }
                }
            }
            else
            {
                e.Result = this.IsConnected;
            }
        }
コード例 #6
0
 private void ConnectOverHttps()
 {
     if (!String.IsNullOrEmpty(Config.Current.HttpsServerName))
     {
         ServerSettings serverSettings = new ServerSettings();
         serverSettings.ServerName = Config.Current.HttpsServerName;
         serverSettings.Port = Config.Current.HttpsPort;
         serverSettings.UserName = Config.Current.UserName;
         serverSettings.Password = Config.Current.Password;
         serverSettings.Transport = ServiceTransport.BinaryHttps;
         if (ServiceChannelFactories.Initialize(serverSettings, false))
         {
             lock (_connectionLock)
             {
                 _serviceTransport = serverSettings.Transport;
                 _isConnected = true;
                 _nextTcpConnectionAttemptTime = DateTime.Now.AddMinutes(_retryTcpConnectionMinutes);
             }
         }
     }
 }
コード例 #7
0
 public TestServiceTransportProvider()
 {
     var(remote, local) = Nerdbank.Streams.FullDuplexStream.CreatePair();
     Connector          = new TestServiceTransportConnector(local);
     _transport         = new ServiceTransport(remote, this);
 }
コード例 #8
0
 public Task Update(ServiceTransport logement)
 {
     return(GenericRepo.PutAsync(logement.Id, logement));
 }
コード例 #9
0
 public Task Delete(ServiceTransport logement)
 {
     return(GenericRepo.DeleteAsync(logement.Id));
 }
コード例 #10
0
 public Task Ajout(ServiceTransport logement)
 {
     return(GenericRepo.InsertAsync(logement));
 }