public async Task <Operation> ImportAsync(DatabaseSmugglerImportOptions options, Stream stream, CancellationToken token = default) { if (options == null) { throw new ArgumentNullException(nameof(options)); } if (stream == null) { throw new ArgumentNullException(nameof(stream)); } if (_requestExecutor == null) { throw new InvalidOperationException("Cannot use Smuggler without a database defined, did you forget to call ForDatabase?"); } using (_requestExecutor.ContextPool.AllocateOperationContext(out JsonOperationContext context)) { var getOperationIdCommand = new GetNextOperationIdCommand(); await _requestExecutor.ExecuteAsync(getOperationIdCommand, context, sessionInfo : null, token : token).ConfigureAwait(false); var operationId = getOperationIdCommand.Result; var command = new ImportCommand(_requestExecutor.Conventions, context, options, stream, operationId); await _requestExecutor.ExecuteAsync(command, context, sessionInfo : null, token : token).ConfigureAwait(false); return(new Operation(_requestExecutor, () => _store.Changes(_databaseName), _requestExecutor.Conventions, operationId)); } }
public async Task <ImportExecutionImpact> ExecuteImport(ImportCommand importCommand, Stream sourceData) { var result = new ImportExecutionImpact { CommandId = importCommand.Id }; try { var filteredData = await ReadAndFilterNewImportDataOnly(importCommand, sourceData); result.NotCompliant = filteredData.NotCompliant; result.AlreadyKnown = filteredData.AlreadyKnown; result.NewOperations = filteredData.NewOperations.Length; if (filteredData.NewOperations.Length > 0) { // Merge new operations with existing operations var newOperations = filteredData.NewOperations; var operationsFiles = GetFilePaths(importCommand.AccountId, newOperations); var existingOperations = await ReadOperations(operationsFiles); var operationsToWrite = existingOperations.Concat(newOperations).ToList(); await WriteOperations(importCommand.AccountId, operationsToWrite); } } catch (Exception exn) { result.Error = exn.Message; _logger.Error("import failed", exn); } return(result); }
public void ConfigImport_Execute_ReturnsSuccess() { var content = new Dictionary <string, string> { { "config1", "config 1 value edited" }, { "config2", "config 2 value" } }; var filePath = Path.Combine(AppContext.BaseDirectory, "exists.json"); if (!File.Exists(filePath)) { File.WriteAllText(filePath, JsonConvert.SerializeObject(content)); } var console = new TestConsole(_output); var command = new ImportCommand(_engineConfig.Object, console, (new Mock <ILogger <ImportCommand> >()).Object) { InputFile = filePath }; var message = command.Execute(); var sb = new StringBuilder("Configs have been imported."); sb.AppendLine("- Modified:"); sb.AppendLine(" - config1: config 1 value edited"); sb.AppendLine("- Added:"); sb.AppendLine(" - config2: config 2 value"); Assert.Equal(sb.ToString(), message); }
public LaPalaceVM() { ImportCommand = new ImportCommand(this); RunCommand = new RunCommand(this); SaveCommand = new SaveCommand(this); ReportCommand = new ReportCommand(this); }
public void ExecuteImportCommand() { ImportCommand importcmd = new ImportCommand("setvar"); Machine machine = new Machine(); importcmd.Execute(machine.Environment); object setvar = machine.Environment.GetValue("setvar"); Assert.IsNotNull(setvar); Assert.IsInstanceOfType(setvar, typeof(IValues)); IValues setvarenv = (IValues)setvar; object var = setvarenv.GetValue("a"); Assert.IsNotNull(var); Assert.AreEqual(1, var); object doc = setvarenv.GetValue("__doc__"); Assert.IsNotNull(doc); Assert.AreEqual("setvar module", doc); }
public async Task <Operation> ImportAsync(DatabaseSmugglerImportOptions options, Stream stream, CancellationToken token = default(CancellationToken)) { if (options == null) { throw new ArgumentNullException(nameof(options)); } if (stream == null) { throw new ArgumentNullException(nameof(stream)); } JsonOperationContext context; using (_requestExecutor.ContextPool.AllocateOperationContext(out context)) { var getOperationIdCommand = new GetNextOperationIdCommand(); await _requestExecutor.ExecuteAsync(getOperationIdCommand, context, token).ConfigureAwait(false); var operationId = getOperationIdCommand.Result; var command = new ImportCommand(_requestExecutor.Conventions, context, options, stream, operationId); await _requestExecutor.ExecuteAsync(command, context, token).ConfigureAwait(false); return(new Operation(_requestExecutor, () => _store.Changes(), _requestExecutor.Conventions, operationId)); } }
public static void Import(User user, string fileName = null) { try { WorldEditCommand command; if (!string.IsNullOrEmpty(fileName)) { command = new ImportCommand(user, fileName); if (command.Invoke()) { user.Player.MsgLoc($"Import done in {command.ElapsedMilliseconds}ms. Use /paste"); } else { new PrintBlueprintListCommand(user).Invoke(); } } else { new PrintBlueprintListCommand(user).Invoke(); } } catch (WorldEditCommandException e) { user.Player.ErrorLocStr(e.Message); } catch (Exception e) { Log.WriteException(e); } }
private void OnImportClick(CommandBarButton Ctrl, ref bool CancelDefault) { using (var command = new ImportCommand(base.IDE)) { command.Execute(); } }
public void Execute(ISession session) { using (var sanityCheck = new SanityCheck()) { sanityCheck.Config = Config; sanityCheck.InitDb(); } var result = Files.GroupBy(f => f.ArchiveFileName.Replace(".meta", "")) .Where(g => g.Count() > 1) .Select(g => Tuple.Create( g.First(f => f.ArchiveFileName.IndexOf(".meta.") == -1).LocalFileName, g.First(f => f.ArchiveFileName.IndexOf(".meta.") >= 0) .ReadContent() .Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries))) .ToList(); using (var importer = new ImportCommand(result)) { importer.Config = Config; importer.InitSession(); importer.Execute(); } var settings = session.Query <Settings>().First(); settings.UserName = "******"; settings.Password = "******"; settings.LastUpdate = DateTime.Now; session.Save(settings); }
private async void ImportToolStripMenuItem_Click(object sender, EventArgs e) { await PromptOpenDatabaseAsync(async (db) => { var cmd = new ImportCommand(_db, db); var result = await cmd.ExecuteAsync(); MessageBox.Show($"{result.NewEntries} new entries imported, {result.UpdatedEntries} entries updated."); }); }
// Local mongodb must be accessble for this test to succeed public void ValidImport() { Command c = new ImportCommand(); c.Parse("--uri mongodb://localhost:27017/test --file *.json".Split(' ')); Assert.Equal("mongodb://localhost:27017/test", c.Connection); Assert.Equal("*.json", (c as ImportCommand).FilesFilter); c.Validate(); }
private Uri GetRequestUri <T>(ImportCommand <T> command) { string requestUri = this.GetMessageBase <T>() + "/import"; List <KeyValuePair <string, string> > queryStringParameters = new List <KeyValuePair <string, string> >(); queryStringParameters.AddRange(this.GetAdditionalParameters(command.AdditionalParameters)); queryStringParameters.ForEach(x => { requestUri = QueryHelpers.AddQueryString(requestUri, x.Key, x.Value); }); return(new Uri(requestUri)); }
protected override void OnSelectedItem(BarEntryModel item) { base.OnSelectedItem(item); ExportCommand.CanExecute(SelectedItem); ImportCommand.CanExecute(SelectedItem); OpenItemCommand.CanExecute(SelectedItem); OnPropertyChanged(nameof(ExportFileName)); }
private static bool OnIdleStartImport() { Db db = new Db(db_path, true); ImportCommand command = new ImportCommand(); command.ImportFromPath(db.Photos, directory_path, true); Application.Quit(); return(false); }
public async Task <ImportExecutionImpact> ExecuteImport(ImportCommand importCommand, Stream sourceData) { var result = await _operationsRepository.ExecuteImport(importCommand, sourceData); if (result.Success) { await GetCacheEntry(importCommand.AccountId).DeleteAsync(); } return(result); }
public ImportCommandTest() { _command = new ImportCommand(); _command.Connection = "mongodb://localhost/db"; _command.ConnectToMongoDb = (conn, db) => _mongoDatabaseMock.Object; _mongoDatabaseMock.Setup(db => db.GetCollection <SyncEntity>(ImportCommand.SyncCollectionName, null)).Returns(_syncEntityCollection.Object); _mongoDatabaseMock.Setup(db => db.DropCollection("Collection", It.IsAny <CancellationToken>())).Verifiable(); Program.Exec = (cmd, arg) => { _execLog.AppendLine($"{cmd} {arg}"); return(arg.Contains("err") ? 1 : 0); }; Program.Console = (line) => _consoleLog.AppendLine(line); }
public void CompileImportCommand() { Parser parser = new Parser("import module"); ICommand command = parser.CompileCommand(); Assert.IsNotNull(command); Assert.IsInstanceOfType(command, typeof(ImportCommand)); ImportCommand impcmd = (ImportCommand)command; Assert.AreEqual("module", impcmd.ModuleName); }
public void ImportModuleWithEmptyDocString() { ImportCommand importcmd = new ImportCommand("setvars"); Machine machine = new Machine(); importcmd.Execute(machine.Environment); var setvar = (IValues)machine.Environment.GetValue("setvars"); Assert.IsNull(setvar.GetValue("__doc__")); Assert.IsTrue(setvar.HasValue("__doc__")); }
/// <summary> /// Initializes a new instance of the <see cref="ImportCommandBinding<TController, TModel>"/> class. /// </summary> /// <param name="viewModel">The view model.</param> /// <param name="owner">The owner window.</param> public ImportCommandBinding(ShellViewModel viewModel, Window owner) { this.Command = ShellCommands.Import; this.CanExecute += delegate(object sender, CanExecuteRoutedEventArgs e) { e.CanExecute = ImportCommand <ShellController, ConfigurationModel> .CanOpen(viewModel); }; this.Executed += delegate(object sender, ExecutedRoutedEventArgs e) { ImportCommand <ShellController, ConfigurationModel> .Open(viewModel, owner, e.Parameter as string); }; }
static IEnumerable <T> Import <T>(string filePath) where T : new() { var csvLines = File.ReadAllLines(filePath); var importSchemaValidatorCommand = new ValidateNameSpaceCommand <T>(csvLines.First()); if (importSchemaValidatorCommand.Execute() == false) { Console.WriteLine($"Schema validation failed for {(new T()).GetType()} and {filePath}"); return(new List <T>()); } var importCommand = new ImportCommand <T>(csvLines.Skip(1)); return(importCommand.Execute()); }
public async Task WhenIImportTheOperationsFileWithTheCurrentStructureMetadata() { var sm = _context.CurrentOperationsFileStructureMetadata; var importCommand = new ImportCommand(_context.AccountId) { Culture = sm.Culture, DecimalSeparator = sm.DecimalSeparator, Encoding = sm.Encoding, SourceKind = sm.SourceKind }; await _context.ImportManager.RequestImportExecution( importCommand, new MemoryStream(_context.AnOperationsFile)); }
public async Task <ActionResult> Import(IFormFile file) { if (file.Length < 1024 * 1024) { var transactionsFile = await ReadStream(file); var command = new ImportCommand(GetCurrentUserId(), transactionsFile); _ = bus.SendAsync(command); return(Accepted(command)); } else { return(BadRequest()); } }
private void OnKeyDown(object sender, KeyEventArgs e) { switch (e.Key) { case Key.Enter when Keyboard.Modifiers.HasFlag(ModifierKeys.Control): ImportCommand.Execute(null); e.Handled = true; break; case Key.Escape: CancelCommand.Execute(null); e.Handled = true; break; } }
public void RaiseWhenImportModuleDoesNotExist() { ImportCommand importcmd = new ImportCommand("spam"); Machine machine = new Machine(); try { importcmd.Execute(machine.Environment); Assert.Fail("Exception expected"); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(ImportError)); Assert.AreEqual("No module named spam", ex.Message); } }
private static void RunImport(ImportOptions options) { int messageCount; using (var messageSerializer = GetMessageSerializer(options)) using (var connection = GetConnection(options)) using (var channel = connection.CreateModel()) { messageCount = new ImportCommand { MessageSerializer = messageSerializer, DirectToQueue = !options.PublishToExchange }.Execute(channel, GetRateLimiter(options.MaxRate)); } Console.WriteLine($"{messageCount} message{(messageCount != 1 ? "s" : "")} published."); }
public void ConfigImport_Execute_ReturnsNotFound() { var filePath = Path.Combine(AppContext.BaseDirectory, "notexist.json"); if (File.Exists(filePath)) { File.Delete(filePath); } var console = new TestConsole(_output); var command = new ImportCommand(_engineConfig.Object, console, (new Mock <ILogger <ImportCommand> >()).Object) { InputFile = filePath }; var message = command.Execute(); Assert.Equal($"File \"{filePath}\" could not be found.", message); }
private async Task <bool> LaunchFilePickerAndImportAsync() { bool processIsSuccessful = false; FileOpenPicker picker = new FileOpenPicker { SuggestedStartLocation = PickerLocationId.Downloads }; picker.FileTypeFilter.Add(".vcf"); StorageFile file = await picker.PickSingleFileAsync(); if (file != null) { try { IsBusy = true; IBuffer buffer = await FileIO.ReadBufferAsync(file); using (DataReader dataReader = DataReader.FromBuffer(buffer)) { if (await ImportContacts(dataReader.ReadString(buffer.Length)).ConfigureAwait(false)) { processIsSuccessful = true; } } } finally { DispatcherHelper.CheckBeginInvokeOnUI(() => { IsBusy = false; ImportCommand.RaiseCanExecuteChanged(); Selected = Manager.Contacts.FirstOrDefault(); }); } } return(processIsSuccessful); }
public void ExecuteImportCommand() { ImportCommand importcmd = new ImportCommand("setvar"); Machine machine = new Machine(); importcmd.Execute(machine, machine.Environment); object setvar = machine.Environment.GetValue("setvar"); Assert.IsNotNull(setvar); Assert.IsInstanceOfType(setvar, typeof(BindingEnvironment)); BindingEnvironment setvarenv = (BindingEnvironment)setvar; object var = setvarenv.GetValue("a"); Assert.IsNotNull(var); Assert.AreEqual(1, var); }
public static Command ParseCommand(params string[] args) { Command result = new HelpCommand(); // try parse arguments only when they exist if (args != null && args.Length > 0) { try { Command candidate = new HelpCommand(); CommandType cmdType = Enum.Parse <CommandType>(args[0], true); switch (cmdType) { case CommandType.Help: candidate = new HelpCommand(); break; case CommandType.Import: candidate = new ImportCommand(); break; case CommandType.Export: candidate = new ExportCommand(); break; default: throw new NotImplementedException($"Command {cmdType} not implemented yet"); } candidate.CommandType = cmdType; candidate.Parse(args); result = candidate; } catch (Exception ex) { Console(ex.Message); #if DEBUG Console(ex.StackTrace); #endif } } return(result); }
private FileStructureMetadata GetFileMetadata(ImportCommand importCommand) { var md = FileStructureMetadataFactory.CreateDefault(importCommand.SourceKind); if (!string.IsNullOrEmpty(importCommand.Culture)) { md.Culture = importCommand.Culture; } if (!string.IsNullOrEmpty(importCommand.Encoding)) { md.Encoding = importCommand.Encoding; } if (!string.IsNullOrEmpty(importCommand.DecimalSeparator)) { md.DecimalSeparator = importCommand.DecimalSeparator; } return(md); }
private static bool OnIdleStartImport () { Db db = new Db (db_path, true); ImportCommand command = new ImportCommand (); command.ImportFromPath (db.Photos, directory_path, true); Application.Quit (); return false; }
public SourceMenu (ImportCommand command) { this.command = command; source_count = 0; SourceItem item = new SourceItem (new BrowseSource ()); item.Activated += HandleActivated; this.Append (item); this.Append (new Gtk.SeparatorMenuItem ()); // Add external hard drives to the menu foreach (Gnome.Vfs.Volume vol in monitor.MountedVolumes) { if (!vol.IsUserVisible || vol.DeviceType == Gnome.Vfs.DeviceType.Unknown) continue; System.Console.WriteLine ("{0} - {1} - {2} {3} {4} {5} {6}", vol.DisplayName, vol.Icon, vol.VolumeType.ToString (), vol.ActivationUri, vol.IsUserVisible, vol.IsMounted, vol.DeviceType); if (vol.Drive != null) System.Console.WriteLine (vol.Drive.DeviceType.ToString ()); ImportSource source = new VolumeSource (vol); item = new SourceItem (source); item.Activated += HandleActivated; this.Append (item); source_count++; } GPhotoCamera cam = new GPhotoCamera (); cam.DetectCameras (); int camera_count = cam.CameraList.Count (); if (camera_count > 0) { source_count += camera_count; for (int i = 0; i < camera_count; i++) { string handle = cam.CameraList.GetValue (i); if (camera_count == 1 || handle != "usb:") { if (handle.StartsWith ("disk:")) { string path = handle.Substring ("disk:".Length); if (FindItemPosition (path) != -1) continue; } ImportSource source = new CameraSource (cam, i); item = new SourceItem (source); item.Activated += HandleActivated; this.Append (item); } } } else { ImportSource source = new BrowseSource (Catalog.GetString ("(No Cameras Detected)"), "emblem-camera"); item = new SourceItem (source); item.Activated += HandleActivated; item.Sensitive = false; this.Append (item); } /* this.Append (new Gtk.SeparatorMenuItem ()); foreach (Gnome.Vfs.Drive drive in monitor.ConnectedDrives) { ImportSource source = new DriveSource (drive); Gtk.ImageMenuItem item = new SourceItem (source); item.Sensitive = drive.IsMounted; this.Append (item); } */ this.ShowAll (); }
private int ImportFiles () { ImportCommand command = new ImportCommand (null); return command.ImportFromPaths (db.Photos, saved_files, selected_tags); }
public void ImportUriList (UriList list, bool copy) { ImportCommand command = new ImportCommand (main_window); if (command.ImportFromPaths (db.Photos, list.ToLocalPaths (), copy) > 0) { query.RollSet = new RollSet (db.Rolls.GetRolls (1)[0]); UpdateQuery (); } }
public void ImportFile (string path) { ImportCommand command = new ImportCommand (main_window); if (command.ImportFromFile (db.Photos, path) > 0) { query.RollSet = new RollSet (db.Rolls.GetRolls (1)[0]); UpdateQuery (); } }
void CreatePhotoWall() { dir_tmp = System.IO.Path.GetTempFileName (); System.IO.File.Delete (dir_tmp); System.IO.Directory.CreateDirectory (dir_tmp); dir_tmp += "/"; //Prepare the pictures ProgressDialog progress_dialog = null; progress_dialog = new ProgressDialog (Catalog.GetString ("Preparing selected pictures"), ProgressDialog.CancelButtonType.Stop, App.Instance.Organizer.SelectedPhotos ().Length, picturetile_dialog); FilterSet filters = new FilterSet (); filters.Add (new JpegFilter ()); uint counter = 0; List<Tag> all_tags = new List<Tag> (); foreach (Photo p in App.Instance.Organizer.SelectedPhotos ()) { if (progress_dialog.Update (String.Format (Catalog.GetString ("Processing \"{0}\""), p.Name))) { progress_dialog.Destroy (); DeleteTmp (); return; } //Store photo tags, to attach them later on import foreach (Tag tag in p.Tags) { if (! all_tags.Contains (tag)) all_tags.Add (tag); } //FIXME should switch to retry/skip if (!GLib.FileFactory.NewForUri (p.DefaultVersion.Uri).Exists) { Log.WarningFormat ("Couldn't access photo {0} while creating mosaics", p.DefaultVersion.Uri.LocalPath); continue; } using (FilterRequest freq = new FilterRequest (p.DefaultVersion.Uri)) { filters.Convert (freq); File.Copy (freq.Current.LocalPath, String.Format ("{0}{1}.jpg", dir_tmp, counter ++)); } } if (progress_dialog != null) progress_dialog.Destroy (); photo_tags = all_tags.ToArray (); string uniform = ""; if (uniform_images.Active) uniform = "--uniform"; string output_format = "jpeg"; if (tiff_radio.Active) output_format = "tiff"; string scale = String.Format (CultureInfo.InvariantCulture, "{0,4}", (double) image_scale.Value / (double) 100); destfile_tmp = String.Format ("{0}.{1}", System.IO.Path.GetTempFileName (), output_format); //Execute picturetile string picturetile_command = String.Format ("--size {0}x{1} " + "--directory {2} " + "--scale {3} " + "--margin {4} " + "--border {5} " + "--background {6} " + "--pages {7} " + "{8} " + "{9}", x_max_size.Text, y_max_size.Text, dir_tmp, scale, space_between_images.Text, outside_border.Text, colors [background_color.Active], pages.Text, uniform, destfile_tmp); Log.Debug ("Executing: picturetile.pl " + picturetile_command); System.Diagnostics.Process pt_exe = System.Diagnostics.Process.Start ("picturetile.pl", picturetile_command); pt_exe.WaitForExit (); // Handle multiple files generation (pages). // If the user wants 2 pages (images), and the output filename is out.jpg, picturetile will create // /tmp/out1.jpg and /tmp/out2.jpg. System.IO.DirectoryInfo di = new System.IO.DirectoryInfo (System.IO.Path.GetDirectoryName (destfile_tmp)); string filemask = System.IO.Path.GetFileNameWithoutExtension (destfile_tmp) + "*" + System.IO.Path.GetExtension (destfile_tmp); FileInfo [] fi = di.GetFiles (filemask); // Move generated files to f-spot photodir string [] photo_import_list = new string [fi.Length]; counter = 0; foreach (FileInfo f in fi) { string orig = System.IO.Path.Combine (f.DirectoryName, f.Name); photo_import_list [counter ++] = MoveFile (orig); } //Add the pic(s) to F-Spot! Db db = App.Instance.Database; ImportCommand command = new ImportCommand (null); if (command.ImportFromPaths (db.Photos, photo_import_list, photo_tags) > 0) { InfoDialog (Catalog.GetString ("PhotoWall generated!"), Catalog.GetString ("Your photo wall have been generated and imported in F-Spot. Select the last roll to see it"), Gtk.MessageType.Info); } else { InfoDialog (Catalog.GetString ("Error importing photowall"), Catalog.GetString ("An error occurred while importing the newly generated photowall to F-Spot"), Gtk.MessageType.Error); } DeleteTmp (); }
void HandleImportCommand (object sender, EventArgs e) { db.Sync = false; ImportCommand command = new ImportCommand (main_window); if (command.ImportFromFile (db.Photos, null) > 0) { query.RollSet = new RollSet (db.Rolls.GetRolls (1)[0]); UpdateQuery (); } db.Sync = true; }
public void Import (string path) { ImportCommand cmd = new ImportCommand (MainWindow, path); cmd.Execute (); }