Ejemplo n.º 1
0
 public FixedStructureImpl(StructureImpl structure)
 {
     foreach (KeyAndValueImpl keyValue in structure)
     {
         _structure.Insert(keyValue.Key.AsString(), keyValue.Value);
     }
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 4
0
        public IRuntimeContextInstance LoadScript(string path, StructureImpl externalContext = null)
        {
            var compiler = EngineInstance.GetCompilerService();

            if (externalContext == null)
            {
                return(EngineInstance.AttachedScriptsFactory.LoadFromPath(compiler, path));
            }
            else
            {
                ExternalContextData extData = new ExternalContextData();

                foreach (var item in externalContext)
                {
                    extData.Add(item.Key.AsString(), item.Value);
                }

                return(EngineInstance.AttachedScriptsFactory.LoadFromPath(compiler, path, extData));
            }
        }
Ejemplo n.º 5
0
 public FixedStructureImpl(string strProperties, params IValue[] values)
 {
     _structure = new StructureImpl(strProperties, values);
 }
Ejemplo n.º 6
0
        public IRuntimeContextInstance LoadScript(string path, StructureImpl externalContext = null)
        {
            var compiler = EngineInstance.GetCompilerService();
            if(externalContext == null)
                return EngineInstance.AttachedScriptsFactory.LoadFromPath(compiler, path);
            else
            {
                ExternalContextData extData = new ExternalContextData();

                foreach (var item in externalContext)
                {
                    var kv = item as KeyAndValueImpl;
                    extData.Add(kv.Key.AsString(), kv.Value);
                }

                return EngineInstance.AttachedScriptsFactory.LoadFromPath(compiler, path, extData);

            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Создает фиксированную структуру по исходной структуре
 /// </summary>
 /// <param name="structure">Исходная структура</param>
 //[ScriptConstructor(Name = "Из структуры")]
 private static FixedStructureImpl Constructor(StructureImpl structObject)
 {
     return(new FixedStructureImpl(structObject));
 }