コード例 #1
0
        protected override bool RunInternal(object options)
        {
            SetAnnotationVerbOptions localOptions = options as SetAnnotationVerbOptions;

            Objects.Version ver = Workspace.GetPartialVersion(localOptions.Version);
            if (ver == null)
            {
                Printer.PrintMessage("#e#Error:## can't find version #b#\"{0}\"## to assign annotation to.", localOptions.Version);
                return(false);
            }

            Objects.Annotation annotation = Workspace.GetAnnotation(ver.ID, localOptions.Key, false);
            if (annotation != null && localOptions.NoOverwrite)
            {
                Printer.PrintMessage("Annotation already exists. Overwriting is currently disabled.");
                return(false);
            }
            if (!localOptions.Precise)
            {
                annotation = Workspace.GetSimilarAnnotation(ver.ID, localOptions.Key);
                if (annotation != null)
                {
                    Printer.PrintMessage("A similar annotation (with key #b#\"{0}\"##) exists. Delete this annotation or enable #b#--precise## mode to continue.", annotation.Key);
                    return(false);
                }
            }

            if (string.IsNullOrEmpty(localOptions.Filename))
            {
                if (localOptions.StringData == null || localOptions.StringData.Count == 0)
                {
                    Printer.PrintMessage("#e#Error:## Data for annotation is empty.");
                    return(false);
                }
                return(Workspace.SetAnnotation(ver.ID, localOptions.Key, string.Join(" ", localOptions.StringData.ToArray())));
            }
            else
            {
                System.IO.FileInfo info = new System.IO.FileInfo(localOptions.Filename);
                if (!info.Exists)
                {
                    Printer.PrintMessage("#e#Error:## Payload file #b#\"{0}\"## does not exist.", info.FullName);
                    return(false);
                }
                using (var s = info.OpenRead())
                    return(Workspace.SetAnnotation(ver.ID, localOptions.Key, Utilities.FileClassifier.Classify(info) == Utilities.FileEncoding.Binary, s));
            }
        }
コード例 #2
0
        protected override bool RunInternal(object options)
        {
            DeleteAnnotationVerbOptions localOptions = options as DeleteAnnotationVerbOptions;

            Objects.Annotation annotation = null;
            if (string.IsNullOrEmpty(localOptions.Key))
            {
                if (!localOptions.Plain)
                {
                    Printer.PrintMessage("#e#Error:## an annotation key must be specified.");
                }
                return(false);
            }
            if (!string.IsNullOrEmpty(localOptions.Version))
            {
                Objects.Version ver = Workspace.GetPartialVersion(localOptions.Version);
                if (ver == null)
                {
                    if (!localOptions.Plain)
                    {
                        Printer.PrintMessage("#e#Error:## can't find version #b#\"{0}\"## to remove annotation.", localOptions.Version);
                    }
                    return(false);
                }
                annotation = Workspace.GetAnnotation(ver.ID, localOptions.Key, localOptions.IgnoreCase);
                if (annotation == null)
                {
                    if (!localOptions.Plain)
                    {
                        Printer.PrintMessage("#e#Error:## no annotation matching that key for the specified version.");
                    }
                    return(false);
                }
            }
            else
            {
                var annotations = Workspace.GetPartialAnnotation(localOptions.Key);
                if (annotations.Count == 0)
                {
                    if (!localOptions.Plain)
                    {
                        Printer.PrintMessage("#e#Error:## no annotation matching that ID.");
                    }
                    return(false);
                }
                else if (annotations.Count > 1)
                {
                    if (!localOptions.Plain)
                    {
                        Printer.PrintMessage("#e#Error:## found #b#{0}## multiple matching annotations:", annotations.Count);
                        for (int i = 0; i < annotations.Count; i++)
                        {
                            var    x      = annotations[i];
                            string suffix = "";
                            if (x.Active == false)
                            {
                                suffix = "#e#(deleted)##";
                            }
                            else
                            {
                                if (Workspace.GetAnnotation(x.Version, x.Key, false).ID == x.ID)
                                {
                                    suffix = "#s#(tip)##";
                                }
                            }
                            suffix += string.Format(" #q#{0}##", Workspace.GetAnnotationPayloadSize(x));
                            Printer.PrintMessage(" [{0}]: #b#{1}## on version #b#{2}## {5}\n   by #b#{3}## on {4} #q#(ID: {6})##", i, x.Key, x.Version, x.Author, x.Timestamp.ToLocalTime(), suffix, x.ID);
                        }
                    }
                    return(false);
                }
                else
                {
                    annotation = annotations[0];
                }
            }
            if (annotation.Active != false)
            {
                Workspace.DeleteAnnotation(annotation);
                Printer.PrintMessage("Deleted.");
                return(true);
            }
            return(false);
        }
