Beispiel #1
0
        public static void ExportTagsForProfileToXml(string deviceName, SyncProfile sp, List<FileModelItem> files)
        {
            Xml.XmlExporter xe = new Xml.XmlExporter();
            string targetFile = Configuration.SyncRootNewXmlExportFile(sp);

            xe.Export(deviceName, null, files, targetFile);
        }
Beispiel #2
0
 public SyncMap(SyncProfile profile,
                SyncDirection direction,
                SyncAction defaultAction)
 {
     this._profile = profile;
     _defaultSyncAction = defaultAction;
     _syncDirection = direction;
 }
        public SyncMapWindow(SyncProfile syncProfile)
        {
            InitializeComponent();
            _syncProfile = syncProfile;

            //SetDemoProfile();
            //LoadProfileFromDb();
            RefreshViewFromProfile(true);
        }
Beispiel #4
0
        public static void ExportTagsForProfileToPath(SyncProfile sp, string sha1Hash, bool timeStampList)
        {
            //load if exists, will just be empty otherwise
            Dictionary<string, string> hashToTags = LoadFromHashToTagsIndex(sp);

            hashToTags[sha1Hash] = GetTagStringForHash(sha1Hash);

            List<string> lst = hashToTags.Select(x => "sha1Hash={" + x.Key + "} tags={" + x.Value + "}").ToList();

            File.WriteAllLines(HashToTagsIndexPath(sp, timeStampList), lst);
        }
Beispiel #5
0
        /// <summary>
        /// used FromHash() to retrieve from database
        /// and stores in SyncRootConfig keyed to hash
        /// </summary>
        /// <param name="sp"></param>
        public static void ExportTagsForProfile(SyncProfile sp, string sha1Hash)
        {
            ////load if exists, will just be empty otherwise
            //Dictionary<string, string> hashToTags = LoadFromHashToTagsIndex(sp);

            //hashToTags[sha1Hash] = FromHash(sp, SyncDirection.Export, sha1Hash);

            //List<string> lst = hashToTags.Select(x => "sha1Hash={" + x.Key + "} tags={" + x.Value + "}").ToList();

            //File.WriteAllLines(HashToTagsIndexPath(sp), lst);

            //for now, supporting both formats (though one gets
            //lost on sync depending on the sequence, which is
            //why this new way is being phased in)
            ExportTagsForProfileToPath(sp, sha1Hash, true);
            ExportTagsForProfileToPath(sp, sha1Hash, false);
        }
        public static string FromHash(SyncProfile sp, SyncDirection direction, string hash)
        {
            ////////////////////TAKEN FROM pre-absorbtion NwdSynergy.ObjectGridWindow/////////////
            //
            ////load displayNameIndex.txt
            //List<DisplayNameIndexEntry> displayNames = new List<DisplayNameIndexEntry>();
            //string path = Configuration.GetPhoneSyncConfigFilePath("displayNameIndex");
            //foreach (string line in File.ReadAllLines(path))
            //{
            //    displayNames.Add(new DisplayNameIndexEntry()
            //    {
            //        DisplayName = p.Extract("displayName", line),
            //        DevicePath = p.Extract("path", line)
            //    });
            //}

            ////load fileHashIndex.txt
            //List<FileHashIndexEntry> fileHashes = new List<FileHashIndexEntry>();
            //path = Configuration.GetPhoneSyncConfigFilePath("fileHashIndex");
            //foreach (string line in File.ReadAllLines(path))
            //{
            //    fileHashes.Add(new FileHashIndexEntry()
            //    {
            //        DevicePath = p.Extract("path", line),
            //        SHA1Hash = p.Extract("sha1Hash", line)
            //    });
            //}

            //IEnumerable<SynergyRowObject> joinResult =
            //    from displayName in displayNames
            //    join fileHash in fileHashes
            //    on displayName.DevicePath equals fileHash.DevicePath
            //    select new SynergyRowObject
            //    {
            //        SHA1Hash = fileHash.SHA1Hash,
            //        DisplayName = displayName.DisplayName,
            //        DevicePath = fileHash.DevicePath
            //    };

            return "";
        }
