Exemplo n.º 1
0
        public void Deploy_Check_Delete_Check()
        {
            var fileSystem   = new RealFileSystem();
            var databaseName = GetRandomDatabaseName();
            var dacpac       = fileSystem.ParseFile("SqlAdapter_Database.dacpac");

            Assert.AreEqual(true, dacpac.Exists);

            int count;

            try
            {
                Adapter.DeployDatabase(databaseName, dacpac);
                Assert.AreEqual(true, Adapter.DatabaseExists(databaseName));
                Assert.AreEqual(true, !string.IsNullOrEmpty(Adapter.GetDatabaseFilePath(databaseName)));

                var databases = Adapter.GetDatabases();
                Assert.AreEqual(true, databases.Contains(databaseName));

                count = databases.Count;
                Assert.AreEqual(true, count >= 1);
            }
            finally
            {
                Adapter.DeleteDatabase(databaseName);
            }

            Assert.AreEqual(false, Adapter.DatabaseExists(databaseName));

            var newCount = Adapter.GetDatabases().Count;

            Assert.AreEqual(count - 1, newCount);
        }
Exemplo n.º 2
0
        private static void ComposeDependencies(ref IConsoleManager consoleManager, ref IPreferences preferences, out HttpState state, out Shell shell)
        {
            consoleManager = consoleManager ?? new ConsoleManager();
            IFileSystem fileSystem = new RealFileSystem();

            preferences = preferences ?? new UserFolderPreferences(fileSystem, new UserProfileDirectoryProvider(), CreateDefaultPreferences());
            var httpClient = GetHttpClientWithPreferences(preferences);

            state = new HttpState(fileSystem, preferences, httpClient);

            var dispatcher = DefaultCommandDispatcher.Create(state.GetPrompt, state);

            dispatcher.AddCommand(new ChangeDirectoryCommand());
            dispatcher.AddCommand(new ClearCommand());
            dispatcher.AddCommand(new ConnectCommand(preferences));
            dispatcher.AddCommand(new DeleteCommand(fileSystem, preferences));
            dispatcher.AddCommand(new EchoCommand());
            dispatcher.AddCommand(new ExitCommand());
            dispatcher.AddCommand(new HeadCommand(fileSystem, preferences));
            dispatcher.AddCommand(new HelpCommand(preferences));
            dispatcher.AddCommand(new GetCommand(fileSystem, preferences));
            dispatcher.AddCommand(new ListCommand(preferences));
            dispatcher.AddCommand(new OptionsCommand(fileSystem, preferences));
            dispatcher.AddCommand(new PatchCommand(fileSystem, preferences));
            dispatcher.AddCommand(new PrefCommand(preferences));
            dispatcher.AddCommand(new PostCommand(fileSystem, preferences));
            dispatcher.AddCommand(new PutCommand(fileSystem, preferences));
            dispatcher.AddCommand(new RunCommand(fileSystem));
            dispatcher.AddCommand(new SetBaseCommand());
            dispatcher.AddCommand(new SetHeaderCommand());
            dispatcher.AddCommand(new UICommand(new UriLauncher(), preferences));

            shell = new Shell(dispatcher, consoleManager: consoleManager);
        }
