示例#1
0
 public static void Invoke(this UserControl c, Action a)
 {
     if (!c.InvokeRequired)
     {
         a();
     }
     else if (!c.IsDisposed && !c.Disposing && c.Created)
     {
         c.BeginInvoke(a);
     }
 }
 static public void OnScope(UserControl control, Action action)
 {
     if (control.InvokeRequired)
     {
         control.EndInvoke(control.BeginInvoke(new MethodInvoker(action)));
     }
     else
     {
         action();
     }
 }
示例#3
0
 public static void SetCtrlValue(UserControl parentCtrl, Control ctrl, string value)
 {
     if (parentCtrl.InvokeRequired)
     {
         SetCtrlValueHandler method = new SetCtrlValueHandler(SetCtrlValueMethod);
         parentCtrl.BeginInvoke(method, new object[] { ctrl, value });
     }
     else
     {
         SetCtrlValueMethod(ctrl, value);
     }
 }
示例#4
0
 private void AddExtraColumnsIfNeeded(DataTable table, AnalogyLogMessage message)
 {
     if (message.AdditionalInformation != null && message.AdditionalInformation.Any() && Settings.CheckAdditionalInformation)
     {
         foreach (KeyValuePair <string, string> info in message.AdditionalInformation)
         {
             if (!currentTable.Columns.Contains(info.Key))
             {
                 if (!owner.InvokeRequired)
                 {
                     try
                     {
                         columnsLockSlim.EnterWriteLock();
                         if (!currentTable.Columns.Contains(info.Key))
                         {
                             table.Columns.Add(info.Key);
                         }
                     }
                     finally
                     {
                         columnsLockSlim.ExitWriteLock();
                     }
                 }
                 else
                 {
                     owner.BeginInvoke(new MethodInvoker(() =>
                     {
                         try
                         {
                             columnsLockSlim.EnterWriteLock();
                             if (!currentTable.Columns.Contains(info.Key))
                             {
                                 columnsLockSlim.EnterWriteLock();
                                 if (!currentTable.Columns.Contains(info.Key))
                                 {
                                     table.Columns.Add(info.Key);
                                     columnAdderSync.Set();
                                 }
                             }
                         }
                         finally
                         {
                             columnsLockSlim.ExitWriteLock();
                         }
                     }));
                     columnAdderSync.WaitOne();
                     columnAdderSync.Reset();
                 }
             }
         }
     }
 }
示例#5
0
 public static void SetEnable(UserControl parentCtrl, Control ctrl, bool value)
 {
     //转到主线程
     if (parentCtrl.InvokeRequired)
     {
         SetEnableHandler handler = new SetEnableHandler(SetEnableMethod);
         parentCtrl.BeginInvoke(handler, ctrl, value);
     }
     else
     {
         SetEnableMethod(ctrl, value);
     }
 }
示例#6
0
 public static void AppendText(UserControl parentCtrl, Control ctrl, String value)
 {
     //转到主线程
     if (parentCtrl.InvokeRequired)
     {
         AppendTextHandler handler = new AppendTextHandler(AppendTextMethod);
         parentCtrl.BeginInvoke(handler, ctrl, value);
     }
     else
     {
         AppendTextMethod(ctrl, value);
     }
 }
    /// <summary>
    /// Handle parent form DragDrop event
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void OnDragDrop(object sender, System.Windows.Forms.DragEventArgs e)
    {
        try
        {
            string[] formats = e.Data.GetFormats(true);
            string[] values  = new string[1];
            string   url     = string.Empty;

            for (int formatIndex = 0; formatIndex < formats.Length; formatIndex++)
            {
                switch (formats[formatIndex])
                {
                case Consts.DragDropFormats.FileDrop:
                    Array itemList = (Array)e.Data.GetData(Consts.DragDropFormats.FileDrop);

                    if (itemList != null)
                    {
                        _parent.BeginInvoke(OnAddFiles, new Object[] { itemList });
                        _parent.Focus();
                    }
                    break;

                case Consts.DragDropFormats.Text:
                case Consts.DragDropFormats.UniformResourceLocator:
                    values[0] = e.Data.GetData(Consts.DragDropFormats.Text).ToString();
                    _parent.BeginInvoke(OnAddFiles, new Object[] { values });
                    _parent.Focus();
                    break;

                default:
                    break;
                }
            }
        }
        catch (Exception ex)
        {
            Trace.WriteLine("Error in DragDropManager.OnDragDrop function: " + ex.Message);
        }
    }
示例#8
0
 /// <summary>非本线程安全访问控件
 /// </summary>
 /// <param name="control">The control.</param>
 /// <param name="handler">The handler.</param>
 /// <param name="async"> </param>
 public static void ThreadSafeInvoke(this UserControl control, InvokeHandler handler, bool async)
 {
     if (control.InvokeRequired)
     {
         if (async)
         {
             control.BeginInvoke(handler);
         }
         else
         {
             control.Invoke(handler);
         }
     }
     else
     {
         handler();
     }
 }
