diff --git a/iOS/WebDavCommon/AppGroupSettings.cs b/iOS/WebDavCommon/AppGroupSettings.cs
index 1c344bb..e0252c1 100644
--- a/iOS/WebDavCommon/AppGroupSettings.cs
+++ b/iOS/WebDavCommon/AppGroupSettings.cs
@@ -12,9 +12,13 @@ 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);
}
}
@@ -22,13 +26,21 @@ public static ServerSettings GetServerSettings()
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())
{
diff --git a/iOS/WebDavCommon/ServerSettings.cs b/iOS/WebDavCommon/ServerSettings.cs
index 0e95783..a28b8fa 100644
--- a/iOS/WebDavCommon/ServerSettings.cs
+++ b/iOS/WebDavCommon/ServerSettings.cs
@@ -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;
@@ -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");
diff --git a/iOS/WebDavContainer/Info.plist b/iOS/WebDavContainer/Info.plist
index e3c3341..742ce1e 100644
--- a/iOS/WebDavContainer/Info.plist
+++ b/iOS/WebDavContainer/Info.plist
@@ -3,7 +3,7 @@
CFBundleDisplayName
- WebDAV Client
+ IT Hit WebDAV Client
CFBundleExecutable
WebDavContainer
CFBundleIdentifier
@@ -46,11 +46,10 @@
XSAppIconAssets
Assets.xcassets/AppIcon.appiconset
CFBundleVersion
- 1032
+ 1034
UIDeviceFamily
1
- 2
diff --git a/iOS/WebDavContainer/Main.cs b/iOS/WebDavContainer/Main.cs
index d4056bf..9a86ce2 100644
--- a/iOS/WebDavContainer/Main.cs
+++ b/iOS/WebDavContainer/Main.cs
@@ -1,5 +1,5 @@
using UIKit;
-using System;
+
namespace WebDavContainer
{
public class Application
@@ -7,16 +7,9 @@ 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");
}
}
-}
+}
\ No newline at end of file
diff --git a/iOS/WebDavContainer/ViewController.cs b/iOS/WebDavContainer/ViewController.cs
index 1808138..456cc1b 100644
--- a/iOS/WebDavContainer/ViewController.cs
+++ b/iOS/WebDavContainer/ViewController.cs
@@ -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;
}
@@ -28,12 +28,6 @@ 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;
@@ -41,7 +35,7 @@ partial void Login_Clicked(UIButton sender)
string passWord = Password.Text;
- if(String.IsNullOrEmpty(serverUri) || String.IsNullOrWhiteSpace(serverUri))
+ if(string.IsNullOrEmpty(serverUri) || string.IsNullOrWhiteSpace(serverUri))
{
UIAlertView alert = new UIAlertView()
{
@@ -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();
}
diff --git a/iOS/WebDavContainerExtension/Extension.cs b/iOS/WebDavContainerExtension/Extension.cs
index 05741db..d14418e 100644
--- a/iOS/WebDavContainerExtension/Extension.cs
+++ b/iOS/WebDavContainerExtension/Extension.cs
@@ -3,7 +3,6 @@
using System.IO;
using System.Net;
using System.Runtime.InteropServices;
-using FileProvider;
using Foundation;
using MobileCoreServices;
using ObjCRuntime;
@@ -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);
@@ -36,7 +35,7 @@ public static string GetUTType(string fileExtension)
public static string Decode(string source)
{
string[] sourceElements = source.Split('/');
- List resultElements = new List();
+ var resultElements = new List();
foreach(string element in sourceElements)
{
resultElements.Add(WebUtility.UrlDecode(element));
@@ -50,7 +49,7 @@ public static string Decode(string source)
public static string Encode(string source)
{
string[] sourceElements = source.Split('/');
- List resultElements = new List();
+ var resultElements = new List();
foreach(string element in sourceElements)
{
resultElements.Add(WebUtility.UrlEncode(element));
@@ -72,7 +71,6 @@ public static string GetTypeIdentifier(string type, string itemName)
baseType += ".folder";
break;
}
- ;
default:
{
string fileExtension = Path.GetExtension(itemName);
diff --git a/iOS/WebDavContainerExtension/Extensions/NSErrorExtension.cs b/iOS/WebDavContainerExtension/Extensions/NSErrorExtension.cs
index bdd7bc2..4144a11 100644
--- a/iOS/WebDavContainerExtension/Extensions/NSErrorExtension.cs
+++ b/iOS/WebDavContainerExtension/Extensions/NSErrorExtension.cs
@@ -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);
}
}
diff --git a/iOS/WebDavContainerExtension/FileProviderEnumerators/EmptyEnumerator.cs b/iOS/WebDavContainerExtension/FileProviderEnumerators/EmptyEnumerator.cs
index 32f6b10..b52db34 100644
--- a/iOS/WebDavContainerExtension/FileProviderEnumerators/EmptyEnumerator.cs
+++ b/iOS/WebDavContainerExtension/FileProviderEnumerators/EmptyEnumerator.cs
@@ -1,5 +1,4 @@
-using System;
-using FileProvider;
+using FileProvider;
using Foundation;
namespace WebDavContainerExtension.FileProviderEnumerators
diff --git a/iOS/WebDavContainerExtension/FileProviderEnumerators/FileEnumerator.cs b/iOS/WebDavContainerExtension/FileProviderEnumerators/FileEnumerator.cs
index cfb6613..c0fc2a3 100644
--- a/iOS/WebDavContainerExtension/FileProviderEnumerators/FileEnumerator.cs
+++ b/iOS/WebDavContainerExtension/FileProviderEnumerators/FileEnumerator.cs
@@ -1,5 +1,4 @@
using System;
-using System.Linq;
using FileProvider;
using Foundation;
using ITHit.WebDAV.Client.Exceptions;
@@ -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());
}
@@ -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());
}
diff --git a/iOS/WebDavContainerExtension/FileProviderEnumerators/FolderEnumerator.cs b/iOS/WebDavContainerExtension/FileProviderEnumerators/FolderEnumerator.cs
index f411762..f9a9ba8 100644
--- a/iOS/WebDavContainerExtension/FileProviderEnumerators/FolderEnumerator.cs
+++ b/iOS/WebDavContainerExtension/FileProviderEnumerators/FolderEnumerator.cs
@@ -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());
}
@@ -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());
}
diff --git a/iOS/WebDavContainerExtension/FileProviderExtension.cs b/iOS/WebDavContainerExtension/FileProviderExtension.cs
index fac2404..60732e9 100644
--- a/iOS/WebDavContainerExtension/FileProviderExtension.cs
+++ b/iOS/WebDavContainerExtension/FileProviderExtension.cs
@@ -3,7 +3,6 @@
using System.IO;
using System.Linq;
using System.Net;
-using CoreGraphics;
using FileProvider;
using Foundation;
using ITHit.WebDAV.Client;
@@ -20,12 +19,17 @@
namespace WebDavContainerExtension
{
- [Register("FileProviderExtension")]
+ [Register(nameof(FileProviderExtension))]
class FileProviderExtension : NSFileProviderExtension
{
private const string StorageFolder = "Documents";
+
public LocationMapper LocationMapper { get; }
+ public WebDavSessionAsync Session { get; }
+
+ public StorageManager StorageManager { get; }
+
public FileProviderExtension()
{
var serverSettings = AppGroupSettings.GetServerSettings();
@@ -40,19 +44,20 @@ private WebDavSessionAsync InitSession(ServerSettings serverSettings)
#if !DEBUG
FileLogger.Level = LogLevel.Off;
#endif
- var session = new WebDavSessionAsync
- {
- };
+ string license = @"The shared document's URL.
///
- /// An action the system calls subseqent to the creation of a placeholder.
+ /// An action the system calls subsequent to the creation of a placeholder.
/// This parameter can be .
///
/// When implemented by the developer, creates a specified placeholder for a previously defined URL.
@@ -89,8 +91,8 @@ public override void ProvidePlaceholderAtUrl(NSUrl url, Action completi
completionHandler?.Invoke(NsErrorHelper.GetFileProviderNotFoundError(identifier));
return;
}
- var placeholderUrl = NSFileProviderManager.GetPlaceholderUrl(url);
- NSError error = null;
+ NSUrl placeholderUrl = NSFileProviderManager.GetPlaceholderUrl(url);
+ NSError error;
NSFileManager.DefaultManager.CreateDirectory(placeholderUrl.RemoveLastPathComponent(), true, null, out error);
if(error != null)
{
@@ -98,13 +100,12 @@ public override void ProvidePlaceholderAtUrl(NSUrl url, Action completi
return;
}
- var providerItem = ProviderItem.CreateFromMetadata(itemMetadata);
+ INSFileProviderItem providerItem = ProviderItem.CreateFromMetadata(itemMetadata);
NSFileProviderManager.WritePlaceholder(placeholderUrl, providerItem, out error);
completionHandler?.Invoke(error);
}
catch (Exception ex)
{
- ;
NSError error = this.MapError(ex);
completionHandler?.Invoke(error);
}
@@ -141,17 +142,10 @@ public override INSFileProviderItem GetItem(NSString identifier, out NSError err
/// This can be used from a background thread.
///
public override string GetPersistentIdentifier(NSUrl itemUrl)
- {
- try
{
string identifierFromLocalPath = this.LocationMapper.GetIdentifierFromLocalPath(itemUrl.Path);
return identifierFromLocalPath;
}
- catch(Exception e)
- {
- throw;
- }
- }
///
/// Persistent identifier for a document that is shared .
@@ -163,15 +157,7 @@ public override string GetPersistentIdentifier(NSUrl itemUrl)
///
public override NSUrl GetUrlForItem(string persistentIdentifier)
{
- try
- {
- NSUrl urlForItem = NSUrl.FromFilename(this.LocationMapper.GetLocalUrlFromIdentifier(persistentIdentifier));
- return urlForItem;
- }
- catch(Exception e)
- {
- throw;
- }
+ return NSUrl.FromFilename(this.LocationMapper.GetLocalUrlFromIdentifier(persistentIdentifier));
}
public override INSFileProviderEnumerator GetEnumerator(string containerItemIdentifier, out NSError error)
@@ -200,13 +186,17 @@ public override INSFileProviderEnumerator GetEnumerator(string containerItemIden
///
public override void ItemChangedAtUrl(NSUrl url)
{
- var identifier = this.GetPersistentIdentifier(url);
+ string identifier = this.GetPersistentIdentifier(url);
try
{
FileMetadata item = this.StorageManager.GetFileMetadata(identifier);
- if (!item.ExistsLocal) throw NsErrorHelper.GetFileProviderNotFoundError().AsException();
+ if (!item.ExistsLocal)
+ {
+ throw NsErrorHelper.GetFileProviderNotFoundError().AsException();
+ }
+
item = StorageManager.ResetLocalVersion(item);
- item = this.StorageManager.PushToServer(item);
+ this.StorageManager.PushToServer(item);
}
catch(Exception e)
{
@@ -235,7 +225,7 @@ private NSError MapError(Exception localFileUploadError)
/// The shared document's URL.
///
- /// An action the system calls when the refernced file becomes available.
+ /// An action the system calls when the referenced file becomes available.
/// This parameter can be .
///
/// When implemented by the developer, supplies an actual file on a disk in place of a placeholder.
@@ -247,7 +237,7 @@ public override void StartProvidingItemAtUrl(NSUrl url, Action completi
{
try
{
- var identifier = this.GetPersistentIdentifier(url);
+ string identifier = this.GetPersistentIdentifier(url);
FileMetadata item = this.StorageManager.GetFileMetadata(identifier);
if(item.HasUploadError)
{
@@ -266,7 +256,6 @@ public override void StartProvidingItemAtUrl(NSUrl url, Action completi
}
catch (Exception ex)
{
- ;
NSError error = this.MapError(ex);
completionHandler?.Invoke(error);
}
@@ -282,7 +271,7 @@ public override void StopProvidingItemAtUrl(NSUrl url)
{
try
{
- var identifier = this.GetPersistentIdentifier(url);
+ string identifier = this.GetPersistentIdentifier(url);
FileMetadata item = this.StorageManager.GetFileMetadata(identifier);
if(!item.LocalFile.HasEtag)
{
@@ -318,7 +307,7 @@ public override void CreateDirectory(string directoryName, string parentItemIden
completionHandler?.Invoke(ProviderItem.CreateFromMetadata(createdFolder), null);
this.StorageManager.NotifyEnumerator(parentItemIdentifier);
}
- catch (MethodNotAllowedException ex)
+ catch (MethodNotAllowedException)
{
completionHandler?.Invoke(null, NsErrorHelper.GetFileProviderDuplicateException());
}
@@ -350,7 +339,7 @@ public override void DeleteItem(string itemIdentifier, Action completio
this.StorageManager.DeleteEveryWhere(metadata);
completionHandler?.Invoke(null);
}
- catch (MethodNotAllowedException ex)
+ catch (MethodNotAllowedException)
{
completionHandler?.Invoke( NsErrorHelper.GetFileProviderDuplicateException());
}
@@ -364,7 +353,7 @@ public override void DeleteItem(string itemIdentifier, Action completio
/// The URL for the file.
/// The parent directory's persistent identifier.
/// A handler to run after the operation completes.
- /// When implemented by the developer, imports the resource at the specified into the directory that is identified by .
+ /// When implemented by the developer, imports the resource at the specified into the directory that is identified by .
///
/// (More documentation for this node is coming)
/// This can be used from a background thread.
@@ -374,14 +363,14 @@ public override void ImportDocument(NSUrl fileUrl, string parentItemIdentifier,
try
{
fileUrl.StartAccessingSecurityScopedResource();
- var parentMetadata = StorageManager.GetFolderMetadata(parentItemIdentifier);
+ FolderMetadata parentMetadata = StorageManager.GetFolderMetadata(parentItemIdentifier);
if(!parentMetadata.IsExists)
{
completionHandler?.Invoke(null, NsErrorHelper.GetFileProviderNotFoundError(parentItemIdentifier));
return;
}
- var existsNames = StorageManager.GetFolderChildrenMetadatas(parentMetadata).Select(x => x.Name);
+ IEnumerable existsNames = StorageManager.GetFolderChildrenMetadatas(parentMetadata).Select(x => x.Name);
string fileName = GetNewFileName(fileUrl.LastPathComponent, existsNames);
FileMetadata createdFile = StorageManager.CreateFileOnServer(parentMetadata, fileName);
createdFile = StorageManager.WriteContentOnServer(createdFile, fileUrl.Path);
@@ -402,7 +391,11 @@ public override void ImportDocument(NSUrl fileUrl, string parentItemIdentifier,
private string GetNewFileName(string fileName, IEnumerable existsNames)
{
var nameSet = existsNames.ToHashSet();
- if (!nameSet.Contains(fileName)) return fileName;
+ if (!nameSet.Contains(fileName))
+ {
+ return fileName;
+ }
+
string filenameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
string extension = Path.GetExtension(fileName);
int i = 1;
@@ -449,17 +442,17 @@ public override void ReparentItem(string itemIdentifier, string destParentItemId
FolderMetadata destinationFolder = this.StorageManager.GetFolderMetadata(destParentItemIdentifier);
string name = newName ?? item.Name;
this.StorageManager.MoveItemOnServer(item, destinationFolder, name);
- var oldParentIdentifier = item.ParentIdentifier;
+ string oldParentIdentifier = item.ParentIdentifier;
item.ParentIdentifier = destParentItemIdentifier;
item.Name = name;
completionHandler(ProviderItem.CreateFromMetadata(item), null);
this.StorageManager.NotifyEnumerator(oldParentIdentifier, item.ParentIdentifier);
}
- catch (PreconditionFailedException ex)
+ catch (PreconditionFailedException)
{
completionHandler?.Invoke(null, NsErrorHelper.GetFileProviderDuplicateException());
}
- catch (ForbiddenException ex)
+ catch (ForbiddenException)
{
completionHandler?.Invoke(null, NsErrorHelper.GetFileProviderDuplicateException());
}
diff --git a/iOS/WebDavContainerExtension/FileProviderItems/FileItem.cs b/iOS/WebDavContainerExtension/FileProviderItems/FileItem.cs
index 127ab51..b7d7276 100644
--- a/iOS/WebDavContainerExtension/FileProviderItems/FileItem.cs
+++ b/iOS/WebDavContainerExtension/FileProviderItems/FileItem.cs
@@ -1,10 +1,6 @@
-using System;
-using WebDavContainerExtension.Metadatas;
+using WebDavContainerExtension.Metadatas;
using FileProvider;
using Foundation;
-using ITHit.WebDAV.Client.Exceptions;
-using WebDavContainerExtension.Helpers;
-using WebDavContainerExtension.Storages;
namespace WebDavContainerExtension.FileProviderItems
{
@@ -43,8 +39,8 @@ public FileItem(FileMetadata fileMetadata) : base(fileMetadata)
}
IsDownloaded = fileMetadata.ExistsLocal;
- IsMostRecentVersionDownloaded = fileMetadata.IsSyncByEtag && IsDownloaded;
- IsUploaded = !fileMetadata.HasUploadError || fileMetadata.IsSyncByEtag;
+ IsMostRecentVersionDownloaded = fileMetadata.IsSyncByEtag && fileMetadata.ExistsLocal;
+ IsUploaded = !fileMetadata.HasUploadError && (fileMetadata.IsSyncByEtag || !fileMetadata.ExistsLocal);
UploadingError = fileMetadata.LocalFile.UploadError;
}
}
diff --git a/iOS/WebDavContainerExtension/FileProviderItems/FolderItem.cs b/iOS/WebDavContainerExtension/FileProviderItems/FolderItem.cs
index ec2cd0c..fff92e3 100644
--- a/iOS/WebDavContainerExtension/FileProviderItems/FolderItem.cs
+++ b/iOS/WebDavContainerExtension/FileProviderItems/FolderItem.cs
@@ -1,6 +1,5 @@
using WebDavContainerExtension.Metadatas;
using FileProvider;
-using Foundation;
namespace WebDavContainerExtension.FileProviderItems
{
diff --git a/iOS/WebDavContainerExtension/Helpers/FileManagerHelper.cs b/iOS/WebDavContainerExtension/Helpers/FileManagerHelper.cs
index b18d3de..9081d6f 100644
--- a/iOS/WebDavContainerExtension/Helpers/FileManagerHelper.cs
+++ b/iOS/WebDavContainerExtension/Helpers/FileManagerHelper.cs
@@ -7,12 +7,8 @@ namespace WebDavContainerExtension.Helpers
{
public class NSFileManagerHelper
{
- const string BackupKey = "com.apple.MobileBackup";
-
private const string LibsystemKernelDylib = "/usr/lib/system/libsystem_kernel.dylib";
- static bool _xattrCompatibility;
-
///
/// Errno for not existing attribute.
///
@@ -26,7 +22,6 @@ public class NSFileManagerHelper
static NSFileManagerHelper()
{
- _xattrCompatibility = true; //!UIDevice.CurrentDevice.CheckSystemVersion (5, 1);
}
@@ -38,7 +33,7 @@ static NSFileManagerHelper()
/// Throw when path is null or empty.
public static bool IsExtendedAttributesSupported(string path)
{
- if(string.IsNullOrEmpty(path))
+ if (string.IsNullOrEmpty(path))
{
throw new ArgumentNullException(nameof(path));
}
@@ -57,20 +52,50 @@ public static bool IsExtendedAttributesSupported(string path)
/// Throw when file or attribute is no available.
public static string GetExtendedAttribute(string path, string attrName)
{
- if(string.IsNullOrEmpty(path))
+ if (string.IsNullOrEmpty(path))
{
throw new ArgumentNullException(nameof(path));
}
- if(string.IsNullOrEmpty(attrName))
+ if (string.IsNullOrEmpty(attrName))
+ {
+ throw new ArgumentNullException(nameof(attrName));
+ }
+
+ byte[] buffer = GetExtendedAttributeBytes(path, attrName);
+ if (buffer != null)
+ {
+ return Encoding.UTF8.GetString(buffer);
+ }
+
+ return null;
+ }
+
+
+ ///
+ /// Reads extended attribute as .
+ ///
+ /// File or folder path.
+ /// Attribute name.
+ ///
+ /// Throw when path is null or empty or attrName is null or empty.
+ /// Throw when file or attribute is no available.
+ public static byte[] GetExtendedAttributeBytes(string path, string attrName)
+ {
+ if (string.IsNullOrEmpty(path))
+ {
+ throw new ArgumentNullException(nameof(path));
+ }
+
+ if (string.IsNullOrEmpty(attrName))
{
throw new ArgumentNullException(nameof(attrName));
}
long attributeSize = GetXAttr(path, attrName, null, 0, 0, 0);
- if(attributeSize == -1)
+ if (attributeSize == -1)
{
- if(Marshal.GetLastWin32Error() == AttributeNotFoundErrno)
+ if (Marshal.GetLastWin32Error() == AttributeNotFoundErrno)
{
return null;
}
@@ -81,13 +106,12 @@ public static string GetExtendedAttribute(string path, string attrName)
byte[] buffer = new byte[attributeSize];
long readLength = GetXAttr(path, attrName, buffer, attributeSize, 0, 0);
- if(readLength == -1)
+ if (readLength == -1)
{
ThrowLastException(path, attrName);
}
- string attributeValue = Encoding.UTF8.GetString(buffer);
- return attributeValue;
+ return buffer;
}
///
@@ -100,19 +124,43 @@ public static string GetExtendedAttribute(string path, string attrName)
/// Throw when file or attribute is no available.
public static void SetExtendedAttribute(string path, string attrName, string attrValue)
{
- if(string.IsNullOrEmpty(path))
+ if (string.IsNullOrEmpty(path))
{
throw new ArgumentNullException(nameof(path));
}
- if(string.IsNullOrEmpty(attrName))
+ if (string.IsNullOrEmpty(attrName))
{
throw new ArgumentNullException(nameof(attrName));
}
byte[] buffer = Encoding.UTF8.GetBytes(attrValue);
+ SetExtendedAttributeBytes(path, attrName, buffer);
+ }
+
+
+ ///
+ /// Writes extended attribute as .
+ ///
+ /// File or folder path.
+ /// Attribute name.
+ /// Attribute value.
+ /// Throw when path is null or empty or attrName is null or empty.
+ /// Throw when file or attribute is no available.
+ public static void SetExtendedAttributeBytes(string path, string attrName, byte[] buffer)
+ {
+ if (string.IsNullOrEmpty(path))
+ {
+ throw new ArgumentNullException(nameof(path));
+ }
+
+ if (string.IsNullOrEmpty(attrName))
+ {
+ throw new ArgumentNullException(nameof(attrName));
+ }
+
long result = SetXAttr(path, attrName, buffer, buffer.Length, 0, 0);
- if(result == -1)
+ if (result == -1)
{
ThrowLastException(path, attrName);
}
@@ -125,18 +173,18 @@ public static void SetExtendedAttribute(string path, string attrName, string att
/// Attribute name.
public static void DeleteExtendedAttribute(string path, string attrName)
{
- if(string.IsNullOrEmpty(path))
+ if (string.IsNullOrEmpty(path))
{
throw new ArgumentNullException(nameof(path));
}
- if(string.IsNullOrEmpty(attrName))
+ if (string.IsNullOrEmpty(attrName))
{
throw new ArgumentNullException(nameof(attrName));
}
long result = RemoveXAttr(path, attrName, 0);
- if(result == -1)
+ if (result == -1)
{
ThrowLastException(path, attrName);
}
diff --git a/iOS/WebDavContainerExtension/Helpers/NSErrorHelper.cs b/iOS/WebDavContainerExtension/Helpers/NSErrorHelper.cs
index 5693525..2f71512 100644
--- a/iOS/WebDavContainerExtension/Helpers/NSErrorHelper.cs
+++ b/iOS/WebDavContainerExtension/Helpers/NSErrorHelper.cs
@@ -10,7 +10,7 @@ class NsErrorHelper
{
public static NSError GetFileProviderError(NSFileProviderError nsFileProviderError)
{
- var errorDomain = nsFileProviderError.GetDomain();
+ NSString errorDomain = nsFileProviderError.GetDomain();
return new NSError(errorDomain, (int)nsFileProviderError);
}
@@ -30,7 +30,7 @@ internal static NSError GetFileProviderErrorWithError(NSFileProviderError nsFile
public static NSError GetFileProviderNotFoundError(string id)
{
var userInfo = new NSDictionary(NSFileProviderErrorKeys.NonExistentItemIdentifierKey, id);
- var errorCode = NSFileProviderError.NoSuchItem;
+ NSFileProviderError errorCode = NSFileProviderError.NoSuchItem;
return new NSError(errorCode.GetDomain(), (int)errorCode, userInfo);
}
diff --git a/iOS/WebDavContainerExtension/Info.plist b/iOS/WebDavContainerExtension/Info.plist
index 019971a..ba23c37 100644
--- a/iOS/WebDavContainerExtension/Info.plist
+++ b/iOS/WebDavContainerExtension/Info.plist
@@ -3,7 +3,7 @@
CFBundleDisplayName
- WebDAV Client
+ IT Hit WebDAV Client
CFBundleExecutable
WebDavContainerExtension
CFBundleIdentifier
@@ -47,6 +47,6 @@
arm64
CFBundleVersion
- 1032
+ 1034
diff --git a/iOS/WebDavContainerExtension/Metadatas/ChangeTracker.cs b/iOS/WebDavContainerExtension/Metadatas/ChangeTracker.cs
index 2e7aaa0..751b0b6 100644
--- a/iOS/WebDavContainerExtension/Metadatas/ChangeTracker.cs
+++ b/iOS/WebDavContainerExtension/Metadatas/ChangeTracker.cs
@@ -17,7 +17,11 @@ public ChangeTracker()
private string[] GetChangeSetOrEmpty(uint anchor)
{
- if(!changeSets.ContainsKey(anchor)) return new string[] { };
+ if(!changeSets.ContainsKey(anchor))
+ {
+ return new string[] { };
+ }
+
return changeSets[anchor];
}
@@ -39,7 +43,7 @@ public uint AddChangeSet(ItemMetadata[] metadatas)
public MetadataDiff GetDiff(uint anchor, ItemMetadata[] metadatas)
{
- var changeSetContent = GetChangeSetOrEmpty(anchor);
+ string[] changeSetContent = GetChangeSetOrEmpty(anchor);
var removed = changeSetContent.Where(item => !metadatas.Any(ch => ch.Identifier == item)).ToArray();
return new MetadataDiff(removed, metadatas);
}
diff --git a/iOS/WebDavContainerExtension/Metadatas/FileMetadata.cs b/iOS/WebDavContainerExtension/Metadatas/FileMetadata.cs
index 47bb38a..2b104c8 100644
--- a/iOS/WebDavContainerExtension/Metadatas/FileMetadata.cs
+++ b/iOS/WebDavContainerExtension/Metadatas/FileMetadata.cs
@@ -10,10 +10,7 @@ public class FileMetadata: ItemMetadata
public IFileAsync ServerFile { get; set; }
- public bool IsSyncByEtag
- {
- get { return ExistsOnServer && LocalFile.Etag == ServerFile.Etag; }
- }
+ public bool IsSyncByEtag => ExistsOnServer && LocalFile.Etag == ServerFile.Etag;
public ulong Size
{
diff --git a/iOS/WebDavContainerExtension/Metadatas/ItemMetadata.cs b/iOS/WebDavContainerExtension/Metadatas/ItemMetadata.cs
index 4b5c61d..dd575b0 100644
--- a/iOS/WebDavContainerExtension/Metadatas/ItemMetadata.cs
+++ b/iOS/WebDavContainerExtension/Metadatas/ItemMetadata.cs
@@ -16,7 +16,7 @@ public abstract class ItemMetadata
public bool IsFolder => this is FolderMetadata;
public bool IsFile => this is FileMetadata;
- public ItemMetadata(string identifier, string parentIdentifier, string name, LocalItem localItem, IHierarchyItemAsync serverItem = null)
+ protected ItemMetadata(string identifier, string parentIdentifier, string name, LocalItem localItem, IHierarchyItemAsync serverItem = null)
{
this.Identifier = identifier;
this.ParentIdentifier = parentIdentifier;
diff --git a/iOS/WebDavContainerExtension/Metadatas/MetadataDiff.cs b/iOS/WebDavContainerExtension/Metadatas/MetadataDiff.cs
index bed8ba9..d353ce3 100644
--- a/iOS/WebDavContainerExtension/Metadatas/MetadataDiff.cs
+++ b/iOS/WebDavContainerExtension/Metadatas/MetadataDiff.cs
@@ -1,8 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-
-namespace WebDavContainerExtension.Metadatas
+namespace WebDavContainerExtension.Metadatas
{
public class MetadataDiff
{
diff --git a/iOS/WebDavContainerExtension/Metadatas/StorageManager.cs b/iOS/WebDavContainerExtension/Metadatas/StorageManager.cs
index c284b74..2b46764 100644
--- a/iOS/WebDavContainerExtension/Metadatas/StorageManager.cs
+++ b/iOS/WebDavContainerExtension/Metadatas/StorageManager.cs
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
-using System.IO;
using System.Linq;
using FileProvider;
using Foundation;
@@ -26,9 +25,9 @@ public StorageManager(LocationMapper locationMapper, WebDavSessionAsync session,
public void NotifyEnumerator(params string[] itemIdentifiers)
{
- foreach (var itemIdentifier in itemIdentifiers)
+ foreach(string itemIdentifier in itemIdentifiers)
{
- NSFileProviderManager.DefaultManager.SignalEnumerator(itemIdentifier,error => { });
+ NSFileProviderManager.DefaultManager.SignalEnumerator(itemIdentifier, error => { });
}
}
@@ -38,14 +37,14 @@ public FolderMetadata GetFolderMetadata(string itemIdentifier)
{
Uri serverUri = LocationMapper.GetServerUriFromIdentifier(itemIdentifier);
IFolderAsync serverItem = Session.OpenFolderAsync(serverUri)
- .GetAwaiter()
- .GetResult();
+ .GetAwaiter()
+ .GetResult();
string localPath = LocationMapper.GetLocalUrlFromIdentifier(itemIdentifier);
LocalFolder localItem = this.LocalStorage.GetFolder(localPath);
return this.CreateFolderMetadata(itemIdentifier, localItem, serverItem);
}
- catch (NotFoundException)
+ catch(NotFoundException)
{
var localPath = LocationMapper.GetLocalUrlFromIdentifier(itemIdentifier);
LocalFolder localItem = this.LocalStorage.GetFolder(localPath);
@@ -63,11 +62,11 @@ private FolderMetadata CreateFolderMetadata(string itemIdentifier, LocalFolder l
public FolderMetadata CreateFolderOnServer(FolderMetadata folderMetadata, string directoryName)
{
IFolderAsync newFolder = folderMetadata.ServerFolder.CreateFolderAsync(directoryName)
- .GetAwaiter()
- .GetResult();
+ .GetAwaiter()
+ .GetResult();
- var id = LocationMapper.GetIdentifierFromServerUri(newFolder.Href);
- var localPath = LocationMapper.GetLocalUrlFromIdentifier(id);
+ string id = LocationMapper.GetIdentifierFromServerUri(newFolder.Href);
+ string localPath = LocationMapper.GetLocalUrlFromIdentifier(id);
LocalFolder localItem = this.LocalStorage.GetFolder(localPath);
return CreateFolderMetadata(id, localItem, newFolder);
}
@@ -84,21 +83,20 @@ public ItemMetadata GetItemMetadata(string itemIdentifier)
public FileMetadata GetFileMetadata(string itemIdentifier)
{
-
try
{
Uri serverUri = LocationMapper.GetServerUriFromIdentifier(itemIdentifier);
IFileAsync serverItem = Session.OpenFileAsync(serverUri)
- .GetAwaiter()
- .GetResult();
+ .GetAwaiter()
+ .GetResult();
string localPath = LocationMapper.GetLocalUrlFromIdentifier(itemIdentifier);
LocalFile localItem = this.LocalStorage.GetFile(localPath);
return this.CreateFileMetadata(itemIdentifier, localItem, serverItem);
}
- catch (NotFoundException)
+ catch(NotFoundException)
{
- var localPath = LocationMapper.GetLocalUrlFromIdentifier(itemIdentifier);
+ string localPath = LocationMapper.GetLocalUrlFromIdentifier(itemIdentifier);
LocalFile localItem = this.LocalStorage.GetFile(localPath);
return this.CreateFileMetadata(itemIdentifier, localItem);
}
@@ -108,50 +106,56 @@ private FileMetadata CreateFileMetadata(string itemIdentifier, LocalFile localIt
{
string parentIdentifier = LocationMapper.GetParentIdentifier(itemIdentifier);
string name = GetItemDisplayName(itemIdentifier, serverItem);
- return new FileMetadata(itemIdentifier, parentIdentifier, name,localItem, serverItem);
+ return new FileMetadata(itemIdentifier, parentIdentifier, name, localItem, serverItem);
}
public void DeleteEveryWhere(ItemMetadata itemMetadata)
{
- if (itemMetadata.ExistsLocal)
+ if(itemMetadata.ExistsLocal)
{
LocalStorage.Delete(itemMetadata.LocalItem);
}
- if (itemMetadata.ExistsOnServer)
+ if(itemMetadata.ExistsOnServer)
{
try
{
itemMetadata.ServerItem.DeleteAsync().GetAwaiter().GetResult();
}
- catch (NotFoundException) { };
+ catch(NotFoundException)
+ {
+ }
}
}
public ItemMetadata[] GetFolderChildrenMetadatas(FolderMetadata folderMetadata)
{
IHierarchyItemAsync[] serverItems;
- if (folderMetadata.ExistsOnServer)
+ if(folderMetadata.ExistsOnServer)
+ {
try
{
serverItems = folderMetadata.ServerFolder.GetChildrenAsync(false)
- .GetAwaiter()
- .GetResult();
+ .GetAwaiter()
+ .GetResult();
}
- catch (NotFoundException)
+ catch(NotFoundException)
{
serverItems = new IHierarchyItemAsync[0];
- } else
+ }
+ }
+ else
{
serverItems = new IHierarchyItemAsync[0];
}
LocalItem[] localItems;
- if (folderMetadata.ExistsLocal)
+ if(folderMetadata.ExistsLocal)
{
localItems = LocalStorage.GetFolderContent(folderMetadata.LocalFolder);
- } else
+ }
+ else
{
localItems = new LocalItem[0];
}
@@ -165,8 +169,8 @@ private ItemMetadata[] CreateItemMetadatas(string parentIdentifier, LocalItem[]
var result = new List();
foreach(IHierarchyItemAsync hierarchyItemAsync in serverItems)
{
- var localUrl = LocationMapper.GetLocalUrlFromServerUri(hierarchyItemAsync.Href);
- var identifier = LocationMapper.GetIdentifierFromServerUri(hierarchyItemAsync.Href);
+ string localUrl = LocationMapper.GetLocalUrlFromServerUri(hierarchyItemAsync.Href);
+ string identifier = LocationMapper.GetIdentifierFromServerUri(hierarchyItemAsync.Href);
if(hierarchyItemAsync is IFolderAsync folder)
{
if(localDictionary.ContainsKey(localUrl) && localDictionary[localUrl].IsFolder)
@@ -182,31 +186,31 @@ private ItemMetadata[] CreateItemMetadatas(string parentIdentifier, LocalItem[]
result.Add(new FolderMetadata(identifier, parentIdentifier, name1, localItem1, folder));
}
- if (hierarchyItemAsync is IFileAsync file)
+ if(hierarchyItemAsync is IFileAsync file)
{
- if (localDictionary.ContainsKey(localUrl) && localDictionary[localUrl].IsFile)
+ if(localDictionary.ContainsKey(localUrl) && localDictionary[localUrl].IsFile)
{
LocalFile localItem = localDictionary[localUrl].AsFile();
string name = GetItemDisplayName(identifier, file);
- result.Add(new FileMetadata(identifier, parentIdentifier, name,localItem, file));
+ result.Add(new FileMetadata(identifier, parentIdentifier, name, localItem, file));
localDictionary.Remove(localUrl);
}
LocalFile localItem1 = LocalStorage.GetFile(localUrl);
string name1 = GetItemDisplayName(identifier, file);
- result.Add(new FileMetadata(identifier, parentIdentifier, name1,localItem1, file));
+ result.Add(new FileMetadata(identifier, parentIdentifier, name1, localItem1, file));
}
}
foreach(KeyValuePair dictionaryItem in localDictionary)
{
- var identifier = LocationMapper.GetIdentifierFromLocalPath(dictionaryItem.Key);
+ string identifier = LocationMapper.GetIdentifierFromLocalPath(dictionaryItem.Key);
if(dictionaryItem.Value.IsFile)
{
result.Add(CreateFileMetadata(identifier, dictionaryItem.Value.AsFile()));
}
- if (dictionaryItem.Value.IsFolder)
+ if(dictionaryItem.Value.IsFolder)
{
result.Add(CreateFolderMetadata(identifier, dictionaryItem.Value.AsFolder()));
}
@@ -223,28 +227,26 @@ private string GetItemDisplayName(string itemIdentifier, IHierarchyItemAsync ser
public FileMetadata CreateFileOnServer(FolderMetadata parentMetadata, string fileName)
{
IFileAsync newFile = parentMetadata.ServerFolder.CreateFileAsync(fileName, null).GetAwaiter().GetResult();
- var identifier = LocationMapper.GetIdentifierFromServerUri(newFile.Href);
- var localPath = LocationMapper.GetLocalUrlFromIdentifier(identifier);
+ string identifier = LocationMapper.GetIdentifierFromServerUri(newFile.Href);
+ string localPath = LocationMapper.GetLocalUrlFromIdentifier(identifier);
LocalFile localItem = LocalStorage.GetFile(localPath);
string name = GetItemDisplayName(identifier, newFile);
- return new FileMetadata(identifier, parentMetadata.Identifier, name,localItem, newFile);
-
+ return new FileMetadata(identifier, parentMetadata.Identifier, name, localItem, newFile);
}
public FileMetadata WriteContentOnServer(FileMetadata createdFile, string fileUrlPath)
{
- var serverItem = createdFile.ServerFile;
+ IFileAsync serverItem = createdFile.ServerFile;
serverItem.TimeOut = 36000000;
- FileInfo file = new FileInfo(fileUrlPath);
serverItem.UploadAsync(fileUrlPath).GetAwaiter().GetResult();
return GetFileMetadata(createdFile.Identifier);
}
public FileMetadata UpdateFileLocal(FileMetadata item)
{
- var localFile = LocalStorage.UpdateFile(item.LocalFile);
+ LocalFile localFile = LocalStorage.UpdateFile(item.LocalFile);
string name = GetItemDisplayName(item.Identifier, item.ServerFile);
- return new FileMetadata(item.Identifier, item.ParentIdentifier, name,localFile, item.ServerFile);
+ return new FileMetadata(item.Identifier, item.ParentIdentifier, name, localFile, item.ServerFile);
}
public FileMetadata PushToServer(FileMetadata item)
@@ -255,36 +257,33 @@ public FileMetadata PushToServer(FileMetadata item)
}
item = WriteContentOnServer(item, item.LocalFile.Path);
-
item.LocalFile.Etag = item.ServerFile.Etag;
item.LocalFile.UploadError = null;
-
-
LocalStorage.UpdateFile(item.LocalFile);
return item;
}
private FileMetadata CreateOnServer(FileMetadata item)
{
- var parent = GetFolderMetadata(item.ParentIdentifier);
+ FolderMetadata parent = GetFolderMetadata(item.ParentIdentifier);
return CreateFileOnServer(parent, item.Name);
}
private FolderMetadata CreateOnServer(FolderMetadata item)
{
- var parent = GetFolderMetadata(item.ParentIdentifier);
+ FolderMetadata parent = GetFolderMetadata(item.ParentIdentifier);
return CreateFolderOnServer(parent, item.Name);
}
public void MoveItemOnServer(ItemMetadata item, FolderMetadata destinationFolder, string name)
{
- item.ServerItem.MoveToAsync(destinationFolder.ServerFolder, name, false,null).GetAwaiter().GetResult();
+ item.ServerItem.MoveToAsync(destinationFolder.ServerFolder, name, false, null).GetAwaiter().GetResult();
}
public void PullFromServer(FileMetadata item)
{
- var serverItem = item.ServerFile;
+ IFileAsync serverItem = item.ServerFile;
item.ServerFile.TimeOut = 36000000;
serverItem.DownloadAsync(item.LocalFile.Path).GetAwaiter().GetResult();
item.LocalFile.Etag = item.ServerFile.Etag;
@@ -298,7 +297,7 @@ public void DeleteLocal(ItemMetadata item)
public void SetUploadError(NSUrl url, NSError localFileUploadError)
{
- var localFile = this.LocalStorage.GetFile(url.Path);
+ LocalFile localFile = this.LocalStorage.GetFile(url.Path);
localFile.UploadError = localFileUploadError;
localFile.Etag = null;
this.LocalStorage.UpdateFile(localFile);
diff --git a/iOS/WebDavContainerExtension/Storages/FileExtendedAttribute.cs b/iOS/WebDavContainerExtension/Storages/FileExtendedAttribute.cs
index 130dbb9..a283f99 100644
--- a/iOS/WebDavContainerExtension/Storages/FileExtendedAttribute.cs
+++ b/iOS/WebDavContainerExtension/Storages/FileExtendedAttribute.cs
@@ -1,30 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
-using System.Runtime.Serialization;
using Foundation;
using WebDavContainerExtension.Helpers;
namespace WebDavContainerExtension.Storages
{
[Serializable]
- [DataContract(Name = nameof(FileExtendedAttribute))]
public class FileExtendedAttribute
{
public FileExtendedAttribute()
{
}
- [DataMember]
public Dictionary UploadErrorInfo { get; set; }
- [DataMember]
public long UploadErrorCode { get; set; }
- [DataMember]
public string UploadErrorDomain { get; set; }
- [DataMember]
public string Etag { get; set; }
public FileExtendedAttribute(NSError error)
diff --git a/iOS/WebDavContainerExtension/Storages/LocalFile.cs b/iOS/WebDavContainerExtension/Storages/LocalFile.cs
index bcf3f22..580594d 100644
--- a/iOS/WebDavContainerExtension/Storages/LocalFile.cs
+++ b/iOS/WebDavContainerExtension/Storages/LocalFile.cs
@@ -1,5 +1,4 @@
-using System;
-using Foundation;
+using Foundation;
namespace WebDavContainerExtension.Storages
{
diff --git a/iOS/WebDavContainerExtension/Storages/LocalItem.cs b/iOS/WebDavContainerExtension/Storages/LocalItem.cs
index fc61215..d1a2106 100644
--- a/iOS/WebDavContainerExtension/Storages/LocalItem.cs
+++ b/iOS/WebDavContainerExtension/Storages/LocalItem.cs
@@ -1,8 +1,5 @@
-using System.Runtime.Serialization;
-
-namespace WebDavContainerExtension.Storages
+namespace WebDavContainerExtension.Storages
{
- [DataContract(Name = nameof(LocalItem))]
public abstract class LocalItem
{
@@ -16,13 +13,13 @@ public abstract class LocalItem
public bool IsFile => this is LocalFile;
- public LocalItem(string localPath, bool exists)
+ protected LocalItem(string localPath, bool exists)
{
this.Path = localPath;
this.IsExists = exists;
}
- public LocalItem()
+ protected LocalItem()
{
}
diff --git a/iOS/WebDavContainerExtension/Storages/LocalStorage.cs b/iOS/WebDavContainerExtension/Storages/LocalStorage.cs
index d3434c0..8763bc2 100644
--- a/iOS/WebDavContainerExtension/Storages/LocalStorage.cs
+++ b/iOS/WebDavContainerExtension/Storages/LocalStorage.cs
@@ -2,21 +2,21 @@
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
-using System.Xml;
using WebDavContainerExtension.Extensions;
using Foundation;
using WebDavContainerExtension.Helpers;
+using System.Runtime.Serialization.Formatters.Binary;
namespace WebDavContainerExtension.Storages
{
public class LocalStorage
{
- private readonly DataContractSerializer _fileExtendedAttributeSerializer;
+ private readonly IFormatter _fileExtendedAttributeSerializer;
private const string ExtendedAttributeKey = "FsExtensionMetadata";
public LocalStorage()
{
- _fileExtendedAttributeSerializer = new DataContractSerializer(typeof(FileExtendedAttribute));
+ _fileExtendedAttributeSerializer = new BinaryFormatter();
}
private LocalFile GetFile(string localPath, bool isExists)
@@ -38,7 +38,7 @@ private LocalFile GetFile(string localPath, bool isExists)
return LocalFile.CreateExists(localPath, fileSize, fileExtendedAttribute);
}
- catch(SerializationException)
+ catch (SerializationException)
{
NSFileManagerHelper.DeleteExtendedAttribute(localPath, ExtendedAttributeKey);
return LocalFile.CreateExists(localPath, fileSize);
@@ -52,16 +52,15 @@ protected FileExtendedAttribute GetFileExtendedAttribute(string localPath)
throw new ArgumentNullException(nameof(localPath));
}
- string extendedAttributes = NSFileManagerHelper.GetExtendedAttribute(localPath, ExtendedAttributeKey);
- if (string.IsNullOrEmpty(extendedAttributes))
+ byte[] extendedAttribute = NSFileManagerHelper.GetExtendedAttributeBytes(localPath, ExtendedAttributeKey);
+ if (extendedAttribute == null)
{
return null;
- }
-
- using (TextReader stringReader = new StringReader(extendedAttributes))
- using (XmlReader xmlReader = new XmlTextReader(stringReader))
+ }
+
+ using (MemoryStream stream = new MemoryStream(extendedAttribute))
{
- return (FileExtendedAttribute)_fileExtendedAttributeSerializer.ReadObject(xmlReader);
+ return (FileExtendedAttribute)_fileExtendedAttributeSerializer.Deserialize(stream);
}
}
@@ -119,12 +118,12 @@ public LocalFile UpdateFile(LocalFile localFile)
private void WriteFileExtendedAttribute(LocalFile itemLocalItem, FileExtendedAttribute fileExtendedAttribute)
{
- using (TextWriter writer = new StringWriter())
- using (var xmlWriter = new XmlTextWriter(writer))
+ using (MemoryStream stream = new MemoryStream())
{
- _fileExtendedAttributeSerializer.WriteObject(xmlWriter, fileExtendedAttribute);
- xmlWriter.Flush();
- NSFileManagerHelper.SetExtendedAttribute(itemLocalItem.Path, ExtendedAttributeKey, writer.ToString());
+ _fileExtendedAttributeSerializer.Serialize(stream, fileExtendedAttribute);
+ stream.Flush();
+ stream.Position = 0;
+ NSFileManagerHelper.SetExtendedAttributeBytes(itemLocalItem.Path, ExtendedAttributeKey, stream.ToArray());
}
}
diff --git a/iOS/WebDavContainerExtension/WebDavContainerExtension.csproj b/iOS/WebDavContainerExtension/WebDavContainerExtension.csproj
index c36e493..8d6cccb 100644
--- a/iOS/WebDavContainerExtension/WebDavContainerExtension.csproj
+++ b/iOS/WebDavContainerExtension/WebDavContainerExtension.csproj
@@ -118,7 +118,7 @@
4
- iPhone Developer: Igor Smok (L6YLB75XGQ)
+
true
@@ -138,15 +138,13 @@
-
- ..\packages\ITHitWebDAVClient.3.0.1032-beta\lib\Xamarin.iOS10\ITHit.WebDAV.Client.dll
+
+ ..\packages\ITHitWebDAVClient.3.0.1034\lib\Xamarin.iOS10\ITHit.WebDAV.Client.dll
-
-
diff --git a/iOS/WebDavContainerExtension/packages.config b/iOS/WebDavContainerExtension/packages.config
index f08dc36..dcd4fca 100644
--- a/iOS/WebDavContainerExtension/packages.config
+++ b/iOS/WebDavContainerExtension/packages.config
@@ -1,4 +1,4 @@
-
+
\ No newline at end of file