]> Creatis software - creaImageIO.git/commitdiff
Added functionality of timestamp and maintenance databases when using multiple sources
authorcaballero <caballero>
Thu, 30 Apr 2009 13:56:10 +0000 (13:56 +0000)
committercaballero <caballero>
Thu, 30 Apr 2009 13:56:10 +0000 (13:56 +0000)
appli/TestWxGimmickReaderDialog/main.cxx
appli/gimmick/main.cxx
src2/creaImageIOGimmick.cpp
src2/creaImageIOGimmick.h
src2/creaImageIOSynchron.cpp
src2/creaImageIOSynchron.h
src2/creaImageIOTimestampDatabaseHandler.cpp
src2/creaImageIOTimestampDatabaseHandler.h
src2/creaImageIOTreeHandlerImageAdder.cpp
src2/creaImageIOTreeHandlerImageAdder.h
src2/creaImageIOWxGimmickView.cpp

index 19afb0578a472c951c51a56509087fc92fb6a3ae..45c72d69daadde5abd1005ea23bcc43a0060bb7c 100644 (file)
@@ -62,6 +62,7 @@ bool myApp::OnInit( )
           //Puts images
        std::vector<vtkImageData*> images;
           w.GetSelectedImages(images,output_dim);
+          std::cout<<images.size()<<std::endl;
 
           crea::VtkBasicSlicer(images.front());
        images.front()->Delete();
index b456e3f48a4b232e3c2f29d36d6f139a13be0849..ab08f622a10ec27ea2bcfb5816233eb8531bf878 100644 (file)
@@ -27,7 +27,7 @@ int main(int ac, char* av[])
     ("print,p","Prints the local database tree  (default=off)")
     ("file,f",po::value< vector<string> >(),"Adds the file to the local database")
     ("dir,d",po::value< vector<string> >(),"Adds the directory to the local database")
-    ("sync,s","Synchronizes the local database with the files")
+    ("sync,s",po::value< vector<string> >(),"Synchronizes the local database with the files")
     ("recurse,r","Recurse into sub-directories  (default=off)")
        ("repair,R","Repair the database (on synchronization) (default=off)")
        ("check,c","Check for attribute differences (on synchronization) (default=off)");
@@ -97,13 +97,14 @@ int main(int ac, char* av[])
        if (vm.count("sync")) {
          bool rep=false;
       bool chk=false;
+         std::vector<std::string> name=vm["sync"].as< vector<string> >();
          std::stringstream out;
          out<<vm.count("repair");
          if(out.str().compare("1")==0){rep=true;}
          std::stringstream out2;
          out2<<vm.count("check");
          if(out2.str().compare("1")==0){chk=true;}
-         cout<<g.Synchronize(rep,chk)<<"\n";
+         cout<<g.Synchronize(name.front(),rep,chk)<<"\n";
        }       
        g.Finalize();
       }
index b30fbc18ba9a4fa5d9704fae24640b158b75cb1b..3213acabe760a9cd60259249f1820d18a86f163f 100644 (file)
@@ -285,6 +285,7 @@ namespace creaImageIO
   {
     GimmickMessage(2,"Adding files to '"<<d<<"'"<<std::endl);
  
+       mImageAdder.SetCurrentDatabase(d);
     mImageAdder.SetTreeHandler(GetTreeHandler(d));
        mImageAdder.SetTimestampHandler(mTimestampDatabase);
        mImageAdder.SetSynchronizer(mSynchronizer);
@@ -302,6 +303,7 @@ namespace creaImageIO
                   <<recurse<<std::endl);
 
        TreeHandler * handler=GetTreeHandler(d);
+       mImageAdder.SetCurrentDatabase(d);
     mImageAdder.SetTreeHandler(handler);
        mImageAdder.SetTimestampHandler(mTimestampDatabase);
        mImageAdder.SetSynchronizer(mSynchronizer);
@@ -314,17 +316,19 @@ namespace creaImageIO
   void Gimmick::RemoveFile(const std::string& d, 
                           tree::Node* node)
   {
+         mImageAdder.SetCurrentDatabase(d);
          mImageAdder.SetSynchronizer(mSynchronizer);
-         mTimestampDatabase->RemoveNode("PATH",node);
+         mTimestampDatabase->RemoveNode("PATH",node,d);
          mImageAdder.RemoveFile(node);
   }
   //========================================================================
 
   //========================================================================
  
