Beispiel #1
0
 //  比較用クラス
 public override bool Equals(object obj)
 {
     if (obj != null && this.GetType() == obj.GetType())
     {
         FileLibrary fl = (FileLibrary)obj;
         if (this.IsDirectory)
         {
             //  ディレクトリの場合の比較
             if (this.TopDir.Equals(fl.TopDir, StringComparison.OrdinalIgnoreCase) &&
                 this.RelativePath.Equals(fl.RelativePath, StringComparison.OrdinalIgnoreCase))
             {
                 return(true);
             }
         }
         else
         {
             //  ファイルの場合の比較
             if (this.TopDir.Equals(fl.TopDir, StringComparison.OrdinalIgnoreCase) &&
                 this.RelativePath.Equals(fl.RelativePath, StringComparison.OrdinalIgnoreCase) &&
                 this.TimeStamp == fl.TimeStamp &&
                 this.Hash == fl.Hash)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Beispiel #2
0
        //
        public void Search(string targetDir)
        {
            FilterDefinition <FileLibrary> filter =
                Builders <FileLibrary> .Filter.Eq("TopDir", Path.GetFileName(targetDir).ToUpper());

            List <FileLibrary> dbFLList = cdb.Collection_fllist.Find(filter).ToList();

            if (Directory.Exists(targetDir))
            {
                //  対象フォルダーのFileLibrary取得
                List <FileLibrary> myFLList = FileLibrary.Search(targetDir);

                //  DBとローカルファイルの照合
                for (int i = myFLList.Count - 1; i >= 0; i--)
                {
                    if (dbFLList.Contains(myFLList[i]))
                    {
                        dbFLList.Remove(myFLList[i]);
                        myFLList.RemoveAt(i);
                    }
                }

                //  DBから不一致分を削除
                FilterDefinitionBuilder <FileLibrary> builder = Builders <FileLibrary> .Filter;
                foreach (FileLibrary tempFL in dbFLList)
                {
                    cdb.Collection_fllist.DeleteOne(builder.Eq("_id", tempFL._id));
                }

                //  DBに追加
                if (myFLList.Count > 0)
                {
                    cdb.Collection_fllist.InsertMany(myFLList);
                }
            }
            else
            {
                //  対象フォルダーが存在しない場合の処理
                FilterDefinitionBuilder <FileLibrary> builder = Builders <FileLibrary> .Filter;
                foreach (FileLibrary tempFL in dbFLList)
                {
                    cdb.Collection_fllist.DeleteOne(builder.Eq("_id", tempFL._id));
                }
            }
        }