示例#1
0
        public FSSnapshot LoadSnapshot(
            ExtensionClasses classes,
            IEnumerable <string> files)
        {
            var fs = new FSSnapshot();

            foreach (var file in files.Where(file => File.Exists(Path.Combine(_rootPath, file))))
            {
                var cls = classes.GetClass(Path.GetExtension(file));

                var fileName = Path.IsPathRooted(file) ? file.Substring(_rootPath.Length) : file;

                switch (cls)
                {
                case eExtensionClass.Text:
                    fs.Files.Add(new FSTextFile()
                    {
                        Name    = fileName,
                        Content = File.ReadAllText(Path.Combine(_rootPath, file))
                    });
                    break;

                case eExtensionClass.Binary:
                    fs.Files.Add(new FSBinaryFile()
                    {
                        Name    = fileName,
                        Content = File.ReadAllBytes(Path.Combine(_rootPath, file))
                    });
                    break;
                }
            }

            return(fs);
        }
        public void ModifiedFilesTest()
        {
            var id = Guid.NewGuid();

            using (var tc = new Toolchain(id))
            {
                // write some content before setup rules
                File.WriteAllText(Path.Combine(tc.RootPath, "1.txt"), "content");
                File.WriteAllText(Path.Combine(tc.RootPath, "2.txt"), "content");

                tc.SetupRules(new[] { new ModifiedFilesRule() });
                File.WriteAllBytes(Path.Combine(tc.RootPath, "1.bin"), new byte[] { 128 });
                File.Move(Path.Combine(tc.RootPath, "2.txt"), Path.Combine(tc.RootPath, "3.txt"));

                var classes = new ExtensionClasses().Text("txt").Binary("bin");

                var result = tc.LoadSnapshot(classes);

                Assert.AreEqual(2, result.Files.Count);

                Assert.AreEqual(1, result.Files.OfType <FSTextFile>().Count());
                var textFile = result.Files.OfType <FSTextFile>().First();
                Assert.AreEqual("3.txt", textFile.Name);

                Assert.AreEqual(1, result.Files.OfType <FSBinaryFile>().Count());
            }
        }
        public void RegexMatchFilesTest()
        {
            var id = Guid.NewGuid();

            using (var tc = new Toolchain(id))
            {
                tc.SetupRules(new[] { new RegexMatchFilesRule()
                                      {
                                          Patterns = new List <string>()
                                          {
                                              "bin"
                                          }
                                      } });
                File.WriteAllText(Path.Combine(tc.RootPath, "1.txt"), "content");
                File.WriteAllBytes(Path.Combine(tc.RootPath, "1.bin"), new byte[] { 128 });

                var classes = new ExtensionClasses().Text("txt").Binary("bin");

                var result = tc.LoadSnapshot(classes);

                Assert.AreEqual(1, result.Files.Count);

                Assert.AreEqual(0, result.Files.OfType <FSTextFile>().Count());
                Assert.AreEqual(1, result.Files.OfType <FSBinaryFile>().Count());
            }
        }
        public RISCVIntegrationContext WithExtensionClasses(ExtensionClasses extensionClasses)
        {
            var result = Clone();

            result.ExtensionClasses = extensionClasses;

            return(result);
        }
 public FSSnapshot LoadSnapshot(ExtensionClasses classes)
 {
     return(new FSManager(RootPath)
            .LoadSnapshot(
                classes,
                _rules
                .SelectMany(r => r.MatchingFiles())
                .ToHashSet()));
 }
示例#6
0
        /// <summary>Gets the body of the extension class.</summary>
        /// <param name="className">The class name.</param>
        /// <returns>The body code</returns>
        /// <exception cref="InvalidOperationException">The extension class is not defined.</exception>
        public string GetExtensionClassBody(string className)
        {
            if (!ExtensionClasses.ContainsKey(className))
            {
                throw new InvalidOperationException("The extension class '" + className + "' is not defined.");
            }

            var match = Regex.Match(ExtensionClasses[className], "(.*?)class (.*?){(.*)}", RegexOptions.Singleline);

            return(match.Groups[3].Value);
        }
示例#7
0
 public void EmailValidator(object sender, EventArgs e)
 {
     if (ExtensionClasses.EmailValidation((sender as TextBox).Text))
     {
         ErrorLabel.Visible = false;
     }
     else
     {
         ErrorLabel.Visible = true;
     }
 }
示例#8
0
    /**
     * Shuffles the list of rewards and return the value at index 0, which will thus be a randomly chosen reward.
     * **/
    private ItemType GetNextRandomReward()
    {
        ExtensionClasses.Shuffle(m_rewardPool);
        m_itemTypeCache = m_rewardPool [0];
        switch (m_itemTypeCache)
        {
        case ItemType.COINS_100:
            m_coins100++;
            break;

        case ItemType.COINS_200:
            m_coins200++;
            break;

        case ItemType.COINS_500:
            m_coins500++;
            break;

        case ItemType.ITEM_01:
            m_item01++;
            break;

        case ItemType.ITEM_02:
            m_item02++;
            break;

        case ItemType.ITEM_03:
            m_item03++;
            break;
        }
        m_items++;
        if (showDebug)
        {
            Debug.Log(
                "COINS100: " + m_coins100 + " (" + Math.Round(m_coins100 / (float)m_items * 100f, 2) + "%) " +
                "COINS200: " + m_coins200 + " (" + Math.Round(m_coins200 / (float)m_items * 100f, 2) + "%) " +
                "COINS500: " + m_coins500 + " (" + Math.Round(m_coins500 / (float)m_items * 100f, 2) + "%) " +
                "ITEM01: " + m_item01 + " (" + Math.Round(m_item01 / (float)m_items * 100f, 2) + "%) " +
                "ITEM02: " + m_item02 + " (" + Math.Round(m_item02 / (float)m_items * 100f, 2) + "%) " +
                "ITEM03: " + m_item03 + " (" + Math.Round(m_item03 / (float)m_items * 100f, 2) + "%) ");
        }
        return(m_itemTypeCache);
    }