public PostRequestData(string data) { MapImpl m_params = new MapImpl(); var pairs = data.Split('&'); foreach (var pair in pairs) { var nameVal = pair.Split(new Char[] { '=' }, 2); if (nameVal.Length == 2) { IValue key = ValueFactory.Create(Decode(nameVal[0])); IValue val = ValueFactory.Create(Decode(nameVal[1])); m_params.Insert(key, val); } else if (pair.Length > 0) { IValue val = ValueFactory.Create(Decode(pair)); m_params.Insert(val, ValueFactory.Create()); } _params = new FixedMapImpl(m_params); _files = new FixedMapImpl(new MapImpl()); } }
public IValue Consume(int WaitTime = 1000) { var consumer = consumerAsync; while (true) { try { var consumeResult = consumer.Consume(WaitTime); if (consumeResult != null) { if (consumeResult.IsPartitionEOF) { Console.WriteLine($"Reached end of topic {consumeResult.Topic}, partition {consumeResult.Partition}, offset {consumeResult.Offset}."); return(ValueFactory.Create()); } var obj = new MapImpl(); latestOffset = obj; obj.Insert( ValueFactory.Create("Канал"), ValueFactory.Create( consumeResult.TopicPartitionOffset.Topic ) ); obj.Insert( ValueFactory.Create("Раздел"), ValueFactory.Create( consumeResult.TopicPartitionOffset.Partition ) ); obj.Insert( ValueFactory.Create("Смещение"), ValueFactory.Create( consumeResult.TopicPartitionOffset.Offset ) ); return(ValueFactory.Create(consumeResult.Message.Value)); } } catch (ConsumeException e) { throw new Exception( $"Error occured: {e.Error.Reason}" ); } } }
public HTTPServiceRequestImpl(System.Web.HttpContext ctx) { _httpContext = ctx; // Инициализируем объект для 1С // Заголовки MapImpl headers = new MapImpl(); for (int i = 0; i < _httpContext.Request.Headers.Count; i++) { headers.Insert(ValueFactory.Create(_httpContext.Request.Headers.GetKey(i)) , ValueFactory.Create(_httpContext.Request.Headers.Get(i)) ); } this._headers = new FixedMapImpl(headers); // ПараметрыURL будут пустыми _urlParams = new FixedMapImpl(new MapImpl()); // Параметры запроса MapImpl queryOptions = new MapImpl(); for (int i = 0; i < _httpContext.Request.Params.Count; i++) { queryOptions.Insert(ValueFactory.Create(_httpContext.Request.Params.GetKey(i)) , ValueFactory.Create(_httpContext.Request.Params.Get(i)) ); } _queryOptions = new FixedMapImpl(queryOptions); _context = new HTTPServiceContextImpl(_httpContext); }
private void ProcessHeaders(WebHeaderCollection webHeaderCollection) { foreach (var item in webHeaderCollection.AllKeys) { _headers.Insert(ValueFactory.Create(item), ValueFactory.Create(webHeaderCollection[item])); } }
/// <summary> /// Строит объекты OneScript на основе результатов парсинга /// </summary> /// <param name="source"></param> /// <returns></returns> private IValue BuildResults(object source) { if (source == null) { return(ValueFactory.Create()); } if (source is List <object> ) { ArrayImpl array = new ArrayImpl(); foreach (object element in (List <object>)source) { array.Add(BuildResults(element)); } return(array); } if (source is Dictionary <object, object> ) { MapImpl map = new MapImpl(); foreach (var element in (Dictionary <object, object>)source) { map.Insert(BuildResults(element.Key), BuildResults(element.Value)); } return(map); } if (source is bool) { return(ValueFactory.Create(System.Convert.ToBoolean(source))); } if (source is sbyte || source is byte || source is short || source is ushort || source is int || source is uint || source is long || source is ulong || source is float || source is double || source is decimal ) { return(ValueFactory.Create(System.Convert.ToDecimal(source))); } if (source is DateTime) { return(ValueFactory.Create(System.Convert.ToDateTime(source))); } // Строка или нечто другое return(ValueFactory.Create(System.Convert.ToString(source))); }
private void FillEnvironmentVars() { foreach (DictionaryEntry item in Environment.GetEnvironmentVariables()) { _environmentVars.Insert( ValueFactory.Create((string)item.Key), ValueFactory.Create((string)item.Value)); } }
private void ParseFormData(string data, MapImpl map) { var pairs = data.Split('&'); foreach (var pair in pairs) { var nameVal = pair.Split(new Char[] { '=' }, 2); if (nameVal.Length == 2) { IValue key = ValueFactory.Create(nameVal[0]); IValue val = ValueFactory.Create(Decode(nameVal[1])); map.Insert(key, val); } else if (pair.Length > 0) { IValue val = ValueFactory.Create(Decode(pair)); map.Insert(val, ValueFactory.Create()); } } }
public MapImpl QueryParameters() { MapImpl result = new MapImpl(); foreach (var kv in _realObject.Query) { result.Insert(ValueFactory.Create(kv.Key), ValueFactory.Create(kv.Value)); } return(result); }
private void FillEnvironmentVars() { MapImpl vars = new MapImpl(); foreach (DictionaryEntry item in Environment.GetEnvironmentVariables()) { vars.Insert( ValueFactory.Create((string)item.Key), ValueFactory.Create((string)item.Value)); } _environmentVars = new FixedMapImpl(vars); }
public void MapPresentation() { var obj = new MapImpl(); obj.Insert(ValueFactory.Create("first"), ValueFactory.Create(1)); obj.Insert(ValueFactory.Create("second"), ValueFactory.Create(2)); var debuggerVar = Visualizer.GetVariable(Variable.Create(obj, "myVar")); Assert.That(debuggerVar.Presentation, Is.EqualTo("Соответствие")); Assert.That(debuggerVar.IsStructured, Is.True); var items = Visualizer.GetChildVariables(obj) .Select(x => Visualizer.GetVariable(x)) .ToArray(); Assert.That(items, Has.Length.EqualTo(2)); Assert.That(items[0].Name, Is.EqualTo("0")); Assert.That(items[0].TypeName, Is.EqualTo("КлючИЗначение")); Assert.That(items[0].Presentation, Is.EqualTo("КлючИЗначение")); Assert.That(items[0].IsStructured, Is.True); Assert.That(items[1].Name, Is.EqualTo("1")); Assert.That(items[1].TypeName, Is.EqualTo("КлючИЗначение")); Assert.That(items[1].Presentation, Is.EqualTo("КлючИЗначение")); Assert.That(items[1].IsStructured, Is.True); var keyValue = Visualizer.GetChildVariables(obj.First()) .Select(x => Visualizer.GetVariable(x)) .ToArray(); Assert.That(keyValue[0].Name, Is.EqualTo("Ключ")); Assert.That(keyValue[0].Presentation, Is.EqualTo("first")); Assert.That(keyValue[1].Name, Is.EqualTo("Значение")); Assert.That(keyValue[1].Presentation, Is.EqualTo("1")); }
public MapImpl QueryParameters() { var result = new MapImpl(); foreach (var(key, value) in _realObject.Query) { var valueToInsert = value.Count > 1 ? new ArrayImpl(value.Select(ValueFactory.Create)) : ValueFactory.Create(value); result.Insert( ValueFactory.Create(key), valueToInsert); } return(result); }
public string Handle(string requestBody) { var headers = new MapImpl(); headers.Insert(ValueFactory.Create("Content-Type"), ValueFactory.Create("application/xml")); var request = HttpRequestContext.Constructor(ValueFactory.Create(Path), headers); request.SetBodyFromString(requestBody); var httpResponse = Connection.Post(request); if (httpResponse.StatusCode != 200) { throw new HttpTransportException(httpResponse); } var stringResponse = httpResponse.GetBodyAsString(ValueFactory.Create("UTF-8")).AsString(); return(stringResponse); }
public HTTPServiceRequestImpl(System.Web.HttpContext ctx) { _httpContext = ctx; // Инициализируем объект для 1С // Заголовки MapImpl headers = new MapImpl(); for (int i = 0; i < _httpContext.Request.Headers.Count; i++) { headers.Insert(ValueFactory.Create(_httpContext.Request.Headers.GetKey(i)) , ValueFactory.Create(_httpContext.Request.Headers.Get(i)) ); } this._headers = new FixedMapImpl(headers); // ПараметрыURL будут пустыми _urlParams = new FixedMapImpl(new MapImpl()); // Параметры запроса MapImpl queryOptions = new MapImpl(); // Изменено для совместимости. в 1С только параметры командной строки // Надо перенести в Контекст //for (int i = 0; i < _httpContext.Request.Params.Count; i++) // queryOptions.Insert(ValueFactory.Create(_httpContext.Request.Params.GetKey(i)) // , ValueFactory.Create(_httpContext.Request.Params.Get(i)) // ); for (int i = 0; i < _httpContext.Request.QueryString.Count; i++) { queryOptions.Insert(ValueFactory.Create(_httpContext.Request.QueryString.GetKey(i)) , ValueFactory.Create(_httpContext.Request.QueryString.Get(i)) ); } _queryOptions = new FixedMapImpl(queryOptions); _context = new HTTPServiceContextImpl(_httpContext); }
public PostRequestData(byte [] buffer, string boundary) { using (var stdin = new MemoryStream(buffer)) { var parser = new MultipartFormDataParser(stdin, boundary, Encoding.UTF8); MapImpl m_params = new MapImpl(); foreach (var param in parser.Parameters) { m_params.Insert(ValueFactory.Create(param.Name), ValueFactory.Create(param.Data)); } _params = new FixedMapImpl(m_params); MapImpl m_files = new MapImpl(); foreach (var file in parser.Files) { m_files.Insert( ValueFactory.Create(file.Name), ValueFactory.Create(new PostFileDescription(file)) ); } _files = new FixedMapImpl(m_files); } }
public IValue ReadJSONInMap(JSONReader Reader, bool nestedArray = false) { if (nestedArray) { ArrayImpl NestedArray = new ArrayImpl(); while (Reader.Read()) { if (Reader.CurrentJsonTokenType == JsonToken.EndArray) { break; } else if (Reader.CurrentJsonTokenType == JsonToken.StartObject) { NestedArray.Add(ReadJSONInMap(Reader)); } else if (Reader.CurrentJsonTokenType == JsonToken.StartArray) { NestedArray.Add(ReadJSONInMap(Reader, true)); } else { NestedArray.Add(Reader.CurrentValue); } } return(NestedArray); } MapImpl ResStruct = new MapImpl(); while ((Reader).Read()) { if (Reader.CurrentJsonTokenType == JsonToken.PropertyName) { string PropertyName = Reader.CurrentValue.AsString(); Reader.Read(); if (Reader.CurrentJsonTokenType == JsonToken.StartObject) { ResStruct.Insert(ValueFactory.Create(PropertyName), ReadJSONInMap(Reader)); } else if (Reader.CurrentJsonTokenType == JsonToken.StartArray) { ResStruct.Insert(ValueFactory.Create(PropertyName), ReadJSONInMap(Reader, true)); } else { ResStruct.Insert(ValueFactory.Create(PropertyName), Reader.CurrentValue); } } else if (Reader.CurrentJsonTokenType == JsonToken.EndObject) { break; } else if (Reader.CurrentJsonTokenType == JsonToken.StartArray) { return(ReadJSONInMap(Reader, true)); } } return(ResStruct); }
public override void CallAsFunction(int methodNumber, IValue [] arguments, out IValue retValue) { var operation = _operations [methodNumber]; retValue = ValueFactory.Create(); ConnectIfNeeded(); var headers = new MapImpl(); headers.Insert(ValueFactory.Create("Content-Type"), ValueFactory.Create("application/xml")); var xmlBody = XmlWriterImpl.Create(); xmlBody.SetString(ValueFactory.Create("UTF-8")); xmlBody.WriteStartElement("soap:Envelope"); xmlBody.WriteNamespaceMapping("xsi", "http://www.w3.org/2001/XMLSchema-instance"); xmlBody.WriteNamespaceMapping("xsd", "http://www.w3.org/2001/XMLSchema"); xmlBody.WriteNamespaceMapping("soap", "http://schemas.xmlsoap.org/soap/envelope/"); xmlBody.WriteNamespaceMapping("s", Endpoint.Interface.NamespaceURI); xmlBody.WriteStartElement("soap:Body"); var serializer = XdtoSerializerImpl.Constructor(XdtoFactory) as XdtoSerializerImpl; operation.WriteRequestBody(xmlBody, serializer, arguments); xmlBody.WriteEndElement(); // soap:Body xmlBody.WriteEndElement(); // soap:Envelope var requestString = xmlBody.Close().ToString(); if (DoDebug) { Console.WriteLine(requestString); } var responseText = _transport.Handle(requestString); var xmlResult = XmlReaderImpl.Create() as XmlReaderImpl; if (DoDebug) { Console.WriteLine(responseText); } // TODO: Отдать на разбор фабрике xmlResult.SetString(responseText); var result = operation.ParseResponse(xmlResult, serializer); if (result is SoapExceptionResponse) { throw new ScriptEngine.Machine.RuntimeException((result as SoapExceptionResponse).FaultMessage); } var soapResponse = result as SuccessfulSoapResponse; retValue = soapResponse.RetValue; foreach (var outParamData in soapResponse.OutputParameters) { var argument = arguments [outParamData.Key] as IVariable; if (argument == null) { continue; } argument.Value = outParamData.Value; } }