/// <summary>
 /// 将所有CIM参数写入到ini,部分以mode为section保存,其余是公共参数
 /// </summary>
 public void WriteCimConfig()
 {
     #region params
     WriteCimConfig(CIM_PARAMS.SendQueue.ToString(), StrSendQueue, ETypeMode.ToString());
     WriteCimConfig(CIM_PARAMS.ReadQueue.ToString(), StrReadQueue, ETypeMode.ToString());
     WriteCimConfig(CIM_PARAMS.IP.ToString(), StrIP, ETypeMode.ToString());
     WriteCimConfig(CIM_PARAMS.Port.ToString(), StrPort, ETypeMode.ToString());
     WriteCimConfig(CIM_PARAMS.CycTimes.ToString(), iCycTimes.ToString());
     WriteCimConfig(CIM_PARAMS.UserID.ToString(), StrUserID);
     WriteCimConfig(CIM_PARAMS.Fab.ToString(), StrFab);
     WriteCimConfig(CIM_PARAMS.Area.ToString(), StrArea);
     WriteCimConfig(CIM_PARAMS.Line.ToString(), StrLine);
     WriteCimConfig(CIM_PARAMS.EqpId.ToString(), EqpId);
     WriteCimConfig(CIM_PARAMS.Operation.ToString(), StrOperation);
     WriteCimConfig(CIM_PARAMS.Wo_id.ToString(), Wo_id);
     WriteCimConfig(CIM_PARAMS.ModelNo.ToString(), StrModelNo);
     WriteCimConfig(CIM_PARAMS.RunCard.ToString(), StrLot);
     WriteCimConfig(CIM_PARAMS.COM.ToString(), StrCom);
     WriteCimConfig(CIM_PARAMS.CodeDelay.ToString(), iCodeDelay.ToString());
     WriteCimConfig(CIM_PARAMS.Baudrate.ToString(), iBaudrate.ToString());
     WriteCimConfig(CIM_PARAMS.CodeType.ToString(), ETypeCode.ToString());
     WriteCimConfig(CIM_PARAMS.ModeType.ToString(), ETypeMode.ToString());
     WriteCimConfig(CIM_PARAMS.BlLog.ToString(), BlLog.ToString());
     #endregion
 }
        private string GenerateFilterCondition(string column, Filter.ECompare filterOperator, ETypeCode compareDataType, object value)
        {
            string filterString;

            switch (compareDataType)
            {
            case ETypeCode.String:
            case ETypeCode.Text:
            case ETypeCode.Json:
            case ETypeCode.Xml:
            case ETypeCode.Guid:
            case ETypeCode.Unknown:
                filterString = TableQuery.GenerateFilterCondition(column, ConvertOperator(filterOperator), (string)value);
                break;

            case ETypeCode.Boolean:
                filterString = TableQuery.GenerateFilterConditionForBool(column, ConvertOperator(filterOperator), (bool)value);
                break;

            case ETypeCode.Int16:
            case ETypeCode.Int32:
            case ETypeCode.UInt16:
            case ETypeCode.UInt32:
                filterString = TableQuery.GenerateFilterConditionForInt(column, ConvertOperator(filterOperator), (int)value);
                break;

            case ETypeCode.UInt64:
            case ETypeCode.Int64:
                filterString = TableQuery.GenerateFilterConditionForLong(column, ConvertOperator(filterOperator), (long)value);
                break;

            case ETypeCode.DateTime:
                filterString = TableQuery.GenerateFilterConditionForDate(column, ConvertOperator(filterOperator), (DateTime)value);
                break;

            case ETypeCode.Time:
                filterString = TableQuery.GenerateFilterCondition(column, ConvertOperator(filterOperator), value.ToString());
                break;

            case ETypeCode.Double:
            case ETypeCode.Decimal:
                filterString = TableQuery.GenerateFilterConditionForDouble(column, ConvertOperator(filterOperator), (double)value);
                break;

            default:
                throw new Exception("The data type: " + compareDataType.ToString() + " is not supported by Azure table storage.");
            }

            return(filterString);
        }
        /// <summary>
        /// Gets the start quote to go around the values in sql insert statement based in the column type.
        /// </summary>
        /// <returns></returns>
        protected override string GetSqlFieldValueQuote(ETypeCode type, object value)
        {
            string returnValue;

            if (value == null || value.GetType().ToString() == "System.DBNull")
            {
                return("null");
            }

            //if (value is string && type != ETypeCode.String && string.IsNullOrWhiteSpace((string)value))
            //    return "null";

            switch (type)
            {
            case ETypeCode.Byte:
            case ETypeCode.Single:
            case ETypeCode.Int16:
            case ETypeCode.Int32:
            case ETypeCode.Int64:
            case ETypeCode.SByte:
            case ETypeCode.UInt16:
            case ETypeCode.UInt32:
            case ETypeCode.UInt64:
            case ETypeCode.Double:
            case ETypeCode.Decimal:
                returnValue = AddEscape(value.ToString());
                break;

            case ETypeCode.Boolean:
                returnValue = (bool)value ? "1" : "0";
                break;

            case ETypeCode.String:
            case ETypeCode.Text:
            case ETypeCode.Json:
            case ETypeCode.Xml:
            case ETypeCode.Guid:
            case ETypeCode.Unknown:
                returnValue = "'" + AddEscape(value.ToString()) + "'";
                break;

            case ETypeCode.DateTime:
            case ETypeCode.Time:
                //sqlite does not have date fields, so convert to format that will work for greater/less compares
                if (value is DateTime)
                {
                    returnValue = "'" + AddEscape(((DateTime)value).ToString("yyyy-MM-dd HH:mm:ss.ff")) + "'";
                }
                else if (value is TimeSpan)
                {
                    returnValue = "'" + AddEscape(((TimeSpan)value).ToString()) + "'";
                }
                else
                {
                    returnValue = "'" + AddEscape((string)value) + "'";
                }
                break;

            default:
                throw new Exception("The datatype " + type.ToString() +
                                    " is not compatible with the create table.");
            }

            return(returnValue);
        }
        /// <summary>
        /// Gets the start quote to go around the values in sql insert statement based in the column type.
        /// </summary>
        /// <returns></returns>
        protected override string GetSqlFieldValueQuote(ETypeCode type, object value)
        {
            string returnValue;

            if (value == null || value is DBNull)
            {
                return("null");
            }

            //if (value is string && type != ETypeCode.String && string.IsNullOrWhiteSpace((string)value))
            //    return "null";

            switch (type)
            {
            case ETypeCode.Byte:
            case ETypeCode.Single:
            case ETypeCode.Int16:
            case ETypeCode.Int32:
            case ETypeCode.Int64:
            case ETypeCode.SByte:
            case ETypeCode.UInt16:
            case ETypeCode.UInt32:
            case ETypeCode.UInt64:
            case ETypeCode.Double:
            case ETypeCode.Decimal:
                returnValue = AddEscape(value.ToString());
                break;

            case ETypeCode.String:
            case ETypeCode.Guid:
            case ETypeCode.Boolean:
            case ETypeCode.Text:
            case ETypeCode.Json:
            case ETypeCode.Xml:
            case ETypeCode.Unknown:
                returnValue = "'" + AddEscape(value.ToString()) + "'";
                break;

            case ETypeCode.DateTime:
                if (value is DateTime)
                {
                    returnValue = "convert(datetime, '" + AddEscape(((DateTime)value).ToString("yyyy-MM-dd HH:mm:ss.ff")) + "')";
                }
                else
                {
                    returnValue = "convert(datetime, '" + AddEscape((string)value) + "')";
                }
                break;

            case ETypeCode.Time:
                if (value is TimeSpan)
                {
                    returnValue = "convert(time, '" + AddEscape(((TimeSpan)value).ToString("c")) + "')";
                }
                else
                {
                    returnValue = "convert(time, '" + AddEscape((string)value) + "')";
                }
                break;

            default:
                throw new Exception("The datatype " + type.ToString() + " is not compatible with the sql statement.");
            }

            return(returnValue);
        }
        private EntityProperty NewEntityProperty(ETypeCode typeCode, object value)
        {
            object returnValue;

            try
            {
                returnValue = TryParse(typeCode, value);
            }
            catch (Exception ex)
            {
                throw new ConnectionException($"Azure failed to create new entity of type {typeCode} due to incompatible value.", ex, value);
            }

            switch (typeCode)
            {
            case ETypeCode.Byte:
                return(new EntityProperty((Byte?)returnValue));

            case ETypeCode.SByte:
                return(new EntityProperty((SByte?)returnValue));

            case ETypeCode.UInt16:
                return(new EntityProperty((UInt16?)returnValue));

            case ETypeCode.UInt32:
                return(new EntityProperty((UInt32?)returnValue));

            case ETypeCode.UInt64:
                return(new EntityProperty(Convert.ToInt64(returnValue)));

            case ETypeCode.Int16:
                return(new EntityProperty((Int16?)returnValue));

            case ETypeCode.Int32:
                return(new EntityProperty((Int32?)returnValue));

            case ETypeCode.Int64:
                return(new EntityProperty((Int64?)returnValue));

            case ETypeCode.Double:
                return(new EntityProperty((Double?)returnValue));

            case ETypeCode.Single:
                return(new EntityProperty((Single?)returnValue));

            case ETypeCode.String:
            case ETypeCode.Text:
            case ETypeCode.Json:
            case ETypeCode.Xml:
                return(new EntityProperty((String)returnValue));

            case ETypeCode.Boolean:
                return(new EntityProperty((Boolean?)returnValue));

            case ETypeCode.DateTime:
                return(new EntityProperty((DateTime?)returnValue));

            case ETypeCode.Guid:
                return(new EntityProperty((Guid?)returnValue));

            case ETypeCode.Decimal:
            case ETypeCode.Unknown:
                return(new EntityProperty(value.ToString()));    //decimal not supported, so convert to string

            case ETypeCode.Time:
                return(new EntityProperty(((TimeSpan)value).Ticks));    //timespan not supported, so use ticks.

            case ETypeCode.Binary:
                return(new EntityProperty((byte[])value));

            default:
                throw new Exception("Cannot create new azure entity as the data type: " + typeCode.ToString() + " is not suppored.");
            }
        }