Skip to content
Permalink
Browse files

added autoupdate xmls (including update of database)

  • Loading branch information...
Piotr Szmielew
Piotr Szmielew committed Jun 4, 2012
1 parent ba82ad0 commit 72f0b60fdef7a1b757f7217ad15005334d4a19d4
@@ -0,0 +1,17 @@
= Autoupdating xml

If you want to use autoupdating xmls, you need to provide OCTGN with link to valid xml.
Xml file need to have this construction:
```
<?xml version="1.0" encoding="UTF-8"?>
<set>
<name>name of the set</name>
<game>uuid of the game</game>
<uuid>uuid of this specific set</uuid>
<version>version of set</version>
<date>date of last regeneration</date>
<link>link to download set</link>
<user>user to basic auth to download set (of left empty)</user>
<password>password to basic auth to download set (of left empty)</password>
</set>
```
@@ -42,6 +42,194 @@ public static string GetUser(string jid)
return null;
}



public static string GetXmlString(int id, string gid)
{
using (var con = new SQLiteConnection(ConString))
{
con.Open();
using (var com = con.CreateCommand())
{
com.CommandText = "SELECT * FROM xml WHERE id=@id AND gid=@gid";
com.CommandType = CommandType.Text;
com.Parameters.AddWithValue("@id", id);
com.Parameters.AddWithValue("@gid", gid);
using(var r = com.ExecuteReader())
{
if(r.Read())
{
return r.GetString(0);
}
}
}
con.Close();
}
return null;
}

public static void AddXmlString(string xml_link, string gid)
{
using (var con = new SQLiteConnection(ConString))
{
con.Open();
using (var com = con.CreateCommand())
{
com.CommandText = "INSERT INTO xml(xml_link, gid) VALUES(@xml_link, @gid)";
com.Parameters.AddWithValue("@xml_link", xml_link);
com.Parameters.AddWithValue("@gid", gid);
com.ExecuteNonQuery();
}
con.Close();
}
}

public static List<String> GetAllXmls(string gid)
{
var result = new List<String>();
using (var con = new SQLiteConnection(ConString))
{
con.Open();
using (var com = con.CreateCommand())
{
com.CommandText = "SELECT xml_link FROM xml WHERE gid=@gid AND xml_link != ''";
com.Parameters.AddWithValue("@gid", gid);
using (var reader = com.ExecuteReader())
{
while (reader.Read())
{
result.Add(reader.GetString(0));
}
}
}
con.Close();
}
return result;
}

public static void DeleteXml(string id, string gid)
{
using (var con = new SQLiteConnection(ConString))
{
con.Open();
using (var com = con.CreateCommand())
{
com.CommandText = "DELETE FROM xml WHERE gid=@gid AND id=@id";
com.Parameters.AddWithValue("@id", id);
com.Parameters.AddWithValue("@gid", gid);
com.ExecuteNonQuery();
}
con.Close();
}
}

public static void DeleteXmlByLink(string xml_link, string gid)
{
using (var con = new SQLiteConnection(ConString))
{
con.Open();
using (var com = con.CreateCommand())
{
com.CommandText = "DELETE FROM xml WHERE gid=@gid AND xml_link=@xml_link";
com.Parameters.AddWithValue("@xml_link", xml_link);
com.Parameters.AddWithValue("@gid", gid);
com.ExecuteNonQuery();
}
con.Close();
}
}

public static void AddOldXmlToXmlString(int id, string old_xml, string gid)
{
using (var con = new SQLiteConnection(ConString))
{
con.Open();
using (var com = con.CreateCommand())
{
com.CommandText = "UPDATE xml SET old_xml=@old_xml WHERE id=@id AND gid=@gid";
com.Parameters.AddWithValue("@old_xml", old_xml);
com.Parameters.AddWithValue("@gid", gid);
com.Parameters.AddWithValue("@id", id);
com.ExecuteNonQuery();
}
con.Close();
}
}

