コード例 #1
0
ファイル: Plugin.cs プロジェクト: svpxc/aasx-package-explorer
        public void InitPlugin(string[] args)
        {
            // start ..
            Log.Info("InitPlugin() called with args = {0}", (args == null) ? "" : string.Join(", ", args));

            // .. with built-in options
            options = AasxPluginGenericForms.GenericFormOptions.CreateDefault();

            // try load defaults options from assy directory
            try
            {
                // need special settings
                var settings = AasxPluginOptionSerialization.GetDefaultJsonSettings(
                    new[] { typeof(AasxPluginGenericForms.GenericFormOptions), typeof(AasForms.FormDescBase) });

                // base options
                var newOpt =
                    AasxPluginOptionsBase.LoadDefaultOptionsFromAssemblyDir <AasxPluginGenericForms.GenericFormOptions>(
                        this.GetPluginName(), Assembly.GetExecutingAssembly(), settings);
                if (newOpt != null)
                {
                    this.options = newOpt;
                }

                // try find additional options
                this.options.TryLoadAdditionalOptionsFromAssemblyDir <AasxPluginGenericForms.GenericFormOptions>(
                    this.GetPluginName(), Assembly.GetExecutingAssembly(), settings, this.Log);
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Exception when reading default options {1}");
            }
        }
コード例 #2
0
        public void InitPlugin(string[] args)
        {
            // start ..
            _log.Info("InitPlugin() called with args = {0}", (args == null) ? "" : string.Join(", ", args));

            // .. with built-in options
            _options = DocumentShelfOptions.CreateDefault();

            // try load defaults options from assy directory
            try
            {
                var newOpt =
                    AasxPluginOptionsBase.LoadDefaultOptionsFromAssemblyDir <DocumentShelfOptions>(
                        this.GetPluginName(), Assembly.GetExecutingAssembly());
                if (newOpt != null)
                {
                    _options = newOpt;
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex, "Exception when reading default options {1}");
            }

            // index them!
            _options.IndexListOfRecords(_options.Records);
        }
コード例 #3
0
        public void TryLoadAdditionalOptionsFromAssemblyDir <T>(
            string pluginName, Assembly assy = null,
            JsonSerializerSettings settings  = null,
            LogInstance log = null) where T : AasxPluginOptionsBase
        {
            // expand assy?
            if (assy == null)
            {
                assy = Assembly.GetExecutingAssembly();
            }
            if (pluginName == null || pluginName == "")
            {
                return;
            }

            // build dir name
            var baseDir = System.IO.Path.GetDirectoryName(assy.Location);

            // search
            var files = Directory.GetFiles(baseDir, "*.add-options.json");

            foreach (var fn in files)
            {
                try
                {
                    var optText = File.ReadAllText(fn);
                    var opts    = Newtonsoft.Json.JsonConvert.DeserializeObject <T>(optText, settings);
                    this.Merge(opts);
                }
                catch (Exception ex)
                {
                    log?.Error(ex, $"loading additional options (${fn})");
                }
            }
        }
