コード例 #1
0
ファイル: TestConnect.cs プロジェクト: mallickhruday/MyDemos
 private void btnConnect_Click(object sender, EventArgs e)
 {
     this.Cursor = Cursors.WaitCursor;
     Application.DoEvents();
     string[] dirs;
     using (UNCAccessWithCredentials unc = new UNCAccessWithCredentials())
     {
         if (unc.NetUseWithCredentials(tbUNCPath.Text,
                                       tbUserName.Text,
                                       tbDomain.Text,
                                       tbPassword.Text))
         {
             dirs = Directory.GetDirectories(tbUNCPath.Text);
             foreach (string d in dirs)
             {
                 tbDirList.Text += d + "\r\n";
             }
         }
         else
         {
             this.Cursor = Cursors.Default;
             MessageBox.Show("Failed to connect to " + tbUNCPath.Text + "\r\nLastError = " + unc.LastError.ToString(),
                             "Failed to connect",
                             MessageBoxButtons.OK,
                             MessageBoxIcon.Error);
         }
     }
     this.Cursor = Cursors.Default;
 }
コード例 #2
0
ファイル: TestConnect.cs プロジェクト: ittray/LocalDemo
        private void btnConnect_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            Application.DoEvents();
            string[] dirs;
            using (UNCAccessWithCredentials unc = new UNCAccessWithCredentials())
            {
                if (unc.NetUseWithCredentials(tbUNCPath.Text,
                                              tbUserName.Text,
                                              tbDomain.Text,
                                              tbPassword.Text))
                {
                    dirs = Directory.GetDirectories(tbUNCPath.Text);
                    foreach (string d in dirs)
                    {
                        tbDirList.Text += d + "\r\n";
                    }
                }
                else
                {
                    this.Cursor = Cursors.Default;
                    MessageBox.Show("Failed to connect to " + tbUNCPath.Text + "\r\nLastError = " + unc.LastError.ToString(),
                                    "Failed to connect",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }

            }
            this.Cursor = Cursors.Default;
        }
コード例 #3
0
ファイル: Global.cs プロジェクト: cdadmin/clonedeploy
        public FileInfo[] GetMunkiResources(string type)
        {
            FileInfo[] directoryFiles = null;
            string pkgInfoFiles = Settings.MunkiBasePath + Path.DirectorySeparatorChar + type + Path.DirectorySeparatorChar;
            if (Settings.MunkiPathType == "Local")
            {
                DirectoryInfo di = new DirectoryInfo(pkgInfoFiles);
                try
                {
                    directoryFiles = di.GetFiles("*.*");
                }
                catch (Exception ex)
                {
                    Logger.Log(ex.Message);

                }
            }

            else
            {
                using (UNCAccessWithCredentials unc = new UNCAccessWithCredentials())
                {
                    var smbPassword = new Helpers.Encryption().DecryptText(Settings.MunkiSMBPassword);
                    var smbDomain = string.IsNullOrEmpty(Settings.MunkiSMBDomain) ? "" : Settings.MunkiSMBDomain;
                    if (unc.NetUseWithCredentials(Settings.MunkiBasePath, Settings.MunkiSMBUsername, smbDomain, smbPassword) || unc.LastError == 1219)
                    {

                        DirectoryInfo di = new DirectoryInfo(pkgInfoFiles);
                        try
                        {
                            directoryFiles = di.GetFiles("*.*");
                        }
                        catch (Exception ex)
                        {
                            Logger.Log(ex.Message);

                        }
                    }
                    else
                    {
                        Logger.Log("Failed to connect to " + Settings.MunkiBasePath + "\r\nLastError = " + unc.LastError);
                    }
                }
            }

            return directoryFiles;
        }
コード例 #4
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            Application.DoEvents();
            string[] dirs;
            using (UNCAccessWithCredentials unc = new UNCAccessWithCredentials())
            {
                if (unc.NetUseWithCredentials(tbUNCPath.Text,
                                              tbUserName.Text,
                                              tbDomain.Text,
                                              tbPassword.Text))
                {
                    //int fileCount = 0;
                    dirs = Directory.GetDirectories(tbUNCPath.Text);
                    string[] files = Directory.GetFiles(tbUNCPath.Text, "*", SearchOption.AllDirectories);
                    tbDirList.Text += "File Count: " + files.Length.ToString();
                    foreach (string s in files)
                        tbDirList.Text += "\n File Path: " + s;

                    //foreach (string d in dirs)
                    //{
                    //    Directory.GetFiles(d);
                    //    tbDirList.Text += d + "\r\n";
                    //}
                }
                else
                {
                    this.Cursor = Cursors.Default;
                    MessageBox.Show("Failed to connect to " + tbUNCPath.Text + "\r\nLastError = " + unc.LastError.ToString(),
                                    "Failed to connect",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }

            }
            this.Cursor = Cursors.Default;
        }
