Пример #1
0
        /*
         *
         *                      // load file
         *
         */

        /// <summary>
        /// Get the handler dedicated to filename
        /// </summary>
        /// <remarks>
        /// DON'T PUT LOGGING IN HERE!
        /// </remarks>
        private FileHandlerBase getHandler(String filename)
        {
            if (filename == null)
            {
                return(null);
            }

            if (FileHandlers.ContainsKey(filename))
            {
                return(FileHandlers[filename]);
            }

            String extension = System.IO.Path.GetExtension(filename);

            if (TextFileExtensions.Any(extension.Contains))
            {
                TextFileHandler handler = new TextFileHandler(filename);
                FileHandlers.Add(filename, handler);
                return(handler);
            }
            else
            {
                BinaryFileHandler handler = new BinaryFileHandler(filename);
                FileHandlers.Add(filename, handler);
                return(handler);
            }
        }
        public async Task FileDoesNotExistTestAsync()
        {
            string inputFile = @".\SampleInputFiles\George.txt";

            TextFileHandler tfh = new TextFileHandler();
            FileInfo fi = new FileInfo(inputFile);

            Dictionary<string, long> count = await tfh.GetWordCount(fi);
        }
        public async Task TestMethod_FiveHundredWords_LineBreaks()
        {
            string inputFile = @".\FiveHundredWords_LineBreaks.txt";

            TextFileHandler tfh = new TextFileHandler();
            FileInfo fi = new FileInfo(inputFile);
            Dictionary<string, long> count = await tfh.GetWordCount(fi);

            Assert.AreEqual(FileWordCounts.FiveHundredWordFile, count.Values.Sum());
        }
        public async Task TestMethod3()
        {
            string inputFile = @".\Immanuel Kant - Critique of Pure Reason.txt";

            TextFileHandler tfh = new TextFileHandler();
            FileInfo fi = new FileInfo(inputFile);
            Dictionary<string, long> count = await tfh.GetWordCount(fi);

            //Assert.AreEqual(211731, count);  // Word Count based on MS Word
            //Assert.AreEqual(193392, count);  // Word Count based on string.Split() over the entire file
            Assert.AreEqual(FileWordCounts.CritiqueofPureReason, count.Values.Sum());
        }
        public async Task TestMethod2()
        {
            string inputFile = @".\George Berkeley - Three Dialogues.txt";

            TextFileHandler tfh = new TextFileHandler();
            FileInfo fi = new FileInfo(inputFile);
            Dictionary<string, long> count = await tfh.GetWordCount(fi);

            //Assert.AreEqual(39105, count);  // Word Count based on MS Word
            //Assert.AreEqual(36532, count);  // Word Count based on string.Split() over the entire file
            Assert.AreEqual(FileWordCounts.ThreeDialogues, count.Values.Sum());
        }
        public async Task TestMethod1()
        {
            string inputFile = @".\George Berkeley - Principles of Human Knowledge.txt";

            TextFileHandler tfh = new TextFileHandler();
            FileInfo fi = new FileInfo(inputFile);
            Dictionary<string, long> count = await tfh.GetWordCount(fi);

            //Assert.AreEqual(39951, count);  // Word Count based on MS Word
            //Assert.AreEqual(36600, count);  // Word Count based on string.Split() over the entire file
            Assert.AreEqual(FileWordCounts.PrinciplesofHumanKnowledge, count.Values.Sum());
        }
        public async Task TestMethod6()
        {
            string inputFile = @".\Locke, John - Essay Concerning Humane Understanding, Vol 2.txt";

            TextFileHandler tfh = new TextFileHandler();
            FileInfo fi = new FileInfo(inputFile);
            Dictionary<string, long> count = await tfh.GetWordCount(fi);

            //Assert.AreEqual(127959, count);  // Word Count based on MS Word
            //Assert.AreEqual(117320, count);  // Word Count based on string.Split() over the entire file
            Assert.AreEqual(FileWordCounts.EssayConcerningHumaneUnderstandingVol2, count.Values.Sum());
        }
        public async Task TestMethod4()
        {
            string inputFile = @".\Leibniz, Gottfried - Theodicy.txt";

            TextFileHandler tfh = new TextFileHandler();
            FileInfo fi = new FileInfo(inputFile);
            Dictionary<string, long> count = await tfh.GetWordCount(fi);

            //Assert.AreEqual(192328, count);  // Word Count based on MS Word
            //Assert.AreEqual(183062, count);  // Word Count based on string.Split() over the entire file
            Assert.AreEqual(FileWordCounts.Theodicy, count.Values.Sum());
        }
        public void ReadfromDataFile(string InputFilePath)
        {
            var lines2 = TextFileHandler.ReadLinesOfFile(InputFilePath);

            for (int i = 0; i < lines2.Length; i++)
            {
                var js = JsonConvert.DeserializeObject <DownloadFile>(lines2[i]);
                if (!storedDls.ContainsKey(js.sha2))
                {
                    storedDls.Add(js.sha2, js);
                }
            }
        }
