Exemple #1
0
        public IValue MoveToContent()
        {
            var nodeType = _reader.MoveToContent();

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

            enumeration._valuesCache.TryGetValue(native, out XSComplexFinal value);
            return(value);
        }
Exemple #3
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);
            }
        }
        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));
        }
        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);
            }
        }
Exemple #6
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 #7
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 #8
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 #9
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 #10
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 #11
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);
            }
        }
Exemple #13
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));
            }
        }
Exemple #14
0
        private void AddSingleFile(string file, SelfAwareEnumValue <ZipStorePathModeEnum> storePathMode)
        {
            var storeModeEnum = GlobalsManager.GetEnum <ZipStorePathModeEnum>();

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

            string pathInArchive;

            if (storePathMode == storeModeEnum.StoreFullPath)
            {
                pathInArchive = null;
            }
            else
            {
                pathInArchive = "";
            }


            _zip.AddFile(file, pathInArchive);
        }
Exemple #15
0
        private void AddSingleFile(string file, SelfAwareEnumValue <ZipStorePathModeEnum> storePathMode)
        {
            var storeModeEnum = GlobalsManager.GetEnum <ZipStorePathModeEnum>();

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

            var currDir = Directory.GetCurrentDirectory();

            string pathInArchive;

            if (storePathMode == storeModeEnum.StoreFullPath)
            {
                pathInArchive = null;
            }
            else if (storePathMode == storeModeEnum.StoreRelativePath)
            {
                var relativePath = GetRelativePath(file, currDir);
                if (relativePath == "")
                {
                    pathInArchive = ".";
                }
                else
                {
                    pathInArchive = Path.GetDirectoryName(relativePath);
                }
            }
            else
            {
                pathInArchive = "";
            }

            _zip.AddFile(file, pathInArchive);
        }
Exemple #16
0
        void SetNewLineChars(TextWriter textWriter)
        {
            if (_settings != null)
            {
                if (_settings.NewLines != null)
                {
                    var NewLines      = _settings.NewLines.GetRawValue() as SelfAwareEnumValue <JSONLineBreakEnum>;
                    var LineBreakEnum = GlobalsManager.GetEnum <JSONLineBreakEnum>();

                    if (NewLines == LineBreakEnum.Unix)
                    {
                        textWriter.NewLine = "\n";
                    }
                    else if (NewLines == LineBreakEnum.Windows)
                    {
                        textWriter.NewLine = "\r\n";
                    }
                    else if (NewLines == LineBreakEnum.Auto)
                    {
                        if (System.Environment.OSVersion.Platform == PlatformID.Unix || System.Environment.OSVersion.Platform == PlatformID.MacOSX)
                        {
                            textWriter.NewLine = "\n";
                        }
                        else
                        {
                            textWriter.NewLine = "\r\n";
                        }
                    }
                    else
                    {
                        textWriter.NewLine = ""; //Нет
                        _writer.Formatting = Formatting.None;
                    }
                }
            }
        }
Exemple #17
0
 void OnTimerElapsed(object state)
 {
     answer = GlobalsManager.GetEnum <DialogReturnCodeEnum>()[_defaultButton.ToString()];
     _form.Close();
     _timeoutTimer.Dispose();
 }
Exemple #18
0
        private bool IsEndElement()
        {
            var isEnd = (NodeType == GlobalsManager.GetEnum <XmlNodeTypeEnum>().FromNativeValue(XmlNodeType.EndElement));

            return(isEnd);
        }
Exemple #19
0
        public int StrFind(string haystack, string needle, SelfAwareEnumValue <SearchDirectionEnum> direction = null, int startPos = 0, int occurance = 0)
        {
            int len = haystack.Length;

            if (len == 0 || needle.Length == 0)
            {
                return(0);
            }

            if (direction == null)
            {
                direction = GlobalsManager.GetEnum <SearchDirectionEnum>().FromBegin as SelfAwareEnumValue <SearchDirectionEnum>;
            }

            bool fromBegin = direction == GlobalsManager.GetEnum <SearchDirectionEnum>().FromBegin;

            if (startPos == 0)
            {
                startPos = fromBegin ? 1 : len;
            }

            if (startPos < 1 || startPos > len)
            {
                throw RuntimeException.InvalidArgumentValue();
            }

            if (occurance == 0)
            {
                occurance = 1;
            }

            int startIndex = startPos - 1;
            int foundTimes = 0;
            int index      = len + 1;

            if (fromBegin)
            {
                while (foundTimes < occurance && index >= 0)
                {
                    index = haystack.IndexOf(needle, startIndex);
                    if (index >= 0)
                    {
                        startIndex = index + 1;
                        foundTimes++;
                    }
                    if (startIndex >= len)
                    {
                        break;
                    }
                }
            }
            else
            {
                while (foundTimes < occurance && index >= 0)
                {
                    index = haystack.LastIndexOf(needle, startIndex);
                    if (index >= 0)
                    {
                        startIndex = index - 1;
                        foundTimes++;
                    }
                    if (startIndex < 0)
                    {
                        break;
                    }
                }
            }

            if (foundTimes == occurance)
            {
                return(index + 1);
            }
            else
            {
                return(0);
            }
        }
Exemple #20
0
 private void buttonClick(object sender, EventArgs e)
 {
     answer = GlobalsManager.GetEnum <DialogReturnCodeEnum>()[((Button)sender).Name];
     _form.Close();
 }