private static XmlNode BuildConfigurationSection(string xml)
        {
            var doc = new ConfigXmlDocument();

            doc.LoadXml(xml);
            return(doc.DocumentElement);
        }
Beispiel #2
0
        public Tease LoadTease(string scriptFileName)
        {
            Tease  result       = null;
            string fileContents = File.ReadAllText(scriptFileName);

            if (fileContents.StartsWith("<?xml"))
            {
                var xmldoc = new ConfigXmlDocument();
                xmldoc.LoadXml(fileContents);

                if (xmldoc.DocumentElement != null)
                {
                    if (xmldoc.DocumentElement.LocalName == "Tease")
                    {
                        // Current file format.
                        if (xmldoc.DocumentElement.SelectSingleNode(String.Format("/Tease[@scriptVersion='{0}']", SupportedScriptVersion)) != null)
                        {
                            using (var reader = new StreamReader(scriptFileName))
                            {
                                result = new XmlSerializer(typeof(Tease)).Deserialize(reader) as Tease;
                            }
                        }
                    }
                }
            }

            if (result != null)
            {
                result.ScriptDirectory       = new FileInfo(scriptFileName).DirectoryName;
                Environment.CurrentDirectory = result.ScriptDirectory;
            }

            return(result);
        }
Beispiel #3
0
        public Tease LoadTease(string scriptFileName)
        {
            Tease  result       = null;
            string fileContents = File.ReadAllText(scriptFileName);

            if (fileContents.StartsWith("<?xml"))
            {
                var xmldoc = new ConfigXmlDocument();
                xmldoc.LoadXml(fileContents);

                if (xmldoc.DocumentElement != null)
                {
                    if (xmldoc.DocumentElement.LocalName == "Tease")
                    {
                        // Current file format.
                        if (xmldoc.DocumentElement.SelectSingleNode(String.Format("/Tease[@scriptVersion='{0}']", SupportedScriptVersion)) != null)
                        {
                            using (var reader = new StreamReader(scriptFileName))
                            {
                                result = new XmlSerializer(typeof(Tease)).Deserialize(reader) as Tease;
                            }
                        }
                    }
                    if (xmldoc.DocumentElement.LocalName == "pages")
                    {
                        // Previous file format.
                        var converter = new OldScriptConverter(fileContents);
                        if (converter.CanConvert())
                        {
                            result = converter.ConvertToTease();

                            var sourceFileName = new FileInfo(scriptFileName);
                            var destFileName   = sourceFileName.Name.BeforeLast(sourceFileName.Extension) + "-v0_0_5" + sourceFileName.Extension;

                            string message = "The tease you selected is made for a previous version of this application. "
                                             + "Do you want to convert it to the current file format?\n"
                                             + "\n"
                                             + "Your old file will be renamed to " + destFileName;
                            if (DialogResult.Yes == MessageBox.Show(message, "Save tease in new file format?", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
                            {
                                File.Move(scriptFileName, Path.Combine(sourceFileName.DirectoryName, destFileName));
                                SaveTease(result, sourceFileName.FullName);
                            }
                        }
                    }
                }
            }

            if (result != null)
            {
                result.ScriptDirectory       = new FileInfo(scriptFileName).DirectoryName;
                Environment.CurrentDirectory = result.ScriptDirectory;
            }

            return(result);
        }
Beispiel #4
0
        protected static Process Start <T>(string executableFileName, T parameter, SubprocessConfiguration configuration, Uri address)
        {
            var configPath = Path.Combine(TempDir, "C" + Interlocked.Increment(ref _AssemblyCount) + ".T" + DateTime.Now.Ticks + ".config");

            var configDocument = new ConfigXmlDocument();

            AppendConfig(configDocument, ConfigurationUserLevel.None);
            AppendConfig(configDocument, ConfigurationUserLevel.PerUserRoaming);
            AppendConfig(configDocument, ConfigurationUserLevel.PerUserRoamingAndLocal);

            if (configuration.ShouldCreateConfig)
            {
                if (configDocument.DocumentElement == null)
                {
                    configDocument.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n<configuration></configuration>");
                }
                configDocument.Save(configPath);
                configuration.RaiseConfigCreated(new ConfigCreatedEventArgs(configPath));
            }
            else if (configDocument.DocumentElement != null)
            {
                configDocument.Save(configPath);
            }

            var psi = new ProcessStartInfo(executableFileName);

            var spp = new SubprocessArgument <T>();

            spp.TemporaryDirectory = TempDir;
            spp.Address            = address;
            spp.Parameter          = parameter;
            spp.ParentProcessId    = Process.GetCurrentProcess().Id;
            spp.IsStandalone       = configuration.IsStandalone;
            if (configuration.AttachDebugger)
            {
                spp.DebuggerInfo = DebuggerInfoProvider.GetCurrent();
            }

            var argFilePath = Path.Combine(TempDir, "A" + Interlocked.Increment(ref _AssemblyCount) + ".T" + DateTime.Now.Ticks + ".xml");

            using (var fs = new FileStream(argFilePath, FileMode.Create))
            {
                new DataContractSerializer(spp.GetType()).WriteObject(fs, spp);
            }

            psi.Arguments = configDocument.DocumentElement != null
                            ? (argFilePath + " \"" + configPath + "\"")
                            : argFilePath;


            var p = Process.Start(psi);

            return(p);
        }
Beispiel #5
0
        private KeyValueConfigurationCollection GetSection(string sectionName, string sectionGroupName = null)
        {
            var result = new KeyValueConfigurationCollection();

            if (string.IsNullOrEmpty(sectionName))
            {
                return(result);
            }

            var configuration = ConfigurationManager.OpenMappedExeConfiguration(_exeConfigMap,
                                                                                ConfigurationUserLevel.None);

            ConfigurationSection section;

            if (string.IsNullOrWhiteSpace(sectionGroupName))
            {
                section = configuration.GetSection(sectionName);
            }
            else
            {
                var group = configuration.GetSectionGroup(sectionGroupName);
                if (group == null)
                {
                    throw new Exception("sectionGroup为空");
                }
                section = group.Sections[sectionName];
            }

            if (section != null)
            {
                ConfigXmlDocument vv = new ConfigXmlDocument();
                vv.LoadXml(section.SectionInformation.GetRawXml());

                var items = vv.GetElementsByTagName("add");
                XmlAttributeCollection attributes;
                foreach (XmlNode item in items)
                {
                    attributes = item.Attributes;
                    if (attributes != null && attributes.Count == 2)
                    {
                        result.Add(attributes["key"].Value, attributes["value"].Value);
                    }
                }
            }
            return(result);
        }