-  std::string Gimmick::Synchronize(bool repair, bool checkAttributes)
+  std::string Gimmick::Synchronize(const std::string& d, bool repair, bool checkAttributes)
   {
-         TreeHandler * handler=GetTreeHandler("Local database");
+         TreeHandler * handler=GetTreeHandler(d);
+         mImageAdder.SetCurrentDatabase(d);
          mImageAdder.SetTreeHandler(handler);
          mImageAdder.SetTimestampHandler(mTimestampDatabase);
          mImageAdder.SetSynchronizer(mSynchronizer);
index b316b1b5383ba2481ff57b2d593c21600bbf37a9..b97df6f9f64adb6d6b5c27ac3ca4c5059470fcd7 100644 (file)
@@ -96,9 +96,9 @@ namespace creaImageIO
        void RemoveFile(const std::string& d, 
                        tree::Node* filename);
 
-       ///Synchronizes the loaded data with the database. If remove is true the database will be updated, otherwise 
+       ///Synchronizes the loaded data with the database d. If repair is true the database will be updated, otherwise 
        ///only a warning sign will be issued
-       std::string Synchronize(bool repair, bool checkAttributes);
+       std::string Synchronize(const std::string& d, bool repair, bool checkAttributes);
 
     /// Prints the tree handled by the handler
     void Print(const std::string& handler);
index 9ec4bae4d3fcf4b7b68469d0f88debe0158c16ec..136c29e7fcd190756e4edb5eeb226b132c50d355 100644 (file)
@@ -72,7 +72,7 @@ namespace creaImageIO
                }
                }
                // get the ADD operations List 
-               UpdateAddList();
+               //UpdateAddList(pathDB);
        }
 
        //=====================================================================
@@ -87,6 +87,7 @@ namespace creaImageIO
            command += ",\nPATH text";
                command += ",\nRECURSIVE boolean";
                command += ",\nFILES_ADDED int";
+               command += ",\nREFERENCEDDB text";
            command += "\n)";
                UPDATESYNCDB(command);
 
@@ -117,9 +118,9 @@ namespace creaImageIO
        }
 
        //=====================================================================
-       void Synchronizer::GetFileList(std::vector<AddList> & list)
+       void Synchronizer::GetFileList(std::vector<AddList> & list, const std::string& refdb)
     {
-       CleanList();
+       CleanList(refdb);
           list=mAddList;
     }
 
@@ -130,9 +131,9 @@ namespace creaImageIO
        }
 
        //=====================================================================
-    void Synchronizer::UpdateAddList()
+       void Synchronizer::UpdateAddList(const std::string& refdb)
     {
-        std::string query = "SELECT * FROM ADD_OPS";
+        std::string query = "SELECT * FROM ADD_OPS WHERE REFERENCEDDB = '"+refdb+"';";
         CppSQLite3Query res;
         QUERYSYNCDB(query, res);
                while (!res.eof())
@@ -157,12 +158,13 @@ namespace creaImageIO
 
     /////////////////////////////////////////////////////////////////////////////////////////////////
     // clean DataBase if an operation has no child anymore
+       // @param refdb: the database segement to clean
     // @result : -
     /////////////////////////////////////////////////////////////////////////////////////////////////
-    void Synchronizer::CleanList()
+    void Synchronizer::CleanList(const std::string& refdb)
     {
                mAddList.clear();
-               UpdateAddList();
+               UpdateAddList(refdb);
         std::vector<AddList>::iterator it_add = mAddList.begin();
         for(;it_add <mAddList.end(); ++it_add)
         {
@@ -174,7 +176,7 @@ namespace creaImageIO
                 }
         }
                mAddList.clear();
-               UpdateAddList();
+               UpdateAddList(refdb);
     }
 
        /////////////////////////////////////////////////////////////////////////////////////////////////
@@ -182,17 +184,19 @@ namespace creaImageIO
     // @param path: the path of the directory that was added
        // @param recursive: shows if the action was called recursively or not
        // @param nChildren: the number of files affected by the operation
+       // @param refdb: the referenced database
     // @result : The operation has been added
     /////////////////////////////////////////////////////////////////////////////////////////////////
-       void Synchronizer::InsertAddOp(const std::string& path, const std::string& recursive,   const std::string& nChildren)
+       void Synchronizer::InsertAddOp(const std::string& path, const std::string& recursive,   const std::string& nChildren, const std::string& refdb)
        {
                std::string insert;
                std::string pat=path.c_str();
                CleanName(pat);
-               insert="INSERT INTO ADD_OPS (PATH,RECURSIVE,FILES_ADDED) VALUES('";
+               insert="INSERT INTO ADD_OPS (PATH,RECURSIVE,FILES_ADDED,REFERENCEDDB) VALUES('";
                insert+=pat+"','";
                insert+=recursive+"',";
-       insert+=nChildren+");";
+       insert+=nChildren+",'";
+               insert+=refdb+"');";
                UPDATESYNCDB(insert);
        }
 
@@ -205,11 +209,11 @@ namespace creaImageIO
     // @result : The file has been inserted
     /////////////////////////////////////////////////////////////////////////////////////////////////
 
