private async void _hubConnection_StateChanged(StateChange obj)
        {
            if (obj.NewState == ConnectionState.Connected)
            {
                _dialog?.Dispose();
                _dialog = null;

                if (_autoLoginUser != null)
                {
                    await CreateOrUpdateAsync(_autoLoginUser);

                    _autoLoginUser = null;

                    if (Settings.LoginUser != null)
                    {
                        await NavigationService.Navigate <MenuViewModel>();
                    }
                }
            }
            else
            {
                if (_viewAppeared)
                {
                    _dialog?.Dispose();
                    _dialog = UserDialogs.Instance.Loading("接続中");
                }
            }
        }
Esempio n. 2
0
 public async Task HideLoadingAsync()
 {
     if (_Progress == null)
     {
         return;
     }
     _Progress.Hide();
     _Progress.Dispose();
     _Progress = null;
 }
Esempio n. 3
0
        void OnNewProfileRead(bool isSuccessful, int profileId, string name)
        {
            if (!isSuccessful)
            {
                throw new InvalidOperationException("Failed to get profile name!");
            }

            _progressDialog.PercentComplete = (int)Math.Round(100 * profileId / (double)_profilesCount);

            _enumeratedProfiles.Add(new Profile()
            {
                Id = profileId, Name = name
            });

            var nextProfileId = profileId + 1;

            if (nextProfileId < _profilesCount)
            {
                // Continuing enumeration
                _getProfileNameCommand.SendGetProfileNameCommand(nextProfileId);
                return;
            }

            // Enumeration completed
            _progressDialog.Dispose();
            _onFoxProfilesEnumerated(_enumeratedProfiles);
        }
Esempio n. 4
0
        async Task ExecuteTapQueueMessageCommandAsync(CloudQueueMessage queueMessage)
        {
            if (queueMessage == null)
            {
                return;
            }

            MessagingService.Current.Subscribe <MessageArgsDeleteQueueMessage>(MessageKeys.DeleteQueueMessage, async(m, argsDeleteQueueMessage) =>
            {
                Navigation.PopAsync();
                IProgressDialog deletingDialog = UserDialogs.Loading("Deleting Queue Message");
                deletingDialog.Show();
                try
                {
                    var message = QueueMessages.Where(qm => qm.Id == argsDeleteQueueMessage.QueueId).FirstOrDefault();

                    if (message == null)
                    {
                        return;
                    }

                    await Queue.BaseQueue.DeleteMessageAsync(message);
                    App.Logger.Track(AppEvent.DeleteQueueMessage.ToString());

                    QueueMessages.Remove(message);
                    QueueMessageCount--;


                    SortQueueMessages();
                }
                catch (Exception ex)
                {
                    Logger.Report(ex, "Method", "HandleMessageArgsDeleteQueueMessage");
                    MessagingService.Current.SendMessage(MessageKeys.Error, ex);
                }
                finally
                {
                    if (deletingDialog != null)
                    {
                        if (deletingDialog.IsShowing)
                        {
                            deletingDialog.Hide();
                        }
                        deletingDialog.Dispose();
                    }
                }
            });

            try
            {
                var queueMessageDetailsPage = new QueueMessageDetailsPage(queueMessage, queue);

                App.Logger.TrackPage(AppPage.QueueMessageDetails.ToString());
                await NavigationService.PushAsync(Navigation, queueMessageDetailsPage);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Ex: " + ex.Message);
            }
        }
        async Task ExecuteTapFileShareCommandAsync(ASECloudFileShare fileShare)
        {
            if (fileShare == null)
            {
                return;
            }


            MessagingService.Current.Subscribe <MessageArgsDeleteFileShare>(MessageKeys.DeleteFileShare, async(m, argsDeleteFileShare) =>
            {
                Navigation.PopAsync();
                IProgressDialog deletingDialog = UserDialogs.Loading("Deleting FileShare");
                deletingDialog.Show();
                try
                {
                    var aseFileShare = FileShares.Where(fs => fs.FileShareName == argsDeleteFileShare.FileShareName &&
                                                        fs.StorageAccountName == argsDeleteFileShare.StorageAccountName).FirstOrDefault();
                    if (aseFileShare == null)
                    {
                        return;
                    }

                    await aseFileShare.BaseFileShare.DeleteAsync();

                    App.Logger.Track(AppEvent.DeleteFileShare.ToString());

                    FileShares.Remove(aseFileShare);
                    SortFileShares();
                    var realm = App.GetRealm();
                    await realm.WriteAsync(temprealm =>
                    {
                        temprealm.Remove(temprealm.All <RealmCloudFileShare>()
                                         .Where(fs => fs.FileShareName == argsDeleteFileShare.FileShareName &&
                                                fs.StorageAccountName == argsDeleteFileShare.StorageAccountName).First());
                    });
                }
                catch (Exception ex)
                {
                    Logger.Report(ex, "Method", "HandleMessageArgsDeleteFileShare");
                    MessagingService.Current.SendMessage(MessageKeys.Error, ex);
                }
                finally
                {
                    if (deletingDialog != null)
                    {
                        if (deletingDialog.IsShowing)
                        {
                            deletingDialog.Hide();
                        }
                        deletingDialog.Dispose();
                    }
                }
            });

            var filesPage = new FilesPage(fileShare);

            App.Logger.TrackPage(AppPage.Files.ToString());
            await NavigationService.PushAsync(Navigation, filesPage);
        }
