Exemple #1
0
 public UncPath(ServerName remoteServer, ShareName shareName, SubDirectory subDirectory, SubDirectory subSubDirectory)
 {
     _remoteServer    = remoteServer;
     _shareName       = shareName;
     _subDirectory    = subDirectory;
     _subSubDirectory = subSubDirectory;
 }
 private static void ShareFolder(ILogger logger, DirectoryPath directoryPath, ShareName shareName, string shareDescription)
 {
     logger.LogDebug(string.Format("Starts trying to share {0} as {1}", directoryPath, shareName));
     WindowsShare.MethodStatus methodStatus = WindowsShare.Create(directoryPath.PathString, shareName.ToString(), WindowsShare.ShareType.DiskDrive, null, shareDescription, null);
     if (methodStatus != WindowsShare.MethodStatus.Success)
     {
         throw new ShareException(string.Format("Creating share failed for {0} at {1}. Error {2}.", shareName, directoryPath, methodStatus.ToString()));
     }
     logger.LogInfo(string.Format("Share {0} created for {1}.", shareName, directoryPath));
 }
        private static void SharePermissions(ILogger logger, ShareName shareName, string domain, string user, WindowsShare.AccessMaskTypes accessMask)
        {
            logger.LogDebug(string.Format("Trying to set permissions to share {0} for user {1}\\{2}", shareName, domain, user));
            WindowsShare windowsShare = WindowsShare.GetShareByName(shareName.ToString());

            if (windowsShare == null)
            {
                throw new ShareException(string.Format("Could not find share {0}.", shareName));
            }
            WindowsShare.MethodStatus methodStatus = windowsShare.SetPermission(domain, user, accessMask);
            if (methodStatus != WindowsShare.MethodStatus.Success)
            {
                throw new ShareException(string.Format("Could not set AccessMask {0} for user {1}\\{2} on share {3}", accessMask.ToString(), domain, user, shareName));
            }
            logger.LogInfo(string.Format("Share permissings set for {0}.", shareName));
        }
Exemple #4
0
        public string BuildUncPath()
        {
            if (RemoteServer == null || ShareName == null)
            {
                throw new ShareException(string.Format("Cannot build Unc path as either server {0} or share {1} is not set", _remoteServer, _shareName));
            }
            string returnValue = "\\\\" + RemoteServer.ToString() + "\\" + ShareName.ToString();

            if (SubDirectory != null)
            {
                returnValue += "\\" + SubDirectory.ToString();
            }
            if (SubSubDirectory != null)
            {
                returnValue += "\\" + SubSubDirectory.ToString();
            }
            return(returnValue);
        }
Exemple #5
0
 public UncPath(ServerName remoteServer, ShareName shareName)
 {
     _remoteServer = remoteServer;
     _shareName    = shareName;
 }
 public static void CreateLocalShareDirectoryIfNotExisting(ILogger logger, DirectoryPath directoryPath, ShareName shareName, string domain, string user)
 {
     try
     {
         DirectoryHelper.CreateLocalDirectoryIfNotExistingAndGiveFullControlToUser(logger, directoryPath, domain, user);
         DirectoryHelper.TestReadWriteAccessToDirectory(logger, directoryPath);
         string shareDescription = string.Format("Shared {0} with {1} on {2}", directoryPath, shareName, DateTime.UtcNow.ToLongDateString());
         if (WindowsShare.GetShareByName(shareName.ToString()) == null)
         {
             logger.LogDebug(string.Format("No share existing. Creating share {0}.", shareName));
             ShareFolder(logger, directoryPath, shareName, shareDescription);
             SharePermissions(logger, shareName, domain, user, WindowsShare.AccessMaskTypes.FullControl);
         }
         TestReadWriteAccessToShare(logger, new UncPath(new ServerName(Environment.MachineName), shareName));
     }
     catch (Exception ex)
     {
         throw new ShareException("Error sharing folders.", ex);
     }
 }
 public static void CreateLocalShareDirectoryIfNotExistingAndGiveAuthenticatedUsersAccess(ILogger logger, DirectoryPath directoryPath, ShareName shareName)
 {
     CreateLocalShareDirectoryIfNotExisting(logger, directoryPath, shareName, "NT Authority", "Authenticated Users");
 }
 public static void CreateLocalShareDirectoryIfNotExistingAndGiveEveryoneAccess(ILogger logger, DirectoryPath directoryPath, ShareName shareName)
 {
     CreateLocalShareDirectoryIfNotExisting(logger, directoryPath, shareName, "NT Authority", "Everyone");
 }