Terraform Dynamic Block for Firewall log config - module

Thanks for the help and time spent in advance.
I am trying to create terraform module for AWS network firewall configuration.
The below is my code:
firewall_arn = var.firewall_arn
logging_configuration {
dynamic "config" {
for_each = var.log_destination_configs
content {
log_destination {
bucketName = lookup(config.value, "bucketName", null)
prefix = lookup(config.value, "prefix", null)
logGroup = lookup(config.value, "logGroup", null)
deliveryStream = lookup(config.value, "deliveryStream", null)
}
log_destination_type = lookup(config.value, "log_destination_type", null)
log_type = lookup(config.value, "log_type", null)
}
}
}
}
However when I tried to compile, I'm getting the following error:
Error: Unsupported block type
on ../../main.tf line 4, in resource "aws_networkfirewall_logging_configuration" "default":
4: dynamic "config" {
Blocks of type "config" are not expected here.
}
Is it because I'm declaring the block within logging_configuration and that is not allowed?
Thanks again.

According to the logging_configuration argument documentation, the nested block is named log_destination_config and not config. That is why the error message states that a block config is not expected within that block. If you update the block name and lambda scope variables accordingly:
logging_configuration {
dynamic "log_destination_config" {
for_each = var.log_destination_configs
content {
log_destination {
bucketName = lookup(log_destination_config.value, "bucketName", null)
prefix = lookup(log_destination_config.value, "prefix", null)
logGroup = lookup(log_destination_config.value, "logGroup", null)
deliveryStream = lookup(log_destination_config.value, "deliveryStream", null)
}
log_destination_type = lookup(log_destination_config.value, "log_destination_type", null)
log_type = lookup(log_destination_config.value, "log_type", null)
}
}
}
then that should resolve the issue around your error message.

Related

How to get the value of another function synchronously

