我想运行一组通常在telnet中运行的命令(来自c#).
例如,我想运行以下内容
using System;
using System.Diagnostics;
namespace InteractWithConsoleApp
{
class Program
{
static void Main(string[] args)
{
ProcessStartInfo cmdStartInfo = new ProcessStartInfo();
cmdStartInfo.FileName = @"C:\Windows\System32\cmd.exe";
cmdStartInfo.RedirectStandardOutput = true;
cmdStartInfo.RedirectStandardError = true;
cmdStartInfo.RedirectStandardInput = true;
cmdStartInfo.UseShellExecute = false;
cmdStartInfo.CreateNoWindow = true;
Process cmdProcess = new Process();
cmdProcess.StartInfo = cmdStartInfo;
cmdProcess.ErrorDataReceived += cmd_Error;
cmdProcess.OutputDataReceived += cmd_DataReceived;
cmdProcess.EnableRaisingEvents = true;
cmdProcess.Start();
cmdProcess.BeginOutputReadLine();
cmdProcess.BeginErrorReadLine();
cmdProcess.StandardInput.WriteLine("telnet telehack.com");
int milliseconds = 2000;
System.Threading.Thread.Sleep(milliseconds);
cmdProcess.StandardInput.WriteLine("exit");
cmdProcess.StandardInput.WriteLine("exit");
cmdProcess.WaitForExit();
}
static void cmd_DataReceived(object sender, DataReceivedEventArgs e)
{
Console.WriteLine(e.Data);
} …Run Code Online (Sandbox Code Playgroud) 我在elasticSearch中遇到以下错误:
[结果窗口太大,+大小必须小于或等于:[10000]但是[100000].
有关请求大型数据集的更有效方法,请参阅scroll api.可以通过更改[index.max_result_window]索引级别参数来设置此限制.]我无法获取我们必须设置的文件
index.max_result_window = 50000;
Run Code Online (Sandbox Code Playgroud) 我需要将json-string转换为python对象.按对象我的意思是"新"python3对象,如:
class MyClass(object):
Run Code Online (Sandbox Code Playgroud)
我在jsonpickle文档中找到了一些帮助.但我发现的只是教程,它首先将对象转换为json,然后向后转换.
我想从Rest-API转换json-string .
这是我到目前为止所做的:
import requests
import jsonpickle
class Goal(object):
def __init__(self):
self.GoaldID = -1
self.IsPenalty = False
class Match(object):
def __init__(self):
self.Goals = []
headers = {
"Content-Type": "application/json; charset=utf-8"
}
url = "https://www.openligadb.de/api/getmatchdata/39738"
result = requests.get(url=url, headers=headers)
obj = jsonpickle.decode(result.json)
print (obj)
Run Code Online (Sandbox Code Playgroud)
这导致:
TypeError: the JSON object must be str, bytes or bytearray, not 'method'
Run Code Online (Sandbox Code Playgroud)
我很清楚,jsonpickle无法将其转换为我的类(目标,匹配),因为我没有告诉jsonpickle应该在哪个类中转换输出.问题是我不知道如何告诉jsonpickle从对象类型转换对象中的JSON?我怎么能说出目标列表应该是类型List<Goal>?
我的老板要我创建具有打印功能的窗口表单,但他想打印datagridview后预览.
所以现在我鼓励这个问题,单击打印按钮时,我无法打印多套纸张或选择打印机或进行任何更改printpreviewdialog.当我单击按钮时,它将直接打印纸张.所以我希望加入printpreviewdialog和printdialog.
为什么printpreviewdialog而printdialog只能在不同的按钮可以使用?当需要单击一个按钮进行预览并单击另一个按钮来打印多个设置并更改打印机时,缺乏可用性.
任何人都可以帮助我吗?
PrintDialog类
DialogResult result = printDialog1.ShowDialog();
// If the result is OK then print the document.
if (result == DialogResult.OK)
{
position = 0;
pageno = 1;
printDocument2.DefaultPageSettings.Margins = new Margins(20, 20, 20, 20);
printDocument2.OriginAtMargins = true;
printPreviewDialog1.Document = printDocument2;
printPreviewDialog1.ShowDialog();
}
Run Code Online (Sandbox Code Playgroud)
PrintPreviewDialog上
printDocument3.DefaultPageSettings.Margins = new Margins(20, 20, 20, 20);
printDocument3.OriginAtMargins = true;
//((ToolStripButton)((ToolStrip)printPreviewDialog1.Controls[1]).Items[0]).Enabled = false;
printPreviewDialog1.Document = printDocument3;
printPreviewDialog1.ShowDialog();
Run Code Online (Sandbox Code Playgroud) 我的数据库中有一个大表,我需要更新内部调用的"ColorByte"字段.此字段根据RGB值计算,主要由Excel-VBA Skripts使用,但也在WinForms C#应用程序中使用.它表示一个表示特定颜色的整数值.
这在VBA中起作用如下(没有工作代码只是为了澄清):
r = 5
g = 50
b = 200
colorByte = RGB(r,g,b)
Run Code Online (Sandbox Code Playgroud)
在这里阅读有关RGB功能的更多信息.
现在我得到了一个复杂的计算方案,用于从公司特定数据中提出更好的RGB值,由我们的研究团队成员在VBA中开发.我必须在数据库上定义这个计算,以便轻松更新我的大表并更正"colorByte"字段.确切的计算并不重要,因为这些东西有效但是:
是否有相当于VBA RGB(r, g, b)功能,我可以在PL/SQL中使用它来完成我的功能?
或者有人知道这个函数内部做了什么,以便我可以在PL/SQL中重新定义它吗?
如何System.Collection.IEnumerable在C#中转换为列表?实际上,我正在执行一个存储过程,该过程给了我ResultSets,System.Collection.IEnumerable并且我想将该结果集转换为c#List<User>。
注意我不想使用任何循环。有没有一种类型转换的方法!
我想通过代码(abap)阅读SAP中IMG活动的自定义路径.我有来自e071K的IMG-Activity,它将对象存储在传输作业中.现在我找到了存储SPRO树结构的表TNODEIMG.这是完美的,因为它符合我的需要.但我找不到与IMG-Activity的连接.TNODEIMG中的Unique-Id采用其他格式,似乎是一个不同的Id.有人知道我怎么能读出这个?
更新:
@vwegert:谢谢你的帮助.到目前为止,我得到的这个列表充满了Node-Id:lt_eref_list但是没有得到父母.你看到一些误解或失败吗?
DATA: lt_iref_list TYPE STANDARD TABLE OF hier_ref,
lt_eref_list TYPE STANDARD TABLE OF hier_ref,
ls_ref TYPE hier_ref,
lt_parent_list TYPE STANDARD TABLE OF hier_iface,
lt_check_list TYPE STANDARD TABLE OF hier_iface.
ls_ref-node_id = 'SIMG_CFMENUOLQSOQ46'.
APPEND ls_ref TO lt_iref_list.
CALL FUNCTION 'STREE_GET_NODES_FOR_GIVEN_REF'
TABLES
i_list_of_references = lt_iref_list
e_list_of_references = lt_eref_list.
LOOP AT lt_eref_list ASSIGNING FIELD-SYMBOL(<ls_ref>).
CALL FUNCTION 'STREE_GET_PARENTS_OF_NODE'
EXPORTING
structure_id = <ls_ref>-node_id
* IMPORTING
* message = ls_message
TABLES
check_nodes = lt_check_list
parent_nodes = lt_parent_list.
ENDLOOP.
Run Code Online (Sandbox Code Playgroud)
先感谢您.
我想在C#中实现一般的Memento-Pattern.它运行正常但我使用Serializeable()属性来执行对象的深层复制.我使用泛型的实现,所以如果有人使用它,他必须给他的类作为类型.现在来自用户的类也必须具有Attribute Serializeable().使用Serializeable()的类是否有任何限制?
事实上:
我不知道属性是如何工作的,所以我有点害怕以这种全局方式使用它.
问候
如果我在C#中从数据库中获取一些值,它们就是类型对象.现在我想转换这些值以将typesafe它们加载到我的对象中,该对象代表datarow或多或少.所以我认为为扩展对象创建一个通用的扩展方法会很好.
所以我构建了以下内容:
public static T ConvertToType<T>(this object value)
{
T returnValue = default(T);
if (value != DBNull.Value)
{
returnValue = (T)value;
}
return returnValue;
}
Run Code Online (Sandbox Code Playgroud)
所以我可以使用它来转换给定的不同值datarow,如果数据库存储null值,我得到默认类型.
例如:
foreach (DataRow row in myTable.Rows)
{
MyClass myObject = new MyClass();
myObject.Id = row["ID"].ConvertToType<int>();
}
Run Code Online (Sandbox Code Playgroud)
这适用于编译时,但似乎不可能将对象转换int为例如.所以我认为所有的值类型都必须手动处理.
所以我扩展了第一个代码块:
public static T ConvertToType<T>(this object value)
{
T returnValue = default(T);
if (value != DBNull.Value)
{
if (wert is int)
{
rueckgabe = Convert.ToInt32(wert);
}
//else …Run Code Online (Sandbox Code Playgroud) 我知道 abap 没有真正的布尔类型。而是使用了 'X' 和 ' '。到目前为止,我总是这样使用 if 语句:
IF myObj->is_sth( ) = abap_true.
ENDIF.
Run Code Online (Sandbox Code Playgroud)
现在我做了这样的事情:
IF myObj->is_sth( ).
ENDIF.
Run Code Online (Sandbox Code Playgroud)
我想知道这似乎有效。返回类型是布尔值。我在 Netweaver 7.4 上。我可以毫无问题地使用它吗?这就像我可爱的 C# 写作:p。
如果我有List<T>从类型获得一些列表MyClass,例如List<List<MyClass>>,MyClass是来自的父类MyClassB.为什么我不能做以下事情?
List<List<MyClass>> allLists = new List<List<MyClass>>();
List<MyClassB> myList = new List<MyClassB>();
myList.Add(new MyClassB());
//And now the point which dont work
allLists.Add(myList);
Run Code Online (Sandbox Code Playgroud)
如果我实现一个方法,我可以说SomeClass<T> ... where T : MyClass,我的列表问题有类似的东西吗?
这样我就可以将任何子类的列表添加到我的第一级列表中?
我正在尝试运行函数,它将通过传递指针返回两个字符串:
#include <stdio.h>
void gen_str(char *str1, char *str2){
char *s1 = "abcd";
char *s2 = "defg";
str1= strdup(s1);
str2= strdup(s2);
printf("\n\r str1 %s str2 %s\n\r", str1, str2);
}
int main(void){
char *s1, *s2;
gen_str(s1, s2);
printf("\n\r s1 %s s2 %s\n\r", s1, s2);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
其中输出是:
str1 abcd str2 defg
s1 8, s2 8,
Run Code Online (Sandbox Code Playgroud)
有人能告诉我,我做错了什么?我认为strdup()会为我的新字符串分配内存,并返回填充字符串的指针.但实际行为是不同的.所以我在寻求帮助.
我有一个接口和两个类.
public interface IMyInterface { }
public class A : IMyInterface { }
public class B : IMyInterface { }
Run Code Online (Sandbox Code Playgroud)
我有一个通用的方法,
private List<T> GetList<T>(DataTable table)
where T : class, IMyInterface
{
...
}
Run Code Online (Sandbox Code Playgroud)
应该根据DataTable中的数据返回一个对象列表.所以,我在这个方法中创建了一个列表,我想在最后返回.我以为我可以做到以下几点,
private List<T> GetList<T>(DataTable table)
where T : class, IMyInterface
{
List<T> myList = new List<T>;
// Now I thought I could easily add Objects based on T because,
// both classes implement the interface
if (typeof(T) == typeof(B))
{
myList.Add(new B());
}
else
{
myList.Add(new A()); …Run Code Online (Sandbox Code Playgroud) c# ×7
abap ×2
generics ×2
ado.net ×1
attributes ×1
c ×1
datagridview ×1
generic-list ×1
json ×1
jsonpickle ×1
oracle ×1
plsql ×1
printing ×1
python ×1
python-3.6 ×1
python-3.x ×1
rgb ×1
sap ×1
sql ×1
tcpclient ×1
telnet ×1
vba ×1