コード例 #4
0
        public void InitPlugin(string[] args)
        {
            // start ..
            Log.Info("InitPlugin() called with args = {0}", (args == null) ? "" : string.Join(", ", args));

            // .. with built-in options
            options = AasxPluginBomStructure.BomStructureOptions.CreateDefault();

            // try load defaults options from assy directory
            try
            {
                var newOpt =
                    AasxPluginOptionsBase
                    .LoadDefaultOptionsFromAssemblyDir <AasxPluginBomStructure.BomStructureOptions>(
                        this.GetPluginName(), Assembly.GetExecutingAssembly());
                if (newOpt != null)
                {
                    this.options = newOpt;
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Exception when reading default options {1}");
            }
        }
コード例 #5
0
        public void InitPlugin(string[] args)
        {
            logger.Info("InitPlugin() called with args = {0}", (args == null) ? "" : string.Join(", ", args));

            // .. with built-in options
            options = AasxUaNetServer.UaNetServerOptions.CreateDefault();

            // try load defaults options from assy directory
            try
            {
                var newOpt =
                    /* AasxPluginOptionsBase */ LoadDefaultOptionsFromAssemblyDirXXXX <
                        AasxUaNetServer.UaNetServerOptions>(
                        this.GetPluginName(), Assembly.GetExecutingAssembly());
                if (newOpt != null)
                {
                    this.options = newOpt;
                }
            }
            catch (Exception ex)
            {
                logger?.Error(ex, "Exception when reading default options {1}");
            }
        }
コード例 #6
0
        private void Import(ExportTableRecord job,
                            IFlyoutProvider fop,
                            AdminShell.Submodel sm, AdminShell.AdministrationShellEnv env)
        {
            // get the import file
            var dlg = new Microsoft.Win32.OpenFileDialog();

            try
            {
                dlg.InitialDirectory = System.IO.Path.GetDirectoryName(
                    System.AppDomain.CurrentDomain.BaseDirectory);
            }
            catch (Exception ex)
            {
                AdminShellNS.LogInternally.That.SilentlyIgnoredError(ex);
            }
            dlg.Title = "Select text file to be exported";

            if (job.Format == (int)ExportTableRecord.FormatEnum.TSF)
            {
                dlg.DefaultExt = "*.txt";
                dlg.Filter     =
                    "Tab separated file (*.txt)|*.txt|Tab separated file (*.tsf)|*.tsf|All files (*.*)|*.*";
            }
            if (job.Format == (int)ExportTableRecord.FormatEnum.LaTex)
            {
                dlg.DefaultExt = "*.tex";
                dlg.Filter     = "LaTex file (*.tex)|*.tex|All files (*.*)|*.*";
            }
            if (job.Format == (int)ExportTableRecord.FormatEnum.Excel)
            {
                dlg.DefaultExt = "*.xlsx";
                dlg.Filter     = "Microsoft Excel (*.xlsx)|*.xlsx|All files (*.*)|*.*";
            }
            if (job.Format == (int)ExportTableRecord.FormatEnum.Word)
            {
                dlg.DefaultExt = "*.docx";
                dlg.Filter     = "Microsoft Word (*.docx)|*.docx|All files (*.*)|*.*";
            }

            fop?.StartFlyover(new EmptyFlyout());
            var res = dlg.ShowDialog(fop?.GetWin32Window());

            fop?.CloseFlyover();

            if (true != res)
            {
                return;
            }

            // try import
            try
            {
                Log.Info("Importing table: {0}", dlg.FileName);
                var success = false;
                try
                {
                    if (job.Format == (int)ExportTableRecord.FormatEnum.Word)
                    {
                        success = true;
                        var pop = new ImportPopulateByTable(Log, job, sm, env, options);
                        using (var stream = File.Open(dlg.FileName, FileMode.Open,
                                                      FileAccess.Read, FileShare.ReadWrite))
                            foreach (var tp in ImportTableWordProvider.CreateProviders(stream))
                            {
                                pop.PopulateBy(tp);
                            }
                    }

                    if (job.Format == (int)ExportTableRecord.FormatEnum.Excel)
                    {
                        success = true;
                        var pop = new ImportPopulateByTable(Log, job, sm, env, options);
                        foreach (var tp in ImportTableExcelProvider.CreateProviders(dlg.FileName))
                        {
                            pop.PopulateBy(tp);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log?.Error(ex, "importing table");
                    success = false;
                }

                if (!success)
                {
                    fop?.MessageBoxFlyoutShow(
                        "Some error occured while importing the table. Please refer to the log messages.",
                        "Error", AnyUiMessageBoxButton.OK, AnyUiMessageBoxImage.Exclamation);
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "When exporting table, an error occurred");
            }
        }