C3DeviceController - prop. IPAddress to field.

This commit is contained in:
DucDangAnh 2020-06-30 16:35:00 +07:00
parent 4ee2507055
commit e72f365013

View File

@ -9,7 +9,7 @@ namespace AIParkingApplication
public class C3DeviceController
{
public string IPAddress { get; }
private string ipAddress;
private int port;
private IntPtr oneTimeConnectedParamHandler;
private string connectionString;
@ -20,9 +20,9 @@ namespace AIParkingApplication
public C3DeviceController(string ipAddress, int port = C3Constant.DEFAULT_C3_PORT)
{
IPAddress = ipAddress;
this.ipAddress = ipAddress;
this.port = port;
connectionString = $"protocol=TCP,ipaddress={this.IPAddress},port={this.port},timeout=2000,passwd=";
connectionString = $"protocol=TCP,ipaddress={this.ipAddress},port={this.port},timeout=2000,passwd=";
oneTimeConnectedParamHandler = IntPtr.Zero;
isReconnected = true;
reconnectCounter = 0;
@ -50,7 +50,7 @@ namespace AIParkingApplication
public ActionResult Connect()
{
if (Util.IsPingable(IPAddress, out long replyTime))
if (Util.IsPingable(ipAddress, out long replyTime))
{
oneTimeConnectedParamHandler = Connect(connectionString);
if (oneTimeConnectedParamHandler != IntPtr.Zero)
@ -58,7 +58,7 @@ namespace AIParkingApplication
var result = new ActionResult
{
HasError = false,
Message = string.Format(C3Constant.CONNECTED_SUCCESSFULLY, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), IPAddress)
Message = string.Format(C3Constant.CONNECTED_SUCCESSFULLY, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), ipAddress)
};
return result;
}
@ -67,7 +67,7 @@ namespace AIParkingApplication
var result = new ActionResult
{
HasError = true,
Message = string.Format(C3Constant.FAILED_TO_CONNECT, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), IPAddress, PullLastError())
Message = string.Format(C3Constant.FAILED_TO_CONNECT, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), ipAddress, PullLastError())
};
return result;
}
@ -77,7 +77,7 @@ namespace AIParkingApplication
var result = new ActionResult
{
HasError = true,
Message = string.Format(C3Constant.FAILED_TO_PING, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), IPAddress)
Message = string.Format(C3Constant.FAILED_TO_PING, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), ipAddress)
};
return result;
}
@ -93,7 +93,7 @@ namespace AIParkingApplication
var result = new ActionResult
{
HasError = false,
Message = string.Format(C3Constant.OPENNED_DOOR_SUCCESSFULLY, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), IPAddress)
Message = string.Format(C3Constant.OPENNED_DOOR_SUCCESSFULLY, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), ipAddress)
};
return result;
}
@ -102,7 +102,7 @@ namespace AIParkingApplication
var result = new ActionResult
{
HasError = true,
Message = string.Format(C3Constant.FAILED_TO_OPEN_DOOR, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), IPAddress)
Message = string.Format(C3Constant.FAILED_TO_OPEN_DOOR, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), ipAddress)
};
return result;
}
@ -112,7 +112,7 @@ namespace AIParkingApplication
var result = new ActionResult
{
HasError = true,
Message = string.Format(C3Constant.NOT_CONNECTTED, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), IPAddress)
Message = string.Format(C3Constant.NOT_CONNECTTED, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), ipAddress)
};
return result;
}
@ -136,13 +136,13 @@ namespace AIParkingApplication
doorId = C3Constant.DEFAULT_DOOR_ID;
cardNumber = C3Constant.DEFAULT_CARD_NUMBER;
if (!Util.IsPingable(IPAddress, out long replyTime))
if (!Util.IsPingable(ipAddress, out long replyTime))
{
isReconnected = false;
var result = new ActionResult
{
HasError = true,
Message = string.Format(C3Constant.FAILED_TO_PING, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), IPAddress)
Message = string.Format(C3Constant.FAILED_TO_PING, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), ipAddress)
};
return result;
}
@ -177,7 +177,7 @@ namespace AIParkingApplication
{
isReconnected = true;
reconnectCounter = 0;
reconnectResult.Message = string.Format(C3Constant.RECONNECTED_SUCCESSFULLY, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), IPAddress);
reconnectResult.Message = string.Format(C3Constant.RECONNECTED_SUCCESSFULLY, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), ipAddress);
}
return reconnectResult;
}
@ -185,7 +185,7 @@ namespace AIParkingApplication
var result = new ActionResult
{
HasError = true,
Message = string.Format(C3Constant.FAILED_TO_READ_LOG, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), IPAddress)
Message = string.Format(C3Constant.FAILED_TO_READ_LOG, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), ipAddress)
};
return result;
}
@ -197,7 +197,7 @@ namespace AIParkingApplication
var result = new ActionResult
{
HasError = true,
Message = string.Format(C3Constant.WRONG_FORMAT_DATA, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), IPAddress, ex.Message)
Message = string.Format(C3Constant.WRONG_FORMAT_DATA, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), ipAddress, ex.Message)
};
return result;
}
@ -210,7 +210,7 @@ namespace AIParkingApplication
var result = new ActionResult
{
HasError = false,
Message = string.Format(C3Constant.DISCONNECTED_SUCCESSFULLY, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), IPAddress)
Message = string.Format(C3Constant.DISCONNECTED_SUCCESSFULLY, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), ipAddress)
};
return result;
}