Exemplo n.º 3
0
        private static void ComposeDependencies(ref IConsoleManager consoleManager, ref IPreferences preferences, ref ITelemetry telemetry, out HttpState state, out Shell shell)
        {
            consoleManager ??= new ConsoleManager();
            IFileSystem fileSystem = new RealFileSystem();

            preferences ??= new UserFolderPreferences(fileSystem, new UserProfileDirectoryProvider(), CreateDefaultPreferences());
            telemetry ??= new Telemetry.Telemetry(VersionSensor.AssemblyInformationalVersion);
            HttpClient httpClient = GetHttpClientWithPreferences(preferences);

            state = new HttpState(preferences, httpClient);

            DefaultCommandDispatcher <HttpState> dispatcher = DefaultCommandDispatcher.Create(state.GetPrompt, state);

            dispatcher.AddCommandWithTelemetry(telemetry, new ChangeDirectoryCommand());
            dispatcher.AddCommandWithTelemetry(telemetry, new ClearCommand());
            dispatcher.AddCommandWithTelemetry(telemetry, new ConnectCommand(preferences, telemetry));
            dispatcher.AddCommandWithTelemetry(telemetry, new DeleteCommand(fileSystem, preferences, telemetry));
            dispatcher.AddCommandWithTelemetry(telemetry, new EchoCommand());
            dispatcher.AddCommandWithTelemetry(telemetry, new ExitCommand());
            dispatcher.AddCommandWithTelemetry(telemetry, new HeadCommand(fileSystem, preferences, telemetry));
            dispatcher.AddCommandWithTelemetry(telemetry, new HelpCommand());
            dispatcher.AddCommandWithTelemetry(telemetry, new GetCommand(fileSystem, preferences, telemetry));
            dispatcher.AddCommandWithTelemetry(telemetry, new ListCommand(preferences));
            dispatcher.AddCommandWithTelemetry(telemetry, new OptionsCommand(fileSystem, preferences, telemetry));
            dispatcher.AddCommandWithTelemetry(telemetry, new PatchCommand(fileSystem, preferences, telemetry));
            dispatcher.AddCommandWithTelemetry(telemetry, new PrefCommand(preferences, telemetry));
            dispatcher.AddCommandWithTelemetry(telemetry, new PostCommand(fileSystem, preferences, telemetry));
            dispatcher.AddCommandWithTelemetry(telemetry, new PutCommand(fileSystem, preferences, telemetry));
            dispatcher.AddCommandWithTelemetry(telemetry, new RunCommand(fileSystem));
            dispatcher.AddCommandWithTelemetry(telemetry, new SetHeaderCommand(telemetry));
            dispatcher.AddCommandWithTelemetry(telemetry, new UICommand(new UriLauncher(), preferences));

            shell = new Shell(dispatcher, consoleManager: consoleManager);
        }
Exemplo n.º 4
0
        public void GetTempFileName_WithValidInput_ReturnsFileInTempPath(string extension)
        {
            RealFileSystem realFileSystem = new RealFileSystem();
            string         expectedPath   = Path.GetTempPath();

            string actualPath = realFileSystem.GetTempFileName(extension);

            Assert.StartsWith(expectedPath, actualPath, StringComparison.OrdinalIgnoreCase);
        }
Exemplo n.º 5
0
        public void GetTempFileName_WithValidInput_ReturnsFileNameWithExtension(string extension)
        {
            RealFileSystem realFileSystem = new RealFileSystem();

            string fullName = realFileSystem.GetTempFileName(extension);

            Assert.NotNull(fullName);
            Assert.EndsWith(extension, fullName, StringComparison.OrdinalIgnoreCase);
        }
Exemplo n.º 6
0
        public void GetTempFileName_WithValidInput_ReturnsFileThatStartsWithHttpRepl(string extension)
        {
            RealFileSystem realFileSystem = new RealFileSystem();
            string         expectedStart  = "HttpRepl.";

            string fullName       = realFileSystem.GetTempFileName(extension);
            string actualFileName = Path.GetFileName(fullName);

            Assert.StartsWith(expectedStart, actualFileName, StringComparison.OrdinalIgnoreCase);
        }
        public void OnClick(Window mainWindow, Instance instance)
        {
            Assert.ArgumentNotNull(mainWindow, nameof(mainWindow));

            Analytics.TrackEvent("Import");

            var fileDialog = new OpenFileDialog
            {
                Title       = "Select zip file of exported solution",
                Multiselect = false,
                DefaultExt  = ".zip"
            };

            fileDialog.ShowDialog();
            var filePath = fileDialog.FileName;

            if (string.IsNullOrEmpty(filePath))
            {
                return;
            }

            Log.Info($"Importing solution from {filePath}");
            var fileSystem = new RealFileSystem();
            var file       = fileSystem.ParseFile(filePath);

            using (var zipFile = new RealZipFile(fileSystem.ParseFile(file.FullName)))
            {
                const string AppPoolFileName = "AppPoolSettings.xml";
                var          appPool         = zipFile.Entries.Contains(AppPoolFileName);
                if (!appPool)
                {
                    WindowHelper.ShowMessage("Wrong package for import. The package does not contain the {0} file.".FormatWith(AppPoolFileName));
                    return;
                }

                const string WebsiteSettingsFileName = "WebsiteSettings.xml";
                var          websiteSettings         = zipFile.Entries.Contains(WebsiteSettingsFileName);
                if (!websiteSettings)
                {
                    WindowHelper.ShowMessage("Wrong package for import. The package does not contain the {0} file.".FormatWith(WebsiteSettingsFileName));

                    return;
                }

                const string WebConfigFileName = @"Website/Web.config";
                if (!zipFile.Entries.Contains(WebConfigFileName))
                {
                    WindowHelper.ShowMessage("Wrong package for import. The package does not contain the {0} file.".FormatWith(WebConfigFileName));

                    return;
                }
            }

            WizardPipelineManager.Start("import", mainWindow, null, null, ignore => MainWindowHelper.SoftlyRefreshInstances(), () => new ImportWizardArgs(file.FullName));
        }
