I have a code that reads my Xslt templates from Resources but I have to make it reads from seperated files in root directory of application. So this is my code:
docs[0] = new DocumentReferenceType
{
ID = new IDType { Value = new Guid().ToString() },
IssueDate = new IssueDateType { Value = DateTime.Now },
DocumentType = new DocumentTypeType { Value = "xslt" },
Attachment = new AttachmentType
{
EmbeddedDocumentBinaryObject = new EmbeddedDocumentBinaryObjectType
{
filename = "customxslt.xslt",
encodingCode = "Base64",
mimeCode = "applicationxml",
format = "",
characterSetCode = "UTF-8",
Value = Encoding.UTF8.GetBytes(Properties.Resource1.XSLTFile)
}
}
};
return docs;
What should I write to "Properties.Resource1.XSLTFile" read from XSLTFile.xslt in root directory? I tried to write this:
string _filePath = Path.GetDirectoryName(System.AppDomain.CurrentDomain.BaseDirectory);
_filePath += #"\XSLTFile.xslt";
And I changed "Properties.Resource1.XSLTFile" with "_filePath " there but it gave me this error: "HTML conversion failed: XSLT compilation error"
i got help and i am sharing maybe there will be someone who needs it
string _filePath = Path.GetDirectoryName(System.AppDomain.CurrentDomain.BaseDirectory);
_filePath += #"\xslt\earsiv.xslt";
string xs = System.IO.File.ReadAllText(_filePath);
docs[0] = new DocumentReferenceType
{
ID = new IDType { Value = new Guid().ToString() },
IssueDate = new IssueDateType { Value = DateTime.Now },
DocumentType = new DocumentTypeType { Value = "xslt" },
Attachment = new AttachmentType
{
EmbeddedDocumentBinaryObject = new EmbeddedDocumentBinaryObjectType
{
filename = "customxslt.xslt",
encodingCode = "Base64",
mimeCode = "applicationxml",
format = "",
characterSetCode = "UTF-8",
Value = Encoding.UTF8.GetBytes(xs)
}
}
};
return docs;
Related
I'm trying to read a text file from WhatsApp and can find the filename in the intent, but not the file itself.
Also confused as to what the MIME type should be. Should "text/plain" be used for both shared text AND a shared text file? How does one differentiate between one and the other?
[IntentFilter(new[] { Intent.ActionSend },
Categories = new[] { Intent.CategoryDefault },
DataMimeType = #"text/plain", Icon = "#drawable/icon")]
void HandleSendIntent(Intent intent)
{
//extra1 = "myfile.txt"
var extra1 = intent?.GetStringExtra(Intent.ExtraText)?.Trim();
//extra2 = null
var extra2 = intent?.GetStringExtra(Intent.ExtraProcessText)?.Trim();
//uri = {content://com.whatsapp.provider.media/item/83019679-d3d1-4e43-805e-7a05734e88df}
Android.Net.Uri uri = (Android.Net.Uri)intent.GetParcelableExtra(Intent.ExtraStream);
string doc_id = "";
using (var c1 = ContentResolver.Query(uri, null, null, null, null))
{
c1.MoveToFirst();
string document_id = c1.GetString(0);
//doc_id = "myfile.txt":
doc_id = document_id.Substring(document_id.LastIndexOf(":") + 1);
}
//a = null
var a = Intent.GetParcelableArrayExtra("com.whatsapp");
//b = null
var b = Intent.GetByteArrayExtra("com.whatsapp");
//c = "text/plain"
var c = Intent.Type;
//
//Where is the file????
//
}
Hi I am developing a chatbot on amazon lex and I want to send a response card using the lambda function but on using response card function inside the close response format it gives the error of null exception. Can anyone tell the solution to it?
PS I am using FlowerOrder blueprint created by Nikki.
if (slots[greet] != null)
{
var validateGreet = ValidateUserGreeting(slots[greet]);
if (validateGreet.IsValid)
{
return Close(sessionAttributes,
"Fulfilled",
new LexResponse.LexMessage
{
ContentType = "PlainText",
Content = String.Format("Hello Kindly choose one option")
},
new LexResponse.LexResponseCard
{
Version = 1,
ContentType = "application/vnd.amazonaws.card.generic",
GenericAttachments =
{
new LexResponse.LexGenericAttachments
{
Buttons =
{
new LexResponse.LexButton
{
Text = "Shop Now",
Value = "Shop Now"
}
},
AttachmentLinkUrl = null,
Title = "Shopping",
SubTitle = "Sub Shopping",
ImageUrl = null
}
}
}
);
}
Exception:-
2020-06-09 17:31:20: Object reference not set to an instance of an object.: NullReferenceException at EVS_Test_Abbar_Lambda_Function.OrderWatchIntentProcessorTest.Process(LexEvent lexEvent, ILambdaContext context) in D:\AWS Project\Abbrar Projects\EVS_Test_Abbar_Lambda_Function\EVS_Test_Abbar_Lambda_Function\OrderWatchIntentProcessorTest.cs:line 52 at EVS_Test_Abbar_Lambda_Function.Function.FunctionHandler(LexEvent lexEvent, ILambdaContext context) in D:\AWS Project\Abbrar Projects\EVS_Test_Abbar_Lambda_Function\EVS_Test_Abbar_Lambda_Function\Function.cs:line 43
at lambda_method(Closure , Stream , Stream , LambdaContextInternal )
Here is the solution to it since if you look at the structure of JSON it contains many models and lists and each has to be handled separately.
LexResponse.LexResponseCard lexResponseCard = new LexResponse.LexResponseCard();
List<LexResponse.LexGenericAttachments> ListlexGenericAttachments = new List<LexResponse.LexGenericAttachments>();
LexResponse.LexGenericAttachments lexGenericAttachments = new LexResponse.LexGenericAttachments();
List<LexResponse.LexButton> ListlexButton = new List<LexResponse.LexButton>();
LexResponse.LexButton lexButton = new LexResponse.LexButton();
lexButton.Text = "Yes Now";
lexButton.Value = "Yes";
ListlexButton.Add(lexButton);
lexGenericAttachments.AttachmentLinkUrl = "Link";
//lexGenericAttachments.AttachmentLinkUrl = null;
lexGenericAttachments.Title = "Shopping";
lexGenericAttachments.SubTitle = "Sub Shopping";
lexGenericAttachments.ImageUrl = "Link";
//lexGenericAttachments.ImageUrl = null;
lexGenericAttachments.Buttons = ListlexButton;
ListlexGenericAttachments.Add(lexGenericAttachments);
lexResponseCard.Version = 0;
lexResponseCard.ContentType = "application/vnd.amazonaws.card.generic";
lexResponseCard.GenericAttachments = ListlexGenericAttachments;
return Close(sessionAttributes,
"Fulfilled",
new LexResponse.LexMessage
{
ContentType = "PlainText",
Content = String.Format("Hello Kindly choose one option")
},
lexResponseCard
);
It may be your capitalization of key names. For example you have ContentType but it should be contentType as camelcase beginning with lowercase letters.
return Close(sessionAttributes,
"Fulfilled",
new LexResponse.LexMessage
{
contentType = "PlainText",
content = String.Format("Hello Kindly choose one option")
},
new LexResponse.LexResponseCard
{
version = 1,
contentType = "application/vnd.amazonaws.card.generic",
GenericAttachments =
{
new LexResponse.LexGenericAttachments
{
Buttons =
{
new LexResponse.LexButton
{
text = "Shop Now",
value = "Shop Now"
}
},
attachmentLinkUrl = null,
title = "Shopping",
subTitle = "Sub Shopping",
imageUrl = null
}
}
}
);
try just one Lex Response Card .
return Close(sessionAttributes,
"Fulfilled"
new LexResponse.LexResponseCard
{
version = 1,
contentType = "application/vnd.amazonaws.card.generic",
GenericAttachments =
{
new LexResponse.LexGenericAttachments
{
Buttons =
{
new LexResponse.LexButton
{
text = "Shop Now",
value = "Shop Now"
}
},
attachmentLinkUrl = null,
title = "Shopping",
subTitle = "Sub Shopping",
imageUrl = null
}
}
}
);
I am trying to use AWS SDK for .NET Core.
Create a table to count views on videos.
Add a view count for a day.
Increment existing count for a day.
Query for video counts between two dates for a video.
.NET Core AWS SDK uses Async methods which are not documented in AWS. There is a feature request on their github page for this to happen.... but it is dated from last year. (https://github.com/aws/aws-sdk-net/issues/787)
CREATE THE TABLE
This works and creates a table on the AWS Console.
var ctRequest = new CreateTableRequest
{
AttributeDefinitions = new List<AttributeDefinition>()
{
new AttributeDefinition
{
AttributeName = "ViewUid",
AttributeType = ScalarAttributeType.S
},
new AttributeDefinition
{
AttributeName = "ViewDate",
AttributeType = ScalarAttributeType.S
}
},
KeySchema = new List<KeySchemaElement>
{
new KeySchemaElement
{
AttributeName = "ViewUid",
KeyType = KeyType.HASH //Partition key
},
new KeySchemaElement
{
AttributeName = "ViewDate",
KeyType = KeyType.RANGE
}
},
ProvisionedThroughput = new ProvisionedThroughput
{
ReadCapacityUnits = 5,
WriteCapacityUnits = 6
},
TableName = _settings.AWSDynamoDBViewCountTable
};
var response = _client.CreateTableAsync(ctRequest).Result;
UPDATE AND ITEM WITH AUTO-INCREMENT A FIELD
This, sadly, is where i hit issues. The old docs are found here under the Atomic Counter section. (https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/LowLevelDotNetItemCRUD.html)
Invalid ConditionExpression: Syntax error; token: \"SET\", near: \"SET
VC\"
var viewData = new Document();
viewData["ViewUid"] = videoUid; //Table entry UID
viewData["VideoId"] = videoId; // Video ID
viewData["ViewDate"] = date;
viewData["ViewCount"] = 0;
//Document result = await _viewCountTable.PutItemAsync(viewData);
Expression expr = new Expression();
expr.ExpressionStatement = "SET #VC = #VC + :val";
expr.ExpressionAttributeValues[":val"] = 1;
expr.ExpressionAttributeNames["#VC"] = "ViewCount";
var updateConfig = new UpdateItemOperationConfig() {
ConditionalExpression = expr,
ReturnValues = ReturnValues.UpdatedNewAttributes
};
var result = await _viewCountTable.UpdateItemAsync(viewData, updateConfig);
return result;
QUERY FOR DATE RANGE
Get one video's view count for a date range.
string queryTimeSpanStartString = dateFrom.ToString(AWSSDKUtils.ISO8601DateFormat);
string queryTimeSpanEndString = dateTo.ToString(AWSSDKUtils.ISO8601DateFormat);
var request = new QueryRequest
{
TableName = _settings.AWSDynamoDBViewCountTable,
KeyConditions = new Dictionary<string, Condition>()
{
{
"VideoId", new Condition()
{
ComparisonOperator = "EQ",
AttributeValueList = new List<AttributeValue>()
{
new AttributeValue { S = videoId }
}
}
},
{
"ViewDate",
new Condition
{
ComparisonOperator = "BETWEEN",
AttributeValueList = new List<AttributeValue>()
{
new AttributeValue { S = queryTimeSpanStartString },
new AttributeValue { S = queryTimeSpanEndString }
}
}
}
}
};
var response = await _client.QueryAsync(request);
Any help would be appreciated.
I was able to update the ViewCount with the following code:
string tableName = "videos";
var request = new UpdateItemRequest
{
Key = new Dictionary<string, AttributeValue>() { { "ViewUid", new AttributeValue { S = "replaceVideoIdhere" } } },
ExpressionAttributeNames = new Dictionary<string, string>()
{
{"#Q", "ViewCount"}
},
ExpressionAttributeValues = new Dictionary<string, AttributeValue>()
{
{":incr", new AttributeValue {N = "1"}}
},
UpdateExpression = "SET #Q = #Q + :incr",
TableName = tableName
};
var response = await _dynamoDbClient.UpdateItemAsync(request);
I created a table called "videos" with a partition key named "ViewUid" as string. Let me know if this works for you.
I am using C# implementation of netsuite api from web reference com.netsuite.webservices
I released filter fileSearch.basic by name (you can see it commented) it is working fine.
Please help to write function to achieve all attached files for current user. Something is wrong in this code, it filters nothing and showing me all files as it is without any filter. Please help me.
public static void GetFileAttachmentByCustomerId(string customerId)
{
using (NetSuiteService netSuiteService = GetNetSuiteService())
{
FileSearch fileSearch = new FileSearch();
// this works fine (filter files by name)
//SearchStringField nameSearchParams = new SearchStringField
//{
// #operator = SearchStringFieldOperator.contains,
// operatorSpecified = true,
// searchValue = "some name",
//};
//fileSearch.basic = new FileSearchBasic() { name = nameSearchParams };
// this code not filter files at all
{
RecordRef nsCustomerRef = new RecordRef
{
internalId = customerId,
type = RecordType.customer,
typeSpecified = true,
};
SearchMultiSelectField shopperSearchParam = new SearchMultiSelectField
{
#operator = SearchMultiSelectFieldOperator.anyOf,
operatorSpecified = true,
searchValue = new RecordRef[] { nsCustomerRef }
};
fileSearch.shopperJoin = new CustomerSearchBasic { internalId = shopperSearchParam };
}
SearchResult result = netSuiteService.search(fileSearch);
// Get connected objects
{
Customer customer = GetCustomerById(netSuiteService, customerId);
Account account = GetAccountById(netSuiteService, "301395"); //
Folder folder = GetFolderById(netSuiteService, "3962");
}
File file = (File)result.recordList.First();
byte[] fileContent = GetFileContentByInternalId(file.internalId);
}
}
.
Try this:
var nsCustomerRef = new RecordRef
{
internalId = "4",
type = RecordType.employee,
typeSpecified = true,
};
var currentUser = new SearchMultiSelectField()
{
operatorSpecified = true,
#operator = SearchMultiSelectFieldOperator.anyOf,
searchValue = new List<RecordRef>() {nsCustomerRef}.ToArray()
};
var fileSearchBasic = new FileSearchBasic() {owner = currentUser};
var fileSearch = new FileSearch() { basic = fileSearchBasic };
var result = netSuiteService.search(fileSearch);
var file = (File)result.recordList.First();
I'm getting the following error:
One or more of the input parameters to the service method is missing or invalid.
when
ObjectService.createDocument(repositoryId, objectPropertyCollection, rootFolderId, myContentStream, ObjectService.enumVersioningState.none, null, addAclcontrol, null, ref extType);
is called. This is how I have setup all of those parameters:
//Get repositoryId, and rootFolder id.
string repositoryId = RepositoryStore[contentType];
RepositoryService.cmisRepositoryInfoType repoInfo =_controller.RepositoryClient.getRepositoryInfo(repositoryId, new RepositoryService.cmisExtensionType());
string rootFolder = repoInfo.rootFolderId;
string theActualName = filename.Substring(filename.LastIndexOf("\\") + 1);
//Create a cmisContentStreamType.
ObjectService.cmisContentStreamType fileStream = new ObjectService.cmisContentStreamType();
fileStream.stream = File.ReadAllBytes(filename);
fileStream.filename = theActualName;
fileStream.length = fileStream.stream.Length.ToString();
fileStream.mimeType = "application/pdf";
//Setting the acl objects needed to create the document.
ObjectService.cmisAccessControlEntryType homeMembers = new ObjectService.cmisAccessControlEntryType();
ObjectService.cmisAccessControlEntryType owners = new ObjectService.cmisAccessControlEntryType();
ObjectService.cmisAccessControlEntryType viewers = new ObjectService.cmisAccessControlEntryType();
ObjectService.cmisAccessControlEntryType visitors = new ObjectService.cmisAccessControlEntryType();
ObjectService.cmisAccessControlPrincipalType ownersPrincipalType = new ObjectService.cmisAccessControlPrincipalType();
ownersPrincipalType.principalId = #"Home Owners";
owners.principal = ownersPrincipalType;
owners.permission = new string[] { "cmis:all" };
ObjectService.cmisAccessControlPrincipalType homePrincipalType = new ObjectService.cmisAccessControlPrincipalType();
homePrincipalType.principalId = #"Home Members";
homeMembers.principal = homePrincipalType;
homeMembers.permission = new string[] { "cmis:write" };
ObjectService.cmisAccessControlPrincipalType viewersPrincipalType = new ObjectService.cmisAccessControlPrincipalType();
homePrincipalType.principalId = #"Viewers";
homeMembers.principal = viewersPrincipalType;
homeMembers.permission = new string[] { "cmis:read" };
ObjectService.cmisAccessControlPrincipalType visitorsPrincipalType = new ObjectService.cmisAccessControlPrincipalType();
homePrincipalType.principalId = #"Home Visitors";
homeMembers.principal = visitorsPrincipalType;
homeMembers.permission = new string[] { "cmis:read" };
ObjectService.cmisAccessControlEntryType[] addAclControl = new ObjectService.cmisAccessControlEntryType[] { homeMembers, owners, viewers, visitors };
ObjectService.cmisExtensionType exttype = new ObjectService.cmisExtensionType();
ObjectService.cmisPropertiesType objectPropertyArray = MakedocumentPropertiesList(theActualName,fileStream.length);
private ObjectService.cmisPropertiesType MakedocumentPropertiesList(string fileName,string contentStreamLength)
{
List<ObjectService.cmisProperty> arrProps = new List<ObjectService.cmisProperty>();
ObjectService.cmisPropertiesType props = new ObjectService.cmisPropertiesType();
arrProps.Add(GetPropertyString("Name", "cmis:name", "mydocuemntname", "FileLeafRef"));
arrProps.Add(GetPropertyId("cmis:baseTypeId", "cmis:baseTypeId", "cmis:document", "cmis:baseTypeId"));
props.Items = arrProps.ToArray();
return props;
}
private ObjectService.cmisPropertyString GetPropertyString(string displayName, string queryName, string value, string localName)
{
ObjectService.cmisPropertyString title = new ObjectService.cmisPropertyString();
title.localName = localName;
title.displayName = displayName;
title.queryName = queryName;
title.propertyDefinitionId = displayName;
title.value = new string[] { value };
return title;
}
private ObjectService.cmisPropertyId GetPropertyId(string displayName, string queryName, string value, string localName)
{
ObjectService.cmisPropertyId id = new ObjectService.cmisPropertyId();
id.localName = localName;
id.displayName = displayName;
id.queryName = queryName;
id.propertyDefinitionId = displayName;
id.value = new string[] { value };
return id;
}
You cannot set the "cmis:baseTypeId" property, but you have to set the "cmis:objectTypeId" property. Try exchanging the id of your second property.
Apart from that, you should have a look at DotCMIS. It could save you a lot of work.
I took your code and I correct it .. now it is functional for me .. take a look :
string user = txtLogin.Text;
string password = txtPwd.Text;
DemoCMISForms.RepositoryService.RepositoryServicePortClient repService = new DemoCMISForms.RepositoryService.RepositoryServicePortClient("BasicHttpBinding_IRepositoryServicePort2");
repService.ClientCredentials.UserName.UserName = user;
repService.ClientCredentials.UserName.Password = password;
DemoCMISForms.ObjectService.ObjectServicePortClient objectService = new DemoCMISForms.ObjectService.ObjectServicePortClient("BasicHttpBinding_IObjectServicePort2");
objectService.ClientCredentials.UserName.UserName = user;
objectService.ClientCredentials.UserName.Password = password;
//Get repositoryId, and rootFolder id.
RepositoryService.cmisRepositoryInfoType repoInfo = repService.getRepositoryInfo(idRep, new RepositoryService.cmisExtensionType());
string rootFolder = repoInfo.rootFolderId;
string theActualName = textBox1.Text.Substring(textBox1.Text.LastIndexOf("\\") + 1);
//Create a cmisContentStreamType.
ObjectService.cmisContentStreamType fileStream = new ObjectService.cmisContentStreamType();
fileStream.stream = File.ReadAllBytes(textBox1.Text);
fileStream.filename = theActualName;
fileStream.length = fileStream.stream.Length.ToString();
fileStream.mimeType = "text/plain";
//Setting the acl objects needed to create the document.
ObjectService.cmisAccessControlEntryType homeMembers = new ObjectService.cmisAccessControlEntryType();
ObjectService.cmisAccessControlEntryType owners = new ObjectService.cmisAccessControlEntryType();
ObjectService.cmisAccessControlEntryType viewers = new ObjectService.cmisAccessControlEntryType();
ObjectService.cmisAccessControlEntryType visitors = new ObjectService.cmisAccessControlEntryType();
ObjectService.cmisAccessControlPrincipalType ownersPrincipalType = new ObjectService.cmisAccessControlPrincipalType();
ownersPrincipalType.principalId = #"Home Owners";
owners.principal = ownersPrincipalType;
owners.permission = new string[] { "cmis:all" };
ObjectService.cmisAccessControlPrincipalType homePrincipalType = new ObjectService.cmisAccessControlPrincipalType();
homePrincipalType.principalId = #"Home Members";
homeMembers.principal = homePrincipalType;
homeMembers.permission = new string[] { "cmis:write" };
ObjectService.cmisAccessControlPrincipalType viewersPrincipalType = new ObjectService.cmisAccessControlPrincipalType();
viewersPrincipalType.principalId = #"Viewers";
viewers.principal = viewersPrincipalType;
viewers.permission = new string[] { "cmis:read" };
ObjectService.cmisAccessControlPrincipalType visitorsPrincipalType = new ObjectService.cmisAccessControlPrincipalType();
visitorsPrincipalType.principalId = #"Home Visitors";
visitors.principal = visitorsPrincipalType;
visitors.permission = new string[] { "cmis:read" };
ObjectService.cmisAccessControlEntryType[] addAclControl = new ObjectService.cmisAccessControlEntryType[] { homeMembers, owners, viewers, visitors };
ObjectService.cmisExtensionType exttype = new ObjectService.cmisExtensionType();
ObjectService.cmisPropertiesType objectPropertyArray = MakedocumentPropertiesList(theActualName, fileStream.length);
objectService.createDocument(idRep, objectPropertyArray, idFolder, fileStream, ObjectService.enumVersioningState.major, null, addAclControl, null, ref exttype);
}
private ObjectService.cmisPropertiesType MakedocumentPropertiesList(string fileName, string contentStreamLength)
{
List<ObjectService.cmisProperty> arrProps = new List<ObjectService.cmisProperty>();
ObjectService.cmisPropertiesType props = new ObjectService.cmisPropertiesType();
arrProps.Add(GetPropertyString(fileName, "cmis:name", fileName, "FileLeafRef"));
arrProps.Add(GetPropertyId("cmis:objectTypeId", "cmis:objectTypeId", "cmis:document", "cmis:objectTypeId"));
props.Items = arrProps.ToArray();
return props;
}
private ObjectService.cmisPropertyString GetPropertyString(string displayName, string queryName, string value, string localName)
{
ObjectService.cmisPropertyString title = new ObjectService.cmisPropertyString();
title.localName = localName;
title.displayName = displayName;
title.queryName = queryName;
title.propertyDefinitionId = displayName;
title.value = new string[] { value };
return title;
}
private ObjectService.cmisPropertyId GetPropertyId(string displayName, string queryName, string value, string localName)
{
ObjectService.cmisPropertyId id = new ObjectService.cmisPropertyId();
id.localName = localName;
id.displayName = displayName;
id.queryName = queryName;
id.propertyDefinitionId = displayName;
id.value = new string[] { value };
return id;
}
I found some variables that were left unchanged after a copy paste manip! I also used this example with a text file !
Hope I helped you!
PS: I didnt handle yet the problem of document types , i just made the example functionnal with Text files.. Also the versionning in the list I'm calling from the SP Site is an issue so i have to verify before I add any document..