示例#1
0
        /// <summary>
        /// Serialize the object using the DataContractSerializer to the file specified. If the file
        /// exists it will be overwritten and it requires an exclusive write lock on the file.
        /// </summary>
        /// <param name="path">The filename to write the serialization string to</param>
        /// <param name="encoding">The encoding to use when serializing.</param>
        /// <param name="entity">The entity to serialize.</param>
        /// <returns></returns>
        public static void ToXmlInFile <T>(string path, Encoding encoding, T entity)
        {
            var serializer = new DataContractSerializer(typeof(T));
            var filename   = SmartLocation.GetLocation(path);

            using (var writer = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.None))
            {
                serializer.WriteObject(writer, entity);
            }
        }
示例#2
0
        /// <summary>
        /// Deserialize the object using the DataContractSerializer from the file specified. If the file
        /// does not exist then an exception will be thrown
        /// </summary>
        /// <param name="path">The fully qualified path to the file</param>
        /// <param name="encoding">The encoding to use when deserializing.</param>
        /// <returns></returns>
        public static T FromXmlInFile <T>(string path, Encoding encoding)
        {
            var serializer = new DataContractSerializer(typeof(T));
            var filename   = SmartLocation.GetLocation(path);

            using (var reader = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                return((T)serializer.ReadObject(reader));
            }
        }
示例#3
0
        static TypeDiscovery()
        {
            _binFolder = SmartLocation.GetBinFolder();
            _config    = Container.Resolve <TypeDiscoveryConfig>();

            _filesToExclude = new List <string>();
            var exclude = new List <string>();

            if (_config.Exclude == null)
            {
                return;
            }

            _config.Exclude.ForEach(e => exclude.AddRange(Directory.GetFiles(_binFolder, e)));
            _filesToExclude = exclude.Distinct().ToList();
        }
示例#4
0
        /// <summary>
        /// Static inline version of the <see cref="Location"/> property
        /// </summary>
        /// <param name="rawLocation">The "raw" location</param>
        /// <returns>The resolved location consistent for the application context/environment</returns>
        public static string GetLocation(string rawLocation)
        {
            var sl = new SmartLocation(rawLocation);

            return(sl.Location);
        }
示例#5
0
 /// <summary>
 /// Static inline version of the <see cref="Location"/> property
 /// </summary>
 /// <param name="rawLocation">The "raw" location</param>
 /// <returns>The resolved location consistent for the application context/environment</returns>
 public static string GetLocation(string rawLocation)
 {
     var sl = new SmartLocation(rawLocation);
     return sl.Location;
 }