Exemplo n.º 1
0
 public ActionResult List()
 {
     using (WindowsNetworkFileShare networkPath = new WindowsNetworkFileShare(sharePath, ShareCredentials))
     {
         return(Json(Directory.EnumerateFiles(sharePath), JsonRequestBehavior.AllowGet));
     }
 }
Exemplo n.º 2
0
 public ActionResult <IEnumerable <string> > List()
 {
     using (var networkPath = new WindowsNetworkFileShare(sharePath, ShareCredentials))
     {
         return(new ActionResult <IEnumerable <string> >(Directory.EnumerateFiles(sharePath)));
     }
 }
Exemplo n.º 3
0
        public ActionResult Delete()
        {
            using (WindowsNetworkFileShare networkPath = new WindowsNetworkFileShare(sharePath, ShareCredentials))
            {
                System.IO.File.Delete(Path.Combine(sharePath, demoFileName));
            }

            return(Json("File deleted successfully", JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 4
0
        public ActionResult Copy()
        {
            using (WindowsNetworkFileShare networkPath = new WindowsNetworkFileShare(sharePath, ShareCredentials))
            {
                System.IO.File.Copy(Path.Combine(Server.MapPath("~"), demoFileName), Path.Combine(sharePath, demoFileName), true);
            }

            return(Json("File copied successfully", JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 5
0
        public ActionResult <string> Delete()
        {
            using (var networkPath = new WindowsNetworkFileShare(sharePath, ShareCredentials))
            {
                System.IO.File.Delete(Path.Combine(sharePath, demoFileName));
            }

            return("File deleted successfully");
        }
Exemplo n.º 6
0
        public ActionResult <string> Copy()
        {
            using (var networkPath = new WindowsNetworkFileShare(sharePath, ShareCredentials))
            {
                System.IO.File.Copy(demoFileName, Path.Combine(sharePath, demoFileName), true);
            }

            return("File copied successfully");
        }
        public void WindowsNetworkFileShare_Constructor_ConcatsUserAndDomain()
        {
            var fakeMPR = new FakeMPR();

            _ = new WindowsNetworkFileShare(@"\\server\path", new NetworkCredential("user", "password", "domain"), fakeMPR);

            Assert.Equal(@"domain\user", fakeMPR._username);
            Assert.Equal("password", fakeMPR._password);
            Assert.Equal(@"\\server\path", fakeMPR._networkpath);
        }
        public void WindowsNetworkFileShare_Constructor_SetsValuesOn_ConnectSuccess()
        {
            var fakeMPR = new FakeMPR();

            _ = new WindowsNetworkFileShare(@"\\server\path", new NetworkCredential("user", "password"), fakeMPR);

            Assert.Equal("user", fakeMPR._username);
            Assert.Equal("password", fakeMPR._password);
            Assert.Equal(@"\\server\path", fakeMPR._networkpath);
        }
Exemplo n.º 9
0
        static void Main(string[] args)
        {
            string uncPath  = args[0];
            string username = args[1];
            string password = args[2];
            string domain   = ""; // domain not used

            NetworkCredential credential = new NetworkCredential(username, password, domain);

            using (WindowsNetworkFileShare networkPath = new WindowsNetworkFileShare(uncPath, credential))
            {
                FindFiles(uncPath);
            }
        }
Exemplo n.º 10
0
        public SmbClient(string uncPath, string userName = "", string password = "", string domain = "")
        {
            UncPath  = uncPath ?? throw new ArgumentNullException(nameof(uncPath));
            UserName = userName;
            Password = password;
            Domain   = domain;

            Console.WriteLine($@"Establishing credentials for user {domain}\{userName}");
            var credential = new NetworkCredential(UserName, Password, Domain);

            Console.WriteLine($"Logging into share at path {uncPath}");
            _fileShare = new WindowsNetworkFileShare(uncPath, credential);
            Console.WriteLine($"Logged into share at path {uncPath}");
        }
Exemplo n.º 11
0
        /// <summary>
        /// Method for File monitoring
        /// </summary>
        public void Monitor()
        {
            LoggerHelper.Debug("Timer is firing");

            //Using X service UNC
            if (Environment.GetEnvironmentVariable(EnvVar.ASPNET_CORE_ENVRIONMENT) == "Development")
            {
                LoggerHelper.Info("Using local service UNC");
                // Attempt to create all directories needed
                UncFolderHelper.CreateUncFolders();

                try
                {
                    FileLoop();
                }
                catch (Exception ex)
                {
                    LoggerHelper.GeneralExceptionLogFile("FileManager_FileLoop", ex);
                }
            }
            else
            {
                LoggerHelper.Info("Using network service UNC");
                try
                {
                    NetworkCredential credential = new NetworkCredential(_volumeServiceUsername, _volumeServicePassword, _volumeServiceDomain);
                    using (WindowsNetworkFileShare networkPath = new WindowsNetworkFileShare(_volumeServiceShare, credential))
                    {
                        try
                        {
                            FileLoop();
                        }
                        catch (Exception ex)
                        {
                            LoggerHelper.GeneralExceptionLogFile("FileManager_FileLoop", ex);
                        }
                    }
                }
                catch (Exception ex)
                {
                    LoggerHelper.GeneralExceptionLogFile("FileManager_FileLoop_NetworkCredentials", ex);
                }
            }

            LoggerHelper.Debug("Timer has finished");
        }
        public IHttpActionResult CopyFileToShareWithCreds()
        {
            string destFilePath   = _shareFolderAddress + @"\the-pivotal-story-copy.pdf";
            string sourceFilePath = @".\the-pivotal-story.pdf";

            //Using the Steeltoe.Common.Net package, which uses WNetUseConnection
            //     we authenticate ouselves and then copy the file
            IHttpActionResult badRequestObj;

            using (WindowsNetworkFileShare networkPath = new WindowsNetworkFileShare(_shareFolderAddress, _shareCredential)) {
                badRequestObj = copyFileToNetworkShare(sourceFilePath, destFilePath);
            }

            if (badRequestObj != null)
            {
                return(badRequestObj);
            }

            return(Json("Yeah! Your file got copied and validated."));
        }
Exemplo n.º 13
0
 public void GetErrorForUnknownNumber_ReturnsUnKnownError()
 {
     Assert.Equal("Error: Unknown, 9999", WindowsNetworkFileShare.GetErrorForNumber(9999));
 }
Exemplo n.º 14
0
 public void GetErrorForKnownNumber_ReturnsKnownError()
 {
     Assert.Equal("Error: Access Denied", WindowsNetworkFileShare.GetErrorForNumber(5));
     Assert.Equal("Error: No Network", WindowsNetworkFileShare.GetErrorForNumber(1222));
 }