Xamarin & Multiple Filepicker - ios

i'm building a project on Xamarin. Right now i have a big issue. I need to browse user's computer for upload any file. He can of course upload multiple files. As i know Xamarin does not provide browsing of all the system but just its. So i tried to find a way with some drag n drop, i didn't find. I tried a filepicker but he let me pick just one file (my client would upload 100 files at once) so it doesn't fit to what i need. Finally i decided to do my own browsing system but it takes forever to browse because of the UI. Do you have any solution for me ? I would appreciate a package with a filepicker that allow multiple files.
Thanks

Have you tried the class FileOpenPicker in UWP ?
It supports to pick multiple files , check the method FileOpenPicker.PickMultipleFilesAsync.
Sample
Define interface in Forms project
public interface MyFilePicker
{
Task OpenFilePickerAsync();
}
Implement in UWP project
[assembly: Dependency(typeof(UWPFilePicker))]
namespace App24.UWP
{
class UWPFilePicker : MyFilePicker
{
public async Task OpenFilePickerAsync()
{
var openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add(".jpg");
openPicker.FileTypeFilter.Add(".jpeg");
openPicker.FileTypeFilter.Add(".png");
IReadOnlyList<StorageFile> files = await openPicker.PickMultipleFilesAsync();
if (files.Count > 0)
{
StringBuilder output = new StringBuilder("Picked files:\n");
// Application now has read/write access to the picked file(s)
}
else
{
return;
}
}
}
}
Call it in Forms project
private async void Button_Clicked(object sender, EventArgs e)
{
MyFilePicker service = DependencyService.Get<MyFilePicker>();
await service.OpenFilePickerAsync();
}

Related

Using DataConnectionDialog

When I am attempting to use the DataConnectionDialog from NuGet (version 1.2), I receive the Advanced Settings dialog for setting up the Database Connection. Is there some Setting I have missed or additional library to retreive?
Code:
using System;
using Microsoft.Data.ConnectionUI;
DataConnectionDialog dcd = new DataConnectionDialog();
DataSource.AddStandardDataSources(dcd);
dcd.SelectedDataSource = DataSource.SqlDataSource;
dcd.SelectedDataProvider = DataProvider.SqlDataProvider;
DataConnectionDialog.Show(dcd);
Output:
What I want (this comes from the datasource wizard in Visual Studio Community 2015):
I happened to stumble on the same issue. From my main form, I called an async method using Task.Factory.StartNew. This method tries to open the Data Connection Dialog but it would show the Advance Settings dialog box instead.
During troubleshooting, I replaced the DataConnectionDialog with a OpenFileDialog and this gave me a ThreadStateException which pointed me towards the solution.
To solve it, I had to put the code in a separate function, e.g. AskConnectionString and call it using Control.Invoke.
e.g.
public void btnConnString_Click(object sender, EventArgs e)
{
_connectionString = (string)this.Invoke(AskConnectionString);
}
public string AskConnectionString()
{
DataConnectionDialog dcd = new DataConnectionDialog();
DataSource.AddStandardDataSources(dcd);
dcd.SelectedDataSource = DataSource.SqlDataSource;
dcd.SelectedDataProvider = DataProvider.SqlDataProvider;
DataConnectionDialog.Show(dcd);
return dcd.ConnectionString;
}

ImageResizer and image files without an extension

I've been using ImageResizer.net just fine in our web app, but now I need it to resize and serve images that don't (and cannot) have a file extension, like this one:
http://localhost:58306/ClientImages/Batch/2012/12/10/f45198b7c452466684a4079de8d5f85f?width=600
In this situation, I know that my files are always TIFF's, but they wont have a file extension.
What are my options?
/resizer.debug.ashx: https://gist.github.com/raw/9c867823c983f0e5be10/4db31cb21af8b9b36f0aa4e765f6f459ba4b309f/gistfile1.txt
Update
I followed Computer Linguist's instructions:
protected void Application_Start()
{
Config.Current.Pipeline.PostAuthorizeRequestStart +=
delegate
{
var path = Config.Current.Pipeline.PreRewritePath;
var clientImgsRelPath = PathUtils.ResolveAppRelative("~/ClientImages/");
var isClientImageRequest = path.StartsWith(clientImgsRelPath, StringComparison.OrdinalIgnoreCase);
if (isClientImageRequest)
Config.Current.Pipeline.SkipFileTypeCheck = true;
};
// other app start code here
}
http://localhost:58306/ClientImages/Batch/2012/12/10/92d67b45584144beb5f791aaaf760252?width=600 just responds with the original image with no resizing.
This was also asked about here: http://imageresizing.net/docs/howto/cache-non-images#comment-571615564
This is happening during development with the Cassini or Visual Studio web server or whatever you want to call it.
First, you MUST be using IIS7 Integrated mode. Classic mode will not work; it does not permit ASP.NET access to extensionless requests
ImageResizer can't know that extension-less URLs are images unless you explicitly tell it.
This doc explains:
http://imageresizing.net/docs/howto/cache-non-images
Essentially, you'll end up performing logic (usually String.StartsWith) on your URLs to find out if ImageResizer should treat the file as an image.
Config.Current.Pipeline.PostAuthorizeRequestStart += delegate(IHttpModule sender, HttpContext context) {
string path = Config.Current.Pipeline.PreRewritePath;
//Skip the file extension check for everything in this folder:
if (path.StartsWith(PathUtils.ResolveAppRelative("~/folder/of/images"),
StringComparison.OrdinalIgnoreCase)){
Config.Current.Pipeline.SkipFileTypeCheck = true;
}
};
You should register this event handler in Application_Start in global.asax.