public static String GetOldXmlByLink(string xml_link, string gid)
{
var result = "";
using (var con = new SQLiteConnection(ConString))
{
con.Open();
using (var com = con.CreateCommand())
{
com.CommandText = "SELECT old_xml FROM xml WHERE gid=@gid AND xml_link=@xml_link";
com.Parameters.AddWithValue("@gid", gid);
com.Parameters.AddWithValue("@xml_link", xml_link);
using (var reader = com.ExecuteReader())
{
while (reader.Read())
{
try
{
result = reader.GetString(0);
}
catch
{
result = null;
}
}
}
}
con.Close();
}
return result;

}

public static void WriteOldXmlByLink(string xml_link, string old_xml, string gid)
{
using (var con = new SQLiteConnection(ConString))
{
con.Open();
using (var com = con.CreateCommand())
{
com.CommandText = "UPDATE xml SET old_xml=@old_xml WHERE xml_link=@xml_link AND gid=@gid";
com.Parameters.AddWithValue("@old_xml", old_xml);
com.Parameters.AddWithValue("@gid", gid);
com.Parameters.AddWithValue("@xml_link", xml_link);
com.ExecuteNonQuery();
}
con.Close();
}
}

public static string SearchXmlByLink(string xml_link, string gid)
{
using (var con = new SQLiteConnection(ConString))
{
con.Open();
using (var com = con.CreateCommand())
{
com.CommandText = "SELECT xml_link FROM xml WHERE xml_link=@xml_link AND gid=@gid";
com.CommandType = CommandType.Text;
com.Parameters.AddWithValue("@xml_link", xml_link);
com.Parameters.AddWithValue("@gid", gid);
using (var r = com.ExecuteReader())
{
if (r.Read())
{
return r.GetString(0);
}
}
}
con.Close();
}
return null;

}

public static void AddUser(string jid, string email)
{
using (var con = new SQLiteConnection(ConString))
@@ -62,6 +62,38 @@ public Uri GetCardBackUri()
return u;
}

public List<String> GetAllXmls()
{
List<String> list = Octgn.Data.DatabaseHandler.GetAllXmls(Id.ToString());
return list;
}

public String GetXmlByLink(string xml_link)
{
string str = Octgn.Data.DatabaseHandler.SearchXmlByLink(xml_link, Id.ToString());
return str;
}

public void DeleteXmlByLink(string xml_link)
{
Octgn.Data.DatabaseHandler.DeleteXmlByLink(xml_link, Id.ToString());
}

public void AddXml(string xml_link)
{
Octgn.Data.DatabaseHandler.AddXmlString(xml_link, Id.ToString());
}

public void WriteOldXmlByLink(string xml_link, string old_xml)
{
Octgn.Data.DatabaseHandler.WriteOldXmlByLink(xml_link, old_xml, Id.ToString());
}

public String GetOldXmlByLink(string xml_link)
{
return Octgn.Data.DatabaseHandler.GetOldXmlByLink(xml_link, Id.ToString());
}

public Set GetSet(Guid id)
{
using (SQLiteCommand com = GamesRepository.DatabaseConnection.CreateCommand())
@@ -718,4 +750,5 @@ orderby pair.Value
return candidates.Select(r => CardModel.FromDataRow(this, r));
}
}

}
@@ -4,7 +4,7 @@ CREATE TABLE [dbinfo] (
[version] INTEGER NOT NULL
);

INSERT INTO dbinfo([version]) VALUES(5);
INSERT INTO dbinfo([version]) VALUES(6);

CREATE TABLE [games] (
[real_id] INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -66,6 +66,12 @@ CREATE TABLE [packs] (
CREATE TABLE [users](
[id] INTEGER PRIMARY KEY AUTOINCREMENT,
[jid] TEXT NOT NULL,
[email] TEXT NOT NULL
);
[email] TEXT NOT NULL);

CREATE TABLE[xml](
[id] INTEGER PRIMARY KEY AUTOINCREMENT,
[xml_link] TEXT NOT NULL,
[gid] TEXT NOT NULL,
[old_xml] TEXT);

commit transaction;
@@ -25,4 +25,14 @@
);
]]>
</update>
<update from="5" to="6">
<![CDATA[
CREATE TABLE[xml](
[id] INTEGER PRIMARY KEY AUTOINCREMENT,
[xml_link] TEXT NOT NULL,
[gid] TEXT NOT NULL,
[old_xml] TEXT
);
]]>
</update>
</updates>
@@ -76,6 +76,7 @@ private static void CurrentDomainUnhandledException(object sender, UnhandledExce
{
var ex = (Exception) e.ExceptionObject;
Console.WriteLine(ex.StackTrace);
Console.ReadLine();
}
}
}
@@ -383,6 +383,8 @@ private void OnPropertyChanged(string propertyName)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}



