Exemplo n.º 1
0
        private string RemoveBackupSets(BackendWrapper backend, List<ManifestEntry> entries)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(backend.FinishDeleteTransaction(false));

            if (entries.Count > 0)
            {
                System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
                System.Xml.XmlNode root = doc.AppendChild(doc.CreateElement("files"));
                root.Attributes.Append(doc.CreateAttribute("version")).Value = "1";

                foreach (ManifestEntry me in entries)
                {
                    if (me.Alternate != null)
                        root.AppendChild(doc.CreateElement("file")).InnerText = me.Alternate.Filename;
                    root.AppendChild(doc.CreateElement("file")).InnerText = me.Filename;

                    if (me.Verification != null)
                        root.AppendChild(doc.CreateElement("file")).InnerText = me.Verification.Filename;

                    foreach (KeyValuePair<SignatureEntry, ContentEntry> kx in me.Volumes)
                    {
                        root.AppendChild(doc.CreateElement("file")).InnerText = kx.Key.Filename;
                        root.AppendChild(doc.CreateElement("file")).InnerText = kx.Value.Filename;
                    }
                }

                if (m_options.Force)
                {
                    using (TempFile tf = new TempFile())
                    {
                        doc.Save(tf);
                        tf.Protected = true;
                        backend.WriteDeleteTransactionFile(tf);
                    }
                }

                foreach (ManifestEntry me in entries)
                {
                    sb.AppendLine(string.Format(Strings.Interface.DeletingBackupSetMessage, me.Time.ToString(System.Globalization.CultureInfo.InvariantCulture)));

                    if (m_options.Force)
                    {
                        //Delete manifest
                        if (me.Alternate != null)
                            backend.Delete(me.Alternate);

                        backend.Delete(me);

                        if (me.Verification != null)
                            backend.Delete(me.Verification);

                        foreach (KeyValuePair<SignatureEntry, ContentEntry> kx in me.Volumes)
                        {
                            backend.Delete(kx.Key);
                            backend.Delete(kx.Value);
                        }
                    }
                }

                if (m_options.Force)
                    backend.RemoveDeleteTransactionFile();

                if (!m_options.Force && entries.Count > 0)
                    sb.AppendLine(Strings.Interface.FilesAreNotForceDeletedMessage);
            }

            return sb.ToString();
        }