-       void Synchronizer::InsertIgnoreFile(const std::string& addKey, const std::string& path, const std::string& remove, const std::string& time)
+       void Synchronizer::InsertIgnoreFile(const std::string& addKey, const std::string& path, const std::string& remove, const std::string& time, const std::string& refdb )
        {
                std::string pat=path.c_str();
                CleanName(pat);
-               std::string id=GetAttribute("ID","IGNORED_FILES","PATH",pat);
+               std::string id=GetAttribute("ID","IGNORED_FILES","PATH",pat,refdb);
                if(id.compare("")==0)
                {
                        std::string insert;
@@ -223,13 +227,29 @@ namespace creaImageIO
                else            
                {
                        //Gets the add key
-                       std::string ak=GetAttribute("ADD_KEY","IGNORED_FILES","ID",id);
-                       //Sets the new add key attribute for the file
-            SetAttribute("ADD_KEY","IGNORED_FILES",addKey,"ID", id);
-                       //Sets the new remove attribute for the file
-                       SetAttribute("REMOVE","IGNORED_FILES",remove,"ID", id);
-                       //Sets the new time attribute for the file
-                       SetAttribute("TIME","IGNORED_FILES",time,"ID", id);
+                       std::string ak=GetAttribute("ADD_KEY","IGNORED_FILES","ID",id,refdb);
+                       //gets the parent database to check if the file has been added to the current database
+                       std::string parentDB=GetAttribute("*","ADD_OPS","ADD_KEY",ak,refdb);
+                       //If there is no such entry, add it
+                       if(parentDB.compare("")==0)
+                       {
+                               std::string insert;
+                               insert="INSERT INTO IGNORED_FILES (ADD_KEY,PATH,REMOVE,TIME) VALUES('";
+                               insert+=addKey+"','";
+                               insert+=pat+"','";
+                               insert+=remove+"',";
+                       insert+=time+");";
+                               UPDATESYNCDB(insert);
+                       }
+                       else
+                       {
+                               //Sets the new add key attribute for the file
+                               SetAttribute("ADD_KEY","IGNORED_FILES",addKey,"ID", id,refdb);
+                               //Sets the new remove attribute for the file
+                               SetAttribute("REMOVE","IGNORED_FILES",remove,"ID", id,refdb);
+                               //Sets the new time attribute for the file
+                               SetAttribute("TIME","IGNORED_FILES",time,"ID", id,refdb);
+                       }
                }
        }
 
@@ -275,13 +295,22 @@ namespace creaImageIO
     std::string Synchronizer::GetAttribute(const std::string& attribute, 
                                                                                const std::string& table, 
                                                                                const std::string& searchParam,
-                                                                               const std::string& searchValue)
+                                                                               const std::string& searchValue, 
+                                                                               const std::string& refdb)
     {
         std::stringstream query;
                std::string result;
                std::string sVal=searchValue.c_str();
                CleanName(sVal);
-               query<<"SELECT "<<attribute<<" FROM "<<table<<" WHERE "<<searchParam<<" = '"<<sVal<<"';";
+               query<<"SELECT "<<attribute<<" FROM "<<table<<" WHERE "<<searchParam<<" = '"<<sVal;
+               if(table.compare("ADD_OPS")==0)
+               {
+                       query<<"' AND REFERENCEDDB = '"<<refdb<<"';";
+               }
+               else
+               {
+                       query<<"';";
+               }
         CppSQLite3Query res;
         QUERYSYNCDB(query.str(), res);
                while (!res.eof())
@@ -305,7 +334,8 @@ namespace creaImageIO
                                                                                const std::string& table, 
                                                                                const std::string& value,
                                                                                const std::string& searchParam,
-                                                                               const std::string& searchValue)
+                                                                               const std::string& searchValue,
+                                                                               const std::string& refdb)
     {
                std::string val=value.c_str();
                std::string sVal=searchValue.c_str();
@@ -321,7 +351,12 @@ namespace creaImageIO
                sql += searchParam;
                sql += " = '";
                sql += sVal;
-               sql += "'";
+               if(table.compare("ADD_OPS")==0)
+               {
+                       sql += "' AND REFERENCEDDB = '";
+                       sql += refdb;
+               }
+               sql += "';";
                UPDATESYNCDB(sql);
     }
 } 
\ No newline at end of file
index c16298c491e1a3b8bccb6aa7b5f3c21b739d9217..9b7333c4a8f3be57739bac2b7c0bb42bc1ccb8a9 100644 (file)
@@ -54,23 +54,27 @@ namespace creaImageIO
                          void Initialize();
                          void InsertAddOp(const std::string& path, 
                                                        const std::string& recursive,
-                                                       const std::string& nChildren);
+                                                       const std::string& nChildren, 
+                                                       const std::string& refdb);
                          void InsertIgnoreFile(const std::string& addKey,
                                                        const std::string& path, 
                                                        const std::string& remove,
-                                                       const std::string& time);
+                                                       const std::string& time,
+                                                       const std::string& refdb);
                          void RemoveEntry(const std::string i_table, const std::string i_key);
