ToChar() public static method

public static ToChar ( DateTime value ) : char
value DateTime
return char
Beispiel #1
0
    static public string CalculateHashPassword(int iLength)
    {
        _pStrBuilder.Length = 0;
        for (int i = 0; i < iLength; i++)
        {
            ERandomCharType eRandomType = (ERandomCharType)Random.Range(0, PrimitiveHelper.GetEnumLength <ERandomCharType>());
            int             iRandomChar = 0;
            switch (eRandomType)
            {
            case ERandomCharType.LowerCase:
                iRandomChar = Random.Range(Convert.ToInt32('a'), Convert.ToInt32('z'));
                _pStrBuilder.Append(Convert.ToChar(iRandomChar));
                break;

            case ERandomCharType.UpperCase:
                iRandomChar = Random.Range(Convert.ToInt32('A'), Convert.ToInt32('Z'));
                _pStrBuilder.Append(Convert.ToChar(iRandomChar));
                break;

            case ERandomCharType.Number:
                iRandomChar = Random.Range(0, 10);
                _pStrBuilder.Append(iRandomChar.ToString());
                break;
            }
        }

        return(_pStrBuilder.ToString());
    }
 public DatabaseInfo getDatabaseInfo()
 {
     if (databaseInfo != null)
     {
         return(databaseInfo);
     }
     try {
         // Synchronize since we're accessing the database file.
         lock (this) {
             bool    hasStructureInfo = false;
             byte [] delim            = new byte[3];
             // Advance to part of file where database info is stored.
             file.Seek(-3, SeekOrigin.End);
             for (int i = 0; i < STRUCTURE_INFO_MAX_SIZE; i++)
             {
                 file.Read(delim, 0, 3);
                 if (delim[0] == 255 && delim[1] == 255 && delim[2] == 255)
                 {
                     hasStructureInfo = true;
                     break;
                 }
             }
             if (hasStructureInfo)
             {
                 file.Seek(-3, SeekOrigin.Current);
             }
             else
             {
                 // No structure info, must be pre Sep 2002 database, go back to end.
                 file.Seek(-3, SeekOrigin.End);
             }
             // Find the database info string.
             for (int i = 0; i < DATABASE_INFO_MAX_SIZE; i++)
             {
                 file.Read(delim, 0, 3);
                 if (delim[0] == 0 && delim[1] == 0 && delim[2] == 0)
                 {
                     byte[] dbInfo  = new byte[i];
                     char[] dbInfo2 = new char[i];
                     file.Read(dbInfo, 0, i);
                     for (int a0 = 0; a0 < i; a0++)
                     {
                         dbInfo2[a0] = Convert.ToChar(dbInfo[a0]);
                     }
                     // Create the database info object using the string.
                     this.databaseInfo = new DatabaseInfo(new String(dbInfo2));
                     return(databaseInfo);
                 }
                 file.Seek(-4, SeekOrigin.Current);
             }
         }
     }
     catch (Exception e) {
         Console.Write(e.Message);
         //e.printStackTrace();
     }
     return(new DatabaseInfo(""));
 }
        /// <summary>
        /// Converts a value to a <see cref="char"/>.
        /// </summary>
        /// <param name="value">The object to convert.</param>
        /// <returns>The converted <paramref name="value"/>.</returns>
        public char ToChar(object value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            return(SConvert.ToChar(value, CultureInfo.InvariantCulture));
        }
        public int SubString(string s)
        {
            int[] upper = new int[26];
            int[] lower = new int[26];
            for (int i = 0; i < 26; i++)
            {
                upper[i] = BalanceItem.INT_MIN;
                lower[i] = BalanceItem.INT_MIN;
            }

            BalanceItem        res       = new BalanceItem();
            List <BalanceItem> intervals = new List <BalanceItem>();

            for (int i = 0; i < s.Length; i++)
            {
                char c = s[i];
                if (char.IsUpper(c))
                {
                    upper[c - 'A'] = i;
                }
                else
                {
                    lower[c - 'a'] = i;
                }

                for (int j = 0; j < 26; j++)
                {
                    BalanceItem existedItem = intervals.FirstOrDefault(item => item.LowerCases.Contains(Convert.ToChar('a' + j)));
                    if (existedItem != null)
                    {
                        existedItem.StartPos = Min(upper[j], lower[j]); //Notes: this is fantastic idea
                        existedItem.EndPos   = Max(upper[j], lower[j]);
                    }
                    else
                    {
                        var item = new BalanceItem(Convert.ToChar('a' + j), Min(upper[j], lower[j]), Max(upper[j], lower[j]));
                        intervals.Add(item);
                    }
                }

                BalanceItem currentSmallestInterval = FindSmallestInterval(intervals, s);
                res = Min(res, currentSmallestInterval);
            }

            return(res.IsUpperLowerSet()
                ? res.Distance()
                : -1);
        }
        public String getOrg(long ipnum)
        {
            int Seek_org;
            int record_pointer;
            int str_length = 0;

            byte [] buf  = new byte[MAX_ORG_RECORD_LENGTH];
            char [] buf2 = new char[MAX_ORG_RECORD_LENGTH];
            String  org_buf;

            try {
                Seek_org = SeekCountry(ipnum);
                if (Seek_org == databaseSegments[0])
                {
                    return(null);
                }

                record_pointer = Seek_org + (2 * recordLength - 1) * databaseSegments[0];
                if ((dboptions & GEOIP_MEMORY_CACHE) == 1)
                {
                    Array.Copy(dbbuffer, record_pointer, buf, 0, Math.Min(dbbuffer.Length - record_pointer, MAX_ORG_RECORD_LENGTH));
                }
                else
                {
                    file.Seek(record_pointer, SeekOrigin.Begin);
                    file.Read(buf, 0, MAX_ORG_RECORD_LENGTH);
                }
                while (buf[str_length] != 0)
                {
                    buf2[str_length] = Convert.ToChar(buf[str_length]);
                    str_length++;
                }
                buf2[str_length] = '\0';
                org_buf          = new String(buf2, 0, str_length);
                return(org_buf);
            }
            catch (IOException) {
                Console.Write("IO Exception");
                return(null);
            }
        }
        public Location getLocation(long ipnum)
        {
            int record_pointer;

            byte[]   record_buf = new byte[FULL_RECORD_LENGTH];
            char[]   record_buf2 = new char[FULL_RECORD_LENGTH];
            int      record_buf_offset = 0;
            Location record = new Location();
            int      str_length = 0;
            int      j, Seek_country;
            double   latitude = 0, longitude = 0;

            try {
                Seek_country = SeekCountry(ipnum);
                if (Seek_country == databaseSegments[0])
                {
                    return(null);
                }
                record_pointer = Seek_country + ((2 * recordLength - 1) * databaseSegments[0]);
                if ((dboptions & GEOIP_MEMORY_CACHE) == 1)
                {
                    Array.Copy(dbbuffer, record_pointer, record_buf, 0, Math.Min(dbbuffer.Length - record_pointer, FULL_RECORD_LENGTH));
                }
                else
                {
                    file.Seek(record_pointer, SeekOrigin.Begin);
                    file.Read(record_buf, 0, FULL_RECORD_LENGTH);
                }
                for (int a0 = 0; a0 < FULL_RECORD_LENGTH; a0++)
                {
                    record_buf2[a0] = Convert.ToChar(record_buf[a0]);
                }
                // get country
                record.countryCode = countryCode[unsignedByteToInt(record_buf[0])];
                record.countryName = countryName[unsignedByteToInt(record_buf[0])];
                record_buf_offset++;

                // get region
                while (record_buf[record_buf_offset + str_length] != '\0')
                {
                    str_length++;
                }
                if (str_length > 0)
                {
                    record.region = new String(record_buf2, record_buf_offset, str_length);
                }
                record_buf_offset += str_length + 1;
                str_length         = 0;

                // get region_name
                record.regionName = RegionName.getRegionName(record.countryCode, record.region);

                // get city
                while (record_buf[record_buf_offset + str_length] != '\0')
                {
                    str_length++;
                }
                if (str_length > 0)
                {
                    record.city = new String(record_buf2, record_buf_offset, str_length);
                }
                record_buf_offset += (str_length + 1);
                str_length         = 0;

                // get postal code
                while (record_buf[record_buf_offset + str_length] != '\0')
                {
                    str_length++;
                }
                if (str_length > 0)
                {
                    record.postalCode = new String(record_buf2, record_buf_offset, str_length);
                }
                record_buf_offset += (str_length + 1);

                // get latitude
                for (j = 0; j < 3; j++)
                {
                    latitude += (unsignedByteToInt(record_buf[record_buf_offset + j]) << (j * 8));
                }
                record.latitude    = (float)latitude / 10000 - 180;
                record_buf_offset += 3;

                // get longitude
                for (j = 0; j < 3; j++)
                {
                    longitude += (unsignedByteToInt(record_buf[record_buf_offset + j]) << (j * 8));
                }
                record.longitude = (float)longitude / 10000 - 180;

                record.metro_code = record.dma_code = 0;
                record.area_code  = 0;
                if (databaseType == DatabaseInfo.CITY_EDITION_REV1)
                {
                    // get metro_code
                    int metroarea_combo = 0;
                    if (record.countryCode == "US")
                    {
                        record_buf_offset += 3;
                        for (j = 0; j < 3; j++)
                        {
                            metroarea_combo += (unsignedByteToInt(record_buf[record_buf_offset + j]) << (j * 8));
                        }
                        record.metro_code = record.dma_code = metroarea_combo / 1000;
                        record.area_code  = metroarea_combo % 1000;
                    }
                }
            }
            catch (IOException) {
                Console.Write("IO Exception while seting up segments");
            }
            return(record);
        }
Beispiel #7
0
        // This method reads the attributes of your container class via
        // reflection  in order to build a schema for the DataTable that you
        // will explicitly convert to.
        private DataTable ConstructDataTableSchema(T item)
        {
            string tableName = string.Empty;
            List <DTConverterContainer> schemaContainers = new List <DTConverterContainer>();
            Type type = item.GetType();

            MemberInfo[] members = type.GetProperties();
            foreach (MemberInfo member in members)
            {
                object[] attributes = member.GetCustomAttributes(true);
                if (attributes.Length == 0)
                {
                    continue;
                }
                foreach (object attribute in attributes)
                {
                    ConversionAttribute ca = attribute as ConversionAttribute;
                    if (ca == null)
                    {
                        continue;
                    }
                    if (!ca.DataTableConversion)
                    {
                        continue;
                    }
                    // The name of the container class is used to name
                    // your DataTable

                    string[] classNameArray =
                        member.ReflectedType.ToString().Split(
                            Convert.ToChar("."));
                    tableName = classNameArray[classNameArray.Length - 1];
                    string       name      = member.Name;
                    PropertyInfo prop      = type.GetProperty(name);
                    Type         valueType = prop.GetValue(item, null).GetType();
                    // Each property that is  will be a column in our
                    // DataTable.

                    schemaContainers.Add(new DTConverterContainer(name,
                                                                  valueType, ca.AllowDBNull, ca.KeyField));
                }
            }
            if (schemaContainers.Count > 0)
            {
                DataTable    dataTable  = new DataTable(tableName);
                DataColumn[] dataColumn = new DataColumn[schemaContainers.Count];
                // Counts the number of keys that will need to be created

                int totalNumberofKeys = 0;
                foreach (DTConverterContainer container in schemaContainers)
                {
                    if (container.IsKey && m_enforceKeys)
                    {
                        totalNumberofKeys = totalNumberofKeys + 1;
                    }
                }
                // Builds the DataColumns for our DataTable

                DataColumn[] keyColumnArray = new DataColumn[totalNumberofKeys];
                int          keyColumnIndex = 0;
                for (int i = 0; i < schemaContainers.Count; i++)
                {
                    dataColumn[i] = new DataColumn
                    {
                        DataType    = schemaContainers[i].PropertyType,
                        ColumnName  = schemaContainers[i].PropertyName,
                        AllowDBNull = schemaContainers[i].AllowDBNull
                    };
                    dataTable.Columns.Add(dataColumn[i]);
                    if (schemaContainers[i].IsKey != true || m_enforceKeys != true)
                    {
                        continue;
                    }
                    keyColumnArray[keyColumnIndex] = dataColumn[i];
                    keyColumnIndex = keyColumnIndex + 1;
                }
                if (m_enforceKeys)
                {
                    dataTable.PrimaryKey = keyColumnArray;
                }
                return(dataTable);
            }
            return(null);
        }
Beispiel #8
0
        public DataTable GetDataTable(List <T> items)
        {
            DataTable dt;

            try
            {
                // Build a table schema from the first element in the collection

                dt = ConstructDataTableSchema(items[0]);
            }
            catch (IndexOutOfRangeException ex)
            {
                throw (new ApplicationException(
                           "Cannot convert List of zero length to a DataTable", ex));
            }
            // If the container is not convertable than throw an

            // ApplicationException.

            if (dt == null)
            {
                throw new ApplicationException("List items are not convertable.");
            }
            // Create a new row for every item in the collection and fill it.
            for (int i = 0; i < items.Count; i++)
            {
                DataRow      dr      = dt.NewRow();
                Type         type    = items[i].GetType();
                MemberInfo[] members = type.GetProperties();

                foreach (MemberInfo member in members)
                {
                    object[] attributes = member.GetCustomAttributes(true);
                    if (attributes.Length == 0)
                    {
                        continue;
                    }
                    foreach (object attribute in attributes)
                    {
                        ConversionAttribute ca = attribute as
                                                 ConversionAttribute;
                        if (ca == null)
                        {
                            continue;
                        }
                        if (!ca.DataTableConversion)
                        {
                            continue;
                        }
                        string[] nameArray
                            = member.Name.Split(
                                  Convert.ToChar(" "));
                        PropertyInfo prop = type.GetProperty(
                            nameArray[0]);
                        //                       Type valueType = prop.GetValue(items[i],
                        //                                                      null).GetType() // COMMENTED BY CODEIT.RIGHT;
                        dr[nameArray[0]] = prop.GetValue(items[i], null);
                    }
                }

                dt.Rows.Add(dr);
            }
            return(dt);
        }
Beispiel #9
0
 char IConvertible.ToChar(IFormatProvider provider)
 {
     return(Convert.ToChar(m_value));
 }
Beispiel #10
0
 char IConvertible.ToChar(IFormatProvider provider)
 {
     return(Convert.ToChar(GetValue(), CultureInfo.CurrentCulture));
 }
Beispiel #11
0
 char IConvertible.ToChar(IFormatProvider provider)
 {
     return(Convert.ToChar(this));
 }
        public bool SubmitFormToEloqua(FormSubmitContext formSubmitContext)
        {
            Logger.Info(Invariant($"Form {formSubmitContext.FormId} submitted successfully."), this);
            HttpPostedFileBase file     = null;
            string             fileName = null;

            foreach (IViewModel field in formSubmitContext.Fields)
            {
                if (field is FileUploadViewModel)
                {
                    var fileUpload = field as FileUploadViewModel;
                    if (fileUpload.Files.Count > 0)
                    {
                        file = fileUpload.Files.First();
                    }
                }

                if (field.Name == "fileName")
                {
                    var textField = field as StringInputViewModel;
                    fileName = textField.Value;
                }
            }

            if (file != null && fileName != null)
            {
                using (new Sitecore.SecurityModel.SecurityDisabler())
                {
                    var master = Sitecore.Configuration.Factory.GetDatabase("master");
                    // Create the options
                    Sitecore.Resources.Media.MediaCreatorOptions options = new Sitecore.Resources.Media.MediaCreatorOptions();
                    // Store the file in the database, not as a file
                    options.FileBased = false;
                    // Remove file extension from item name
                    options.IncludeExtensionInItemName = false;
                    // Overwrite any existing file with the same name
                    options.OverwriteExisting = true;
                    // Do not make a versioned template
                    options.Versioned = false;
                    // set the path
                    options.Destination = "/sitecore/media library/Items/Uploaded/" + fileName;
                    // Set the database
                    options.Database = master;

                    var mediaItem = Sitecore.Resources.Media.MediaManager.Creator.CreateFromStream(file.InputStream, fileName + "." + file.FileName.Split(Convert.ToChar(".")).Last(), options);

                    Item         parentItem = master.Items[Sitecore.Context.Site.StartPath];
                    TemplateItem template   = master.GetTemplate(new ID("{744445AA-E445-44C4-85D9-88E5EF8C44F3}"));

                    Item marketplaceItem = parentItem.Add(fileName, template);

                    marketplaceItem.Editing.BeginEdit();

                    try
                    {
                        marketplaceItem.Fields["Name"]?.SetValue(fileName, true);
                        var fileField = (FileField)marketplaceItem.Fields["File"];
                        fileField.MediaID = mediaItem.ID;
                        marketplaceItem.Editing.EndEdit();
                    }
                    catch (Exception ex)
                    {
                        marketplaceItem.Editing.CancelEdit();
                    }

                    PublishItem(mediaItem);
                    PublishItem(marketplaceItem);
                }
            }

            return(true);
        }
        // Special coersion rules for primitives, enums and pointer.
        private static Exception ConvertOrWidenPrimitivesEnumsAndPointersIfPossible(object srcObject, EETypePtr srcEEType, EETypePtr dstEEType, CheckArgumentSemantics semantics, out object dstObject)
        {
            if (semantics == CheckArgumentSemantics.SetFieldDirect && (srcEEType.IsEnum || dstEEType.IsEnum))
            {
                dstObject = null;
                return(CreateChangeTypeException(srcEEType, dstEEType, semantics));
            }

            if (dstEEType.IsPointer)
            {
                Exception exception = ConvertPointerIfPossible(srcObject, srcEEType, dstEEType, semantics, out IntPtr dstIntPtr);
                if (exception != null)
                {
                    dstObject = null;
                    return(exception);
                }
                dstObject = dstIntPtr;
                return(null);
            }

            if (!(srcEEType.IsPrimitive && dstEEType.IsPrimitive))
            {
                dstObject = null;
                return(CreateChangeTypeException(srcEEType, dstEEType, semantics));
            }

            RuntimeImports.RhCorElementType dstCorElementType = dstEEType.CorElementType;
            if (!srcEEType.CorElementTypeInfo.CanWidenTo(dstCorElementType))
            {
                dstObject = null;
                return(CreateChangeTypeArgumentException(srcEEType, dstEEType));
            }

            switch (dstCorElementType)
            {
            case RuntimeImports.RhCorElementType.ELEMENT_TYPE_BOOLEAN:
                bool boolValue = Convert.ToBoolean(srcObject);
                dstObject = dstEEType.IsEnum ? Enum.ToObject(dstEEType, boolValue ? 1 : 0) : boolValue;
                break;

            case RuntimeImports.RhCorElementType.ELEMENT_TYPE_CHAR:
                char charValue = Convert.ToChar(srcObject);
                dstObject = dstEEType.IsEnum ? Enum.ToObject(dstEEType, charValue) : charValue;
                break;

            case RuntimeImports.RhCorElementType.ELEMENT_TYPE_I1:
                sbyte sbyteValue = Convert.ToSByte(srcObject);
                dstObject = dstEEType.IsEnum ? Enum.ToObject(dstEEType, sbyteValue) : sbyteValue;
                break;

            case RuntimeImports.RhCorElementType.ELEMENT_TYPE_I2:
                short shortValue = Convert.ToInt16(srcObject);
                dstObject = dstEEType.IsEnum ? Enum.ToObject(dstEEType, shortValue) : shortValue;
                break;

            case RuntimeImports.RhCorElementType.ELEMENT_TYPE_I4:
                int intValue = Convert.ToInt32(srcObject);
                dstObject = dstEEType.IsEnum ? Enum.ToObject(dstEEType, intValue) : intValue;
                break;

            case RuntimeImports.RhCorElementType.ELEMENT_TYPE_I8:
                long longValue = Convert.ToInt64(srcObject);
                dstObject = dstEEType.IsEnum ? Enum.ToObject(dstEEType, longValue) : longValue;
                break;

            case RuntimeImports.RhCorElementType.ELEMENT_TYPE_U1:
                byte byteValue = Convert.ToByte(srcObject);
                dstObject = dstEEType.IsEnum ? Enum.ToObject(dstEEType, byteValue) : byteValue;
                break;

            case RuntimeImports.RhCorElementType.ELEMENT_TYPE_U2:
                ushort ushortValue = Convert.ToUInt16(srcObject);
                dstObject = dstEEType.IsEnum ? Enum.ToObject(dstEEType, ushortValue) : ushortValue;
                break;

            case RuntimeImports.RhCorElementType.ELEMENT_TYPE_U4:
                uint uintValue = Convert.ToUInt32(srcObject);
                dstObject = dstEEType.IsEnum ? Enum.ToObject(dstEEType, uintValue) : uintValue;
                break;

            case RuntimeImports.RhCorElementType.ELEMENT_TYPE_U8:
                ulong ulongValue = Convert.ToUInt64(srcObject);
                dstObject = dstEEType.IsEnum ? Enum.ToObject(dstEEType, (long)ulongValue) : ulongValue;
                break;

            case RuntimeImports.RhCorElementType.ELEMENT_TYPE_R4:
                if (srcEEType.CorElementType == RuntimeImports.RhCorElementType.ELEMENT_TYPE_CHAR)
                {
                    dstObject = (float)(char)srcObject;
                }
                else
                {
                    dstObject = Convert.ToSingle(srcObject);
                }
                break;

            case RuntimeImports.RhCorElementType.ELEMENT_TYPE_R8:
                if (srcEEType.CorElementType == RuntimeImports.RhCorElementType.ELEMENT_TYPE_CHAR)
                {
                    dstObject = (double)(char)srcObject;
                }
                else
                {
                    dstObject = Convert.ToDouble(srcObject);
                }
                break;

            default:
                Debug.Fail("Unexpected CorElementType: " + dstCorElementType + ": Not a valid widening target.");
                dstObject = null;
                return(CreateChangeTypeException(srcEEType, dstEEType, semantics));
            }

            Debug.Assert(dstObject.EETypePtr == dstEEType);
            return(null);
        }
Beispiel #14
0
        protected static internal object ConvertValue(Type type, NSJSValue value)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            object o = FetchValue(type, value);

            if (type == typeof(int))
            {
                o = (o == null ? 0 : Converter.ToInt32(o));
            }
            else if (type == typeof(uint))
            {
                o = (o == null ? 0u : Converter.ToUInt32(o));
            }
            else if (type == typeof(short))
            {
                o = (o == null ? (short)0 : Converter.ToInt16(o));
            }
            else if (type == typeof(ushort))
            {
                o = (o == null ? (ushort)0 : Converter.ToUInt16(o));
            }
            else if (type == typeof(sbyte))
            {
                o = (o == null ? (sbyte)0 : Converter.ToSByte(o));
            }
            else if (type == typeof(byte))
            {
                o = (o == null ? (byte)0 : Converter.ToByte(o));
            }
            else if (type == typeof(long))
            {
                o = (o == null ? 0L : Converter.ToInt64(o));
            }
            else if (type == typeof(ulong))
            {
                o = (o == null ? 0ul : Converter.ToUInt64(o));
            }
            else if (type == typeof(float))
            {
                o = (o == null ? 0f : Converter.ToSingle(o));
            }
            else if (type == typeof(double))
            {
                o = (o == null ? 0d : Converter.ToDouble(o));
            }
            else if (type == typeof(decimal))
            {
                o = (o == null ? 0m : Converter.ToDecimal(o));
            }
            else if (type == typeof(char))
            {
                o = (o == null ? '\0' : Converter.ToChar(o));
            }
            else if (type == typeof(DateTime))
            {
                long ticks = 0;
                if (o is long)
                {
                    ticks = (long)o;
                }
                else if (o != null)
                {
                    ticks = Converter.ToInt64(o);
                }
                o = NSJSDateTime.LocalDateToDateTime(ticks);
            }
            else if (type == typeof(string))
            {
                if (o == null)
                {
                    o = null;
                }
                else if (!(o is string))
                {
                    o = o.ToString();
                }
            }
            else if (typeof(NSJSValue).IsAssignableFrom(type))
            {
                return(type.IsInstanceOfType(value) ? value : null);
            }
            return(o);
        }
Beispiel #15
0
 public char ToChar(object value)
     => SystemConvert.ToChar(value);
Beispiel #16
0
		char IConvertible.ToChar (IFormatProvider provider)
		{
			return Convert.ToChar (Value, provider);
		}