Example #1
0
        public static RegistrationResults RegisterApi(OpenApiDocument apiDefinition, bool reregister = false)
        {
            List <Delegate>       delegates      = new List <Delegate>();
            List <object>         funcAttribs    = new List <object>();
            List <List <object> > argAttribsList = new List <List <object> >();

            var functionsAdded = new List <string>();

            foreach (var path in apiDefinition.Paths)
            {
                foreach (var operation in path.Value.Operations)
                {
                    delegates.Add(CreateDelegateForOperation(path.Key, path.Value, operation.Key, operation.Value));

                    ExcelFunctionAttribute att = new ExcelFunctionAttribute();

                    att.Name = operation.Value.OperationId;

                    att.Description            = operation.Value.Description;
                    att.HelpTopic              = apiDefinition.ExternalDocs?.Url?.ToString();
                    att.SuppressOverwriteError = reregister;

                    funcAttribs.Add(att);
                    List <object> argAttribs = new List <object>();

                    foreach (var parameter in operation.Value.Parameters)
                    {
                        ExcelArgumentAttribute atta1 = new ExcelArgumentAttribute();
                        atta1.Name        = parameter.Name;
                        atta1.Description = parameter.Description;

                        argAttribs.Add(atta1);
                    }

                    argAttribsList.Add(argAttribs);

                    functionsAdded.Add(att.Name);
                }
            }

            ExcelIntegration.RegisterDelegates(delegates, funcAttribs, argAttribsList);

            var registrationResults = new RegistrationResults
            {
                FunctionsAdded = functionsAdded
            };

            return(registrationResults);
        }
Example #2
0
        public static void DeregisterFunctions(RegistrationResults registeredFunctions)
        {
            foreach (var function in registeredFunctions.FunctionsAdded)
            {
                // get the path to the XLL
                var xllName = XlCall.Excel(XlCall.xlGetName);

                // get the registered ID for this function and unregister
                var regId = XlCall.Excel(XlCall.xlfEvaluate, function);
                XlCall.Excel(XlCall.xlfSetName, function);
                XlCall.Excel(XlCall.xlfUnregister, regId);

                //var reregId = XlCall.Excel(XlCall.xlfRegister, xllName, "xlAutoRemove", "I", function, ExcelMissing.Value, 2);
                //XlCall.Excel(XlCall.xlfSetName, function);
                //XlCall.Excel(XlCall.xlfUnregister, reregId);
            }
        }