-                         void GetFileList(std::vector<AddList>& files);
+                         void GetFileList(std::vector<AddList>& files , const std::string& refdb);
                          void GetIgnoredFiles(const std::string& key, std::vector<std::string> &ignoreList);
                          std::string GetAttribute(const std::string& attribute, 
                                                                                const std::string& table, 
                                                                                const std::string& searchParam,
-                                                                               const std::string& searchValue);
+                                                                               const std::string& searchValue,
+                                                                               const std::string& refdb);
                          void SetAttribute(const std::string& attribute, 
                                                                                const std::string& table, 
                                                                                const std::string& value,
                                                                                const std::string& searchParam,
-                                                                               const std::string& searchValue);
+                                                                               const std::string& searchValue, 
+                                                                               const std::string& refdb);
               std::vector<AddList>  mAddList;
               std::vector<RemoveList>  mIgnoreList;
       private :
@@ -79,8 +83,8 @@ namespace creaImageIO
               CppSQLite3DB* mDB;
               std::string pathDB;
               void CreateDB();
-              void UpdateAddList();
-              void CleanList();
+              void UpdateAddList(const std::string& refdb);
+              void CleanList(const std::string& refdb);
                          void CleanName(std::string& str) const;
        
                      std::vector<std::string> GetIgnoreList(const std::string &i_key);
index be586d8cdf5f924ac80e5792f1d6c724cca27259..167224be19496f29074a278b5c30343f542a8fb2 100644 (file)
@@ -169,6 +169,7 @@ namespace creaImageIO
                command += ",\nLastModified datetext";
                command += ",\nLastRead datetext";
                command += ",\nTopLevelNodeId text";
+               command += ",\nReferencedDB text";
                command += ",\nconstraint FK_PARENT foreign key (PARENT_ID) references ";
                command += "FILES";
                command += "(ID) on delete restrict on update restrict";
@@ -182,7 +183,7 @@ namespace creaImageIO
 
 
   //=====================================================================
-  void TimestampDatabaseHandler::CleanName(std::string& str) const
+  void TimestampDatabaseHandler::CleanPath(std::string& str) const
   {
         size_t pos;
         do
@@ -195,56 +196,55 @@ namespace creaImageIO
      }
      while ((int)pos!=-1);
   }
-
-
   //=====================================================================
 
   bool TimestampDatabaseHandler::AddDirectory(const std::string& parent,
                                                                                   const std::string& path, 
                                                                                   const time_t lastModif, 
-                                                                                  const time_t lastRead)
+                                                                                  const time_t lastRead,
+                                                                                  const std::string& refdb)
   {
         bool valid=false;
         std::string par=parent.c_str();
         std::string pat=path.c_str();
-        CleanName(par);
-        CleanName(pat);
+        CleanPath(par);
+        CleanPath(pat);
 
-        std::string pathId=IsIndexed(pat);
+        std::string pathId=IsIndexed(pat,refdb);
         //Case: It is a root parent
         if(parent.compare("")==0)
         {
                 if(pathId.compare("")==0)
                 {
-                       AddFile(pat,lastModif,lastRead);
+                       AddFile(pat,lastModif,lastRead,refdb);
                        valid=true;
                 }
                 else
                 {
-                        valid=CheckTimestamp(pathId, lastModif);
+                        valid=CheckTimestamp(pathId, lastModif, refdb);
                 }
         }
         else 
         {
-                std::string parentId=IsIndexed(par);
+                std::string parentId=IsIndexed(par,refdb);
                 //Case: Parent is not in database
                 if(parentId.compare("")==0)
                {
-                       AddFile(par,lastModif,lastRead);
-                       parentId=IsIndexed(par);
+                       AddFile(par,lastModif,lastRead,refdb);
+                       parentId=IsIndexed(par,refdb);
                }
 
                //Case path is not in database
                if(pathId.compare("")==0)
                {
-                   AddFile(parentId,pat,lastModif,lastRead);
+                   AddFile(parentId,pat,lastModif,lastRead,refdb);
                        valid=true;
                }
                //Parent and path are in the database
                else
                {
                        SetAttribute("PARENT_ID",parentId,"ID", pathId);
-                       valid=CheckTimestamp(pathId, lastModif);
+                       valid=CheckTimestamp(pathId, lastModif, refdb);
                }
         }
         return valid;
@@ -253,11 +253,11 @@ namespace creaImageIO
 
   //=====================================================================
 
-  void TimestampDatabaseHandler::AddFile(const std::string& path, const time_t lastModif, const time_t lastRead)
+  void TimestampDatabaseHandler::AddFile(const std::string& path, const time_t lastModif, const time_t lastRead,  const std::string& refdb)
   {
        std::stringstream out;
-       out<<"INSERT INTO FILES (PARENT_ID,PATH,LastModified,LastRead) VALUES(0,'"<<path<<"',";
-       out<<lastModif<<","<<lastRead<<");";
+       out<<"INSERT INTO FILES (PARENT_ID,PATH,LastModified,LastRead,ReferencedDB) VALUES(0,'"<<path<<"',";
+       out<<lastModif<<","<<lastRead<<",'"<<refdb<<"');";
     UPDATETIMESTAMPDB(out.str());
        
   }
@@ -267,20 +267,21 @@ namespace creaImageIO
   void TimestampDatabaseHandler::AddFile(const std::string& parentId, 
                                                                                 const std::string& path, 
                                                                                 const time_t lastModif, 
-                                                                                const time_t lastRead)
+                                                                                const time_t lastRead,  
+                                                                                const std::string& refdb)
   {
        std::stringstream out;
-       out<<"INSERT INTO FILES (PARENT_ID,PATH,LastModified,LastRead) VALUES("<<parentId<<",'"<<path<<"',";
-       out<<lastModif<<","<<lastRead<<");";
+       out<<"INSERT INTO FILES (PARENT_ID,PATH,LastModified,LastRead,ReferencedDB) VALUES("<<parentId<<",'"<<path<<"',";
+       out<<lastModif<<","<<lastRead<<",'"<<refdb<<"');";
     UPDATETIMESTAMPDB(out.str());
   }
 
   //=====================================================================