コード例 #3
0
        protected override bool RunInternal(object options)
        {
            GetAnnotationVerbOptions localOptions = options as GetAnnotationVerbOptions;

            Objects.Annotation annotation = null;
            if (string.IsNullOrEmpty(localOptions.Key))
            {
                if (!localOptions.Plain)
                {
                    Printer.PrintMessage("#e#Error:## an annotation key must be specified.");
                }
                return(false);
            }
            if (!string.IsNullOrEmpty(localOptions.Version))
            {
                Objects.Version ver = Workspace.GetPartialVersion(localOptions.Version);
                if (ver == null)
                {
                    if (!localOptions.Plain)
                    {
                        Printer.PrintMessage("#e#Error:## can't find version #b#\"{0}\"## to retrieve annotation.", localOptions.Version);
                    }
                    return(false);
                }
                annotation = Workspace.GetAnnotation(ver.ID, localOptions.Key, localOptions.IgnoreCase);
                if (annotation == null)
                {
                    if (localOptions.Recursive)
                    {
                        if (!localOptions.Plain)
                        {
                            Printer.PrintMessage("#w#Warning:## no annotation matching that key for the current version, searching history.");
                        }
                        var history = Workspace.GetLogicalHistory(ver, false, true, true);
                        foreach (var v in history)
                        {
                            if (!localOptions.Plain)
                            {
                                Printer.PrintMessage("Checking version #b#{0}##.", v.ID);
                            }
                            annotation = Workspace.GetAnnotation(ver.ID, localOptions.Key, localOptions.IgnoreCase);
                            if (annotation != null)
                            {
                                break;
                            }
                        }
                        if (annotation == null)
                        {
                            if (!localOptions.Plain)
                            {
                                Printer.PrintMessage("#e#Error:## no annotation matching that key.");
                            }
                            return(false);
                        }
                    }
                    else
                    {
                        if (!localOptions.Plain)
                        {
                            Printer.PrintMessage("#e#Error:## no annotation matching that key for the specified version.");
                        }
                        return(false);
                    }
                }
            }
            else
            {
                var annotations = Workspace.GetPartialAnnotation(localOptions.Key);
                if (annotations.Count == 0)
                {
                    if (!localOptions.Plain)
                    {
                        Printer.PrintMessage("#e#Error:## no annotation matching that ID.");
                    }
                    return(false);
                }
                else if (annotations.Count > 1)
                {
                    if (!localOptions.Plain)
                    {
                        Printer.PrintMessage("#e#Error:## found #b#{0}## multiple matching annotations:", annotations.Count);
                        for (int i = 0; i < annotations.Count; i++)
                        {
                            var    x      = annotations[i];
                            string suffix = "";
                            if (x.Active == false)
                            {
                                suffix = "#e#(deleted)##";
                            }
                            else
                            {
                                if (Workspace.GetAnnotation(x.Version, x.Key, false).ID == x.ID)
                                {
                                    suffix = "#s#(tip)##";
                                }
                            }
                            suffix += string.Format(" #q#{0}##", Workspace.GetAnnotationPayloadSize(x));
                            Printer.PrintMessage(" [{0}]: #b#{1}## on version #b#{2}## {5}\n   by #b#{3}## on {4} #q#(ID: {6})##", i, x.Key, x.Version, x.Author, x.Timestamp.ToLocalTime(), suffix, x.ID);
                        }
                    }
                    return(false);
                }
                else
                {
                    annotation = annotations[0];
                }
            }
            if (!localOptions.Plain)
            {
                Printer.PrintMessage("Version #b#{0}## - annotation #b#{1}## #q#({2})##", annotation.Version, annotation.Key, annotation.ID);
                Printer.PrintMessage("Added by #b#{0}## on {1}", annotation.Author, annotation.Timestamp.ToLocalTime());
                Printer.PrintMessage("");
            }
            if (annotation.Active == false)
            {
                if (!localOptions.Plain)
                {
                    Printer.PrintMessage("#e#Annotation has been deleted.##");
                }
                return(false);
            }
            if (!localOptions.Plain && annotation.Flags.HasFlag(Objects.AnnotationFlags.Binary) && string.IsNullOrEmpty(localOptions.Filename))
            {
                Printer.PrintMessage("#q#[Annotation contents is a binary blob.]##");
            }
            else
            {
                if (string.IsNullOrEmpty(localOptions.Filename))
                {
                    Printer.PrintMessage(Printer.Escape(Workspace.GetAnnotationAsString(annotation)));
                }
                else
                {
                    using (System.IO.Stream s = Workspace.GetAnnotationStream(annotation))
                        using (System.IO.FileStream fs = System.IO.File.Open(localOptions.Filename, System.IO.FileMode.Create))
                            s.CopyTo(fs);
                    if (!localOptions.Plain)
                    {
                        Printer.PrintMessage("Wrote annotation contents to file #b#{0}##.", localOptions.Filename);
                    }
                }
            }
            return(true);
        }