Skip to content

Commit

Permalink
v3.0.1034
Browse files Browse the repository at this point in the history
  • Loading branch information
ITHitBuild committed May 21, 2019
1 parent 86d425b commit 58a8a1e
Show file tree
Hide file tree
Showing 27 changed files with 256 additions and 229 deletions.
20 changes: 16 additions & 4 deletions iOS/WebDavCommon/AppGroupSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,35 @@ public static class AppGroupSettings
public static ServerSettings GetServerSettings()
{
using (NSUrl userDataPath = GetSharedContainerUrl())
using (NSDictionary userData = NSDictionary.FromFile(Path.Combine(userDataPath.Path, ServerSettingFile)))
using (var userData = NSDictionary.FromFile(Path.Combine(userDataPath.Path, ServerSettingFile)))
{
if (userData == null) return null;
if (userData == null)
{
return null;
}

return ServerSettings.CreateFromNsDictionary(userData);
}
}

private static NSUrl GetSharedContainerUrl()
{
NSUrl userDataPath = NSFileManager.DefaultManager.GetContainerUrl(AppGroupId);
if (userDataPath == null) throw new AccessViolationException("Group container is null");
if (userDataPath == null)
{
throw new AccessViolationException("Group container is null");
}

return userDataPath;
}

public static void SaveServerSettings(ServerSettings serverSettings)
{
if (serverSettings == null) throw new ArgumentNullException(nameof(serverSettings));
if (serverSettings == null)
{
throw new ArgumentNullException(nameof(serverSettings));
}

using (NSUrl userDataPath = GetSharedContainerUrl())
using (NSDictionary data = serverSettings.ToNsDictionary())
{
Expand Down
12 changes: 10 additions & 2 deletions iOS/WebDavCommon/ServerSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ public class ServerSettings

public ServerSettings(string serverUri, string userName = "", string password = "")
{
if(string.IsNullOrEmpty(serverUri)) throw new ArgumentException(serverUri);
if(string.IsNullOrEmpty(serverUri))
{
throw new ArgumentException(serverUri);
}

ServerUri = new Uri(serverUri);
UserName = userName;
Password = password;
Expand All @@ -22,7 +26,11 @@ public ServerSettings(string serverUri, string userName = "", string password =

public static ServerSettings CreateFromNsDictionary(NSDictionary userDataDictionary)
{
if(userDataDictionary == null) throw new ArgumentNullException(nameof(userDataDictionary));
if(userDataDictionary == null)
{
throw new ArgumentNullException(nameof(userDataDictionary));
}

NSObject serverUrl = userDataDictionary.ValueForKey((NSString) "ServerUri");
NSObject userName = userDataDictionary.ValueForKey((NSString) "UserName");
NSObject passWord = userDataDictionary.ValueForKey((NSString) "PassWord");
Expand Down
5 changes: 2 additions & 3 deletions iOS/WebDavContainer/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>CFBundleDisplayName</key>
<string>WebDAV Client</string>
<string>IT Hit WebDAV Client</string>
<key>CFBundleExecutable</key>
<string>WebDavContainer</string>
<key>CFBundleIdentifier</key>
Expand Down Expand Up @@ -46,11 +46,10 @@
<key>XSAppIconAssets</key>
<string>Assets.xcassets/AppIcon.appiconset</string>
<key>CFBundleVersion</key>
<string>1032</string>
<string>1034</string>
<key>UIDeviceFamily</key>
<array>
<integer>1</integer>
<integer>2</integer>
</array>
</dict>
</plist>
17 changes: 5 additions & 12 deletions iOS/WebDavContainer/Main.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
using UIKit;
using System;

namespace WebDavContainer
{
public class Application
{
// This is the main entry point of the application.
static void Main(string[] args)
{
try
{
// if you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here.
UIApplication.Main(args, null, "AppDelegate");
}
catch(Exception x)
{

}
// if you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here.
UIApplication.Main(args, null, "AppDelegate");
}
}
}
}
18 changes: 7 additions & 11 deletions iOS/WebDavContainer/ViewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public override void ViewDidLoad()
ServerSettings serverSettings = AppGroupSettings.GetServerSettings();
if(serverSettings != null)
{
Server.Text = serverSettings.ServerUri.ToString() ?? string.Empty;
Server.Text = serverSettings.ServerUri.ToString();
Username.Text = serverSettings.UserName ?? string.Empty;
Password.Text = serverSettings.Password ?? string.Empty;
}
Expand All @@ -28,20 +28,14 @@ public override void ViewDidLoad()
#endif
}

public override void DidReceiveMemoryWarning()
{
base.DidReceiveMemoryWarning();
// Release any cached data, images, etc that aren't in use.
}

partial void Login_Clicked(UIButton sender)
{
string serverUri = Server.Text;
string userName = Username.Text;
string passWord = Password.Text;


if(String.IsNullOrEmpty(serverUri) || String.IsNullOrWhiteSpace(serverUri))
if(string.IsNullOrEmpty(serverUri) || string.IsNullOrWhiteSpace(serverUri))
{
UIAlertView alert = new UIAlertView()
{
Expand All @@ -57,21 +51,23 @@ partial void Login_Clicked(UIButton sender)
{
var serverSettings = new ServerSettings(serverUri, userName, passWord);
AppGroupSettings.SaveServerSettings(serverSettings);
UIAlertView alert = new UIAlertView()
var alert = new UIAlertView()
{
Title = "Login successful",
Message = "Now you can open documents in MS Office or any other application from http://server/ via Location->Browse dialog and save back directly to server."
Message = "Now you can open documents from your server in MS Office Mobile or any other application via Location->Browse dialog and save back directly to server."
};

alert.AddButton("Ok");
alert.Show();
}
catch(Exception ex)
{
UIAlertView doneAlert = new UIAlertView()
var doneAlert = new UIAlertView()
{
Title = "Error",
Message = ex.Message
};

doneAlert.AddButton("Ok");
doneAlert.Show();
}
Expand Down
10 changes: 4 additions & 6 deletions iOS/WebDavContainerExtension/Extension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.IO;
using System.Net;
using System.Runtime.InteropServices;
using FileProvider;
using Foundation;
using MobileCoreServices;
using ObjCRuntime;
Expand All @@ -17,14 +16,14 @@ namespace WebDavContainerExtension
public static class Extension
{
[DllImport(Constants.MobileCoreServicesLibrary, EntryPoint = "UTTypeCreatePreferredIdentifierForTag")]
public static extern IntPtr UTTypeCreatePreferredIdentifierForTag(IntPtr tagClass, IntPtr tag, IntPtr uti);
private static extern IntPtr UTTypeCreatePreferredIdentifierForTag(IntPtr tagClass, IntPtr tag, IntPtr uti);


public static string GetUTType(string fileExtension)
{
fileExtension = fileExtension.Substring(1);
NSString classRef = new NSString(UTType.TagClassFilenameExtension);
NSString mimeRef = new NSString(fileExtension);
var mimeRef = new NSString(fileExtension);

IntPtr utiRef = UTTypeCreatePreferredIdentifierForTag(classRef.Handle, mimeRef.Handle, IntPtr.Zero);

Expand All @@ -36,7 +35,7 @@ public static string GetUTType(string fileExtension)
public static string Decode(string source)
{
string[] sourceElements = source.Split('/');
List<string> resultElements = new List<string>();
var resultElements = new List<string>();
foreach(string element in sourceElements)
{
resultElements.Add(WebUtility.UrlDecode(element));
Expand All @@ -50,7 +49,7 @@ public static string Decode(string source)
public static string Encode(string source)
{
string[] sourceElements = source.Split('/');
List<string> resultElements = new List<string>();
var resultElements = new List<string>();
foreach(string element in sourceElements)
{
resultElements.Add(WebUtility.UrlEncode(element));
Expand All @@ -72,7 +71,6 @@ public static string GetTypeIdentifier(string type, string itemName)
baseType += ".folder";
break;
}
;
default:
{
string fileExtension = Path.GetExtension(itemName);
Expand Down
6 changes: 5 additions & 1 deletion iOS/WebDavContainerExtension/Extensions/NSErrorExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ public static class NSErrorExtension
{
public static NSErrorException AsException(this NSError error)
{
if(error == null) throw new ArgumentNullException(nameof(error));
if(error == null)
{
throw new ArgumentNullException(nameof(error));
}

return new NSErrorException(error);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using FileProvider;
using FileProvider;
using Foundation;

namespace WebDavContainerExtension.FileProviderEnumerators
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Linq;
using FileProvider;
using Foundation;
using ITHit.WebDAV.Client.Exceptions;
Expand Down Expand Up @@ -45,15 +44,15 @@ public void EnumerateItems(INSFileProviderEnumerationObserver observer, NSData s
observer.DidEnumerateItems(new[] {item});
observer.FinishEnumerating((NSData) null);
}
catch(UnauthorizedException ex)
catch(UnauthorizedException)
{
observer.FinishEnumerating(NsErrorHelper.GetFileProviderNotFoundError(this.EnumeratedItemIdentifier));
}
catch(WebDavHttpException ex)
catch(WebDavHttpException)
{
observer.FinishEnumerating(NsErrorHelper.GetUnspecifiedServerError());
}
catch(Exception ex)
catch(Exception)
{
observer.FinishEnumerating(NsErrorHelper.GetUnspecifiedErrorError());
}
Expand All @@ -75,15 +74,15 @@ public void EnumerateChanges(INSFileProviderChangeObserver observer, NSData sync
observer.DidUpdateItems(new[] { ProviderItem.CreateFromMetadata(metadata) });
observer.FinishEnumeratingChanges(this.GetNsDataFromUint(this.SyncAnchor++), false);
}
catch(UnauthorizedException ex)
catch(UnauthorizedException)
{
observer.FinishEnumerating(NsErrorHelper.GetFileProviderUnauthorizedError());
}
catch(WebDavHttpException ex)
catch(WebDavHttpException)
{
observer.FinishEnumerating(NsErrorHelper.GetUnspecifiedServerError());
}
catch(Exception ex)
catch(Exception)
{
observer.FinishEnumerating(NsErrorHelper.GetUnspecifiedErrorError());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ public void EnumerateItems(INSFileProviderEnumerationObserver observer, NSData s
observer.DidEnumerateItems(items);
observer.FinishEnumerating((NSData) null);
}
catch (UnauthorizedException ex)
catch (UnauthorizedException)
{
observer.FinishEnumerating(NsErrorHelper.GetFileProviderUnauthorizedError());
}
catch (WebDavHttpException ex)
catch (WebDavHttpException)
{
observer.FinishEnumerating(NsErrorHelper.GetUnspecifiedServerError());
}
catch (Exception ex)
catch (Exception)
{
observer.FinishEnumerating(NsErrorHelper.GetUnspecifiedErrorError());
}
Expand Down Expand Up @@ -86,15 +86,15 @@ public void EnumerateChanges(INSFileProviderChangeObserver observer, NSData sync
this.SyncAnchor = this.changeTracker.AddChangeSet(metadatas);
observer.FinishEnumeratingChanges(this.GetCurrentAnchorNsData(this.SyncAnchor), false);
}
catch (UnauthorizedException ex)
catch (UnauthorizedException)
{
observer.FinishEnumerating(NsErrorHelper.GetFileProviderUnauthorizedError());
}
catch (WebDavHttpException ex)
catch (WebDavHttpException)
{
observer.FinishEnumerating(NsErrorHelper.GetUnspecifiedServerError());
}
catch (Exception ex)
catch (Exception)
{
observer.FinishEnumerating(NsErrorHelper.GetUnspecifiedErrorError());
}
Expand Down
Loading

0 comments on commit 58a8a1e

Please sign in to comment.