Browse Source

改变protobuf类型, 数据库实体类的字段类型

mengxiangge 4 years ago
parent
commit
e2e9c99916

+ 1 - 1
Dispatcher/Client/ClientApp.cs

@@ -77,7 +77,7 @@ namespace Client
                 try
                 {
                     Thread.Sleep(30000);
-                    var retMsg = MessageUtil.generateMessage(Command.Useless.ToString(), 0, "{}");
+                    var retMsg = MessageUtil.generateMessageStr(Command.Useless.ToString(), "", "{}");
                     simpleHandler.WriteMessage(retMsg);
                 }
                 catch (Exception e)

+ 6 - 5
Dispatcher/Client/MessageHandler.cs

@@ -1,5 +1,5 @@
 using NettyClient;
-using NettyClient.proto;
+using Message = Google.Protobuf.WellKnownTypes.Message;
 using Newtonsoft.Json;
 using System;
 using System.Collections.Generic;
@@ -7,6 +7,7 @@ using System.Linq;
 using System.Text;
 using System.Threading;
 using System.Threading.Tasks;
+using NettyClient.proto;
 
 namespace Client
 {
@@ -48,13 +49,13 @@ namespace Client
                             bool isSuccess = taskHandler.addOneTask(message.TaskId, message.Content);
                             if (isSuccess)
                             {
-                                retMsg = MessageUtil.generateMessage(Command.AcceptTask.ToString(), message.TaskId, "");
+                                retMsg = MessageUtil.generateMessageStr(Command.AcceptTask.ToString(), message.TaskId, "");
                                 simpleHandler.WriteMessage(retMsg);
                             }
                         }
                         else {
                             // 3. 如果拒绝, 直接返回拒绝消息
-                            retMsg = MessageUtil.generateMessage(Command.RefuseTask.ToString(), message.TaskId, "");
+                            retMsg = MessageUtil.generateMessageStr(Command.RefuseTask.ToString(), message.TaskId, "");
                             simpleHandler.WriteMessage(retMsg);
                         }
                         break;
@@ -63,7 +64,7 @@ namespace Client
                         info.Ipv4 = ClientInfoUtil.GetClientLocalIPv4Address();
                         info.MacAddr = ClientInfoUtil.GetMacAddress();
                         info.Name = ClientInfoUtil.GetUserName();
-                        retMsg = MessageUtil.generateMessage(Command.ClientInfo.ToString(), 0, JsonConvert.SerializeObject(info, Formatting.None));
+                        retMsg = MessageUtil.generateMessageStr(Command.ClientInfo.ToString(), "", JsonConvert.SerializeObject(info, Formatting.None));
                         simpleHandler.WriteMessage(retMsg);
                         break;
                     default:
@@ -72,7 +73,7 @@ namespace Client
             }
         }
 
