aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-10-29 15:08:39 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-10-29 15:08:39 +0200
commit5bf030a1137f09e9d9898c8a837e49a1af0468f9 (patch)
tree6535fef5affffe2b28bd87472c18383867510560 /Software/Visual_Studio
parent4973c8ff53c8758852f707af5cc7f4a6a82151e0 (diff)
downloadTango-5bf030a1137f09e9d9898c8a837e49a1af0468f9.tar.gz
Tango-5bf030a1137f09e9d9898c8a837e49a1af0468f9.zip
Improved some aspects of machine service and machine update.
Diffstat (limited to 'Software/Visual_Studio')
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs29
-rw-r--r--Software/Visual_Studio/Tango.Logging/ExceptionLogItem.cs25
-rw-r--r--Software/Visual_Studio/Tango.Logging/LogManager.cs2
-rw-r--r--Software/Visual_Studio/Tango.PMR/IO/GetStorageInfoRequest.cs65
-rw-r--r--Software/Visual_Studio/Tango.PMR/IO/GetStorageInfoResponse.cs63
-rw-r--r--Software/Visual_Studio/Tango.PMR/Synchronization/HttpProtoException.cs188
-rw-r--r--Software/Visual_Studio/Tango.PMR/Tango.PMR.csproj3
-rw-r--r--Software/Visual_Studio/Tango.Transport/Tango.Transport.csproj3
-rw-r--r--Software/Visual_Studio/Tango.Transport/Web/ProtoWebClient.cs9
-rw-r--r--Software/Visual_Studio/Web/Tango.MachineService/App_Start/WebApiConfig.cs7
-rw-r--r--Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs30
-rw-r--r--Software/Visual_Studio/Web/Tango.MachineService/JsonNetFormatter.cs89
-rw-r--r--Software/Visual_Studio/Web/Tango.MachineService/ProtoBufFormatter.cs26
-rw-r--r--Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj4
-rw-r--r--Software/Visual_Studio/Web/Tango.MachineService/WebApiException.cs18
15 files changed, 480 insertions, 81 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs
index 252491669..a3012ffd8 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs
@@ -113,9 +113,16 @@ namespace Tango.PPC.Common.MachineSetup
MachineSetupResponse setup_response = null;
- using (var http = new ProtoWebClient())
+ try
{
- setup_response = http.Post<MachineSetupRequest, MachineSetupResponse>(machineServiceAddress + "/api/Synchronization/MachineSetup", request).Result;
+ using (var http = new ProtoWebClient())
+ {
+ setup_response = http.Post<MachineSetupRequest, MachineSetupResponse>(machineServiceAddress + "/api/Synchronization/MachineSetup", request).Result;
+ }
+ }
+ catch (Exception ex)
+ {
+ throw LogManager.Log(ex, $"An error occurred while trying to contact machine service: {ex.Message}");
}
LogManager.Log($"Machine setup response received: {Environment.NewLine}{setup_response.ToJsonString()}");
@@ -178,14 +185,24 @@ namespace Tango.PPC.Common.MachineSetup
LogManager.Log($"Synchronizing database '{remote_address}\\{db_name}' => '{localAddress}\\{db_name}'...");
- LogManager.Log("Initializing database manager...");
- DbManager db = DbManager.FromAddressAndName(localAddress, db_name);
+ LogManager.Log($"Connecting to local database at {localAddress}...");
+ DbManager db = DbManager.FromAddress(localAddress);
- LogManager.Log("Checking Tango database exists on the local machine...");
+ LogManager.Log($"Ensuring {db_name} database exists on the local machine...");
if (!db.Exists(db_name))
{
- throw new InvalidProgramException("Database tango does not exists.");
+ LogManager.Log("Database does not exist. Creating new database...");
+ db.Create(db_name);
}
+ else
+ {
+ LogManager.Log("Database exists.");
+ }
+
+ db.Dispose();
+
+ LogManager.Log("Initializing database manager...");
+ db = DbManager.FromAddressAndName(localAddress, db_name);
LogManager.Log("Clearing database...");
db.ClearDb();
diff --git a/Software/Visual_Studio/Tango.Logging/ExceptionLogItem.cs b/Software/Visual_Studio/Tango.Logging/ExceptionLogItem.cs
index de8485249..d2a1a352d 100644
--- a/Software/Visual_Studio/Tango.Logging/ExceptionLogItem.cs
+++ b/Software/Visual_Studio/Tango.Logging/ExceptionLogItem.cs
@@ -29,7 +29,30 @@ namespace Tango.Logging
{
get
{
- return Exception.Message;
+ if (Exception is AggregateException)
+ {
+ try
+ {
+ String message = String.Empty;
+
+ if (Description != null)
+ {
+ message += Description + Environment.NewLine;
+ }
+
+ message += String.Join(Environment.NewLine, (Exception as AggregateException).InnerExceptions.Select(x => x.Message));
+
+ return message;
+ }
+ catch
+ {
+ return Exception.Message;
+ }
+ }
+ else
+ {
+ return Exception.Message;
+ }
}
set { }
}
diff --git a/Software/Visual_Studio/Tango.Logging/LogManager.cs b/Software/Visual_Studio/Tango.Logging/LogManager.cs
index b67128a8d..04c66a71f 100644
--- a/Software/Visual_Studio/Tango.Logging/LogManager.cs
+++ b/Software/Visual_Studio/Tango.Logging/LogManager.cs
@@ -123,7 +123,7 @@ namespace Tango.Logging
log.TimeStamp = DateTime.Now;
log.Exception = e;
log.Category = category;
- log.Description = description != null ? description : e.ToString();
+ log.Description = description;
AppendLog(log);
diff --git a/Software/Visual_Studio/Tango.PMR/IO/GetStorageInfoRequest.cs b/Software/Visual_Studio/Tango.PMR/IO/GetStorageInfoRequest.cs
index ae06664ae..e77104d56 100644
--- a/Software/Visual_Studio/Tango.PMR/IO/GetStorageInfoRequest.cs
+++ b/Software/Visual_Studio/Tango.PMR/IO/GetStorageInfoRequest.cs
@@ -22,14 +22,13 @@ namespace Tango.PMR.IO {
static GetStorageInfoRequestReflection() {
byte[] descriptorData = global::System.Convert.FromBase64String(
string.Concat(
- "ChtHZXRTdG9yYWdlSW5mb1JlcXVlc3QucHJvdG8SDFRhbmdvLlBNUi5JTyI8",
- "ChVHZXRTdG9yYWdlSW5mb1JlcXVlc3QSEAoIQ2FwYWNpdHkYASABKAUSEQoJ",
- "RnJlZVNwYWNlGAIgASgFQhgKFmNvbS50d2luZS50YW5nby5wbXIuaW9iBnBy",
- "b3RvMw=="));
+ "ChtHZXRTdG9yYWdlSW5mb1JlcXVlc3QucHJvdG8SDFRhbmdvLlBNUi5JTyIX",
+ "ChVHZXRTdG9yYWdlSW5mb1JlcXVlc3RCGAoWY29tLnR3aW5lLnRhbmdvLnBt",
+ "ci5pb2IGcHJvdG8z"));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { },
new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] {
- new pbr::GeneratedClrTypeInfo(typeof(global::Tango.PMR.IO.GetStorageInfoRequest), global::Tango.PMR.IO.GetStorageInfoRequest.Parser, new[]{ "Capacity", "FreeSpace" }, null, null, null)
+ new pbr::GeneratedClrTypeInfo(typeof(global::Tango.PMR.IO.GetStorageInfoRequest), global::Tango.PMR.IO.GetStorageInfoRequest.Parser, null, null, null, null)
}));
}
#endregion
@@ -60,8 +59,6 @@ namespace Tango.PMR.IO {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public GetStorageInfoRequest(GetStorageInfoRequest other) : this() {
- capacity_ = other.capacity_;
- freeSpace_ = other.freeSpace_;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
@@ -69,28 +66,6 @@ namespace Tango.PMR.IO {
return new GetStorageInfoRequest(this);
}
- /// <summary>Field number for the "Capacity" field.</summary>
- public const int CapacityFieldNumber = 1;
- private int capacity_;
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
- public int Capacity {
- get { return capacity_; }
- set {
- capacity_ = value;
- }
- }
-
- /// <summary>Field number for the "FreeSpace" field.</summary>
- public const int FreeSpaceFieldNumber = 2;
- private int freeSpace_;
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
- public int FreeSpace {
- get { return freeSpace_; }
- set {
- freeSpace_ = value;
- }
- }
-
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override bool Equals(object other) {
return Equals(other as GetStorageInfoRequest);
@@ -104,16 +79,12 @@ namespace Tango.PMR.IO {
if (ReferenceEquals(other, this)) {
return true;
}
- if (Capacity != other.Capacity) return false;
- if (FreeSpace != other.FreeSpace) return false;
return true;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override int GetHashCode() {
int hash = 1;
- if (Capacity != 0) hash ^= Capacity.GetHashCode();
- if (FreeSpace != 0) hash ^= FreeSpace.GetHashCode();
return hash;
}
@@ -124,25 +95,11 @@ namespace Tango.PMR.IO {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
- if (Capacity != 0) {
- output.WriteRawTag(8);
- output.WriteInt32(Capacity);
- }
- if (FreeSpace != 0) {
- output.WriteRawTag(16);
- output.WriteInt32(FreeSpace);
- }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
- if (Capacity != 0) {
- size += 1 + pb::CodedOutputStream.ComputeInt32Size(Capacity);
- }
- if (FreeSpace != 0) {
- size += 1 + pb::CodedOutputStream.ComputeInt32Size(FreeSpace);
- }
return size;
}
@@ -151,12 +108,6 @@ namespace Tango.PMR.IO {
if (other == null) {
return;
}
- if (other.Capacity != 0) {
- Capacity = other.Capacity;
- }
- if (other.FreeSpace != 0) {
- FreeSpace = other.FreeSpace;
- }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
@@ -167,14 +118,6 @@ namespace Tango.PMR.IO {
default:
input.SkipLastField();
break;
- case 8: {
- Capacity = input.ReadInt32();
- break;
- }
- case 16: {
- FreeSpace = input.ReadInt32();
- break;
- }
}
}
}
diff --git a/Software/Visual_Studio/Tango.PMR/IO/GetStorageInfoResponse.cs b/Software/Visual_Studio/Tango.PMR/IO/GetStorageInfoResponse.cs
index 13152184d..46dc2e308 100644
--- a/Software/Visual_Studio/Tango.PMR/IO/GetStorageInfoResponse.cs
+++ b/Software/Visual_Studio/Tango.PMR/IO/GetStorageInfoResponse.cs
@@ -23,12 +23,13 @@ namespace Tango.PMR.IO {
byte[] descriptorData = global::System.Convert.FromBase64String(
string.Concat(
"ChxHZXRTdG9yYWdlSW5mb1Jlc3BvbnNlLnByb3RvEgxUYW5nby5QTVIuSU8i",
- "GAoWR2V0U3RvcmFnZUluZm9SZXNwb25zZUIYChZjb20udHdpbmUudGFuZ28u",
- "cG1yLmlvYgZwcm90bzM="));
+ "PQoWR2V0U3RvcmFnZUluZm9SZXNwb25zZRIQCghDYXBhY2l0eRgBIAEoBRIR",
+ "CglGcmVlU3BhY2UYAiABKAVCGAoWY29tLnR3aW5lLnRhbmdvLnBtci5pb2IG",
+ "cHJvdG8z"));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { },
new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] {
- new pbr::GeneratedClrTypeInfo(typeof(global::Tango.PMR.IO.GetStorageInfoResponse), global::Tango.PMR.IO.GetStorageInfoResponse.Parser, null, null, null, null)
+ new pbr::GeneratedClrTypeInfo(typeof(global::Tango.PMR.IO.GetStorageInfoResponse), global::Tango.PMR.IO.GetStorageInfoResponse.Parser, new[]{ "Capacity", "FreeSpace" }, null, null, null)
}));
}
#endregion
@@ -59,6 +60,8 @@ namespace Tango.PMR.IO {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public GetStorageInfoResponse(GetStorageInfoResponse other) : this() {
+ capacity_ = other.capacity_;
+ freeSpace_ = other.freeSpace_;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
@@ -66,6 +69,28 @@ namespace Tango.PMR.IO {
return new GetStorageInfoResponse(this);
}
+ /// <summary>Field number for the "Capacity" field.</summary>
+ public const int CapacityFieldNumber = 1;
+ private int capacity_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int Capacity {
+ get { return capacity_; }
+ set {
+ capacity_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "FreeSpace" field.</summary>
+ public const int FreeSpaceFieldNumber = 2;
+ private int freeSpace_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int FreeSpace {
+ get { return freeSpace_; }
+ set {
+ freeSpace_ = value;
+ }
+ }
+
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override bool Equals(object other) {
return Equals(other as GetStorageInfoResponse);
@@ -79,12 +104,16 @@ namespace Tango.PMR.IO {
if (ReferenceEquals(other, this)) {
return true;
}
+ if (Capacity != other.Capacity) return false;
+ if (FreeSpace != other.FreeSpace) return false;
return true;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override int GetHashCode() {
int hash = 1;
+ if (Capacity != 0) hash ^= Capacity.GetHashCode();
+ if (FreeSpace != 0) hash ^= FreeSpace.GetHashCode();
return hash;
}
@@ -95,11 +124,25 @@ namespace Tango.PMR.IO {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ if (Capacity != 0) {
+ output.WriteRawTag(8);
+ output.WriteInt32(Capacity);
+ }
+ if (FreeSpace != 0) {
+ output.WriteRawTag(16);
+ output.WriteInt32(FreeSpace);
+ }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
+ if (Capacity != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(Capacity);
+ }
+ if (FreeSpace != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(FreeSpace);
+ }
return size;
}
@@ -108,6 +151,12 @@ namespace Tango.PMR.IO {
if (other == null) {
return;
}
+ if (other.Capacity != 0) {
+ Capacity = other.Capacity;
+ }
+ if (other.FreeSpace != 0) {
+ FreeSpace = other.FreeSpace;
+ }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
@@ -118,6 +167,14 @@ namespace Tango.PMR.IO {
default:
input.SkipLastField();
break;
+ case 8: {
+ Capacity = input.ReadInt32();
+ break;
+ }
+ case 16: {
+ FreeSpace = input.ReadInt32();
+ break;
+ }
}
}
}
diff --git a/Software/Visual_Studio/Tango.PMR/Synchronization/HttpProtoException.cs b/Software/Visual_Studio/Tango.PMR/Synchronization/HttpProtoException.cs
new file mode 100644
index 000000000..431dcdf15
--- /dev/null
+++ b/Software/Visual_Studio/Tango.PMR/Synchronization/HttpProtoException.cs
@@ -0,0 +1,188 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: HttpProtoException.proto
+#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 Tango.PMR.Synchronization {
+
+ /// <summary>Holder for reflection information generated from HttpProtoException.proto</summary>
+ public static partial class HttpProtoExceptionReflection {
+
+ #region Descriptor
+ /// <summary>File descriptor for HttpProtoException.proto</summary>
+ public static pbr::FileDescriptor Descriptor {
+ get { return descriptor; }
+ }
+ private static pbr::FileDescriptor descriptor;
+
+ static HttpProtoExceptionReflection() {
+ byte[] descriptorData = global::System.Convert.FromBase64String(
+ string.Concat(
+ "ChhIdHRwUHJvdG9FeGNlcHRpb24ucHJvdG8SGVRhbmdvLlBNUi5TeW5jaHJv",
+ "bml6YXRpb24iOQoSSHR0cFByb3RvRXhjZXB0aW9uEhIKClN0YXR1c0NvZGUY",
+ "ASABKAUSDwoHTWVzc2FnZRgCIAEoCUIlCiNjb20udHdpbmUudGFuZ28ucG1y",
+ "LnN5bmNocm9uaXphdGlvbmIGcHJvdG8z"));
+ descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
+ new pbr::FileDescriptor[] { },
+ new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] {
+ new pbr::GeneratedClrTypeInfo(typeof(global::Tango.PMR.Synchronization.HttpProtoException), global::Tango.PMR.Synchronization.HttpProtoException.Parser, new[]{ "StatusCode", "Message" }, null, null, null)
+ }));
+ }
+ #endregion
+
+ }
+ #region Messages
+ public sealed partial class HttpProtoException : pb::IMessage<HttpProtoException> {
+ private static readonly pb::MessageParser<HttpProtoException> _parser = new pb::MessageParser<HttpProtoException>(() => new HttpProtoException());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<HttpProtoException> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Tango.PMR.Synchronization.HttpProtoExceptionReflection.Descriptor.MessageTypes[0]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public HttpProtoException() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public HttpProtoException(HttpProtoException other) : this() {
+ statusCode_ = other.statusCode_;
+ message_ = other.message_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public HttpProtoException Clone() {
+ return new HttpProtoException(this);
+ }
+
+ /// <summary>Field number for the "StatusCode" field.</summary>
+ public const int StatusCodeFieldNumber = 1;
+ private int statusCode_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int StatusCode {
+ get { return statusCode_; }
+ set {
+ statusCode_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "Message" field.</summary>
+ public const int MessageFieldNumber = 2;
+ private string message_ = "";
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string Message {
+ get { return message_; }
+ set {
+ message_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as HttpProtoException);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(HttpProtoException other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (StatusCode != other.StatusCode) return false;
+ if (Message != other.Message) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (StatusCode != 0) hash ^= StatusCode.GetHashCode();
+ if (Message.Length != 0) hash ^= Message.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 (StatusCode != 0) {
+ output.WriteRawTag(8);
+ output.WriteInt32(StatusCode);
+ }
+ if (Message.Length != 0) {
+ output.WriteRawTag(18);
+ output.WriteString(Message);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (StatusCode != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(StatusCode);
+ }
+ if (Message.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(Message);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(HttpProtoException other) {
+ if (other == null) {
+ return;
+ }
+ if (other.StatusCode != 0) {
+ StatusCode = other.StatusCode;
+ }
+ if (other.Message.Length != 0) {
+ Message = other.Message;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 8: {
+ StatusCode = input.ReadInt32();
+ break;
+ }
+ case 18: {
+ Message = input.ReadString();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ #endregion
+
+}
+
+#endregion Designer generated code
diff --git a/Software/Visual_Studio/Tango.PMR/Tango.PMR.csproj b/Software/Visual_Studio/Tango.PMR/Tango.PMR.csproj
index cdea3a5e8..48d204d0f 100644
--- a/Software/Visual_Studio/Tango.PMR/Tango.PMR.csproj
+++ b/Software/Visual_Studio/Tango.PMR/Tango.PMR.csproj
@@ -212,6 +212,7 @@
<Compile Include="Printing\UploadProcessParametersResponse.cs" />
<Compile Include="Printing\WindingMethod.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="Synchronization\HttpProtoException.cs" />
<Compile Include="Synchronization\UpdateDBRequest.cs" />
<Compile Include="Synchronization\UpdateDBResponse.cs" />
<Compile Include="TangoMessage.cs" />
@@ -244,7 +245,7 @@
</PropertyGroup>
<ProjectExtensions>
<VisualStudio>
- <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" />
+ <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" />
</VisualStudio>
</ProjectExtensions>
</Project> \ No newline at end of file
diff --git a/Software/Visual_Studio/Tango.Transport/Tango.Transport.csproj b/Software/Visual_Studio/Tango.Transport/Tango.Transport.csproj
index ead68f9cc..e3bf302c5 100644
--- a/Software/Visual_Studio/Tango.Transport/Tango.Transport.csproj
+++ b/Software/Visual_Studio/Tango.Transport/Tango.Transport.csproj
@@ -53,6 +53,7 @@
<HintPath>..\packages\System.Reactive.Windows.Threading.3.1.1\lib\net45\System.Reactive.Windows.Threading.dll</HintPath>
</Reference>
<Reference Include="System.ServiceModel" />
+ <Reference Include="System.Web" />
<Reference Include="System.Windows" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
@@ -131,7 +132,7 @@
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
<VisualStudio>
- <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" />
+ <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" />
</VisualStudio>
</ProjectExtensions>
</Project> \ No newline at end of file
diff --git a/Software/Visual_Studio/Tango.Transport/Web/ProtoWebClient.cs b/Software/Visual_Studio/Tango.Transport/Web/ProtoWebClient.cs
index 43ff482fd..7f8beef04 100644
--- a/Software/Visual_Studio/Tango.Transport/Web/ProtoWebClient.cs
+++ b/Software/Visual_Studio/Tango.Transport/Web/ProtoWebClient.cs
@@ -5,6 +5,8 @@ using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
+using System.Web;
+using Tango.PMR.Synchronization;
namespace Tango.Transport.Web
{
@@ -26,8 +28,15 @@ namespace Tango.Transport.Web
req.Headers.Add("Content-Type", "application/x-protobuf");
var response = _httpClient.PostAsync(url, req).Result;
+
var data = response.Content.ReadAsByteArrayAsync().Result;
+ if (response.StatusCode != System.Net.HttpStatusCode.OK)
+ {
+ HttpProtoException exception = HttpProtoException.Parser.ParseFrom(data);
+ throw new HttpException(exception.StatusCode, exception.Message);
+ }
+
Response dummy = Activator.CreateInstance<Response>() as Response;
return dummy.GetParser().ParseFrom(data) as Response;
diff --git a/Software/Visual_Studio/Web/Tango.MachineService/App_Start/WebApiConfig.cs b/Software/Visual_Studio/Web/Tango.MachineService/App_Start/WebApiConfig.cs
index 28968684e..3129482cb 100644
--- a/Software/Visual_Studio/Web/Tango.MachineService/App_Start/WebApiConfig.cs
+++ b/Software/Visual_Studio/Web/Tango.MachineService/App_Start/WebApiConfig.cs
@@ -1,4 +1,5 @@
-using System;
+using Newtonsoft.Json;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
@@ -20,6 +21,10 @@ namespace Tango.MachineService
defaults: new { id = RouteParameter.Optional });
config.Formatters.Insert(0, new ProtoBufFormatter());
+ config.Formatters.Insert(1, new JsonNetFormatter(new JsonSerializerSettings()
+ {
+ PreserveReferencesHandling = PreserveReferencesHandling.All,
+ }));
}
}
}
diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs
index 06c1a4a23..51cf6f96b 100644
--- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs
+++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs
@@ -1,4 +1,5 @@
using Google.Protobuf;
+using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Configuration;
@@ -10,10 +11,13 @@ using System.Threading.Tasks;
using System.Web.Hosting;
using System.Web.Http;
using Tango.BL;
+using Tango.BL.Builders;
+using Tango.BL.Entities;
using Tango.Core.DB;
using Tango.Core.Helpers;
using Tango.Core.IO;
using Tango.Logging;
+using Tango.MachineService.Models;
using Tango.PMR.Stubs;
using Tango.PMR.Synchronization;
using Tango.Synchronization.Local;
@@ -86,13 +90,14 @@ namespace Tango.MachineService.Controllers
String serial_number = request.SerialNumber;
var machine = db.Machines.SingleOrDefault(x => x.SerialNumber == serial_number);
- var machine_version = db.MachineVersions.SingleOrDefault(x => x.Guid == machine.MachineVersionGuid);
if (machine == null)
{
- OnError(HttpStatusCode.NotFound, "The specified serial number could not be found.");
+ ThrowError(HttpStatusCode.NotFound, "The specified serial number could not be found.");
}
+ var machine_version = db.MachineVersions.SingleOrDefault(x => x.Guid == machine.MachineVersionGuid);
+
var latest_machine_version = db.TangoVersions.Where(x => x.MachineVersionGuid == machine_version.Guid).ToList().OrderByDescending(x => Version.Parse(x.Version)).FirstOrDefault();
response.Version = latest_machine_version.Version;
@@ -125,7 +130,7 @@ namespace Tango.MachineService.Controllers
catch (Exception ex)
{
logManager.Log(ex);
- OnError(HttpStatusCode.InternalServerError, ex.Message);
+ throw;
}
return response;
@@ -274,8 +279,27 @@ namespace Tango.MachineService.Controllers
return response;
}
+ [HttpPost]
+ public Machine PersonTest(Person p)
+ {
+ using (var db = ObservablesContext.CreateDefault(GetLocalServerAddress()))
+ {
+ var machine = new MachineBuilder(db)
+ .Set(x => x.SerialNumber == "1111")
+ .WithOrganization()
+ .WithConfiguration().Build();
+
+ return machine;
+ }
+ }
+
#region Helpers
+ private void ThrowError(HttpStatusCode code, String message)
+ {
+ throw new WebApiException(code, message);
+ }
+
private void OnError(HttpStatusCode code, String message)
{
throw new HttpResponseException(Request.CreateErrorResponse(code, message));
diff --git a/Software/Visual_Studio/Web/Tango.MachineService/JsonNetFormatter.cs b/Software/Visual_Studio/Web/Tango.MachineService/JsonNetFormatter.cs
new file mode 100644
index 000000000..7cadceb0b
--- /dev/null
+++ b/Software/Visual_Studio/Web/Tango.MachineService/JsonNetFormatter.cs
@@ -0,0 +1,89 @@
+using Newtonsoft.Json;
+using Newtonsoft.Json.Serialization;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Net;
+using System.Net.Http;
+using System.Net.Http.Formatting;
+using System.Net.Http.Headers;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+using System.Web;
+using Tango.BL;
+
+namespace Tango.MachineService
+{
+ public class JsonNetFormatter : MediaTypeFormatter
+ {
+ private class JsonIgnoreAttributeIgnorerContractResolver : DefaultContractResolver
+ {
+ protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
+ {
+ var property = base.CreateProperty(member, memberSerialization);
+
+ if (typeof(IObservableEntity).IsAssignableFrom(property.PropertyType))
+ {
+ property.Ignored = false;
+ }
+ return property;
+ }
+ }
+
+ private JsonSerializerSettings _jsonSerializerSettings;
+
+ public JsonNetFormatter(JsonSerializerSettings jsonSerializerSettings)
+ {
+ _jsonSerializerSettings = jsonSerializerSettings ?? new JsonSerializerSettings();
+ _jsonSerializerSettings.ContractResolver = new JsonIgnoreAttributeIgnorerContractResolver();
+
+ SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/json"));
+ }
+
+ public override bool CanReadType(Type type)
+ {
+ return true;
+ }
+
+ public override bool CanWriteType(Type type)
+ {
+ return true;
+ }
+
+ public override Task<object> ReadFromStreamAsync(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)
+ {
+ // Create a serializer
+ JsonSerializer serializer = JsonSerializer.Create(_jsonSerializerSettings);
+
+ // Create task reading the content
+ return Task.Factory.StartNew(() =>
+ {
+ using (StreamReader streamReader = new StreamReader(readStream))
+ {
+ using (JsonTextReader jsonTextReader = new JsonTextReader(streamReader))
+ {
+ return serializer.Deserialize(jsonTextReader, type);
+ }
+ }
+ });
+ }
+
+ public override Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content, TransportContext transportContext)
+ {
+ // Create a serializer
+ JsonSerializer serializer = JsonSerializer.Create(_jsonSerializerSettings);
+
+ // Create task writing the serialized content
+ return Task.Factory.StartNew(() =>
+ {
+ using (JsonTextWriter jsonTextWriter = new JsonTextWriter(new StreamWriter(writeStream)) { CloseOutput = false })
+ {
+ serializer.Serialize(jsonTextWriter, value);
+ jsonTextWriter.Flush();
+ }
+ });
+ }
+ }
+} \ No newline at end of file
diff --git a/Software/Visual_Studio/Web/Tango.MachineService/ProtoBufFormatter.cs b/Software/Visual_Studio/Web/Tango.MachineService/ProtoBufFormatter.cs
index 529cbde54..ef233df7d 100644
--- a/Software/Visual_Studio/Web/Tango.MachineService/ProtoBufFormatter.cs
+++ b/Software/Visual_Studio/Web/Tango.MachineService/ProtoBufFormatter.cs
@@ -6,7 +6,9 @@ using System.Net.Http;
using System.Net.Http.Formatting;
using System.Net.Http.Headers;
using System.Threading.Tasks;
+using System.Web.Http;
using Tango.PMR.Stubs;
+using Tango.PMR.Synchronization;
namespace Tango.MachineService
{
@@ -98,10 +100,10 @@ namespace Tango.MachineService
/// <returns></returns>
public override Task WriteToStreamAsync(Type type, object value, Stream stream, HttpContent content, TransportContext transportContext)
{
+ var tcs = new TaskCompletionSource<object>();
+
if (value is IMessage)
{
- var tcs = new TaskCompletionSource<object>();
-
try
{
(value as IMessage).WriteTo(stream);
@@ -114,6 +116,26 @@ namespace Tango.MachineService
return tcs.Task;
}
+ else if (value is HttpError)
+ {
+ var httpError = value as HttpError;
+
+ try
+ {
+ HttpProtoException msg = new HttpProtoException();
+ msg.Message = httpError.ExceptionMessage;
+ msg.StatusCode = (int)HttpStatusCode.InternalServerError;
+
+ msg.WriteTo(stream);
+ tcs.SetResult(null);
+ }
+ catch (Exception ex)
+ {
+ tcs.SetException(ex);
+ }
+
+ return tcs.Task;
+ }
return base.WriteToStreamAsync(type, value, stream, content, transportContext);
}
diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj b/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj
index 6b3b7069d..f3b4a228e 100644
--- a/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj
+++ b/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj
@@ -173,6 +173,7 @@
</Compile>
<Compile Include="App_Start\BundleConfig.cs" />
<Compile Include="App_Start\FilterConfig.cs" />
+ <Compile Include="JsonNetFormatter.cs" />
<Compile Include="ProtoBufFormatter.cs" />
<Compile Include="App_Start\RouteConfig.cs" />
<Compile Include="App_Start\WebApiConfig.cs" />
@@ -184,6 +185,7 @@
</Compile>
<Compile Include="Models\Person.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="WebApiException.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Global.asax" />
@@ -255,7 +257,7 @@
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
</WebProjectProperties>
</FlavorProperties>
- <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" />
+ <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" />
</VisualStudio>
</ProjectExtensions>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
diff --git a/Software/Visual_Studio/Web/Tango.MachineService/WebApiException.cs b/Software/Visual_Studio/Web/Tango.MachineService/WebApiException.cs
new file mode 100644
index 000000000..a52a0ce6f
--- /dev/null
+++ b/Software/Visual_Studio/Web/Tango.MachineService/WebApiException.cs
@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Web;
+
+namespace Tango.MachineService
+{
+ public class WebApiException : Exception
+ {
+ public HttpStatusCode StatusCode { get; set; }
+
+ public WebApiException(HttpStatusCode statusCode, String message) : base(message)
+ {
+ StatusCode = statusCode;
+ }
+ }
+} \ No newline at end of file