/* * 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; }
public bool IsPasswordCompliant(String password) { bool isCompliant = false; if(password.Length>=8 && password.Any(char.IsDigit) && password.Any(char.IsUpper) && password.Any(char.IsLower)) { isCompliant = true; } return isCompliant; }
/// <summary> /// Initializes a new instance of the <see cref="ArchiveGenerationParameters"/> class. /// </summary> /// <param name="args">The application's command line arguments.</param> public ArchiveGenerationParameters(String[] args) { if (args == null || !args.Any()) throw new InvalidCommandLineException(); var parser = new CommandLineParser(args); if (!parser.IsParameter(args.First())) throw new InvalidCommandLineException(); switch (args.First().ToLowerInvariant()) { case "-pack": Command = ArchiveGenerationCommand.Pack; ProcessPackParameters(args, parser); break; case "-list": Command = ArchiveGenerationCommand.List; ProcessListParameters(args, parser); break; default: throw new InvalidCommandLineException(); } }
/// <summary> /// Initializes a new instance of the <see cref="FontGenerationParameters"/> class. /// </summary> /// <param name="args">The application's command line arguments.</param> public FontGenerationParameters(String[] args) { if (args == null || !args.Any()) throw new InvalidCommandLineException(); var parser = new CommandLineParser(args.Skip(1)); if (parser.IsParameter(args.First())) { throw new InvalidCommandLineException(); } NoBold = parser.HasArgument("nobold"); NoItalic = parser.HasArgument("noitalic"); FontName = args.First(); FontSize = parser.GetArgumentOrDefault<Single>("fontsize", 16f); Overhang = parser.GetArgumentOrDefault<Int32>("overhang", 0); PadLeft = parser.GetArgumentOrDefault<Int32>("pad-left", 0); PadRight = parser.GetArgumentOrDefault<Int32>("pad-right", 0); SuperSamplingFactor = parser.GetArgumentOrDefault<Int32>("supersample", 2); if (SuperSamplingFactor < 1) SuperSamplingFactor = 1; SourceText = parser.GetArgumentOrDefault<String>("sourcetext"); SourceFile = parser.GetArgumentOrDefault<String>("sourcefile"); SourceCulture = parser.GetArgumentOrDefault<String>("sourceculture"); if (SourceText != null && SourceFile != null) throw new InvalidCommandLineException("Both a source text and a source file were specified. Pick one!"); SubstitutionCharacter = parser.GetArgumentOrDefault<Char>("sub", '?'); }
public static List<SPFile> GetFiles(string webUrl, string libraryTitle, String[] extensions = null) { var context = new ClientContext(webUrl); var web = context.Web; var list = web.Lists.GetByTitle(libraryTitle); var files = list.RootFolder.Files; context.Load(files, fs => fs.Include(f => f.Name, f => f.ETag, f => f.ServerRelativeUrl, f => f.ListItemAllFields)); context.ExecuteQuery(); var items = new List<SPFile>(); foreach (File file in files) if (extensions == null || extensions.Any(ext => file.Name.EndsWith(ext))) { var listitem = file.ListItemAllFields; items.Add(new SPFile() { Name = file.Name.Substring(0, file.Name.LastIndexOf('.')), Extension = file.Name.Substring(file.Name.LastIndexOf('.')), ETag = file.ETag, RemoteUrl = new Uri(webUrl).Server() + file.ServerRelativeUrl, Category = listitem.FieldValues.GetValue("Category") }); } return new List<SPFile>(items.OrderBy(f => f.Name)); }
private static Int32 Main(String[] args) { if (!args.Any()) { var assemblyFileName = Path.GetFileName( Assembly.GetEntryAssembly().Location ); Console.Error.WriteLine($"Usage: {assemblyFileName} outputDirectory"); return 2; } try { var writer = new SourceFileWriter(args[0]); foreach (var command in ShellployMetadata.GetCommands()) { Console.WriteLine($"Generating {command.ClassName}..."); var targetUnit = new CommandCodeGenerator(command) .GenerateCompileUnit(); writer.Write(targetUnit); } Console.WriteLine("Done."); return 0; } catch (Exception exc) { Console.Error.WriteLine(exc); return 1; } }
bool isValidPath(String path) { if (path.Any(c => Path.GetInvalidPathChars().Contains(c))) { return (false); } return (Path.IsPathRooted(path)); }
public StatManager(String SaveStatePath) { if (string.IsNullOrEmpty(SaveStatePath)) { logger.Error("SaveStatePath was null or empty."); throw new ArgumentNullException("SaveStatePath Can't be Null or Empty String. "); } if (SaveStatePath.LastIndexOfAny(Path.GetInvalidPathChars()) >= 0) { logger.Error("Invalid Path Characters In SaveStatePath=\"{0}\")", SaveStatePath); throw new ArgumentException("Invalid Characters In Path"); } if (SaveStatePath.Any( x => char.IsWhiteSpace ( x ))) { logger.Error("Whitespace Characters In SaveStatePath=\"{0}\" ", SaveStatePath); throw new ArgumentException("WhiteSpace Characters In Path"); } logger.Info("Called with (SaveStatePath=\"{0}\")", SaveStatePath); LoadSaveState(SaveStatePath); _savestatepath = SaveStatePath; }
public static int CalculateDyingYear(String name) { if (name.Any(x => !char.IsLetter(x))) throw new ArgumentException("name musst be a name"); int result = 0; foreach (char c in name.ToLower()) { result += c - 'a' + 1; } return result % 100; }
/// <summary> /// Creates an instance of the version control system with the given filesystem and root. /// </summary> /// <param name="root">The root of the version control system, relative to the file system.</param> /// <param name="fileSystemAdaptee">The file system to perform IO operations on.</param> protected AbstractVersionControlSystem(String root, IFileSystem fileSystemAdaptee) : base(root, fileSystemAdaptee) { // Parse the root to make sure it ends with a path separator root = ((root.EndsWith(FileSystem.PathSeparator) || !root.Any()) ? String.Empty : FileSystem.PathSeparator); // Verify that the version dir exists var version = root + FileSystem.VERSION_DIR; if (!Exists(version)) { CreateDirectory(version); } }
static void Main(String[] args) { if (!args.Any()) { String src = @" int printf(char *, ...); int main(int argc, char **argv) { printf(""%d"", argc); return 0; } "; Compiler compiler = Compiler.FromSource(src); Console.WriteLine(compiler.Assembly); } else { Compiler compiler = Compiler.FromFile(args[0]); Console.WriteLine(compiler.Assembly); } }
/// <summary>根据字段名数组获取字段数组</summary> /// <param name="table"></param> /// <param name="names"></param> /// <returns></returns> public static IDataColumn[] GetColumns(this IDataTable table, String[] names) { if (names == null || names.Length < 1) return null; //List<IDataColumn> list = new List<IDataColumn>(); //foreach (String item in names) //{ // IDataColumn dc = table.GetColumn(item); // if (dc != null) list.Add(dc); //} //if (list.Count < 1) return null; //return list.ToArray(); return table.Columns.Where(c => names.Any(n => c.Is(n))).ToArray(); }
private bool ParseParameters( String[] parameters, out string input_file, out string output_file ) { input_file = null; output_file = null; //--help -help /help /? -? string general_help_str = "Saleae Serial Export txt to bin converter\n"; general_help_str += "usage: thing.exe input_file output_file\n"; var help_parameters = new string[] { "--help", "-help", "-h", "/?", "/help", "-?" }; if( parameters.Any( x => help_parameters.Contains( x.ToLower() ) ) || parameters.Count() == 0 ) { Console.WriteLine( general_help_str ); return false; } if( parameters.Count() != 2 ) { Console.WriteLine( "expected 2 parameters" ); return false; } input_file = parameters[ 0 ]; output_file = parameters[ 1 ]; if( System.IO.File.Exists( input_file ) == false ) { Console.WriteLine( "input file " + input_file + " does not exist" ); return false; } string output_folder = new System.IO.FileInfo( output_file ).Directory.FullName; if( System.IO.Directory.Exists( output_folder ) == false ) { Console.WriteLine( "output file directory " + output_folder + " does not exist" ); return false; } return true; }
/// <summary> /// Does the URL contain invalid characters? /// </summary> /// <param name="url">The URL</param> /// <returns>True if the URL contains invalid characters.</returns> public static bool ContainsInvalidURLCharacters(String url) { return url.Any(ch => ch > 255); }
static Boolean IsTextExtension(String url) { String[] extensions = new String[] { "txt", "csv", "html", "htm" }; return extensions.Any(x => url.EndsWith("." + x)); }
/// <summary> /// Helper for check if we are a command in the command line arguments /// </summary> static bool HasCommand(String[] args, String command) { if (args == null || args.Length == 0 || String.IsNullOrWhiteSpace(command)) return false; return args.Any(a => String.Equals(a, command, StringComparison.OrdinalIgnoreCase)); }
/// <summary> /// Does hmm comput to see if exercise was found or not /// </summary> /// <param name="exerciseToCheck"></param> /// <returns></returns> static Boolean exerciseFound(String exerciseToCheck) { if (!avgFramesPerLabel_Training.ContainsKey(exerciseToCheck)){ log.Error("Invalid exercise name! " + exerciseToCheck + " not found in average frames per label dictionary"); return false; } // only consider exercises if the number of frames are within a threshold double frameCount = observationSequences[0].Count(); double avgFrameCountForExc = avgFramesPerLabel_Training[exerciseToCheck] ; double frameDifference = avgFrameCountForExc - frameCount; double frameDifferenceThreshold = Convert.ToInt32(avgFrameCountForExc * Constants.FRAME_THRESHOLD_PERCENT); if (Math.Abs(frameDifference) > frameDifferenceThreshold) { if (frameCount > avgFrameCountForExc) { clearObservations(); } return false; } if (debugging) { log.Debug("Frames DIfference is: " + frameDifference + ", avg frames for exercise: " + exerciseToCheck + " is: " + avgFrameCountForExc + ", Frames Threshold is " + frameDifferenceThreshold + ", Frame Differ Count is: " + frameCount); } //prepare for hmm computations double[][][] inputs = new Double[numJoints][][]; for (int i = 0; i < numJoints; i++) { inputs[i] = Sequence.Preprocess(observationSequences[i].ToArray()); } //do hmm computation to find closest exercise match for each joint String[] outputLabels = new String[inputs.Length]; String label; for (int i = 0; i < inputs.Length; i++) { int index = hmms[i].Compute(inputs[i]); label = (index >= 0) ? databases[i].Classes[index] : "NOT FOUND"; outputLabels[i] = label; } //determine if exercise is done by analyzing evidence in each joint for the given exercise if (outputLabels.Any(x => x != "NOT FOUND")) { //return most occuring exercise label by considering labels for all the joints label = outputLabels.Where(x => x != "NOT FOUND").GroupBy(x => x).OrderByDescending(x => x.Count()).First().Key; int numLabels = outputLabels.Where(x => x == label).Count(); if (numLabels < Constants.MIN_NUM_MATCHED_JOINTS) { label = "NOT FOUND"; } } else { label = "NOT FOUND"; } if (label == exerciseToCheck) { return true; } return false; }
/// <summary>根据字段名数组获取字段数组</summary> /// <param name="table"></param> /// <param name="names"></param> /// <returns></returns> public static IDataColumn[] GetColumns(this IDataTable table, String[] names) { if (names == null || names.Length < 1) return new IDataColumn[0]; return table.Columns.Where(c => names.Any(n => c.Is(n))).ToArray(); }
public bool InvokeActions(String[] actions) { if (AppContext.Workflow != null) foreach (var a in AppContext.Workflow.RegisteredActions) { if (actions.Any(s => a.ContainsWorkflowAction(s))) { a.InvokeAll(AppContext); return true; } } return false; }
/// <summary> /// Parses the changes into change objects. /// </summary> /// <param name="text">The text to parse change objects from.</param> /// <returns>A list of change objects. NOTE: If no items have been deleted, index = 0 will be null. If no items have been created, index = 1 will be null</returns> public static IList<AbstractChange> ParseChanges(String[] text) { if (text.Any(s => s == null)) throw new ArgumentNullException("text"); if (!text.Any()) throw new ArgumentException("Argument was empty"); IList<AbstractChange> parsedChanges = new List<AbstractChange>(); ItemsCreatedChange itemsCreated = null; ItemsDeletedChange itemsDeleted = null; parsedChanges.Add(itemsDeleted); parsedChanges.Add(itemsCreated); int pointer = 0; while (pointer < text.Length) { if (text[pointer].StartsWith(AbstractChange.ItemCreationMark)) { // An item has been created if (parsedChanges[1] == null) { parsedChanges[1] = new ItemsCreatedChange(); } // The item is a folder if (text[pointer].EndsWith(FileSystem.PathSeparator)) { if (parsedChanges[1] is ItemsCreatedChange) { ((ItemsCreatedChange)parsedChanges[1]).CreateItem(new FolderCreation(text[pointer].Substring(AbstractChange.ItemCreationMark.Length))); } pointer++; } else { IList<String> fileContents = new List<string>(); String createdFilePath = text[pointer].Substring(AbstractChange.ItemCreationMark.Length); pointer++; while (pointer < text.Length) { // No more modifications for this file if (text[pointer].Equals(AbstractChange.BlockSeparatorMark)) break; // Line insertion if (text[pointer].StartsWith(AbstractChange.LineInsertionMark)) { String lineNumber = text[pointer].Substring(AbstractChange.LineInsertionMark.Length); int tmp = lineNumber.IndexOf(AbstractChange.LineInsertionMark); String line = lineNumber.Substring(tmp + AbstractChange.LineInsertionMark.Length); fileContents.Add(line); pointer++; } } if (parsedChanges[1] is ItemsCreatedChange) { ((ItemsCreatedChange)parsedChanges[1]).CreateItem(new FileCreation(createdFilePath, fileContents.ToArray())); } } } else if (text[pointer].StartsWith(AbstractChange.ItemDeletionMark)) { // An item has been deleted String path = text[pointer].Substring(AbstractChange.ItemDeletionMark.Length); if (parsedChanges[0] == null) { parsedChanges[0] = new ItemsDeletedChange(); } if (parsedChanges[0] is ItemsDeletedChange) { ((ItemsDeletedChange)parsedChanges[0]).DeleteItem(path); } pointer++; } else if (text[pointer].StartsWith(AbstractChange.ItemModificationMark)) { // A file has been modified String path = text[pointer].Substring(AbstractChange.ItemModificationMark.Length); FileModifiedChange modified = new FileModifiedChange(path); pointer++; // Iterate through the file modifications until there are no more (end of file or linebreak) while (pointer < text.Length) { // No more modifications for this file if (text[pointer].Equals(AbstractChange.BlockSeparatorMark)) break; // Line insertion if (text[pointer].StartsWith(AbstractChange.LineInsertionMark)) { String lineNumber = text[pointer].Substring(AbstractChange.LineInsertionMark.Length); int tmp = lineNumber.IndexOf(AbstractChange.LineInsertionMark); int number = int.Parse(lineNumber.Substring(0, tmp)); String line = lineNumber.Substring(tmp + AbstractChange.LineInsertionMark.Length); modified.AddInsertion(number, line); pointer++; } // Line deletion if (text[pointer].StartsWith(AbstractChange.LineDeletionMark)) { String lineNumber = text[pointer].Substring(AbstractChange.LineDeletionMark.Length); int tmp = lineNumber.IndexOf(AbstractChange.LineDeletionMark); int number = int.Parse(lineNumber.Substring(0, tmp)); String line = lineNumber.Substring(tmp + AbstractChange.LineDeletionMark.Length); modified.AddDeletion(number, line); pointer++; } } parsedChanges.Add(modified); } if (pointer < text.Length && text[pointer].Equals(AbstractChange.BlockSeparatorMark)) { // Current line is empty pointer++; } } return parsedChanges; }
static void Main(String[] args) { if (!args.Any()) { String src = @" int printf(char *, ...); int main(int argc, char **argv) { printf(""%d"", argc); return 0; } "; Compiler compiler = Compiler.FromSrc(src); Console.WriteLine(compiler.assembly); } else { // Console.WriteLine(System.IO.Directory.GetCurrentDirectory()); Compiler compiler = Compiler.FromFile(args[0]); Console.WriteLine(compiler.assembly); } // Scanner scanner = new Scanner(); // scanner.src = // @" //int foo() { // return 0; //} //struct S { // int a; //}; //int printf(char *s, int); //int main(int argc, char **argv) { // int b = 3 * 4; // char c; // float local_variable_2; // double local_variable_3; // const int * const * volatile a[3][4]; // struct S s; // s; // b; // foo(); // 3.25f; // ""3.0""; // c; // printf(""%d"", 3); // if (3) 4; // b++; //} // "; // scanner.src = // @" //struct B { // int b1; // int b2; //}; //struct A { // int a1; // int a2; // struct B b; //}; //int main() { // struct A a = { 1, 1, { {1} , 1 } }; //} //"; // scanner.src = @" //int printf(char *, int); //int i; //int main() { // int a; // struct S { // int member; // } s; // a = 1; // printf(""%d\n"", (char)a - 1); // printf(""%d\n"", s.member = 10); //} //"; // scanner.src = @" //int main() { // int arr[] = { 1, 2, 3 }; //} //"; // scanner.src = @" //int printf(char *, int); //void *malloc(unsigned int nbytes); //typedef struct Node { // int value; // struct Node *next; //} Node; //Node *cons(int value, Node *tl) { // Node *hd = malloc(sizeof(struct Node)); // hd->value = value; // hd->next = tl; // return hd; //} //void print_list(Node *hd) { // Node *cur = hd; // for (; cur != (void *)0; cur = cur->next) { // printf(""%d\t"", cur->value); // } //} //void print_list_recursive(Node *hd) { // if (hd != (void *)0) { // printf(""%d\t"", hd->value); // print_list_recursive(hd->next); // } //} //int main() { // Node *hd = cons(2, cons(1, cons(0, (void *)0))); // print_list(hd); // print_list_recursive(hd); // return 0; //} //"; // scanner.Lex(); // Console.WriteLine("Source code:"); // Console.WriteLine("======================"); // Console.WriteLine(scanner.src); // Console.WriteLine("Tokens:"); // Console.WriteLine("======================"); // Console.WriteLine(scanner); // List<Token> tokens = scanner.tokens; // SyntaxTree.TranslnUnit unit; // if (_translation_unit.Parse(tokens, 0, out unit) != tokens.Count - 1) { // throw new InvalidOperationException("Error: not finished parsing"); // } // Tuple<AST.Env, AST.TranslnUnit> ast = unit.GetTranslationUnit(); // //AST.TStructOrUnion type = (AST.TStructOrUnion)ast.Item1.Find("struct A").type; // //AST.MemberIterator iter = new AST.MemberIterator(type); // //iter.Read(new AST.TLong()); // //iter.Next(); // //iter.Read(new AST.TLong()); // //iter.Next(); // //iter.Read(new AST.TLong()); // //iter.Next(); // //iter.Read(new AST.TLong()); // CGenState state = new CGenState(); // ast.Item2.CodeGenerate(state); // Console.WriteLine("x86 Assembly:"); // Console.WriteLine("======================"); // Console.WriteLine(state); }
static Boolean IsKeyWord(String name) { if (String.IsNullOrEmpty(name)) return false; // 特殊处理item if (String.Equals(name, "item", StringComparison.OrdinalIgnoreCase)) return true; // 只要有大写字母,就不是关键字 if (name.Any(c => c >= 'A' && c <= 'Z')) return false; foreach (CodeDomProvider item in CGS) { if (!item.IsValidIdentifier(name)) return true; } return false; }
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> /// Invalid Chars are: " < > | and all chars lower than ASCII value 32 /// </summary> /// <remarks>Ignores Unix File Systems</remarks> /// <param name="path">Path to check</param> public static void ThrowIfPathContainsInvalidChars(String path) { if (path.Any(currentChar => currentChar < 32 || currentChar == '\"' || currentChar == '<' || currentChar == '>' || currentChar == '|')) { throw new Exception("Path contains invalid characters" + path); } }
private Panel CreateExistingWorldInterface(String[] worldNames) { var panel = new Panel(ControlManager.Manager) { Width = 856, Height = 467, AutoScroll = true, Left = 300, Top = 50 }; panel.Init(); ControlManager.Add(panel); if (!worldNames.Any()) { var label = new Label(ControlManager.Manager) { Height = 50, Left = 20, Width = 400, Text = "There are no existing worlds to edit!\nSelect the Create New World tab to create one." }; panel.Add(label); return panel; } var existingWorldLabel = new Label(ControlManager.Manager) { Text = "Existing World :: ", Width = 200, Left = 16, Top = 16, Parent = panel }; var worldNamesSelection = new ComboBox(ControlManager.Manager) { Width = 200, Parent = panel, Top = 16, Left = existingWorldLabel.Left + existingWorldLabel.Width + 20 }; worldNamesSelection.Items.AddRange(worldNames); worldNamesSelection.Init(); worldNamesSelection.ItemIndex = 0; worldNamesSelection.Left = existingWorldLabel.Left + existingWorldLabel.Width + 16; panel.Add(worldNamesSelection); var beginWorldEditor = new Button(ControlManager.Manager) { Text = "Load world", Top = 200, Left = 100, Width = 200 }; beginWorldEditor.Init(); beginWorldEditor.Click += (sender, args) => LoadExistingWorld(worldNamesSelection.Text); panel.Add(beginWorldEditor); return panel; }
/// <summary>是否关键字</summary> /// <param name="name"></param> /// <returns></returns> static Boolean IsKeyWord(String name) { if (String.IsNullOrEmpty(name)) return false; // 特殊处理item if (String.Equals(name, "item", StringComparison.OrdinalIgnoreCase)) return true; // 只要有大写字母,就不是关键字 if (name.Any(c => c >= 'A' && c <= 'Z')) return false; return !_CG.IsValidIdentifier(name); }
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(); }
/// <summary> /// Creates a FileSystemAdapter that wraps a given file system with the only difference that the adapter adds the /// given root to allow use in sub-directories to the file system. /// </summary> /// <param name="root">The root of the file system, relative to the given file system.</param> /// <param name="fileSystemAdapteeile system to wrap.</param> public FileSystemAdapter(String root, IFileSystem fileSystemAdaptee) { FileSystemAdaptee = fileSystemAdaptee; Root = root + ((root.EndsWith(InputOutputLayer.FileSystem.PathSeparator) || !root.Any()) ? String.Empty : InputOutputLayer.FileSystem.PathSeparator); }