Esempio n. 6
0
 public async Task HideLoadingAsync()
 {
     try
     {
         if (_Progress == null)
         {
             return;
         }
         _Progress.Hide();
         _Progress.Dispose();
         _Progress = null;
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine(string.Format("*** DialogService.HideLoadingAsync - Exception: {0}", ex));
     }
 }
Esempio n. 7
0
        async Task ExecuteTapContainerCommandAsync(ASECloudBlobContainer container)
        {
            if (container == null)
            {
                return;
            }
            MessagingService.Current.Subscribe <MessageArgsDeleteContainer>(MessageKeys.DeleteContainer, async(m, argsDeleteContainer) =>
            {
                Console.WriteLine("Delete containerX: " + argsDeleteContainer.ContainerName);
                Navigation.PopAsync();
                IProgressDialog deletingDialog = UserDialogs.Loading("Deleting Container");
                deletingDialog.Show();
                try
                {
                    var aseContainer = Containers.Where(c => c.ContainerName == argsDeleteContainer.ContainerName &&
                                                        c.StorageAccountName == argsDeleteContainer.StorageAccountName).FirstOrDefault();
                    if (aseContainer == null)
                    {
                        return;
                    }

                    await aseContainer.BaseContainer.DeleteAsync();

                    App.Logger.Track(AppEvent.DeleteContainer.ToString());

                    Containers.Remove(aseContainer);
                    SortContainers();
                    var realm = App.GetRealm();
                    await realm.WriteAsync(temprealm =>
                    {
                        temprealm.Remove(temprealm.All <RealmCloudBlobContainer>()
                                         .Where(c => c.ContainerName == argsDeleteContainer.ContainerName &&
                                                c.StorageAccountName == argsDeleteContainer.StorageAccountName).First());
                    });
                }
                catch (Exception ex)
                {
                    Logger.Report(ex, "Method", "HandleMessageArgsDeleteContainer");
                    MessagingService.Current.SendMessage(MessageKeys.Error, ex);
                }
                finally
                {
                    if (deletingDialog != null)
                    {
                        if (deletingDialog.IsShowing)
                        {
                            deletingDialog.Hide();
                        }
                        deletingDialog.Dispose();
                    }
                }
            });

            var blobsPage = new BlobsPage(container);

            App.Logger.TrackPage(AppPage.Blobs.ToString());
            await NavigationService.PushAsync(Navigation, blobsPage);
        }
Esempio n. 8
0
 public static bool TryConnectFinish()
 {
     if (progress != null)
     {
         progress.Dispose();
         progress = null;
     }
     return(true);
 }