コード例 #5
0
        public int Apply(int templateId)
        {
            var errorCount = 0;
            string basePath = Settings.MunkiBasePath + Path.DirectorySeparatorChar + "manifests" + Path.DirectorySeparatorChar;

            var groups = BLL.GroupMunki.GetGroupsForManifestTemplate(templateId);
            if (Settings.MunkiPathType == "Local")
            {
                foreach (var munkiGroup in groups)
                {
                    var effectiveManifest = new BLL.Workflows.EffectiveMunkiTemplate().Group(munkiGroup.GroupId);
                    var computersInGroup = BLL.Group.GetGroupMembers(munkiGroup.GroupId);
                    foreach (var computer in computersInGroup)
                    {
                        if (!WritePath(basePath + computer.Name, Encoding.UTF8.GetString(effectiveManifest.ToArray())))
                            errorCount++;
                    }
                }
            }
            else
            {
                using (UNCAccessWithCredentials unc = new UNCAccessWithCredentials())
                {
                    var smbPassword = new Helpers.Encryption().DecryptText(Settings.MunkiSMBPassword);
                    var smbDomain = string.IsNullOrEmpty(Settings.MunkiSMBDomain) ? "" : Settings.MunkiSMBDomain;
                    if (unc.NetUseWithCredentials(Settings.MunkiBasePath, Settings.MunkiSMBUsername, smbDomain, smbPassword) || unc.LastError == 1219)
                    {
                        foreach (var munkiGroup in groups)
                        {
                            var effectiveManifest = new BLL.Workflows.EffectiveMunkiTemplate().Group(munkiGroup.GroupId);
                            var computersInGroup = BLL.Group.GetGroupMembers(munkiGroup.GroupId);
                            foreach (var computer in computersInGroup)
                            {
                                if (!WritePath(basePath + computer.Name, Encoding.UTF8.GetString(effectiveManifest.ToArray())))
                                    errorCount++;
                            }
                        }
                    }
                    else
                    {
                        Logger.Log("Failed to connect to " + Settings.MunkiBasePath + "\r\nLastError = " + unc.LastError);
                        foreach (var munkiGroup in groups)
                        {
                            var computersInGroup = BLL.Group.GetGroupMembers(munkiGroup.GroupId);
                            errorCount += computersInGroup.Count();
                        }
                    }
                }
            }
            var computers = BLL.ComputerMunki.GetComputersForManifestTemplate(templateId);
            if (Settings.MunkiPathType == "Local")
            {
                foreach (var munkiComputer in computers)
                {
                    var effectiveManifest = new BLL.Workflows.EffectiveMunkiTemplate().Computer(munkiComputer.ComputerId);
                    var computer = BLL.Computer.GetComputer(munkiComputer.ComputerId);
                    if (!WritePath(basePath + computer.Name, Encoding.UTF8.GetString(effectiveManifest.ToArray())))
                        errorCount++;
                }
            }
            else
            {
                using (UNCAccessWithCredentials unc = new UNCAccessWithCredentials())
                {
                    var smbPassword = new Helpers.Encryption().DecryptText(Settings.MunkiSMBPassword);
                    var smbDomain = string.IsNullOrEmpty(Settings.MunkiSMBDomain) ? "" : Settings.MunkiSMBDomain;
                    if (
                        unc.NetUseWithCredentials(Settings.MunkiBasePath, Settings.MunkiSMBUsername, smbDomain,
                            smbPassword) || unc.LastError == 1219)
                    {
                        foreach (var munkiComputer in computers)
                        {
                            var effectiveManifest =
                                new BLL.Workflows.EffectiveMunkiTemplate().Computer(munkiComputer.ComputerId);
                            var computer = BLL.Computer.GetComputer(munkiComputer.ComputerId);

                            if (
                                !WritePath(basePath + computer.Name,
                                    Encoding.UTF8.GetString(effectiveManifest.ToArray())))
                                errorCount++;
                        }
                    }
                    else
                    {
                        Logger.Log("Failed to connect to " + Settings.MunkiBasePath + "\r\nLastError = " +
                                   unc.LastError);
                        errorCount += computers.Count();
                    }
                }
            }

            if (errorCount > 0)
                return errorCount;

            var includedTemplates = new List<Models.MunkiManifestTemplate>();
            foreach (var munkiGroup in groups)
            {
                foreach (var template in BLL.GroupMunki.Get(munkiGroup.GroupId))
                {
                    includedTemplates.Add(BLL.MunkiManifestTemplate.GetManifest(template.MunkiTemplateId));
                }
            }

            foreach (var computer in computers)
            {
                foreach (var template in BLL.ComputerMunki.Get(computer.ComputerId))
                {
                    includedTemplates.Add(BLL.MunkiManifestTemplate.GetManifest(template.MunkiTemplateId));
                }
            }

            foreach (var template in includedTemplates)
            {
                template.ChangesApplied = 1;
                BLL.MunkiManifestTemplate.UpdateManifest(template);
            }

            return 0;
        }