private void tvNav_AfterSelect(object sender, TreeViewEventArgs e) { try { //--This is for "container" nodes so that when user pressess up arrow, the container node is skipped. if (e.Node.Tag == null && e.Node.Nodes.Count > 0) { if (!_lastKeywasUpArrow || e.Node.PrevNode == null) { tvNav.SelectedNode = e.Node.Nodes[0]; } else { tvNav.SelectedNode = e.Node.PrevNode.LastNode; } return; } //--using reflection here for performance reasons, this allows the application to delay-load the Action user control. if (e.Node.Tag.GetType().FullName == "System.RuntimeType") { SetTreeNodeTagToActionParentInstance(e.Node); } ActionParent ucp = (ActionParent)e.Node.Tag; splitContainer1.Panel2.Controls.Clear(); ucp.Dock = DockStyle.Fill; splitContainer1.Panel2.Controls.Add(ucp); ucp.ActionFormActivate(); if (ucp.PictureboxImage != null) { this.pictureBoxTop.Image = ucp.PictureboxImage; } rtbTitle.Text = " " + e.Node.Text; } catch (Exception ex) { Eh.GlobalErrorHandler(ex); } }
public static object DeepCopy(object obj) { try { MemoryStream ms = new MemoryStream(); System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); bf.Serialize(ms, obj); object retval; ms.Seek(0, SeekOrigin.Begin); retval = bf.Deserialize(ms); ms.Close(); return(retval); } catch (Exception ex) { Eh.GlobalErrorHandler(ex); return(null); } }
private void StartBackup2(bool onlyValidate) { try { if (!System.IO.Directory.Exists(txtBackupPath.Text)) { SmartStepUtil.AddToRTB(rtbDisplay, "Backup folder '" + txtBackupPath.Text + "' does not exist.", Color.Red, 10, false); return; } if (onlyValidate) { SmartStepUtil.AddToRTB(rtbDisplay, "validating only\r\n\r\n", Color.SeaGreen, 11, true); } int urlCount = 0; foreach (string item in lstSiteURLs.Items) { urlCount++; StartBackup3(onlyValidate, item, urlCount); } //-- if (!onlyValidate) { SmartStepUtil.AddToRTB(rtbDisplay, "backup complete\r\n\r\n", Color.SeaGreen, 11, true); } } catch (Eh.CancelException) { SmartStepUtil.AddToRTB(rtbDisplay, "Backup Cancelled by user\r\n", Color.Red, 12, true); } catch (Exception ex) { Eh.GlobalErrorHandler(ex); } finally { toggleCancel(false, false, true); } }
/// <summary> /// Generate a LinkLabel to the right of a control which will open the corresponding Wiki help page for that control. /// </summary> public static void createHelpLinkLabel(Control control, string helpKey) { try { LinkLabel lnk = new LinkLabel(); lnk.Text = "?"; lnk.Location = new System.Drawing.Point(control.Left + control.Width + 1, control.Top); lnk.Tag = helpKey; lnk.Width = 16; lnk.Height = 16; lnk.Font = new System.Drawing.Font("Courier New", 10); control.Parent.Controls.Add(lnk); lnk.BringToFront(); lnk.LinkClicked += new LinkLabelLinkClickedEventHandler(lnk_LinkClicked); } catch (Exception ex) { Eh.GlobalErrorHandler(ex); } }
private void createSchedule(bool validateOnly) { try { rtbDisplay.Clear(); string sc = optWeekly.Checked ? "WEEKLY" : "DAILY"; string taskToRun = Environment.CurrentDirectory + "\\" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + ".exe -autostart:" + this._autostartType.ToString(); string systemName = @"\\" + Environment.MachineName; string taskName = this._autostartType.ToString().Replace("_", " "); string args = "SCHTASKS /create /sc " + sc + " /mo 1 /tn \"" + taskName + "\" /tr \"" + taskToRun + "\" /s " + systemName; args += " /st " + dtpTimeofDay.Value.ToString("HH:mm") + " /F"; args += " /u " + Environment.UserDomainName + "\\" + Environment.UserName; if (!validateOnly) { string batFilename = System.IO.Path.GetTempPath() + "\\SUSHI_schedule_backup_tempfile.bat"; using (StreamWriter sw = new StreamWriter(batFilename)) { sw.WriteLine(@"CD \"); sw.WriteLine(args); sw.WriteLine("PAUSE"); } ProcessStartInfo si = new ProcessStartInfo(batFilename); Process ret = Process.Start(si); SmartStepUtil.AddToRTB(rtbDisplay, "scheduled:\r\n", Color.Blue, 10, true); SmartStepUtil.AddToRTB(rtbDisplay, args); } else { SmartStepUtil.AddToRTB(rtbDisplay, "to be scheduled:\r\n", Color.Blue, 10, true); SmartStepUtil.AddToRTB(rtbDisplay, args); } } catch (Exception ex) { Eh.GlobalErrorHandler(ex); } }
private void btnPopulateDocLibs_Click(object sender, EventArgs e) { try { MainForm.DefInstance.Cursor = Cursors.WaitCursor; SPWeb web = Util.RetrieveWeb(txtTargetSite.Text, rtbValidateMessage); if (web == null) { return; } txtTargetSite.Text = web.Url; Util.PopulateComboboWithSharePointLists(web, cboDocLibs, true, false); } catch (Exception ex) { Eh.GlobalErrorHandler(ex); } finally { MainForm.DefInstance.Cursor = Cursors.Default; } }
static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e) { Eh.GlobalErrorHandler(e.Exception, "Exception"); }
private void updateSingleColumn(bool onlyValidate) { int counterUpdated = 0; int counterTotalItemsInList = 0; try { FrmCancelRunning.ToggleEnabled(true);//toggleEnabled(true); SmartStepUtil.ClearRtbSafely(rtbDisplay); //--validate if (cboCurrentValue.SelectedItem == null) { AddToRtbLocal("Please select a Current Value", StyleType.bodyBlack); return; } if (cboColumnNames.SelectedItem == null) { AddToRtbLocal("Please select a Column", StyleType.bodyBlack); return; } FieldAndContentType fnwc = (FieldAndContentType)cboColumnNames.SelectedItem; //--messagebox to validate if the user really wants to update value to blank. (prevent accident). if (txtNewValue.Text.Trim() == "" && !onlyValidate) { if (MessageBox.Show(this, "You have selected to update to a blank, Are you sure?", "SUSHI", MessageBoxButtons.YesNo) == DialogResult.No) { return; } } //-- string s = onlyValidate ? "Displaying" : "Updating"; SmartStepUtil.AddToRTB(rtbDisplay, s + " values for column ", Color.Green, 14, true); SmartStepUtil.AddToRTB(rtbDisplay, fnwc.Field.Title, Color.Chocolate, 14, true); SmartStepUtil.AddToRTB(rtbDisplay, " where value = ", Color.Green, 14, true); SmartStepUtil.AddToRTB(rtbDisplay, "\"" + cboCurrentValue.Text + "\"\r\n", Color.Chocolate, 14, true); SPList list = (SPList)cboDocLibs.SelectedItem; counterTotalItemsInList = list.Items.Count; foreach (SPListItem listitem in (list.Items)) { if (GlobalVars.CancelRunning) { throw new Eh.CancelException(); } SmartStepUtil.ScrollToBottom(rtbDisplay); Application.DoEvents(); if (Util.ToStr(listitem[fnwc.Field.Id]) == cboCurrentValue.Text) { //object o = listitem[fnwc.Field.Id]; // SmartStepUtil.AddToRTB(rtbDisplay, listitem.File.Name, Color.Blue, 8, false); AddToRtbLocal(" column ", StyleType.bodyBlack); SmartStepUtil.AddToRTB(rtbDisplay, fnwc.Field.Title, Color.DarkCyan, 8, false); if (onlyValidate) { AddToRtbLocal(" = ", StyleType.bodyBlack); SmartStepUtil.AddToRTB(rtbDisplay, "\"" + cboCurrentValue.Text + "\"\r\n", Color.DarkGreen, 8, false); } else { listitem[fnwc.Field.Id] = txtNewValue.Text; listitem.Update(); //idea: ability to replace part of a field, rather than the whole thing. //mySPLI[mySPField.Title]=mySPLI[mySPField.Title].ToString().Replace(oldValue.Text,newValue.Text);mySPLI.Update(); if (listitem[fnwc.Field.Id].ToString() == txtNewValue.Text) { AddToRtbLocal(" updated to ", StyleType.bodyBlack); SmartStepUtil.AddToRTB(rtbDisplay, "\"" + txtNewValue.Text + "\"\r\n", Color.DarkBlue, 8, false); counterUpdated++; } else { SmartStepUtil.AddToRTB(rtbDisplay, " NOT successfully updated\r\n", Color.Red, 8, false); } } } } //-- if (!onlyValidate) { cboColumnNames_SelectedIndexChanged(null, null); SmartStepUtil.AddToRTB(rtbDisplay, "update completed successfully\r\n", Color.Black, 8, true); } } catch (Eh.CancelException) { SmartStepUtil.AddToRTB(rtbDisplay, "Canceled by user\r\n", Color.Black, 10, true); } catch (Exception ex) { Eh.GlobalErrorHandler(ex); } finally { FrmCancelRunning.ToggleEnabled(false); //toggleEnabled(false); } SmartStepUtil.AddToRTB(rtbDisplay, "STATS: total items in list:" + counterTotalItemsInList + ", items updated:" + counterUpdated + "\r\n", Color.DarkGray, 8, false); SmartStepUtil.ScrollToBottom(rtbDisplay); }
private void btnAddCt_Click(object sender, EventArgs e) { try { //TODO: add validate button SPContentType newCT = ((ContentTypeHolder)cboRootContentTypes.SelectedItem).CT; RichTextBox rtb = ActionMetadata.DefInstance.rtbDisplay; rtb.Clear(); AddToRtbLocal("Adding Content Type to Document Library " + m_docLib.Title + "...\r\n", StyleType.titleSeagreen); //-- if (!m_docLib.ContentTypesEnabled) { m_docLib.ContentTypesEnabled = true; m_docLib.Update(); AddToRtbLocal("Content Type management enabled for " + m_docLib.Title + "\r\n", StyleType.bodySeaGreen); } //-- bool found = false; foreach (SPContentType ct in m_docLib.ContentTypes) { if (ct.Name == newCT.Name) { found = true; } } if (!found) { m_docLib.ContentTypes.Add(newCT); AddToRtbLocal("Content Type " + newCT.Name + " added to " + m_docLib.Title + "\r\n", StyleType.bodySeaGreen); } else { AddToRtbLocal("Content Type " + newCT.Name + " was already previously added to " + m_docLib.Title + "\r\n", StyleType.bodyChocolate); } GlobalVars.SETTINGS.metadata_defaultContentTypeForApplyCT = newCT.Group + " - " + newCT.Name; //-- if (chkChangeAllDocumentsToContentType.Checked) { int counter = 0; AddToRtbLocal("Changing all documents in library to new ContentType\r\n", StyleType.bodyBlack); FrmCancelRunning.ToggleEnabled(true); //ActionMetadata.DefInstance.toggleEnabled(true); for (int i = 0; i <= m_docLib.Items.Count - 1; i++) { if (GlobalVars.CancelRunning) { throw new Eh.CancelException(); } SPListItem listitem = m_docLib.Items[i]; SPContentTypeId currentContentTypeId = (SPContentTypeId)listitem["ContentTypeId"]; if (!currentContentTypeId.IsChildOf(newCT.Id)) { listitem["ContentTypeId"] = newCT.Id; listitem.Update(); counter++; AddToRtbLocal(listitem.File.Name, StyleType.bodySeaGreen); AddToRtbLocal(" ContentType-> " + newCT.Name + "\r\n", StyleType.bodyBlack); SmartStepUtil.ScrollToBottom(rtb); Application.DoEvents(); } } AddToRtbLocal("STATS: changed ContentType for " + counter + " documents, " + " total items in library: " + m_docLib.Items.Count + "\r\n", StyleType.bodyDarkGray); } SmartStepUtil.AddToRTB(rtb, "Done\r\n", Color.Black, 10, true); //-- this.Close(); } catch (Eh.CancelException) { AddToRtbLocal("canceled by user\r\n", StyleType.bodyBlackBold); } catch (Exception ex) { Eh.GlobalErrorHandler(ex); } finally { //ActionMetadata.DefInstance.toggleEnabled(false); FrmCancelRunning.ToggleEnabled(false); } }