Exemple #1
0
        public Config(String[] args)
        {
            if (args.Count() == 1 && args[0] == "/?")
            {
                Banners.About();
                throw new ConfigurationErrorsException(String.Empty);
            }
            else
            {
                if (args.LastOrDefault() == "/verbose")
                {
                    IsVerbose = true;
                    args = args.Take(args.Count() - 1).ToArray();
                }

                if (args.Count() != 3)
                {
                    throw new ConfigurationErrorsException("Expected three arguments as explained below.");
                }
                else
                {
                    ProjectFile = Path.GetFullPath(args[0]);
                    if (IsVerbose) Console.WriteLine("Resolved %ProjectFile as {0}.", ProjectFile.ToTrace());
                    if (!File.Exists(ProjectFile))
                    {
                        throw new ConfigurationErrorsException(String.Format(
                            "%ProjectFile (specified as \"{0}\") does not exist.", ProjectFile.ToTrace()));
                    }

                    ProjectDir = Path.GetDirectoryName(ProjectFile);
                    if (IsVerbose) Console.WriteLine("Resolved %ProjectDir as {0}.", ProjectDir.ToTrace());

                    TemplateFile = Path.GetFullPath(args[1]);
                    if (IsVerbose) Console.WriteLine("Resolved %TemplateFile as {0}.", TemplateFile.ToTrace());
                    if (!File.Exists(TemplateFile))
                    {
                        throw new ConfigurationErrorsException(String.Format(
                            "%TemplateFile (specified as \"{0}\") does not exist.", TemplateFile.ToTrace()));
                    }

                    DestinationFile = Path.GetFullPath(args[2]);
                    if (IsVerbose) Console.WriteLine("Resolved %DestinationFile as {0}.", DestinationFile.ToTrace());
                    if (!File.Exists(DestinationFile))
                    {
                        if (IsVerbose) Console.WriteLine("Destination file doesn't exist at {0}. Creating it...", DestinationFile.ToTrace());

                        var destinationDir = Path.GetDirectoryName(DestinationFile);
                        if (!Directory.Exists(destinationDir))
                        {
                            if (IsVerbose) Console.WriteLine("Destination file directory doesn't exist at {0}. Creating it...", destinationDir.ToTrace());
                            Directory.CreateDirectory(destinationDir);
                            if (IsVerbose) Console.WriteLine("Destination file directory successfully created at {0}.", destinationDir.ToTrace());
                        }

                        File.WriteAllText(DestinationFile, String.Empty);
                        if (IsVerbose) Console.WriteLine("Destination file successfully created at {0}.", DestinationFile.ToTrace());
                    }
                }
            }
        }
        //Search action for games
        public ActionResult Index(String search = "")
        {
            ViewBag.SearchError = search.Length > 50 ? "Search is limited to 50 characters" : "";
            search = String.Join("", search.Take(50));
            ViewBag.PreviewSearch = search;
            var games = db.Games.Where(x => x.Title.Contains(search)).Include(g => g.GameReviews);

            return View(games.ToList());
        }
        //Allows searching of gamers
        public ActionResult Index(String search = "")
        {
            ViewBag.SearchError = search.Length > 50 ? "Search is limited to 50 characters" : "";
            search = String.Join("", search.Take(50));
            ViewBag.PreviewSearch = search;
            //Generates the select statement for the search
            //See authors for an example
            var gamers = db.Gamers.Where(x => x.Name.Contains(search));

            return View(gamers.ToList());
        }
        public void PrincipalExtensions_Unit_IsInAllRoles_RolesContainsAllNecessaryRoles()
        {
            String name = "Chad.Greer";
            IIdentity identity = new GenericIdentity(name);
            String[] principalRoles = new String[] { "Admin", "Contributor", "Member" };
            IPrincipal principal = new GenericPrincipal(identity, principalRoles);
            String[] roles = principalRoles.Take(2).ToArray();

            Boolean actual = PrincipalExtensions.IsInAllRoles(principal, roles);
            Assert.AreEqual(true, actual);
        }
        //Search index for Game Reviews
        //Also the first page the users see when they connect to the site for the first time
        public ActionResult Index(String search = "")
        {
            ViewBag.SearchError = search.Length > 50 ? "Search is limited to 50 characters" : "";
            search = String.Join("", search.Take(50));
            ViewBag.PreviewSearch = search;

            //Generates the search sql
            //See Authors Action for example
            var gamereviews = db.GameReviews.Where(x => x.Title.Contains(search)).Include(g => g.Author).Include(g => g.Game);

            return View(gamereviews.ToList());
        }
 public void ParseLogger(String[] loggerParts, Int32 level) 
 {
     if (level == LoggerLevel) 
     {
         LoggerCount++;
         return;
     } 
     //do I have a child logger for this name?
     String name = loggerParts.Take(level + 1).Aggregate((s1, s2) => s1 + "." + s2);
     var cvm = Childs.SingleOrDefault(vm => vm.LoggerPrefix.Equals(name));
     if (cvm == null) 
     {
         cvm = new LoggerViewModel(name);
         Childs.Add(cvm);
     }
     cvm.ParseLogger(loggerParts, level + 1);
 }
        //Shows the Authors search page
        public ActionResult Index(String search = "")
        {
            ViewBag.SearchError = search.Length > 50 ? "Search is limited to 50 characters" : "";
            search = String.Join("", search.Take(50));
            ViewBag.PreviewSearch = search;

            //Select statement to the database
            //Automatically Generates code into query:

            var authors = db.Authors.Where(x => x.Name.Contains(search));
            //{SELECT 
            //[Extent1].[AuthorId] AS [AuthorId], 
            //[Extent1].[Name] AS [Name], 
            //[Extent1].[Genre] AS [Genre], 
            //[Extent1].[Biography] AS [Biography]
            //FROM [dbo].[Author] AS [Extent1]
            //WHERE [Extent1].[Name] LIKE @p__linq__0 ESCAPE N'~'}

            //Views route automatically to views of the same name
            return View(authors.ToList());
        }
        public int Parse(String[] commands)
        {
            int ret = 0;
            bool elseDetected = false;
            int conditionStart = 0;
            int conditionEnd = 0;
            int ifStart = 0;
            int ifEnd = 0;
            int elseStart = 0;
            int elseEnd = 0;

            int innerIfCount = 0;
            int innerThenCount = 0;

            for (int i = ret; i < commands.Length; i++ )
            {
                if (commands[i].ToUpper() == "IF")
                {
                    innerIfCount++;
                    continue;
                }
                if (commands[i].ToUpper() == "THEN")
                {
                    if (innerIfCount != innerThenCount)
                    {
                        innerThenCount++;
                    }
                    else
                    {
                        conditionStart = 0;
                        conditionEnd = i;
                        ret = i + 1;
                        break;
                    }
                }
            }

            innerIfCount = 0;
            int innerElseCount = 0;

            for (int i = ret; i < commands.Length; i++)
            {
                if (commands[i].ToUpper() == "IF")
                {
                    innerIfCount++;
                    continue;
                }
                if (commands[i].ToUpper() == "ELSE")
                {
                    if (innerIfCount != innerElseCount)
                    {
                        innerElseCount++;
                    }
                    else
                    {
                        ifStart = ret;
                        ifEnd = i;
                        ret = i + 1;
                        elseDetected = true;
                        break;
                    }
                }
            }

            innerIfCount = 0;
            int innerEndIfCount = 0;

            for (int i = ret; i < commands.Length; i++)
            {
                if (commands[i].ToUpper() == "IF")
                {
                    innerIfCount++;
                    continue;
                }
                if (commands[i].ToUpper() == "ENDIF")
                {
                    if (innerIfCount != innerEndIfCount)
                    {
                        innerEndIfCount++;
                    }
                    else
                    {
                        if (elseDetected)
                        {
                            elseStart = ret;
                            elseEnd = i;
                        }
                        else
                        {
                            ifStart = ret;
                            ifEnd = i;
                        }
                        ret = i + 1;
                        break;
                    }
                }
                else if (i == commands.Length - 1)
                {
                    if (elseDetected)
                    {
                        elseStart = ret;
                        elseEnd = i + 1;
                    }
                    else
                    {
                        ifStart = ret;
                        ifEnd = i + 1;
                    }
                    ret = i + 1;
                    break;
                }
            }

            Condition = commands.Take(conditionEnd).Skip(conditionStart).ToArray();
            IfCommands =  commands.Take(ifEnd).Skip(ifStart).ToArray();
            ElseCommands = commands.Take(elseEnd).Skip(elseStart).ToArray();

            return ret;
        }
 protected String FormatGuid(String guid) {
     return String.Format("{0}..{1}", new String(guid.Take(5).ToArray()), new String(guid.Skip(Math.Max(0, guid.Count() - 3)).Take(3).ToArray()));
 }