Esempio n. 9
0
        async Task ExecuteTapContainerCommandAsync(ASECloudTable table)
        {
            if (table == null)
            {
                return;
            }

            MessagingService.Current.Subscribe <MessageArgsDeleteTable>(MessageKeys.DeleteTable, async(m, argsDeleteTable) =>
            {
                Navigation.PopAsync();
                IProgressDialog deletingDialog = UserDialogs.Loading("Deleting Table");
                deletingDialog.Show();
                try
                {
                    var aseTable = Tables.Where(t => t.TableName == argsDeleteTable.TableName &&
                                                t.StorageAccountName == argsDeleteTable.StorageAccountName).FirstOrDefault();
                    if (aseTable == null)
                    {
                        return;
                    }
                    await aseTable.BaseTable.DeleteIfExistsAsync();
                    App.Logger.Track(AppEvent.DeleteTable.ToString());
                    Tables.Remove(aseTable);
                    SortTables();
                    var realm = App.GetRealm();
                    await realm.WriteAsync(temprealm =>
                    {
                        temprealm.Remove(temprealm.All <RealmCloudTable>()
                                         .Where(t => t.TableName == argsDeleteTable.TableName &&
                                                t.StorageAccountName == argsDeleteTable.StorageAccountName).First());
                    });
                }
                catch (Exception ex)
                {
                    Logger.Report(ex, "Method", "HandleMessageArgsDeleteTable");
                    MessagingService.Current.SendMessage(MessageKeys.Error, ex);
                }
                finally
                {
                    if (deletingDialog != null)
                    {
                        if (deletingDialog.IsShowing)
                        {
                            deletingDialog.Hide();
                        }
                        deletingDialog.Dispose();
                    }
                }
            });

            var tableRowsPage = new TableRowsPage(table);

            App.Logger.TrackPage(AppPage.TableRows.ToString());
            await testPage.Navigation.PushAsync(tableRowsPage);
        }
        /// <summary>
        /// milliseconds 秒経っても task が完了しない場合、Loading ダイアログを完了まで表示
        /// </summary>
        public static Task <T> LoadingDelayedAsync <T>(this IUserDialogs instance, Task <T> task, CancellationTokenSource source, string title = "", string cancelText = null, Action onCancel = null, int milliseconds = 500)
        {
            var canCancel = source != null;

            if (!canCancel)
            {
                source = new CancellationTokenSource(); // dummy
            }
            IProgressDialog dialog = null;

            return(Task.Run(async() =>
            {
                // delay
                var t = 0.0;
                while (t < milliseconds)
                {
                    await Task.Delay(TimeSpan.FromMilliseconds(100));
                    if (task.IsCompleted || task.IsFaulted || (source?.Token.IsCancellationRequested ?? false))
                    {
                        return await task;
                    }

                    t += 100;
                }

                // show
                dialog = canCancel ?
                         instance.Loading(title, () => { source?.Cancel(true); onCancel?.Invoke(); }, cancelText) :
                         instance.Loading(title);

                // wait
                return await task;
            }, source.Token).ContinueWith(t =>
            {
                dialog?.Hide();
                dialog?.Dispose();

                return t.Result;
            }, source.Token).ContinueWith(t =>
            {
                if (t.IsCanceled)
                {
                    return default(T);
                }

                if (t.IsFaulted)
                {
                    // show error
                    UserDialogs.Instance.Alert(t.Exception);
                    return default(T);
                }
                return t.Result;
            }, source.Token));
        }
Esempio n. 11
0
        private async Task OnGetAntennaMatchingDataAsync(int matcherPosition, float antennaVoltage)
        {
            MainModel.MatchingModel.MatchingData.Add(antennaVoltage);

            if (matcherPosition < MainModel.MatchingModel.MatchingPositionsCount - 1)
            {
                _progressDialog.PercentComplete = (int)Math.Round(100 * matcherPosition / (double)MainModel.MatchingModel.MatchingPositionsCount);
                await _antennaMatchingManager.GetAntennaMatchingDataAsync(matcherPosition + 1, async (p, v) => await OnGetAntennaMatchingDataAsync(p, v));

                return;
            }

            _progressDialog.Dispose();
            RedrawMatchingGraph();
        }