Exemplo n.º 8
0
        private void Setup(string commandText, out MockedShellState mockedShellState, out HttpState httpState, out ICoreParseResult parseResult)
        {
            mockedShellState = new MockedShellState();
            IFileSystem fileSystem = new RealFileSystem();
            IUserProfileDirectoryProvider userProfileDirectoryProvider = new UserProfileDirectoryProvider();
            IPreferences preferences = new UserFolderPreferences(fileSystem, userProfileDirectoryProvider, null);

            parseResult = CoreParseResultHelper.Create(commandText);
            HttpClient httpClient = new HttpClient();

            httpState = new HttpState(preferences, httpClient);
        }
 public DBConnector(string strConnectionString, DbConnectorSettings dbConnectorSettings, IMemoryCache cache, IHttpContextAccessor httpContextAccessor)
 {
     ThrowNotificationExceptions = true;
     ForceLocalCache             = false;
     UpdateManyToMany            = true;
     UpdateManyToOne             = true;
     CacheData = true;
     CustomConnectionString = strConnectionString;
     DbConnectorSettings    = dbConnectorSettings;
     CacheManager           = new DbCacheManager(this, cache);
     FileSystem             = new RealFileSystem();
     DynamicImageCreator    = new DynamicImageCreator(FileSystem);
     HttpContext            = httpContextAccessor?.HttpContext;
     WithTransaction        = true;
 }
        public DBConnector(string strConnectionString, DbConnectorSettings dbConnectorSettings, IMemoryCache cache)
        {
            if (!string.IsNullOrWhiteSpace(dbConnectorSettings.ConnectionString))
            {
                ConnectionString = dbConnectorSettings.ConnectionString;
            }

            ThrowNotificationExceptions = true;
            ForceLocalCache             = false;
            UpdateManyToMany            = true;
            UpdateManyToOne             = true;
            CacheData = true;
            CustomConnectionString = strConnectionString;
            DbConnectorSettings    = dbConnectorSettings;
            CacheManager           = new DbCacheManager(this, cache);
            FileSystem             = new RealFileSystem();
            DynamicImageCreator    = new DynamicImageCreator(FileSystem);
            WithTransaction        = true;
        }
        public DBConnector(string strConnectionString, DatabaseType dbType = DatabaseType.SqlServer)
        {
            ForceLocalCache             = false;
            CacheData                   = true;
            UpdateManyToMany            = true;
            UpdateManyToOne             = true;
            ThrowNotificationExceptions = true;

            CustomConnectionString = strConnectionString;
            DbConnectorSettings    = new DbConnectorSettings(ConfigurationManager.AppSettings)
            {
                ConnectionString = strConnectionString,
                DbType           = dbType
            };

            CacheManager        = new DbCacheManager(this);
            FileSystem          = new RealFileSystem();
            DynamicImageCreator = new DynamicImageCreator(FileSystem);
            WithTransaction     = true;
        }
Exemplo n.º 12
0
        public void GetTEmpFileName_WithInvalidInput_ThrowsArgumentException(string extension)
        {
            RealFileSystem realFileSystem = new RealFileSystem();

            Assert.Throws <ArgumentException>(() => realFileSystem.GetTempFileName(extension));
        }
