Exemple #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);
 }
Exemple #2
0
        /// <summary>
        /// Saves the current script parameter in the solution settings files.
        /// </summary>
        /// <param name="csqlParameter">The current script parameter.</param>
        internal void SaveScriptParameterInSolutionSettings(ScriptParameterCollection scriptParameters)
        {
            if (scriptParameters == null)
            {
                return;
            }

            string solutionDirectory = GetSolutionDirectory(application);
            string csqlParameterName = "CSqlParameter.xml";
            string csqlParameterPath;

            if (string.IsNullOrEmpty(solutionDirectory))
            {
                csqlParameterPath = GetGlobalFilePath(csqlParameterName);
            }
            else
            {
                csqlParameterPath = GetSolutionFilePath(application, csqlParameterName);
                if (!IsFileWritable(csqlParameterPath))
                {
                    csqlParameterName = "CSqlParameter.user.xml";
                    csqlParameterPath = GetSolutionFilePath(application, csqlParameterName);
                }
            }

            if (String.IsNullOrEmpty(csqlParameterPath))
            {
                return;
            }

            SaveScriptParameterCore(scriptParameters, csqlParameterPath);
        }
        public void SerializeDeserializeOne()
        {
            ScriptParameterCollection collection = new ScriptParameterCollection();

            collection.Add(new ScriptParameter()
            {
                Name = "A"
            });
            collection.Add(new ScriptParameter()
            {
                Name = "B"
            });
            ScriptParameterCollection collectionClone;

            XmlSerializer serializer = new XmlSerializer(typeof(ScriptParameterCollection));

            using (Stream stream = new MemoryStream()) {
                serializer.Serialize(stream, collection);

                stream.Seek(0, SeekOrigin.Begin);
                object clone = serializer.Deserialize(stream);
                collectionClone = (ScriptParameterCollection)clone;
            }
            Assert.AreEqual(collection.Count, collectionClone.Count);
        }
Exemple #4
0
        private void Solution_Opened()
        {
            ScriptParameterCollection scriptParameters = LoadSolutionScriptParameter();

            if (scriptParameters != null)
            {
                this.scriptParameters = scriptParameters;
                RaiseSettingsReloaded();
            }
        }
Exemple #5
0
        /// <summary>
        /// Loads the parameter located in the current solution directory
        /// and updates the global current settings variable with the script
        /// parameters loaded.
        /// </summary>
        private ScriptParameterCollection LoadSolutionScriptParameter()
        {
            ScriptParameterCollection parameters = LoadSolutionScriptParameterCore();

            if (parameters != null && parameters.DbConnection != null)
            {
                SaveDbConnectionParameterInGlobals(parameters.DbConnection);
            }

            return(parameters);
        }
Exemple #6
0
 private static void SaveScriptParameterCore(ScriptParameterCollection scriptParameters, string filePath)
 {
     try {
         using (Stream stream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None, 4096, FileOptions.SequentialScan)) {
             XmlSerializer serializer = new XmlSerializer(scriptParameters.GetType());
             serializer.Serialize(stream, scriptParameters);
             stream.Close();
         }
     }
     catch (IOException ex) {
         string context = MethodInfo.GetCurrentMethod().Name;
         Debug.WriteLine(String.Format("{0}: Failed to save parameter because [{1}].", context, ex.Message));
     }
 }
Exemple #7
0
        private ScriptParameterCollection LoadSolutionScriptParameterCore()
        {
            string solutionPath = application.Solution.FileName;
            string parametersPath;

            if (string.IsNullOrEmpty(solutionPath))
            {
                // If no solution is open use the global file.
                parametersPath = GetGlobalFilePath("CSqlParameter.xml");
                if (!String.IsNullOrEmpty(parametersPath) && File.Exists(parametersPath))
                {
                    ScriptParameterCollection parameters = LoadScriptParameterFromFile(parametersPath);
                    if (parameters != null)
                    {
                        return(parameters);
                    }
                }
            }
            else
            {
                parametersPath = GetSolutionFilePath(application, "CSqlParameter.user.xml");
                if (!String.IsNullOrEmpty(parametersPath) && File.Exists(parametersPath))
                {
                    ScriptParameterCollection parameters = LoadScriptParameterFromFile(parametersPath);
                    if (parameters != null)
                    {
                        return(parameters);
                    }
                }
                parametersPath = GetSolutionFilePath(application, "CSqlParameter.xml");
                if (!String.IsNullOrEmpty(parametersPath) && File.Exists(parametersPath))
                {
                    ScriptParameterCollection parameters = LoadScriptParameterFromFile(parametersPath);
                    if (parameters != null)
                    {
                        return(parameters);
                    }
                }
            }

            return(null);
        }