I am using the ktor websocket module
When I send data to the client, how do I get the data back from the client after this send?
val result = serverSession.send(json)
// result
Just like this
It is actually the Unit type
But I want to get the String
There are great examples on official site of Ktor.
If you are server-side, check this link (https://ktor.io/docs/websocket.html#handle-single-session) and the below example.
webSocket("/echo") {
send("Please enter your name")
for (frame in incoming) {
when (frame) {
is Frame.Text -> {
val receivedText = frame.readText()
if (receivedText.equals("bye", ignoreCase = true)) {
close(CloseReason(CloseReason.Codes.NORMAL, "Client said BYE"))
} else {
send(Frame.Text("Hi, $receivedText!"))
}
}
}
}
}
If you are client-side, check this link (https://ktor.io/docs/websocket-client.html#example) and the below example.
client.webSocket(method = HttpMethod.Get, host = "127.0.0.1", port = 8080, path = "/echo") {
while(true) {
val othersMessage = incoming.receive() as? Frame.Text
println(othersMessage?.readText())
val myMessage = Scanner(System.`in`).next()
if(myMessage != null) {
send(myMessage)
}
}
}

Unable to access DynamoDb Locally from Kotlin

First I want to say I am pretty new to Kotlin and DynamoDB. I am writing a sample program in Kotlin to play with DynamoDb. I am following the steps in this link: https://docs.aws.amazon.com/sdk-for-kotlin/latest/developer-guide/examples-dynamodb-tables.html
First I instantiate a client object for making requests to DynamoDB
val dynamoDbClient = DynamoDbClient { region = "us-east-1" }
Then I run the code below to create a new table.
suspend fun createNewTable(ddb: DynamoDbClient, newTableName: String, key: String): String {
val attDef = AttributeDefinition {
attributeName = key
attributeType = ScalarAttributeType.S
}
val keySchemaVal = KeySchemaElement {
attributeName = key
keyType = KeyType.Hash
}
val provisionedVal = ProvisionedThroughput {
readCapacityUnits = 10
writeCapacityUnits = 10
}
val request = CreateTableRequest {
attributeDefinitions = listOf(attDef)
keySchema = listOf(keySchemaVal)
provisionedThroughput = provisionedVal
tableName = newTableName
}
try {
val response = ddb.createTable(request)
val tableActive = false
// Wait until the table is in Active state.
while (!tableActive) {
val tableStatus = checkTableStatus(ddb, newTableName)
if (tableStatus.equals("ACTIVE"))
break
delay(500)
}
return response.tableDescription?.tableArn.toString()
} catch (e: DynamoDbException) {
println("ERROR (DynamoDbException): " + e.message)
} catch (e: UnknownServiceErrorException) {
println("ERROR (UnknownServiceErrorException): " + e.message)
} finally {
ddb.close()
}
return ""
}
I can see the table created on my AWS account. However I want to modify my DynamoDbClient to execute the table creation on a local instance of the DynamoDB. I followed the instructions from AWS pages and I installed DynamoDB locally.
Here is how I am running it locally:
c:\code\dynamodb_local_latest>java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb
Initializing DynamoDB Local with the following configuration:
Port: 8000
InMemory: false
DbPath: null
SharedDb: true
shouldDelayTransientStatuses: false
CorsParams: *
I am able to access the local DynamoDB instance from the aws cli tool.
In order to try accessing the local instance of DynamoDB from the Kotlin code, I changed DynamoDbClient from this:
val dynamoDbClient = DynamoDbClient { region = "us-east-1" }
to this:
val endpoint = aws.sdk.kotlin.runtime.endpoint.Endpoint( "localhost",
"http",
port=8000,
false,
null,
"us-west-1")
val myEndpointResolver = StaticEndpointResolver(endpoint)
val dynamoDbClient = DynamoDbClient {endpointResolver = myEndpointResolver; region ="us-west-1" }
However I get the following error:
Exception in thread "DefaultDispatcher-worker-1" software.amazon.awssdk.crt.http.HttpException: socket connection refused.
at software.amazon.awssdk.crt.http.HttpClientConnection.onConnectionAcquired(HttpClientConnection.java:85)
What is the proper way to resolve that?
Thanks!
You can specify the EndPointResolver for the DynamoDbClient with the address of your DynamoDb local instance.
For example:
class LocalHostDynamoDb: AwsEndpointResolver {
override suspend fun resolve(service: String, region: String): AwsEndpoint
= AwsEndpoint("http://localhost:8000")
}
class MyClient {
...
val dynamoDbClient = DynamoDbClient {
region = awsRegion
endpointResolver = LocalHostDynamoDb()
}
...

Entity Framework fails to update records

I am developing a Webapp using MVC and Entity framework and i have encountered a problem which is starting to get pretty annoying now.
[HttpPost]
[ValidateAntiForgeryToken]
[ValidateInput(true)]
public ActionResult ChangeUser(HttpPostedFileBase avatar, int? id)
{
try
{
if (id == null) return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
if (ModelState.IsValid)
{
Models.Users usr = db.Users.Find(id);
var at = db.Users.Attach(usr);
if (usr == null) return HttpNotFound();
at.Password = Encryption.Encode(usr.Password);
at.Email = usr.Email;
at.NickName = usr.NickName;
if (avatar != null && avatar.ContentLength > 0)
{
var _fileName = Path.GetFileName(avatar.FileName);
var ext = Path.GetExtension(_fileName);
var fileName = Encryption.EncodeFileName(_fileName);
//End of file properties
var path = Path.Combine(Server.MapPath("~/CMS-Content/User/Files/Avatars/"), fileName + ext);
avatar.SaveAs(Server.MapPath(path));
at.ThumbnailPath = path;
}
db.Entry(usr).State = EntityState.Modified;
// other changed properties
db.SaveChanges();
TempData["result"] = "User settings changed successfully.";
}
}
catch
{
TempData["result"] = "An error occured to change the user information!";
}
return RedirectToAction("Users");
}
The problem is that the records in the database does not update. I get the output that they have been updated successfully but in database the records does not change.

Is there a way to change command-line arguments in a signed RDP file?

I need to specify command line arguments for a RemoteApp using the remoteapplicationcmdline property of a signed RDP file.
However, after the RDP file is signed, I cannot change the value for remoteapplicationcmdline. If I remove remoteapplicationcmdline from the signscope, I can't specify any parameters.
This is the same question asked by Chupkb on Technet.
I might be able to do as Naraen suggested on this question, but before I do that I'm hoping there is a simpler way.
The route I eventually took was to gather the command line arguments from a previous page (perhaps a login page) and then on the next page I dynamically create an rdp file, sign it, and embed the contents into the javascript on the html page. The code below is ASP.NET and c# but it should be a good starting point for other languages as well.
First, the html (notice the <%= RdpFileContents %> in LaunchRemoteApp():
<html>
<head>
<title>RD Web Access</title>
<script type="text/javascript" language="javascript">
var g_workspace = null;
var workspaceID = "[RemoteAppMachineName]";
var domainUserName = "[RemoteAppMachineName]\\[RemoteAppUserName]";
// This is the certificate's thumbprint.
var rdpCertificates = "04b83503a710cad89f25d3e15a48245f490773c4";
var machineType = "public";
function onAutoDisconnect() {
var workspace = null;
if (workspaceID != null && workspaceID != "") {
try {
workspace = GetWorkspaceObject();
workspace.ClearWorkspaceCredential(workspaceID);
}
catch (objException) {
workspace = null;
}
}
}
function onUserDisconnect() {
var workspace = null;
try {
workspace = GetWorkspaceObject();
workspace.DisconnectWorkspace(workspaceID);
}
catch (objException) {
workspace = null;
}
}
function onAuthenticated() {
var workspace = null;
var isOnAuthenticatedCalled = false;
if (workspaceID != null && workspaceID != "") {
try {
workspace = GetWorkspaceObject();
workspace.StartWorkspace(workspaceID, domainUserName, password, rdpCertificates, 1200000, 0);
var countUnauthenticatedCredentials = true;
var isWorkspaceCredentialSpecified = workspace.IsWorkspaceCredentialSpecified(workspaceID, countUnauthenticatedCredentials);
if (isWorkspaceCredentialSpecified) {
isOnAuthenticatedCalled = true;
workspace.OnAuthenticated(workspaceID, domainUserName);
}
setTimeout("onAutoDisconnect()", 1200000);
}
catch (objException) {
workspace = null;
var errorCode = (objException.number & 0xFFFF);
if (isOnAuthenticatedCalled) {
if (errorCode == 183) {
// 183 = ERROR_ALREADY_EXISTS.
}
else if (errorCode == 1168) {
// 1168 = ERROR_NOT_FOUND.
}
}
}
}
}
function GetWorkspaceObject() {
var objClientShell = null;
if (g_workspace == null) {
objClientShell = new ActiveXObject("MsRdpWebAccess.MsRdpClientShell");
g_workspace = objClientShell.MsRdpWorkspace;
}
return g_workspace;
}
function LaunchRemoteApp() {
var msRdpClientShell = document.all.MsRdpClient;
msRdpClientShell.PublicMode = true;
msRdpClientShell.RdpFileContents = <%= RDPContents %>;
try {
msRdpClientShell.Launch();
}
catch (e) {
throw e;
}
}
</script>
</head>
<body onload="onAuthenticated();">
<form name="form1" method="post" action="default.aspx" id="form1">
<object name="MsRdpClient" width="0" height="0" id="MsRdpClient" classid="CLSID:6A5B0C7C-5CCB-4F10-A043-B8DE007E1952" type="application/x-oleobject"></object>
YourAppName
</form>
</body>
</html>
Then I created a template RDP file with all the correct content. Notice the remoteapplicationcmdline value has some dummy command line parameters (FirstName, LastName, CustomerID). You'll replace these as appropriate in your code.
redirectclipboard:i:0
redirectposdevices:i:0
redirectprinters:i:0
redirectcomports:i:0
redirectsmartcards:i:0
devicestoredirect:s:
drivestoredirect:s:
redirectdrives:i:0
session bpp:i:32
prompt for credentials:i:0
span monitors:i:0
use multimon:i:0
remoteapplicationmode:i:1
server port:i:3389
allow font smoothing:i:1
promptcredentialonce:i:1
authentication level:i:2
gatewayusagemethod:i:2
gatewayprofileusagemethod:i:0
gatewaycredentialssource:i:0
full address:s:[RemoteAppMachineName]
alternate shell:s:||[YourAppName]
remoteapplicationprogram:s:||[YourAppName]
gatewayhostname:s:
remoteapplicationname:s:[YourAppName]
remoteapplicationcmdline:s:/FirstName:{0} /LastName:{1} /CustomerID:{2}
Workspace Id:s:[RemoteAppMachineName]
Then in the code behind, I load the template rdp file, replace the command line arguments, write to a temp rdp file, sign the temp rdp file, and embed the resulting contents into the javascript at <%= RdpFileContents %>
private string GetRDPContents()
{
FileInfo fileInfo = new FileInfo(Path.Combine(Server.MapPath("~"), "Template.rdp"));
string[] unsignedRDPContents = File.ReadAllLines(fileInfo.FullName);
for (int i = 0; i < unsignedRDPContents.Length; i++)
{
if (unsignedRDPContents[i].IndexOf("remoteapplicationcmdline") != -1)
unsignedRDPContents[i] = String.Format(unsignedRDPContents[i], FirstName, LastName, CustomerID);
}
string tempFileName = Path.Combine(Server.MapPath("~"), Guid.NewGuid().ToString() + ".rdp");
File.WriteAllLines(tempFileName, unsignedRDPContents);
InvokeRDPSign(tempFileName, certificateThumbprint);
string[] signedRDPContents = File.ReadAllLines(tempFileName);
File.Delete(tempFileName);
// This escape function is identical to the javascript escape function.
return String.Format("unescape('{0}')", Microsoft.JScript.GlobalObject.escape(String.Join("\r\n", signedRDPContents)));
}
// This is the certificate's thumbprint.
private const string certificateThumbprint = "04a85503a810cad89f25d3f14c48245f499773c4";
private void InvokeRDPSign(string fileName, string certificateThumbPrint)
{
Process rdpSign = new Process();
rdpSign.StartInfo.FileName = "rdpsign.exe";
rdpSign.StartInfo.Arguments = String.Format("/sha1 {0} \"{1}\"", certificateThumbPrint, fileName);
rdpSign.StartInfo.UseShellExecute = false;
rdpSign.StartInfo.RedirectStandardOutput = true;
rdpSign.StartInfo.RedirectStandardInput = true;
rdpSign.StartInfo.RedirectStandardError = true;
rdpSign.StartInfo.WorkingDirectory = Server.MapPath("~");
rdpSign.Start();
string signingOutput = rdpSign.StandardOutput.ReadToEnd();
rdpSign.WaitForExit();
int exitCode = rdpSign.ExitCode;
}
The final javascript will look something like this:
function LaunchRemoteApp() {
var msRdpClientShell = document.all.MsRdpClient;
msRdpClientShell.PublicMode = true;
msRdpClientShell.RdpFileContents = unescape('redirectclipboard%3Ai%3A0%0D%0A%0D%0Aredirectposdevices%3Ai%3A0%0D%0A%0D%0Aredirectprinters%3Ai%3A0%0D%0A%0D%0Aredirectcomports%3Ai%3A0%0D%0A%0D%0Aredirectsmartcards%3Ai%3A0%0D%0A%0D%0Adevicestoredirect%3As%3A%0D%0A%0D%0Adrivestoredirect%3As%3A%0D%0A%0D%0Aredirectdrives%3Ai%3A0%0D%0A%0D%0Asession%20bpp%3Ai%3A32%0D%0A%0D%0Aprompt%20for%20credentials%3Ai%3A0%0D%0A%0D%0Aspan%20monitors%3Ai%3A0%0D%0A%0D%0Ause%20multimon%3Ai%3A0%0D%0A%0D%0Aremoteapplicationmode%3Ai%3A1%0D%0A%0D%0Aserver%20port%3Ai%3A3389%0D%0A%0D%0Aallow%20font%20smoothing%3Ai%3A1%0D%0A%0D%0Apromptcredentialonce%3Ai%3A1%0D%0A%0D%0Aauthentication%20level%3Ai%3A2%0D%0A%0D%0Agatewayusagemethod%3Ai%3A2%0D%0A%0D%0Agatewayprofileusagemethod%3Ai%3A0%0D%0A%0D%0Agatewaycredentialssource%3Ai%3A0%0D%0A%0D%0Afull%20address%3As%3A[YourMachineName]%0D%0A%0D%0Aalternate%20shell%3As%3A%7C%7C[YourAppName]%0D%0A%0D%0Aremoteapplicationprogram%3As%3A%7C%7C[YourAppName]%0D%0A%0D%0Agatewayhostname%3As%3A%0D%0A%0D%0Aremoteapplicationname%3As%3A[YourAppName]%0D%0A%0D%0Aremoteapplicationcmdline%3As%3A/FirstName%3AJon%20/LastName%3ADoe%20/CustomerID%3A7921385%0D%0A%0D%0Aworkspace%20id%3As%3A[YourMachineName]%0D%0A%0D%0Aalternate%20full%20address%3As%3A[YourMachineName]%0D%0A%0D%0Asignscope%3As%3AFull%20Address%2CAlternate%20Full%20Address%2CServer%20Port%2CGatewayHostname%2CGatewayUsageMethod%2CGatewayProfileUsageMethod%2CGatewayCredentialsSource%2CPromptCredentialOnce%2CAlternate%20Shell%2CRemoteApplicationProgram%2CRemoteApplicationMode%2CRemoteApplicationName%2CRemoteApplicationCmdLine%2CPrompt%20For%20Credentials%2CAuthentication%20Level%2CRedirectDrives%2CRedirectPrinters%2CRedirectCOMPorts%2CRedirectSmartCards%2CRedirectPOSDevices%2CRedirectClipboard%2CDevicesToRedirect%2CDrivesToRedirect%0D%0A%0D%0Asignature%3As%3AAQABAAEAAADgEgAAMIIS3AYJKoZIhvcNAQcCoIISzTCCEskCAQExCzAJBgUrDgMC%20%20GgUAMAsGCSqGSIb3DQEHAaCCEQMwggPFMIICraADAgECAhACrFwmagtAm48LefKu%20%20RiV3MA0GCSqGSIb3DQEBBQUAMGwxCzAJBgNVBAYTAlVTMRUwEwYDVQQKEwxEaWdp%20%20Q2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5jb20xKzApBgNVBAMTIkRp%20%20Z2lDZXJ0IEhpZ2ggQXNzdXJhbmNlIEVWIFJvb3QgQ0EwHhcNMDYxMTEwMDAwMDAw%20%20WhcNMzExMTEwMDAwMDAwWjBsMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNl%20%20cnQgSW5jMRkwFwYDVQQLExB3d3cuZGlnaWNlcnQuY29tMSswKQYDVQQDEyJEaWdp%20%20Q2VydCBIaWdoIEFzc3VyYW5jZSBFViBSb290IENBMIIBIjANBgkqhkiG9w0BAQEF%20%20AAOCAQ8AMIIBCgKCAQEAxszlc+b71LvlLS0ypt/lgT/JzSVJtnEqw9WUNGeiChyw%20%20X2mmQLHEt7KP0JikqUFZOtPclNY823Q4pErMTSWC90qlUxI47vNJbXGRfmO2q6Zf%20%20w6SE+E9iUb74xezbOJLjBuUIkQzEKEFV+8taiRV+ceg1v01yCT2+OjhQW3cxG42z%20%20xyRFmqesbQAUWgS3uhPrUQqYQUEiTmVhh4FBUKZ5XIneGUpX1S7mXRxTLH6YzRoG%20%20FqRoc9A0BBNcoXHTWnxV215k4TeHMFYE5RG0KYAS8Xk5iKICEXwnZreIt3jyygqo%20%20OKsKZMK/Zl2VhMGhJR6HXRpQCyASzEG7bgtROL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OWhsod+A/4HGHgL/Z3febiyhTaIyp9hMY%20%20x0xLArDbcjGCAaEwggGdAgEBMHowZjELMAkGA1UEBhMCVVMxFTATBgNVBAoTDERp%20%20Z2lDZXJ0IEluYzEZMBcGA1UECxMQd3d3LmRpZ2ljZXJ0LmNvbTElMCMGA1UEAxMc%20%20RGlnaUNlcnQgSGlnaCBBc3N1cmFuY2UgQ0EtMwIQDyZO5SPrkaGllR9mdxiQpTAJ%20%20BgUrDgMCGgUAMA0GCSqGSIb3DQEBAQUABIIBAJGNkWq+QeMYRPJZG3+Kwen96uy3%20%208V+6iE5pnGAFzrBPuN1BhvmkhiSDKLcT4ZSI07PNAsuZFLFz7g8yAuVWyWkfCJkn%20%20TAzj7kFCZBUP82ousA+Pp0VMdmfKjKfqOlJKPMpNJ6AKSHT1aAw4N2ZuzhnddZ/I%20%20HzrOoIJ9McvrMzGQSmhA4MefBg1ppqbudo1QCvVfOdwWg5KijHKIkVOe9BI8Dyic%20%20+cLu3iJ1jF3IMwMQb2Q4JX/FgIFMy9Hf12uhx9HP0JnR2sp5AnwfAGqPj2RSCmoA%20%20Px1XJxuea7WjMBnfTCUuQjuD/hfYdyTmj95G2nuZZM2Za4438JWPMPMW5ro%3D%20%20%0D%0A');
try {
msRdpClientShell.Launch();
}
catch (e) {
throw e;
}
}
I tried to escape the rdp contents myself but could never get it to work. If you don't have access to Microsoft.JScript.GlobalObject.escape() function, you can try it yourself. Here are some of the character entity references I know of:
Replace : with %3A
Replace | with %7C
Replace \r\n with %0D%0A
Replace spaces with %20
No extra spaces after lines.

How to programmatically set the task outcome (task response) of a Nintex Flexi Task?

Is there any way of set a Nintex Flexi task completion through Sharepoint's web services? We have tried updating the "WorkflowOutcome", "ApproverComments" and "Status" fields without success (actually the comments and status are successfully updated, however I can find no way of updating the WorkflowOutcome system field).
I can't use the Nintex Web service (ProcessTaskResponse) because it needs the task's assigned user's credentials (login, password, domain).
The Asp.net page doesn't have that information, it has only the Sharepoint Administrator credentials.
One way is to delegate the task to the admin first, and then call ProcessTaskResponse, but it isn't efficient and is prone to errors.
In my tests so far, any update (UpdateListItems) to the WorkflowOutcome field automatically set the Status field to "Completed" and the PercentComplete field to "1" (100%), ending the task (and continuing the flow), but with the wrong answer: always "Reject", no matter what I try to set it to.
Did you try this code: (try-cacth block with redirection does the trick)
\\set to actual outcome id here, for ex. from OutComePanel control
taskItem[Nintex.Workflow.Common.NWSharePointObjects.FieldDecision] = 0;
taskItem[Nintex.Workflow.Common.NWSharePointObjects.FieldComments] = " Some Comments";
taskItem.Update();
try
{
Nintex.Workflow.Utility.RedirectOrCloseDialog(HttpContext.Current, Web.Url);
}
catch
{
}
?
Here are my code to change outcome of nintex flexi task. My problem is permission. I had passed admin token to site. It's solve the problem.
var siteUrl = "...";
using (var tempSite = new SPSite(siteUrl))
{
var sysToken = tempSite.SystemAccount.UserToken;
using (var site = new SPSite(siteUrl, sysToken))
{
var web = site.OpenWeb();
...
var cancelled = "Cancelled";
task.Web.AllowUnsafeUpdates = true;
Hashtable ht = new Hashtable();
ht[SPBuiltInFieldId.TaskStatus] = SPResource.GetString(new CultureInfo((int)task.Web.Language, false), Strings.WorkflowStatusCompleted, new object[0]);
ht["Completed"] = true;
ht["PercentComplete"] = 1;
ht["Status"] = "Completed";
ht["WorkflowOutcome"] = cancelled;
ht["Decision"] = CommonHelper.GetFlexiTaskOutcomeId(task, cancelled);
ht["ApproverComments"] = "cancelled";
CommonHelper.AlterTask((task as SPListItem), ht, true, 5, 100);
task.Web.AllowUnsafeUpdates = false;
}
}
}
}
}
}
public static string GetFlexiTaskOutcomeId(Microsoft.SharePoint.Workflow.SPWorkflowTask task, string outcome)
{
if (task["MultiOutcomeTaskInfo"] == null)
{
return string.Empty;
}
string xmlOutcome = HttpUtility.HtmlDecode(task["MultiOutcomeTaskInfo"].ToString());
if (string.IsNullOrEmpty(xmlOutcome))
{
return string.Empty;
}
XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlOutcome);
var node = doc.SelectSingleNode(string.Format("/MultiOutcomeResponseInfo/AvailableOutcomes/ConfiguredOutcome[#Name='{0}']", outcome));
return node.Attributes["Id"].Value;
}
public static bool AlterTask(SPListItem task, Hashtable htData, bool fSynchronous, int attempts, int milisecondsTimeout)
{
if ((int)task[SPBuiltInFieldId.WorkflowVersion] != 1)
{
SPList parentList = task.ParentList.ParentWeb.Lists[new Guid(task[SPBuiltInFieldId.WorkflowListId].ToString())];
SPListItem parentItem = parentList.Items.GetItemById((int)task[SPBuiltInFieldId.WorkflowItemId]);
for (int i = 0; i < attempts; i++)
{
SPWorkflow workflow = parentItem.Workflows[new Guid(task[SPBuiltInFieldId.WorkflowInstanceID].ToString())];
if (!workflow.IsLocked)
{
task[SPBuiltInFieldId.WorkflowVersion] = 1;
task.SystemUpdate();
break;
}
if (i != attempts - 1)
{
Thread.Sleep(milisecondsTimeout);
}
}
}
var result = SPWorkflowTask.AlterTask(task, htData, fSynchronous);
return result;
}