-  std::string TimestampDatabaseHandler::IsIndexed(const std::string& path)
+  std::string TimestampDatabaseHandler::IsIndexed(const std::string& path, const std::string& refdb)
   {
        std::stringstream out;
        std::stringstream result;
-       out<<"SELECT ID FROM FILES WHERE PATH='"<<path<<"'";
+       out<<"SELECT ID FROM FILES WHERE PATH='"<<path<<"' AND REFERENCEDDB='"<<refdb<<"';";
                
        CppSQLite3Query q;
        QUERYTIMESTAMPDB(out.str(),q);
@@ -306,8 +307,8 @@ namespace creaImageIO
   {
        std::string av=attValue.c_str();
        std::string sv=searchValue.c_str();
-       CleanName(av);
-       CleanName(sv);
+       CleanPath(av);
+       CleanPath(sv);
 
        std::string sql = "UPDATE FILES SET ";
     sql += attName;
@@ -322,7 +323,7 @@ namespace creaImageIO
   }
  
   //=====================================================================
-  void TimestampDatabaseHandler::RemoveNode(const std::string& searchAtt, const tree::Node* node)
+  void TimestampDatabaseHandler::RemoveNode(const std::string& searchAtt, const tree::Node* node, const std::string& refdb)
   {
          int n=node->GetNumberOfChildren();
          if(n>0)
@@ -331,26 +332,26 @@ namespace creaImageIO
                  std::vector<tree::Node*>::iterator it;
                  for(it=children.begin();it!=children.end();++it)
                  {
-                         RemoveNode(searchAtt,(*it));
+                         RemoveNode(searchAtt,(*it),refdb);
                  }
          }
          else if(node->GetLevel()==3)
          {
-                 RemoveFile(searchAtt,node->GetAttribute("FullFileName"));
+                 RemoveFile(searchAtt,node->GetAttribute("FullFileName"),refdb);
          }
          else
          {
-                 DBRemove("TopLevelNodeId",node->GetAttribute("ID"));
+                 DBRemove("TopLevelNodeId",node->GetAttribute("ID"),refdb);
          }
 
 
   }
   //=====================================================================
-  void TimestampDatabaseHandler::RemoveFile(const std::string& searchAtt, const std::string& searchVal)
+  void TimestampDatabaseHandler::RemoveFile(const std::string& searchAtt, const std::string& searchVal, const std::string& refdb )
   {
          
          std::stringstream result;
-         std::string sel="SELECT PARENT_ID FROM FILES WHERE "+searchAtt+"='"+searchVal+"'";
+         std::string sel="SELECT PARENT_ID FROM FILES WHERE "+searchAtt+"='"+searchVal+"' AND REFERENCEDDB='"+refdb+"';";
                
          CppSQLite3Query q;
          QUERYTIMESTAMPDB(sel,q);
@@ -363,7 +364,7 @@ namespace creaImageIO
              }
            q.nextRow();
          }
-         DBRemove(searchAtt,searchVal);
+         DBRemove(searchAtt,searchVal,refdb);
          
                  int nChildren=0;
                  sel="SELECT ID FROM FILES WHERE PARENT_ID='"+result.str()+"'";
@@ -378,27 +379,27 @@ namespace creaImageIO
                        {
                                if(!result.str().compare("0"))
                                {
-                               RemoveFile("ID",result.str());
+                               RemoveFile("ID",result.str(),refdb);
                                }
                                else
                                {
-                               DBRemove("ID",result.str());
+                               DBRemove("ID",result.str(),refdb);
                                }
                        }
   }
 
   //=====================================================================