Пример #10
0
        public void writeLine(String output, String fileName)
        {
            if (output == null || fileName == null)
            {
                return;
            }
            if (!Ready)
            {
                return;
            }
            TextFileHandler textHandler = getHandler(fileName) as TextFileHandler;

            if (textHandler != null)
            {
                textHandler.WriteLine(output);
            }
        }
        internal async Task <(MalwareDTO, HttpStatusCode)> Fetch(string key)
        {
            var httpRequestMessage = new HttpRequestMessage
            {
                Method     = HttpMethod.Get,
                RequestUri = new Uri(@"https://www.virustotal.com/api/v3/files/" + key /*"https://raw.githubusercontent.com/BlackPhlox/cowrie-logviewer-data-analysis-tool/master/cowrie-logviewer-data-analysis-tool/test.json"*/),
                Headers    =
                {
                    { HttpRequestHeader.Accept.ToString(), "*/*"                    },
                    { "x-apikey",                          File.ReadAllText(TextFileHandler.GetSrcPath("Data", "virustotalapi.secret"))}
                }
            };

            var response = await Client.SendAsync(httpRequestMessage);

            var res_out = await response.Content.ReadAsStringAsync();

            MalwareDTO malData = JsonConvert.DeserializeObject <MalwareDTO>(res_out);

            return(malData, response.StatusCode);
        }
 // Use this for initialization
 void Start()
 {
     this.save_file_handler = new TextFileHandler("Assets/Resources/player_scores.txt");
     this.LoadSavedScores();
     this.InitPlayer();
     // Create the toggle_list before doing anything else related to the toggle_list
     this.toggle_list = GameObject.FindObjectsOfType <Toggle>();
     this.InitToggleNameDictionary();
     this.InitToggleStateDictionary();
     foreach (Toggle toggle in this.toggle_list)
     {
         //Add listener for when the state of the Toggle changes, to take action
         toggle.onValueChanged.AddListener(delegate {
             UpdateScoreText();
         });
     }
     this.UpdateScoreText();
     // TODO: Add a save and reset button to the scene
     //this.save_and_reset_button = this.GetComponent<Button>();
     //this.save_and_reset_button.onClick.AddListener(SaveAndReset);
 }
Пример #13
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            try {
                var usn = txtUsername.Text;
                var psw = txtPassword.Text;
                if (string.IsNullOrWhiteSpace(usn))
                {
                    MessageBox.Show(@"Please enter username"); return;
                }
                if (string.IsNullOrWhiteSpace(psw))
                {
                    MessageBox.Show(@"Please enter password"); return;
                }

                var crd         = TextFileHandler.ReadFile(@"Resource\Cred.txt");
                var credentials = crd.Split('░');
                var susn        = credentials[0];
                var spsw        = credentials[1];
                if (susn.Equals(usn) && spsw.Equals(psw))
                {
                    if (hm == null || hm.IsDisposed)
                    {
                        hm = new Home();
                    }
                    hm.Show();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show(@"Incorrect username or password"); return;
                }
            }
            catch (Exception exception) {
                ErrorLogger.Log("Error occured in login", exception);
            }
        }
Пример #14
0
 public FileHandlerController()
 {
     this.textHandler    = new TextFileHandler();
     this.archiveHandler = new ArchiveFileHandler(this.textHandler);
 }
 public void TestInitialize()
 {
     underTest = new TextFileHandler();
 }
Пример #16
0
        static void Main(string[] args)
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            GaussMethod gauss = new GaussMethod(num, num);

            gauss.RandomInit(num, num);

            Task <string> rightStringTask  = new Task <string>(() => GaussMethod.ArrayToString(gauss.rightPart));
            Task <string> matrixStringTask = new Task <string>(() => GaussMethod.MatrixToString(gauss.matrix));

            Task[] tasks1 = new Task[2] {
                rightStringTask, matrixStringTask
            };
            for (int i = 0; i < tasks1.Length; i++)
            {
                tasks1[i].Start();
            }
            Task.WaitAll(tasks1);


            Task first  = TextFileHandler.WriteToFile(TextFileHandler.RIGHT_PART_FILE, rightStringTask.Result);
            Task second = TextFileHandler.WriteToFile(TextFileHandler.MATRIX_FILE, matrixStringTask.Result);
            Task third  = TextFileHandler.WriteSizeInfoToFile(TextFileHandler.SIZE_INFO_FILE, gauss);

            Task[] tasks2 = new Task[3] {
                first, second, third
            };

            for (int i = 0; i < tasks2.Length; i++)
            {
                tasks2[i].GetAwaiter().GetResult();
            }
            Task.WaitAll(tasks2);

            GaussMethod gaussMethod = null;

            Task <GaussMethod> info = new Task <GaussMethod>(() => TextFileHandler.ReadSizeInfoFromFile(TextFileHandler.SIZE_INFO_FILE));

            info.Start();
            info.Wait();

            gaussMethod = info.Result;

            Task fouth = TextFileHandler.ReadArraytFromFile(TextFileHandler.RIGHT_PART_FILE, gaussMethod.rightPart);
            Task fifth = TextFileHandler.ReadMatrixFromFile(TextFileHandler.MATRIX_FILE, gaussMethod.matrix);

            Task[] tasks3 = new Task[2] {
                fouth, fifth
            };
            for (int i = 0; i < tasks3.Length; i++)
            {
                tasks3[i].GetAwaiter().GetResult();
            }
            Task.WaitAll(tasks3);

            //Console.WriteLine(GaussMethod.ArrayToString(gaussMethod.rightPart));
            //Console.WriteLine(GaussMethod.MatrixToString(gaussMethod.matrix));

            gaussMethod.SolveMatrix();

            Task sixth = TextFileHandler.WriteToFile(TextFileHandler.RESULT_FILE, GaussMethod.ArrayToString(gaussMethod.result));

            sixth.GetAwaiter().GetResult();

            //Console.WriteLine(gaussMethod.ToString());

            stopwatch.Stop();
            TimeSpan ts          = stopwatch.Elapsed;
            string   elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00000000}",
                                                 ts.Hours, ts.Minutes, ts.Seconds,
                                                 ts.Milliseconds / 10);

            Console.WriteLine("RunTime: " + elapsedTime);

            Console.ReadKey();
        }