using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml;
namespace installer
{
public partial class installerWebSticky : System.Web.UI.UserControl
{
public System.Web.UI.WebControls.Literal literalRestExtension;
public System.Web.UI.WebControls.Literal literalDatabaseTable;
public System.Web.UI.WebControls.Literal literalSuccess;
protected void Page_Load(object sender, EventArgs e)
{
this.addRestEXtensions();
this.CreateTable();
literalRestExtension.Text = "Webstickies successfuly installed. Try it right now: WebSTickies
Send any comments or bug reports to len.dierickx@gmail.com.";
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
// this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void addRestEXtensions(){
XmlDocument document = new XmlDocument();
document.Load(Server.MapPath("/config/") + "restExtensions.config");
if (document.SelectNodes("/ext [@assembly = '/bin/webstickies']").Count == 0)
{
XmlNode newChild = document.CreateElement("ext");
XmlAttribute AtAssembly = document.CreateAttribute("assembly");
AtAssembly.Value = "/bin/webstickies";
newChild.Attributes.Append(AtAssembly);
XmlAttribute atType = document.CreateAttribute("type");
atType.Value = "webstickies.ws";
newChild.Attributes.Append(atType);
XmlAttribute atAlias = document.CreateAttribute("alias");
atAlias.Value = "ws";
newChild.Attributes.Append(atAlias);
/**/
XmlNode permissionNode = document.CreateElement("permission");
newChild.AppendChild(permissionNode);
XmlAttribute atMethod = document.CreateAttribute("method");
atMethod.Value = "getnotes";
permissionNode.Attributes.Append(atMethod);
XmlAttribute atAllowAll = document.CreateAttribute("allowAll");
atAllowAll.Value = "true";
permissionNode.Attributes.Append(atAllowAll);
/**/
XmlNode permissionNode2 = document.CreateElement("permission");
newChild.AppendChild(permissionNode2);
XmlAttribute atMethod2 = document.CreateAttribute("method");
atMethod2.Value = "savenote";
permissionNode2.Attributes.Append(atMethod2);
XmlAttribute atAllowAll2 = document.CreateAttribute("allowAll");
atAllowAll2.Value = "true";
permissionNode2.Attributes.Append(atAllowAll2);
/**/
XmlNode permissionNode3 = document.CreateElement("permission");
newChild.AppendChild(permissionNode3);
XmlAttribute atMethod3 = document.CreateAttribute("method");
atMethod3.Value = "deletenote";
permissionNode3.Attributes.Append(atMethod3);
XmlAttribute atAllowAll3 = document.CreateAttribute("allowAll");
atAllowAll3.Value = "true";
permissionNode3.Attributes.Append(atAllowAll3);
document.DocumentElement.AppendChild(newChild);
document.Save(Server.MapPath("/config/") + "restExtensions.config");
}
}
private void CreateTable()
{
try
{
using (SqlConnection cn = new SqlConnection(ConfigurationManager.AppSettings.Get("umbracoDbDSN").ToString()))
{
string query = @"CREATE TABLE [dbo].[pluginWebstickies](
[id] [int] IDENTITY(1,1) NOT NULL,
[user] [int] NOT NULL,
[noteText] [ntext] NULL,
[nodeId] [int] NOT NULL,
[isClosed] [bit] NULL,
[x] [int] NULL,
[y] [int] NULL,
CONSTRAINT [PK_pluginWebstickies] PRIMARY KEY CLUSTERED
(
[id] ASC
) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]";
SqlCommand cmd = new SqlCommand(query, cn);
cn.Open();
cmd.ExecuteNonQuery();
}
}
catch (Exception x)
{
Response.Write(x.Message);
}
}
}
}