Beispiel #7
0
        private static string GetTagsFromKeyValFile(SyncProfile sp, string sha1Hash)
        {
            //load by using profile to get sync root
            //which gives us NWD/config
            string fileHashIndexPath = Configuration.SyncRootConfigFile(sp.Name, "FileHashIndex");
            string tagIndexPath = Configuration.SyncRootConfigFile(sp.Name, "TagIndex");

            string tags = "";

            if (File.Exists(fileHashIndexPath) && File.Exists(tagIndexPath))
            {
                Parser.Parser p = new Parser.Parser();
                List<string> paths = new List<string>();

                //get all paths matching hash (may be multiple files, if copied in multiple places)
                foreach (string lineItem in File.ReadLines(fileHashIndexPath))
                {
                    string path = p.Extract("path", lineItem);
                    string hash = p.Extract("sha1Hash", lineItem);

                    if (!string.IsNullOrWhiteSpace(path) &&
                        !string.IsNullOrWhiteSpace(hash))
                    {
                        if (hash.Equals(sha1Hash, StringComparison.CurrentCultureIgnoreCase))
                        {
                            paths.Add(path);
                        }
                    }
                }

                List<string> tagStrings = new List<string>();

                //since we may have multiple files for a given hash, need to get all tags for those paths
                foreach (string lineItem in File.ReadLines(tagIndexPath))
                {
                    string path = p.Extract("path", lineItem);
                    string tagString = p.Extract("tags", lineItem);

                    if (paths.Contains(path))
                    {
                        tagStrings.Add(tagString);
                    }
                }

                //remove any duplicates
                HashSet<string> uniqueTags = new HashSet<string>();

                foreach (string tagString in tagStrings)
                {
                    var theseTags = StringToList(tagString);

                    foreach (string tag in theseTags)
                    {
                        if (!uniqueTags.Contains(tag))
                        {
                            uniqueTags.Add(tag);
                        }
                    }
                }

                tags = string.Join(", ", uniqueTags);
            }

            return tags;
        }
Beispiel #8
0
        public static void ReloadFromXmlFile(SyncProfile sp)
        {
            //load from file
            string xmlPath =
                Configuration.SyncRootMostRecentXmlFile(sp.Name);

            if (!string.IsNullOrWhiteSpace(xmlPath))
            {
                Xml.XmlImporter xi = new Xml.XmlImporter(xmlPath);

                foreach (FileModelItem fmi in xi.GetFiles())
                {
                    String tagString = string.Join(", ", fmi.GetTags());

                    foreach (HashModelItem hash in fmi.GetHashes())
                    {
                        hashToTagString[hash.GetHash()] = tagString;
                    }
                }
            }
        }
Beispiel #9
0
        public static Dictionary<string, string> LoadFromHashToTagsIndex(SyncProfile sp)
        {
            Dictionary<string, string> hashToTagString = new Dictionary<string, string>();
            Parser.Parser p = new Parser.Parser();

            //use syncprofile to load an existing one if it is there
            string exportedTagsIndexPath = HashToTagsIndexPath(sp, false);

            if (File.Exists(exportedTagsIndexPath))
            {
                foreach (string lineItem in File.ReadLines(exportedTagsIndexPath))
                {
                    string hash = p.Extract("sha1Hash", lineItem);
                    string tagString = p.Extract("tags", lineItem);

                    hashToTagString[hash] = tagString;
                }
            }

            return hashToTagString;
        }
Beispiel #10
0
        public static string ImportForHash(SyncProfile sp,
                                           string sha1Hash,
                                           bool tagsFromXmlNotKeyVal)
        {
            String tagString = "";

            if (tagsFromXmlNotKeyVal)
            {
                tagString = GetTagsFromXmlFile(sp, sha1Hash);
            }
            else
            {
                tagString = GetTagsFromKeyValFile(sp, sha1Hash);
            }

            return tagString;
        }