-  void TimestampDatabaseHandler::DBRemove(const std::string& searchAtt, const std::string& searchVal)
+  void TimestampDatabaseHandler::DBRemove(const std::string& searchAtt, const std::string& searchVal, const std::string& refdb)
   {
        
-    std::string query = "DELETE FROM FILES WHERE "+searchAtt+"='"+ searchVal + "';";
+    std::string query = "DELETE FROM FILES WHERE "+searchAtt+"='"+ searchVal + "' AND REFERENCEDDB='"+refdb+"';";
     UPDATETIMESTAMPDB(query);
   }
 
    //=====================================================================
-  bool TimestampDatabaseHandler::CheckTimestamp(const std::string pathId, const time_t lastModif)
+  bool TimestampDatabaseHandler::CheckTimestamp(const std::string pathId, const time_t lastModif, const std::string& refdb)
   {
-       std::string sel="SELECT LastModified FROM FILES WHERE ID='"+pathId+"';";
+       std::string sel="SELECT LastModified FROM FILES WHERE ID='"+pathId+"' AND REFERENCEDDB='"+refdb+"';";
        CppSQLite3Query q;
        QUERYTIMESTAMPDB(sel,q);
        double timestamp;
index 2a6d78e3fe65daceb898aee67f3e9135b509cd4e..4727fe3fde9bc0a080428b0e665825b184d835f0 100644 (file)
@@ -45,30 +45,31 @@ namespace creaImageIO
     //====================================================================
        //====================================================================
        ///Returns the id of the path if it's indexed, blank otherwise
-       std::string IsIndexed(const std::string& path);
+       std::string IsIndexed(const std::string& path, const std::string& refdb);
     ///Sets the current path's parent
        bool AddDirectory(const std::string& parent,
                                   const std::string& path, 
                                   const time_t lastModif, 
-                                  const time_t lastRead);
+                                  const time_t lastRead,
+                                  const std::string& refdb);
        ///Adds a new file to the database without a parent
-       void AddFile(const std::string& path, const time_t lastModif, const time_t lastRead);
+       void AddFile(const std::string& path, const time_t lastModif, const time_t lastRead, const std::string& refdb);
        ///Adds a new file to the database with a parent
-       void AddFile(const std::string& parentId,const std::string& path, const time_t lastModif, const time_t lastRead);
+       void AddFile(const std::string& parentId,const std::string& path, const time_t lastModif, const time_t lastRead, const std::string& refdb);
        ///Sets the attribute to the value passed as parameter where the searchParameter is searchValue
        void SetAttribute(const std::string& attName, 
                                        const std::string& attValue,
                                        const std::string& searchParam,
                                        const std::string& searchValue);
        ///Removes the given node
-       void RemoveNode(const std::string& searchAtt, const tree::Node* node);
+       void RemoveNode(const std::string& searchAtt, const tree::Node* node, const std::string& refdb);
        ///Removes the filename with the given pathname
-       void RemoveFile(const std::string& searchAtt, const std::string& searchVal);
+       void RemoveFile(const std::string& searchAtt, const std::string& searchVal, const std::string& refdb);
        ///Cleans the path name
-       void CleanName(std::string& str) const;
+       void CleanPath(std::string& str) const;
        ///Checks the timestamp in the database and compares it with the given one. 
        //If there is a difference, it will return false, otherwise it will return true.
-       bool CheckTimestamp(const std::string pathId, const time_t lastModif);
+       bool CheckTimestamp(const std::string pathId, const time_t lastModif, const std::string& refdb);
 
        //====================================================================
 
@@ -85,7 +86,7 @@ namespace creaImageIO
     //======================================================================
        //======================================================================
     // Removes a file from the database
-       void DBRemove(const std::string& searchAtt, const std::string& searchVal);
+       void DBRemove(const std::string& searchAtt, const std::string& searchVal, const std::string& refdb);
  
   private:
     /// The DB