Restarting Blackberry Programmatically

I want to make Blackberry application that can restart the blackberry it self (after doing some task)
for example, i make this little application using the dummy
dummy : (after it becomes dummy.cod, i move it to the res folder and rename it to dummy, not using .cod anymore)
public class Dummy extends Application{
public static void main( String[] args ) {
new Dummy().enterEventDispatcher();
}
public Dummy(){
}
}
application sample code :
(description of my application : just have 1 button to call the reset method)
public void reset() throws Exception {
// load the dummy cod file
byte[] cod = IOUtilities.streamToBytes(getClass().getResourceAsStream("/dummy"));
// create new module
int newHandle = CodeModuleManager.createNewModule(cod.length, cod, cod.length);
// install the module
if (newHandle != 0) {
int savecode = CodeModuleManager.saveNewModule(newHandle, true);
if (savecode == CodeModuleManager.CMM_OK_MODULE_OVERWRITTEN)
Logger.debug("The operation completed successfully; a module was overwritten and marked for deletion in the process.");
// now run the dummy application in background
ApplicationDescriptor appDesc = CodeModuleManager.getApplicationDescriptors(newHandle)[0];
ApplicationManager.getApplicationManager().runApplication(appDesc, false);
CodeModuleManager.deleteModuleEx(newHandle, true);
}
// restart the blackberry if required
CodeModuleManager.promptForResetIfRequired();
}
When I run my code to Simulator (SimPackage 6.0.0.587 - 9780 & SimPackage 5.0.0.977 - 9300) the code was running well, it shows a message to "Restart Now / Restart Later".
But when I’ve load my code to real device 9780 OS 6.0.0.570 and device 9300 OS 5.0.0.846, the code is still won’t work.
Any idea why is it happen ? or I just make a simple but fatal mistake ?
Thanks :)
Your code is correct, but you need to sign your code to be able to execute CodeModuleManager.deleteModuleEx on a real device.
Please refer to the CodeModuleManager documentation for more information.

Adobe air Native Process only works in the flash environment, but when deployed i get Error #3219

