public static Log ( LogLevel level, string msg ) : void | ||
level | LogLevel | |
msg | string | |
return | void |
private void FlickrSync_Load(object sender, EventArgs e) { string token = ""; try { token = Properties.Settings.Default.FlickrToken; } catch (Exception) { } if (token == "") { FlickrGetToken(); } messages_level = FlickrSync.StringToMsgLevel(Properties.Settings.Default.MessageLevel); log_level = FlickrSync.StringToLogLevel(Properties.Settings.Default.LogLevel); if (autorun) { messages_level = MessagesLevel.MessagesNone; } // ri is needed to get the user. TODO: Get User without using ri ri = new RemoteInfo(); UpdateUser(); LoadConfig(); Reload(); FlickrSync.Log(LogLevel.LogBasic, "Application loaded"); if (autorun) { WindowState = FormWindowState.Minimized; } else { WindowState = FormWindowState.Maximized; } if (autorun) { ViewAndSync(); Close(); } }
private void FlickrSync_Load(object sender, EventArgs e) { // probably not needed but just to make sure no message from previous versions is shown if (Properties.Settings.Default.MessageId.CompareTo("090130_0000") < 0) { Properties.Settings.Default.MessageId = "090130_0000"; Properties.Settings.Default.Save(); } HashUsers = new ArrayList(); OAuthAccessToken token = null; try { token = Properties.Settings.Default.OAuthToken; } catch (Exception) { } if (token == null) { FlickrGetToken(); } messages_level = FlickrSync.StringToMsgLevel(Properties.Settings.Default.MessageLevel); log_level = FlickrSync.StringToLogLevel(Properties.Settings.Default.LogLevel); if (autorun) { messages_level = MessagesLevel.MessagesNone; } // ri is needed to get the user. TODO: Get User without using ri try { ri = new RemoteInfo(); } catch (FlickrNet.Exceptions.LoginFailedInvalidTokenException) { FlickrGetToken(); ri = new RemoteInfo(); } UpdateUser(); LoadConfig(); Reload(); FlickrSync.Log(LogLevel.LogBasic, "Application loaded"); if (autorun) { WindowState = FormWindowState.Minimized; } else { WindowState = FormWindowState.Maximized; } if (!message_tested) { try { webBrowser1.Navigate(Properties.Settings.Default.MessageUrl + "?version=" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()); } catch (Exception) { } } if (autorun) { ViewAndSync(); Close(); } }
public void LoadFromXML(string xml) { XmlDocument xmldoc = new XmlDocument(); xmldoc.LoadXml(xml); XPathNavigator nav = xmldoc.CreateNavigator(); XPathNodeIterator iterator = nav.Select("/FlickrSync/SyncFolder"); while (iterator.MoveNext()) { SyncFolder sf = new SyncFolder(); XPathNavigator nav2 = iterator.Current; sf.LoadFromXPath(nav2); DirectoryInfo dir = new DirectoryInfo(sf.FolderPath); if (!dir.Exists) { if (FlickrSync.messages_level != FlickrSync.MessagesLevel.MessagesNone) { if (MessageBox.Show("Folder " + sf.FolderPath + " no longer exists. Remove from configuration?", "Warning", MessageBoxButtons.YesNo) == DialogResult.Yes) { FlickrSync.Log(FlickrSync.LogLevel.LogAll, sf.FolderPath + "marked for removal from configuration"); continue; } else { FlickrSync.Log(FlickrSync.LogLevel.LogAll, sf.FolderPath + "does not exists"); } } } SyncFolders.Add(sf); } iterator = nav.Select("/FlickrSync/PathInfo"); while (iterator.MoveNext()) { PathInfo pi = new PathInfo(); XPathNavigator nav2 = iterator.Current; pi.LoadFromXPath(nav2); DirectoryInfo dir = new DirectoryInfo(pi.Path); if (!dir.Exists) { if (!pi.ManualAdd) { continue; } if (FlickrSync.messages_level != FlickrSync.MessagesLevel.MessagesNone) { if (MessageBox.Show("Folder " + pi.Path + " no longer exists. Remove from configuration?", "Warning", MessageBoxButtons.YesNo) == DialogResult.Yes) { FlickrSync.Log(FlickrSync.LogLevel.LogAll, "Path" + pi.Path + " marked for removal from configuration"); continue; } else { FlickrSync.Log(FlickrSync.LogLevel.LogAll, "Path" + pi.Path + " no longer exists"); } } } PathInfoList.Add(pi); } }
public void LoadFromXML(string xml) { // current search/replace pattern in case base directory has moved List <SearchReplace> paths = new List <SearchReplace>(); XmlDocument xmldoc = new XmlDocument(); xmldoc.LoadXml(xml); XPathNavigator nav = xmldoc.CreateNavigator(); XPathNodeIterator iterator = nav.Select("/FlickrSync/SyncFolder"); while (iterator.MoveNext()) { SyncFolder sf = new SyncFolder(); XPathNavigator nav2 = iterator.Current; sf.LoadFromXPath(nav2); DirectoryInfo dir = new DirectoryInfo(sf.FolderPath); if (!dir.Exists && paths.Count > 0) { for (int i = 0; i < paths.Count; i++) { if (sf.FolderPath.StartsWith(paths[i].oldpath)) { // Directory no longer exists, but it seems that we might be able to find its new location, // based on an alternate directory location we got from a previously missing directory string potentialFolderPath = sf.FolderPath.Replace(paths[i].oldpath, paths[i].newpath); // replace prefix as we did last time dir = new DirectoryInfo(potentialFolderPath); // Have we succeeded? silently replace prefix if (dir.Exists) { FlickrSync.Log(FlickrSync.LogLevel.LogAll, "Replaced " + sf.FolderPath + " with " + potentialFolderPath + " based on previous alternate directory location"); sf.FolderPath = potentialFolderPath; paths[i].use_count++; } } } } if (!dir.Exists) { if (FlickrSync.messages_level != FlickrSync.MessagesLevel.MessagesNone) { InformationBoxResult r = InformationBox.Show( "Folder " + sf.FolderPath + " no longer exists. Remove from list of folders to sync?", "Folder not found", InformationBoxButtons.YesNoUser1, new string[] { "Find on disk", String.Empty }, InformationBoxIcon.Exclamation, InformationBoxDefaultButton.Button2); if (r == InformationBoxResult.Yes) { FlickrSync.Log(FlickrSync.LogLevel.LogAll, sf.FolderPath + "marked for removal from configuration"); continue; } else if (r == InformationBoxResult.User1) { Microsoft.WindowsAPICodePack.Dialogs.CommonOpenFileDialog cofd = new Microsoft.WindowsAPICodePack.Dialogs.CommonOpenFileDialog(); //cofd.InitialDirectory = oldpaths[oldpaths.Length-1]; cofd.Multiselect = false; cofd.IsFolderPicker = true; if (cofd.ShowDialog() == Microsoft.WindowsAPICodePack.Dialogs.CommonFileDialogResult.Ok) { string newfolderpath = cofd.FileName.ToString(); SearchReplace p = new SearchReplace(sf.FolderPath, newfolderpath); paths.Add(p); FlickrSync.Log(FlickrSync.LogLevel.LogAll, sf.FolderPath + "replaced by " + newfolderpath + " in the configuration"); FlickrSync.Log(FlickrSync.LogLevel.LogAll, "From now on, we will try replacing " + p.oldpath + " by " + p.newpath); sf.FolderPath = newfolderpath; } else { FlickrSync.Log(FlickrSync.LogLevel.LogAll, sf.FolderPath + "not replaced after all"); continue; } } else { FlickrSync.Log(FlickrSync.LogLevel.LogAll, sf.FolderPath + "does not exists"); } } } SyncFolders.Add(sf); } foreach (var p in paths) { if (p.use_count > 0) { MessageBox.Show("Replaced Folder prefix " + p.oldpath + " with " + p.newpath + ((p.use_count == 1) ? " once" : " " + p.use_count.ToString() + " times"), "Info", MessageBoxButtons.OK); } } iterator = nav.Select("/FlickrSync/PathInfo"); while (iterator.MoveNext()) { PathInfo pi = new PathInfo(); XPathNavigator nav2 = iterator.Current; pi.LoadFromXPath(nav2); DirectoryInfo dir = new DirectoryInfo(pi.Path); if (!dir.Exists) { if (!pi.ManualAdd) { continue; } if (FlickrSync.messages_level != FlickrSync.MessagesLevel.MessagesNone) { if (MessageBox.Show("Folder " + pi.Path + " no longer exists. Remove from configuration?", "Warning", MessageBoxButtons.YesNo) == DialogResult.Yes) { FlickrSync.Log(FlickrSync.LogLevel.LogAll, "Path" + pi.Path + " marked for removal from configuration"); continue; } else { FlickrSync.Log(FlickrSync.LogLevel.LogAll, "Path" + pi.Path + " no longer exists"); } } } PathInfoList.Add(pi); } }