Example #1
0
        public CommonReturnValue GetInlinePluginModuleSource(string inlineEntryId, out InlineModuleManifestEntry existingInlineEntry, out string source)
        {
            source = null;
            existingInlineEntry = null;

            var pluginAssembly = this.PluginAssemblies.FirstOrDefault(p => p.InlineEntryId != null && p.InlineEntryId.Equals(inlineEntryId, StringComparison.Ordinal) && p.IsInline);

            if (pluginAssembly == null)
            {
                return(CommonReturnValue.UserError($"An inline module with the Id '{inlineEntryId}' does not exist"));
            }

            try
            {
                existingInlineEntry = InlineModuleManifest.Instance.GetEntryById(pluginAssembly.InlineEntryId);
                var sourcePath = System.IO.Path.Combine(InlinePluginSourcePath, existingInlineEntry.Id);

                if (System.IO.File.Exists(sourcePath))
                {
                    source = System.IO.File.ReadAllText(sourcePath);
                    return(CommonReturnValue.Success());
                }
                else
                {
                    return(CommonReturnValue.UserError($"Failed to find source at: {sourcePath}"));
                }
            }
            catch (Exception e)
            {
                SessionLog.Warning("Failed to fetch file of plugin module with InstanceId = {0}; {1}", pluginAssembly.InstanceId, pluginAssembly.Assembly.FullName);
                SessionLog.Exception(e);
            }

            return(CommonReturnValue.Success());
        }
Example #2
0
        // public void HandleAssemblyUpdated(PluginInfo pluginInfo)
        // {
        //     this.PluginInfo = pluginInfo;
        //     this.Process();
        // }

        public void CombineOutput(OM.Application appContext, ref Dictionary <string /*Namespace*/, List <Definition> > combinedJS, ref Dictionary <string /*Namespace*/, List <Definition> > combinedTSD, ref List <string> combinedConverterLookup)
        {
            // converters
            foreach (var c in this.ConverterLookup)
            {
                if (combinedConverterLookup.IndexOf(c) == -1)
                {
                    combinedConverterLookup.Add(c);
                }
            }

            foreach (var namespaceKV in this.JavaScriptDefinitions)
            {
                // js
                foreach (var definition in namespaceKV.Value)
                {
                    if (!combinedJS.ContainsKey(namespaceKV.Key))
                    {
                        combinedJS.Add(namespaceKV.Key, new List <Definition>());
                    }

                    if (combinedJS[namespaceKV.Key].FirstOrDefault(m => m.MethodName.Equals(definition.MethodName, StringComparison.Ordinal)) != null)
                    {
                        // TODO: Consider allowing overloads
                        SessionLog.Warning($"{appContext.Project.Name}/{appContext.Name} - ServerMethods - conflicting method name '{definition.MethodName}'.");
                        continue;
                    }

                    var hasConverter = definition.InputConverter != null || definition.OutputConverter != null || definition.ResultsConverter != null;

                    if (hasConverter)
                    {
                        var convertersSB = new StringBuilder("{ ");
                        var lst          = new List <string>();

                        string inputConverter  = definition.InputConverter;
                        string outputConverter = definition.OutputConverter;
                        string resultConverter = definition.ResultsConverter;

                        foreach (var converterJson in combinedConverterLookup)
                        {
                            if (inputConverter != null)
                            {
                                inputConverter = inputConverter.Replace(converterJson, combinedConverterLookup.IndexOf(converterJson).ToString());
                            }

                            if (outputConverter != null)
                            {
                                outputConverter = outputConverter.Replace(converterJson, combinedConverterLookup.IndexOf(converterJson).ToString());
                            }

                            if (resultConverter != null)
                            {
                                resultConverter = resultConverter.Replace(converterJson, combinedConverterLookup.IndexOf(converterJson).ToString());
                            }
                        }

                        if (inputConverter != null)
                        {
                            lst.Add($"input: {{ {inputConverter} }}");
                        }

                        if (outputConverter != null)
                        {
                            lst.Add($"output: {{ {outputConverter} }}");
                        }

                        if (resultConverter != null)
                        {
                            lst.Add($"results: {{ {resultConverter} }}");
                        }

                        convertersSB.Append(string.Join(", ", lst));

                        convertersSB.Append(" }");


                        definition.Line = definition.Line.Replace("<<CONV_SEP>>", ", ");
                        definition.Line = definition.Line.Replace("<<CONVERTERS>>", convertersSB.ToString());
                    }

                    combinedJS[namespaceKV.Key].Add(definition);
                }
            }

            // tsd
            foreach (var namespaceKV in this.TypescriptDefinitions)
            {
                foreach (var definition in namespaceKV.Value)
                {
                    if (!combinedTSD.ContainsKey(namespaceKV.Key))
                    {
                        combinedTSD.Add(namespaceKV.Key, new List <Definition>());
                    }

                    if (combinedTSD[namespaceKV.Key].FirstOrDefault(m => m.MethodName.Equals(definition.MethodName, StringComparison.Ordinal)) != null)
                    {
                        // just skip, should have already been handled on the .js side
                        continue;
                    }

                    combinedTSD[namespaceKV.Key].Add(definition);
                }
            }
        }