#-Begin-----------------------------------------------------------------
#-WriteMMF--------------------------------------------------------------
Function WriteMMF {
Param(
[String]$Name,
[String]$Text
)
Try {
[System.IO.MemoryMappedFiles.MemoryMappedFile]$MMF = `
[System.IO.MemoryMappedFiles.MemoryMappedFile]::OpenExisting($Name);
If($Null -eq $MMF) {
Return;
}
$Stream = $MMF.CreateViewStream();
$StreamWriter = [System.IO.StreamWriter]::new($Stream);
$StreamWriter.Write($Text);
} Catch {
Return;
}
Try {
While($True) {
$StreamWriter.Write([System.Convert]::ToChar(0));
}
} Catch {}
Try {
$StreamWriter.Dispose();
} Catch {
Return;
}
$Stream.Dispose();
Write-Host "ok";
}
#-ReadMMF---------------------------------------------------------------
Function ReadMMF {
Param(
[String]$Name
)
Try {
[System.IO.MemoryMappedFiles.MemoryMappedFile]$MMF = `
[System.IO.MemoryMappedFiles.MemoryMappedFile]::OpenExisting($Name);
If($Null -eq $MMF) {
Return;
}
$Stream = $MMF.CreateViewStream();
$StreamReader = [System.IO.StreamReader]::new($Stream);
$Text = $StreamReader.ReadToEnd().Replace("`0", "");
$StreamReader.Dispose();
} Catch {
Return;
}
$Stream.Dispose();
Write-Host $Text;
}
#-AppendMMF-------------------------------------------------------------
Function AppendMMF {
Param(
[String]$Name,
[String]$Text
)
Try {
[System.IO.MemoryMappedFiles.MemoryMappedFile]$MMF = `
[System.IO.MemoryMappedFiles.MemoryMappedFile]::OpenExisting($Name);
If($Null -eq $MMF) {
Return;
}
$Stream = $MMF.CreateViewStream();
$StreamReader = [System.IO.StreamReader]::new($Stream);
$Buffer = $StreamReader.ReadToEnd().Replace("`0", "");
$StreamReader.Dispose();
$Stream.Dispose();
$Buffer = $Buffer + $Text;
$Stream = $MMF.CreateViewStream();
$StreamWriter = [System.IO.StreamWriter]::new($Stream);
$StreamWriter.Write($Buffer);
} Catch {
Return;
}
Try {
While($True) {
$StreamWriter.Write([System.Convert]::ToChar(0));
}
} Catch {}
Try {
$StreamWriter.Dispose();
} Catch {
Return;
}
$Stream.Dispose();
Write-Host "ok";
}
#-Main------------------------------------------------------------------
#FunctionCall
#-End-------------------------------------------------------------------
"-Begin-----------------------------------------------------------------
CLASS z_cl_mmf DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
METHODS write
IMPORTING
VALUE(iv_mmf_name) TYPE string
VALUE(iv_text) TYPE string
RETURNING
VALUE(rv_status) TYPE string.
METHODS read
IMPORTING
VALUE(iv_mmf_name) TYPE string
RETURNING
VALUE(rv_text) TYPE string.
METHODS append
IMPORTING
VALUE(iv_mmf_name) TYPE string
VALUE(iv_text) TYPE string
RETURNING
VALUE(rv_status) TYPE string.
PROTECTED SECTION.
PRIVATE SECTION.
METHODS call_ps_function
IMPORTING
VALUE(iv_functioncall) TYPE string
RETURNING
VALUE(rv_result) TYPE string.
ENDCLASS.
CLASS z_cl_mmf IMPLEMENTATION.
METHOD write."--------------------------------------------------------
rv_status = me->call_ps_function(
iv_functioncall = `WriteMMF -Name ` && iv_mmf_name &&
` -Text '` && iv_text && `';`
).
ENDMETHOD.
METHOD read."---------------------------------------------------------
rv_text = me->call_ps_function(
iv_functioncall = `ReadMMF -Name ` && iv_mmf_name && `;`
).
ENDMETHOD.
METHOD append."-------------------------------------------------------
rv_status = me->call_ps_function(
iv_functioncall = `AppendMMF -Name ` && iv_mmf_name &&
` -Text '` && iv_text && `';`
).
ENDMETHOD.
METHOD call_ps_function."---------------------------------------------
DATA:
lo_ps TYPE REF TO z_cl_activexposhv3,
lv_result TYPE string,
lv_pscode TYPE string,
lv_temp TYPE string
.
CREATE OBJECT lo_ps.
CHECK lo_ps->load_lib( ) = lo_ps->mc_true.
CHECK lo_ps->get_is_powershell_installed( ) = lo_ps->mc_true.
CHECK lo_ps->init( iv_load_profiles = lo_ps->mc_false ) = 0.
lo_ps->set_outputmode( lo_ps->mc_outputbuffer ).
lo_ps->set_outputwidth( 132 ).
lo_ps->clear_output( ).
lv_pscode = lo_ps->read_incl_as_string('Z_POSH_MMF').
REPLACE '#FunctionCall' WITH iv_functioncall INTO lv_pscode.
lo_ps->execute( lv_pscode ).
rv_result = lo_ps->get_outputstring( ).
lo_ps->free_lib( ).
ENDMETHOD.
ENDCLASS.
"-End-------------------------------------------------------------------
#-Begin-----------------------------------------------------------------
$Text = @"
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam
voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet
clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit
amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam
nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat,
sed diam voluptua. At vero eos et accusam et justo duo dolores et ea
rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem
ipsum dolor sit amet.
"@
#-Sub Main--------------------------------------------------------------
Function Main {
$Name = "UiPathRobot";
$Size = 128KB;
[System.IO.MemoryMappedFiles.MemoryMappedFile]$MMF = `
[System.IO.MemoryMappedFiles.MemoryMappedFile]::CreateOrOpen($Name, $Size);
If($Null -eq $MMF) {
Return;
}
$Stream = $MMF.CreateViewStream();
$StreamWriter = [System.IO.StreamWriter]::new($Stream);
$StreamWriter.Write($Text);
$StreamWriter.Dispose();
$Stream.Dispose();
$Stream = $MMF.CreateViewStream();
$StreamReader = [System.IO.StreamReader]::new($Stream);
$JSON = $StreamReader.ReadToEnd().Replace("`0", "");
$StreamReader.Dispose();
$Stream.Dispose();
$MMF.Dispose();
Write-Host $JSON.Length;
Write-Host $JSON;
}
#-Main------------------------------------------------------------------
Main;
#-End-------------------------------------------------------------------
"-Begin-----------------------------------------------------------------
REPORT z_mmf.
DATA:
lo_mmf TYPE REF TO z_cl_mmf,
lv_text TYPE string,
lv_status TYPE string,
lt_flight TYPE STANDARD TABLE OF sflight.
CREATE OBJECT lo_mmf.
lv_text = lo_mmf->read( iv_mmf_name = 'UiPathRobot' ).
WRITE: lv_text.
lo_mmf->write(
iv_mmf_name = 'UiPathRobot'
iv_text = 'Hello World from ABAP'
).
lo_mmf->append(
iv_mmf_name = 'UiPathRobot'
iv_text = ', so long, and thanks for all the fish'
).
SELECT CARRID, CONNID, FLDATE, PRICE, CURRENCY, PLANETYPE, SEATSMAX,
SEATSOCC, PAYMENTSUM, SEATSMAX_B, SEATSOCC_B, SEATSMAX_F, SEATSOCC_F
FROM sflight INTO CORRESPONDING FIELDS OF TABLE @lt_flight.
lv_text = /ui2/cl_json=>serialize( lt_flight ).
lo_mmf->write(
iv_mmf_name = 'UiPathRobot'
iv_text = lv_text
).
"-End-------------------------------------------------------------------
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
3 | |
3 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |