コード例 #1
0
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            string newLocation = "";

            try
            {
                if (string.IsNullOrWhiteSpace(textBoxLocation.Text))
                {
                    TextboxLocationDoubleClick(null, null);
                }
                foreach (var item in textBoxLocation.Text.Split('+').ToList())
                {
                    newLocation = "";
                    string[] fragment = item.Split('\\').ToArray();
                    if (!File.Exists(Lingkungan.getDataBaru() + fragment[fragment.Length - 1]) && db.tbInformasis.Where(x => x.Judul.ToString() == fragment[fragment.Length - 1].ToString()).FirstOrDefault() == null)
                    {
                        tbInformasi baru = new tbInformasi();
                        baru.Judul   = fragment[fragment.Length - 1];
                        baru.Indexed = 0;
                        baru.Lokasi  = Lingkungan.getDataBaru() + fragment[fragment.Length - 1];

                        current.tbInformasis.Add(baru);
                        newLocation = Lingkungan.getDataBaru() + fragment[fragment.Length - 1];

                        LokasilamaData.Add(item);
                        LokasibaruData.Add(newLocation);
                        DataBaru.Add(baru);
//                        File.Copy(item, newLocation);
//                        db.SubmitChanges();
//                        MessageBox.Show("Data " + fragment[fragment.Length - 1] + " berhasil ditambahkan");
                    }
                    else
                    {
                        //MessageBox.Show("Data " + fragment[fragment.Length - 1] + " sudah ada");
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex is FileNotFoundException)
                {
                    MessageBox.Show("Masukkan data");
                }
                else
                {
                    MessageBox.Show("Error! " + ex.Message);
                }
            }
            finally
            {
                textBoxLocation.Text = "";
                IndexChange(null, null);
            }
        }
コード例 #2
0
        public void FileCrawler(string args) //uncalled
        {
            //Crawler
            List <string> LokasiFile = new List <string>();
            //menyimpan daftar folder yang akan di crawl
            Queue <string> ListLocation = new Queue <string>();
            //menimpan daftar file yang akan di index
            List <string> FileLocation = new List <string>();

            string process; // variabel pemrosesan
            string location;

            if (args == "cache")
            {
                location = Lingkungan.getDataCache(); // menyimpan lokasi cache yang akan dicrawl
            }
            else
            {
                location = Lingkungan.getDataBaru(); // menyimpan lokasi Data baru yang akan dicrawl
            }
            if ((File.Exists(location) || Directory.Exists(location)) && string.IsNullOrWhiteSpace(location) == false)
            {
                ListLocation.Enqueue(location);
                do
                {
                    process = ListLocation.Dequeue();
                    if (File.GetAttributes(process) == FileAttributes.Directory)
                    {
                        foreach (string item in Directory.GetDirectories(process))
                        {
                            ListLocation.Enqueue(item);
                        }
                        foreach (string item2 in Directory.GetFiles(process))
                        {
                            FileLocation.Add(item2);
                        }
                    }
                } while (ListLocation.Count > 0);
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("Gagal Melakukan Crawling");
            }
            locations = FileLocation;
        }