Beispiel #1
0
 /// <summary>
 /// Try to load the collection of pramters. If that fails try to load a single parameter set (backward compatibility:
 /// </summary>
 /// <param name="csqlParameterPath">The parameter file path.</param>
 /// <returns></returns>
 private static ScriptParameterCollection LoadScriptParameterFromFile(string parameterPath)
 {
     try {
         using (Stream stream = new FileStream(parameterPath, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, FileOptions.SequentialScan)) {
             XmlSerializer             serializer = new XmlSerializer(typeof(ScriptParameterCollection));
             ScriptParameterCollection parameters = (ScriptParameterCollection)serializer.Deserialize(stream);
             stream.Close();
             return(parameters);
         }
     }
     catch (Exception ex) {
         string context = MethodInfo.GetCurrentMethod().Name;
         Debug.WriteLine(String.Format("{0}: Failed to load parameter because [{1}].", context, ex.Message));
     }
     try {
         using (Stream stream = new FileStream(parameterPath, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, FileOptions.SequentialScan)) {
             XmlSerializer   serializer = new XmlSerializer(typeof(ScriptParameter));
             ScriptParameter parameter  = (ScriptParameter)serializer.Deserialize(stream);
             stream.Close();
             ScriptParameterCollection parameters = new ScriptParameterCollection();
             parameters.Add(parameter);
             return(parameters);
         }
     }
     catch (Exception ex) {
         string context = MethodInfo.GetCurrentMethod().Name;
         Debug.WriteLine(String.Format("{0}: Failed to load parameter because [{1}].", context, ex.Message));
     }
     return(null);
 }
Beispiel #2
0
        /// <summary>
        /// Copy constructor
        /// </summary>
        /// <param name="that">The parameter to copy.</param>
        public ScriptParameter(ScriptParameter that)
            : this()
        {
            this.Name                 = that.Name;
            this.Verbosity            = that.Verbosity;
            this.maxResultColumnWidth = that.maxResultColumnWidth;

            this.IncludeDirectories.Clear();
            this.IncludeDirectories.AddRange(that.IncludeDirectories);

            this.preprocessorDefinitions.Clear();
            foreach (PreprocessorDefinition def in that.PreprocessorDefinitions)
            {
                PreprocessorDefinition defCopy = new PreprocessorDefinition(def);
                this.preprocessorDefinitions.Add(defCopy);
            }

            this.AdvancedPreprocessorParameter = that.AdvancedPreprocessorParameter;
            this.OutputFile             = that.OutputFile;
            this.IsOutputFileEnabled    = that.IsOutputFileEnabled;
            this.IsPreprocessorEnabled  = that.IsPreprocessorEnabled;
            this.IsBreakOnErrorEnabled  = that.IsBreakOnErrorEnabled;
            this.TemporaryFile          = that.TemporaryFile;
            this.IsTemporaryFileEnabled = that.IsTemporaryFileEnabled;
        }
Beispiel #3
0
        internal static ScriptParameter CreateDefaultInstance()
        {
            var result = new ScriptParameter();

            result.Name = "Default";

            return(result);
        }
Beispiel #4
0
        private ScriptParameter CloneParameterBySerialization(ScriptParameter parameter)
        {
            XmlSerializer serializer = new XmlSerializer(parameter.GetType());

            using (Stream stream = new MemoryStream()) {
                serializer.Serialize(stream, parameter);
                stream.Seek(0, SeekOrigin.Begin);
                object clone = serializer.Deserialize(stream);
                return((ScriptParameter)clone);
            }
        }
Beispiel #5
0
        public void SerializeIncludeDirectoriesTest()
        {
            ScriptParameter parameterIn = new ScriptParameter();

            parameterIn.IncludeDirectories = new List <string>()
            {
                "A", "B"
            };
            ScriptParameter parameterOut = CloneParameterBySerialization(parameterIn);

            Assert.AreEqual(2, parameterOut.IncludeDirectories.Count);
            Assert.AreEqual("A", parameterOut.IncludeDirectories[0]);
            Assert.AreEqual("B", parameterOut.IncludeDirectories[1]);
        }