本文整理匯總了C#中System.Guid.?.ToString方法的典型用法代碼示例。如果您正苦於以下問題:C# Guid.?.ToString方法的具體用法?C# Guid.?.ToString怎麽用?C# Guid.?.ToString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Guid
的用法示例。
在下文中一共展示了Guid.?.ToString方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: ConfigurePorts
/// <summary>
/// Configures the ports.
/// </summary>
/// <param name="portList">The port list.</param>
/// <param name="clientId">The client id.</param>
/// <returns>
/// A Guid created by the service as identificator
/// </returns>
/// <exception cref="FaultException">Thrown when adding portlist caused an error.</exception>
public async Task<string> ConfigurePorts(List<CommunicationPort> portList, Guid? clientId)
{
logger.Info("START CONFIGUREPORTS for clientId {0}.", clientId);
await this.ResetAllPorts();
using (await AsyncLock.LockAsync())
{
if (string.IsNullOrWhiteSpace(clientId?.ToString()))
{
// create new Guid if no valid clientId value was submitted
// this is normal for the first call to initially configure the portlist
clientId = Guid.NewGuid();
logger.Info("New clientId {0} created.", clientId);
}
// add new ports
var errMsg = string.Empty;
portList.ToList().ForEach(
port =>
{
if (ClientComListDict.ContainsKey(port.ComPortName))
{
// assign the clientId to this port
port.ClientGuid = clientId;
}
else
{
// create new port
try
{
IBasicComThread comThread;
if (bool.Parse(System.Configuration.ConfigurationManager.AppSettings["useMappedPorts"]))
{
// create TCP com thread for the configured port mapping
var endpoint =
System.Configuration.ConfigurationManager.AppSettings[port.ComPortName];
if (endpoint == null)
{
throw new NullReferenceException("No mapping configured for port: " + port.ComPortName);
}
if (port.MeterType == MeterType.Basemeter)
{
// get ip and tcp port from endpoint
var tmp = endpoint.Split(new[] { ":" }, StringSplitOptions.RemoveEmptyEntries);
comThread = new BasemeterComThread(tmp[0], tmp[1], port);
}
else
{
comThread = new DvseTcpEdlComThread(endpoint);
}
}
else
{
// no mapped ports -> virtual serial ports are used
if (port.MeterType == MeterType.Basemeter)
{
comThread = new BasemeterComThread(port.ComPortName, port);
}
else
{
comThread = new DvseSerialEdlComThread(port.ComPortName);
}
}
var newPort = new CommunicationPort
{
ComPortName = port.ComPortName,
ClientGuid = clientId,
ComThread = comThread
};
if (port.MeterType == MeterType.Basemeter)
{
newPort.BaseMeterDevice = new BasemeterDevice();
newPort.MeterType = MeterType.Basemeter;
}
else
{
newPort.EdlMeterDevice = new EdlMeterDevice();
newPort.MeterType = MeterType.Edl;
}
ClientComListDict[newPort.ComPortName] = newPort;
}
catch (Exception ex)
{
errMsg = $"ERROR: {ex.Message}.";
}
}
//.........這裏部分代碼省略.........
示例2: AddGuid
public static void AddGuid(this SQLiteParameterCollection parmeters, string parameterName, Guid? guid)
{
parmeters.AddWithValue(parameterName, guid?.ToString("D"));
}