public override void WriteValue(string key, object value, bool isLastAtThisNestingLevel)
        {
            var type = value.GetAppDataType();

            System.Diagnostics.Debug.Assert(type != AppDataType.Type.ApplicationDataCompositeValue);

            string jkey   = key.JSONEscape();
            string jtype  = type.ToString().JSONEscape();
            string jvalue = AppDataExtensions.ValueToJSON(value);
            string suffix = Delimiter(isLastAtThisNestingLevel);

            WriteIndent();
            writer.WriteLine(String.Format("\"{0}\": [ \"{1}\", {2} ]{3}", jkey, jtype, jvalue, suffix));
        }
Beispiel #2
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.");
        }
Beispiel #3
0
 private void DumpContainer(ApplicationDataContainer container, string path)
 {
     PrintLine();
     PrintLine(AppDataExtensions.BuildPath(container, path));
 }