Esempio n. 12
0
        async Task ExecuteTapFileCommandAsync(IListFileItem fileItem)
        {
            if (fileItem == null)
            {
                return;
            }

            MessagingService.Current.Subscribe <MessageArgsDeleteFile>(MessageKeys.DeleteFile, async(m, argsDeleteFile) =>
            {
                Navigation.PopAsync();
                IProgressDialog deletingDialog = UserDialogs.Loading("Deleting File");
                deletingDialog.Show();
                try
                {
                    var file = Files.Where(f => f.Share.Name == argsDeleteFile.FileName).FirstOrDefault();
                    if (file == null)
                    {
                        return;
                    }
                    await FileShare.BaseFileShare.GetRootDirectoryReference().GetFileReference(file.Share.Name).DeleteAsync();

                    App.Logger.Track(AppEvent.DeleteFile.ToString());
                    Files.Remove(file);
                    FileAndDirectoryCount--;
                    SortFiles();
                }
                catch (Exception ex)
                {
                    Logger.Report(ex, "Method", "HandleMessageArgsDeleteFile");
                    MessagingService.Current.SendMessage(MessageKeys.Error, ex);
                }
                finally
                {
                    if (deletingDialog != null)
                    {
                        if (deletingDialog.IsShowing)
                        {
                            deletingDialog.Hide();
                        }
                        deletingDialog.Dispose();
                    }
                }
            });
        }
        async Task ExecuteCreateTableAsync()
        {
            if (IsBusy)
            {
                return;
            }

            if (!ReadyToSave)
            {
                Logger.Report(new Exception("Create table called when ReadyToSave was false"), "Method", "ExecuteCreateTableAsync");
                return;
            }
            if (tableName.Length < 3 || tableName.Length > 63 ||
                !Regex.IsMatch(tableName, @"^[A-Za-z][A-Za-z0-9]*$"))
            {
                MessagingService.Current.SendMessage <MessagingServiceAlert>(MessageKeys.Message, new MessagingServiceAlert
                {
                    Title   = "Table name is invalid",
                    Message = "Table names must be between 3 and 63 chars, only contain letters and numbers, and start with a letter.",
                    Cancel  = "OK"
                });
                return;
            }
            IProgressDialog savingDialog = UserDialogs.Loading("Saving Table");

            savingDialog.Show();
            try
            {
                IsBusy = true;
                string connectionString = Constants.StorageConnectionString;
                connectionString = connectionString.Replace("<ACCOUNTNAME>", SelectedStorageAccount.Name);
                connectionString = connectionString.Replace("<ACCOUNTKEY>", SelectedStorageAccount.PrimaryKey);
                CloudStorageAccount sa = CloudStorageAccount.Parse(connectionString);
                var        tableClient = sa.CreateCloudTableClient();
                CloudTable table       = tableClient.GetTableReference(tableName);
                if (table == null)
                {
                    Console.WriteLine("Table is null");
                }
                if (await table.ExistsAsync())
                {
                    MessagingService.Current.SendMessage <MessagingServiceAlert>(MessageKeys.Message, new MessagingServiceAlert
                    {
                        Title   = "Table Exists",
                        Message = "A table with the name \"" + TableName + "\" already exists in this storage account.",
                        Cancel  = "OK"
                    });
                    return;
                }
                else
                {
                    await table.CreateAsync();

                    var realm = App.GetRealm();
                    var storageAccountName = selectedStorageAccount.Name;
                    realm.Write(() =>
                    {
                        realm.Add(new RealmCloudTable(table.Name,
                                                      selectedStorageAccount.Name,
                                                      table.Uri.ToString()));
                    });
                    if (tablesVM != null)
                    {
                        tablesVM.AddTable(new ASECloudTable(table, selectedStorageAccount.Name));
                        App.Logger.Track(AppEvent.CreatedTable.ToString());
                    }
                    //This is here and in finally so we'll dismiss this before popping the page so the
                    //Loader doesn't stay longer than the popup
                    if (savingDialog != null)
                    {
                        if (savingDialog.IsShowing)
                        {
                            savingDialog.Hide();
                        }
                        savingDialog.Dispose();
                    }
                    await PopupNavigation.PopAsync();
                }
            }
            catch (Exception ex)
            {
                Logger.Report(ex, "Method", "ExecuteCreateTableAsync");
                MessagingService.Current.SendMessage(MessageKeys.Error, ex);
            }
            finally
            {
                IsBusy = false;
                if (savingDialog != null)
                {
                    if (savingDialog.IsShowing)
                    {
                        savingDialog.Hide();
                    }
                    savingDialog.Dispose();
                }
            }
            return;
        }
        async Task ExecuteCreateQueueMessageAsync()
        {
            if (IsBusy)
            {
                return;
            }

            if (!ReadyToSave)
            {
                //This should never happen as the save button should be disabled
                Logger.Report(new Exception("Create Queue Message called when ReadyToSave was false"), "Method", "ExecuteCreateQueueMessageAsync");
                return;
            }

            //Messages must expire in 1 second to 7 days
            //Calculate time to live
            TimeSpan?messageTTL = null;

            switch (SelectedExpirationTimePeriod)
            {
            case "Days":
                messageTTL = new TimeSpan(ExpiresInTime, 0, 0, 0);
                break;

            case "Hours":
                messageTTL = new TimeSpan(0, ExpiresInTime, 0, 0);
                break;

            case "Minutes":
                messageTTL = new TimeSpan(0, 0, ExpiresInTime, 0);
                break;

            case "Seconds":
                messageTTL = new TimeSpan(0, 0, 0, ExpiresInTime);
                break;
            }
            if (messageTTL < MinimumExpirationtime || messageTTL > MaximumExpirationtime)
            {
                MessagingService.Current.SendMessage <MessagingServiceAlert>(MessageKeys.Message, new MessagingServiceAlert
                {
                    Title   = "Expiration time is invalid",
                    Message = "Messages must expire in no less than 1 second and no more than 7 days.",
                    Cancel  = "OK"
                });
                return;
            }

            IProgressDialog savingDialog = UserDialogs.Loading("Saving Queue Message");

            savingDialog.Show();

            try
            {
                IsBusy = true;
                var newMessage = new CloudQueueMessage(MessageText);
                await queueMessagesViewModel.Queue.BaseQueue.AddMessageAsync(newMessage, messageTTL, null, null, null);

                if (queueMessagesViewModel != null)
                {
                    queueMessagesViewModel.AddQueueMessage(newMessage);
                    App.Logger.Track(AppEvent.CreatedQueueMessage.ToString());
                }
                //This is here and in finally so we'll dismiss this before popping the page so the
                //Loader doesn't stay longer than the popup
                if (savingDialog != null)
                {
                    if (savingDialog.IsShowing)
                    {
                        savingDialog.Hide();
                    }
                    savingDialog.Dispose();
                }

                await PopupNavigation.PopAsync();
            }
            catch (Exception ex)
            {
                Logger.Report(ex, "Method", "ExecuteCreateQueueMessageAsync");
                MessagingService.Current.SendMessage(MessageKeys.Error, ex);
            }
            finally
            {
                IsBusy = false;
                if (savingDialog != null)
                {
                    if (savingDialog.IsShowing)
                    {
                        savingDialog.Hide();
                    }
                    savingDialog.Dispose();
                }
            }
            return;
        }
