示例#1
0
        //File manipulators
        public static string createBinTreeFile(BTree<int, sTweet> Tree, TreeIndexCheck check)
        {
            string filePath;
            string startDir = Directory.GetCurrentDirectory();
            string currentDir = startDir + @"\Searches\";

            if(!Directory.Exists(currentDir))
                Directory.CreateDirectory(currentDir);
            Directory.SetCurrentDirectory(currentDir);

            BinaryFormatter bf = new BinaryFormatter();
            byte[] buffer;
            using(var ms = new MemoryStream())
            {
                bf.Serialize(ms, Tree);
                buffer = ms.ToArray();
            }

            filePath = String.Format("indexedTweets.bin");
            using(BinaryWriter newFile = new BinaryWriter(File.Open(filePath, FileMode.Create)))
            {
                newFile.Write(buffer, 0, buffer.Length);
                newFile.Close();
            }

            Directory.SetCurrentDirectory(startDir);
            SaveTreeIndex(check.index, check.height, check.degree);

            return currentDir + filePath;
        }
示例#2
0
        private void button1_Click(object sender, EventArgs e)
        {
            TreeOfTweets = Pesquisar();

            TreeIndexCheck newCheck = new TreeIndexCheck(0, 0, 0);
            sTweet[] TweetArray = FileManipulation.GetNewArrayToBin(TreeOfTweets);
            TreeOfTweets = FileManipulation.SerialITweetToBTree(TweetArray, ref newCheck);
            FileManipulation.createBinTreeFile(TreeOfTweets, newCheck);
        }
示例#3
0
        public static sTweet[] BTreeToSerialITweet(BTree<int, sTweet> Tree, TreeIndexCheck check)
        {
            Entry<int, sTweet> chave = new Entry<int, sTweet>();
            sTweet[] TweetArray = new sTweet[check.index];

            for(int index = 0; index < check.index; index++)
            {
                chave = Tree.Search(index);
                TweetArray[index] = chave.Pointer; //salva ponteiro da árvore no array
            }

            return TweetArray;
        }