Beispiel #11
0
        public static string HashToTagsIndexPath(SyncProfile sp, bool timeStampList)
        {
            string name = "HashToTagsIndex";

            if (timeStampList)
            {
                name = NwdUtils.GetTimeStamp_yyyyMMddHHmmss() + "-" + name;
            }

            return Configuration.SyncRootConfigFile(sp.Name, name);
        }
 public string LoadSyncProfile(SyncProfile _syncProfile)
 {
     return db.LoadSyncProfile(_syncProfile);
 }
 string IDbAdapter.SaveSyncProfile(SyncProfile _syncProfile)
 {
     return db.SaveSyncProfile(_syncProfile);
 }
        public string SaveSyncProfile(SyncProfile sp)
        {
            string outputMsg = "implementation in progress";
            string time = "";

            //RefreshIds();

            try
            {
                using (var conn =
                    new SQLiteConnection(@"Data Source=" +
                        Configuration.GetSqliteDbPath(GetDbName())))
                {
                    conn.Open();

                    using (var cmd = new SQLiteCommand(conn))
                    {
                        using (var transaction = conn.BeginTransaction())
                        {
                            Stopwatch sw = Stopwatch.StartNew();

                            /////////use open transaction to insert or ignore all paths, and profile name.
                            int profileId = EnsureProfileId(sp.Name, cmd);

                            List<string> paths = sp.SyncMaps.AllPaths();

                            foreach (string path in paths)
                            {
                                InsertOrIgnorePath(path, cmd);
                            }

                            /////////use open transaction to get path ids for path values
                            Dictionary<string, int> pathIds = new Dictionary<string, int>();

                            //store all paths
                            foreach (string path in paths)
                            {
                                pathIds[path] = -1;
                            }

                            RefreshPathIds(pathIds, cmd);

                            foreach (SyncMap map in sp.SyncMaps)
                            {
                                int destId = pathIds[map.Destination];
                                int srcId = pathIds[map.Source];
                                //int directionId = directionIds[map.SyncDirection];
                                //int actionId = actionIds[map.DefaultSyncAction];
                                int directionId = GetDirectionId(map.SyncDirection);
                                int actionId = GetActionId(map.DefaultSyncAction);

                                UpsertSyncMap(profileId, srcId, destId, directionId, actionId, cmd);
                            }

                            transaction.Commit();

                            sw.Stop();
                            time = sw.Elapsed.ToString("mm\\:ss\\.ff");
                        }
                    }

                    conn.Close();
                }

                outputMsg = "Save Sync Profile Finished: " + time;
            }
            catch (Exception ex)
            {
                outputMsg = "error: " + ex.Message;
            }

            return outputMsg;
        }
 public void PopulateSyncMaps(SyncProfile sp, SQLiteCommand cmd)
 {
     db.PopulateSyncMaps(sp, cmd);
 }
 public abstract void PopulateSyncMaps(SyncProfile sp, SQLiteCommand cmd);
        public string LoadSyncProfile(SyncProfile sp)
        {
            string outputMsg = "implementation in progress";
            string time = "";

            try
            {
                //we need to make sure our id dictionaries are refreshed
                RefreshIds();

                using (var conn =
                    new SQLiteConnection(@"Data Source=" +
                        Configuration.GetSqliteDbPath(GetDbName())))
                {
                    conn.Open();

                    using (var cmd = new SQLiteCommand(conn))
                    {
                        using (var transaction = conn.BeginTransaction())
                        {
                            Stopwatch sw = Stopwatch.StartNew();

                            PopulateSyncMaps(sp, cmd);

                            transaction.Commit();

                            sw.Stop();
                            time = sw.Elapsed.ToString("mm\\:ss\\.ff");
                        }
                    }

                    conn.Close();
                }

                outputMsg = "Load Sync Profile Finished: " + time;
            }
            catch (Exception ex)
            {
                outputMsg = "error: " + ex.Message;
            }

            return outputMsg;
        }
 public static void ExportNamesForProfile(SyncProfile profile, string hash)
 {
     //needs implementation
 }
Beispiel #19
0
        private static string GetTagsFromXmlFile(SyncProfile sp, string sha1Hash)
        {
            if (hashToTagString.Count < 1)
            {
                ReloadFromXmlFile(sp);
            }

            String tagString = "";

            if (hashToTagString.ContainsKey(sha1Hash))
            {
                tagString = hashToTagString[sha1Hash];
            }

            return tagString;
        }
        private void SetDemoProfile()
        {
            _syncProfile = new SyncProfile("demo");

            _syncProfile.SyncMaps.Add(
                new SyncMap(_syncProfile,
                            SyncDirection.Import,
                            SyncAction.Ignore)
                {
                    Source = @"C:\Source\Path\Here",
                    Destination = @"C:\Destination\Path\Here"
                });

            _syncProfile.SyncMaps.Add(
                new SyncMap(_syncProfile,
                            SyncDirection.Export,
                            SyncAction.Ignore)
                {
                    Source = @"C:\Source\Path\Here",
                    Destination = @"C:\Destination\Path\Here"
                });

            _syncProfile.SyncMaps.Add(
                new SyncMap(_syncProfile,
                            SyncDirection.Import,
                            SyncAction.Ignore)
                {
                    Source = @"C:\Source\Path\Here",
                    Destination = @"C:\Destination\Path\Here"
                });

            _syncProfile.SyncMaps.Add(
                new SyncMap(_syncProfile,
                            SyncDirection.Export,
                            SyncAction.Ignore)
                {
                    Source = @"C:\Source\Path\Here",
                    Destination = @"C:\Destination\Path\Here"
                });
        }
