How to send a excel attachment in QCubed - excel

This is what i am trying
$attach is the path to my excel => c:/xampp/htdocs/project/excel.xlsx
Notification::SendEmail('xyz#gmail.com', 'abc#gmail.com', "Subject","message", $attach);
If the$attach is removed then the email will go.
But it fails if i add the attachment
SendEmail function
public static function SendEmail($mixFrom, $mixTo, $strSubject, $strMessage, $mixAttachment = null, $mixCc = null, $mixBcc = null) {
// Declaration of Local Variables
$strSMTPHost = QApplication::getSettingValue(Mssetting::SMTP_HOST);
$strSMTPPort = QApplication::getSettingValue(Mssetting::SMTP_PORT);
$objMessage = Swift_Message::newInstance($strSubject, $strMessage, 'text/html');
// Set the source/destination data
$objMessage->setFrom($mixFrom);
$objMessage->setTo($mixTo);
$objMessage->setCc($mixCc);
$objMessage->setBcc($mixBcc);
// Check for attachments
if(is_array($mixAttachment)) {
foreach($mixAttachment as $strFilePath)
$objMessage->attach (Swift_Attachment::fromPath ($strFilePath));
}
elseif(is_string($mixAttachment)) {
$objMessage->attach(Swift_Attachment::fromPath($mixAttachment));
}
// Setup the transport
$objTransport = Swift_SmtpTransport::newInstance();
if($strSMTPHost) $objTransport->setHost ($strSMTPHost);
if($strSMTPPort) $objTransport->setPort($strSMTPPort);
// Setup the mailer
$objMailer = Swift_Mailer::newInstance($objTransport);
// Send the message
$objMailer->send($objMessage, $arrFailures);
if($arrFailures)
return $arrFailures;
return true;
}