示例#9
0
        /// <summary>
        /// Does the main merge operation for selected items and checks-in every changeset.
        /// </summary>
        /// <param name="mfrm">The UserControl.</param>
        /// <param name="lvcoll">The Collection of ListViewItems.</param>
        /// <param name="trg">The target path.</param>
        static internal void DoMerge(UserControl mfrm, IEnumerable <ListViewItem> lvcoll, string trg)
        {
            Workspace wrkspc = Utilities.vcext.Explorer.Workspace;

            if (!ServerItemExists(trg))
            {
                MessageBox.Show("Target server path is cloacked or doesn't exist.", Utilities.AppTitle);
                return;
            }

            if (AutomaticCheckin && wrkspc.GetPendingChanges().Length > 0)
            {
                MessageBox.Show("Please resolve all pending changes before going on.", Utilities.AppTitle);
                return;
            }

            //object prgmerge = CreateProgressMerge(vcsrv);
            //ShowProgressMerge(prgmerge, mfrm);

            int  idx       = 0;
            bool bcanceled = false;
            int  icanceled;
            var  dlg = Utilities.CreateThreadedWaitDialog("Merging changesets", "Stating changesets merge...", "status", 100);

            ErrorHandler.ThrowOnFailure(dlg.UpdateProgress("Merging changesets", "Stating changesets merge...", "status", idx++, 100, false, out bcanceled));
            if (bcanceled)
            {
                return;
            }

            foreach (var lvItem in lvcoll)
            {
                string MergeTypeText = lvItem.SubItems[MergeTypeIndex].Text;
                if (MergeTypeText == "none")
                {
                    continue;
                }

                Changeset ch = Utilities.vcsrv.GetChangeset((lvItem.Tag as ListViewItemTag).ChangesetID);
                Utilities.OutputCommandString("Preparing for merge changeset: " + ch.ChangesetId);

                if (LinkWorkItems)
                {
                    foreach (var workItm in ch.WorkItems)
                    {
                        Utilities.OutputCommandString("Associated WorkItem: " + workItm.Id);
                    }
                }

                ErrorHandler.ThrowOnFailure(dlg.UpdateProgress("Merging changesets", "Merging changeset: " + ch.ChangesetId, "status", idx++, 100, false, out bcanceled));
                if (bcanceled)
                {
                    return;
                }

                var chverspc = new ChangesetVersionSpec(ch.ChangesetId);
                Utilities.OutputCommandString("Changeset Version: " + chverspc.DisplayString);

                MergeOptionsEx mergeType = (MergeTypeText == "baseless" ? MergeOptionsEx.Baseless : MergeTypeText == "force" ? MergeOptionsEx.ForceMerge : MergeOptionsEx.None);
                mergeType |= mergeOptions;

                GetStatus sts = wrkspc.Merge((lvItem.Tag as ListViewItemTag).sourcePath, trg, chverspc, chverspc, LockLevel.Unchanged, RecursionType.Full, mergeType);
                Utilities.OutputCommandString("Merge summary: MergeOptionsEx=" + mergeType + ", NoActionNeeded=" + sts.NoActionNeeded + ", NumFailures=" + sts.NumFailures + ", NumOperations=" + sts.NumOperations + ", NumUpdated=" + sts.NumUpdated + ", NumWarnings=" + sts.NumWarnings);

                if (AutomaticCheckin)
                {
                    while (wrkspc.QueryConflicts(ch.Changes.Select(x => x.Item.ServerItem).ToArray(), true).Length > 0)
                    {
                        //foreach (var conflict in conflicts) wrkspc.ResolveConflict(conflict);
                        DialogResult res = MessageBox.Show("Merge conflicts where found. Resolve them or click Cancel to break merge operaton.", "Merge conflicts", MessageBoxButtons.OKCancel);
                        if (res == DialogResult.Cancel)
                        {
                            ErrorHandler.ThrowOnFailure(dlg.EndWaitDialog(out icanceled));
                            return;
                        }

                        if (mfrm.InvokeRequired)
                        {
                            var asynchres = mfrm.BeginInvoke(new MethodInvoker(Utilities.ShowResolveConflictsDlg));
                            mfrm.EndInvoke(asynchres);
                        }
                        else
                        {
                            Utilities.ShowResolveConflictsDlg();
                        }
                    }

                    var pendingCh = wrkspc.GetPendingChanges();//ch.Changes.Select(x => new ItemSpec(x.Item.ServerItem, RecursionType.Full, x.Item.DeletionId)).ToArray(), true).ToArray();
                    if (pendingCh.Length == 0)
                    {
                        Utilities.OutputCommandString("No pending changes found.");
                        continue;
                    }

                    var wrkitmch = (LinkWorkItems ? ch.WorkItems.Select(x => new WorkItemCheckinInfo(x, WorkItemCheckinAction.Associate)).ToArray() : null);

                    foreach (var pendChItem in pendingCh)
                    {
                        Utilities.OutputCommandString("Found pending change " + pendChItem.ChangeTypeName + ": " + pendChItem.SourceServerItem);
                    }

                    int newchid = wrkspc.CheckIn(pendingCh, ch.Committer, ch.Comment, ch.CheckinNote, wrkitmch, null, CheckinOptions.SuppressEvent);
                    Utilities.OutputCommandString("Created new changeset: " + newchid);
                }
                if (idx == 100)
                {
                    idx = 0;
                }
            }

            ErrorHandler.ThrowOnFailure(dlg.EndWaitDialog(out icanceled));
            //CloseProgressMerge(prgmerge);
        }