Example #1
0
        public void Save(FileIndex index)
        {
            SqlCeConnection connection = new SqlCeConnection(_connString);
            SqlCeDataAdapter adapter = new SqlCeDataAdapter("select * from Indexes", connection);
            adapter.InsertCommand = new SqlCeCommand("Insert Into Indexes (Timestamp, Machine, Profile, RelPath, Size, Hash) Values (@Timestamp, @Machine, @Profile, @RelPath, @Size, @Hash)", connection);
            adapter.InsertCommand.Parameters.Add("@Timestamp", SqlDbType.DateTime);
            adapter.InsertCommand.Parameters.Add("@Machine", SqlDbType.NVarChar);
            adapter.InsertCommand.Parameters.Add("@Profile", SqlDbType.NVarChar);
            adapter.InsertCommand.Parameters.Add("@RelPath", SqlDbType.NVarChar);
            adapter.InsertCommand.Parameters.Add("@Size", SqlDbType.BigInt);
            adapter.InsertCommand.Parameters.Add("@Hash", SqlDbType.NVarChar);
            // A static timestamp to share among all records.
            DateTime indextime = DateTime.Now;
            connection.Open();
            foreach (FileHeader file in index.Files)
            {
                adapter.InsertCommand.Parameters["@Timestamp"] = new SqlCeParameter("@Timestamp", indextime);
                adapter.InsertCommand.Parameters["@Machine"] = new SqlCeParameter("@Machine", _localSettings.MachineName);
                adapter.InsertCommand.Parameters["@Profile"] = new SqlCeParameter("@Profile", _options.ProfileName);
                adapter.InsertCommand.Parameters["@RelPath"] = new SqlCeParameter("@RelPath", Path.Combine(file.RelativePath, file.FileName));
                adapter.InsertCommand.Parameters["@Size"] = new SqlCeParameter("@Size", file.FileSize);
                adapter.InsertCommand.Parameters["@Hash"] = new SqlCeParameter("@Hash", file.ContentsHash);
                adapter.InsertCommand.ExecuteNonQuery();
            }

            // TODO: Find any indexes older than the last two. Remove them.
            adapter.DeleteCommand = new SqlCeCommand("Delete From Indexes Where Timestamp Not In (Select Top 2 Timestamp From Indexes Where Machine = @Machine And Profile = @Profile) And Machine = @Machine And Profile = @Profile", connection);
            adapter.DeleteCommand.Parameters.Add("@Machine", SqlDbType.NVarChar);
            adapter.DeleteCommand.Parameters.Add("@Profile", SqlDbType.NVarChar);
            adapter.DeleteCommand.Parameters["@Machine"] = new SqlCeParameter("@Machine", _localSettings.MachineName);
            adapter.DeleteCommand.Parameters["@Profile"] = new SqlCeParameter("@Profile", _options.ProfileName);
            adapter.DeleteCommand.ExecuteNonQuery();
            connection.Close();
        }
 void IIndexMapper.Save(FileIndex index)
 {
     foreach (FileHeader file in index.Files)
     {
         Console.WriteLine(file.FileName);
     }
 }
 void IIndexMapper.Save(FileIndex index)
 {
     throw new NotImplementedException();
 }
 public void Save(FileIndex index)
 {
     var files = from f in index.Files select Path.Combine(f.RelativePath, f.FileName);
     File.WriteAllLines(IndexFileName, files.ToArray());
 }
 public void Save(FileIndex index)
 {
     _indexes.Add(index);
     // TODO: Prune all but the most recent two indexes for the same machine and profile.
     serialiser.Serialize(_indexes, _filename);
 }
        public FileIndex CreateIndex()
        {
            FileIndex index = new FileIndex();
            index.MachineName = _localSettings.MachineName;
            index.ProfileName = _profile.ProfileName;
            index.TimeStamp = DateTime.Now;
            index.LocalBasePath = _localSettings.LocalPath;
            IFileHashProvider hasher = new MockHasher();

            foreach (string file in ListLocalFiles())
            {
                try
                {
                    index.Files.Add(new FileHeader(file, index.LocalBasePath, hasher));
                }
                catch (Exception e)
                {
                    _errors.Add(e);
                }
            }
            return index;
        }