I got the answer for this,
use this code:
$Attachment = $file_path; // path to your excel
Notification::SendEmail('from#abc.com',to#abc,com, "Subject", "Message", $Attachment);
in Notification.php
class Notification {
public static function SendEmail($mixFrom, $mixTo, $strSubject, $strMessage, $mixAttachment, $mixCc = null, $mixBcc = null) {
// Declaration of Local Variables
$strSMTPHost = QApplication::getSettingValue(Mssetting::SMTP_HOST);
$strSMTPPort = QApplication::getSettingValue(Mssetting::SMTP_PORT);
$objMessage = Swift_Message::newInstance($strSubject, $strMessage, 'text/html');
// Set the source/destination data
$objMessage->setFrom($mixFrom);
$objMessage->setTo($mixTo);
$objMessage->setCc($mixCc);
$objMessage->setBcc($mixBcc);
// Check for attachments
if(is_array($mixAttachment)) {
foreach($mixAttachment as $strFilePath)
$objMessage->attach (Swift_Attachment::fromPath ($strFilePath));
}
elseif(is_string($mixAttachment)) {
$objMessage->attach(Swift_Attachment::fromPath($mixAttachment));
}
// Setup the transport
$objTransport = Swift_SmtpTransport::newInstance();
if($strSMTPHost) $objTransport->setHost ($strSMTPHost);
if($strSMTPPort) $objTransport->setPort($strSMTPPort);
// Setup the mailer
$objMailer = Swift_Mailer::newInstance($objTransport);
// Send the message
$objMailer->send($objMessage, $arrFailures);
if($arrFailures)
return $arrFailures;
return true;
}
This will do the work.

Related

Cast Application Framework receiver app not working on external cast device 2nd Geneation

I'm trying to develop CAF v3 receiver app and it's working with in-built and setup boxes cast devices but not working on external cast devices.
External cast devices NC2-A65 throws PIPELINE_INITIALIZATION_ERROR or VIDEO_ERROR with shaka error code 3016
After debugging, observation is drm License Url doesn't get called when useLegacyDashSupport is true
Any help is appreciated
Here is the code,
<script>
const context = cast.framework.CastReceiverContext.getInstance();
context.setLoggerLevel(cast.framework.LoggerLevel.DEBUG);
const options = new cast.framework.CastReceiverOptions();
const castDebugLogger = cast.debug.CastDebugLogger.getInstance();
const playerManager = context.getPlayerManager();
const playbackConfig = (Object.assign(new cast.framework.PlaybackConfig(), playerManager.getPlaybackConfig()));
options.maxInactivity = 3600;
options.supportedCommands = cast.framework.messages.Command.ALL_BASIC_MEDIA;
castDebugLogger.setEnabled(true);
// Show debug overlay
castDebugLogger.showDebugLogs(true);
let useLegacyDashSupport = false;
if (context.canDisplayType('video/mp4; codecs="avc1.640028"; width=3840; height=2160')) {
// The device and display can both do 4k. Assume a 4k limit.
castDebugLogger.info("Hardware Resolution: ", '3840x2160');;
options.touchScreenOptimizedApp = true;
} else {
// Chromecast has always been able to do 1080p. Assume a 1080p limit.
castDebugLogger.info("Hardware Resolution: ", '1920x1080');
useLegacyDashSupport = true;
}
options.useLegacyDashSupport = useLegacyDashSupport;
context.loadPlayerLibraries(useLegacyDashSupport);
context.addEventListener(cast.framework.system.EventType.ERROR, event => {
castDebugLogger.info('Context Error - ', JSON.stringify(event));
});
playerManager.addEventListener(cast.framework.events.EventType.ERROR, event => {
castDebugLogger.info('Error - ', "ERROR event: " + JSON.stringify(event));
});
playerManager.addEventListener(cast.framework.events.EventType.MEDIA_STATUS, (event) => {
castDebugLogger.info('Player State - ', event.mediaStatus.playerState);
});
// Intercept the LOAD request to be able to read in a contentId and get data.
playerManager.setMessageInterceptor(cast.framework.messages.MessageType.LOAD, loadRequestData => {
castDebugLogger.info('LoadRequest Data - ', JSON.stringify(loadRequestData));
const error = new cast.framework.messages.ErrorData(cast.framework.messages.ErrorType.LOAD_CANCELLED);
if (!loadRequestData.media) {
error.reason = cast.framework.messages.ErrorReason.INVALID_PARAM;
return error;
}
if (!loadRequestData.media.contentId) {
error.reason = cast.framework.messages.ErrorReason.INVALID_PARAM;
return error;
}
loadRequestData.autoplay = true;
let url = loadRequestData.media.contentId;
castDebugLogger.info('Content Id - ', url);
const ext = url.substring(url.lastIndexOf('.'), url.length);
loadRequestData.media.contentType = 'video/mp4';
if (ext.includes('mpd')) {
loadRequestData.media.contentType = 'application/dash+xml';
} else if (ext.includes('m3u8')) {
loadRequestData.media.contentType = 'application/vnd.apple.mpegurl';
// TODO: Create option to set hlsSegmentFormat option.
loadRequestData.media.hlsSegmentFormat = cast.framework.messages.HlsSegmentFormat.TS;
} else if (ext.includes('ism')) {
loadRequestData.media.contentType = 'application/vnd.ms-sstr+xml';
}
if (loadRequestData.media.customData && loadRequestData.media.customData.drm) {
playerManager.setMediaPlaybackInfoHandler((loadRequest, playbackConfigData) => {
playbackConfigData.licenseUrl = loadRequest.media.customData.drm.widevine.url;
playbackConfigData.protectionSystem = cast.framework.ContentProtection.WIDEVINE;
castDebugLogger.info('PlaybackConfig Data - ', JSON.stringify(playbackConfigData));
return playbackConfigData;
});
}
return loadRequestData;
});
options.playbackConfig = playbackConfig;
context.start(options);
</script>

Bot builder : Adaptive cards - call a method when submitting

I need to create a form in which the user has to fill it and to send it. So i have to create a submit button that calls another method but i couldn't find the link between the submit action and the call to another method.
The script of my form is :
public Attachment CreateAdaptiveCardwithEntry()
{
var submitActionData = JObject.Parse("{ \"Type\": \"SaveFunction\" }");
var card = new AdaptiveCard()
{
Body = new List<CardElement>()
{
// Hotels Search form
new TextBlock() { Text = "Titre de la note des frais" },
new TextInput()
{
Id = "titre",
Speak = "<s>Veuillez saisir le titre</s>",
Placeholder = "Veuillez saisir le titre",
Style = TextInputStyle.Text
},
},
Actions = new List<ActionBase>()
{
new SubmitAction()
{
DataJson = submitActionData.ToString()
}
}
};
The script of my card is :
var replyMessage = context.MakeMessage();
replyMessage.Attachments = new List<Attachment> { FraisDialog.CreateAdaptiveCardwithEntry() };
await context.PostAsync(replyMessage, CancellationToken.None);
context.Wait(MessageReceived);
the script in MessageReceivedAsync is :
public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
{
var message = await result;
if (message.Value != null)
{
// Got an Action Submit
dynamic value = message.Value;
string submitType = value.Type.ToString();
switch (submitType)
{
case "SaveFunction":
await context.PostAsync("Please complete all the search parameters:\n");
return;
}
}
}
In this example i need to send the information with the Id = "titre" and pprocess it afterwards, i don't know how to send it(DataJson ?) and where(MessageReceivedAsync ?). Can someone help me ? do i need to create another dialog just for the card ?
Ps : all this code is in rootDialog.
i'm not getting the message 'Please complete all the search parameters'
If all of your code is in RootDialog then please use context.Wait(MessageReceivedAsync); after sending your attachment.
i need to send the information with the Id = "titre" and process it afterwards
When clicking the submit button, the form data is send to MessageReceived method as usual. If you want to just access the fields in the adaptive card you can access the dynamic variable value. Here is an example.
var message = await result;
if (message.Value != null)
{
// Got an Action Submit
dynamic value = message.Value;
string submitType = value.Type.ToString();
switch (submitType)
{
case "SaveFunction":
if(value.titre == "")
{
await context.PostAsync("Please complete all the search parameters:\n");
}
else
{
await context.PostAsync($"You entered {value.titre}");
}
return;
}
}

How do you implement a stream that properly handles backpressure in node.js?

I can't for the life of me figure out how to implement a stream that properly handles backpressure. Should you never use pause and resume?
I have this implementation I'm trying to get to work correctly:
var StreamPeeker = exports.StreamPeeker = function(myStream, callback) {
stream.Readable.call(this, {highWaterMark: highWaterMark})
this.stream = myStream
myStream.on('readable', function() {
var data = myStream.read(5000)
//process.stdout.write("Eff: "+data)
if(data !== null) {
if(!this.push(data)) {
process.stdout.write("Pause")
this.pause()
}
callback(data)
}
}.bind(this))
myStream.on('end', function() {
this.push(null)
}.bind(this))
}
util.inherits(StreamPeeker, stream.Readable)
StreamPeeker.prototype._read = function() {
process.stdout.write("resume")
//this.resume() // putting this in for some reason causes the stream to not output???
}
It correctly sends output, but doesn't correctly produce backpressure. How can I change it to properly support backpressure?
Ok I finally figured it out after lots of trial and error. A couple guidelines:
Never ever use pause or resume (otherwise it'll go into legacy "flowing" mode)
Never add a "data" event listener (otherwise it'll go into legacy "flowing" mode)
Its the implementor's responsibility to keep track of when the source is readable
Its the implementor's responsibility to keep track of when the destination wants more data
The implementation should not read any data until the _read method is called
The argument to read tells the source to give it that many bytes, it probably best to pass the argument passed to this._read into the source's read method. This way you should be able to configure how much to read at a time at the destination, and the rest of the stream chain should be automatic.
So this is what I changed it to:
Update: I created a Readable that is much easier to implement with proper back-pressure, and should have just as much flexibility as node's native streams.
var Readable = stream.Readable
var util = require('util')
// an easier Readable stream interface to implement
// requires that subclasses:
// implement a _readSource function that
// * gets the same parameter as Readable._read (size)
// * should return either data to write, or null if the source doesn't have more data yet
// call 'sourceHasData(hasData)' when the source starts or stops having data available
// calls 'end()' when the source is out of data (forever)
var Stream666 = {}
Stream666.Readable = function() {
stream.Readable.apply(this, arguments)
if(this._readSource === undefined) {
throw new Error("You must define a _readSource function for an object implementing Stream666")
}
this._sourceHasData = false
this._destinationWantsData = false
this._size = undefined // can be set by _read
}
util.inherits(Stream666.Readable, stream.Readable)
Stream666.Readable.prototype._read = function(size) {
this._destinationWantsData = true
if(this._sourceHasData) {
pushSourceData(this, size)
} else {
this._size = size
}
}
Stream666.Readable.prototype.sourceHasData = function(_sourceHasData) {
this._sourceHasData = _sourceHasData
if(_sourceHasData && this._destinationWantsData) {
pushSourceData(this, this._size)
}
}
Stream666.Readable.prototype.end = function() {
this.push(null)
}
function pushSourceData(stream666Readable, size) {
var data = stream666Readable._readSource(size)
if(data !== null) {
if(!stream666Readable.push(data)) {
stream666Readable._destinationWantsData = false
}
} else {
stream666Readable._sourceHasData = false
}
}
// creates a stream that can view all the data in a stream and passes the data through
// correctly supports backpressure
// parameters:
// stream - the stream to peek at
// callback - called when there's data sent from the passed stream
var StreamPeeker = function(myStream, callback) {
Stream666.Readable.call(this)
this.stream = myStream
this.callback = callback
myStream.on('readable', function() {
this.sourceHasData(true)
}.bind(this))
myStream.on('end', function() {
this.end()
}.bind(this))
}
util.inherits(StreamPeeker, Stream666.Readable)
StreamPeeker.prototype._readSource = function(size) {
var data = this.stream.read(size)
if(data !== null) {
this.callback(data)
return data
} else {
this.sourceHasData(false)
return null
}
}
Old Answer:
// creates a stream that can view all the data in a stream and passes the data through
// correctly supports backpressure
// parameters:
// stream - the stream to peek at
// callback - called when there's data sent from the passed stream
var StreamPeeker = exports.StreamPeeker = function(myStream, callback) {
stream.Readable.call(this)
this.stream = myStream
this.callback = callback
this.reading = false
this.sourceIsReadable = false
myStream.on('readable', function() {
this.sourceIsReadable = true
this._readMoreData()
}.bind(this))
myStream.on('end', function() {
this.push(null)
}.bind(this))
}
util.inherits(StreamPeeker, stream.Readable)
StreamPeeker.prototype._read = function() {
this.reading = true
if(this.sourceIsReadable) {
this._readMoreData()
}
}
StreamPeeker.prototype._readMoreData = function() {
if(!this.reading) return;
var data = this.stream.read()
if(data !== null) {
if(!this.push(data)) {
this.reading = false
}
this.callback(data)
}
}

How can I pass object properties to onSyndicationSuccess event while using SMF.Net.WebClient dynamically

I'm trying to create a central function for dynamic web requests.
function makeWebRequest(remoteURL, requestString, callBackFunction) {
var myWebRequest = new SMF.Net.WebClient({
url : remoteURL,
httpMethod : "POST",
requestString : requestString,
requestHeaders : [
"Content-Type: application/x-www-form-urlencoded"],
onSyndicationSuccess : callBackFunction,
onServerError : function (e) {
alert(e);
}
});
myWebRequest.run(false);
}
While calling makeWebRequest, passing a callBackFunction to it like;
var remoteURL = "http://parse.com/12/test";
var requestString = "category=news&type=world";
function callBackFunction(e) {
responseText = this.responseText;
if (responseText != null) {
parsedJSON = JSON.parse(responseText);
}
}
makeWebRequest(remoteURL,requestString,callBackFunction);
Application raises an error at line
responseText = this.responseText;
How can I pass myWebRequest itself to a function like that?
I used your codeLines. I just add a textButton to Page1, and it works fine both for Android and iOS .
In Global.js;
function makeWebRequest(remoteURL, requestString, callBackFunction) {
var myWebRequest = new SMF.Net.WebClient({
url : remoteURL,
httpMethod : "POST",
requestString : requestString,
requestHeaders : [
"Content-Type: application/x-www-form-urlencoded"],
onSyndicationSuccess : callBackFunction,
onServerError : function (e) {
alert(e);
}
});
myWebRequest.run(false);
}
var remoteURL = "http://parse.com/12/test";
var requestString = "category=news&type=world";
function callBackFunction(e) {
var responseText = this.responseText;
alert(responseText);
if (responseText != null) {
parsedJSON = JSON.parse(responseText);
}
}
function Global_Events_OnStart(e) {
changeLang(Device.language, true);
include("BC.js"); //included for future BC support. Removing is not advised.
// Comment following block for navigationbar/actionbar sample. Read the JS code file for usage.
// Also there is a part of code block in Page1, which should be copied to every page for HeaderBar usage
load("HeaderBar.js");
header = new HeaderBar();
// Uncomment following block for menu sample. Read the JS code file for usage.
/*
load("Menu.js");
/**/
}
function Global_Events_OnError(e) {
switch (e.type) {
case "Server Error":
case "Size Overflow":
alert(lang.networkError);
break;
default:
SES.Analytics.eventLog("error", JSON.stringify(e));
//change the following code for desired generic error messsage
alert({
title : lang.applicationError,
message : e.message + "\n\n*" + e.sourceURL + "\n*" + e.line + "\n*" + e.stack
});
break;
}
}
In Page1.js;
function Page1_Self_OnKeyPress(e) {
if (e.keyCode === 4) {
Application.exit();
}
}
function Page1_Self_OnShow() {
//Comment following block for removing navigationbar/actionbar sample
//Copy this code block to every page onShow
header.init(this);
header.setTitle("Page1");
header.setRightItem("RItem");
header.setLeftItem();
/**/
}
function Page1_TextButton1_OnPressed(e){
makeWebRequest(remoteURL,requestString,callBackFunction);
}
it works fine. Check your makeWebRequest function, must be on Global.js. Also define "responseText" variable with "var".

Need if-else advice in actionscript3

function clickButtonHandler(event:MouseEvent):void
{
var message:Object = new Object();
message.text = txtMessage.text;
message.userName = txtUser.text;
//Posts to this swf
showMessage(message);
//Posts to ALL OTHER swf files..
group.post(message);
}
function showMessage(message:Object):void
{
output_txt.appendText(message.userName+": "+message.text + "\n");
}
function jsalertwindow(event:MouseEvent):void
{
var alert:URLRequest = new URLRequest("javascript:alert('Please enter your User name')");
navigateToURL(alert, "_self");
}
As you can see there are two function which are contain mouseevent. I want to send those function with an if-else statement. If user write something in text input component which name is txtUser and,
send_btn.addEventListener(MouseEvent.CLICK, clickButtonHandler);
will work, else(if the user forget writing anything)
send_btn.addEventListener(MouseEvent.CLICK, jsalertwindow);
will work.
And one more question should i use MouseEvent.CLICK or MouseEvent.MOUSE_DOWN? Thanks for your advice.
Assign a single handler to the button click (MouseEvent.CLICK is the right event to use) and check the field is populated in the handler:
function clickButtonHandler(event:MouseEvent):void
{
var message:Object = new Object();
// Check the field is populated
if (txtUser.text != "")
{
message.text = txtMessage.text;
message.userName = txtUser.text;
showMessage(message);
//Posts to ALL OTHER swf files..
group.post(message);
}
else
{
// Nothing in the input field, show the alert
showAlert();
}
}
function showMessage(message:Object):void
{
output_txt.appendText(message.userName+": "+message.text + "\n");
}
function showAlert():void
{
var alert:URLRequest = new URLRequest("javascript:alert('Please enter your User name')");
navigateToURL(alert, "_self");
}

Resources