daily pastebin goal
94%
SHARE
TWEET

Untitled

a guest Jan 25th, 2016 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?xml version="1.0" encoding="utf-8"?>
  2.     <configuration>
  3.       <configSections>
  4.         <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  5.       </configSections>
  6.       <appSettings>
  7.         <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  8.       </appSettings>
  9.       <system.web>
  10.         <compilation targetFramework="4.5" />
  11.         <httpRuntime targetFramework="4.5" />
  12.       </system.web>
  13.       <system.serviceModel>
  14.         <services>
  15.           <service name="UpdateWCF.Service" behaviorConfiguration="UpdateServiceBehavior">
  16.             <host>
  17.               <baseAddresses>
  18.                 <add baseAddress="http://localhost:62135/" />
  19.               </baseAddresses>
  20.             </host>
  21.             <endpoint address="" behaviorConfiguration="UpdateServiceEndpointBehavior" binding="wsHttpBinding" bindingConfiguration="UpdateWCFBinding" contract="UpdateWCF.IService"></endpoint>
  22.             <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>
  23.           </service>
  24.         </services>
  25.         <behaviors>
  26.           <endpointBehaviors>
  27.             <behavior name="UpdateServiceEndpointBehavior"></behavior>
  28.           </endpointBehaviors>
  29.           <serviceBehaviors>
  30.             <behavior name="UpdateServiceBehavior">
  31.               <serviceMetadata httpGetEnabled="True" />
  32.               <serviceDebug includeExceptionDetailInFaults="True" />
  33.               <serviceCredentials>
  34.                 <serviceCertificate findValue="ServerCertificate" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName" />
  35.                 <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="UpdateWCF.CustomUserNamePasswordValidator, UpdateWCF"></userNameAuthentication>
  36.                 <clientCertificate>
  37.                   <authentication certificateValidationMode="None" />
  38.                 </clientCertificate>
  39.               </serviceCredentials>
  40.             </behavior>
  41.           </serviceBehaviors>
  42.         </behaviors>
  43.         <bindings>
  44.           <wsHttpBinding>
  45.             <binding name="UpdateWCFBinding">
  46.               <readerQuotas maxDepth="2147483647" maxStringContentLength="10000000" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
  47.               <security mode="Message">
  48.                 <message clientCredentialType="UserName" />
  49.               </security>
  50.             </binding>
  51.           </wsHttpBinding>
  52.         </bindings>
  53.         <protocolMapping>
  54.           <add binding="basicHttpsBinding" scheme="https" />
  55.         </protocolMapping>
  56.         <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  57.       </system.serviceModel>
  58.       <system.webServer>
  59.         <modules runAllManagedModulesForAllRequests="true" />
  60.         <directoryBrowse enabled="false" />
  61.       </system.webServer>
  62.       <entityFramework>
  63.         <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
  64.           <parameters>
  65.             <parameter value="mssqllocaldb" />
  66.           </parameters>
  67.         </defaultConnectionFactory>
  68.         <providers>
  69.           <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
  70.         </providers>
  71.       </entityFramework>
  72.       <connectionStrings>
  73.         <add connectionString="Data Source=37.18.74.28;Initial Catalog=JfsServiceUpdate;User ID=UpdateWCF;Password=5JHWCoBY;Connection Timeout=0" name="JfsUpdates"
  74.    
  75. <system.serviceModel>
  76.     <bindings>
  77.         <wsHttpBinding>
  78.             <binding name="WSHttpBinding_IService">
  79.                 <security>
  80.                     <message clientCredentialType="UserName" />
  81.                 </security>
  82.             </binding>
  83.         </wsHttpBinding>
  84.     </bindings>
  85.     <client>
  86.         <endpoint address="" binding="wsHttpBinding"
  87.             bindingConfiguration="WSHttpBinding_IService" contract="UpdateDatebaseService.IService"
  88.             name="WSHttpBinding_IService">
  89.             <identity>
  90.                 <certificate encodedValue="AwAAAAEAAAAUAAAAUPh/fe6CAezWVPxG5tHLT0gcSOUgAAAAAQAAAMQCAAAwggLAMIIBqKADAgECAhAbQdtkdHjEl0ZM/BK9f5DnMA0GCSqGSIb3DQEBBQUAMBwxGjAYBgNVBAMTEVNlcnZlckNlcnRpZmljYXRlMB4XDTE1MTIwMTIxMDAwMFoXDTI1MTIwODIxMDAwMFowHDEaMBgGA1UEAxMRU2VydmVyQ2VydGlmaWNhdGUwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCiwe3qcGW/JFU1HOcqRfnrKTaASKgM05A2s+o1iubgruaQ9pqmBXVeN5H0N0wGtQiEY2waVR62l4F9WeDdmj5hx+SXyE3qq0vw+lFnJBsW9A16YGTijlRgbH/mjwQUOLrTtbwGoDIPu82RBn//B6tFGtGt6+D4NRTM+J1a0bpTAr79iUeOJSn6+vCsDz7KvwXBhPSbz/nQ1Y9ccf4+uS2IkWO1lm03qlVNg3rFdgZV8g80TjObc4h88H/xTSLMse4MEvxi5OPHAxDRe3feycnfjC8oTFn/sUmhJ8PrBwUFz3DhURKl+aZ12yN0dQJdz/Ioe1mWcCv8bH2yq+EdA6mpAgMBAAEwDQYJKoZIhvcNAQEFBQADggEBAE6rd1DznozwBgZ5fivrFX2vsYCgDchQ/IP7tIYu/Avl89seNyW0hTMcUcaKSmcU2N+AXxOV0JBmaeg5Xr6D/mby98PxKXING3fViLfuUqfk14u5Pb24bj8yLLKy5HZ0E5/6KTMBAfqOw/j1rVDjXmq47cXPWf8FMejXjW5NwpBMbSj65NxcJ/qNFMR5yHNyPChKwt2UyG5Y2Yw9Y/r7iNc30wnr0xE1T5Db2GhxeEfuBALhatGBsirQMZV1fs23lQeLZZtAtStpfAmP665BA9B3fbheYRxXIh8DCqWLdTEr3LEK70b9YmRhDlY3gIrnmIfACDwvfCWgbZbYYNTCgZY=" />
  91.             </identity>
  92.         </endpoint>
  93.     </client>
  94. </system.serviceModel>
  95.    
  96. public string Inn { get; set; }
  97.     public string Url { get; set; }
  98.     public string Password { get; set; }
  99.     public Guid BaseID { get; set; }
  100.  
  101.     private bool result;
  102.  
  103.     public void SearchUpdate(SplashScreenManager manager) {
  104.         if (!CheckConnection()) {
  105.             if (manager.IsSplashFormVisible) manager.CloseWaitForm();
  106.             XtraMessageBox.Show("Поиск обновлений невозможен, т.к. отсутствует подключение к интернету.", "Ошибка сервиса обновлений", MessageBoxButtons.OK, MessageBoxIcon.Information);
  107.             return;
  108.         }
  109.  
  110.         var factory = WcfConnection();
  111.         IService client = factory.CreateChannel();
  112.         try {
  113.             var updates = client.GetUpdates(BaseID);
  114.             if (updates.Count() > 0) {
  115.                 int i = 1;
  116.                 foreach (var item in updates.OrderBy(x => x.Key)) {
  117.                     manager.SetWaitFormDescription(string.Format("Установка обновлений {0}/{1}", i, updates.Count));
  118.                     string errorMessage = UpdateResult(item.Value, manager);
  119.                     client.SetUpdateResult(BaseID, item.Key, result, errorMessage);
  120.                     if (!result) {
  121.                         if (manager.IsSplashFormVisible) manager.CloseWaitForm();
  122.                         factory.Close();
  123.                         return;
  124.                     }
  125.                     i++;
  126.                 }
  127.             }
  128.             if (manager.IsSplashFormVisible) manager.CloseWaitForm();
  129.             factory.Close();
  130.         } catch (TimeoutException ex) {
  131.             if (manager.IsSplashFormVisible) manager.CloseWaitForm();
  132.             XtraMessageBox.Show((ex.InnerException != null ? ex.InnerException.Message : ex.Message), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
  133.             factory.Abort();
  134.         } catch (CommunicationException ex) {
  135.             if (manager.IsSplashFormVisible) manager.CloseWaitForm();
  136.             XtraMessageBox.Show(ex.InnerException != null ? ex.InnerException.Message : ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
  137.             factory.Abort();
  138.         }
  139.     }
  140.  
  141.     private ChannelFactory<IService> WcfConnection() {
  142.         WSHttpBinding binding = new WSHttpBinding();
  143.         binding.ReaderQuotas.MaxStringContentLength = 10000000;
  144.         binding.MaxReceivedMessageSize = 10000000;
  145.         binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
  146.         //binding.ReceiveTimeout = new TimeSpan(1, 0, 0);
  147.         //binding.ReliableSession.InactivityTimeout = new TimeSpan(1, 0, 0);
  148.  
  149.         EndpointIdentity ei = EndpointIdentity.CreateDnsIdentity("ServerCertificate");
  150.  
  151.  
  152.         EndpointAddress ea = new EndpointAddress(new Uri(Url), ei);
  153.  
  154.         ChannelFactory<IService> factory = new ChannelFactory<IService>(binding, ea);
  155.         factory.Credentials.UserName.UserName = Inn;
  156.         factory.Credentials.UserName.Password = Password;
  157.         factory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
  158.  
  159.         return factory;
  160.     }        
  161.     private string UpdateResult(string update, SplashScreenManager manager) {
  162.         SqlConnection connection = new SqlConnection(Client.ConnectionString);
  163.         Server server = new Server(new ServerConnection(connection));
  164.         try {
  165.             server.ConnectionContext.BeginTransaction();
  166.             server.ConnectionContext.ExecuteNonQuery(update);
  167.             server.ConnectionContext.CommitTransaction();
  168.             result = true;
  169.             return null;
  170.         } catch (Exception ex) {
  171.             server.ConnectionContext.RollBackTransaction();
  172.             result = false;
  173.             if (manager.IsSplashFormVisible) manager.CloseWaitForm();
  174.             XtraMessageBox.Show("Ошибка обновления данных. Все установленные обновления отменены.nОбратитесь в техподдержку", "Ошибка сервиса обновлений", MessageBoxButtons.OK, MessageBoxIcon.Error);
  175.             return (ex.InnerException != null ? ex.InnerException.Message : ex.Message);
  176.         }
  177.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top