예제 #1
0
        public int insertFile()
        {
            DBFileManagerDataContext db = new DBFileManagerDataContext();
            myfile mf = new myfile();

            mf.code      = this.p_code;
            mf.file_loca = this.p_loca;
            mf.create_at = this.p_date;
            db.myfiles.InsertOnSubmit(mf);
            db.SubmitChanges();
            return(0);
        }
예제 #2
0
        private void createdownloadqueue()
        {
            // stop timer so it can not intrupt on going process
            dispatcherTimer.Stop();
            // get local file dictionary.
            showNotificationMessage("Dowloading File list", 0);
            LIVEFILES = GetlivefilesData(); // get live files

            try
            {
                List <myfile> currentfiles = new List <myfile>();

                List <String> fileEntries = DirSearch(localfolder);

                LOCALFILES = new Dictionary <string, myfile>();

                foreach (string fileName in fileEntries)
                {
                    FileInfo fi = new FileInfo(fileName);

                    if (fi.Extension != ".part")
                    {
                        myfile mf = new myfile();
                        mf.name = fi.Name;
                        mf.size = fi.Length;

                        mf.dir = System.IO.Path.GetDirectoryName(fileName);

                        mf.md5 = createmd5(fileName).ToLower();


                        if (!LOCALFILES.ContainsKey(mf.md5))
                        {
                            LOCALFILES.Add(mf.md5, mf);
                        }
                    }
                    else if (fi.Extension == ".part")
                    {
                        DOWNLOADPENDING.Add(System.IO.Path.GetFileNameWithoutExtension(fi.Name));
                    }
                }


                // get live file dictionary.



                // check both dictionary and manage downloadqueue.

                foreach (String k in LOCALFILES.Keys.ToList())
                {
                    var i = LIVEFILES.ContainsKey(k.Trim());

                    if (!i)
                    {
                        var localitem = LOCALFILES[k];


                        if (File.Exists(localitem.dir + "\\" + localitem.name))
                        {
                            File.Delete(localitem.dir + "\\" + localitem.name);
                            bool isEmpty = !Directory.EnumerateFiles(localitem.dir).Any();
                            if (isEmpty)
                            {
                                Directory.Delete(localitem.dir, true);
                            }
                            showNotificationMessage(localitem.dir + "\\" + localitem.name + "removing... ", 0);
                        }
                        //  LOCALFILES.Remove(k.Trim());
                        //  LOCALFILES.Clear();
                    }
                }

                // cross checking of existing file to live files.
                while (DOWNLOADPENDING.Count > 0)
                {
                    showNotificationMessage("Genarating Pending Download List", 0);
                    String k = DOWNLOADPENDING.First();
                    var    i = LIVEFILES.ContainsKey(k);
                    if (i)
                    {
                        var          item = LIVEFILES[k];
                        downloadfile df   = new downloadfile(item.name, item.md5 + ".part", item.md5, item.size, 0, item.dir);

                        myfile mf = new myfile();
                        mf.name = item.name;
                        mf.size = item.size;
                        mf.md5  = item.md5;
                        if (!LOCALFILES.ContainsKey(mf.md5))
                        {
                            LOCALFILES.Add(mf.md5, mf);
                        }
                        // LOCALFILES.Add(mf.md5, mf);

                        DOWNLOADQUEUE.Add(df);
                    }
                    else
                    {
                        //TODO:delete the unwanted .partfiles

                        var localFileList = DirSearch(localfolder);
                        var match         = localFileList.FirstOrDefault(stringToCheck => stringToCheck.Contains(k));

                        if (File.Exists(match))
                        {
                            File.Delete(match);
                        }
                        // deletefile(k + ".part");
                    }
                    DOWNLOADPENDING.Remove(k);
                }

                // checking for new file
                foreach (String lv in LIVEFILES.Keys)
                {
                    var i = LOCALFILES.ContainsKey(lv);
                    if (!i)
                    {
                        var item = LIVEFILES[lv];


                        if (!File.Exists(localfolder + "\\" + item.dir + "\\" + item.md5 + ".part"))
                        {
                            Directory.CreateDirectory(System.IO.Path.GetDirectoryName(localfolder + "\\" + item.dir + "\\" + item.md5 + ".part"));

                            File.Create(localfolder + "\\" + item.dir + "\\" + item.md5 + ".part").Close();
                        }
                        downloadfile df = new downloadfile(item.name, item.md5 + ".part", item.md5, item.size, 0, item.dir);
                        //  MessageBox.Show("new" + item.name + item.md5 + ".part"  + item.dir);
                        DOWNLOADQUEUE.Add(df);
                    }
                }

                dispatcherTimer.Start();
            }
            catch (Exception ex)
            {
                Reset_On_Error(ex);
            }
        }