public batchForm() { batchItems = new List <ContentMeta>(); InitializeComponent(); if (!toolbar.Contains(skipBox)) { Win32.SuspendDrawing(this); toolbar.Items.Insert(3, new ToolStripControlHost(skipBox)); Win32.ResumeDrawing(this); } Shown += (s, e) => { LoadKeys(); }; FormClosing += (s, e) => { if (!Equals(null, batchItems) && batchItems.Count > 0) { foreach (ContentMeta contentMeta in batchItems) { contentMeta.Dispose(); } batchItems.Clear(); } }; keysButton.Click += (s, e) => { keys = new keyForm().ShowDialog(this, keys); LoadKeys(); }; clearButton.Click += (s, e) => { if (Equals(null, batchItems)) { return; } foreach (ContentMeta contentMeta in batchItems) { contentMeta.Dispose(); } batchItems.Clear(); LoadItems(); }; addButton.Click += (s, e) => { string path; using (FolderBrowserDialog folder = new FolderBrowserDialog()) { folder.Description = "Select folder containing ContentMeta.xbx files"; if (folder.ShowDialog() != DialogResult.OK) { return; } path = folder.SelectedPath; } IEnumerable <string> files = Directory.EnumerateFiles(path, "*.xbx", SearchOption.AllDirectories); if (Equals(null, files) || files.Count() == 0) { MessageBox.Show("No .xbx files found"); return; } List <ContentMeta> items = new List <ContentMeta>(); ContentMeta item; bool success; foreach (string file in files) { item = new ContentMeta(file, out success); foreach (ContentMeta contentMeta in batchItems) { if (contentMeta.FilePath == file) { success = false; break; } } if (success) { items.Add(item); } } if (items.Count == 0) { MessageBox.Show("No valid .xbx files found"); return; } batchItems.AddRange(items); LoadItems(); }; signButton.Click += (s, e) => { if (Equals(null, batchItems) || batchItems.Count == 0) { return; } if (keys.Count == 0) { MessageBox.Show("You must add a key to sign content with"); return; } string alias = (string)keyBox.SelectedItem; if (string.IsNullOrEmpty(alias)) { MessageBox.Show("Invalid key selected"); return; } bool exists; byte[] key = keys.GetKey(alias, out exists); if (!exists) { MessageBox.Show("Selected key does not exist"); return; } bool skipContentHashing = skipBox.Checked; string result; new Thread(delegate() { Invoke((Action) delegate { signButton.Enabled = false; addButton.Enabled = false; clearButton.Enabled = false; keysButton.Enabled = false; foreach (ListViewItem item in fileList.Items) { item.SubItems[1].Text = null; } fileList.RedrawItems(0, (fileList.Items.Count - 1), false); }); int i = 0; foreach (ContentMeta contentMeta in batchItems) { result = Sign(contentMeta, key, skipContentHashing); Invoke((Action) delegate { fileList.Items[i].SubItems[1].Text = result; fileList.RedrawItems(i, i, false); }); i++; } Invoke((Action) delegate { signButton.Enabled = true; addButton.Enabled = true; clearButton.Enabled = true; keysButton.Enabled = true; }); Thread.CurrentThread.Abort(); }).Start(); }; }
void grdContentMeta_RowUpdating(object sender, GridViewUpdateEventArgs e) { if (productGuid == Guid.Empty) { return; } if (store == null) { return; } Product product = new Product(productGuid); if (product.StoreGuid != store.Guid) { return; } GridView grid = (GridView)sender; Guid guid = new Guid(grid.DataKeys[e.RowIndex].Value.ToString()); TextBox txtName = (TextBox)grid.Rows[e.RowIndex].Cells[1].FindControl("txtName"); TextBox txtScheme = (TextBox)grid.Rows[e.RowIndex].Cells[1].FindControl("txtScheme"); TextBox txtLangCode = (TextBox)grid.Rows[e.RowIndex].Cells[1].FindControl("txtLangCode"); DropDownList ddDirection = (DropDownList)grid.Rows[e.RowIndex].Cells[1].FindControl("ddDirection"); TextBox txtMetaContent = (TextBox)grid.Rows[e.RowIndex].Cells[1].FindControl("txtMetaContent"); ContentMeta meta = null; if (guid != Guid.Empty) { meta = metaRepository.Fetch(guid); } else { meta = new ContentMeta(); if (siteUser != null) { meta.CreatedBy = siteUser.UserGuid; } meta.SortRank = metaRepository.GetNextSortRank(product.Guid); meta.ModuleGuid = store.ModuleGuid; } if (meta != null) { meta.SiteGuid = siteSettings.SiteGuid; meta.ContentGuid = product.Guid; meta.Dir = ddDirection.SelectedValue; meta.LangCode = txtLangCode.Text; meta.MetaContent = txtMetaContent.Text; meta.Name = txtName.Text; meta.Scheme = txtScheme.Text; if (siteUser != null) { meta.LastModBy = siteUser.UserGuid; } metaRepository.Save(meta); product.CompiledMeta = metaRepository.GetMetaString(product.Guid); product.Save(); } grid.EditIndex = -1; grdContentMeta.Columns[2].Visible = true; BindMeta(); upMeta.Update(); }