当前位置: 首页>>代码示例>>C#>>正文


C# Guid.?.ToString方法代码示例

本文整理汇总了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}.";
                            }
                        }
//.........这里部分代码省略.........
开发者ID:cwschroeder,项目名称:MeterTestComService,代码行数:101,代码来源:SmlComService.cs

示例2: AddGuid

 public static void AddGuid(this SQLiteParameterCollection parmeters, string parameterName, Guid? guid)
 {
     parmeters.AddWithValue(parameterName, guid?.ToString("D"));
 }
开发者ID:caesay,项目名称:Hurricane,代码行数:4,代码来源:SqlExtensions.cs


注:本文中的System.Guid.?.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。