Beispiel #1
0
        private void _copyTo(List <TValue> items, AbstractDb <TKey> db)
        {
            try {
                if (items == null || items.Count == 0)
                {
                    return;
                }

                if (typeof(string) == typeof(TKey))
                {
                    if ((DbComponent.DbSource & ServerDbs.MobSkillsItems) != 0)
                    {
                        try {
                            db.Table.Commands.Begin();

                            for (int i = 0; i < items.Count; i++)
                            {
                                var    item  = items[i];
                                TKey   old   = item.GetValue <TKey>(Settings.AttributeList.PrimaryAttribute);
                                string newId = (string)(object)old + Methods.RandomString(30);

                                if (i == items.Count - 1)
                                {
                                    db.Table.Commands.CopyTupleTo((Table <TKey, ReadableTuple <TKey> >)(object) Table, old, (TKey)(object)newId, (a, b, c, d, e) => _copyToCallback2(db, c, d, e));
                                }
                                else
                                {
                                    db.Table.Commands.CopyTupleTo((Table <TKey, ReadableTuple <TKey> >)(object) Table, old, (TKey)(object)newId, (a, b, c, d, e) => _copyToCallback3(c, d, e));
                                }
                            }
                        }
                        catch (Exception err) {
                            db.Table.Commands.CancelEdit();
                            ErrorHandler.HandleException(err);
                        }
                        finally {
                            db.Table.Commands.End();
                        }
                        return;
                    }

                    throw new Exception("Operation not supported.");
                }

                if (db.DbSource == Settings.DbData && items.Count == 1)
                {
                    _copyTo(items[0]);
                    return;
                }

                CopyToDialog dialog = new CopyToDialog(this, items.OfType <Database.Tuple>().ToList(), DbComponent, db);
                dialog.ShowDialog();
            }
            catch (KeyInvalidException) {
            }
            catch (Exception err) {
                ErrorHandler.HandleException(err);
            }
        }
Beispiel #2
0
        public override void OnExecute(CommandEventArgs e)
        {
            Uri  target = null;
            Uri  root   = null;
            bool up     = false;

            List <SvnUriTarget> copyFrom = new List <SvnUriTarget>();

            foreach (ISvnRepositoryItem item in e.Selection.GetSelection <ISvnRepositoryItem>())
            {
                SvnUriTarget utt = item.Origin.Target as SvnUriTarget;

                if (utt == null)
                {
                    utt = new SvnUriTarget(item.Origin.Uri, item.Origin.Target.Revision);
                }

                copyFrom.Add(utt);

                if (root == null)
                {
                    root = item.Origin.RepositoryRoot;
                }

                if (target == null)
                {
                    target = item.Origin.Uri;
                }
                else
                {
                    Uri itemUri = SvnTools.GetNormalizedUri(item.Origin.Uri);

                    Uri r = item.Origin.Uri.MakeRelativeUri(target);

                    if (r.IsAbsoluteUri)
                    {
                        target = null;
                        break;
                    }

                    string rs = r.ToString();

                    if (r.ToString().StartsWith("/", StringComparison.Ordinal))
                    {
                        target = new Uri(target, "/");
                        break;
                    }

                    if (!up && r.ToString().StartsWith("../"))
                    {
                        target = new Uri(target, "../");
                        up     = true;
                    }
                }
            }

            bool   isMove = e.Command == AnkhCommand.ReposMoveTo;
            Uri    toUri;
            string logMessage;

            using (CopyToDialog dlg = new CopyToDialog())
            {
                dlg.RootUri     = root;
                dlg.SelectedUri = target;

                dlg.Text = isMove ? "Move to Url" : "Copy to Url";

                if (dlg.ShowDialog(e.Context) != System.Windows.Forms.DialogResult.OK)
                {
                    return;
                }

                toUri      = dlg.SelectedUri;
                logMessage = dlg.LogMessage;
            }

            // TODO: BH: Make sure the 2 attempts actually make sense

            e.GetService <IProgressRunner>().RunModal(isMove ? CommandStrings.Moving : CommandStrings.Copying,
                                                      delegate(object snd, ProgressWorkerArgs a)
            {
                if (isMove)
                {
                    List <Uri> uris = new List <Uri>();
                    foreach (SvnUriTarget ut in copyFrom)
                    {
                        uris.Add(ut.Uri);
                    }

                    SvnMoveArgs ma   = new SvnMoveArgs();
                    ma.LogMessage    = logMessage;
                    ma.CreateParents = true;

                    try
                    {
                        // First try with the full new name
                        a.Client.RemoteMove(uris, toUri, ma);
                    }
                    catch (SvnFileSystemException fs)
                    {
                        if (fs.SvnErrorCode != SvnErrorCode.SVN_ERR_FS_ALREADY_EXISTS)
                        {
                            throw;
                        }

                        // If exists retry below this directory with the existing name
                        ma.AlwaysMoveAsChild = true;
                        a.Client.RemoteMove(uris, toUri, ma);
                    }
                }
                else
                {
                    SvnCopyArgs ca   = new SvnCopyArgs();
                    ca.LogMessage    = logMessage;
                    ca.CreateParents = true;

                    try
                    {
                        // First try with the full new name
                        a.Client.RemoteCopy(copyFrom, toUri, ca);
                    }
                    catch (SvnFileSystemException fs)
                    {
                        if (fs.SvnErrorCode != SvnErrorCode.SVN_ERR_FS_ALREADY_EXISTS)
                        {
                            throw;
                        }

                        // If exists retry below this directory with the existing name
                        ca.AlwaysCopyAsChild = true;
                        a.Client.RemoteCopy(copyFrom, toUri, ca);
                    }
                }
            });

            // TODO: Send some notification to the repository explorer on this change?
        }