コード例 #1
0
        public void Write(string path, IValue encoding = null, string lineSeparator = null)
        {
            using (var writer = GetDefaultWriter(path, encoding))
            {
                if (lineSeparator == null)
                {
                    lineSeparator = "\r\n";
                }
                else if (lineSeparator != "\n" && lineSeparator != "\r" && lineSeparator != "\r\n")
                {
                    throw RuntimeException.InvalidArgumentValue();
                }

                foreach (var line in _lines)
                {
                    writer.Write(line);
                    writer.Write(lineSeparator);
                }
            }

            UsedFileName = Path.GetFullPath(path);
        }
        public bool AuthorizeByPassword(InfobaseUserContext user, string password, bool remember = false)
        {
            if (user == null)
            {
                throw RuntimeException.InvalidArgumentValue();
            }

            var manager = GetUsersManager();
            var appUser = manager.FindByIdAsync(user.UserId).Result;

            if (appUser == null)
            {
                return(false);
            }

            var signer = _requestAccessor.HttpContext.RequestServices.GetRequiredService <SignInManager <ApplicationUser> >();

            signer.SignOutAsync().Wait();
            var result = signer.PasswordSignInAsync(appUser, password, remember, false).Result;

            return(result.Succeeded);
        }
コード例 #3
0
        public HttpConnectionContext(string host,
                                     int port                   = 0,
                                     string user                = null,
                                     string password            = null,
                                     InternetProxyContext proxy = null,
                                     int timeout                = 0,
                                     IValue ssl                 = null,
                                     bool useOSAuth             = false)
        {
            if (ssl != null && !(ssl.DataType == Machine.DataType.Undefined || ssl.DataType == Machine.DataType.NotAValidValue))
            {
                throw new RuntimeException("Защищенное соединение по произвольным сертификатам не поддерживается. Если необходим доступ по https, просто укажите протокол https в адресе хоста.");
            }

            var uriBuilder = new UriBuilder(host);

            if (port != 0)
            {
                uriBuilder.Port = port;
            }

            if (uriBuilder.Scheme != HTTP_SCHEME && uriBuilder.Scheme != HTTPS_SCHEME)
            {
                throw RuntimeException.InvalidArgumentValue();
            }

            _hostUri = uriBuilder.Uri;

            Host = _hostUri.Host;
            Port = _hostUri.Port;

            User     = user == null ? String.Empty : user;
            Password = password == null ? String.Empty : password;

            Timeout             = timeout;
            _proxy              = proxy;
            UseOSAuthentication = useOSAuth;
            AllowAutoRedirect   = true;
        }
コード例 #4
0
        public StructureImpl(string strProperties, params IValue[] values)
        {
            var props = strProperties.Split(',');

            if (props.Length < values.Length)
            {
                throw RuntimeException.InvalidArgumentValue();
            }

            for (int i = 0; i < props.Length; i++)
            {
                props[i] = props[i].Trim();
                if (i < values.Length)
                {
                    Insert(props[i], values[i]);
                }
                else
                {
                    Insert(props[i], null);
                }
            }
        }
コード例 #5
0
ファイル: Reflector.cs プロジェクト: thedemoncat/OneScript
        private static Type GetReflectableClrType(TypeTypeValue type)
        {
            Type clrType;

            try
            {
                clrType = TypeManager.GetImplementingClass(type.Value.ID);
            }
            catch (InvalidOperationException)
            {
                throw RuntimeException.InvalidArgumentValue("Тип не может быть отражен.");
            }

            var attrs = clrType.GetCustomAttributes(typeof(ContextClassAttribute), false).ToArray();

            if (attrs.Length == 0)
            {
                throw RuntimeException.InvalidArgumentValue("Тип не может быть отражен.");
            }

            return(clrType);
        }
コード例 #6
0
        private IEnumerable <ValueTableRow> GetRowsEnumByArray(IValue Rows)
        {
            IEnumerable <ValueTableRow> requestedRows;
            var rowsArray = Rows.GetRawValue() as ArrayImpl;

            if (rowsArray == null)
            {
                throw RuntimeException.InvalidArgumentType();
            }

            requestedRows = rowsArray.Select(x =>
            {
                var vtr = x.GetRawValue() as ValueTableRow;
                if (vtr == null || vtr.Owner() != this)
                {
                    throw RuntimeException.InvalidArgumentValue();
                }

                return(vtr);
            });
            return(requestedRows);
        }
コード例 #7
0
        private static string ExtractExecutableName(string cmdLine, out int argsPosition)
        {
            bool inQuotes = false;
            int  startIdx = 0;
            int  i;

            for (i = 0; i < cmdLine.Length; i++)
            {
                var symb = cmdLine[i];

                if (symb == '\"')
                {
                    if (inQuotes)
                    {
                        argsPosition = i + 1;
                        return(cmdLine.Substring(startIdx, i - startIdx));
                    }

                    inQuotes = true;
                    startIdx = i + 1;
                }
                else if (symb == ' ' && !inQuotes)
                {
                    argsPosition = i + 1;
                    return(cmdLine.Substring(startIdx, i - startIdx));
                }
            }

            if (inQuotes)
            {
                throw RuntimeException.InvalidArgumentValue();
            }

            argsPosition = i + 1;
            return(cmdLine.Substring(startIdx, i - startIdx));
        }
