Example #1
0
        private void tsbImportNN_Click(object sender, EventArgs e)
        {
            listLog.Items.Clear();

            var settings = new ImportFileSettings
            {
                FirstEntity           = ((EntityInfo)cbbFirstEntity.SelectedItem).Metadata.LogicalName,
                FirstAttributeIsGuid  = rdbFirstGuid.Checked,
                FirstAttributeName    = ((AttributeInfo)cbbFirstEntityAttribute.SelectedItem).Metadata.LogicalName,
                Relationship          = ((RelationshipInfo)cbbRelationship.SelectedItem).Metadata.SchemaName,
                SecondEntity          = ((EntityInfo)cbbSecondEntity.SelectedItem).Metadata.LogicalName,
                SecondAttributeIsGuid = rdbSecondGuid.Checked,
                SecondAttributeName   = ((AttributeInfo)cbbSecondEntityAttribute.SelectedItem).Metadata.LogicalName,
            };

            WorkAsync("Importing many to many relationships...",
                      evt =>
            {
                var innerSettings = (ImportFileSettings)((object[])evt.Argument)[0];
                var filePath      = ((object[])evt.Argument)[1].ToString();
                var ie            = new ImportEngine(filePath, this.Service, innerSettings);
                ie.RaiseError    += ie_RaiseError;
                ie.RaiseSuccess  += ie_RaiseSuccess;
                ie.Import();
            },
                      evt => {},
                      new object[] { settings, txtFilePath.Text });
        }
Example #2
0
        public void TestImports()
        {
            File.Delete(newDataRoot + "cmd_out.txt"); //this is needed because the add on the ds/_start has no value and gets ignored

            ImportEngine eng = new ImportEngine();

            eng.Load(root + "import.xml");
            var report = eng.Import("json,jsoncmd,tika_raw,tika_sort_title,tika_undup_title");

            Console.WriteLine(report);
            Assert.AreEqual(null, report.ErrorMessage);

            CheckFiles("cmd_out.txt");
            CheckFiles("json_out.txt");
            CheckFiles("tika_raw.txt");
            CheckFiles("tika_sort_title.txt");
            CheckFiles("tika_undup_title.txt");

            Assert.AreEqual(5, report.DatasourceReports.Count);
            int i = -1;

            checkDataSourceStats(report.DatasourceReports[++i], 5, 5);//The string value will not be added, bcause its emitted as 'record'. It is 5/5 because there are 2 EP's. Maybe we need to do something for the string value...
            checkDataSourceStats(report.DatasourceReports[++i], 5, 5);
            checkDataSourceStats(report.DatasourceReports[++i], 10, 10);
            checkDataSourceStats(report.DatasourceReports[++i], 10, 10);
            checkDataSourceStats(report.DatasourceReports[++i], 10, 3);
        }
Example #3
0
        void importWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            var settings = (ImportFileSettings)((object[])e.Argument)[0];
            var filePath = ((object[])e.Argument)[1].ToString();
            var ie       = new ImportEngine(filePath, service, settings);

            ie.RaiseError   += ie_RaiseError;
            ie.RaiseSuccess += ie_RaiseSuccess;
            ie.Import();
        }
Example #4
0
        public void TestCommands()
        {
            File.Delete(newDataRoot + "cmd-out.txt");
            ImportEngine eng = new ImportEngine();

            eng.Load(root + "import.xml");
            var report = eng.Import("jsoncmd");

            Assert.AreEqual(1, report.DatasourceReports.Count);
            Assert.AreEqual(null, report.ErrorMessage);
            var dsReport = report.DatasourceReports[0];

            Console.WriteLine("Report: {0}", dsReport);
            Assert.AreEqual(5, dsReport.Emitted);
            Assert.AreEqual(4, dsReport.Added);

            CheckFiles("cmd-out.txt");
        }
Example #5
0
 public ImportReport Run(_ImportFlags flags, String switches, String xml, String[] activeDS, int maxAdds, int maxEmits)
 {
     try
     {
         using (ImportEngine engine = new ImportEngine())
         {
             engine.Switches    = switches;
             engine.ImportFlags = flags;
             engine.Load(xml);
             engine.MaxAdds  = maxAdds;
             engine.MaxEmits = maxEmits;
             return(engine.Import(activeDS));
         }
     }
     catch (Exception e)
     {
         Logs.ErrorLog.Log(e);
         throw new Exception(e.Message);
     }
 }
Example #6
0
        private void Import()
        {
            this.ClearLog();
            var engine = new ImportEngine(this.Database);

            engine.Logged          += (sender, e) => this.AppendLog(e.Data);
            engine.ProgressChanged += (sender, e) => this.Progress = e.Data;

            if (engine.Check())
            {
                this.RunInBackground(() =>
                {
                    Thread.CurrentThread.CurrentUICulture = cultureInfo;
                    var result      = engine.Import(component);
                    this.importDone = true;
                    return(result);
                });
            }
            else
            {
                this.AppendLog(Messages.Log_InvalidDb);
            }
        }
Example #7
0
        private static int runAsConsole(String[] args)
        {
            try
            {
                bool b = Bitmanager.Core.ConsoleHelpers.AttachConsole();
                if (!b)
                {
                    b = Bitmanager.Core.ConsoleHelpers.AllocConsole();
                }
            }
            catch { }

            try
            {
                Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
                var cmd = new CommandLineParms(args);
                if (cmd.NamedArgs.ContainsKey("?") || cmd.NamedArgs.ContainsKey("help"))
                {
                    goto WRITE_SYNTAX;
                }

                String responseFile = cmd.NamedArgs.OptGetItem("resp");
                if (responseFile != null)
                {
                    if (cmd.Args.Count != 0)
                    {
                        goto WRITE_SYNTAX_ERR;
                    }
                    cmd = new CommandLineParms(responseFile);
                }

                _ImportFlags flags    = Invariant.ToEnum <_ImportFlags>(cmd.NamedArgs.OptGetItem("flags"), _ImportFlags.UseFlagsFromXml);
                int          maxAdds  = Invariant.ToInt32(cmd.NamedArgs.OptGetItem("maxadds"), -1);
                int          maxEmits = Invariant.ToInt32(cmd.NamedArgs.OptGetItem("maxemits"), -1);
                if (cmd.Args.Count == 0)
                {
                    goto WRITE_SYNTAX_ERR;
                }

                using (ImportEngine eng = new ImportEngine())
                {
                    eng.MaxAdds     = maxAdds;
                    eng.MaxEmits    = maxEmits;
                    eng.ImportFlags = flags;
                    String[] dsList = new String[cmd.Args.Count - 1];
                    for (int i = 1; i < cmd.Args.Count; i++)
                    {
                        dsList[i - 1] = cmd.Args[i];
                    }

                    eng.Load(cmd.Args[0]);
                    eng.Import(dsList.Length == 0 ? null : dsList);
                }
                return(0);

WRITE_SYNTAX_ERR:
                logError("Invalid commandline: {0}", Environment.CommandLine);
WRITE_SYNTAX:
                logError("");
                logError("Syntax: <importxml file> [list of datasources] [/flags:<importflags>] [/maxadds:<number>] [/maxemits:<number>] [/$$xxxx$$:<value>");
                logError("    or: /resp:<responsefile> with 1 option per line");
                return(12);
            }
            catch (Exception e)
            {
                logError("Error: {0}\r\nType: {1}\r\nStack:\r\n{2}", e.Message, e.GetType().FullName, e.StackTrace);
                return(12);
            }
        }