Exemplo n.º 13
0
        public void GetTempFileName_WithNullExtension_ThrowsArgumentNullException()
        {
            RealFileSystem realFileSystem = new RealFileSystem();

            Assert.Throws <ArgumentNullException>(() => realFileSystem.GetTempFileName(null));
        }
Exemplo n.º 14
0
        static async Task Main(string[] args)
        {
            IFileSystem fileSystem = new RealFileSystem();
            HttpState   state      = new HttpState(fileSystem);

            if (Console.IsOutputRedirected)
            {
                Reporter.Error.WriteLine("Cannot start the REPL when output is being redirected".SetColor(state.ErrorColor));
                return;
            }

            var dispatcher = DefaultCommandDispatcher.Create(state.GetPrompt, state);

            dispatcher.AddCommand(new ChangeDirectoryCommand());
            dispatcher.AddCommand(new ClearCommand());
            //dispatcher.AddCommand(new ConfigCommand());
            dispatcher.AddCommand(new DeleteCommand(fileSystem));
            dispatcher.AddCommand(new EchoCommand());
            dispatcher.AddCommand(new ExitCommand());
            dispatcher.AddCommand(new HeadCommand(fileSystem));
            dispatcher.AddCommand(new HelpCommand());
            dispatcher.AddCommand(new GetCommand(fileSystem));
            dispatcher.AddCommand(new ListCommand());
            dispatcher.AddCommand(new OptionsCommand(fileSystem));
            dispatcher.AddCommand(new PatchCommand(fileSystem));
            dispatcher.AddCommand(new PrefCommand());
            dispatcher.AddCommand(new PostCommand(fileSystem));
            dispatcher.AddCommand(new PutCommand(fileSystem));
            dispatcher.AddCommand(new RunCommand(fileSystem));
            dispatcher.AddCommand(new SetBaseCommand());
            dispatcher.AddCommand(new SetDiagCommand());
            dispatcher.AddCommand(new SetHeaderCommand());
            dispatcher.AddCommand(new SetSwaggerCommand());
            dispatcher.AddCommand(new UICommand());

            CancellationTokenSource source = new CancellationTokenSource();
            Shell shell = new Shell(dispatcher);

            shell.ShellState.ConsoleManager.AddBreakHandler(() => source.Cancel());
            if (args.Length > 0)
            {
                if (string.Equals(args[0], "--help", StringComparison.OrdinalIgnoreCase) || string.Equals(args[0], "-h", StringComparison.OrdinalIgnoreCase))
                {
                    shell.ShellState.ConsoleManager.WriteLine("Usage: dotnet httprepl [<BASE_ADDRESS>] [options]");
                    shell.ShellState.ConsoleManager.WriteLine();
                    shell.ShellState.ConsoleManager.WriteLine("Arguments:");
                    shell.ShellState.ConsoleManager.WriteLine("  <BASE_ADDRESS> - The initial base address for the REPL.");
                    shell.ShellState.ConsoleManager.WriteLine();
                    shell.ShellState.ConsoleManager.WriteLine("Options:");
                    shell.ShellState.ConsoleManager.WriteLine("  --help - Show help information.");

                    shell.ShellState.ConsoleManager.WriteLine();
                    shell.ShellState.ConsoleManager.WriteLine("REPL Commands:");
                    new HelpCommand().CoreGetHelp(shell.ShellState, (ICommandDispatcher <HttpState, ICoreParseResult>)shell.ShellState.CommandDispatcher, state);
                    return;
                }

                shell.ShellState.CommandDispatcher.OnReady(shell.ShellState);
                shell.ShellState.InputManager.SetInput(shell.ShellState, $"set base \"{args[0]}\"");
                await shell.ShellState.CommandDispatcher.ExecuteCommandAsync(shell.ShellState, CancellationToken.None).ConfigureAwait(false);
            }
            Task result = shell.RunAsync(source.Token);
            await result.ConfigureAwait(false);
        }