#region MEF stuff for easy services composition

private static readonly AssemblyCatalog Catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
Binary file not shown.
@@ -45,7 +45,7 @@
</EventTrigger>
</Page.Triggers>

<Grid>
<Grid Height="380">
<Grid.RowDefinitions>
<RowDefinition Height="20" />
<RowDefinition Height="100*" />
@@ -70,7 +70,7 @@
<MenuItem Name="menuAboutUs" Header="About Us" Click="menuAboutUs_Click" />
</MenuItem>
</Menu>
<Grid x:Name="MainGrid" Margin="10" Grid.Row="1" Background="{x:Null}">
<Grid x:Name="MainGrid" Margin="10,10,10,12" Grid.Row="1" Background="{x:Null}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="378*" />
<ColumnDefinition Width="375*" />
@@ -96,7 +96,7 @@
</TextBlock.Effect>
</TextBlock>
<TextBlock Foreground="#FFF00000" HorizontalAlignment="Right" Margin="0,0,232,6" Name="versionText"
Style="{x:Null}" TextWrapping="Wrap" VerticalAlignment="Bottom">Version 0.2.0.1</TextBlock>
Style="{x:Null}" TextWrapping="Wrap" VerticalAlignment="Bottom" Text="3.0.1.10"></TextBlock>
<Viewbox Height="82.137" HorizontalAlignment="Left" Margin="50,0,0,0" RenderTransformOrigin="0.5,0.5"
Stretch="UniformToFill" VerticalAlignment="Center" Width="82.137">
<Viewbox.RenderTransform>
@@ -265,10 +265,10 @@ StrokeLineJoin="Round" StrokeThickness="0.32" VerticalAlignment="Stretch" Width=
</Grid>
</StackPanel>

<Border BorderThickness="1" Height="222" HorizontalAlignment="Center" Margin="18,0,10,6" Name="border3"
<Border BorderThickness="1" Height="227" HorizontalAlignment="Center" Margin="12,0,16,6" Name="border3"
Style="{StaticResource Panel}" VerticalAlignment="Bottom" Visibility="Visible" Width="347" Grid.Row="2" Grid.Column="1"
Padding="5" Grid.RowSpan="2">
<ScrollViewer VerticalScrollBarVisibility="Auto" ClipToBounds="True">
<ScrollViewer VerticalScrollBarVisibility="Auto" ClipToBounds="True" Height="215">
<TextBlock FontWeight="Bold" Foreground="White" HorizontalAlignment="Center" Name="textBlock5"
VerticalAlignment="Center" FontSize="12" TextWrapping="Wrap" Text="Loading Headlines">
</TextBlock>
@@ -287,8 +287,7 @@ StrokeLineJoin="Round" StrokeThickness="0.32" VerticalAlignment="Stretch" Width=
</LinearGradientBrush>
</Border.BorderBrush>
</Border>

</Grid>
</Grid>

</Grid>
</Page>
@@ -499,6 +499,7 @@ private void menuInstallOnBoot_Unchecked(object sender, RoutedEventArgs e)
Prefs.InstallOnBoot = menuInstallOnBoot.IsChecked;
}


}

}
@@ -13,6 +13,7 @@ namespace Octgn.Launcher
public partial class SetList
{
public Data.Game SelectedGame;
private Data.Game game;

public SetList(Data.Game selectedGame)
{
@@ -128,5 +129,11 @@ public void PatchSelected()
new Windows.PatchDialog {Owner = Program.MainWindow}.ShowDialog();
RefreshList();
}

public void AddAutoUpdatedSets()
{
new Windows.UrlSetList { game = SelectedGame }.ShowDialog();
RefreshList();
}
}
}

0 comments on commit 72f0b60

Please sign in to comment.
You can’t perform that action at this time.