Ejemplo n.º 1
0
        public override void Execute()
        {
            PrintLineVerbose("open");
            OpenApplicationData();

            PrintLineVerbose("execute");
            System.Diagnostics.Debug.Assert(this.locality == Locality.Local || this.locality == Locality.Roaming);
            var settings = (this.locality == Locality.Local) ? appdata.LocalSettings : appdata.RoamingSettings;

            PrintLineVerbose("container");
            if (this.valueKey.IsEmpty() && !this.deleteAllValuesInContainer)
            {
                System.Diagnostics.Debug.Assert(!this.path.IsEmpty());
                if (!this.force && !Stdio.Prompt(String.Format("Permanently delete the container {0} (Yes/No)? ", AppDataExtensions.BuildPath(settings, this.path))))
                {
                    FatalError("The operation was canceled by the user.");
                }
                try
                {
                    settings.DeleteContainer(this.path);
                }
                catch (Exception ex)
                {
                    if (ex.HResult == Win32Errors.ERROR_OBJECT_NOT_FOUND)
                    {
                        FatalError("Container path not found", this.path);
                    }
                    else
                    {
                        FatalError(ex.ToString());
                    }
                    return;
                }
            }
            else
            {
                ApplicationDataContainer container;
                if (this.path.IsEmpty())
                {
                    container = settings;
                }
                else
                {
                    try
                    {
                        container = settings.CreateContainer(this.path, ApplicationDataCreateDisposition.Always);
                    }
                    catch (Exception ex)
                    {
                        if (ex.HResult == Win32Errors.ERROR_OBJECT_NOT_FOUND)
                        {
                            FatalError("Container path not found", this.path);
                        }
                        else
                        {
                            FatalError(ex.ToString());
                        }
                        return;
                    }
                }

                PrintLineVerbose("delete");
                if (this.deleteAllValuesInContainer)
                {
                    DeleteValues(container, AppDataExtensions.BuildPath(container, this.path));
                }
                else
                {
                    DeleteValue(container, this.valueKey);
                }
            }

            PrintLine("The operation completed successfully.");
        }
Ejemplo n.º 2
0
 private void DumpContainer(ApplicationDataContainer container, string path)
 {
     PrintLine();
     PrintLine(AppDataExtensions.BuildPath(container, path));
 }