コード例 #8
0
        private CompressionLevel MakeZipCompressionLevel(SelfAwareEnumValue <ZipCompressionLevelEnum> compressionLevel)
        {
            if (compressionLevel == null)
            {
                return(CompressionLevel.Default);
            }

            var owner = (ZipCompressionLevelEnum)compressionLevel.Owner;

            if (compressionLevel == owner.Minimal)
            {
                return(CompressionLevel.BestSpeed);
            }
            if (compressionLevel == owner.Optimal)
            {
                return(CompressionLevel.Default);
            }
            if (compressionLevel == owner.Maximal)
            {
                return(CompressionLevel.BestCompression);
            }

            throw RuntimeException.InvalidArgumentValue();
        }
コード例 #9
0
ファイル: Pop3Receiver.cs プロジェクト: regcpr1c/oscript-mail
        public ArrayImpl Get(bool deleteMessages, ArrayImpl ids, bool markAsRead)
        {
            if (markAsRead != true)
            {
                throw RuntimeException.InvalidArgumentValue();                 // TODO: Внятное сообщение
            }
            var result            = new ArrayImpl();
            var processedMessages = GetMessagesList(ids);

            foreach (var i in processedMessages)
            {
                var mimeMessage = client.GetMessage(i);
                var iMessage    = new InternetMailMessage(mimeMessage, client.GetMessageUid(i));
                result.Add(iMessage);
            }

            if (deleteMessages && processedMessages.Count > 0)
            {
                client.DeleteMessages(processedMessages);
                Relogon();
            }

            return(result);
        }
コード例 #10
0
ファイル: LibraryLoader.cs プロジェクト: shtorin/OneScript
        public void AddModule(string file, string moduleName)
        {
            if (!Utils.IsValidIdentifier(moduleName))
            {
                throw RuntimeException.InvalidArgumentValue();
            }

            _delayLoadedScripts.Add(new DelayLoadedScriptData()
            {
                path       = file,
                identifier = moduleName,
                asClass    = false
            });

            try
            {
                _env.InjectGlobalProperty(null, moduleName, true);
            }
            catch (InvalidOperationException e)
            {
                // символ уже определен
                throw new RuntimeException(String.Format("Невозможно загрузить модуль {0}. Такой символ уже определен.", moduleName), e);
            }
        }
コード例 #11
0
        public void ReplaceLine(int number, string newLine)
        {
            if (number > _lines.Count)
            {
                return;
            }

            if (number < 1)
            {
                throw RuntimeException.InvalidArgumentValue();
            }

            var newLines = ParseInputString(newLine);

            if (newLines.Count == 1)
            {
                _lines[number - 1] = newLines[0];
            }
            else
            {
                _lines[number - 1] = newLines[0];
                _lines.InsertRange(number, newLines.Skip(1));
            }
        }
コード例 #12
0
        private EncryptionAlgorithm MakeZipEncryption(SelfAwareEnumValue <ZipEncryptionMethodEnum> encryptionMethod)
        {
            if (encryptionMethod == null)
            {
                return(EncryptionAlgorithm.PkzipWeak);
            }

            var enumOwner = (ZipEncryptionMethodEnum)encryptionMethod.Owner;

            if (encryptionMethod == enumOwner.Zip20)
            {
                return(EncryptionAlgorithm.PkzipWeak);
            }
            if (encryptionMethod == enumOwner.Aes128)
            {
                return(EncryptionAlgorithm.WinZipAes128);
            }
            if (encryptionMethod == enumOwner.Aes256)
            {
                return(EncryptionAlgorithm.WinZipAes256);
            }

            throw RuntimeException.InvalidArgumentValue();
        }
コード例 #13
0
        private void SetMinOccurs(XmlSchemaParticle particle, IValue minOccurs)
        {
            if (minOccurs.DataType == DataType.Undefined)
            {
                particle.MinOccursString = null;
            }

            else if (minOccurs.DataType == DataType.Number)
            {
                decimal number = minOccurs.AsNumber();
                if (number >= 0)
                {
                    particle.MinOccurs = number;
                }
                else
                {
                    throw RuntimeException.InvalidArgumentValue();
                }
            }
            else
            {
                throw RuntimeException.InvalidArgumentType();
            }
        }