index 22c727b87d83ae02b21b47dbff5e85d6646baa66..2d6ab3a40f0e6a7960d16d0174dd6d8ad57580a1 100644 (file)
@@ -50,16 +50,16 @@ namespace creaImageIO
     std::vector<std::string>::const_iterator i;
     for (i=filenames.begin();i!=filenames.end();++i)
       {
-       mTimestampHandler->AddFile((*i), fs::last_write_time(*i), time(0));
+       mTimestampHandler->AddFile((*i), fs::last_write_time(*i), time(0),mCurrentDB);
        mProgress.IncNumberScannedFiles();
        if (IsHandledFile(*i)) 
          {
            mProgress.IncNumberHandledFiles();
-               mSynchronizer->InsertAddOp((*i),"0","1");
-               std::string addKey=mSynchronizer->GetAttribute("ADD_KEY","ADD_OPS","PATH",(*i));
+               mSynchronizer->InsertAddOp((*i),"0","1",mCurrentDB);
+               std::string addKey=mSynchronizer->GetAttribute("ADD_KEY","ADD_OPS","PATH",(*i),mCurrentDB);
                std::stringstream removedOn;
                removedOn<<time(0);
-               mSynchronizer->InsertIgnoreFile(addKey,(*i),"0",removedOn.str());
+               mSynchronizer->InsertIgnoreFile(addKey,(*i),"0",removedOn.str(),mCurrentDB);
            AddFile(*i);
          }
        mProgressSignal(mProgress);
@@ -77,13 +77,13 @@ namespace creaImageIO
        
        std::stringstream rec;
        rec<<recurse;
-       mSynchronizer->InsertAddOp(directory,rec.str(),"0");
-       std::string addKey=mSynchronizer->GetAttribute("ADD_KEY","ADD_OPS","PATH",directory);
+       mSynchronizer->InsertAddOp(directory,rec.str(),"0",mCurrentDB);
+       std::string addKey=mSynchronizer->GetAttribute("ADD_KEY","ADD_OPS","PATH",directory,mCurrentDB);
        AddDirectoryRecursor( directory, recurse, addKey );
        
        int nFiles=GetProgress().GetNumberAddedFiles();
        files<<nFiles;
-       mSynchronizer->SetAttribute("FILES_ADDED","ADD_OPS",files.str(),"ADD_KEY",addKey);
+       mSynchronizer->SetAttribute("FILES_ADDED","ADD_OPS",files.str(),"ADD_KEY",addKey,mCurrentDB);
     GimmickDebugMessage(3,mProgress<<std::endl);
   }
 
@@ -115,16 +115,16 @@ namespace creaImageIO
                {
                  std::string path=node->GetAttribute("FullFileName");
                  //Gets the add key
-                 std::string addKey=mSynchronizer->GetAttribute("ADD_KEY","IGNORED_FILES","PATH",path);
+                 std::string addKey=mSynchronizer->GetAttribute("ADD_KEY","IGNORED_FILES","PATH",path,mCurrentDB);
                  //Gets the number of files added
-                 int files=atoi((mSynchronizer->GetAttribute("FILES_ADDED","ADD_OPS","ADD_KEY",addKey)).c_str());
+                 int files=atoi((mSynchronizer->GetAttribute("FILES_ADDED","ADD_OPS","ADD_KEY",addKey,mCurrentDB)).c_str());
                  files=files-1;
                  std::stringstream out;
                  out<<files;
                  //Sets the new number of files
-                 mSynchronizer->SetAttribute("FILES_ADDED","ADD_OPS",out.str(),"ADD_KEY",addKey);
+                 mSynchronizer->SetAttribute("FILES_ADDED","ADD_OPS",out.str(),"ADD_KEY",addKey,mCurrentDB);
                  //Sets the file as removed
-                 mSynchronizer->SetAttribute("REMOVE","IGNORED_FILES","1","PATH",path);
+                 mSynchronizer->SetAttribute("REMOVE","IGNORED_FILES","1","PATH = '"+path+"' AND ADD_KEY",addKey,mCurrentDB);
                }
   }
 
@@ -144,16 +144,16 @@ namespace creaImageIO
                {
                   std::string path=(*it)->GetAttribute("FullFileName");
                  //Gets the add key
-                 std::string addKey=mSynchronizer->GetAttribute("ADD_KEY","IGNORED_FILES","PATH",path);
+                 std::string addKey=mSynchronizer->GetAttribute("ADD_KEY","IGNORED_FILES","PATH",path,mCurrentDB);
                  //Gets the number of files added
-                 int files=atoi((mSynchronizer->GetAttribute("FILES_ADDED","ADD_OPS","ADD_KEY",addKey)).c_str());
+                 int files=atoi((mSynchronizer->GetAttribute("FILES_ADDED","ADD_OPS","ADD_KEY",addKey,mCurrentDB)).c_str());
                  files=files-1;
                  std::stringstream out;
                  out<<files;
                  //Sets the new number of files
-                 mSynchronizer->SetAttribute("FILES_ADDED","ADD_OPS",out.str(),"ADD_KEY",addKey);
+                 mSynchronizer->SetAttribute("FILES_ADDED","ADD_OPS",out.str(),"ADD_KEY",addKey,mCurrentDB);
                  //Sets the file as removed
-                 mSynchronizer->SetAttribute("REMOVE","IGNORED_FILES","1","PATH",path);
+                 mSynchronizer->SetAttribute("REMOVE","IGNORED_FILES","1","PATH = '"+path+"' AND ADD_KEY",addKey,mCurrentDB);
                }
        
          }
