/// <summary>
        /// Initialises the packages store by validating parameters, then connecting to the network share.
        /// </summary>
        /// <exception cref="ArgumentNullException"> if <paramref name="DriveLetter"/> is null or contains only whitespace or <paramref name="RootPath"/> is null or contains only whitespace or <paramref name="UserName"/> is null or contains only whitespace or <paramref name="AccessKey"/> is null or contains only whitespace or <paramref name="FileShareName"/> is null or contains only whitespace.</exception>
        /// <exception cref="ArgumentOutOfRangeException"> if <paramref name="DriveLetter"/> does not match ^[A-Za-z]:$ or <paramref name="RootPath"/> does not start with <paramref name="DriveLetter"/></exception>
        private void InitPackageStore()
        {
            _logger = Logger.Initialise(LogFileName);
            _fileSystemOperations.Logger = _logger;

            if (string.IsNullOrWhiteSpace(DriveLetter))
            {
                throw new ArgumentNullException("DriveLetter");
            }
            if (!Regex.IsMatch(DriveLetter, "^[A-Za-z]:$"))
            {
                throw new ArgumentOutOfRangeException("DriveLetter", "DriveLetter must be a single drive letter (A-Z) followed by a colon");
            }

            if (string.IsNullOrWhiteSpace(RootPath))
            {
                throw new ArgumentNullException("RootPath");
            }
            if (!RootPath.ToLower().StartsWith(DriveLetter.ToLower()))
            {
                throw new ArgumentOutOfRangeException("RootPath", "RootPath must be on the drive specified by DriveLetter (ie, if DriveLetter='P:', then RootPath must start with 'P:\'");
            }

            if (string.IsNullOrWhiteSpace(UserName))
            {
                throw new ArgumentNullException("UserName");
            }

            if (string.IsNullOrWhiteSpace(AccessKey))
            {
                throw new ArgumentNullException("AccessKey");
            }

            if (string.IsNullOrWhiteSpace(FileShareName))
            {
                throw new ArgumentNullException("FileShareName");
            }

            var uncPath = string.Format(@"\\{0}.file.core.windows.net\{1}", UserName, FileShareName);

            try
            {
                _logger.DebugFormat("Mapping network share '{0}' to drive '{1}' with username '{2}'", uncPath, DriveLetter, UserName);
                var stopWatch = new Stopwatch();
                stopWatch.Start();
                _fileShareMapper.Mount(DriveLetter, uncPath, UserName, AccessKey, _logger);
                stopWatch.Stop();
                _logger.DebugFormat("Drive mapping successful and took {0} milliseconds.", stopWatch.ElapsedMilliseconds);
            }
            catch (Exception ex)
            {
                _logger.Error(String.Format("Exception occurred mapping drive '{0}' to '{1}' with username '{2}'", DriveLetter, uncPath, UserName), ex);
                throw;
            }
        }
Example #2
0
        public void Test_Slice_2_WithPrefix()
        {
            var basepath = Filepath.Parse(@"C:\home\kuma\foo\bar\baz.txt");

            // 色々なパラメータを入力しても
            // へんな例外が発生しなければOK
            {
                for (var c = -20; c < 20; c++)
                {
                    for (var s = -20; s < 20; s++)
                    {
                        var path = basepath.Slice(s, c);
                        Assert.IsTrue(true);
                    }
                }
            }

            {             // Slice(0) ... 実質、何も変わらないはず
                var path = basepath.Slice(0);
                Assert.IsInstanceOfType(path.Prefix, typeof(PathPrefix.Dos));
                Assert.AreEqual((path.Prefix as PathPrefix.Dos) !.DriveLetter.ToLower(), "c");

                Assert.IsTrue(path.IsAbsolute);
                Assert.AreEqual("home", path.Items[0]);
                Assert.AreEqual("baz.txt", path.Items[4]);
            }

            {             // Slice(1) ... 相対パスを表すようになるはず
                var path = basepath.Slice(1);
                Assert.IsInstanceOfType(path.Prefix, typeof(PathPrefix.Dos));
                Assert.AreEqual((path.Prefix as PathPrefix.Dos) !.DriveLetter.ToLower(), "c");

                Assert.IsFalse(path.IsAbsolute);
                Assert.AreEqual("kuma", path.Items[0]);
                Assert.AreEqual("baz.txt", path.Items[3]);
            }
        }