-        private bool checkIsAcceptTask(int taskId)
+        private bool checkIsAcceptTask(string taskId)
         {
             //一. isPauseTask == true的时候拒绝任务, 二. 如果已存在该任务, 则拒绝, 三. 如果当前任务数达到maxTaskCount, 拒绝
             if (isPauseTask)

+ 9 - 9
Dispatcher/Client/TaskHandler.cs

@@ -29,14 +29,14 @@ namespace Client
                         bool isAllDownloaded = true;
                         // 看当前任务依赖的文件下载状况
                         foreach (DownloadTaskModel downloadTaskModel in task.DownloadTaskModelList) {
-                            DownloadTask download = taskDownloadManager.getDownloadTaskByDownloadTaskId(downloadTaskModel.Tid);
+                            DownloadTask download = taskDownloadManager.getDownloadTaskByDownloadTaskId(downloadTaskModel.Task_id);
                             if (download == null) // 如果还未加入下载队列
                             {
                                 // 开始下载
                                 if (downloadTaskModel.Local_dir == null) {
-                                    downloadTaskModel.Local_dir = defaultFileDir + downloadTaskModel.Tid + ".rvt";
+                                    downloadTaskModel.Local_dir = defaultFileDir + downloadTaskModel.Task_id + ".rvt";
                                 } 
-                                download = taskDownloadManager.enqueueTask(task.Id, downloadTaskModel.Tid, downloadTaskModel.Task_url,
+                                download = taskDownloadManager.enqueueTask(task.Id, downloadTaskModel.Task_url,
                                     downloadTaskModel.Local_dir, downloadTaskModel.Task_md5, downloadTaskModel.Downloaded_bytes);
                                 taskDownloadManager.runTask(download);
                                 isAllDownloaded &= false;
@@ -66,7 +66,7 @@ namespace Client
                             task.Task_status = -1;
                             taskService.UpdateTask(task);
                             taskModels.RemoveAt(i);
-                            simpleHandler.WriteMessage(MessageUtil.generateMessage(Command.DownloadError.ToString(), task.Id, ""));
+                            simpleHandler.WriteMessage(MessageUtil.generateMessageStr(Command.DownloadError.ToString(), task.Id, ""));
                             continue;
                         }
                         // 如果该任务的所有下载文件均已完成, 开始执行Revit命令
@@ -80,7 +80,7 @@ namespace Client
                                 try
                                 {
                                     string resultJson = revitCommandExcutor.ExecuteCmd(task.Task_cmd, task.Task_param, fileSet);
-                                    simpleHandler.WriteMessage(MessageUtil.generateMessage(Command.TaskSuccess.ToString(), task.Id, resultJson));
+                                    simpleHandler.WriteMessage(MessageUtil.generateMessageStr(Command.TaskSuccess.ToString(), task.Id, resultJson));
                                     task.Task_status = 1;
                                     task.Task_result_json = resultJson;
                                     taskService.UpdateTask(task);
@@ -100,7 +100,7 @@ namespace Client
                             task.Task_status = -2;
                             taskService.UpdateTask(task);
                             taskModels.RemoveAt(i);
-                            simpleHandler.WriteMessage(MessageUtil.generateMessage(Command.CommandError.ToString(), task.Id, ""));
+                            simpleHandler.WriteMessage(MessageUtil.generateMessageStr(Command.CommandError.ToString(), task.Id, ""));
                             continue;
                         }
                     }
@@ -154,7 +154,7 @@ namespace Client
             IList<TaskModel> tasks = taskService.GetTasksByStatus(0); // 任务状态 0 未执行完的任务, 1 执行完成  -1 下载出错  -2 revit命令执行异常
             taskModels = tasks;
         }
-        internal bool addOneTask(int taskId, string msgContent) {
+        internal bool addOneTask(string taskId, string msgContent) {
             try
             {
                 TaskModel taskModel = JsonConvert.DeserializeObject<TaskModel>(msgContent);
@@ -162,7 +162,7 @@ namespace Client
                 TaskModel task = taskService.GetTasksByTaskId(taskId)[0];
                 taskModels.Add(task);
                 foreach (DownloadTaskModel download in taskModel.DownloadTaskModelList) {
-                    download.Local_dir = defaultFileDir + download.Tid + ".rvt";
+                    download.Local_dir = defaultFileDir + download.Task_id + ".rvt";
                     taskService.UpdateDownload(download);
                 }
                 return true;
@@ -173,7 +173,7 @@ namespace Client
             }
         }
 
-        internal bool isContainTask(int taskId)
+        internal bool isContainTask(string taskId)
         {
             try
             {

+ 4 - 5
Dispatcher/HttpDownload/DownloadTask.cs

@@ -9,8 +9,8 @@ namespace HttpDownload
 {
     public class DownloadTask
     {
-        public int BelongingId { get; set; }
-        public int DownloadTaskId { get; set; }
+        public string BelongingId { get; set; }     // 任务id
+        //public int DownloadTaskId { get; set; }
         public string FileUrl { get; }
         public string FileDir { get; }
         public long Offset { get; } // 开始下载的位置
@@ -41,10 +41,9 @@ namespace HttpDownload
 
         }
 
-        public DownloadTask(int belongingId, int downTaskId, string fileUrl, string fileDir, string expectedMD5, long offset = 0L)
+        public DownloadTask(string taskId, string fileUrl, string fileDir, string expectedMD5, long offset = 0L)
         {
-            this.BelongingId = belongingId;
-            this.DownloadTaskId = downTaskId;
+            this.BelongingId = taskId;
             this.FileUrl = fileUrl;
             this.FileDir = fileDir;
             this.Offset = offset;

+ 5 - 5
Dispatcher/HttpDownload/TaskDownloadManager.cs

@@ -44,16 +44,16 @@ namespace HttpDownload
             allTasks.Add(task);
             return task;
         }
-        public DownloadTask enqueueTask(int belongingId, int downTaskId, string fileUrl, string fileDir, string expectedMD5, long offset = 0L)
+        public DownloadTask enqueueTask(string taskId, string fileUrl, string fileDir, string expectedMD5, long offset = 0L)
         {
-            DownloadTask task = new DownloadTask(belongingId, downTaskId, fileUrl, fileDir, expectedMD5, offset);
+            DownloadTask task = new DownloadTask(taskId, fileUrl, fileDir, expectedMD5, offset);
             allTasks.Add(task);
             return task;
         }
 
-        public DownloadTask getDownloadTaskByDownloadTaskId(int downloadTaskId) {
+        public DownloadTask getDownloadTaskByDownloadTaskId(string taskId) {
             foreach (DownloadTask down in allTasks) {
-                if (downloadTaskId == down.DownloadTaskId) {
+                if (taskId == down.BelongingId) {
                     return down;
                 }
             }
@@ -89,7 +89,7 @@ namespace HttpDownload
         public Hashtable getAllTasksMap() {
             Hashtable table = new Hashtable();
             foreach (DownloadTask down in allTasks) {
-                int belongingid = down.BelongingId;
+                string belongingid = down.BelongingId;
                 if (table.ContainsKey(belongingid))
                 {
                     ArrayList arr = (ArrayList)table[belongingid];

+ 1 - 0
Dispatcher/NettyClient/NettyClient.csproj

@@ -119,6 +119,7 @@
   <ItemGroup>
     <Compile Include="ClientWrapper.cs" />
     <Compile Include="proto\MessageProto.cs" />
+    <Compile Include="proto\MessageProtoStr.cs" />
     <Compile Include="proto\MessageUtil.cs" />
     <Compile Include="TaskNettyClient.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />

+ 1 - 1
Dispatcher/NettyClient/SimpleMessageHandler.cs

@@ -2,7 +2,7 @@
 using System;
 using System.Collections.Concurrent;
 using System.Windows.Forms;
-using Message = NettyClient.proto.Message;
+using Message = Google.Protobuf.WellKnownTypes.Message;
 
 namespace NettyClient
 {

+ 230 - 0
Dispatcher/NettyClient/proto/MessageProtoStr.cs

@@ -0,0 +1,230 @@
+// <auto-generated>
+//     Generated by the protocol buffer compiler.  DO NOT EDIT!
+//     source: MessageProto.proto
+// </auto-generated>
+#pragma warning disable 1591, 0612, 3021
+#region Designer generated code
+
+using pb = global::Google.Protobuf;
+using pbc = global::Google.Protobuf.Collections;
+using pbr = global::Google.Protobuf.Reflection;
+using scg = global::System.Collections.Generic;
+namespace Google.Protobuf.WellKnownTypes {
+
+  /// <summary>Holder for reflection information generated from MessageProto.proto</summary>
+  public static partial class MessageProtoReflection {
+
+    #region Descriptor
+    /// <summary>File descriptor for MessageProto.proto</summary>
+    public static pbr::FileDescriptor Descriptor {
+      get { return descriptor; }
+    }
+    private static pbr::FileDescriptor descriptor;
+
+    static MessageProtoReflection() {
+      byte[] descriptorData = global::System.Convert.FromBase64String(
+          string.Concat(
+            "ChJNZXNzYWdlUHJvdG8ucHJvdG8SEmNuLnNhZ2FjbG91ZC5wcm90byI3CgdN",
+            "ZXNzYWdlEgsKA2NtZBgBIAEoCRIOCgZ0YXNrSWQYAiABKAkSDwoHY29udGVu",
+            "dBgDIAEoCUI0Qg9NZXNzYWdlUHJvdG9TdHJIAaoCHkdvb2dsZS5Qcm90b2J1",
+            "Zi5XZWxsS25vd25UeXBlc2IGcHJvdG8z"));
+      descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
+          new pbr::FileDescriptor[] { },
+          new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] {
+            new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.WellKnownTypes.Message), global::Google.Protobuf.WellKnownTypes.Message.Parser, new[]{ "Cmd", "TaskId", "Content" }, null, null, null, null)
+          }));
+    }
+    #endregion
+
+  }
+  #region Messages
+  public sealed partial class Message : pb::IMessage<Message> {
+    private static readonly pb::MessageParser<Message> _parser = new pb::MessageParser<Message>(() => new Message());
+    private pb::UnknownFieldSet _unknownFields;
+    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+    public static pb::MessageParser<Message> Parser { get { return _parser; } }
+
+    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+    public static pbr::MessageDescriptor Descriptor {
+      get { return global::Google.Protobuf.WellKnownTypes.MessageProtoReflection.Descriptor.MessageTypes[0]; }
+    }
+
+    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+    pbr::MessageDescriptor pb::IMessage.Descriptor {
+      get { return Descriptor; }
+    }
+
+    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+    public Message() {
+      OnConstruction();
+    }
+
+    partial void OnConstruction();
+
+    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+    public Message(Message other) : this() {
+      cmd_ = other.cmd_;
+      taskId_ = other.taskId_;
+      content_ = other.content_;
+      _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
+    }
+
+    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+    public Message Clone() {
+      return new Message(this);
+    }
+
+    /// <summary>Field number for the "cmd" field.</summary>
+    public const int CmdFieldNumber = 1;
+    private string cmd_ = "";
+    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+    public string Cmd {
+      get { return cmd_; }
+      set {
+        cmd_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+      }
+    }
+
+    /// <summary>Field number for the "taskId" field.</summary>
+    public const int TaskIdFieldNumber = 2;
+    private string taskId_ = "";
+    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+    public string TaskId {
+      get { return taskId_; }
+      set {
+        taskId_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+      }
+    }
+
+    /// <summary>Field number for the "content" field.</summary>
+    public const int ContentFieldNumber = 3;
+    private string content_ = "";
+    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+    public string Content {
+      get { return content_; }
+      set {
+        content_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+      }
+    }
+
+    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+    public override bool Equals(object other) {
+      return Equals(other as Message);
+    }
+
+    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+    public bool Equals(Message other) {
+      if (ReferenceEquals(other, null)) {
+        return false;
+      }
+      if (ReferenceEquals(other, this)) {
+        return true;
+      }
+      if (Cmd != other.Cmd) return false;
+      if (TaskId != other.TaskId) return false;
+      if (Content != other.Content) return false;
+      return Equals(_unknownFields, other._unknownFields);
+    }
+
+    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+    public override int GetHashCode() {
+      int hash = 1;
+      if (Cmd.Length != 0) hash ^= Cmd.GetHashCode();
+      if (TaskId.Length != 0) hash ^= TaskId.GetHashCode();
+      if (Content.Length != 0) hash ^= Content.GetHashCode();
+      if (_unknownFields != null) {
+        hash ^= _unknownFields.GetHashCode();
+      }
+      return hash;
+    }
+
+    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+    public override string ToString() {
+      return pb::JsonFormatter.ToDiagnosticString(this);
+    }
+
+    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+    public void WriteTo(pb::CodedOutputStream output) {
+      if (Cmd.Length != 0) {
+        output.WriteRawTag(10);
+        output.WriteString(Cmd);
+      }
+      if (TaskId.Length != 0) {
+        output.WriteRawTag(18);
+        output.WriteString(TaskId);
+      }
+      if (Content.Length != 0) {
+        output.WriteRawTag(26);
+        output.WriteString(Content);
+      }
+      if (_unknownFields != null) {
+        _unknownFields.WriteTo(output);
+      }
+    }
+
+    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+    public int CalculateSize() {
+      int size = 0;
+      if (Cmd.Length != 0) {
+        size += 1 + pb::CodedOutputStream.ComputeStringSize(Cmd);
+      }
+      if (TaskId.Length != 0) {
+        size += 1 + pb::CodedOutputStream.ComputeStringSize(TaskId);
+      }
+      if (Content.Length != 0) {
+        size += 1 + pb::CodedOutputStream.ComputeStringSize(Content);
+      }
+      if (_unknownFields != null) {
+        size += _unknownFields.CalculateSize();
+      }
+      return size;
+    }
+
+    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+    public void MergeFrom(Message other) {
+      if (other == null) {
+        return;
+      }
+      if (other.Cmd.Length != 0) {
+        Cmd = other.Cmd;
+      }
+      if (other.TaskId.Length != 0) {
+        TaskId = other.TaskId;
+      }
+      if (other.Content.Length != 0) {
+        Content = other.Content;
+      }
+      _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
+    }
+
+    [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+    public void MergeFrom(pb::CodedInputStream input) {
+      uint tag;
+      while ((tag = input.ReadTag()) != 0) {
+        switch(tag) {
+          default:
+            _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+            break;
+          case 10: {
+            Cmd = input.ReadString();
+            break;
+          }
+          case 18: {
+            TaskId = input.ReadString();
+            break;
+          }
+          case 26: {
+            Content = input.ReadString();
+            break;
+          }
+        }
+      }
+    }
+
+  }
+
+  #endregion
+
+}
+
+#endregion Designer generated code

+ 9 - 0
Dispatcher/NettyClient/proto/MessageUtil.cs

@@ -15,5 +15,14 @@ namespace NettyClient.proto
             msg.Content = content;
             return msg;
         }
+
+        public static Google.Protobuf.WellKnownTypes.Message generateMessageStr(string cmd, string taskId, string content)
+        {
+            Google.Protobuf.WellKnownTypes.Message msg = new Google.Protobuf.WellKnownTypes.Message();
+            msg.Cmd = cmd;
+            msg.TaskId = taskId;
+            msg.Content = content;
+            return msg;
+        }
     }
 }

+ 3 - 3
Dispatcher/TaskDatabase/Model/DownloadTaskModel.cs

@@ -5,9 +5,9 @@ namespace TaskDatabase.Model
 
     public class DownloadTaskModel
     {
-        public virtual int Tid { get; set; }
-        [JsonProperty(PropertyName = "id")]
-        public virtual int Id { get; set; }
+        //public virtual int Tid { get; set; }
+        //[JsonProperty(PropertyName = "id")]
+        //public virtual int Id { get; set; }
         [JsonProperty(PropertyName = "taskId")]
         public virtual string Task_id { get; set; }
         [JsonProperty(PropertyName = "httpUrl")]

+ 2 - 2
Dispatcher/TaskDatabase/Model/TaskModel.cs

@@ -9,9 +9,9 @@ namespace TaskDatabase.Model
 {
     public class TaskModel
     {
-        public virtual int Tid { get; set; }
+        //public virtual int Tid { get; set; }
         [JsonProperty(PropertyName = "id")]
-        public virtual int Id { get; set; }
+        public virtual string Id { get; set; }
         [JsonProperty(PropertyName = "name")]
         public virtual string Task_name { get; set; }
         [JsonProperty(PropertyName = "cmd")]

+ 4 - 4
Dispatcher/TaskDatabase/TaskService.cs

@@ -111,7 +111,7 @@ namespace TaskDatabase
             return null;
         }
 
-        public TaskModel GetTasksByTid(int tid)
+        public TaskModel GetTasksByTid(string taskId)
         {
             ITransaction transaction = null;
             try
@@ -121,7 +121,7 @@ namespace TaskDatabase
                     using (transaction = session.BeginTransaction())
                     {
                         var queryResult = session.CreateCriteria(typeof(TaskModel))
-                                .Add(Restrictions.Eq("Tid", tid))
+                                .Add(Restrictions.Eq("Id", taskId))
                                 .UniqueResult<TaskModel>();
                         return queryResult;
                     }
@@ -135,7 +135,7 @@ namespace TaskDatabase
             return null;
         }
 
-        public IList<TaskModel> GetTasksByTaskId(int taskId)
+        public IList<TaskModel> GetTasksByTaskId(string taskId)
         {
             ITransaction transaction = null;
             try
@@ -158,7 +158,7 @@ namespace TaskDatabase
             return null;
         }
 
-        public bool isContainsTask(int taskId)
+        public bool isContainsTask(string taskId)
         {
             ITransaction transaction = null;
             try