@@ -186,7 +186,7 @@ namespace creaImageIO
        else 
          {
                std::string parent_id;
-               bool valid=mTimestampHandler->AddDirectory(dirpath, itr->string(), lastModif, time(0));
+               bool valid=mTimestampHandler->AddDirectory(dirpath, itr->string(), lastModif, time(0),mCurrentDB);
                if(valid)
                {
                        mProgress.IncNumberScannedFiles();
@@ -198,7 +198,7 @@ namespace creaImageIO
                        mTimestampHandler->SetAttribute("TopLevelNodeId",parent_id,"PATH",itr->string());
                        std::stringstream removedOn;
                        removedOn<<time(0);
-                       mSynchronizer->InsertIgnoreFile(addKey, itr->string(),"0",removedOn.str());
+                       mSynchronizer->InsertIgnoreFile(addKey, itr->string(),"0",removedOn.str(),mCurrentDB);
                        }
                        mProgressSignal(mProgress);
                        if (mProgress.GetStop()) 
@@ -279,7 +279,7 @@ namespace creaImageIO
          std::vector<AddList>::iterator iter;
 
          //Gets the list of added files
-         mSynchronizer->GetFileList(fileList);
+         mSynchronizer->GetFileList(fileList,mCurrentDB);
 
          std::vector<std::string>::iterator i;
          //Actions to take if the user doesn't want to repair
@@ -348,19 +348,19 @@ namespace creaImageIO
                        //For the new files, add them
                        for (i=newFiles.begin();i!=newFiles.end();++i)
                        {
-                       mTimestampHandler->AddFile((*i), fs::last_write_time(*i), time(0));
+                       mTimestampHandler->AddFile((*i), fs::last_write_time(*i), time(0),mCurrentDB);
                        if (IsHandledFile(*i)) 
                        {
                                std::stringstream removedOn;
                                removedOn<<time(0);
-                               mSynchronizer->InsertIgnoreFile((*iter).key,(*i),"0",removedOn.str());
+                               mSynchronizer->InsertIgnoreFile((*iter).key,(*i),"0",removedOn.str(),mCurrentDB);
                                //Gets the number of files added
-                               int files=atoi((mSynchronizer->GetAttribute("FILES_ADDED","ADD_OPS","ADD_KEY",(*iter).key)).c_str());
+                               int files=atoi((mSynchronizer->GetAttribute("FILES_ADDED","ADD_OPS","ADD_KEY",(*iter).key,mCurrentDB)).c_str());
                                files=files+1;
                                std::stringstream out;
                                out<<files;
                                //Sets the new number of files
-                               mSynchronizer->SetAttribute("FILES_ADDED","ADD_OPS",out.str(),"ADD_KEY",(*iter).key);
+                               mSynchronizer->SetAttribute("FILES_ADDED","ADD_OPS",out.str(),"ADD_KEY",(*iter).key,mCurrentDB);
                                AddFile(*i);
                        }
                        }
index 60654911c76c14976cd47a516c5f41b76f581901..8311fdd59d318c9c785e8da5ebc9e0f7d8b0f176 100644 (file)
@@ -37,6 +37,8 @@ namespace creaImageIO
     void SetTimestampHandler(TimestampDatabaseHandler* tdh) { mTimestampHandler = tdh;}
        /// Sets the synchronizer
        void SetSynchronizer(Synchronizer* s){mSynchronizer=s;}
+       /// Sets the synchronizer
+       void SetCurrentDatabase(std::string cur){mCurrentDB=cur;}
     //====================================================================
 
     //====================================================================
@@ -147,6 +149,7 @@ namespace creaImageIO
        TimestampDatabaseHandler* mTimestampHandler;
        Synchronizer* mSynchronizer;
     ImageReader mReader;
+       std::string mCurrentDB;
     
     Progress mProgress;
     ProgressSignalType mProgressSignal;
index 646782cac0372c4152f63ee5c5ff95235789ad24..4381a6e1a38e422714d0d6fa19c93fd093555108 100644 (file)
@@ -607,8 +607,8 @@ namespace creaImageIO
   //=================================================
   void WxGimmickView::AddIgnoreFile(tree::Node* toRemove)
   {
-         mGimmick->RemoveFile("Local database",toRemove);
-         GetTreeViewMap()["Local database"]->UpdateLevel(1);
+         mGimmick->RemoveFile(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),toRemove);
+         GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
   }
 
    //=================================================
@@ -635,9 +635,11 @@ namespace creaImageIO
                bool checkAttributes=false;
                if(sel==2 || sel==3){repair=true;}
                if(sel==1 || sel==3){checkAttributes=true;}
-               std::string mess=mGimmick->Synchronize(repair, checkAttributes);
+               std::string mess=mGimmick->Synchronize(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),repair, checkAttributes);
                wxMessageBox(std2wx(mess),_T("Synchronization result"),wxOK,this);
-               GetTreeViewMap()["Local database"]->UpdateLevel(1);
+               if(sel==2 || sel==3){
+               GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
+               }
                
     }
   }