本篇文章给大家谈谈cratedbrestinsertobject,同时本文还将给你拓展.net中的CreateJobObject/SetInformationJobObjectpinvoke的工作示例
本篇文章给大家谈谈cratedb rest insert object,同时本文还将给你拓展.net中的CreateJobObject / SetInformationJobObject pinvoke的工作示例?、angular – 无法解析AuthenticationService的所有参数:([object Object],?,[object Object])、asp-classic – 通过object标签和Server.CreateObject声明连接有什么区别、ASP.NET list等相关知识,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:- cratedb rest insert object
- .net中的CreateJobObject / SetInformationJobObject pinvoke的工作示例?
- angular – 无法解析AuthenticationService的所有参数:([object Object],?,[object Object])
- asp-classic – 通过object标签和Server.CreateObject声明连接有什么区别
- ASP.NET list
cratedb rest insert object
先定义一个数据表:
create table my_table (
name string,
mxlist array (object as(name string, age integer))
);
这样就新建了一个表,结构是这样的:
可以看到mxlist中有2个对象,关于object和array的建立,官网有很详细的说明
接下来执行对my_table的CRUD操作,cratedb有基于各种语言的client端,我这里使用的是java,不过我选择的是rest方式,因为java的client端代码版本号太低,一直没有更新,用rest的话更加自由,rest官方文档:https://crate.io/docs/reference/protocols/http.html
java代码:
JSONObject o = new JSONObject(); o.put("name", "jemmy"); o.put("age", 67); JSONArray arr = new JSONArray(); HTTPAliveCRUDClient client = HTTPAliveCRUDClient.getInstance("192.168.13.50", 4200);//这是自己封装的方法 client.connect(); // String sql = "SELECT * FROM my_table"; String sql = "INSERT INTO my_table(name,mxlist) VALUES (?,?)"; JSONObject json = new JSONObject(); json.put("stmt", sql); String arg = "凯文"; JSONArray d = new JSONArray(); d.add(arg); JSONArray b = new JSONArray(); b.add(o); d.add(b); json.put("args", d); String url = "http://192.168.13.50" + ":" + "4200/_sql?pretty"; System.out.println(url); System.out.println(json); try { HTTPResp resp = client.post(url, json); if (resp == null || resp.getRespCode(-1) != 200) { int errorCode = resp.getRespJson().getJSONObject("error").getIntValue("code"); String errorMsg = resp.getRespJson().getJSONObject("error").getString("message"); logger.error(" ----- execute failed :" + resp.getRespMsg()); } else { logger.info(" ----- execute success"); } System.out.println(resp.getRespJson()); }catch (Exception e) { e.printStackTrace(); logger.error(e.getMessage(), e); }
这样就OK了
.net中的CreateJobObject / SetInformationJobObject pinvoke的工作示例?
我正在努力拼凑一个拼凑的CreateJobObject和SetInformationJobObject的工作示例。通过各种Google搜索(包括俄语和中文帖子!),我将以下代码拼凑在一起。我认为JOBOBJECT_BASIC_LIMIT_INFORMATION的定义根据平台(32/64位)而变化。CreateJobObject
/ AssignProcessToJobObject 似乎 可以工作。SetInformationJobObject失败-错误24或87。
Process myProcess // POPULATED SOMEWHERE ELSE// Create Job & assign this process and another process to the jobIntPtr jobHandle = CreateJobObject( null , null );AssignProcessToJobObject( jobHandle , myProcess.Handle );AssignProcessToJobObject( jobHandle , Process.GetCurrentProcess().Handle );// Ensure that killing one process kills the others JOBOBJECT_BASIC_LIMIT_INFORMATION limits = new JOBOBJECT_BASIC_LIMIT_INFORMATION();limits.LimitFlags = (short)LimitFlags.JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;IntPtr pointerToJobLimitInfo = Marshal.AllocHGlobal( Marshal.SizeOf( limits ) );Marshal.StructureToPtr( limits , pointerToJobLimitInfo , false ); SetInformationJobObject( job , JOBOBJECTINFOCLASS.JobObjectBasicLimitInformation , pionterToJobLimitInfo , ( uint )Marshal.SizeOf( limits ) )... [DllImport( "kernel32.dll" , EntryPoint = "CreateJobObjectW" , CharSet = CharSet.Unicode )] public static extern IntPtr CreateJobObject( SecurityAttributes JobAttributes , string lpName ); public class SecurityAttributes { public int nLength; //Useless field = 0 public IntPtr pSecurityDescriptor; //хз)) public bool bInheritHandle; //Возможность наследования public SecurityAttributes() { this.bInheritHandle = true; this.nLength = 0; this.pSecurityDescriptor = IntPtr.Zero; } } [DllImport( "kernel32.dll" )] static extern bool SetInformationJobObject( IntPtr hJob , JOBOBJECTINFOCLASS JobObjectInfoClass , IntPtr lpJobObjectInfo , uint cbJobObjectInfoLength ); public enum JOBOBJECTINFOCLASS { JobObjectAssociateCompletionPortInformation = 7 , JobObjectBasicLimitInformation = 2 , JobObjectBasicUIRestrictions = 4 , JobObjectEndOfJobTimeInformation = 6 , JobObjectExtendedLimitInformation = 9 , JobObjectSecurityLimitInformation = 5 } [StructLayout( LayoutKind.Sequential )] struct JOBOBJECT_BASIC_LIMIT_INFORMATION { public Int64 PerProcessUserTimeLimit; public Int64 PerJobUserTimeLimit; public Int16 LimitFlags; public UIntPtr MinimumWorkingSetSize; public UIntPtr MaximumWorkingSetSize; public Int16 ActiveProcessLimit; public Int64 Affinity; public Int16 PriorityClass; public Int16 SchedulingClass; } public enum LimitFlags { JOB_OBJECT_LIMIT_ACTIVE_PROCESS = 0x00000008 , JOB_OBJECT_LIMIT_AFFINITY = 0x00000010 , JOB_OBJECT_LIMIT_BREAKAWAY_OK = 0x00000800 , JOB_OBJECT_LIMIT_DIE_ON_UNHANDLED_EXCEPTION = 0x00000400 , JOB_OBJECT_LIMIT_JOB_MEMORY = 0x00000200 , JOB_OBJECT_LIMIT_JOB_TIME = 0x00000004 , JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE = 0x00002000 , JOB_OBJECT_LIMIT_PRESERVE_JOB_TIME = 0x00000040 , JOB_OBJECT_LIMIT_PRIORITY_CLASS = 0x00000020 , JOB_OBJECT_LIMIT_PROCESS_MEMORY = 0x00000100 , JOB_OBJECT_LIMIT_PROCESS_TIME = 0x00000002 , JOB_OBJECT_LIMIT_SCHEDULING_CLASS = 0x00000080 , JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK = 0x00001000 , JOB_OBJECT_LIMIT_WORKINGSET = 0x00000001 } [DllImport( "kernel32.dll" )] [return: MarshalAs( UnmanagedType.Bool )] static extern bool AssignProcessToJobObject( IntPtr hJob , IntPtr hProcess ); [StructLayout( LayoutKind.Sequential )] public struct SECURITY_ATTRIBUTES { public int nLength; public IntPtr lpSecurityDescriptor; public int bInheritHandle; }
答案1
小编典典这可能会晚一点,但仍然如此。
我在这里尝试了所有示例,但是没有人同时在32位和64位模式下为我工作。最后,我需要亲自检查所有签名并创建相应的PInvoke例程。我认为,其他人可能会发现这很有帮助。
免责声明:解决方案基于 Matt Howells的答案。
using System;using System.Diagnostics;using System.Runtime.InteropServices;namespace JobManagement{ public class Job : IDisposable { [DllImport("kernel32.dll", CharSet = CharSet.Unicode)] static extern IntPtr CreateJobObject(IntPtr a, string lpName); [DllImport("kernel32.dll")] static extern bool SetInformationJobObject(IntPtr hJob, JobObjectInfoType infoType, IntPtr lpJobObjectInfo, UInt32 cbJobObjectInfoLength); [DllImport("kernel32.dll", SetLastError = true)] static extern bool AssignProcessToJobObject(IntPtr job, IntPtr process); [DllImport("kernel32.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] static extern bool CloseHandle(IntPtr hObject); private IntPtr handle; private bool disposed; public Job() { handle = CreateJobObject(IntPtr.Zero, null); var info = new JOBOBJECT_BASIC_LIMIT_INFORMATION { LimitFlags = 0x2000 }; var extendedInfo = new JOBOBJECT_EXTENDED_LIMIT_INFORMATION { BasicLimitInformation = info }; int length = Marshal.SizeOf(typeof(JOBOBJECT_EXTENDED_LIMIT_INFORMATION)); IntPtr extendedInfoPtr = Marshal.AllocHGlobal(length); Marshal.StructureToPtr(extendedInfo, extendedInfoPtr, false); if (!SetInformationJobObject(handle, JobObjectInfoType.ExtendedLimitInformation, extendedInfoPtr, (uint)length)) throw new Exception(string.Format("Unable to set information. Error: {0}", Marshal.GetLastWin32Error())); } public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } private void Dispose(bool disposing) { if (disposed) return; if (disposing) { } Close(); disposed = true; } public void Close() { CloseHandle(handle); handle = IntPtr.Zero; } public bool AddProcess(IntPtr processHandle) { return AssignProcessToJobObject(handle, processHandle); } public bool AddProcess(int processId) { return AddProcess(Process.GetProcessById(processId).Handle); } } #region Helper classes [StructLayout(LayoutKind.Sequential)] struct IO_COUNTERS { public UInt64 ReadOperationCount; public UInt64 WriteOperationCount; public UInt64 OtherOperationCount; public UInt64 ReadTransferCount; public UInt64 WriteTransferCount; public UInt64 OtherTransferCount; } [StructLayout(LayoutKind.Sequential)] struct JOBOBJECT_BASIC_LIMIT_INFORMATION { public Int64 PerProcessUserTimeLimit; public Int64 PerJobUserTimeLimit; public UInt32 LimitFlags; public UIntPtr MinimumWorkingSetSize; public UIntPtr MaximumWorkingSetSize; public UInt32 ActiveProcessLimit; public UIntPtr Affinity; public UInt32 PriorityClass; public UInt32 SchedulingClass; } [StructLayout(LayoutKind.Sequential)] public struct SECURITY_ATTRIBUTES { public UInt32 nLength; public IntPtr lpSecurityDescriptor; public Int32 bInheritHandle; } [StructLayout(LayoutKind.Sequential)] struct JOBOBJECT_EXTENDED_LIMIT_INFORMATION { public JOBOBJECT_BASIC_LIMIT_INFORMATION BasicLimitInformation; public IO_COUNTERS IoInfo; public UIntPtr ProcessMemoryLimit; public UIntPtr JobMemoryLimit; public UIntPtr PeakProcessMemoryUsed; public UIntPtr PeakJobMemoryUsed; } public enum JobObjectInfoType { AssociateCompletionPortInformation = 7, BasicLimitInformation = 2, BasicUIRestrictions = 4, EndOfJobTimeInformation = 6, ExtendedLimitInformation = 9, SecurityLimitInformation = 5, GroupInformation = 11 } #endregion}
angular – 无法解析AuthenticationService的所有参数:([object Object],?,[object Object])
Can’t resolve all parameters for AuthenticationService: ([object Object],?,[object Object])
我已经检查了几乎每个主题,并尝试了多种方法来解决它,但仍然无法在第二天击败它.
我试图像这样在appService中注入第一个authService但是得到了同样的错误
@Inject(forwardRef(() => AuthenticationService)) public authService: AuthenticationService
我检查了所有DI和服务内部的导入顺序,在我看来一切都是正确的
如果有人可以帮我处理它,我很感激.
Angular 4.0.0
AuthService
import { Injectable } from '@angular/core'; import {Http,Headers,Response} from '@angular/http'; import 'rxjs/add/operator/toPromise'; import {Observable} from 'rxjs/Rx'; import {AppServices} from "../../app.services"; import {Router} from "@angular/router"; @Injectable() export class AuthenticationService { public token: any; constructor( private http: Http,private appService: AppServices,private router: Router ) { this.token = localStorage.getItem('token'); } login(username: string,password: string): Observable<boolean> { let headers = new Headers(); let body = null; headers.append("Authorization",("Basic " + btoa(username + ':' + password))); return this.http.post(this.appService.api + '/login',body,{headers: headers}) .map((response: Response) => { let token = response.json() && response.json().token; if (token) { this.token = token; localStorage.setItem('Conform_token',token); return true; } else { return false; } }); } logout(): void { this.token = null; localStorage.removeItem('Conform_token'); this.router.navigate(['/login']); } }
应用服务
import {Injectable} from '@angular/core'; import {Headers,Http,RequestOptions} from '@angular/http'; import {Router} from "@angular/router"; import {AuthenticationService} from "./auth/auth.service"; import 'rxjs/add/operator/toPromise'; import {Observable} from 'rxjs/Rx'; @Injectable() export class AppServices { api = '//endpoint/'; public options: any; constructor( private http: Http,private router: Router,public authService: AuthenticationService // doesn't work // @Inject(forwardRef(() => AuthenticationService)) public authService: AuthenticationService // doesn't work either ) { let head = new Headers({ 'Authorization': 'Bearer ' + this.authService.token,"Content-Type": "application/json; charset=utf8" }); this.options = new RequestOptions({headers: head}); } // ==================== // data services // ==================== getData(): Promise<any> { return this.http .get(this.api + "/data",this.options) .toPromise() .then(response => response.json() as Array<Object>) .catch((err)=>{this.handleError(err);}) }
应用模块
import { browserModule } from '@angular/platform-browser'; import { browserAnimationsModule } from '@angular/platform-browser/animations'; import { NgModule } from '@angular/core'; import { FormsModule } from '@angular/forms'; import {BaseRequestOptions,HttpModule} from '@angular/http'; import { MaterialModule} from '@angular/material'; import {FlexLayoutModule} from "@angular/flex-layout"; import 'hammerjs'; import { routing,appRoutingProviders } from './app.routing'; import { AppServices } from './app.services'; import {AuthGuard} from "./auth/auth.guard"; import {AuthenticationService} from "./auth/auth.service"; import {AppComponent} from './app.component'; import {AuthComponent} from './auth/auth.component'; import {NotFoundComponent} from './404/not-found.component'; import { HomeComponent } from './home/home.component'; @NgModule({ declarations: [ AppComponent,AuthComponent,NotFoundComponent,HomeComponent ],imports: [ browserModule,browserAnimationsModule,FormsModule,HttpModule,routing,MaterialModule,FlexLayoutModule ],providers: [AppServices,AuthGuard,AuthenticationService],bootstrap: [AppComponent] }) export class AppModule { }
解决方法
你可以使用
export class AuthenticationService { public token: any; appService: AppServices; constructor( private http: Http,// private appService: AppServices,injector:Injector; private router: Router ) { setTimeout(() => this.appService = injector.get(AppServices)); this.token = localStorage.getItem('token'); }
另见DI with cyclic dependency with custom HTTP and ConfigService
要避免使用setTimeout,您还可以从AppService的构造函数中设置AuthenticationService.appService(或者相反)
asp-classic – 通过object标签和Server.CreateObject声明连接有什么区别
<object RUNAT="Server" ID="cn" PROGID="ADODB.Connection"></object>
并通过Server.CreateObject()调用声明连接:
set cn = Server.CreateObject("ADODB.Connection")
或者有什么区别?表现,记忆等.
解决方法
我找到了一些文章,也许他们会给你一些见解:
http://www.aspmessageboard.com/showthread.php?t=6775
http://www.asp101.com/tips/index.asp?id=4
ASP.NET list
public partial class 测试 : System.Web.UI.Page
{
static List<Item> allAnswer= new List<Item>();
protected void Page_Load(object sender, EventArgs e)
{
//首次加载
if (IsPostBack == false)
{
//不能使用将allAnswer中的元素全部删除,这样也会将session中的值清空
//allAnswer.clean();
//使用重新定义新的空的对象来实现对allAnswer的清空
allAnswer = new List<Item>();
List<Item> reallAnswer = null;
try
{
//其中Session["ReAllAnswer"]来自于另一页面
reallAnswer = (List<Item>)Session["ReAllAnswer"];
//PrintAllAnwser(reallAnswer);
}
catch { }
}
}
如果使用allAnswer.clean()函数,则接收的数据Session["ReAllAnswer"]将会设置为空;
而使用new List<Item>(),则不会。
今天关于cratedb rest insert object的分享就到这里,希望大家有所收获,若想了解更多关于.net中的CreateJobObject / SetInformationJobObject pinvoke的工作示例?、angular – 无法解析AuthenticationService的所有参数:([object Object],?,[object Object])、asp-classic – 通过object标签和Server.CreateObject声明连接有什么区别、ASP.NET list等相关知识,可以在本站进行查询。
本文标签: