Ejemplo n.º 1
0
        public static Int64 ParseSize(String sizeString, Boolean defaultToBinaryPrefix)
        {
            if (sizeString.All(char.IsDigit))
            {
                return Int64.Parse(sizeString);
            }

            var match = ParseSizeRegex.Matches(sizeString);

            if (match.Count != 0)
            {
                var value = Decimal.Parse(Regex.Replace(match[0].Groups["value"].Value, "\\,", ""), CultureInfo.InvariantCulture);

                var unit = match[0].Groups["unit"].Value.ToLower();

                switch (unit)
                {
                    case "kb":
                        return ConvertToBytes(Convert.ToDouble(value), 1, defaultToBinaryPrefix);
                    case "mb":
                        return ConvertToBytes(Convert.ToDouble(value), 2, defaultToBinaryPrefix);
                    case "gb":
                        return ConvertToBytes(Convert.ToDouble(value), 3, defaultToBinaryPrefix);
                    case "kib":
                        return ConvertToBytes(Convert.ToDouble(value), 1, true);
                    case "mib":
                        return ConvertToBytes(Convert.ToDouble(value), 2, true);
                    case "gib":
                        return ConvertToBytes(Convert.ToDouble(value), 3, true);
                    default:
                        return (Int64)value;
                }
            }
            return 0;
        }
        /*
         * Validates that password is a strong password
         * Conditions:
         *      Special characters not allowed
         *      Spaces not allowed
         *      At least one number character
         *      At least one capital character
         *      Between 6 to 12 characters in length
         */
        public static bool isStrongPassword(String password)
        {
            // Check for null
            if (password == null)
                return false;

            // Minimum and Maximum Length of field - 6 to 12 Characters
            if (password.Length < passwordLowerBoundary || password.Length > passwordUpperBoundary)
                return false;

            // Special Characters - Not Allowed
            // Spaces - Not Allowed
            if (!(password.All(c => char.IsLetterOrDigit(c))))
                return false;

            // Numeric Character - At least one character
            if (!password.Any(c => char.IsNumber(c)))
                return false;

            // At least one Capital Letter
            if (!password.Any(c => char.IsUpper(c)))
                return false;

            return true;
        }
Ejemplo n.º 3
0
        public static bool IsValidFolderName( String name )
        {
            Contract.Requires( !String.IsNullOrWhiteSpace( name ) );

            // check system names

            if( String.IsNullOrWhiteSpace( name ) || name == "." || name == ".." )
            {
                return false;
            }

            // whitespace and the start or end not allowed
            if( name[ 0 ] == WhiteSpace || name[ name.Length - 1 ] == WhiteSpace )
            {
                return false;
            }

            // max length
            if( name.Length > QuickIOPath.MaxFolderNameLength )
            {
                return false;
            }

            // point at the beginning or at the end is not allowed
            // windows would automatically remove the point at the end
            if( name[ 0 ] == '.' || name[ name.Length - 1 ] == '.' )
            {
                return false;
            }

            return name.All( IsValidFolderChar );
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Checks if passed string can be used as a filename or it contains
        /// some invalid characters.
        /// </summary>
        /// <param name="source">A string to test.</param>
        /// <returns><see langword="true"/> if string contains invalid characters.</returns>
        public static Boolean ContainsInvalidFileNameChars(String source)
        {
            Contract.Requires(source != null);

            Char[] chars = Path.GetInvalidFileNameChars();

            Contract.Assert(chars != null);

            return source.All(s => chars.All(c => s != c));
        }
Ejemplo n.º 5
0
 public static bool isValidYYMM(String s)
 {
     if (s.Length != 4)
     return false;
     if (!s.All(Char.IsDigit))
     return false;
     String mm = s.Substring(2, 2);
     int month = int.Parse(mm);
     if ((month < 1) || (month > 12))
     return false;
     return true;
 }
Ejemplo n.º 6
0
        public static void Main(String[] args)
        {
            Contract.Requires(!ReferenceEquals(args, null));
            Contract.Requires(args.All(s => !String.IsNullOrWhiteSpace(s)));
            Contract.Requires(args.Length >= 2);
            Contract.Requires(File.Exists(args[1]));

            if (args.Length < 2)
            {
                Console.WriteLine("To start the PocketInvester Server use:");
                Console.WriteLine("./Server.exe <predictor name> <path to FIXML>");
                return;
            }
            Log.Write("PocketInvestor starting.");
            ServerClass server = new ServerClass(args[0], args[1]);

            if (args.Any(a => a.Equals("-genkeys")))
                server.GenerateKeyFiles();

            server.requestManager.StartServer();
        }
Ejemplo n.º 7
0
 public static Boolean IsNumbers(String value)
 {
     return value.All(Char.IsDigit);
 }
Ejemplo n.º 8
0
 public bool comprobarTipos(String telefono, String documento)
 {
     return (telefono.All(char.IsDigit) && documento.All(char.IsDigit));
 }
 public bool comprobarTipos(String precio, String cantidad)
 {
     return (precio.All(char.IsDigit) && cantidad.All(char.IsDigit));
 }
 // Is the given string a hexadecimal?
 private Boolean isHex(String input)
 {
     for (int i = 0; i < input.Length; i++)
     {
         var current = input[i];
         if (!input.All(c => "0123456789abcdefABCDEF\n".Contains(c)))
             return false;
     }
     return true;
 }
        /*
         * Validates that username is correct format
         * Conditions:
         *      Special characters not allowed
         *      Spaces not allowed
         *      Between 4-12 characters in length
         */
        public static bool isValidUsername(String username)
        {
            // Check for null
            if (username == null)
            {
                return false;
            }

            // Minimum and Maximum Length of field - 4 to 12 Characters
            if (username.Length < usernameLowerBoundary || username.Length > usernameUpperBoundary)
                return false;

            // Special Characters - Not Allowed
            // Spaces - Not Allowed
            if (!(username.All(c => char.IsLetterOrDigit(c))))
                return false;

            return true;
        }
        public bool ValidateIntSearchKey(String SearchKey)
        {
            Int64 id;
            if (string.IsNullOrEmpty(SearchKey) || !SearchKey.All(i => Char.IsDigit(i)) || !Int64.TryParse(SearchKey, out id))
            {
                MessageBox.Show("Please enter valid search key");
                return false;
            }

            return true;
        }
 public bool ValidateNumber(String Num)
 {
     // Home number validation
     if (string.IsNullOrEmpty(Num) || !Num.All(C => Char.IsDigit(C)))
     {
         return false;
     }
     return true;
 }
 public bool ValidateName(String Name)
 {
     // Name Validation
     if (string.IsNullOrEmpty(Name) || !Name.All(C => Char.IsLetter(C) || Char.IsWhiteSpace(C)))
     {
         MessageBox.Show("Please enter valid Name");
         return false;
     }
     return true;
 }
Ejemplo n.º 15
0
 public bool comprobarTipos(String cantidad)
 {
     return (cantidad.All(char.IsDigit));
 }
Ejemplo n.º 16
0
        public Boolean Keywords(string searchtext, string fieldname, string mode)
        {
            //TODO: DEBUG_DAO create a function to build these filters. using brute force right now
            // need to add quoted phrases, exclude operators, whole or partial wor support
            // algorithm not always returning values, or sometimes rturns multiple when there should be one

            PortalCatalogDataContext dbPortalCatalog = new PortalCatalogDataContext();
            PortalDataContext dbPortal = new PortalDataContext();
            CategoryNodeDataContext dbCategoryNode = new CategoryNodeDataContext();
            ProductCategoryDataContext dbProductCategory = new ProductCategoryDataContext();
            ProductDataContext dbProduct = new ProductDataContext();
            CategoryDataContext dbCategories = new CategoryDataContext();

            PortalCatalog portal = new PortalCatalog();

            Boolean fStatus = false;

            // Work through the database  to find all products associated with a portal ID.
            // Znode has a few tables that simply act as relationship tables, hence the complexity of this query.

            var listPortalCatalog = portal.ReadDB(PortalID);

            var _productlist = listPortalCatalog.AsEnumerable()

                    // staring with the portal ID, grab all catalogs for that portal

                    // get mapping of catalogs to various categories
                    .Join
                        (dbCategoryNode.ZNodeCategoryNodes,
                            joinedPortalCatalogs => joinedPortalCatalogs.catalogID,
                            tempCategoryNode => tempCategoryNode.CatalogID,
                                (joinedPortalCatalogs, tempCategoryNode) => new
                                { joinedPortalCatalogs = joinedPortalCatalogs, tempCategoryNode = tempCategoryNode }
                        ) // produces joinedCategoryNode
                    // get mapping of all product IDs within categories
                    .Join
                        (dbProductCategory.ZNodeProductCategories,
                            joinedCategoryNode => joinedCategoryNode.tempCategoryNode.CategoryID,
                            tempProductCategories => tempProductCategories.CategoryID,
                                (joinedCategoryNode, tempProductCategories) => new
                                { joinedCategoryNode = joinedCategoryNode, tempProductCategories = tempProductCategories }
                        ) // produces joinedProductCategories
                    // get mapping of all products to categories and get product details
                    .Join
                        (dbProduct.ZNodeProducts,
                            joinedProductCategories => joinedProductCategories.tempProductCategories.ProductID,
                            tempProducts => tempProducts.ProductID,
                                (joinedProductCategories, tempProducts) => new
                                { joinedProductCategories = joinedProductCategories, tempProducts = tempProducts }
                        )  // produces final product list (tempProducts)
                    .Distinct()
                    .Select
                        (row => new Product
                            {
                                productID = row.tempProducts.ProductID,
                                parentCategoryID = row.joinedProductCategories.tempProductCategories.CategoryID,
                                categoryID = row.joinedProductCategories.joinedCategoryNode.tempCategoryNode.CategoryID,
                                shortDescription = row.tempProducts.ShortDescription,
                                description = row.tempProducts.Description,
                                productNumber = row.tempProducts.ProductNum,
                                imageFile = row.tempProducts.ImageFile,
                                displayOrder = (!row.tempProducts.DisplayOrder.HasValue) ? 0 : (int)row.tempProducts.DisplayOrder,
                                imageAltTag = row.tempProducts.ImageAltTag,
                                title = row.tempProducts.Name,
                                salePrice = row.tempProducts.SalePrice,
                                retailPrice = row.tempProducts.RetailPrice,
                                isOnSale = (row.tempProducts.SalePrice.HasValue) ? true : false,
                                portalID = (!row.tempProducts.PortalID.HasValue) ? 0 : (int)row.tempProducts.PortalID
                            }
                        );

            // set operational modes
            //fieldName = all | title | description    mode = all | exact | any

            if ((fieldname != null) && (fieldname.Length > 0))
            {
                fieldname = fieldname.ToLower();
            }
            else
            {
                fieldname = null;
            }

            if ((mode != null) && (mode.Length > 0))
            {
                mode = mode.ToLower();
            }
            else
            {
                mode = null;
            }

            // get any search terms

            String[] searchTerms = new String[] { };
            string[] separators = { ",", ".", "!", "?", ";", ":", " " };

            if (mode != null)
            {
                mode = mode.ToLower();
            }
                if (mode == "all" || mode == "any" || mode==null)
                {
                    searchTerms = searchtext.Split(separators, StringSplitOptions.RemoveEmptyEntries);
                }
                else
                {
                    searchTerms = null; // use searctext for an exact phrase matching
                }

            if (fieldname == "all" || fieldname == null)
            {
                if (mode == "exact")
                {
                    _productlist = _productlist
                                        .Where
                                            (
                                            row => row.title.ToLower().Contains(searchtext) ||
                                            row.description.ToLower().Contains(searchtext) ||
                                            row.keywords.ToLower().Contains(searchtext) ||
                                            row.shortDescription.ToLower().Contains(searchtext) ||
                                            row.SEOKeywords.ToLower().Contains(searchtext) ||
                                            row.SEOTitle.ToLower().Contains(searchtext) ||
                                            row.SEODescription.ToLower().Contains(searchtext)
                                            );
                }
                else if ((mode == "any") || (mode == null))
                {
                    var p1 = _productlist
                    .Where
                    (
                            row => searchTerms.Any
                            (
                                term => row.title.ToLower().Contains(term)
                            )
                    );
                    var p2 = _productlist
                            .Where
                        (
                                row => searchTerms.Any
                                (
                                    term => row.description.ToLower().Contains(term)
                                )
                        );
                    var p3 = _productlist
                        .Where
                        (
                                row => searchTerms.Any
                                (
                                    term => row.keywords.ToLower().Contains(term)
                                )
                        );

                    _productlist = p1.Union(p2).ToList();

                }
                else if (mode == "all")
                {

                    var p1 = _productlist
                            .Where
                            (
                                    row => searchTerms.All
                                    (
                                        term => row.title.ToLower().Contains(term)
                                    )
                            );
                    var p2 = _productlist
                            .Where
                        (
                                row => searchTerms.All
                                (
                                    term => row.description.ToLower().Contains(term)
                                )
                        );
                    var p3 = _productlist
                        .Where
                        (
                                row => searchTerms.All
                                (
                                    term => row.keywords.ToLower().Contains(term)
                                )
                        );

                    _productlist = p1.Union(p2).ToList();

                    //_productlist.Union(p3);

                }
            }
            else if (fieldname == "title")
            {
                if (mode == "exact")
                {
                    _productlist = _productlist
                                        .Where
                                            (
                                            row => row.title.ToLower().Contains(searchtext)
                                            );
                }
                else if ((mode == "any") || (mode == null))
                {
                    _productlist = _productlist
                        .Where
                            (
                            row => searchTerms.Any
                                (
                                    term => row.title.ToLower().Contains(term)
                                )
                        );
                }
                else if (mode == "all")
                {
                    _productlist = _productlist
                        .Where
                            (
                                row => searchTerms.All
                                    (
                                        term => row.title.ToLower().Contains(term)
                                    )
                            );
                }
            }
            else if (fieldname == "description")
            {
                if (mode == "exact")
                {
                    _productlist = _productlist
                                        .Where
                                            (
                                            row => row.description.ToLower().Contains(searchtext)
                                            );
                }
                else if ((mode == "any") || (mode == null))
                {
                    _productlist = _productlist
                        .Where
                            (
                            row => searchTerms.Any
                                (
                                    term => row.description.ToLower().Contains(term)
                                )
                        );
                }
                else if (mode == "all")
                {
                    _productlist = _productlist
                        .Where
                            (
                            row => searchTerms.All
                                (
                                    term => row.description.ToLower().Contains(term)
                                )
                        );
                }

            }
            else if (fieldname == "keywords")
            {
                if (mode == "exact")
                {
                    _productlist = _productlist
                                        .Where
                                            (
                                            row => row.keywords.ToLower().Contains(searchtext)
                                            );
                }
                else if ((mode == "any") || (mode == null))
                {
                    _productlist = _productlist
                        .Where
                            (
                            row => searchTerms.Any
                                (
                                    term => row.keywords.ToLower().Contains(term)
                                )
                        );
                }
                else if (mode == "all")
                {
                    _productlist = _productlist
                        .Where
                            (
                            row => searchTerms.All
                                (
                                    term => row.keywords.ToLower().Contains(term)
                                )
                        );
                }

            }

            _productlist = _productlist
                            .OrderBy(row => row.productCategoryID);

            if (_productlist != null)
            {
                try {
                    fStatus = true;
                    Count = _productlist.Count();
                    ProductList = _productlist;
                }
                catch (Exception e)
                {
                    Count = 0;
                    ProductList = null;
                }
            }

            return fStatus;
        }
 /// <summary>Test a string is nothing but letters and digits</summary>
 /// <param name="str"></param>
 /// <returns></returns>
 public static bool IsAlphanumeric(this System.String str)
 {
     return(str.All(char.IsLetterOrDigit));
 }
Ejemplo n.º 18
0
 public bool comprobarTipos(String precioPublicitar, String porcentajeVenta, String decimalPrecio, String decimalPorcentaje)
 {
     return (precioPublicitar.All(char.IsDigit) && porcentajeVenta.All(char.IsDigit) && decimalPrecio.All(char.IsDigit) && decimalPorcentaje.All(char.IsDigit));
 }
Ejemplo n.º 19
0
 /// <summary>
 /// Chequea que el string solo contenga digitos;
 /// </summary>
 /// <param name="value">String a chequear</param>
 /// <exception cref="ExcepcionesSKD.InformacionPersonalInvalidaException">
 /// Si el el valor contiene algún caracter que no sea dígito.
 /// </exception>
 private void CheckDigits(String value)
 {
     if (!value.All(char.IsDigit))
             throw new InformacionPersonalInvalidaException("La información de Telefono solo deben ser digitos.");
 }
Ejemplo n.º 20
0
        private static String validateAndCleanUpName(String name)
        {
            try
            {
                name = name.Replace('_', ' ');
                // be a bit careful with hypens - if it's before the first space, just remove it as
                // it's a separated firstname
                if (name.IndexOf(' ') > 0 && name.IndexOf('-') > 0 && name.IndexOf('-') < name.IndexOf(' '))
                {
                    name = name.Replace("-", "");
                }
                name = name.Replace('-', ' ');
                name = name.Replace('.', ' ');
                if (name.EndsWith("]") && name.Contains("["))
                {
                    name = name.Substring(0, name.LastIndexOf('['));
                }
                if (name.StartsWith("[") && name.Contains("]"))
                {
                    name = name.Substring(name.LastIndexOf(']') + 1);
                }
                for (int i = 0; i < 4; i++)
                {
                    if (name.Count() > 1 && Char.IsNumber(name[name.Count() - 1]))
                    {
                        name = name.Substring(0, name.Count() - 1);
                    }
                    else
                    {
                        break;
                    }
                }
                if (name.All(c=>Char.IsLetter(c) || c==' ' || c=='\'') && name.Length > 0) {
                    return name.Trim();
                }
            }
            catch (Exception)
            {

            }
            return null;
        }
Ejemplo n.º 21
0
        // Methods
        /// <summary>
        /// Creates a target <see cref="T:DataRecord"/> object that can be tested.
        /// </summary>
        /// <param name="columnNames">The column names.</param>
        /// <param name="values">The values.</param>
        /// <returns>The <see cref="T:DataRecord"/> created.</returns>
        private static DataRecord CreateDataRecord(String[] columnNames, Object[] values)
        {
            Debug.Assert(columnNames != null);
            Debug.Assert(columnNames.Length != 0);
            Debug.Assert(columnNames.All(columnName => columnName != null));
            Debug.Assert(values != null);
            Debug.Assert(values.Length != 0);
            Debug.Assert(columnNames.Length == values.Length);

            using (DataTable dataTable = new DataTable()) {
                DataColumn[] dataColumns = columnNames
                    .Select((columnName, i) => new DataColumn(columnName, values[i] != null ? values[i].GetType() : typeof(String)))
                    .ToArray();
                dataTable.Columns.AddRange(dataColumns);
                dataTable.Rows.Add(values);

                return dataTable.CreateDataReader().ReadAll().First();
            }
        }
Ejemplo n.º 22
0
 public bool comprobarTipos(String telefono)
 {
     return (telefono.All(char.IsDigit));
 }
Ejemplo n.º 23
0
        /* Invalidate Keys of type */
        public void InvalidateKeyOfParts(String[] Keys)
        {
            /* Iterate */
            lock (_Lock)
            {
                lCache.RemoveAll(mco => Keys.All(mco.Key.Contains));
            }

            /* Cleanup */
            GC.Collect();
        }
Ejemplo n.º 24
0
 public bool comprobarTipos(String valorInicial, String valorDecimal, String cantidadPorLote)
 {
     return (valorInicial.All(char.IsDigit) && valorDecimal.All(char.IsDigit) &&  cantidadPorLote.All(char.IsDigit));
 }
Ejemplo n.º 25
0
 private Boolean isHexValid(String value)
 {
     if (value.All(c => "0123456789ABCDEF".Contains(c)))
         return true;
     else
         return false;
 }
Ejemplo n.º 26
0
        // Methods
        /// <summary>
        /// Creates a target <see cref="T:IDataReader"/> object that can be tested.
        /// </summary>
        /// <param name="columnNames">The column names.</param>
        /// <param name="values">The values.</param>
        /// <returns>The <see cref="T:IDataReader"/> created.</returns>
        private static IDataReader CreateDataRecord(String[] columnNames, params IEnumerable<Object>[] values)
        {
            Debug.Assert(columnNames != null);
            Debug.Assert(columnNames.Length != 0);
            Debug.Assert(columnNames.All(columnName => columnName != null));

            using (DataTable dataTable = new DataTable()) {
                DataColumn[] dataColumns = columnNames
                    .Select((columnName, i) => new DataColumn(columnName, (values != null && values.Length > 0 && values[0].ElementAt(i) != null) ? values[0].ElementAt(i).GetType() : typeof(String)))
                    .ToArray();
                dataTable.Columns.AddRange(dataColumns);

                if (values != null && values.Length > 0) {
                    foreach (Object[] rowValues in values) {
                        dataTable.Rows.Add(rowValues);
                    }
                }

                return dataTable.CreateDataReader();
            }
        }
Ejemplo n.º 27
0
 //Creates hexadecimal color from sequence
 private Brush convertColorFromSeq(String s)
 {
     try
     {
         if (s.All(c => "actg".Contains(c)))
         {
             String color = "#";
             char[] array = s.ToArray();
             for (int i = 0; i < 4; i++)
             {
                 char c = char.ToLower(array[i]);
                 if (c == 'a') color += "99";
                 if (c == 'c') color += "bb";
                 if (c == 't') color += "dd";
                 if (c == 'g') color += "ff";
             }
             return (Brush)new BrushConverter().ConvertFromString(color); //To always ensure Opacity = 1, use i < 3 and initialize color = "#ff"
         }
         else { return Brushes.LightGray; }
     }
     catch (Exception exc) { 
         Console.WriteLine(exc);
         return Brushes.LightGray;
     }
 }
        public static bool IsAValidNumber(String number)
        {
            number = number.RemoveWhiteSpace();

            return (number.All(Char.IsNumber) && !String.IsNullOrEmpty(number));
        }
Ejemplo n.º 29
0
 public Boolean isNumber(String value)
 {
     return value.All(Char.IsDigit);
 }