コード例 #1
0
 public FixedStructureImpl(StructureImpl structure)
 {
     foreach (KeyAndValueImpl keyValue in structure)
     {
         _structure.Insert(keyValue.Key.AsString(), keyValue.Value);
     }
 }
コード例 #2
0
 public void AddDataProcessorManagers(System.Collections.Hashtable managerFiles)
 {
     ScriptEngine.HostedScript.Library.StructureImpl dataProcessors = new ScriptEngine.HostedScript.Library.StructureImpl();
     // Добавляем обработки, написанные на OneScript
     foreach (System.Collections.DictionaryEntry cm in managerFiles)
     {
         ICodeSource src             = _hostedScript.Loader.FromString(InsertMandatoryMethods((string)cm.Value, (string)cm.Key));
         var         compilerService = _hostedScript.GetCompilerService();
         var         module          = compilerService.CreateModule(src);
         var         _loaded         = _hostedScript.EngineInstance.LoadModuleImage(module);
         dataProcessors.Insert((string)cm.Key, (IValue)_hostedScript.EngineInstance.NewObject(_loaded));
     }
     // Добавляем библиотеки как обработки
     AddLibrariesAsDataProcessors(dataProcessors);
     _hostedScript.EngineInstance.Environment.SetGlobalProperty("Обработки", new ScriptEngine.HostedScript.Library.FixedStructureImpl(dataProcessors));
 }
コード例 #3
0
        void AddLibrariesAsDataProcessors(ScriptEngine.HostedScript.Library.StructureImpl dataProcessors)
        {
            System.Collections.Specialized.NameValueCollection appSettings = System.Web.Configuration.WebConfigurationManager.AppSettings;

            foreach (string typeInfo in appSettings.AllKeys)
            {
                string info = typeInfo.Replace(" ", "");
                if (info.StartsWith("attachAsDataProcessor;"))
                {
                    // Запись должна быть вида <key="attachAsDataProcessor;ИмяСборки;ИмяТипа" value="[ИмяОбработки]" />
                    // Если пункта ИмяОбработки нет - получаем из атрибута класса
                    string[] dataProcessorInfo = info.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);

                    if (dataProcessorInfo.Length != 3)
                    {
                        continue;
                    }

                    string typeName          = dataProcessorInfo[2].Trim();
                    string dataProcessorName = appSettings[typeInfo] ?? "";
                    dataProcessorName = dataProcessorName.Replace(" ", "");
                    string assemblyName = dataProcessorInfo[1].Trim();
                    object instance     = Activator.CreateInstance(assemblyName, typeName).Unwrap();

                    if (dataProcessorName == "")
                    {
                        ContextClassAttribute attribute = instance.GetType().GetCustomAttributes(typeof(ContextClassAttribute), false).FirstOrDefault() as ContextClassAttribute;

                        if (attribute != null)
                        {
                            dataProcessorName = attribute.GetName();
                        }
                        else
                        {
                            continue;
                        }
                    }

                    dataProcessors.Insert(dataProcessorName, (IValue)instance);
                }
            }
        }