コード例 #14
0
        public void FillPropertyValues(IRuntimeContextInstance acceptor, IRuntimeContextInstance source, string filledProperties = null, string ignoredProperties = null)
        {
            var accReflector = acceptor as IReflectableContext;

            if (accReflector == null)
            {
                throw RuntimeException.InvalidArgumentValue();
            }

            var srcReflector = source as IReflectableContext;

            if (srcReflector == null)
            {
                throw RuntimeException.InvalidArgumentValue();
            }

            IEnumerable <string> sourceProperties;
            IEnumerable <string> ignoredPropCollection;

            if (filledProperties == null)
            {
                sourceProperties = srcReflector.GetProperties().Select(x => x.Identifier);
            }
            else
            {
                sourceProperties = filledProperties.Split(',')
                                   .Select(x => x.Trim())
                                   .Where(x => x.Length > 0)
                                   .ToArray();

                // Проверка существования заявленных свойств
                foreach (var item in sourceProperties)
                {
                    acceptor.FindProperty(item);
                }
            }

            if (ignoredProperties != null)
            {
                ignoredPropCollection = ignoredProperties.Split(',')
                                        .Select(x => x.Trim())
                                        .Where(x => x.Length > 0);
            }
            else
            {
                ignoredPropCollection = new string[0];
            }

            foreach (var srcProperty in sourceProperties.Where(x => !ignoredPropCollection.Contains(x)))
            {
                try
                {
                    var propIdx    = acceptor.FindProperty(srcProperty);
                    var srcPropIdx = source.FindProperty(srcProperty);

                    acceptor.SetPropValue(propIdx, source.GetPropValue(srcPropIdx));
                }
                catch (PropertyAccessException)
                {
                }
            }
        }
コード例 #15
0
ファイル: Reflector.cs プロジェクト: zeratulayuris/OneScript
 private static RuntimeException NonReflectableType()
 {
     return(RuntimeException.InvalidArgumentValue("Тип не может быть отражен."));
 }
コード例 #16
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);
            }
        }
コード例 #17
0
        public IValue ReadXML(XmlReaderImpl xmlReader, IValue valueType = null)
        {
            TypeTypeValue typeValue = null;

            if (valueType is TypeTypeValue typeTypeValue)
            {
                typeValue = typeTypeValue;
            }

            else if (xmlReader.NodeType == xmlNodeEnum.FromNativeValue(XmlNodeType.Element))
            {
                IValue xsiType = xmlReader.GetAttribute(ValueFactory.Create("type"), XmlSchema.InstanceNamespace);
                IValue xsiNil  = xmlReader.GetAttribute(ValueFactory.Create("nil"), XmlSchema.InstanceNamespace);

                if (xsiType.DataType == DataType.String)
                {
                    switch (xsiType.AsString())
                    {
                    case "string":
                        typeValue = new TypeTypeValue("String");
                        break;

                    case "decimal":
                        typeValue = new TypeTypeValue("Number");
                        break;

                    case "boolean":
                        typeValue = new TypeTypeValue("Boolean");
                        break;

                    case "dateTime":
                        typeValue = new TypeTypeValue("Date");
                        break;

                    default:
                        break;
                    }
                }
                else if (xsiNil.DataType == DataType.String)
                {
                    typeValue = new TypeTypeValue("Undefined");
                }
            }
            ;

            if (typeValue == null)
            {
                throw RuntimeException.InvalidArgumentValue();
            }

            Type implType = TypeManager.GetImplementingClass(typeValue.Value.ID);

            IValue result = ValueFactory.Create();

            if (typeValue.Equals(new TypeTypeValue("Undefined")))
            {
                result = ValueFactory.Create();
                xmlReader.Skip();
            }
            else if (implType == typeof(DataType))
            {
                xmlReader.Read();
                if (xmlReader.NodeType == xmlNodeEnum.FromNativeValue(XmlNodeType.Text))
                {
                    result = XMLValue(typeValue, xmlReader.Value);
                    xmlReader.Read();
                }
                else
                {
                    throw RuntimeException.InvalidArgumentValue();
                }
            }
            else if (typeof(IXDTOSerializableXML).IsAssignableFrom(implType))
            {
                result = Activator.CreateInstance(implType, new object[] { xmlReader, this }) as IValue;
            }

            xmlReader.Read();
            return(result);
        }
コード例 #18
0
        public int StrFind(string haystack, string needle, SearchDirection direction = SearchDirection.FromBegin, int startPos = 0, int occurance = 0)
        {
            int len = haystack.Length;

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

            bool fromBegin = direction == SearchDirection.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, StringComparison.Ordinal);
                    if (index >= 0)
                    {
                        startIndex = index + 1;
                        foundTimes++;
                    }
                    if (startIndex >= len)
                    {
                        break;
                    }
                }
            }
            else
            {
                while (foundTimes < occurance && index >= 0)
                {
                    index = haystack.LastIndexOf(needle, startIndex, StringComparison.Ordinal);
                    if (index >= 0)
                    {
                        startIndex = index - 1;
                        foundTimes++;
                    }
                    if (startIndex < 0)
                    {
                        break;
                    }
                }
            }

            if (foundTimes == occurance)
            {
                return(index + 1);
            }
            else
            {
                return(0);
            }
        }