Esempio n. 15
0
        async Task ExecuteAddBlobCommandAsync()
        {
            if (IsBusy)
            {
                return;
            }

            IProgressDialog savingDialog = null;

            try
            {
                //Check for Storage Permissions
                var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Storage);

                if (status != PermissionStatus.Granted)
                {
                    if (await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(Permission.Location))
                    {
                        MessagingService.Current.SendMessage <MessagingServiceAlert>(MessageKeys.Message, new MessagingServiceAlert
                        {
                            Title   = "Need storage access",
                            Message = "In order to upload new blobs, we need access to your phone's storage.",
                            Cancel  = "OK"
                        });
                    }

                    var results = await CrossPermissions.Current.RequestPermissionsAsync(new[] { Permission.Storage });

                    status = results[Permission.Storage];
                }

                if (status == PermissionStatus.Granted)
                {
                    var result = await DependencyService.Get <IFilePicker>().PickFile();

                    if (result != null)
                    {
                        savingDialog = UserDialogs.Loading("Saving Blob");
                        savingDialog.Show();

                        var blob = Container.BaseContainer.GetBlockBlobReference(result.FileName);
                        if (await blob.ExistsAsync())
                        {
                            savingDialog.Hide();
                            MessagingService.Current.SendMessage <MessagingServiceQuestion>(MessageKeys.Question, new MessagingServiceQuestion
                            {
                                Negative    = "No",
                                Positive    = "Yes",
                                Question    = "A blob with the same name already exists in this Container, would you like to overwrite?",
                                Title       = "Overwrite blob?",
                                OnCompleted = (async(questionResult) =>
                                {
                                    if (questionResult)
                                    {
                                        try
                                        {
                                            savingDialog.Show();
                                            await blob.FetchAttributesAsync();
                                            byteCount -= blob.Properties.Length;
                                            await blob.UploadFromByteArrayAsync(result.DataArray, 0, result.DataArray.Length);
                                            byteCount += blob.Properties.Length;
                                            TotalBlobSize = FileSizeHelper.GetHumanizedSizeFromBytes(byteCount);
                                            App.Logger.Track(AppEvent.OverwriteBlob.ToString());
                                        }
                                        catch (Exception ex)
                                        {
                                            Logger.Report(ex);
                                            MessagingService.Current.SendMessage <MessagingServiceAlert>(MessageKeys.Message, new MessagingServiceAlert
                                            {
                                                Title = "Unable to Overwrite Blob",
                                                Message = "There was an issue trying to overwrite blob in storage.  Please try again.",
                                                Cancel = "OK"
                                            });
                                        }
                                        finally
                                        {
                                            if (savingDialog != null)
                                            {
                                                if (savingDialog.IsShowing)
                                                {
                                                    savingDialog.Hide();
                                                }
                                                savingDialog.Dispose();
                                            }
                                        }
                                    }
                                }
                                               )
                            });
                        }
                        else
                        {
                            await blob.UploadFromByteArrayAsync(result.DataArray, 0, result.DataArray.Length);

                            App.Logger.Track(AppEvent.CreatedBlob.ToString());

                            Blobs.Add((CloudBlob)blob);
                            byteCount += blob.Properties.Length;

                            BlobCount     = Blobs.Count.ToString();
                            TotalBlobSize = FileSizeHelper.GetHumanizedSizeFromBytes(byteCount);

                            SortBlobs();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Report(ex);
                MessagingService.Current.SendMessage <MessagingServiceAlert>(MessageKeys.Message, new MessagingServiceAlert
                {
                    Title   = "Unable to Save Blob",
                    Message = "There was an issue trying to save to blob storage.  Please try again.",
                    Cancel  = "OK"
                });
            }
            finally
            {
                if (savingDialog != null)
                {
                    if (savingDialog.IsShowing)
                    {
                        savingDialog.Hide();
                    }
                    savingDialog.Dispose();
                }
            }
        }
Esempio n. 16
0
        async Task ExecuteTapBlobCommandAsync(CloudBlob blob)
        {
            if (blob == null)
            {
                return;
            }

            MessagingService.Current.Subscribe <MessageArgsDeleteBlob>(MessageKeys.DeleteBlob, async(m, argsDeleteBlob) =>
            {
                Navigation.PopAsync();
                IProgressDialog deletingDialog = UserDialogs.Loading("Deleting Blob");
                deletingDialog.Show();
                try
                {
                    var aseBlob = Blobs.Where(b => b.Name == argsDeleteBlob.BlobName &&
                                              b.Container.Name == argsDeleteBlob.ContainerName).FirstOrDefault();
                    if (aseBlob == null)
                    {
                        return;
                    }
                    await aseBlob.DeleteAsync();

                    App.Logger.Track(AppEvent.DeleteBlob.ToString());

                    Blobs.Remove(aseBlob);

                    byteCount    -= aseBlob.Properties.Length;
                    BlobCount     = Blobs.Count.ToString();
                    TotalBlobSize = FileSizeHelper.GetHumanizedSizeFromBytes(byteCount);

                    SortBlobs();
                }
                catch (Exception ex)
                {
                    Logger.Report(ex, "Method", "HandleMessageArgsDeleteBlob");
                    MessagingService.Current.SendMessage(MessageKeys.Error, ex);
                }
                finally
                {
                    if (deletingDialog != null)
                    {
                        if (deletingDialog.IsShowing)
                        {
                            deletingDialog.Hide();
                        }
                        deletingDialog.Dispose();
                    }
                }
            });

            try
            {
                var blobDetailsPage = new BlobDetailsPage(blob);

                App.Logger.TrackPage(AppPage.BlobDetails.ToString());
                await NavigationService.PushAsync(Navigation, blobDetailsPage);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Ex: " + ex.Message);
            }
        }
Esempio n. 17
0
 private void DisposeLoading()
 {
     _loading?.Dispose();
     _loading = null;
 }
Esempio n. 18
0
 /// <inheritdoc />
 public void HideLoadingDialog()
 {
     currentProgressDialog?.Dispose();
 }
Esempio n. 19
0
        async Task ExecuteCreateContainerAsync()
        {
            if (IsBusy)
            {
                return;
            }

            if (!ReadyToSave)
            {
                //This should never happen as the save button should be disabled
                Logger.Report(new Exception("Create container called when ReadyToSave was false"), "Method", "ExecuteCreateContainerAsync");
                return;
            }

            if (containerName.Length < 3 || containerName.Length > 63 ||
                !Regex.IsMatch(containerName, @"^[a-z0-9]+(-[a-z0-9]+)*$"))
            {
                MessagingService.Current.SendMessage <MessagingServiceAlert>(MessageKeys.Message, new MessagingServiceAlert
                {
                    Title   = "Container name is invalid",
                    Message = "Container names must be between 3 and 63 chars, only contain lowercase letters, numbers, and hyphens, must begin with a number or letter, must not contain consecutive hyphens, or end with a hyphen.",
                    Cancel  = "OK"
                });
                return;
            }

            IProgressDialog savingDialog = UserDialogs.Loading("Saving Container");

            savingDialog.Show();

            try
            {
                IsBusy = true;
                string connectionString = Constants.StorageConnectionString;
                connectionString = connectionString.Replace("<ACCOUNTNAME>", SelectedStorageAccount.Name);
                connectionString = connectionString.Replace("<ACCOUNTKEY>", SelectedStorageAccount.PrimaryKey);

                CloudStorageAccount sa = CloudStorageAccount.Parse(connectionString);
                var blobClient         = sa.CreateCloudBlobClient();

                CloudBlobContainer container = blobClient.GetContainerReference(ContainerName);
                if (container == null)
                {
                    Console.WriteLine("Container is null");
                }
                if (await container.ExistsAsync())
                {
                    MessagingService.Current.SendMessage <MessagingServiceAlert>(MessageKeys.Message, new MessagingServiceAlert
                    {
                        Title   = "Container Exists",
                        Message = "A container with the name \"" + ContainerName + "\" already exists in this storage account.",
                        Cancel  = "OK"
                    });
                    return;
                }
                else
                {
                    await container.CreateAsync();

                    if (SelectedAccessType != "Private")
                    {
                        if (SelectedAccessType == "Container")
                        {
                            await container.SetPermissionsAsync(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Container });
                        }
                        else if (SelectedAccessType == "Blob")
                        {
                            await container.SetPermissionsAsync(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob });
                        }
                    }
                    var realm = App.GetRealm();
                    var storageAccountName = selectedStorageAccount.Name;

                    realm.Write(() =>
                    {
                        realm.Add(new RealmCloudBlobContainer(container.Name,
                                                              selectedStorageAccount.Name,
                                                              container.Uri.ToString()));
                    });

                    if (containersVM != null)
                    {
                        containersVM.AddContainer(new ASECloudBlobContainer(container, selectedStorageAccount.Name));
                        App.Logger.Track(AppEvent.CreatedContainer.ToString());
                    }

                    //This is here and in finally so we'll dismiss this before popping the page so the
                    //Loader doesn't stay longer than the popup
                    if (savingDialog != null)
                    {
                        if (savingDialog.IsShowing)
                        {
                            savingDialog.Hide();
                        }
                        savingDialog.Dispose();
                    }

                    await PopupNavigation.PopAsync();
                }
            }
            catch (Exception ex)
            {
                Logger.Report(ex, "Method", "ExecuteCreateContainerAsync");
                MessagingService.Current.SendMessage(MessageKeys.Error, ex);
            }
            finally
            {
                IsBusy = false;
                if (savingDialog != null)
                {
                    if (savingDialog.IsShowing)
                    {
                        savingDialog.Hide();
                    }
                    savingDialog.Dispose();
                }
            }
            return;
        }