• WCF实现客户端自动更新


    IServiceUpdate

     1 using System.IO;
     2 using System.ServiceModel;
     3 using System.ServiceModel.Web;
     4 
     5 namespace ServiceUpdater
     6 {
     7     // 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码和配置文件中的接口名“IServiceUpdate”。
     8     [ServiceContract]
     9     public interface IServiceUpdate
    10     {
    11         [OperationContract, WebInvoke(Method = "GET", UriTemplate = "SyncTool/{fileName}")]
    12         Stream SyncTool(string fileName);
    13 
    14         [OperationContract, WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json)]
    15         Stream DownloadFile(PostData postData);
    16     }
    17 
    18     public class PostData
    19     {
    20         public string CustomerCode { get; set; }
    21         public string Token { get; set; }
    22         public string Mac { get; set; }
    23         public string Filename { get; set; }
    24     }
    25 }

    ServiceUpdate

     1 using System;
     2 using System.Collections.Generic;
     3 using System.IO;
     4 using System.Linq;
     5 using System.Runtime.Serialization;
     6 using System.ServiceModel;
     7 using System.ServiceModel.Web;
     8 using System.Text;
     9 using log4net;
    10 
    11 namespace ServiceUpdater
    12 {
    13     // 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码和配置文件中的类名“ServiceUpdate”。
    14     public class ServiceUpdate : IServiceUpdate
    15     {
    16         public Stream SyncTool(string fileName)
    17         {
    18             string basePath = AppDomain.CurrentDomain.BaseDirectory + "Release\SyncTool\";
    19             string downloadFileName = basePath + fileName;
    20             if (File.Exists(downloadFileName) && WebOperationContext.Current != null)
    21             {
    22                 var fileExt = Path.GetExtension(downloadFileName);
    23                 switch (fileExt.ToLower())
    24                 {
    25                     case ".js":
    26                         WebOperationContext.Current.OutgoingResponse.ContentType = "text/javascript";
    27                         break;
    28                     case ".css":
    29                         WebOperationContext.Current.OutgoingResponse.ContentType = "text/css";
    30                         break;
    31                     case ".html":
    32                     case ".htm":
    33                         WebOperationContext.Current.OutgoingResponse.ContentType = "text/html";
    34                         break;
    35                 }
    36                 LogManager.GetLogger(this.GetType()).Info("File downloaded = " + downloadFileName);
    37                 return File.OpenRead(downloadFileName);
    38             }
    39             return null;
    40         }
    41 
    42         public Stream DownloadFile(PostData postData)
    43         {
    44             if (postData != null
    45                 && !string.IsNullOrEmpty(postData.CustomerCode)
    46                 && !string.IsNullOrEmpty(postData.Token)
    47                 && !string.IsNullOrEmpty(postData.Mac)
    48                 && !string.IsNullOrEmpty(postData.Filename))
    49             {
    50                 string downFilename = AppDomain.CurrentDomain.BaseDirectory + "Release\" + postData.CustomerCode + "\" + postData.Filename;
    51                 if (File.Exists(downFilename))
    52                 {
    53                     LogManager.GetLogger(this.GetType()).Info(
    54                         "File download = " + downFilename
    55                         + Environment.NewLine + "CustomerCode = " + postData.CustomerCode
    56                         + Environment.NewLine + "Token = " + postData.Token
    57                         + Environment.NewLine + "Mac = " + postData.Mac);
    58                     return File.OpenRead(downFilename);
    59                 }
    60             }
    61             return null;
    62         }
    63     }
    64 }
  • 相关阅读:
    Unity WebGL MoonSharp崩溃问题
    UISprite(NGUI)扩展 图片镂空
    自动化交易机器人Beta猪
    如何成为一个真正在路上的Linuxer
    课堂里学不到的C与C++那些事(一)
    Android ART运行时与Dalvik虚拟机
    用Dockerfile构建docker image
    论docker中 CMD 与 ENTRYPOINT 的区别
    sshfs远程文件系统挂载
    docker镜像与容器存储结构分析
  • 原文地址:https://www.cnblogs.com/jonney-wang/p/5724184.html
Copyright © 2020-2023  润新知