Exemplo n.º 15
0
        public bool CheckResources(GraphicsDevice device, IProgressReceiver progressReceiver, McResourcePack.McResourcePackPreloadCallback preloadCallback)
        {
            LoadHWID();

            PreloadCallback = preloadCallback;

            Log.Info($"Loading registries...");
            progressReceiver?.UpdateProgress(0, "Loading registries...");
            Registries = JsonConvert.DeserializeObject <Registries>(ReadStringResource("Alex.Resources.registries.json"));
            progressReceiver?.UpdateProgress(100, "Loading registries...");

            string defaultResources;
            string defaultBedrock;

            if (!CheckJavaAssets(progressReceiver, out defaultResources))
            {
                return(false);
            }

            if (!CheckBedrockAssets(progressReceiver, out defaultBedrock))
            {
                return(false);
            }

            progressReceiver?.UpdateProgress(0, "Loading vanilla resources...");

            var vanilla = LoadResourcePack(progressReceiver, new RealFileSystem(defaultResources), preloadCallback);

            vanilla.Manifest.Name = "Vanilla";

            ActiveResourcePacks.AddFirst(vanilla);

            Alex.AudioEngine.Initialize(vanilla);

            // Log.Info($"Loading bedrock resources...");

            progressReceiver?.UpdateProgress(0, "Loading bedrock resources...");

            using (RealFileSystem fileSystem = new RealFileSystem(defaultBedrock))
            {
                BedrockResourcePack = new BedrockResourcePack(
                    fileSystem, (percentage, file) => { progressReceiver?.UpdateProgress(percentage, null, file); });

                int modelCount = EntityFactory.LoadModels(BedrockResourcePack, device, true, progressReceiver);

                Log.Info($"Imported {modelCount} entity models...");
            }

            //Log.Info($"Loading known entity data...");
            EntityFactory.Load(this, progressReceiver);

            Storage.TryGetDirectory(Path.Combine("assets", "resourcepacks"), out DirectoryInfo root);
            ResourcePackDirectory = root;

            LoadRegistries(progressReceiver);

            LoadResourcePacks(
                device, progressReceiver, Options.AlexOptions.ResourceOptions.LoadedResourcesPacks.Value);

            ItemFactory.Init(RegistryManager, this, ResourcePack, progressReceiver);

            BlockEntityFactory.LoadResources(device, ResourcePack);

            if (Storage.TryGetDirectory(Path.Combine("assets", "bedrockpacks"), out DirectoryInfo info))
            {
                SkinPackDirectory = info;
                LoadBedrockPacks(progressReceiver, info);
            }
            else
            {
                if (Storage.TryCreateDirectory(Path.Combine("assets", "bedrockpacks")))
                {
                    if (Storage.TryGetDirectory(Path.Combine("assets", "bedrockpacks"), out var dirInfo))
                    {
                        SkinPackDirectory = dirInfo;
                    }
                }
            }

            BlockMapper.Init(progressReceiver);

            Options.AlexOptions.ResourceOptions.LoadedResourcesPacks.Bind(ResourcePacksChanged);
            _hasInit = true;

            return(true);
        }
