コード例 #1
0
        public ExcelFunction LoadAndGetExcelFunction(string functionName)
        {
            var delegates                  = new List <Delegate>();
            var functionAttributes         = new List <object>();
            var functionArgumentAttributes = new List <List <object> >();
            var assembly = Assembly.GetAssembly(typeof(XLEquities));

            StaticData.Load();
            ExcelTypeConverter.AddConvertersFrom(Assembly.GetAssembly(typeof(AddIn)));
            FunctionRegistration.GetDelegatesAndAttributes(assembly, "QSA", new Dictionary <string, bool>(),
                                                           ref delegates, ref functionAttributes, ref functionArgumentAttributes);

            ExcelFunction func = null;

            foreach (var d in delegates)
            {
                func = (ExcelFunction)d.Target;
                if (func.GetName() == functionName)
                {
                    return(func);
                }
            }

            throw new InvalidOperationException($"{functionName} is not an available Excel function.");
        }
コード例 #2
0
ファイル: AddIn.cs プロジェクト: zhangz/QuantSA
    // Called when addin opens
    public void AutoOpen()
    {
        try
        {
            QuantSAState.SetLogger(new ExcelFileLogFactory());
            ExcelDna.IntelliSense.IntelliSenseServer.Install();
            _log = QuantSAState.LogFactory.Get(MethodBase.GetCurrentMethod().DeclaringType);

            var pathString = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                                          "QuantSA");
            if (!Directory.Exists(pathString))
            {
                Directory.CreateDirectory(pathString);
            }
            //TODO: Check if newer version of addin exists.

            _log.Info("Loading static data");
            StaticData.Load();

            _log.Info("Check custom function visibility");
            // Get the functions that are set for the user.
            var funcsInUserFile = GetFunctionVisibility(FunctionsFilenameUser);

            //Check in the installation folder for any dlls that include a class of type IQuantSAPlugin
            AssemblyImageResources = new Dictionary <string, Bitmap>();
            _log.Info("Check for plugins");
            GetPlugins();
            var assemblies = new[]
            {
                Assembly.GetAssembly(typeof(XLEquities)),
                Assembly.GetAssembly(typeof(AddIn))
            };
            _log.Info("Add converters");
            foreach (var tuple in Plugins)
            {
                ExcelTypeConverter.AddConvertersFrom(tuple.Item2);
            }
            foreach (var assembly in assemblies)
            {
                ExcelTypeConverter.AddConvertersFrom(assembly);
            }

            _log.Info("Register user functions");
            foreach (var tuple in Plugins)
            {
                FunctionRegistration.RegisterFrom(tuple.Item2, tuple.Item1.GetShortName(), funcsInUserFile);
            }
            foreach (var assembly in assemblies)
            {
                FunctionRegistration.RegisterFrom(assembly, "QSA", funcsInUserFile);
            }
            UpdateUserFunctionFile(funcsInUserFile, FunctionRegistration.FunctionNames);
        }
        catch (Exception e)
        {
            _log.Error(e);
            var pathString = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                                          "QuantSA");
            var fileName = Path.Combine(pathString, "QuantSAError.txt");
            File.WriteAllText(fileName, e.ToString());
            throw new AddInException("An error occurred while opening the QuantSA addin.\n" +
                                     "Check the error log file for details.\n\n" +
                                     $"{fileName}");
        }
    }
コード例 #3
0
        public void ExcelTypeConverter_ExcelTypeConverter_Custom2D()
        {
            var o2 = new CustomTypeForTests[1, 1];

            Assert.IsTrue(ExcelTypeConverter.ShouldUseReference(o2.GetType()));
        }
コード例 #4
0
        public void ExcelTypeConverter_ExcelTypeConverter_object2D()
        {
            var o2 = new object[1, 1];

            Assert.IsFalse(ExcelTypeConverter.ShouldUseReference(o2.GetType()));
        }