Beispiel #1
0
        private void GetPositionIndex()
        {
            Console.Clear();

            try
            {
                Console.WriteLine("Informe o ID");
                long idBusca = long.Parse(Console.ReadLine());

                StrFileIndice         sfi = new StrFileIndice();
                BinarySearchAlgorithm bsa = new BinarySearchAlgorithm();
                if (bsa.BinarySearchById(idBusca, strNameFileIndice, ref sfi))
                {
                    Console.WriteLine("Índice encontrado.");
                    Console.WriteLine(string.Format("ID: {0}|Posição: {1}", sfi.Id, sfi.Posicao));
                }
                else
                {
                    Console.WriteLine("Índice ñ encontrado.");
                }

                Console.WriteLine("Pressione uma tecla para continuar.");
                Console.ReadKey();
            }
            catch (Exception)
            {
                Console.WriteLine("Dados inválidos.");
                Console.WriteLine("Pressione uma tecla para continuar.");
                Console.ReadKey();
            }
        }
        public void MethodTestGravaDados()
        {
            string path = Path.GetDirectoryName(Path.GetDirectoryName(Directory.GetCurrentDirectory()));

            path = path.Replace("\\UnitTestProjeto\\bin", "");
            string strNameFile       = path + "\\ArquivoDados.txt";
            string strNameFileIndice = path + "\\ArquivoIndice.txt";

            List <ITweet> listaTweets = new List <ITweet>();
            Tweets        tweets      = new Tweets();

            listaTweets.AddRange(tweets.BuscarTweets("", "", "", "", "#RockBand"));

            Principal p = new Principal();

            p.strNameFile       = strNameFile;
            p.strNameFileIndice = strNameFileIndice;
            p.GravarDados(listaTweets);
            BinarySearchAlgorithm bsa    = new BinarySearchAlgorithm();
            StrFileIndice         objeto = new StrFileIndice();

            if (bsa.BinarySearchById(1170023482421325824, strNameFileIndice, ref objeto))
            {
                Assert.AreEqual(1170023482421325824, objeto.Id);
            }
        }