Beispiel #21
0
        public override void PopulateSyncMaps(SyncProfile sp, SQLiteCommand cmd)
        {
            sp.SyncMaps.Clear();

            cmd.Parameters.Clear(); //since we will be reusing command
            cmd.CommandText =
                //"SELECT sp.SyncProfileName, " +
                //        "pSrc.PathValue AS SourcePath,  " +
                //        "pDst.PathValue AS DestPath, " +
                //        "sm.SyncDirectionId, " +
                //        "sm.SyncActionIdDefault " +
                //"FROM SyncMap AS sm " +
                //"JOIN SyncProfile AS sp " +
                //"ON sm.SyncProfileId = sp.SyncProfileId " +
                //"JOIN Path AS pSrc " +
                //"ON pSrc.PathId = sm.PathIdSource " +
                //"JOIN Path AS pDst " +
                //"ON pDst.PathId = sm.PathIdDestination " +
                //"WHERE sp.SyncProfileName = @name ";
                "SELECT sp." + NwdContract.COLUMN_SYNC_PROFILE_NAME + ", " +
                        "pSrc." + NwdContract.COLUMN_PATH_VALUE + " AS SourcePath,  " +
                        "pDst." + NwdContract.COLUMN_PATH_VALUE + " AS DestPath, " +
                        "sm." + NwdContract.COLUMN_SYNC_DIRECTION_ID + ", " +
                        "sm." + NwdContract.COLUMN_SYNC_ACTION_ID_DEFAULT + " " +
                "FROM " + NwdContract.TABLE_SYNC_MAP + " AS sm " +
                "JOIN " + NwdContract.TABLE_SYNC_PROFILE + " AS sp " +
                "ON sm." + NwdContract.COLUMN_SYNC_PROFILE_ID + " = sp." + NwdContract.COLUMN_SYNC_PROFILE_ID + " " +
                "JOIN " + NwdContract.TABLE_PATH + " AS pSrc " +
                "ON pSrc." + NwdContract.COLUMN_PATH_ID + " = sm." + NwdContract.COLUMN_PATH_ID_SOURCE + " " +
                "JOIN " + NwdContract.TABLE_PATH + " AS pDst " +
                "ON pDst." + NwdContract.COLUMN_PATH_ID + " = sm." + NwdContract.COLUMN_PATH_ID_DESTINATION + " " +
                "WHERE sp." + NwdContract.COLUMN_SYNC_PROFILE_NAME + " = @name ";

            cmd.Parameters.AddWithValue("@name", sp.Name);

            using (var rdr = cmd.ExecuteReader())
            {
                while (rdr.Read())
                {
                    string source = rdr.GetString(1);
                    string destination = rdr.GetString(2);
                    int directionId = rdr.GetInt32(3);
                    int actionId = rdr.GetInt32(4);

                    SyncDirection direction = idDirections[directionId];
                    SyncAction action = idActions[actionId];

                    sp.SyncMaps.Add(new SyncMap(sp,
                                                direction,
                                                action)
                    {
                        Source = source,
                        Destination = destination
                    });
                }
            }
        }
 internal string SaveSyncProfile(SyncProfile _syncProfile)
 {
     return db.SaveSyncProfile(_syncProfile);
 }
Beispiel #23
0
        public override void PopulateSyncProfiles(List<SyncProfile> lst, SQLiteCommand cmd)
        {
            cmd.Parameters.Clear(); //since we will be reusing command
            cmd.CommandText =
                //"SELECT SyncProfileName FROM SyncProfile";
                "SELECT " +
                    NwdContract.COLUMN_SYNC_PROFILE_NAME +
                " FROM " + NwdContract.TABLE_SYNC_PROFILE + " ";

            using (var rdr = cmd.ExecuteReader())
            {
                while (rdr.Read())
                {
                    string name = rdr.GetString(0);

                    SyncProfile sp = new SyncProfile(name);

                    lst.Add(sp);
                }
            }

            //cannot set command text while reader in use,
            //so need to populate after reader completes
            foreach (SyncProfile sp in lst)
            {
                PopulateSyncMaps(sp, cmd);
            }
        }
 public static string SyncRootNewXmlExportFile(SyncProfile sp)
 {
     string fileName = TimeStamp.Now() + "-nwd.xml";
     return Path.Combine(SyncRootXmlFolder(sp.Name), fileName);
 }