public SiteUtilBase CloneFreshSiteFromExisting(SiteUtilBase site) { // create new instance of this site with reset settings SerializableSettings s = new SerializableSettings() { Sites = new BindingList <SiteSettings>() }; s.Sites.Add(site.Settings); System.IO.MemoryStream ms = new System.IO.MemoryStream(); s.Serialize(ms); ms.Position = 0; SiteSettings originalSettings = SerializableSettings.Deserialize(new StreamReader(ms))[0]; return(CreateUtilFromShortName(site.Settings.UtilName, originalSettings)); }
void Publish(object sender) { // set current Time to last updated in the xml, so it can be compared later DateTime lastUdpBkp = Site.LastUpdated; Site.LastUpdated = DateTime.Now; SerializableSettings s = new SerializableSettings() { Sites = new BindingList<SiteSettings>() }; s.Sites.Add(Site); var siteDoc = new XmlDocument(); using (var ms = new MemoryStream()) { s.Serialize(ms); ms.Position = 0; siteDoc.Load(ms); } XmlWriterSettings xmlSettings = new XmlWriterSettings { Encoding = Encoding.UTF8, Indent = true, OmitXmlDeclaration = true }; StringBuilder sb = new StringBuilder(); XmlWriter writer = XmlWriter.Create(sb, xmlSettings); siteDoc.SelectSingleNode("//Site").WriteTo(writer); writer.Flush(); string siteXmlString = sb.ToString(); byte[] icon = null; string image = Path.Combine(Path.Combine(OnlineVideoSettings.Instance.ThumbsDir, "Icons"), Site.Name + ".png"); if (File.Exists(image)) icon = File.ReadAllBytes(image); byte[] banner = null; image = Path.Combine(Path.Combine(OnlineVideoSettings.Instance.ThumbsDir, "Banners"), Site.Name + ".png"); if (File.Exists(image)) banner = File.ReadAllBytes(image); bool success = false; try { string dll = OnlineVideos.Sites.SiteUtilFactory.RequiredDll(Site.UtilName); var ws = new OnlineVideos.OnlineVideosWebservice.OnlineVideosService(); string msg = ""; if (!string.IsNullOrEmpty(dll)) { string location = Path.Combine(OnlineVideoSettings.Instance.DllsDir, dll + ".dll"); if (File.Exists(location)) { byte[] data = File.ReadAllBytes(location); System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider(); string md5LocalDll = BitConverter.ToString(md5.ComputeHash(data)).Replace("-", "").ToLower(); // check webservice if we need to submit the dll string md5RemoteDll = null; string owner = ws.GetDllOwner(dll, out md5RemoteDll); bool dllFound = md5RemoteDll != null; bool dllsAreEqual = dllFound ? md5RemoteDll == md5LocalDll : false; bool userIsOwner = dllFound ? owner == Email : true; if (!dllsAreEqual) { bool isAdmin = false; if (!userIsOwner) { if (MessageBox.Show("Only administrators can overwrite a DLL they don't own. I am an Admin. Proceed?", "New DLL - Admin required", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes) { return; } } if (userIsOwner || isAdmin) { string info = dllFound ? "DLL found on server differs from your local file, do you want to update the existing one?" : "Do you want to upload the required dll?"; if (MessageBox.Show(info, "DLL required", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { if (data == null) data = File.ReadAllBytes(location); success = ws.SubmitDll(Email, Password, dll, data, out msg); MessageBox.Show(msg, success ? Translation.Instance.Success : Translation.Instance.Error, MessageBoxButton.OK, success ? MessageBoxImage.Information : MessageBoxImage.Error); } } } } } success = ws.SubmitSite(Email, Password, siteXmlString, icon, banner, dll, out msg); MessageBox.Show(msg, success ? Translation.Instance.Success : Translation.Instance.Error, MessageBoxButton.OK, success ? MessageBoxImage.Information : MessageBoxImage.Error); } catch (Exception ex) { MessageBox.Show(ex.Message, Translation.Instance.Error, MessageBoxButton.OK, MessageBoxImage.Error); } // if the site was not submitted, restore old last updated date, so saving won't write the wrong value if (!success) Site.LastUpdated = lastUdpBkp; }
private void btnPublishSite_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(PluginConfiguration.Instance.email) || string.IsNullOrEmpty(PluginConfiguration.Instance.password)) { if (MessageBox.Show("Do you want to register an Email now?", "Registration required!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { RegisterEmail reFrm = new RegisterEmail(); reFrm.tbxEmail.Text = PluginConfiguration.Instance.email; reFrm.tbxPassword.Text = PluginConfiguration.Instance.password; if (reFrm.ShowDialog() == DialogResult.OK) { PluginConfiguration.Instance.email = reFrm.tbxEmail.Text; PluginConfiguration.Instance.password = reFrm.tbxPassword.Text; } } return; } foreach (SiteSettings site in siteList.SelectedObjects) { // set current Time to last updated in the xml, so it can be compared later DateTime lastUdpBkp = site.LastUpdated; site.LastUpdated = DateTime.Now; SerializableSettings s = new SerializableSettings() { Sites = new BindingList<SiteSettings>() }; s.Sites.Add(site); System.IO.MemoryStream ms = new System.IO.MemoryStream(); s.Serialize(ms); ms.Position = 0; System.Xml.XmlDocument siteDoc = new System.Xml.XmlDocument(); siteDoc.Load(ms); XmlWriterSettings xmlSettings = new XmlWriterSettings(); xmlSettings.Encoding = System.Text.Encoding.UTF8; xmlSettings.Indent = true; xmlSettings.OmitXmlDeclaration = true; StringBuilder sb = new StringBuilder(); XmlWriter writer = XmlWriter.Create(sb, xmlSettings); siteDoc.SelectSingleNode("//Site").WriteTo(writer); writer.Flush(); string siteXmlString = sb.ToString(); byte[] icon = null; string image = Path.Combine(Path.Combine(OnlineVideoSettings.Instance.ThumbsDir, "Icons"), site.Name + ".png"); if (File.Exists(image)) icon = File.ReadAllBytes(image); byte[] banner = null; image = Path.Combine(Path.Combine(OnlineVideoSettings.Instance.ThumbsDir, "Banners"), site.Name + ".png"); if (File.Exists(image)) banner = File.ReadAllBytes(image); bool success = false; try { string dll = Sites.SiteUtilFactory.RequiredDll(site.UtilName); OnlineVideosWebservice.OnlineVideosService ws = new OnlineVideos.OnlineVideosWebservice.OnlineVideosService(); string msg = ""; if (!string.IsNullOrEmpty(dll)) { string location = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "OnlineVideos\\") + dll + ".dll"; if (System.IO.File.Exists(location)) { byte[] data = System.IO.File.ReadAllBytes(location); System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider(); string md5LocalDll = BitConverter.ToString(md5.ComputeHash(data)).Replace("-", "").ToLower(); // check webservice if we need to submit the dll string md5RemoteDll = null; string owner = ws.GetDllOwner(dll, out md5RemoteDll); bool dllFound = md5RemoteDll != null; bool dllsAreEqual = dllFound ? md5RemoteDll == md5LocalDll : false; bool userIsOwner = dllFound ? owner == PluginConfiguration.Instance.email : true; if (!dllsAreEqual) { bool isAdmin = false; if (!userIsOwner) { if (MessageBox.Show("Only administrators can overwrite a DLL they don't own. I am an Admin. Proceed?", "New DLL - Admin required", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { isAdmin = true; } } if (userIsOwner || isAdmin) { string info = dllFound ? "DLL found on server differs from your local file, do you want to update the existing one?" : "Do you want to upload the required dll?"; if (MessageBox.Show(info, "DLL required", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { if (data == null) data = System.IO.File.ReadAllBytes(location); success = ws.SubmitDll(PluginConfiguration.Instance.email, PluginConfiguration.Instance.password, dll, data, out msg); MessageBox.Show(msg, success ? Translation.Instance.Success : Translation.Instance.Error, MessageBoxButtons.OK, success ? MessageBoxIcon.Information : MessageBoxIcon.Error); } } } } } success = ws.SubmitSite(PluginConfiguration.Instance.email, PluginConfiguration.Instance.password, siteXmlString, icon, banner, dll, out msg); MessageBox.Show(msg, success ? Translation.Instance.Success : Translation.Instance.Error, MessageBoxButtons.OK, success ? MessageBoxIcon.Information : MessageBoxIcon.Error); } catch (Exception ex) { MessageBox.Show(ex.Message, Translation.Instance.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } // if the site was not submitted, restore old last updated date, so saving won't write the wrong value if (!success) site.LastUpdated = lastUdpBkp; } }
private void btnEditSite_Click(object sender, EventArgs e) { SiteSettings siteSettings = (SiteSettings)bindingSourceSiteSettings.Current; // use a copy of the original settings so anything that is changed can be canceled SerializableSettings s = new SerializableSettings() { Sites = new BindingList<SiteSettings>() }; s.Sites.Add(siteSettings); System.IO.MemoryStream ms = new System.IO.MemoryStream(); s.Serialize(ms); ms.Position = 0; SiteSettings copiedSiteSettings = SerializableSettings.Deserialize(new StreamReader(ms))[0]; CreateEditSite frm = new CreateEditSite(); frm.Text = "Edit " + siteSettings.Name; frm.SiteSettingsBindingSource.DataSource = copiedSiteSettings; if (frm.ShowDialog() == DialogResult.OK) { // make sure the configuration is clean and for the cosen util copiedSiteSettings.AddConfigurationValues(frm.SiteUtil); // replace original settings object with the new one int index = bindingSourceSiteSettings.IndexOf(siteSettings); bindingSourceSiteSettings.RemoveCurrent(); bindingSourceSiteSettings.Insert(index, copiedSiteSettings); bindingSourceSiteSettings.Position = index; } }
void Publish(object sender) { // set current Time to last updated in the xml, so it can be compared later DateTime lastUdpBkp = Site.LastUpdated; Site.LastUpdated = DateTime.Now; SerializableSettings s = new SerializableSettings() { Sites = new BindingList <SiteSettings>() }; s.Sites.Add(Site); var siteDoc = new XmlDocument(); using (var ms = new MemoryStream()) { s.Serialize(ms); ms.Position = 0; siteDoc.Load(ms); } XmlWriterSettings xmlSettings = new XmlWriterSettings { Encoding = Encoding.UTF8, Indent = true, OmitXmlDeclaration = true }; StringBuilder sb = new StringBuilder(); XmlWriter writer = XmlWriter.Create(sb, xmlSettings); siteDoc.SelectSingleNode("//Site").WriteTo(writer); writer.Flush(); string siteXmlString = sb.ToString(); byte[] icon = null; string image = Path.Combine(Path.Combine(OnlineVideoSettings.Instance.ThumbsDir, "Icons"), Site.Name + ".png"); if (File.Exists(image)) { icon = File.ReadAllBytes(image); } byte[] banner = null; image = Path.Combine(Path.Combine(OnlineVideoSettings.Instance.ThumbsDir, "Banners"), Site.Name + ".png"); if (File.Exists(image)) { banner = File.ReadAllBytes(image); } bool success = false; try { string dll = OnlineVideos.Sites.SiteUtilFactory.RequiredDll(Site.UtilName); var ws = new OnlineVideos.OnlineVideosWebservice.OnlineVideosService(); string msg = ""; if (!string.IsNullOrEmpty(dll)) { string location = Path.Combine(OnlineVideoSettings.Instance.DllsDir, dll + ".dll"); if (File.Exists(location)) { byte[] data = File.ReadAllBytes(location); System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider(); string md5LocalDll = BitConverter.ToString(md5.ComputeHash(data)).Replace("-", "").ToLower(); // check webservice if we need to submit the dll string md5RemoteDll = null; string owner = ws.GetDllOwner(dll, out md5RemoteDll); bool dllFound = md5RemoteDll != null; bool dllsAreEqual = dllFound ? md5RemoteDll == md5LocalDll : false; bool userIsOwner = dllFound ? owner == Email : true; if (!dllsAreEqual) { bool isAdmin = false; if (!userIsOwner) { if (MessageBox.Show("Only administrators can overwrite a DLL they don't own. I am an Admin. Proceed?", "New DLL - Admin required", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes) { return; } } if (userIsOwner || isAdmin) { string info = dllFound ? "DLL found on server differs from your local file, do you want to update the existing one?" : "Do you want to upload the required dll?"; if (MessageBox.Show(info, "DLL required", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { if (data == null) { data = File.ReadAllBytes(location); } success = ws.SubmitDll(Email, Password, dll, data, out msg); MessageBox.Show(msg, success ? Translation.Instance.Success : Translation.Instance.Error, MessageBoxButton.OK, success ? MessageBoxImage.Information : MessageBoxImage.Error); } } } } } success = ws.SubmitSite(Email, Password, siteXmlString, icon, banner, dll, out msg); MessageBox.Show(msg, success ? Translation.Instance.Success : Translation.Instance.Error, MessageBoxButton.OK, success ? MessageBoxImage.Information : MessageBoxImage.Error); } catch (Exception ex) { MessageBox.Show(ex.Message, Translation.Instance.Error, MessageBoxButton.OK, MessageBoxImage.Error); } // if the site was not submitted, restore old last updated date, so saving won't write the wrong value if (!success) { Site.LastUpdated = lastUdpBkp; } }
public SiteUtilBase CloneFreshSiteFromExisting(SiteUtilBase site) { // create new instance of this site with reset settings SerializableSettings s = new SerializableSettings() { Sites = new BindingList<SiteSettings>() }; s.Sites.Add(site.Settings); System.IO.MemoryStream ms = new System.IO.MemoryStream(); s.Serialize(ms); ms.Position = 0; SiteSettings originalSettings = SerializableSettings.Deserialize(new StreamReader(ms))[0]; return CreateUtilFromShortName(site.Settings.UtilName, originalSettings); }