void Register(object sender) { var ws = new OnlineVideos.OnlineVideosWebservice.OnlineVideosService(); string msg = null; var success = ws.RegisterEmail(Email, out msg); MessageBox.Show(msg, success ? Translation.Instance.Success : Translation.Instance.Error, MessageBoxButton.OK, success ? MessageBoxImage.Information : MessageBoxImage.Error); }
private void btnSubmit_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(tbxEmail.Text) || !emailRegex.IsMatch(tbxEmail.Text)) { MessageBox.Show("Please enter a valid Email!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { OnlineVideosWebservice.OnlineVideosService ws = new OnlineVideos.OnlineVideosWebservice.OnlineVideosService(); string msg = ""; bool success = ws.RegisterEmail(tbxEmail.Text, out msg); MessageBox.Show(msg, success ? "Success" : "Error", MessageBoxButtons.OK, success ? MessageBoxIcon.Information : MessageBoxIcon.Error); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnOK_Click(object sender, EventArgs e) { if (tbxMessage.Text.Trim().Length < 10) { MessageBox.Show("You must enter a short text! No Report submitted.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { OnlineVideosWebservice.ReportType type = (OnlineVideosWebservice.ReportType)Enum.Parse(typeof(OnlineVideosWebservice.ReportType), cbType.SelectedItem.ToString()); OnlineVideosWebservice.OnlineVideosService ws = new OnlineVideos.OnlineVideosWebservice.OnlineVideosService(); string msg = ""; bool success = ws.SubmitReport(SiteName, tbxMessage.Text, type, out msg); MessageBox.Show(msg, success ? "Success" : "Error", MessageBoxButtons.OK, success ? MessageBoxIcon.Information : MessageBoxIcon.Error); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
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 btnImportGlobal_Click(object sender, EventArgs e) { if (onlineSites == null) { OnlineVideosWebservice.OnlineVideosService ws = new OnlineVideos.OnlineVideosWebservice.OnlineVideosService(); onlineSites = ws.GetSitesOverview(); } Dictionary<string, SiteSettings> hashedLocalSites = new Dictionary<string, SiteSettings>(); foreach (SiteSettings ss in OnlineVideoSettings.Instance.SiteSettingsList) if (!hashedLocalSites.ContainsKey(ss.Name)) hashedLocalSites.Add(ss.Name, ss); List<OnlineVideosWebservice.Site> onlyOnlineSites = new List<OnlineVideos.OnlineVideosWebservice.Site>(); int i = 0; while (i < onlineSites.Length) { if (!hashedLocalSites.ContainsKey(onlineSites[i].Name)) { int indexOfAt = onlineSites[i].Owner_FK.IndexOf('@'); if (indexOfAt > 0) onlineSites[i].Owner_FK = onlineSites[i].Owner_FK.Substring(0, onlineSites[i].Owner_FK.IndexOf('@')); onlyOnlineSites.Add(onlineSites[i]); } i++; } ImportGlobalSite frm = new ImportGlobalSite(); frm.dgvSites.DataSource = onlyOnlineSites; if (frm.ShowDialog() == DialogResult.OK) { List<SiteSettings> importedSites = new List<SiteSettings>(); Cursor oldCursor = Cursor; try { Cursor = Cursors.WaitCursor; OnlineVideosWebservice.OnlineVideosService ws = new OnlineVideos.OnlineVideosWebservice.OnlineVideosService(); foreach (DataGridViewRow dgvr in frm.dgvSites.SelectedRows) { OnlineVideosWebservice.Site onlineSite = (OnlineVideosWebservice.Site)dgvr.DataBoundItem; string siteXml = ws.GetSiteXml(onlineSite.Name); IList<SiteSettings> sitesFromServer = SerializableSettings.Deserialize(siteXml); if (sitesFromServer != null) { foreach (SiteSettings site in sitesFromServer) { OnlineVideoSettings.Instance.SiteSettingsList.Add(site); importedSites.Add(site); } } byte[] icon = ws.GetSiteIcon(onlineSite.Name); if (icon != null && icon.Length > 0) { File.WriteAllBytes(Path.Combine(Path.Combine(OnlineVideoSettings.Instance.ThumbsDir, "Icons"), onlineSite.Name + ".png"), icon); if (!imageListSiteIcons.Images.ContainsKey(onlineSite.Name)) imageListSiteIcons.Images.Add(onlineSite.Name, Image.FromStream(new MemoryStream(icon))); } icon = ws.GetSiteBanner(onlineSite.Name); if (icon != null && icon.Length > 0) { File.WriteAllBytes(Path.Combine(Path.Combine(OnlineVideoSettings.Instance.ThumbsDir, "Banners"), onlineSite.Name + ".png"), icon); } } } catch (Exception ex) { MessageBox.Show(ex.Message, Translation.Instance.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { Cursor = oldCursor; } if (importedSites.Count > 0) { siteList.SelectedObjects = importedSites; siteList.EnsureModelVisible(importedSites[0]); siteList.Focus(); } } }
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; } }
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; } }