Esempio n. 1
0
        public void InstallUtilTest()
        {
            Console.WriteLine("Integration testing InstallUtil by installing current test assembly '{0}' which contains installer class '{1}'", typeof(InstallUtilTests).Assembly.Location, typeof(InstallerExample).FullName);
            var target = new InstallUtil(_stubLoggingConfiguration, _folderFileSearcher, _logger);

            if (_assemblyFileInfo.Directory == null)
            {
                throw new ArgumentNullException();
            }
            Assert.AreEqual(1, _folderFileSearcher.GetFiles(_assemblyFileInfo.Directory.FullName, _includeFileSpecification).Count, "Number of assemblies to be processed by InstallUtil should be 1.");
            Assert.AreEqual(0, _folderFileSearcher.GetFiles(_assemblyFileInfo.Directory.FullName, _excludeFileSpecifications).Count, "Number of assemblies to be excluded by InstallUtil should be 0.");

            Assert.IsFalse(File.Exists(InstallerExample.InstalledFile), "'Installed' exists when it should not: " + InstallerExample.InstalledFile);
            Assert.IsFalse(File.Exists(InstallerExample.UnInstalledFile), "'UnInstalled' exists when it should not: " + InstallerExample.UnInstalledFile);

            target.Execute(InstallAction.Install, _assemblyFileInfo.Directory.FullName, _includeFileSpecification, _excludeFileSpecifications);
            Assert.IsTrue(File.Exists(InstallerExample.InstalledFile), "'Installed' file does not exist: " + InstallerExample.InstalledFile);
            Assert.IsFalse(File.Exists(InstallerExample.UnInstalledFile), "'UnInstalled' exists when it should not: " + InstallerExample.UnInstalledFile);

            target.Execute(InstallAction.UnInstall, _assemblyFileInfo.Directory.FullName, _includeFileSpecification, _excludeFileSpecifications);
            Assert.IsTrue(File.Exists(InstallerExample.UnInstalledFile), "'UnInstalled' file does not exist: " + InstallerExample.UnInstalledFile);
            Assert.IsFalse(File.Exists(InstallerExample.InstalledFile), "'Installed' exists when it should not: " + InstallerExample.InstalledFile);

            target.Execute(InstallAction.UnInstallInstall, _assemblyFileInfo.Directory.FullName, _includeFileSpecification, _excludeFileSpecifications);
            Assert.IsTrue(File.Exists(InstallerExample.InstalledFile), "'Installed' file does not exist: " + InstallerExample.InstalledFile);
            Assert.IsFalse(File.Exists(InstallerExample.UnInstalledFile), "'UnInstalled' exists when it should not: " + InstallerExample.UnInstalledFile);

            target.Execute(InstallAction.UnInstall, _assemblyFileInfo.Directory.FullName, _includeFileSpecification, _excludeFileSpecifications);
            Assert.IsTrue(File.Exists(InstallerExample.UnInstalledFile), "'UnInstalled' file does not exist: " + InstallerExample.UnInstalledFile);
            Assert.IsFalse(File.Exists(InstallerExample.InstalledFile), "'Installed' exists when it should not: " + InstallerExample.InstalledFile);
        }
Esempio n. 2
0
        /// <summary>
        /// Patches the directory access rights for the specified directory to allow full access for network service.
        /// </summary>
        /// <param name="directoryPath">The directory path to patch.</param>
        private static void PatchDirectoryAccessRights(string directoryPath)
        {
            // directory access rights patching is only used for Windows Vista or higher

            if (System.Environment.OSVersion.Version.Major > 5)
            {
                var accessRuleSvc = new FileSystemAccessRule(InstallUtil.GetNetworkServiceName(),
                                                             FileSystemRights.FullControl,
                                                             InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
                                                             PropagationFlags.None,
                                                             AccessControlType.Allow);

                var accessRuleUsr = new FileSystemAccessRule(System.Environment.UserName,
                                                             FileSystemRights.FullControl,
                                                             InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
                                                             PropagationFlags.None,
                                                             AccessControlType.Allow);

                var directoryInfo     = new DirectoryInfo(directoryPath);
                var directorySecurity = directoryInfo.GetAccessControl();

                directorySecurity.AddAccessRule(accessRuleSvc);
                directorySecurity.AddAccessRule(accessRuleUsr);
                directoryInfo.SetAccessControl(directorySecurity);
            }
        }
Esempio n. 3
0
        private async void MainWindow_LoadedAsync(object sender, RoutedEventArgs e)
        {
            versionTextBlock.Text = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();

            await Task.Run(() =>
            {
                InstallUtil.Install();
                if (!DataService.ImportData())
                {
                    MessageBox.Show("Данните не могат да бъдат разчетени!", "Cannot Import Data",
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                    Environment.Exit(0);
                }
                if (!DataService.ReadData())
                {
                    MessageBox.Show("Не е поставена флашка или няма данни на нея!", "No Data",
                                    MessageBoxButton.OK, MessageBoxImage.Warning);
                }
                if (!DataService.ExportData())
                {
                    MessageBox.Show("Данните не могат да бъдат записани!", "No Data",
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                }
            });

            loadingTextBlock.Visibility = Visibility.Collapsed;
            tabControl.Visibility       = Visibility.Visible;

            minIndex = DataService.Times
                       .Where(t => t <= DataService.Times.Last().Subtract(TimeSpan.FromDays(7))).Count();
            countElements = DataService.Times.Count - minIndex;

            InitializeControls();

            var timer = new DispatcherTimer()
            {
                Interval = TimeSpan.FromMilliseconds(200)
            };

            timer.Tick += Timer_Tick;
            timer.Start();
        }