Пример #1
0
        public static FileSystemShare InitializeShare(ShareSettings shareSettings)
        {
            string          shareName   = shareSettings.ShareName;
            string          sharePath   = shareSettings.SharePath;
            List <string>   readAccess  = shareSettings.ReadAccess;
            List <string>   writeAccess = shareSettings.WriteAccess;
            FileSystemShare share       = new FileSystemShare(shareName, new NTDirectoryFileSystem(sharePath));

            share.AccessRequested += delegate(object sender, AccessRequestArgs args)
            {
                bool hasReadAccess  = Contains(readAccess, "Users") || Contains(readAccess, args.UserName);
                bool hasWriteAccess = Contains(writeAccess, "Users") || Contains(writeAccess, args.UserName);
                if (args.RequestedAccess == FileAccess.Read)
                {
                    args.Allow = hasReadAccess;
                }
                else if (args.RequestedAccess == FileAccess.Write)
                {
                    args.Allow = hasWriteAccess;
                }
                else // FileAccess.ReadWrite
                {
                    args.Allow = hasReadAccess && hasWriteAccess;
                }
            };
            return(share);
        }
Пример #2
0
        public static List <ShareSettings> ReadSharesSettings()
        {
            List <ShareSettings> shares   = new List <ShareSettings>();
            XmlDocument          document = ReadSettingsXML();
            XmlNode sharesNode            = document.SelectSingleNode("Settings/Shares");

            foreach (XmlNode shareNode in sharesNode.ChildNodes)
            {
                string shareName = shareNode.Attributes["Name"].Value;
                string sharePath = shareNode.Attributes["Path"].Value;

                XmlNode       readAccessNode  = shareNode.SelectSingleNode("ReadAccess");
                List <string> readAccess      = ReadAccessList(readAccessNode);
                XmlNode       writeAccessNode = shareNode.SelectSingleNode("WriteAccess");
                List <string> writeAccess     = ReadAccessList(writeAccessNode);
                ShareSettings share           = new ShareSettings(shareName, sharePath, readAccess, writeAccess);
                shares.Add(share);
            }
            return(shares);
        }