Exemplo n.º 16
0
        private void LoadGameDirectory(KeyUtil keyUtil, string gameName)
        {
            using (new WaitCursor(this))
            {
                FileSystem fs = new RealFileSystem();

                string gamePath = keyUtil.FindGameDirectory();
                while (gamePath == null)
                {
                    var fbd = new VistaFolderBrowserDialog
                    {
                        Description =
                            "Could not find the " + gameName + " game directory. Please select the directory containing " + keyUtil.ExecutableName,
                        ShowNewFolderButton = false
                    };

                    if (fbd.ShowDialog() == DialogResult.Cancel)
                    {
                        MessageBox.Show(
                            keyUtil.ExecutableName +
                            " is required to extract cryptographic keys for this program to function. " +
                            "SparkIV can not run without this file.", "Error", MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                        return;
                    }
                    if (System.IO.File.Exists(Path.Combine(fbd.SelectedPath, keyUtil.ExecutableName)))
                    {
                        gamePath = fbd.SelectedPath;
                    }
                }

                byte[] key = keyUtil.FindKey(gamePath);

                if (key == null)
                {
                    string message = "Your " + keyUtil.ExecutableName + " seems to be modified or is a newer version than this tool supports. " +
                                     "SparkIV can not run without a supported " + keyUtil.ExecutableName + " file." + "\n" + "Would you like to check for updates?";
                    string caption = "Newer or Modified " + keyUtil.ExecutableName;

                    if (MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes)
                    {
                        Updater.CheckForUpdate();
                    }

                    return;
                }


                KeyStore.SetKeyLoader(() => key);

                fs.Open(gamePath);

                if (_fs != null)
                {
                    _fs.Close();
                }
                _fs = fs;

                Text = Application.ProductName + " - Browse Game Directory";

                PopulateUI();
            }
        }
Exemplo n.º 17
0
        public void OpenFile(string filename, FileSystem fs)
        {
            if (fs == null)
            {
                if (filename.EndsWith(".rpf"))
                {
                    fs = new RPFFileSystem();
                }
                else if (filename.EndsWith(".img"))
                {
                    fs = new IMGFileSystem();
                }
                else if (IODirectory.Exists(filename))
                {
                    fs       = new RealFileSystem();
                    filename = (new DirectoryInfo(filename)).FullName;
                }
            }

            if (fs != null)
            {
                if (IOFile.Exists(filename))
                {
                    FileInfo fi = new FileInfo(filename);
                    if ((fi.Attributes & FileAttributes.ReadOnly) != 0)
                    {
                        DialogResult result =
                            MessageBox.Show("The file you are trying to open appears to be read-only. " +
                                            "Would you like to make it writable before opening this file?",
                                            "Open", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                        if (result == DialogResult.Yes)
                        {
                            fi.Attributes = fi.Attributes & ~FileAttributes.ReadOnly;
                        }
                    }
                }

                try
                {
                    using (new WaitCursor(this))
                    {
                        fs.Open(filename);

                        if (_fs != null)
                        {
                            _fs.Close();
                        }
                        _fs = fs;

                        Text = Application.ProductName + " - " + new FileInfo(filename).Name;
                    }

                    PopulateUI();
                }
                catch (Exception ex)
                {
                    fs.Close();
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Exemplo n.º 18
0
        static int DoWork(RunOptions opts)
        {
            var rulesText = opts.RulesFile == "-" ? Console.In.ReadToEnd() : File.ReadAllText(opts.RulesFile);

            var ruleSet = RuleSet.Parse(rulesText);

            if (opts.DryRun)
            {
                opts.Log.WriteLine("== DRY RUN ==");

                // load all files from source and destination
                var allFiles = Directory.GetFiles(opts.SourceRoot, "*", SearchOption.AllDirectories)
                               .Concat(Directory.GetFiles(opts.DestinationRoot, "*", SearchOption.AllDirectories))
                ;

                var fs = new TextFileSystem(allFiles);
                fs.Force = opts.Force;

                var copyMachine = new CopyMachine(fs, opts.SourceRoot, opts.DestinationRoot, Console.Error, opts.Log);
                var result      = copyMachine.Copy(ruleSet);

                opts.Log.WriteLine("== DRY RUN RESULTS ==");

                if (fs.CreatedDirectories.Count > 0)
                {
                    opts.Log.WriteLine("Created directories:");
                    foreach (var dir in fs.CreatedDirectories.OrderBy(x => x))
                    {
                        opts.Log.WriteLine("\t" + dir);
                    }
                }

                if (fs.CopiedFiles.Count > 0)
                {
                    opts.Log.WriteLine("Copied files:");
                    foreach (var file in fs.CopiedFiles.OrderBy(x => x))
                    {
                        opts.Log.WriteLine("\t" + file);
                    }
                }

                if (fs.CopiedOverFiles.Count > 0)
                {
                    opts.Log.WriteLine("Copied with overwite files:");
                    foreach (var file in fs.CopiedOverFiles.OrderBy(x => x))
                    {
                        opts.Log.WriteLine("\t" + file);
                    }
                }

                return(result);
            }
            else
            {
                // usual run
                var fs = new RealFileSystem();
                fs.Force = opts.Force;

                var copyMachine = new CopyMachine(fs, opts.SourceRoot, opts.DestinationRoot, Console.Error, opts.Log);
                var result      = copyMachine.Copy(ruleSet);

                if (opts.Summary)
                {
                    Console.WriteLine($"{copyMachine.FilesCopied} files copied");
                    Console.WriteLine($"Exit code: {result}");
                }

                return(result);
            }
        }