Ejemplo n.º 1
0
        internal string FormatStringData(StringBuilder npText, FormatType fType, bool isSel)
        {
            string npOut = "";
            var    view  = npc.GetViewSettings(isSel);

            if (fType == FormatType.PrettyJson)
            {
                npOut = JsonFormatter.PrettyJson(npText, new JsonFormatSettings()
                {
                    TabWidth = view.TabWidth, UseTabs = view.UseTabs, EolMode = view.EolMode
                });
                npc.CheckSetLangType(view.Id, (int)LangType.L_JSON);
            }
            else if (fType == FormatType.PrettyJsonSorted)
            {
                npOut = JsonFormatter.PrettyJsonSorted(npText, new JsonFormatSettings()
                {
                    TabWidth = view.TabWidth, UseTabs = view.UseTabs, EolMode = view.EolMode
                });
                npc.CheckSetLangType(view.Id, (int)LangType.L_JSON);
            }
            else if (fType == FormatType.MiniJson)
            {
                npOut = JsonFormatter.MiniJson(npText);
                npc.CheckSetLangType(view.Id, (int)LangType.L_JSON);
            }
            else if (fType == FormatType.PrettyXml)
            {
                npOut = XmlFormatter.PrettyXml(npText, new XmlFormatSettings()
                {
                    TabWidth = view.TabWidth, UseTabs = view.UseTabs, EolMode = view.EolMode, IsSelection = view.IsSelection
                });
                npc.CheckSetLangType(view.Id, (int)LangType.L_XML);
            }
            else if (fType == FormatType.PrettyXmlSorted)
            {
                npOut = XmlFormatter.PrettyXmlSorted(npText, new XmlFormatSettings()
                {
                    TabWidth = view.TabWidth, UseTabs = view.UseTabs, EolMode = view.EolMode, IsSelection = view.IsSelection
                },
                                                     nps.XmlSortExcludeAttributeValues.ValToString().Split(new string[] { nps.XmlSortExcludeValueDelimiter.ValToString() }, StringSplitOptions.RemoveEmptyEntries));
                npc.CheckSetLangType(view.Id, (int)LangType.L_XML);
            }
            else if (fType == FormatType.MiniXml)
            {
                npOut = XmlFormatter.MiniXml(npText, new XmlFormatSettings()
                {
                    TabWidth = view.TabWidth, UseTabs = view.UseTabs, EolMode = view.EolMode, IsSelection = view.IsSelection
                });
                npc.CheckSetLangType(view.Id, (int)LangType.L_XML);
            }
            else if (fType == FormatType.B64GzipString)
            {
                if (npText.ToString(0, 5).StartsWith("Data=", StringComparison.OrdinalIgnoreCase))
                {
                    npText.Remove(0, 5);
                }

                npOut = Base64GzipConverter.ConvertToString(npText);
            }
            else if (fType == FormatType.B64GzipPrettyJson)
            {
                if (npText.ToString(0, 5).StartsWith("Data=", StringComparison.OrdinalIgnoreCase))
                {
                    npText.Remove(0, 5);
                }

                npOut = JsonFormatter.PrettyJson(new StringBuilder(Base64GzipConverter.ConvertToString(npText)),
                                                 new JsonFormatSettings()
                {
                    TabWidth = view.TabWidth, UseTabs = view.UseTabs, EolMode = view.EolMode
                });
                npc.CheckSetLangType(view.Id, (int)LangType.L_JSON);
            }
            else if (fType == FormatType.B64GzipPayload)
            {
                npOut = Base64GzipConverter.ConvertToPayload(npText);
            }
            else if (fType == FormatType.BlobString)
            {
                npOut = BlobConverter.ConvertToString(npText);
            }
            else if (fType == FormatType.BlobPayload)
            {
                npOut = BlobConverter.ConvertToPayload(npText);
            }
            else
            {
                throw new Exception("Invalid command.");
            }

            return(npOut);
        }