Browse Source

minor changes to ensure that the user is prompted when an attempt it made to overwrite and existing local metadata file

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1704 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Dickon Field 19 years ago
parent
commit
c4fe8d4e5a
  1. 36
      src/AddIns/Misc/SharpDbTools/Project/Src/Model/DbModelInfoService.cs
  2. 16
      src/AddIns/Misc/SharpDbTools/Project/Src/ServerBrowserTool.cs

36
src/AddIns/Misc/SharpDbTools/Project/Src/Model/DbModelInfoService.cs

@ -122,7 +122,14 @@ namespace SharpDbTools.Model @@ -122,7 +122,14 @@ namespace SharpDbTools.Model
return modelInfo;
}
public static void SaveToFile(string name)
/// <summary>
///
/// </summary>
/// <param name="name">the logical name of the DbModelInfo to save to a file</param>
/// <param name="overwriteExistingFile">if true, any existing file will be overwritten</param>
/// <returns>true if the DbModelInfo was saved, false if not. It will not be saved if
/// either overwriteExistingFile is set to true, and there is an existing file</returns>
public static bool SaveToFile(string name, bool overwriteExistingFile)
{
string path = GetSaveLocation();
DbModelInfo modelInfo = null;
@ -134,21 +141,28 @@ namespace SharpDbTools.Model @@ -134,21 +141,28 @@ namespace SharpDbTools.Model
string filePath = path + @"\" + name + ".metadata";
LoggingService.Debug("writing metadata to: " + filePath);
if (File.Exists(filePath)) {
File.Delete(filePath);
if (overwriteExistingFile) {
File.Delete(filePath);
} else {
return false;
}
}
using (StreamWriter sw = File.CreateText(filePath)) {
string xml = modelInfo.GetXml();
sw.Write(xml);
sw.Flush();
sw.Close();
return true;
}
} else {
throw new DbModelInfoDoesNotExistException(name);
}
}
public static void SaveAll()
{
foreach (string name in cache.Keys) {
SaveToFile(name);
SaveToFile(name, true);
}
}
@ -218,4 +232,20 @@ namespace SharpDbTools.Model @@ -218,4 +232,20 @@ namespace SharpDbTools.Model
return saveLocation;
}
}
public class DbModelInfoDoesNotExistException: ApplicationException
{
string name;
public DbModelInfoDoesNotExistException(string dbModelInfoName): base()
{
this.name = dbModelInfoName;
}
public string Name {
get {
return name;
}
}
}
}

16
src/AddIns/Misc/SharpDbTools/Project/Src/ServerBrowserTool.cs

@ -276,8 +276,20 @@ namespace SharpDbTools @@ -276,8 +276,20 @@ namespace SharpDbTools
public void SaveDbModelInfoClickHandler(object sender, EventArgs e)
{
LoggingService.Debug("save all metadata clicked");
DbModelInfoService.SaveAll();
// save each DbModelInfo separately, confirming overwrite where necessary
LoggingService.Debug("save all metadata clicked - will iterate through each and attempt to save");
IList<string> names = DbModelInfoService.Names;
foreach (string name in names) {
bool saved = DbModelInfoService.SaveToFile(name, false);
if (!saved) {
DialogResult result = MessageBox.Show("Overwrite existing file for connection: " + name + "?",
"File exists for connection", MessageBoxButtons.YesNo,
MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
if (result.Equals(DialogResult.Yes)) {
DbModelInfoService.SaveToFile(name, true);
}
}
}
}
public void LoadMetadataFromFileClickHandler(object sender, EventArgs e)

Loading…
Cancel
Save