コード例 #1
0
        public void DownloadProfileList(bool bForce = false)
        {
            if (m_profileCollection != null && !bForce)
            {
                return;
            }

            string state = null;

            if (m_profileCollection != null)
            {
                state = SerializeState();
            }

            //LetsMTWebService.MTSystem[] mtList = m_service.GetSystemList(m_strAppID, null);
            ((IContextChannel)m_service.InnerChannel).OperationTimeout = new TimeSpan(0, 1, 0);
            LetsMTAPI.MTSystem[] mtList = null;
            try
            {
                mtList = m_service.GetSystemList(m_strAppID, null, null).System;
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("The HTTP request is unauthorized"))
                {
                    throw new TranslationProviderAuthenticationException();
                }
                else
                {
                    throw new Exception("Could not connect to translation provider.");
                }
            }
            m_profileCollection = new CMtProfileCollection(mtList);

            if (state != null)
            {
                LoadState(state);
            }
        }
コード例 #2
0
        public void InitService(string m_strToken)
        {
            // create Web Service client
            string           url     = Properties.Settings.Default.WebServiceUrl;
            BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);

            // remove buffet limmit
            binding.MaxBufferSize          = int.MaxValue;
            binding.MaxReceivedMessageSize = int.MaxValue;
            // binding.ReceiveTimeout =

            //try to read Software\\Tilde\\LetsMT\\url registry string entry and it it exists replace the link
            try
            {
                Microsoft.Win32.RegistryKey key;
                key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\\Tilde\\LetsMT");
                if (key != null)
                {
                    string RegUrl = key.GetValue("url", "none").ToString();
                    if (RegUrl.Length > 3)
                    {
                        if (RegUrl.Substring(0, 4) == "http")
                        {
                            url = RegUrl;
                        }
                    }
                }
            }
            catch (Exception) { }



            EndpointAddress endpoint = new EndpointAddress(url);


            //TODO: HACK {
            // Attach custom Certificate validator to pass validation of untrusted development certificate
            // TODO: This should be removed when trusted CA certificate will be used (or callback method have to do harder checking)
            // ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(ValidateRemoteCertificate);
            //TODO: HACK }

            //binding.Security.Transport.
            //if (m_strAppID != "")
            //{
            //    binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
            //}
            //else
            //{
            //    binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
            //}
            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
            m_service = new LetsMTAPI.TranslationServiceContractClient(binding, endpoint);

            HeaderManagerMessageInspector inspector          = new HeaderManagerMessageInspector("client-id", m_strToken);
            InspectorBehaviour            addUserIdBehaviour = new InspectorBehaviour(inspector);

            m_service.Endpoint.Behaviors.Add(addUserIdBehaviour);
            ReaderQuotaExtensionBehaviour increaseQuotaBehaviour = new ReaderQuotaExtensionBehaviour();

            m_service.Endpoint.Behaviors.Add(increaseQuotaBehaviour);

            // m_service.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.PeerTrust;

            m_profileCollection = null;
        }