Esempio n. 1
0
 public CloudStorageSource(CRCloudMetaData[] metaData, ICRCloudStorageProtocol cloudStorage, CloudStorageViewController controller)
 {
     this._metaData     = metaData;
     this._cloudStorage = cloudStorage;
     this._controller   = controller;
     helper             = new Helper();
     logic = new CloudStorageLogic();
 }
 //Logout - Logout user, Revokes the current authentication.
 public void Logout(ICRCloudStorageProtocol cloudStorage)
 {
     try
     {
         cloudStorage.Logout();
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
 }
 //Copy File From Path - Copies a file or a folder to the new location.
 public void CopyFileFromPath(ICRCloudStorageProtocol cloudStorage, string path, string destination)
 {
     try
     {
         cloudStorage.CopyFileFromPath(path, destination);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
 }
 //Create Folder With Path - Creates a new empty folder at the specified location.
 public void CreateFolderWithPath(ICRCloudStorageProtocol cloudStorage, string path)
 {
     try
     {
         cloudStorage.CreateFolderWithPath(path);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
 }
 //Upload File To Path - Uploads a file to the specified location. Can either overwrite the existing file or will fail if the file already exists.
 public void UploadFileToPath(ICRCloudStorageProtocol cloudStorage, string path, NSInputStream inputSteam, int size, bool overwrite)
 {
     try
     {
         cloudStorage.UploadFileToPath(path, inputSteam, size, overwrite);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
 }
 //Share Link For File With Path - Creates a link to a file or folder that allows to share it with others.
 public string ShareLinkForFileWithPath(ICRCloudStorageProtocol cloudStorage, string path)
 {
     try
     {
         return(cloudStorage.ShareLinkForFileWithPath(path));
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return("");
     }
 }
 //Get User Name - Returns the username
 public string GetUserName(ICRCloudStorageProtocol cloudStorage)
 {
     try
     {
         return(cloudStorage.GetUserName());
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return("");
     }
 }
 //Metadata Of File With Path - Returns a metadata object for a file or a folder.
 public CRCloudMetaData MetadataOfFileWithPath(ICRCloudStorageProtocol cloudStorage, string path)
 {
     try
     {
         return(cloudStorage.MetadataOfFileWithPath(path));
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return(new CRCloudMetaData());
     }
 }
 //Thumbnail Of File With Path - Returns a thumbnail of the specified file. This is inteded for image files but also works for others for some services.
 public NSInputStream ThumbnailOfFileWithPath(ICRCloudStorageProtocol cloudStorage, string path)
 {
     try
     {
         return(cloudStorage.ThumbnailOfFileWithPath(path));
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return(null);
     }
 }
 //File Exists At Path - Returns if there is a file or folder at the specified folder.
 public bool FileExistsAtPath(ICRCloudStorageProtocol cloudStorage, string path)
 {
     try
     {
         return(cloudStorage.FileExistsAtPath(path));
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return(false);
     }
 }
 //Get Space Allocation - Returns metadata on the usage of the users storage volume.
 public CRSpaceAllocation GetSpaceAllocation(ICRCloudStorageProtocol cloudStorage)
 {
     try
     {
         return(new CRSpaceAllocation());
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return(new CRSpaceAllocation());
     }
 }
 //Children Of Folder With Path - Returns a list of metadata object for the children of a folder.
 public CRCloudMetaData[] ChildrenOfFolderWithPath(ICRCloudStorageProtocol cloudStorage, string path)
 {
     try
     {
         CRCloudMetaData[] array = NSArray.FromArray <CRCloudMetaData>(cloudStorage.ChildrenOfFolderWithPath(path));
         return(array);
     }
     catch (Exception e)
     {
         // Console.WriteLine(e.Message);
         CRCloudMetaData[] metaData = new CRCloudMetaData[] { };
         return(metaData);
     }
 }
 //Search With Query - Returns a list of files and folders that match the provided search query.
 public CRCloudMetaData[] SearchWithQuery(ICRCloudStorageProtocol cloudStorage, string query)
 {
     try
     {
         CRCloudMetaData[] array = NSArray.FromArray <CRCloudMetaData>(cloudStorage.SearchWithQuery(query));
         return(array);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         CRCloudMetaData[] metaData = new CRCloudMetaData[] { };
         return(metaData);
     }
 }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            this.NavigationItem.SetLeftBarButtonItem(new UIBarButtonItem(
                                                         UIImage.FromBundle("BackArrow"), UIBarButtonItemStyle.Plain, (sender, args) =>
            {
                NavigationController.PopViewController(true);
            }), true);

            this.Title = selectedService;

            TableView.TableFooterView = new UIView();

            this.NavigationItem.SetRightBarButtonItem(new UIBarButtonItem(
                                                          UIBarButtonSystemItem.Add, (sender, args) =>
            {
                var alert = UIAlertController.Create("Upload File", "Uploads photos to Cloud Ctorage", UIAlertControllerStyle.ActionSheet);

                alert.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, null));
                alert.AddAction(UIAlertAction.Create("Take a Photo", UIAlertActionStyle.Default, action => CameraPhoto()));
                alert.AddAction(UIAlertAction.Create("Choose a Photo", UIAlertActionStyle.Default, action => UploadImage()));
                PresentViewController(alert, animated: true, completionHandler: null);
            }), true);


            activityIndicator        = new UIActivityIndicatorView(UIActivityIndicatorViewStyle.White);
            activityIndicator.Frame  = new CGRect(150, 120, 30, 30);
            activityIndicator.Center = View.Center;
            View.AddSubview(activityIndicator);
            activityIndicator.BringSubviewToFront(View);
            activityIndicator.Color = UIColor.LightGray;
            activityIndicator.StartAnimating();

            cloudStorageLogic = new CloudStorageLogic();

            if (selectedService == "Box")
            {
                cloudStorage = new CRBox("qnskodzvd2naq16xowc40t43fug2848n", "cQE7Sf9DzZqChjvCTxIMTp3ye6hynhTd");
            }
            else if (selectedService == "Dropbox")
            {
                cloudStorage = new CRDropbox("38nu3lwdvyaqs78", "c95g0wfkdv6ua2d");
            }
            else if (selectedService == "Google Drive")
            {
                CRGoogleDrive drive = new CRGoogleDrive("1007170750392-r3p483hu2q02nsp45679dbqsbt9po8h0.apps.googleusercontent.com", "", "com.cloudrail.unifiedcloudstorage:/oauth2redirect", "State");
                drive.UseAdvancedAuthentication();
                cloudStorage = drive;
            }
            else if (selectedService == "One Drive")
            {
                cloudStorage = new CROneDrive("000000004018F12F", "lGQPubehDO6eklir1GQmIuCPFfzwihMo");
            }
            else if (selectedService == "One Drive for Business")
            {
                cloudStorage = new CROneDriveBusiness("", "");
            }
            else if (selectedService == "Egnynte")
            {
                cloudStorage = new CREgnyte("cloudrailcloudtest", "k9y879bha2kmsyyqx4urtnaz", "TsgByd2YZqsJPyYMDhEB6ctAYQ6kP35qYTnEG9urPKq2eNNXRF", "https://www.cloudrailauth.com/auth", "State");
            }

            //First Service Called (delay it by 500 millseconds for Advanced Authentication)
            PerformSelector(new Selector("GetRootFilesFolders"), null, 1.0f);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            this.NavigationItem.SetLeftBarButtonItem(new UIBarButtonItem(
                                                         UIImage.FromBundle("BackArrow"), UIBarButtonItemStyle.Plain, (sender, args) =>
            {
                NavigationController.PopViewController(true);
            }), true);

            this.Title = selectedService;

            TableView.TableFooterView = new UIView();

            this.NavigationItem.SetRightBarButtonItem(new UIBarButtonItem(
                                                          UIBarButtonSystemItem.Add, (sender, args) =>
            {
                var alert = UIAlertController.Create("Upload File", "Uploads photos to Cloud Ctorage", UIAlertControllerStyle.ActionSheet);

                alert.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, null));
                alert.AddAction(UIAlertAction.Create("Take a Photo", UIAlertActionStyle.Default, action => CameraPhoto()));
                alert.AddAction(UIAlertAction.Create("Choose a Photo", UIAlertActionStyle.Default, action => UploadImage()));
                PresentViewController(alert, animated: true, completionHandler: null);
            }), true);


            activityIndicator        = new UIActivityIndicatorView(UIActivityIndicatorViewStyle.White);
            activityIndicator.Frame  = new CGRect(150, 120, 30, 30);
            activityIndicator.Center = View.Center;
            View.AddSubview(activityIndicator);
            activityIndicator.BringSubviewToFront(View);
            activityIndicator.Color = UIColor.LightGray;
            activityIndicator.StartAnimating();

            cloudStorageLogic = new CloudStorageLogic();

            //Setup:
            //https://cloudrail.com/integrations/interfaces/CloudStorage;serviceIds=Box,Dropbox,Egnyte,GoogleDrive,OneDrive,OneDriveBusiness,PCloud;platformId=XamarinIOS;tab=setup

            if (selectedService == "Box")
            {
                cloudStorage = new CRBox("Box Client Identifier", "Box Client Secret");
            }
            else if (selectedService == "Dropbox")
            {
                CRDropbox dropbox = new CRDropbox("Dropbox Client Identifier", "Dropbox Client Secret", "https://auth.cloudrail.com/com.cloudrail.unifiedcloudstorage", "State");
                dropbox.UseAdvancedAuthentication();
                cloudStorage = dropbox;
            }
            else if (selectedService == "Google Drive")
            {
                //NOTE: Only Need Client Identifier
                CRGoogleDrive drive = new CRGoogleDrive("Google Drive Client Identifier", "", "com.cloudrail.unifiedcloudstorage:/oauth2redirect", "State");
                drive.UseAdvancedAuthentication();
                cloudStorage = drive;
            }
            else if (selectedService == "One Drive")
            {
                cloudStorage = new CROneDrive("OneDrive Client Identifier", "OneDrive Client Secret");
            }
            else if (selectedService == "One Drive for Business")
            {
                cloudStorage = new CROneDriveBusiness("OneDrive Business Client Identifier", "OneDrive Business Client Secret");
            }
            else if (selectedService == "Egnynte")
            {
                cloudStorage = new CREgnyte("Your Egnyte Domain", "Your Egnyte API Key", "Your Egnyte Shared Secret", "https://www.cloudrailauth.com/auth", "State");
            }
            else if (selectedService == "PCloud")
            {
                cloudStorage = new CRPCloud("PCloud Client Identifier", "PCloud Client Secret");
            }

            //First Service Called (delay it by 500 millseconds for Advanced Authentication)
            PerformSelector(new Selector("GetRootFilesFolders"), null, 1.0f);
        }