Ejemplo n.º 1
0
        public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
        {
            tableView.DeselectRow(indexPath, true);

            if (indexPath.Section == 1 && indexPath.Row == 0)
            {
                var text = UIPasteboard.General.GetValue(UTType.PlainText)?.ToString()?.Trim();
                if (!string.IsNullOrEmpty(text) && text.Length > 1)
                {
                    if (text[0] == '{' && text[^ 1] == '}')
                    {
                        try
                        {
                            var model = JsonConvert.DeserializeObject <OssConfig>(text);
                            Endpoint.Text        = model.OssEndpoint;
                            BucketName.Text      = model.BucketName;
                            AccessKeyID.Text     = model.AccessKeyId;
                            AccessKeySecret.Text = model.AccessKeySecret;
                            return;
                        }
                        catch
                        {
                            // Ignored.
                        }
                    }
                }

                this.ShowAlert(this.Localize("Online.ClipboardNoData"), this.Localize("Online.PasteManually"));
                return;
            }

            if (indexPath.Section == 3 && indexPath.Row == 0)
            {
                visibility = StorageProviderVisibility.Public;
                ShareCredentialsCell.Accessory = UITableViewCellAccessory.Checkmark;
                StoreCredentialsCell.Accessory = UITableViewCellAccessory.None;
                return;
            }

            if (indexPath.Section == 3 && indexPath.Row == 1)
            {
                visibility = StorageProviderVisibility.Private;
                ShareCredentialsCell.Accessory = UITableViewCellAccessory.None;
                StoreCredentialsCell.Accessory = UITableViewCellAccessory.Checkmark;
                return;
            }
        }
Ejemplo n.º 2
0
 public void ConnectToAzure(Guid cloudId, string name, AzureBlobConfig config, StorageProviderVisibility visibility)
 {
     Globals.CloudService.AddStorageProvider(cloudId.ToString("N"), Guid.NewGuid(), name, config, visibility);
 }
Ejemplo n.º 3
0
        public bool AddStorageProvider(Guid nodeId, string nodeName, AzureBlobConfig azureBlobConfig, StorageProviderVisibility visibility)
        {
            if (string.IsNullOrWhiteSpace(nodeName))
            {
                throw new ArgumentException("The node name is empty", nameof(nodeName));
            }
            if (azureBlobConfig == null)
            {
                throw new ArgumentNullException(nameof(azureBlobConfig));
            }

            lock (StorageProviderInstances)
            {
                if (StorageProviderInstances.Any(x => nodeId.Equals(x.RuntimeId) || string.Equals(x.ProviderInfo.Name, nodeName, StringComparison.InvariantCultureIgnoreCase)))
                {
                    return(false);
                }
                var instance = new StorageProviderInstance_AzureBlob(new StorageProviderInfo {
                    Id         = nodeId,
                    Type       = StorageProviderInstance.TypeAzure,
                    Name       = nodeName,
                    Visibility = visibility,
                    Settings   = JsonConvert.SerializeObject(azureBlobConfig)
                });
                StorageProviderInstances.Add(instance);
                ResyncClientListToStorageProviderInstances();
                return(true);
            }
        }
Ejemplo n.º 4
0
        public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
        {
            tableView.DeselectRow(indexPath, true);

            if (indexPath.Section == 1 && indexPath.Row == 0)
            {
                var text = UIPasteboard.General.GetValue(UTType.PlainText)?.ToString()?.Trim();
                if (!string.IsNullOrEmpty(text) && text.Length > 1)
                {
                    if (text[0] == '{' && text[^ 1] == '}')
                    {
                        try
                        {
                            var model = JsonConvert.DeserializeObject <AzureBlobConfig>(text);
                            text           = model.ConnectionString;
                            Container.Text = model.BlobName;
                        }
                        catch
                        {
                            // Ignored.
                        }
                    }

                    if (Uri.IsWellFormedUriString(text, UriKind.Absolute))
                    {
                        var uri = new Uri(text);
                        EndpointSuffix.Text = uri.GetLeftPart(UriPartial.Path);
                        AccountKey.Text     = uri.Query.Substring(1);
                        Container.Text      = uri.LocalPath.Substring(1);
                        return;
                    }

                    var pairs = new NameValueCollection();
                    foreach (var pair in text.Split(';', StringSplitOptions.RemoveEmptyEntries))
                    {
                        var splitIndex = pair.IndexOf('=', StringComparison.Ordinal);
                        pairs.Add(pair.Substring(0, splitIndex), pair.Substring(splitIndex + 1));
                    }

                    if (pairs["BlobEndpoint"] is { } endpoint&& Uri.IsWellFormedUriString(endpoint, UriKind.Absolute) && pairs["SharedAccessSignature"] is { } sas)
                    {
                        var uri = new Uri(endpoint);
                        EndpointSuffix.Text = uri.GetLeftPart(UriPartial.Path);
                        AccountKey.Text     = sas;
                        Container.Text      = uri.LocalPath.Substring(1);
                        return;
                    }

                    if (pairs["AccountName"] is { } account&& pairs["AccountKey"] is { } key&& pairs["EndpointSuffix"] is { } suffix)
                    {
                        EndpointSuffix.Text = suffix;
                        AccountName.Text    = account;
                        AccountKey.Text     = key;
                        Container.BecomeFirstResponder();
                        return;
                    }
                }
                this.ShowWarning(this.Localize("Online.ClipboardNoData"), this.Localize("Online.PasteManually"));
                return;
            }

            if (indexPath.Section == 3 && indexPath.Row == 0)
            {
                visibility = StorageProviderVisibility.Public;
                ShareCredentialsCell.Accessory = UITableViewCellAccessory.Checkmark;
                StoreCredentialsCell.Accessory = UITableViewCellAccessory.None;
                return;
            }

            if (indexPath.Section == 3 && indexPath.Row == 1)
            {
                visibility = StorageProviderVisibility.Private;
                ShareCredentialsCell.Accessory = UITableViewCellAccessory.None;
                StoreCredentialsCell.Accessory = UITableViewCellAccessory.Checkmark;
                return;
            }
        }
Ejemplo n.º 5
0
        public bool AddStorageProvider(string cloudId, Guid nodeId, string nodeName, AzureBlobConfig azureConfig, StorageProviderVisibility visibility, bool saveChanges = true)
        {
            PersonalCloud personalCloud = null;

            lock (_PersonalClouds)
            {
                personalCloud = _PersonalClouds.FirstOrDefault(x => x.Id == cloudId);
            }

            if (personalCloud != null)
            {
                var haveChanges = personalCloud.AddStorageProvider(nodeId, nodeName, azureConfig, visibility);
                if (haveChanges && saveChanges)
                {
                    SavePCList();
                }
                return(haveChanges);
            }
            else
            {
                throw new NoSuchCloudException();
            }
        }