Beispiel #3
0
        private void GetAllIndiceStructureValue()
        {
            try
            {
                using (FileStream readStream = new FileStream(strNameFileIndice, FileMode.Open))
                {
                    while (readStream.Position < readStream.Length)
                    {
                        if (readStream.Position > 0)
                        {
                            readStream.Position += 1;
                        }

                        BinarySearchAlgorithm bsa     = new BinarySearchAlgorithm();
                        StrFileIndice         oReturn = bsa.GetFileValue <StrFileIndice>(readStream);
                        Console.WriteLine(string.Format("ID: {0}|Posição: {1}", oReturn.Id, oReturn.Posicao));
                    }
                }

                Console.WriteLine("Pressione uma tecla para continuar.");
                Console.ReadKey();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #4
0
        public void GravarDados(IEnumerable <ITweet> tweetsPar)
        {
            var tweets = tweetsPar.Distinct().OrderBy(x => x.Id);

            foreach (var item in tweets)
            {
                StrFileIndice         sfi = new StrFileIndice();
                BinarySearchAlgorithm bsa = new BinarySearchAlgorithm();
                if (!bsa.BinarySearchById(item.Id, strNameFileIndice, ref sfi))
                {
                    StrFile strFile = new StrFile();
                    strFile.Id = item.Id;
                    if (item.FullText.Length > 500)
                    {
                        strFile.Mensagem = item.FullText.Substring(0, 500);
                    }
                    else
                    {
                        strFile.Mensagem = item.FullText;
                    }
                    strFile.Data    = item.CreatedAt.ToString("dd/MM/yyyy");
                    strFile.Usuario = item.CreatedBy.Name;
                    strFile.Pais    = item.Place != null && item.Place.Name != null ? item.Place.Name : "";

                    StringBuilder strHash = new StringBuilder();
                    if (item.Hashtags != null && item.Hashtags.Count > 0)
                    {
                        foreach (var hash in item.Hashtags)
                        {
                            strHash.Append(hash);
                        }
                    }
                    if (strHash.ToString().Length > 200)
                    {
                        strFile.HashTags = strHash.ToString().Substring(0, 200);
                    }
                    else
                    {
                        strFile.HashTags = strHash.ToString();
                    }
                    strFile.Elo     = 0;
                    strFile.NewLine = '\n';
                    FileWrite fWrite   = new FileWrite();
                    long      position = fWrite.WriteStructure(strFile, strNameFile);

                    StrFileIndice strFileIndice = new StrFileIndice();
                    strFileIndice.Id      = item.Id;
                    strFileIndice.Posicao = position;
                    strFileIndice.NewLine = '\n';
                    fWrite.WriteStructureIndex(strFileIndice, strNameFileIndice);
                }
            }
        }
Beispiel #5
0
        private void GetPositionIndexData()
        {
            Console.Clear();

            try
            {
                Console.WriteLine("Informe o ID");
                long idBusca = long.Parse(Console.ReadLine());

                DateTime begin = DateTime.UtcNow;

                StrFileIndice         sfi = new StrFileIndice();
                BinarySearchAlgorithm bsa = new BinarySearchAlgorithm();
                if (bsa.BinarySearchById(idBusca, strNameFileIndice, ref sfi))
                {
                    FileStream fsDados = new FileStream(strNameFile, FileMode.Open);
                    fsDados.Seek(sfi.Posicao, SeekOrigin.Begin);
                    StrFile oReturn = bsa.GetFileValue <StrFile>(fsDados);
                    Console.WriteLine(string.Format("Id: {0}", oReturn.Id));
                    Console.WriteLine(string.Format("Usuário: {0}", oReturn.Usuario));
                    Console.WriteLine(string.Format("Mensagem: {0}", oReturn.Mensagem));
                    Console.WriteLine(string.Format("Data: {0}", oReturn.Data.Trim() + "9"));
                    Console.WriteLine(string.Format("País: {0}", oReturn.Pais));
                    Console.WriteLine(string.Format("Hashtags: {0}", oReturn.HashTags));
                    Console.WriteLine("");

                    fsDados.Close();
                    fsDados.Dispose();

                    double total = (DateTime.UtcNow - begin).TotalMilliseconds;

                    DesempenhoModel dm = new DesempenhoModel();
                    dm.NomeTeste     = "Tempo dado índice(Arquivo)";
                    dm.TempoExecucao = total;
                    dm.Data          = DateTime.Now;
                    desempenhoDao.Store(dm);
                }
                else
                {
                    Console.WriteLine("Índice ñ encontrado.");
                }

                Console.WriteLine("Pressione uma tecla para continuar.");
                Console.ReadKey();
            }
            catch (Exception)
            {
                Console.WriteLine("Dados inválidos.");
                Console.WriteLine("Pressione uma tecla para continuar.");
                Console.ReadKey();
            }
        }
        public void MethodTestBinarySearch()
        {
            string path = Path.GetDirectoryName(Path.GetDirectoryName(Directory.GetCurrentDirectory()));

            path = path.Replace("\\UnitTestProjeto\\bin", "");
            string strNameFileIndice     = path + "\\ArquivoIndice.txt";
            BinarySearchAlgorithm bsa    = new BinarySearchAlgorithm();
            StrFileIndice         objeto = new StrFileIndice();

            if (bsa.BinarySearchById(1170023482421325824, strNameFileIndice, ref objeto))
            {
                Assert.AreEqual(1170023482421325824, objeto.Id);
            }
        }
        public void MethodTestEnderecoIndice()
        {
            string path = Path.GetDirectoryName(Path.GetDirectoryName(Directory.GetCurrentDirectory()));

            path = path.Replace("\\UnitTestProjeto\\bin", "");
            string strNameFile       = path + "\\ArquivoDados.txt";
            string strNameFileIndice = path + "\\ArquivoIndice.txt";

            BinarySearchAlgorithm bsa    = new BinarySearchAlgorithm();
            StrFileIndice         objeto = new StrFileIndice();

            if (bsa.BinarySearchById(1170023482421325824, strNameFileIndice, ref objeto))
            {
                FileStream fsDados = new FileStream(strNameFile, FileMode.Open);
                fsDados.Seek(objeto.Posicao, SeekOrigin.Begin);
                StrFile oReturn = bsa.GetFileValue <StrFile>(fsDados);
                Assert.AreEqual(1170023482421325824, oReturn.Id);

                fsDados.Close();
                fsDados.Dispose();
            }
        }
Beispiel #8
0
        private void GetPositionIndexDataByHashTag()
        {
            Console.Clear();

            try
            {
                Console.WriteLine("Informe a HashTag");
                string hashTagBusca = Console.ReadLine();

                if (hashTagBusca.Trim() == "")
                {
                    throw new Exception("Erro");
                }

                DateTime begin = DateTime.UtcNow;

                List <FileStream> listaStream = new List <FileStream>();
                listaStream.Add(new FileStream(strNameFile, FileMode.Open));
                listaStream.Add(new FileStream(strNameIndiceHashtags, FileMode.Open));

                while (listaStream[1].Position < listaStream[1].Length)
                {
                    if (listaStream[1].Position > 0)
                    {
                        listaStream[1].Position += 1;
                    }

                    BinarySearchAlgorithm bsa     = new BinarySearchAlgorithm();
                    StrFileIndiceHashtags oReturn = bsa.GetFileValue <StrFileIndiceHashtags>(listaStream[1]);
                    if (oReturn.Hashtag.Contains(hashTagBusca.Trim()))
                    {
                        for (int i = 0; i < 1000; i++)
                        {
                            if (oReturn.Ids[i] == 0)
                            {
                                break;
                            }

                            StrFileIndice sfi = new StrFileIndice();
                            if (bsa.BinarySearchById(oReturn.Ids[i], strNameFileIndice, ref sfi))
                            {
                                listaStream[0].Seek(sfi.Posicao, SeekOrigin.Begin);
                                StrFile oReturnData = bsa.GetFileValue <StrFile>(listaStream[0]);
                                Console.WriteLine(string.Format("Id: {0}", oReturnData.Id));
                                Console.WriteLine(string.Format("Usuário: {0}", oReturnData.Usuario));
                                Console.WriteLine(string.Format("Mensagem: {0}", oReturnData.Mensagem));
                                Console.WriteLine(string.Format("Data: {0}", oReturnData.Data.Trim() + "9"));
                                Console.WriteLine(string.Format("País: {0}", oReturnData.Pais));
                                Console.WriteLine(string.Format("Hashtags: {0}", oReturnData.HashTags));
                                Console.WriteLine("---------------------------------------------------------------------");
                            }
                        }
                    }
                }

                listaStream[0].Close();
                listaStream[1].Close();
                listaStream[0].Dispose();
                listaStream[1].Dispose();

                double total = (DateTime.UtcNow - begin).TotalMilliseconds;

                DesempenhoModel dm = new DesempenhoModel();
                dm.NomeTeste     = "Tempo dado hashtag(Arquivo)";
                dm.TempoExecucao = total;
                dm.Data          = DateTime.Now;
                desempenhoDao.Store(dm);

                Console.WriteLine("Pressione uma tecla para continuar.");
                Console.ReadKey();
            }
            catch (Exception)
            {
                Console.WriteLine("Dados inválidos.");
                Console.WriteLine("Pressione uma tecla para continuar.");
                Console.ReadKey();
            }
        }