public IValue ReadJSONDate(string String, IValue Format)
        {
            var format             = Format.GetRawValue() as SelfAwareEnumValue <JSONDateFormatEnum>;
            var JSONDateFormatEnum = GlobalsManager.GetEnum <JSONDateFormatEnum>();
            DateFormatHandling dateFormatHandling = new DateFormatHandling();

            if (format == JSONDateFormatEnum.ISO || format == null)
            {
                dateFormatHandling = DateFormatHandling.IsoDateFormat;
            }
            else if (format == JSONDateFormatEnum.Microsoft)
            {
                dateFormatHandling = DateFormatHandling.MicrosoftDateFormat;
            }
            else
            {
                throw new RuntimeException(Locale.NStr("ru='Формат даты JavaScript не поддерживается.'; en='JavaScript date format is not supported'"));
            }

            string json = @"{""Date"":""" + String + @"""}";

            var settings = new JsonSerializerSettings
            {
                DateFormatHandling = dateFormatHandling
            };
            var result = JsonConvert.DeserializeObject <ConvertedDate>(json, settings);

            return(ValueFactory.Create((DateTime)result.Date));
        }
Exemple #2
0
        private void AddEnumeratedFiles(IEnumerable <string> filesToAdd, string relativePath, SelfAwareEnumValue <ZipStorePathModeEnum> storePathMode)
        {
            var storeModeEnum = GlobalsManager.GetEnum <ZipStorePathModeEnum>();

            if (storePathMode == null)
            {
                storePathMode = (SelfAwareEnumValue <ZipStorePathModeEnum>)storeModeEnum.DontStorePath;
            }

            foreach (var item in filesToAdd)
            {
                string pathInArchive;
                if (storePathMode == storeModeEnum.StoreRelativePath)
                {
                    pathInArchive = Path.GetDirectoryName(GetRelativePath(item, relativePath));
                }
                else if (storePathMode == storeModeEnum.StoreFullPath)
                {
                    pathInArchive = null;
                }
                else
                {
                    pathInArchive = "";
                }

                _zip.AddFile(item, pathInArchive);
            }
        }
Exemple #3
0
        public IValue MoveToContent()
        {
            var nodeType = _reader.MoveToContent();

            CheckEmptyElementEntering();
            return(GlobalsManager.GetEnum <XmlNodeTypeEnum>().FromNativeValue(nodeType));
        }
Exemple #4
0
        internal static XSComplexFinal FromNativeValue(XmlSchemaDerivationMethod native)
        {
            EnumerationXSComplexFinal enumeration = GlobalsManager.GetEnum <EnumerationXSComplexFinal>();

            enumeration._valuesCache.TryGetValue(native, out XSComplexFinal value);
            return(value);
        }
Exemple #5
0
        public static ConsoleContext Constructor()
        {
            var provider = GlobalsManager.GetGlobalContext <ConsoleProvider>();

            SystemLogger.Write("WARNING: Constructor of Console is obsolete. Use global property Консоль/Console");

            return(provider.Console);
        }
Exemple #6
0
        public ScriptingEngine()
        {
            TypeManager.Initialize(new StandartTypeManager());
            GlobalsManager.Reset();
            ContextDiscoverer.DiscoverClasses(System.Reflection.Assembly.GetExecutingAssembly());

            _scriptFactory = new ScriptSourceFactory();
        }
Exemple #7
0
 private void Awake()
 {
     if (Instance == null)
     {
         Instance = this;
         DontDestroyOnLoad(gameObject);
     }
 }
        private static void RegisterSimpleEnum(Type enumType, RuntimeEnvironment environment)
        {
            var enumTypeAttribute = (EnumerationTypeAttribute)enumType.GetCustomAttributes(typeof(EnumerationTypeAttribute), false)[0];

            var type = TypeManager.RegisterType("Перечисление" + enumTypeAttribute.Name, typeof(EnumerationContext));

            if (enumTypeAttribute.Alias != null)
            {
                TypeManager.RegisterAliasFor(type, "Enum" + enumTypeAttribute.Alias);
            }

            var enumValueType = TypeManager.RegisterType(enumTypeAttribute.Name, enumType);

            var instance = new EnumerationContext(type, enumValueType);

            var wrapperTypeUndefined = typeof(CLREnumValueWrapper <>);
            var wrapperType          = wrapperTypeUndefined.MakeGenericType(new Type [] { enumType });
            var constructor          = wrapperType.GetConstructor(new Type [] { typeof(EnumerationContext), enumType, typeof(DataType) });

            foreach (var field in enumType.GetFields())
            {
                foreach (var contextFieldAttribute in field.GetCustomAttributes(typeof(EnumItemAttribute), false))
                {
                    var contextField = (EnumItemAttribute)contextFieldAttribute;
                    var osValue      = (EnumerationValue)constructor.Invoke(new object [] { instance, field.GetValue(null), DataType.Enumeration });

                    if (contextField.Alias == null)
                    {
                        if (StringComparer
                            .InvariantCultureIgnoreCase
                            .Compare(field.Name, contextField.Name) != 0)
                        {
                            instance.AddValue(contextField.Name, field.Name, osValue);
                        }
                        else
                        {
                            instance.AddValue(contextField.Name, osValue);
                        }
                    }
                    else
                    {
                        instance.AddValue(contextField.Name, contextField.Alias, osValue);
                    }
                }
            }

            if (enumTypeAttribute.CreateGlobalProperty)
            {
                GlobalsManager.RegisterInstance(enumType, instance);
                environment.InjectGlobalProperty(instance, enumTypeAttribute.Name, true);
                if (enumTypeAttribute.Alias != null)
                {
                    environment.InjectGlobalProperty(instance, enumTypeAttribute.Alias, true);
                }
            }
        }
    // Start is called before the first frame update
    void Start()
    {
        // find localization manager in globals
        // scan current for text field
        // replace by provided value
        LocalizationManager locaMgr = GlobalsManager.GetLocalizationManager();
        Text goText = GetComponent <Text>();

        goText.text = locaMgr.GetText(key);
    }
Exemple #10
0
        private void CreateDump(Stream output)
        {
            var offset = (int)output.Length;

            var engine = new HostedScriptEngine
            {
                CustomConfig = ScriptFileHelper.CustomConfigPath(_codePath)
            };

            engine.Initialize();
            ScriptFileHelper.OnBeforeScriptRead(engine);
            var source   = engine.Loader.FromFile(_codePath);
            var compiler = engine.GetCompilerService();

            engine.SetGlobalEnvironment(new DoNothingHost(), source);
            var entry = compiler.Compile(source);

            var embeddedContext = engine.GetUserAddedScripts();
            var templates       = GlobalsManager.GetGlobalContext <TemplateStorage>();

            var dump = new ApplicationDump();

            dump.Scripts = new UserAddedScript[]
            {
                new UserAddedScript()
                {
                    Image  = entry,
                    Symbol = "$entry",
                    Type   = UserAddedScriptType.Module
                }
            }.Concat(embeddedContext)
            .ToArray();
            dump.Resources = templates.GetTemplates()
                             .Select(SerializeTemplate)
                             .ToArray();

            using (var bw = new BinaryWriter(output))
            {
                var serializer = new BinaryFormatter();
                serializer.Serialize(output, dump);

                var signature = new byte[]
                {
                    0x4f,
                    0x53,
                    0x4d,
                    0x44
                };
                output.Write(signature, 0, signature.Length);

                bw.Write(offset);

                OutputToFile(output);
            }
        }
Exemple #11
0
 private void Awake()
 {
     if (Instance == null)
     {
         Instance = this;
     }
     else
     {
         Destroy(gameObject);
     }
 }
        public static Encoding GetEncoding(IValue encoding, bool addBOM = true)
        {
            if (encoding.DataType == DataType.String)
            {
                return(GetEncodingByName(encoding.AsString(), addBOM));
            }
            else
            {
                if (encoding.DataType != DataType.GenericValue)
                {
                    throw RuntimeException.InvalidArgumentType();
                }

                var encValue = encoding.GetRawValue() as SelfAwareEnumValue <TextEncodingEnum>;
                if (encValue == null)
                {
                    throw RuntimeException.InvalidArgumentType();
                }

                var encodingEnum = GlobalsManager.GetEnum <TextEncodingEnum>();

                Encoding enc;
                if (encValue == encodingEnum.Ansi)
                {
                    enc = Encoding.GetEncoding(1251);
                }
                else if (encValue == encodingEnum.Oem)
                {
                    enc = Encoding.GetEncoding(866);
                }
                else if (encValue == encodingEnum.Utf16)
                {
                    enc = new UnicodeEncoding(false, addBOM);
                }
                else if (encValue == encodingEnum.Utf8)
                {
                    enc = new UTF8Encoding(addBOM);
                }
                else if (encValue == encodingEnum.Utf8NoBOM)
                {
                    enc = new UTF8Encoding(false);
                }
                else if (encValue == encodingEnum.System)
                {
                    enc = Encoding.Default;
                }
                else
                {
                    throw RuntimeException.InvalidArgumentValue();
                }

                return(enc);
            }
        }
        public KeyValueConfig GetWorkingConfig()
        {
            var cfgAccessor = GlobalsManager.GetGlobalContext <SystemConfigAccessor>();

            if (!_configInitialized)
            {
                cfgAccessor.Provider = new EngineConfigProvider(CustomConfig);
                cfgAccessor.Refresh();
                _configInitialized = true;
            }
            return(cfgAccessor.GetConfig());
        }
        public ScriptingEngine()
        {
            _machine = MachineInstance.Current;

            TypeManager.Initialize(new StandartTypeManager());
            TypeManager.RegisterType("Сценарий", typeof(UserScriptContextInstance));

            GlobalsManager.Reset();
            AttachAssembly(System.Reflection.Assembly.GetExecutingAssembly());

            _scriptFactory     = new ScriptSourceFactory();
            DirectiveResolvers = new DirectiveMultiResolver();
        }
Exemple #15
0
        public void SortByValue(SelfAwareEnumValue <SortDirectionEnum> direction)
        {
            var enumInstance = GlobalsManager.GetEnum <SortDirectionEnum>();

            if (direction == enumInstance.Asc)
            {
                _items.Sort((x, y) => SafeCompare(x.Value, y.Value));
            }
            else
            {
                _items.Sort((x, y) => SafeCompare(y.Value, x.Value));
            }
        }
Exemple #16
0
        public void SortByPresentation(SelfAwareEnumValue <SortDirectionEnum> direction)
        {
            var enumInstance = GlobalsManager.GetEnum <SortDirectionEnum>();

            if (direction == enumInstance.Asc)
            {
                _items.Sort((x, y) => x.Presentation.CompareTo(y.Presentation));
            }
            else
            {
                _items.Sort((x, y) => y.Presentation.CompareTo(x.Presentation));
            }
        }
Exemple #17
0
        void WriteStringValue(string val)
        {
            string fval = val;

            if (_settings.EscapeCharacters != null)
            {
                var jsonCharactersEscapeMode     = _settings.EscapeCharacters.GetRawValue() as SelfAwareEnumValue <JSONCharactersEscapeModeEnum>;
                var jsonCharactersEscapeModeEnum = GlobalsManager.GetEnum <JSONCharactersEscapeModeEnum>();

                if (jsonCharactersEscapeMode == jsonCharactersEscapeModeEnum.NotASCIISymbols)
                {
                    StringWriter wr         = new StringWriter();
                    var          jsonWriter = new JsonTextWriter(wr);
                    jsonWriter.QuoteChar            = '\"';
                    jsonWriter.StringEscapeHandling = StringEscapeHandling.EscapeNonAscii;
                    new JsonSerializer().Serialize(jsonWriter, fval);
                    string str = wr.ToString();
                    fval = str.Substring(1, str.Length - 2);
                }
                else if (jsonCharactersEscapeMode == jsonCharactersEscapeModeEnum.SymbolsNotInBMP)
                {
                    throw new NotImplementedException("Свойство \"СимволыВнеBMP\" не поддерживается");
                }
            }

            if (_settings.EscapeSlash == true)
            {
                fval = fval.Replace("\\", "\\\\");
            }
            if (_settings.EscapeAngleBrackets == true)
            {
                fval = fval.Replace("<", "\\<");
                fval = fval.Replace(">", "\\>");
            }
            if (_settings.EscapeLineTerminators == true)
            {
                fval = fval.Replace("\r", "\\r").Replace("\n", "\\n");
            }
            if (_settings.EscapeAmpersand == true)
            {
                fval = fval.Replace("&", "\\&");
            }
            if (_settings.EscapeSingleQuotes == true || !_settings.UseDoubleQuotes)
            {
                fval = fval.Replace("'", "\\'");
            }


            _writer.WriteRawValue(_writer.QuoteChar + fval + _writer.QuoteChar);
        }
Exemple #18
0
        internal static XSForm FromNativeValue(XmlSchemaForm native)
        {
            switch (native)
            {
            case XmlSchemaForm.Qualified:
            case XmlSchemaForm.Unqualified:

                EnumerationXSForm enumeration = GlobalsManager.GetEnum <EnumerationXSForm>();
                return(enumeration._valuesCache[native]);

            default:
                return(null);
            }
        }
Exemple #19
0
        internal static XSSubstitutionGroupExclusions FromNativeValue(XmlSchemaDerivationMethod native)
        {
            switch (native)
            {
            case XmlSchemaDerivationMethod.All:
            case XmlSchemaDerivationMethod.Restriction:
            case XmlSchemaDerivationMethod.Extension:

                EnumerationXSSubstitutionGroupExclusions enumeration = GlobalsManager.GetEnum <EnumerationXSSubstitutionGroupExclusions>();
                return(enumeration._valuesCache[native]);

            default:
                return(null);
            }
        }
Exemple #20
0
    private void Awake()
    {
        gm          = GetComponent <GlobalsManager>();
        nodes       = new Dictionary <string, Node>(); //new List<string>();
        traces      = new Dictionary <string, Wire>(); //new List<string>();
        adjacencies = new List <List <string> >();

        route_types = new List <string>()
        {
            "hsquare", "diag", "direct", "vsquare", "rdiag"
        };
        off_grid      = new Vector3(-1000, 0, -1000);
        grid_center   = new Vector3(0, 0, 0);
        last_position = off_grid;
    }
Exemple #21
0
        private void SetOptions(IValue settings)
        {
            _settings = (JSONWriterSettings)settings.GetRawValue();
            if (_settings.UseDoubleQuotes)
            {
                _writer.QuoteChar = '\"';
            }
            else
            {
                _writer.QuoteChar = '\'';
            }

            if (_settings.PaddingSymbols != null && _settings.PaddingSymbols.Length > 0)
            {
                _writer.IndentChar = _settings.PaddingSymbols[0];
            }
            else
            {
                _writer.IndentChar = ' ';
            }

            if (_settings.PaddingSymbols != null && _settings.PaddingSymbols.Length > 0)
            {
                _writer.Indentation = 1;
            }
            else
            {
                _writer.Indentation = INDENT_SIZE;
            }
            _writer.Formatting = Formatting.Indented;

            if (_settings.EscapeCharacters != null)
            {
                var jsonCharactersEscapeMode     = _settings.EscapeCharacters.GetRawValue() as SelfAwareEnumValue <JSONCharactersEscapeModeEnum>;
                var jsonCharactersEscapeModeEnum = GlobalsManager.GetEnum <JSONCharactersEscapeModeEnum>();

                if (jsonCharactersEscapeMode == jsonCharactersEscapeModeEnum.NotASCIISymbols)
                {
                    _escapeNonAscii              = true;
                    _writer.QuoteChar            = '\"';
                    _writer.StringEscapeHandling = StringEscapeHandling.EscapeNonAscii;
                }
                else if (jsonCharactersEscapeMode == jsonCharactersEscapeModeEnum.SymbolsNotInBMP)
                {
                    throw new NotImplementedException("Свойство \"СимволыВнеBMP\" не поддерживается");
                }
            }
        }
        public static XSSimpleFinal FromNativeValue(XmlSchemaDerivationMethod native)
        {
            switch (native)
            {
            case XmlSchemaDerivationMethod.All:
            case XmlSchemaDerivationMethod.Union:
            case XmlSchemaDerivationMethod.Restriction:
            case XmlSchemaDerivationMethod.List:

                EnumerationXSSimpleFinal enumeration = GlobalsManager.GetEnum <EnumerationXSSimpleFinal>();
                return(enumeration._valuesCache[native]);

            default:
                return(null);
            }
        }
        public ApplicationInstance CreateApp()
        {
            var codeSrc = new FileInfoCodeSource(_scripts.GetFileInfo("main.os"));

            _webEng.Environment.InjectObject(new WebGlobalContext(this, codeSrc, _webEng));

            var templateFactory = new DefaultTemplatesFactory();

            var storage = new TemplateStorage(templateFactory);

            _webEng.Environment.InjectObject(storage);
            _webEng.Engine.UpdateContexts();
            GlobalsManager.RegisterInstance(storage);

            return(ApplicationInstance.Create(codeSrc, _webEng));
        }
        private static void RegisterSystemEnum(Type enumType, RuntimeEnvironment environment)
        {
            var method = enumType.GetMethod(INSTANCE_RETRIEVER_NAME, System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);

            System.Diagnostics.Trace.Assert(method != null, "System enum must have a static method " + INSTANCE_RETRIEVER_NAME);

            var instance = (IValue)method.Invoke(null, null);

            GlobalsManager.RegisterInstance(instance);
            var enumMetadata = (SystemEnumAttribute)enumType.GetCustomAttributes(typeof(SystemEnumAttribute), false)[0];

            environment.InjectGlobalProperty(instance, enumMetadata.GetName(), true);
            if (enumMetadata.GetAlias() != String.Empty)
            {
                environment.InjectGlobalProperty(instance, enumMetadata.GetAlias(), true);
            }
        }
        private static void RegisterGlobalContext(Type contextType, RuntimeEnvironment environment)
        {
            var attribData = (GlobalContextAttribute)contextType.GetCustomAttributes(typeof(GlobalContextAttribute), false)[0];

            if (attribData.ManualRegistration)
            {
                return;
            }

            var method = contextType.GetMethod(INSTANCE_RETRIEVER_NAME, System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);

            System.Diagnostics.Trace.Assert(method != null, "Global context must have a static method " + INSTANCE_RETRIEVER_NAME);
            var instance = (IAttachableContext)method.Invoke(null, null);

            GlobalsManager.RegisterInstance(instance);
            environment.InjectObject(instance, false);
        }
Exemple #26
0
	void Awake()
    {
        // If we have no set instance, set the instance to this
        if (instance == null)
        {
            instance = this;
        }

        // Otherwise, if we have an instance, and that instance is not this, destroy the game object
        // to prevent duplicates
        else if (instance != this)
        {
            Destroy(gameObject);
        }

        // Preserve this object
        DontDestroyOnLoad(gameObject);
    }
Exemple #27
0
    void Awake()
    {
        // If we have no set instance, set the instance to this
        if (instance == null)
        {
            instance = this;
        }

        // Otherwise, if we have an instance, and that instance is not this, destroy the game object
        // to prevent duplicates
        else if (instance != this)
        {
            Destroy(gameObject);
        }

        // Preserve this object
        DontDestroyOnLoad(gameObject);
    }
        public HostedScriptEngine()
        {
            _engine = new ScriptingEngine();
            _env    = new RuntimeEnvironment();
            _engine.AttachAssembly(System.Reflection.Assembly.GetExecutingAssembly(), _env);

            _globalCtx = new SystemGlobalContext();
            _globalCtx.EngineInstance = _engine;

            _env.InjectObject(_globalCtx, false);

            InitializationCallback = (eng, env) =>
            {
                var templateFactory = new DefaultTemplatesFactory();
                var storage         = new TemplateStorage(templateFactory);
                env.InjectObject(storage);
                GlobalsManager.RegisterInstance(storage);
            };

            _engine.Environment = _env;
        }
Exemple #29
0
        private static IValue ConvertEnum(object objParam, Type type)
        {
            if (!type.IsAssignableFrom(objParam.GetType()))
            {
                throw new RuntimeException("Некорректный тип конвертируемого перечисления");
            }

            var memberInfo = type.GetMember(objParam.ToString());
            var valueInfo  = memberInfo.FirstOrDefault(x => x.DeclaringType == type);
            var attrs      = valueInfo.GetCustomAttributes(typeof(EnumItemAttribute), false);

            if (attrs.Length == 0)
            {
                throw new RuntimeException("Значение перечисления должно быть помечено атрибутом EnumItemAttribute");
            }

            var itemName = ((EnumItemAttribute)attrs[0]).Name;
            var enumImpl = GlobalsManager.GetSimpleEnum(type);

            return(enumImpl.GetPropValue(itemName));
        }
        public Process CreateProcess(Stream sourceStream, IHostApplication host)
        {
            var appDump         = DeserializeAppDump(sourceStream);
            var engine          = new HostedScriptEngine();
            var src             = new BinaryCodeSource();
            var templateStorage = new TemplateStorage(new StandaloneTemplateFactory());

            engine.SetGlobalEnvironment(host, src);
            engine.InitializationCallback = (e, env) =>
            {
                e.Environment.InjectObject(templateStorage);
                GlobalsManager.RegisterInstance(templateStorage);
            };
            engine.Initialize();

            LoadResources(templateStorage, appDump.Resources);
            LoadScripts(engine, appDump.Scripts);

            var process = engine.CreateProcess(host, appDump.Scripts[0].Image, src);

            return(process);
        }
Exemple #31
0
        public string EncodeString(string sourceString, SelfAwareEnumValue <StringEncodingMethodEnum> codeType, IValue encoding = null)
        {
            var      encMethod = GlobalsManager.GetEnum <StringEncodingMethodEnum>();
            Encoding enc;

            if (encoding != null)
            {
                enc = TextEncodingEnum.GetEncoding(encoding);
            }
            else
            {
                enc = Encoding.UTF8;
            }

            if (codeType == encMethod.URLEncoding)
            {
                return(EncodeStringImpl(sourceString, enc, false));
            }
            else
            {
                return(EncodeStringImpl(sourceString, enc, true));
            }
        }