示例#4
0
 private bool checkTreeFileIntegrity(BTree.BTree<int, sTweet> tree, TreeIndexCheck checkNewTree)
 {
     if(tree.Degree != checkNewTree.degree || tree.Height != checkNewTree.height)
     {
         MessageBox.Show(@"Problema com a árvore lida! Houve problema no salvamento dos arquivos,
                         \nOu alguém alterou informações de dentro dos arquivos.", "ERRO 004");
         return false;
     }
     else
     {
         MessageBox.Show(String.Format("Árvore salva com sucesso!\n\nHeight:\t{0}\nDegree:\t{1}\nIndex:\t{2}", tree.Height, tree.Degree, checkNewTree.index));
         return true;
     }
 }
示例#5
0
        public Tweet_Reader()
        {
            InitializeComponent();

            string ReadFile = @"\indexedTweets.bin";

            if(File.Exists(Directory.GetCurrentDirectory() + @"\Searches" + ReadFile))
            {
                TreeIndexCheck check = new TreeIndexCheck(0, 0, 0);
                sTree = FileManipulation.readBinTreeFile(ReadFile, ref check);
                sList = FileManipulation.BTreeToSerialITweet(sTree, check);

                if(sList != null)
                    buildListBox(false, 1);
            }
            else
            {
                BackgroundNull.BringToFront();
                label1.BringToFront();

                BackgroundNull.Show();
                label1.Show();
            }
        }
示例#6
0
        private void TweetRefresh_Click(object sender, EventArgs e)
        {
            if(File.Exists(Directory.GetCurrentDirectory() + @"\Searches\indexedTweets.bin"))
            {
                TreeIndexCheck check = new TreeIndexCheck(0, 0, 0);
                sTree = FileManipulation.readBinTreeFile(@"\indexedTweets.bin", ref check);
                sList = FileManipulation.BTreeToSerialITweet(sTree, check);

                buildListBox(crescentOrder.Checked, 1);
            }
            else
            {
                MessageBox.Show("Não foi possível localizar o arquivo.");
            }
        }
示例#7
0
        private static void SaveTreeIndex(int index, int height, int degree)
        {
            string startDir = Directory.GetCurrentDirectory();
            string currentDir = startDir + @"\Searches\";
            string filePath = String.Empty;

            if(!Directory.Exists(currentDir))
                Directory.CreateDirectory(currentDir);
            Directory.SetCurrentDirectory(currentDir);

            TreeIndexCheck newTree = new TreeIndexCheck(index, height, degree);
            BinaryFormatter bf = new BinaryFormatter();
            byte[] buffer;
            using(var ms = new MemoryStream())
            {
                bf.Serialize(ms, newTree);
                buffer = ms.ToArray();
            }

            filePath = String.Format("treeIndex.bin");

            using(BinaryWriter newFile = new BinaryWriter(File.Open(filePath, FileMode.Create)))
            {
                newFile.Write(buffer, 0, buffer.Length);
                newFile.Close();
            }

            Directory.SetCurrentDirectory(startDir);

            return;
        }
示例#8
0
        public static BTree<int, sTweet> SerialITweetToBTree(sTweet[] TweetArray, ref TreeIndexCheck check)
        {
            BTree<int, sTweet> Tree = new BTree<int, sTweet>(5);

            int index = 0;
            foreach(var tweet in TweetArray)
                Tree.Insert(index++, tweet);

            check = new TreeIndexCheck(index, Tree.Height, Tree.Degree);
            return Tree;
        }
示例#9
0
        public static BTree<int, sTweet> readBinTreeFile(string path, ref TreeIndexCheck check)
        {
            string currentdir = Directory.GetCurrentDirectory() + @"\Searches\";

            BinaryFormatter formatter = new BinaryFormatter();
            System.IO.Stream stream = new FileStream(currentdir + path, FileMode.Open, FileAccess.Read, FileShare.Read);
            BTree<int, sTweet> Tree = (BTree<int, sTweet>) formatter.Deserialize(stream);
            stream.Close();

            check = ReadTreeIndex(currentdir + @"\treeIndex.bin");

            return Tree;
        }
示例#10
0
        //Tree functions
        public static TreeIndexCheck GetTreeIndexCheck(BTree<int, sTweet> Tree)
        {
            TreeIndexCheck check;
            int index = 0;
            bool flag = false;
            Entry<int, sTweet> temp;

            while(flag != true)
            {
                temp = Tree.Search(index++);
                if(temp == null)
                    flag = true;
            }

            check = new TreeIndexCheck(--index, Tree.Height, Tree.Degree);

            return check;
        }
示例#11
0
        public static sTweet[] GetNewArrayToBin(BTree<int, sTweet> newTree)
        {
            TreeIndexCheck checkTree = new TreeIndexCheck(0,0,0);
            sTweet[] auxNew;

            TreeIndexCheck newTreeCheck;

            if(!File.Exists(Directory.GetCurrentDirectory() + @"\Searches\indexedTweets.bin"))
            {
                newTreeCheck = GetTreeIndexCheck(newTree);
                auxNew = BTreeToSerialITweet(newTree, newTreeCheck);  //auxNew contains the new tree that the function received

                return auxNew;
            }
            else
            {
                BTree<int, sTweet> Tree = readBinTreeFile("indexedTweets.bin", ref checkTree);
                sTweet[] auxTweetArray = BTreeToSerialITweet(Tree, checkTree); //auxTweetArray contains the old tree that was in memory

                newTreeCheck = GetTreeIndexCheck(newTree);
                auxNew = BTreeToSerialITweet(newTree, newTreeCheck);  //auxNew contains the new tree that the function received

                //sTweet[] combined = auxTweetArray.Concat(auxNew).ToArray();    //combines the two arrays, with no sorting

                //combined = checkIfRepeatedTweets(combined);

                sTweet[] combined = checkIfRepeatedTweets(auxNew, auxTweetArray);

                return combined;
            }
        }
示例#12
0
        private BTree.BTree<int, sTweet> Pesquisar(TweetSearchParameters searchParameter)
        {
            string aux = button1.Text;
            if ((searchParameter.SearchQuery != "") || (searchParameter.GeoCode != null)) //usuário passou parâmetros
            {
                progressBar.Show();
                button1.Text = "Searching, please wait...";
                IEnumerable<ITweet> list = Search.SearchTweets(searchParameter);

                progressBar.Step = 33;
                progressBar.PerformStep();

                sTweet[] tweetArray = FileManipulation.ListToSerialTweet(list, list.Count(), searchParameter);
                progressBar.PerformStep();

                TreeIndexCheck check = new TreeIndexCheck(0, 0, 0);
                BTree.BTree<int, sTweet> Tree = FileManipulation.SerialITweetToBTree(tweetArray, ref check);
                progressBar.PerformStep();

                int i = list.Count();
                button1.Text = aux;

                MessageBox.Show("Todos tweets lidos. Retornando a lista com " + i.ToString() + " elementos.");
                progressBar.Value = 0;

                return Tree;
            }
            else
            {
                MessageBox.Show("Pesquisa sem parâmetros!\nInsira pelos menos um query de texto ou um geolocal.", "ERROR 001");
                return null;
            }
        }