I have followed the below mentioned link to generate an image of live graph in my application and it is working fine on my local machine but when I deploy it on azure it is not doing anything. I am getting an empty image that does not contains graph in it further I have checked in logs no error or exception is being thrown. It seems that it is not working on Azure.
https://github.com/beto-rodriguez/Live-Charts/blob/develop/Examples/Wpf/CartesianChart/Chart%20to%20Image/ChartToImageSample.xaml.cs
I can reproduce the issue on my local environment now by just commenting the following line of code:
myChart.Update(true, true); //force chart redraw
viewbox.UpdateLayout();
It seems that control cannot be updated on Azure. I have also tried to update the controls through "Dispatcher" but still getting the same issue on Azure.
Can anybody help me please?
I create a test sample on my side, I find the code that is used to generate image for LiveChart can work in Bot application on Azure.
Installed following LiveCharts and LiveCharts.Wpf NuGet
<package id="LiveCharts" version="0.9.7" targetFramework="net46" />
<package id="LiveCharts.Wpf" version="0.9.7" targetFramework="net46" />
Create a Bot Application project and Put the code of generating image for LiveChart in Bot Application (if possible, you can recreate a new Bot Application and test the following code to check if it works for you)
string sfp = "";
private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
{
var activity = await result as Activity;
// calculate something for us to return
int length = (activity.Text ?? string.Empty).Length;
sfp = System.Web.HttpContext.Current.Server.MapPath($"~/IMG/chart.png");
Thread STAThread = new Thread(() =>
{
var myChart = new LiveCharts.Wpf.CartesianChart
{
DisableAnimations = true,
Width = 600,
Height = 200,
Series = new SeriesCollection
{
new LineSeries
{
Values = new ChartValues<double> {1, 6, 7, 2, 9, 3, 6, 5}
}
}
};
var viewbox = new System.Windows.Controls.Viewbox();
viewbox.Child = myChart;
viewbox.Measure(myChart.RenderSize);
viewbox.Arrange(new System.Windows.Rect(new Point(0, 0), myChart.RenderSize));
myChart.Update(true, true); //force chart redraw
viewbox.UpdateLayout();
SaveToPng(myChart, "chart.png");
});
STAThread.SetApartmentState(ApartmentState.STA);
STAThread.Start();
STAThread.Join();
await context.PostAsync($"You sent {activity.Text} which was {length} characters1");
context.Wait(MessageReceivedAsync);
}
Note: in my test, I create IMG folder manually via Kudu Console, not create it in code.
Test in Web Chat and send a message to Bot, and then check site folder, can find the image chart.png is generated via Kudu Console
chart.png
Besides, I send image as an attachment to client with the following test code, the chart.png can be rendered fine in client side.
var replymes = context.MakeMessage();
replymes.Attachments.Add(new Attachment()
{
Name = "chart.png",
ContentType = "image/png",
ContentUrl = "https://xxxx.azurewebsites.net/IMG/chart.png"
});
await context.PostAsync(replymes);
Related
I just converted one of my apps to target Android API 9 (was targeting API 8); now when notifications are sent out, the volume of media is lowered and never comes back to full volume.
The app uses WebView to play media files. This was not happening prior to targeting API 9. I had to convert the app into level 9 so that I could upload to the Google Play Store. I am running a Samsung S7 which was originally designed for API level 6 (with the OS upgraded to 8.0), not sure if that has something to do with the issue. Another detail is that I use Xamarin.Android for development, not sure if that matters either.
Additionally, I forced the notifications to play a blank sound (a very short[couple ms] blank mp3) in the same build that I converted the app to target API 9:
var channelSilent = new Android.App.NotificationChannel(CHANNEL_ID, name + " Silent", Android.App.NotificationImportance.High)
{
Description = description
};
var alarmAttributes = new Android.Media.AudioAttributes.Builder()
.SetContentType(Android.Media.AudioContentType.Sonification)
.SetUsage(Android.Media.AudioUsageKind.Notification).Build()
//blank is blank mp3 file with nothing in it, a few ms in duration
var uri = Android.Net.Uri.Parse("file:///Assets/blank.mp3")
channelSilent.SetSound(uri, alarmAttributes);
...so it could also be the blank sound that is causing the ducking to malfunction, not the API change. Is there something to do with notification sound ducking that could be causing the issue? Is there any other way to mute a notification with Xamarin.Android other than playing a blank sound? That is one route I think would be worth trying to fix this issue.
Here is the code I am using to generate notifications:
private static List<CustomNotification> _sentNotificationList = new List<CustomNotification>();
private static NotificationManagerCompat _notificationManager;
public async void SendNotifications(List<CustomNotification> notificationList)
{
await Task.Run(() =>
{
try
{
var _ctx = Android.App.Application.Context;
if (_notificationManager == null)
{
_notificationManager = Android.Support.V4.App.NotificationManagerCompat.From(_ctx);
}
if (notificationList.Count == 0)
{
return;
}
int notePos = 0;
foreach (var note in notificationList)
{
var resultIntent = new Intent(_ctx, typeof(MainActivity));
var valuesForActivity = new Bundle();
valuesForActivity.PutInt(MainActivity.COUNT_KEY, _count);
valuesForActivity.PutString("URL", note._noteLink);
resultIntent.PutExtras(valuesForActivity);
var resultPendingIntent = PendingIntent.GetActivity(_ctx, MainActivity.NOTIFICATION_ID, resultIntent, PendingIntentFlags.UpdateCurrent);
resultIntent.AddFlags(ActivityFlags.SingleTop);
var alarmAttributes = new Android.Media.AudioAttributes.Builder()
.SetContentType(Android.Media.AudioContentType.Sonification)
.SetUsage(Android.Media.AudioUsageKind.Notification).Build();
//I am playing this blank sound to prevent android from spamming sounds as the notifications get sent out
var uri = Android.Net.Uri.Parse("file:///Assets/blank.mp3");
//if the notification is the first in our batch then use this
//code block to send the notifications with sound
if (!_sentNotificationList.Contains(note) && notePos == 0)
{
var builder = new Android.Support.V4.App.NotificationCompat.Builder(_ctx, MainActivity.CHANNEL_ID + 1)
.SetAutoCancel(true)
.SetContentIntent(resultPendingIntent) // Start up this activity when the user clicks the intent.
.SetContentTitle(note._noteText) // Set the title
.SetNumber(1) // Display the count in the Content Info
.SetSmallIcon(Resource.Drawable.bitchute_notification2)
.SetContentText(note._noteType)
.SetPriority(NotificationCompat.PriorityMin);
MainActivity.NOTIFICATION_ID++;
_notificationManager.Notify(MainActivity.NOTIFICATION_ID, builder.Build());
_sentNotificationList.Add(note);
notePos++;
}
//if the notification isn't the first in our batch, then use this
//code block to send the notifications without sound
else if (!_sentNotificationList.Contains(note))
{
var builder = new Android.Support.V4.App.NotificationCompat.Builder(_ctx, MainActivity.CHANNEL_ID)
.SetAutoCancel(true) // Dismiss the notification from the notification area when the user clicks on it
.SetContentIntent(resultPendingIntent) // Start up this activity when the user clicks the intent.
.SetContentTitle(note._noteText) // Set the title
.SetNumber(1) // Display the count in the Content Info
.SetSmallIcon(Resource.Drawable.bitchute_notification2)
.SetContentText(note._noteType)
.SetPriority(NotificationCompat.PriorityHigh);
MainActivity.NOTIFICATION_ID++;
_notificationManager.Notify(MainActivity.NOTIFICATION_ID, builder.Build());
_sentNotificationList.Add(note);
notePos++;
}
ExtStickyService._notificationsHaveBeenSent = true;
}
}
catch
{
}
});
}
In my MainActivity I've created two different notification channels: one is silent; the other uses default notification setting for the device:
void CreateNotificationChannel()
{
var alarmAttributes = new Android.Media.AudioAttributes.Builder()
.SetContentType(Android.Media.AudioContentType.Sonification)
.SetUsage(Android.Media.AudioUsageKind.Notification).Build();
var uri = Android.Net.Uri.Parse("file:///Assets/blank.mp3");
if (Build.VERSION.SdkInt < BuildVersionCodes.O)
{
// Notification channels are new in API 26 (and not a part of the
// support library). There is no need to create a notification
// channel on older versions of Android.
return;
}
var name = "BitChute";
var description = "BitChute for Android";
var channelSilent = new Android.App.NotificationChannel(CHANNEL_ID, name + " Silent", Android.App.NotificationImportance.High)
{
Description = description
};
var channel = new Android.App.NotificationChannel(CHANNEL_ID + 1, name, Android.App.NotificationImportance.High)
{
Description = description
};
channel.LockscreenVisibility = NotificationVisibility.Private;
//here is where I set the sound for the silent channel... this could be the issue?
var notificationManager = (Android.App.NotificationManager)GetSystemService(NotificationService);
channelSilent.SetSound(uri, alarmAttributes);
notificationManager.CreateNotificationChannel(channel);
notificationManager.CreateNotificationChannel(channelSilent);
}
Full source: https://github.com/hexag0d/BitChute_Mobile_Android_BottomNav/tree/APILevel9
EDIT: something really interesting is that if I pulldown the system ui bar, the volume goes back to normal. Very strange workaround but it might help diagnose the cause.
DOUBLE EDIT: I used .SetSound(null, null) instead of using the blank .mp3 and the ducking works fine now. See comments
I'm trying to scan a QR Code from my Xamarin.Forms application but the QR Code isn't getting detected until i restart the scanner.
I'm using ZXing.Net.Mobile.Forms. Once the ScannerPage has been pushed on the navigation stack it requests the camera permissions. After fulfilling the request it has access to the camera but isn't scanning the QR Code. I tried changing the permission handler since it works after restarting the scanner after granting the permission, but that didn't work.
private async void createScanPageAsync()
{
#if __ANDROID__
// Initialize the scanner first so it can track the current context
MobileBarcodeScanner.Initialize (Application);
#endif
var options = new MobileBarcodeScanningOptions()
{
TryHarder = true,
};
var scanPage = new ZXingScannerPage()
{
Title = AppResources.scanPageTitle,
DefaultOverlayTopText = AppResources.scanPageTitle,
DefaultOverlayShowFlashButton = true
};
await Navigation.PushAsync(scanPage);
scanPage.OnScanResult += (scanResult) =>
{
scanPage.IsScanning = false;
Vibration.Vibrate();
QRCode scans = JsonConvert.DeserializeObject<QRCode>(scanResult.Text);
AppPreferences.Network.Ip = scans.ip;
AppPreferences.Network.Port = scans.port;
Device.BeginInvokeOnMainThread(async () =>
{
await Navigation.PopAsync();
});
};
}
}
The expected outcome would be a successful scan on the first try, but i only get a successful scan after granting permissions and then reopening the scanner page.
For me the Xamarin.Essentials did the trick. It has a permission plugin that can help you ask for permission and after that, you can then launch the scanner without problem
I can create a pool with an autoscale formula fine. The code for this is as follows.
var pool = client.PoolOperations.CreatePool(poolName, vmsize, new CloudServiceConfiguration(osFamily, osVersion));
pool.TaskSchedulingPolicy = new TaskSchedulingPolicy(ComputeNodeFillType.Pack);
pool.AutoScaleFormula = autoscaleFormula;
pool.AutoScaleEnabled = true;
pool.AutoScaleEvaluationInterval = new TimeSpan(0, 0, 5, 0);
pool.Commit();
However if once the pool exists, I try and update the AutoScale formula, I get an error. The error is
{"The property AutoScaleFormula cannot be modified while the object is
in the Bound state."}
The code is
var client = BatchClient.Open(GetCloudSharedKeyCredentials(primary));
var pool = client.PoolOperations.GetPool(poolName);
pool.AutoScaleFormula = formula;
pool.AutoScaleEnabled = true;
pool.AutoScaleEvaluationInterval = new TimeSpan(0, 0, 5, 0);
pool.Commit();
This used to work before I updated to the latest version of the Azure Batch library. Has anyone got any experience of Azure Batch and can advise why I'm getting this error?
You can use the PoolOperations.EnableAutoScale method directly.
For your example, you could use the following:
var client = BatchClient.Open(GetCloudSharedKeyCredentials(primary));
client.Pooloperations.EnableAutoScale(poolName, formula, TimeSpan.FromMinutes(5));
I'm currently implementing a browser helper object which would allow dragging emails from the outlook to the internet explorer's page.
I'm following the approach described in the following post: Implementing a Drag-and-Drop function from MS Outlook into our web application. I've got it working but only on x64 machines. On the x32/86 machines i'm getting the exception in the following piece of code (obviously i've replaced real filename inserting with fake one for simplicity):
DropFiles df = new DropFiles();
string filename = #"D:\projects\hello.txt";
byte[] binaryData = Encoding.Unicode.GetBytes(filename);
binaryData = binaryData.Concat(new byte[] { 0, 0 }).ToArray();
IntPtr pointerToGlobalMemory = Marshal.AllocHGlobal(Marshal.SizeOf(df) + binaryData.Length);
df.Files = Marshal.SizeOf(df);
df.Wide = true;
Marshal.StructureToPtr(df, pointerToGlobalMemory, true);
IntPtr newPointer = new IntPtr(pointerToGlobalMemory.ToInt32() + Marshal.SizeOf(df));
Marshal.Copy(binaryData, 0, newPointer, binaryData.Length);
var descriptorFormat = new COMInterop.FORMATETC();
descriptorFormat.cfFormat = HdropDescriptorId; // 15
descriptorFormat.ptd = IntPtr.Zero;
descriptorFormat.dwAspect = COMInterop.DVASPECT.DVASPECT_CONTENT;
descriptorFormat.lindex = -1;
descriptorFormat.tymed = COMInterop.TYMED.TYMED_HGLOBAL;
var td = new COMInterop.STGMEDIUM();
td.unionmember = pointerToGlobalMemory;
td.tymed = COMInterop.TYMED.TYMED_HGLOBAL;
dataObject.SetData(ref descriptorFormat, ref td, true);
On the executing the last ling of this code (actually setting the fake HDROP descriptor) i'm getting the following exception:
"Invalid FORMATETC structure (Exception from HRESULT: 0x80040064 (DV_E_FORMATETC))".
Did someone experienced described problem or have an idea what can be the reason of this issue?
To be more specific about environment - i'm having this trouble on win7 32 bit with IE 10 but i'm pretty sure that the reason especially in that machine is 32 bit.
You need to implement your own IDataObject and pass it to the original IDropTarget.Drop instead of hijacking an existing IDataObject coming from Outlook.
This is the code to upload a video to Youtube using the C# .NET API from a Windows Forms desktop application:
YouTubeRequestSettings settings = new YouTubeRequestSettings("whatwill come here ?",
"my api key",
"my youtube login email", "my youtube login password");
YouTubeRequest request = new YouTubeRequest(settings);
Video newVideo = new Video();
newVideo.Title = "test 1";
newVideo.Tags.Add(new MediaCategory("Gaming", YouTubeNameTable.CategorySchema));
newVideo.Keywords = "test 1 , test 2";
newVideo.Description = "test 3 test 4";
newVideo.YouTubeEntry.Private = false;
newVideo.Tags.Add(new MediaCategory("tag 1, tag 2",
YouTubeNameTable.DeveloperTagSchema));
newVideo.YouTubeEntry.Location = new GeoRssWhere(37, -122);
newVideo.YouTubeEntry.MediaSource = new MediaFileSource("C:\\test.avi", "video/quicktime");
Video createdVideo = request.Upload(newVideo);
This works. What I'm looking for is the events that get me back the upload progress, so I can show the progress in a progressbar. Ich can register the following events:
request.Service.AsyncOperationProgress +=
new AsyncOperationProgressEventHandler(Service_AsyncOperationProgress);
request.Service.AsyncOperationCompleted +=
new AsyncOperationCompletedEventHandler(Service_AsyncOperationCompleted);
... but they never get fired while uploading. Also, I cannot find any documentation about the .NET api that goes much further than the small video upload example above. So: Are those the wrong events to look for? Just for reference, I'm starting the seemingly synchonous upload in the following code in a background thread:
ThreadPool.QueueUserWorkItem(
delegate
{
try
{
createdVideo = request.Upload(newVideo);
} catch (Exception ex){
Invoke((ThreadStart) delegate{uploadingFailedWithException(ex);});
}
});
Invoke((ThreadStart)readyUploading);
This way I know when the synchonous operation ended, but I'd like to have events for progress updates to the user. Any ideas?
The Upload method you are using is synchronous and, as such, the execution of your program will stop on that line of code and only move on when the upload is complete.
What you are trying to do requires using asynchronous upload. A complete example showing how to use the ResumableUploader component and the AsyncOperationCompleted/AsyncOperationProgress events is included in the .NET client library and available at http://code.google.com/p/google-gdata/source/browse/#svn%2Ftrunk%2Fclients%2Fcs%2Fsamples%2FYouTubeUploader%2FYouTubeUploader