Пример #1
0
        //Sets the drive selected and the current path
        public void SetBasePath(string sPath)
        {
            //Chech if we have a # in the name, if so, extract the username and passwords
            string sUNCUsername = "";
            string SUNCPassword = "";
            string sUNCDomain   = "";

            if (sPath.IndexOf('#') != -1)
            {
                string[] sItems = sPath.Split('#');
                sPath        = sItems[0];
                sUNCUsername = sItems[1]; //Later on add the domain feature
                SUNCPassword = sItems[2];
            }

            //If the path does not exists a \, then it is a network connection
            if (sPath.IndexOf('\\') == -1)
            {
                sPath = @"\\" + sPath + @"\";
                pUNC.NetUseDelete();
            }

            //Now connect to the networkdrive
            if (sPath.IndexOf(@"\\") != -1)
            {
                bool bLoggedIn = false;
                if (sUNCUsername.Length > 0)
                {
                    bLoggedIn = pUNC.login(sPath + @"IPC$\", sUNCUsername, sUNCDomain, SUNCPassword);
                }
                else
                {
                    bLoggedIn = pUNC.login(sPath, sUNCUsername, sUNCDomain, SUNCPassword);
                }

                if (!bLoggedIn)
                {
                    SetErrorString(@"Could not log into " + sPath + " using username " + sUNCUsername);
                }
            }

            sDriveSelected = sPath;
            sCurrentPath   = sPath;
        }
Пример #2
0
        private void ConnectToUNC(BasePathsDb baseDb)
        {
            //Path is \\<server>@<username>:<password>\rest\of\the\path

            //             Regex x = new Regex(@"\\\\(?<server>.*?)@(?<user>.*?):(?<pass>.*?)\\(?<path>.*?)$", RegexOptions.IgnoreCase);
            //             MatchCollection mc = x.Matches(aBasePath.sBasePath);
            //
            //             if (mc.Count != 0)
            //             {
            //                 string sServer = mc[0].Groups["server"].Value;
            //                 string sUser = mc[0].Groups["user"].Value;
            //                 string sPassword = mc[0].Groups["pass"].Value;
            //                 string sPath = mc[0].Groups["path"].Value;
            //                 aBasePath.sBasePath = @"\\" + sServer + @"\" + sPath;


            //Create a UNC connector
            UNCAccess pUNC = new UNCAccess(); //to be added in array based on ID

            //Fire up a task to connect
            var bgw = new BackgroundWorker();

            bgw.DoWork += (_, __) =>
            {
                if (!pUNC.login(baseDb.BasePath, baseDb.Username, "", baseDb.Password))
                {
                    Console.WriteLine("Could not connect to: " + baseDb.BasePath);
                }
            };
            bgw.RunWorkerCompleted += (_, __) =>
            {
                Console.WriteLine("Finished connecting to UNC: " + baseDb.BasePath);
            };
            bgw.RunWorkerAsync();

            //Add the entry to the list of UNCs
            BasePathsUNC sUNC = new BasePathsUNC
            {
                pUNC = pUNC,
                Id   = baseDb.Id
            };

            aUNCConnections.Add(sUNC);
        }