コード例 #1
0
        internal static void SaveFile(IFilePath fp)
        {
            using (new EntityCache(EntityCacheType.ForceNew))
            {
                FileTypeAlgorithm alg = FileTypes.GetOrThrow(fp.FileType);

                if (alg.TakesOwnership)
                {
                    string sufix = alg.CalculateSufix(fp);
                    if (!sufix.HasText())
                        throw new InvalidOperationException("Sufix not set");

                    fp.SetPrefixPair(alg.GetPrefixPair(fp));

                    int i = 2;
                    fp.Sufix = sufix;
                    while (alg.RenameOnCollision && File.Exists(fp.FullPhysicalPath))
                    {
                        fp.Sufix = alg.RenameAlgorithm(sufix, i);
                        i++;
                    }

                    alg.SaveFileInDisk(fp);
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RijndaelSymmetricCryptoSerialized"/> class.
 /// </summary>
 /// <param name="configurationFilePath">The configuration file path.</param>
 public RijndaelSymmetricCryptoSerialized(IFilePath configurationFilePath)
 {
     XmlSerializer serializer = new XmlSerializer(typeof(RijndaelSymmetricCryptoConfiguration));
     using (Stream stream = configurationFilePath.GetFileStream())
     using (XmlTextReader reader = new XmlTextReader(stream))
     {
         RijndaelSymmetricCryptoConfiguration configuration = serializer.Deserialize(reader) as RijndaelSymmetricCryptoConfiguration;
         this.wrapped = new RijndaelSymmetricCrypto(configuration);
     }
 }
コード例 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AliasIpReader"/> class.
 /// </summary>
 /// <param name="configurationFilePath">The configuration file path.</param>
 public AliasIpReader(IFilePath configurationFilePath)
 {
     XmlSerializer serializer = new XmlSerializer(typeof(AliasIpReaderConfiguration));
     using (Stream stream = configurationFilePath.GetFileStream())
     {
         using (XmlTextReader reader = new XmlTextReader(stream))
         {
             this.configuration = serializer.Deserialize(reader) as AliasIpReaderConfiguration;
         }
     }
 }
コード例 #4
0
ファイル: Config.cs プロジェクト: cgavieta/WORKPAC2016-poc
        /// <summary>
        /// Initializes a new instance of the <see cref="Config" /> class.
        /// </summary>
        /// <param name="path">The path to the config file.</param>
        /// <param name="configSection">The name of the configuration section to load.</param>
        public Config(IFilePath path, string configSection)
        {
            this.config = null;
            var filepath = ((RelativeFilePath)path).FilePath;

            // It's ok for the config file to not be specified.
            // We will just use the default values for each request.
            if (!string.IsNullOrEmpty(filepath) && File.Exists(filepath) && !string.IsNullOrEmpty(configSection))
            {
                var json = File.ReadAllText(((RelativeFilePath)path).FilePath);
                var conf = JToken.Parse(json);
                this.config = conf.SelectToken(configSection, false);
            }
        }
コード例 #5
0
ファイル: Worker.cs プロジェクト: evilbaschdi/FileWatcher
        /// <summary>
        ///     Initialisiert eine neue Instanz der <see cref="T:System.Object" />-Klasse.
        /// </summary>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="filePath" /> is <see langword="null" />.
        ///     <paramref name="app" /> is <see langword="null" />.
        /// </exception>
        public Worker(IFilePath filePath, App app)
        {
            if (filePath == null)
            {
                throw new ArgumentNullException(nameof(filePath));
            }
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }

            _filePath = filePath;
            _app = app;
            _xmlPath = _app.XmlPath;
        }
コード例 #6
0
         internal static string UpdateExtension(IFilePath filePath, string newExtension) {
            Debug.Assert(filePath != null);
            // All these 3 assertions have been checked by contract!
            Debug.Assert(newExtension != null);
            Debug.Assert(newExtension.Length >= 2);
            Debug.Assert(newExtension[0] == '.');

            var fileNameBefore = filePath.FileName;
            var fileNameAfter = filePath.FileNameWithoutExtension + newExtension;
            var filePathString = filePath.ToString();
            Debug.Assert(filePathString.Length > fileNameBefore.Length);
            var filePathStringWithoutFileName = filePathString.Substring(0, filePathString.Length - fileNameBefore.Length);
            var filePathStringWithFileNameAfter = filePathStringWithoutFileName + fileNameAfter;
            return filePathStringWithFileNameAfter;
         }
コード例 #7
0
			internal static string UpdateExtension(IFilePath filePath, string extension)
			{
				Argument.IsNotNull(nameof(filePath), filePath);

				Argument.IsNotNull(nameof(extension), extension);
				Argument.IsValid(nameof(extension), extension, extension.Length >= 2 && extension[0] == '.');

				var fileNameBefore = filePath.FileName;
				var fileNameAfter = filePath.FileNameWithoutExtension + extension;
				var filePathString = filePath.ToString();

				//Debug.Assert(filePathString.Length > fileNameBefore.Length);

				var filePathStringWithoutFileName = filePathString.Substring(0, filePathString.Length - fileNameBefore.Length);
				
				return filePathStringWithoutFileName + fileNameAfter;
			}
コード例 #8
0
		/// <summary>
		///     Try get a new <see cref="IFilePath" /> object object from this string.
		/// </summary>
		/// <returns>
		///     <i>true</i> if <paramref name="path" /> is a valid file path and as a consequence, the returned <paramref name="filePath" /> is not
		///     null.
		/// </returns>
		/// <remarks>The path represented by this string doesn't need to exist for this operation to complete properly.</remarks>
		/// <param name="path">Represents the path.</param>
		/// <param name="filePath">If this method returns <i>true</i>, this is the returned path object.</param>
		/// <param name="failureMessage">If this method returns <i>false</i>, this is the plain english description of the failure.</param>
		public static bool TryGetFilePath(this string path, out IFilePath filePath, out string failureMessage)
		{
			filePath = null;

			if (IsNullOrEmpty(() => path, out failureMessage))
			{
				return false;
			}

			if (path.IsValidAbsoluteFilePath())
			{
				filePath = path.ToAbsoluteFilePath();

				return true;
			}

			if (path.IsValidRelativeFilePath())
			{
				filePath = path.ToRelativeFilePath();

				return true;
			}

			if (path.IsValidEnvVarFilePath())
			{
				filePath = path.ToEnvVarFilePath();

				return true;
			}

			if (path.IsValidVariableFilePath())
			{
				filePath = path.ToVariableFilePath();

				return true;
			}

			path.IsValidFilePath(out failureMessage);

			failureMessage = $@"The parameter pathString is not a valid file path.{Environment.NewLine}{failureMessage}";

			return false;
		}
コード例 #9
0
		/// <summary>
		///     Try get a new <see cref="IFilePath" /> object object from this string.
		/// </summary>
		/// <returns>
		///     <i>true</i> if <paramref name="path" /> is a valid file path and as a consequence, the returned <paramref name="filePath" /> is not
		///     null.
		/// </returns>
		/// <remarks>The path represented by this string doesn't need to exist for this operation to complete properly.</remarks>
		/// <param name="path">Represents the path.</param>
		/// <param name="filePath">If this method returns <i>true</i>, this is the returned path object.</param>
		public static bool TryGetFilePath(this string path, out IFilePath filePath)
		{
			string failureMessage;

			return path.TryGetFilePath(out filePath, out failureMessage);
		}
コード例 #10
0
 static bool IsNotExcluded(IFilePath x, IReadOnlyCollection<IAbsoluteDirectoryPath> excludedDirectories,
     IEnumerable<IAbsoluteFilePath> excludedFiles) {
     return IsNotDirectoryExcluded(x, excludedDirectories) && !excludedFiles.Contains(x);
 }
コード例 #11
0
 static bool IsNotDirectoryExcluded(IFilePath x,
     IReadOnlyCollection<IAbsoluteDirectoryPath> excludedDirectories) {
     IPath b = x;
     while (b.HasParentDirectory) {
         var parent = b.ParentDirectoryPath;
         if (excludedDirectories.Contains(parent))
             return false;
         b = parent;
     }
     return true;
 }
コード例 #12
0
ファイル: DoPutAction.cs プロジェクト: kapiya/Warewolf
 public DoPutAction(Stream currentStream, IActivityIOPath destination, IDev2CRUDOperationTO crudArgument, string whereToPut, IDev2LogonProvider logOnProvider, IFile fileWrapper, IFileStreamFactory fileStreamFactory, IFilePath pathWrapper, IMemoryStreamFactory memoryStreamFactory, ImpersonationDelegate impersonationDelegate)
     : base(impersonationDelegate)
 {
     _logOnProvider       = logOnProvider;
     _pathWrapper         = pathWrapper;
     _fileWrapper         = fileWrapper;
     _fileStreamFactory   = fileStreamFactory;
     _memoryStreamFactory = memoryStreamFactory;
     _currentStream       = currentStream;
     _destination         = destination;
     _arguments           = crudArgument;
     _impersonatedUser    = _impersonationDelegate(_destination, _logOnProvider);
     _whereToPut          = whereToPut;
 }
コード例 #13
0
ファイル: Test_FilePath.cs プロジェクト: endjin/NDepend.Path
 public void Test_Invalid_IsValidFile(string pathString)
 {
     Assert.IsFalse(pathString.IsValidFilePath());
     Assert.Throws(typeof(ArgumentException), delegate { IFilePath filePath = pathString.ToRelativeFilePath(); });
 }
コード例 #14
0
ファイル: Test_FilePath.cs プロジェクト: endjin/NDepend.Path
 public void Test_InvalidInputRelativePathNull()
 {
     Assert.IsFalse(PathHelpers.IsValidRelativeFilePath(null));
     Assert.Throws(typeof(ArgumentNullException), delegate { IFilePath filePath = PathHelpers.ToRelativeFilePath(null); });
 }
コード例 #15
0
        public static void SaveFileDefault(IFilePath fp)
        {
            string fullPhysicalPath = null;
            try
            {
                string path = Path.GetDirectoryName(fp.FullPhysicalPath);
                fullPhysicalPath = path;
                if (!Directory.Exists(path))
                    Directory.CreateDirectory(path);
                File.WriteAllBytes(fp.FullPhysicalPath, fp.BinaryFile);
                fp.BinaryFile = null;
            }
            catch (IOException ex)
            {
                ex.Data.Add("FullPhysicalPath", fullPhysicalPath);
                ex.Data.Add("CurrentPrincipal", System.Threading.Thread.CurrentPrincipal.Identity.Name);

                throw;
            }
        }
コード例 #16
0
      ///<summary>
      ///Try get a new <see cref="IFilePath"/> object object from this string.
      ///</summary>
      ///<returns><i>true</i> if <paramref name="pathString"/> is a valid file path and as a consequence, the returned <paramref name="filePath"/> is not null.</returns>
      ///<remarks>The path represented by this string doesn't need to exist for this operation to complete properly.</remarks>
      ///<param name="pathString">Represents the path.</param>
      ///<param name="filePath">If this method returns <i>true</i>, this is the returned path object.</param>
      ///<param name="failureReason">If this method returns <i>false</i>, this is the plain english description of the failure.</param>
      public static bool TryGetFilePath(this string pathString, out IFilePath filePath, out string failureReason) {
         filePath = null;
         if (pathString.IsPathStringNullOrEmpty(out failureReason)) { return false; }

         if (pathString.IsValidAbsoluteFilePath()) {
            filePath = pathString.ToAbsoluteFilePath();
            return true;
         }
         if (pathString.IsValidRelativeFilePath()) {
            filePath = pathString.ToRelativeFilePath();
            return true;
         }
         if (pathString.IsValidEnvVarFilePath()) {
            filePath = pathString.ToEnvVarFilePath();
            return true;
         }
         if (pathString.IsValidVariableFilePath()) {
            filePath = pathString.ToVariableFilePath();
            return true;
         }
         
         var b = pathString.IsValidFilePath(out failureReason);
         Debug.Assert(!b);
         failureReason = @"The parameter pathString is not a valid file path.
" + failureReason;
         return false;
      }
コード例 #17
0
 public IEnumerable<IDebugState> GetDebugStates(string serverWebUri, IDirectoryPath directory, IFilePath path)
 {
     yield break;
 }
コード例 #18
0
ファイル: Test_FilePath.cs プロジェクト: endjin/NDepend.Path
 public void Test_ValidFilePath(string pathString)
 {
     Assert.IsTrue(pathString.IsValidFilePath());
     IFilePath path = pathString.ToFilePath();
 }
コード例 #19
0
ファイル: EmployeeDal.cs プロジェクト: Tia94/Internship2015
 public EmployeeDal(IFilePath filePath)
 {
     _filePath = filePath;
 }
コード例 #20
0
 public IEnumerable <IDebugState> GetDebugStates(string serverWebUri, IDirectoryPath directory, IFilePath path)
 {
     yield break;
 }
コード例 #21
0
 internal static bool IsSketchFilesFile(IFilePath path)
 {
     return(path.Name.HasExtension(SketchFilesExtension));
 }
コード例 #22
0
 public FilePathCollection(IFilePath filePathMain, IFilePath filePathPdf, IFilePath filePathPrint)
 {
     FilePathMain  = filePathMain;
     FilePathPdf   = filePathPdf;
     FilePathPrint = filePathPrint;
 }
コード例 #23
0
 ///<summary>
 ///Try get a new <see cref="IFilePath"/> object object from this string.
 ///</summary>
 ///<returns><i>true</i> if <paramref name="pathString"/> is a valid file path and as a consequence, the returned <paramref name="filePath"/> is not null.</returns>
 ///<remarks>The path represented by this string doesn't need to exist for this operation to complete properly.</remarks>
 ///<param name="pathString">Represents the path.</param>
 ///<param name="filePath">If this method returns <i>true</i>, this is the returned path object.</param>
 public static bool TryGetFilePath(this string pathString, out IFilePath filePath) {
    string failureReasonUnused;
    return pathString.TryGetFilePath(out filePath, out failureReasonUnused);
 }
コード例 #24
0
ファイル: ResourceDirectory.cs プロジェクト: yts233/Minecraft
 protected override void LoadAssets(object argument)
 {
     var root = _filepath = (IFilePath)argument;
コード例 #25
0
ファイル: ResourceDirectory.cs プロジェクト: yts233/Minecraft
 /// <summary>
 /// 从<see cref="IFilePath" />创建<see cref="DirectoryResource" />
 /// </summary>
 /// <param name="path"></param>
 /// <param name="name"></param>
 public DirectoryResource(IFilePath path, string name = null) : base(Uuid.NewUuid(), name ?? path.GetFileName(),
                                                                     null, path)
 {
 }
コード例 #26
0
        static ServerVersionRepository CreateServerVersionRepository(IVersionStrategy strat, IResourceCatalog cat, IDirectory dir, string rootPath, IFile file, IFilePath filePath)
        {
            var serverVersionRepostory = new ServerVersionRepository(strat, cat, dir, rootPath, file, filePath);

            return(serverVersionRepostory);
        }