I've been trying to use ffmpeg with an air app that I made in flash cs5.5. I have it so that ffmpeg.exe needs to be located in the directory where the air app is installed (File.applicationDirectory.nativePath).
For some reason this only works when I run the program through the flash dev environment. But when I actually deploy the app, I get error #3219:The NativeProcess could not be started. ffmpeg.exe is located in the same folder.
I actually don't know the full message that it gives...not sure what the property of the error that will give me that message when I catch it. All I know is that it's error 3219.
Would this be a profile issue? If i didn't have the extended desktop desktop profile, I don't think I would be able to get this error, I'd get a profiling error wouldn't I?
I've disabled user access control as well...I'm using windows 7.
So I'm the OP, and I just realized that you can't use native process calls if you do not install the air application through the exe installer, which is an option in publish settings. I've been using the air installer.
one thing to mention is that (I'm sure you already know) the NativeProcess works only on that OS where it was compiled, so if you compile on a windows box your NativeProcess will only work on windows and not on unix/mac.
I don't know how you call the native process, but here is a code snippet that I extracted of one of my working Classes, maybe comparing it with your aproach it will give you some hint to find the problem :)
import flash.desktop.*;
import flash.errors.*;
import flash.events.*;
import flash.filesystem.*;
public function execute():void
{
var executablePath:String = "C:\ffmpeg.exe";
var parametersString:String = "-i input.avi -b 64k output.avi";
if(NativeProcess.isSupported) {
var args:Vector.<String> = new Vector.<String>();
var file:File = new File(String(executablePath));
var parameters:Array;
parameters = parametersString.split(" ");
for each ( var parameter:String in parameters ) {
args.push(parameter);
}
}
var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
nativeProcessStartupInfo.executable = file;
nativeProcessStartupInfo.arguments = args;
startExecution(nativeProcessStartupInfo);
}
private function startExecution(nativeProcessStartupInfo:NativeProcessStartupInfo):void
{
var nativeProcess:NativeProcess = new NativeProcess();
nativeProcess.addEventListener(NativeProcessExitEvent.EXIT, onExitError);
var msg:String = "";
try {
nativeProcess.start(nativeProcessStartupInfo);
trace("Trying to start process");
} catch (error:IllegalOperationError) {
trace("Illegal Operation: "+error.toString());
} catch (error:ArgumentError) {
trace("Argument Error: "+error.toString());
} catch (error:Error) {
trace("Error: "+error.toString());
}
if (nativeProcess.running) {
trace("Native Process Support");
}
}
public function onExitError(event:NativeProcessExitEvent):void
{
trace("Native Process Exit code: "+event.exitCode);
}

Avoiding missing views in ASP.NET MVC

When testing an ASP.NET MVC 2 application I hit a problem when a view could not be located.
Looking at the code I realised that the aspx file for the view had not been added to the source control repository. On this project that's quite easy to do as we use StarTeam for source control and it doesn't show new folders when checking in. This view was for a new controller and so a new folder was created for it and it was therefore missed.
Our build server (using Hudson/MSBuild) didn't pick up on this, as the code still builds fine with the aspx file missing. Our controller unit tests test the ActionResults which obviously still pass without the view there.
This got picked up in system testing but how can I catch this earlier (ideally on the build server).
Thanks in advance
You can write unit tests that test the actual view, and then if the unit test doesn't pass on the build server, you know you have a problem. To do this, you can use a framework such as this:
http://blog.stevensanderson.com/2009/06/11/integration-testing-your-aspnet-mvc-application/
With this you can write unit tests such as this (from the post)
[Test]
public void Root_Url_Renders_Index_View()
{
appHost.SimulateBrowsingSession(browsingSession => {
// Request the root URL
RequestResult result = browsingSession.ProcessRequest("/");
// You can make assertions about the ActionResult...
var viewResult = (ViewResult) result.ActionExecutedContext.Result;
Assert.AreEqual("Index", viewResult.ViewName);
Assert.AreEqual("Welcome to ASP.NET MVC!", viewResult.ViewData["Message"]);
// ... or you can make assertions about the rendered HTML
Assert.IsTrue(result.ResponseText.Contains("<!DOCTYPE html"));
});
}
What version of StarTeam are you running? In StarTeam 2008 (not sure when this feature was first added) within a selected project/view, you can select from the menu Folder Tree->Show Not-In-View Folders. This will show folders you have on local disk that have not been added to the project (they will appear with the folder icon colored white).
This is an old question, but if anyone still looking for this you ought to try SpecsFor.Mvc by Matt Honeycutt.
Not only it can be used to make sure the Views are properly included/added in the source control, it can even do integration test to make sure those Views are valid.
Link to its website: http://specsfor.com/SpecsForMvc/default.cshtml
Link to the nuget package: https://www.nuget.org/packages/SpecsFor.Mvc/
Link to github: https://github.com/MattHoneycutt/SpecsFor
Here is a code snippet taken from the website showing how to use it.
public class UserRegistrationSpecs
{
public class when_a_new_user_registers : SpecsFor<MvcWebApp>
{
protected override void Given()
{
SUT.NavigateTo<AccountController>(c => c.Register());
}
protected override void When()
{
SUT.FindFormFor<RegisterModel>()
.Field(m => m.Email).SetValueTo("test#user.com")
.Field(m => m.UserName).SetValueTo("Test User")
.Field(m => m.Password).SetValueTo("P#ssword!")
.Field(m => m.ConfirmPassword).SetValueTo("P#ssword!")
.Submit();
}
[Test]
public void then_it_redirects_to_the_home_page()
{
SUT.Route.ShouldMapTo<HomeController>(c => c.Index());
}
[Test]
public void then_it_sends_the_user_an_email()
{
SUT.Mailbox().MailMessages.Count().ShouldEqual(1);
}
[Test]
public void then_it_sends_to_the_right_address()
{
SUT.Mailbox().MailMessages[0].To[0].Address.ShouldEqual("test#user.com");
}
[Test]
public void then_it_comes_from_the_expected_address()
{
SUT.Mailbox().MailMessages[0].From.Address.ShouldEqual("registration#specsfor.com");
}
}
}

Resources