Ejemplo n.º 1
0
        public async Task <bool> UpdateAppInfo(AppInfo appInfo)
        {
            try
            {
                CloudTable appInfoTable = tableClient.GetTableReference(AppInfoTableName);

                // すでにデータが保存されているかどうかチェック
                TableOperation retrieveOperation = TableOperation.Retrieve <AppInfoEntity>(appInfo.Name, "");
                TableResult    retrievedResult   = await appInfoTable.ExecuteAsync(retrieveOperation);

                AppInfoEntity appInfoEntry = (AppInfoEntity)retrievedResult.Result;

                if (appInfoEntry == null)
                {
                    return(false);
                }
                else
                {
                    appInfoEntry.Description = appInfo.Description;
                    appInfoEntry.Developer   = appInfo.DeveloperName;

                    TableOperation insertOperation = TableOperation.InsertOrReplace(appInfoEntry);
                    var            result          = await appInfoTable.ExecuteAsync(insertOperation);

                    return(true);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                return(false);
            }
        }
Ejemplo n.º 2
0
        public async Task <bool> Delete(AppInfo appInfo)
        {
            // appinfo テーブルにパッケージのデータを保存
            try
            {
                CloudTable appInfoTable = tableClient.GetTableReference(AppInfoTableName);

                // すでにデータが保存されているかどうかチェック
                TableOperation retrieveOperation = TableOperation.Retrieve <AppInfoEntity>(appInfo.Name, "");
                TableResult    retrievedResult   = await appInfoTable.ExecuteAsync(retrieveOperation);

                AppInfoEntity deleteAppInfoEntity = (AppInfoEntity)retrievedResult.Result;

                if (deleteAppInfoEntity == null)
                {
                    return(false);
                }

                // バージョンごとに削除
                if (deleteAppInfoEntity.AppVersions != null)
                {
                    foreach (var version in deleteAppInfoEntity.AppVersions)
                    {
                        await DeleteApplication(appInfo.Name, version.ToString());
                    }
                }

                retrievedResult = await appInfoTable.ExecuteAsync(retrieveOperation);

                deleteAppInfoEntity = (AppInfoEntity)retrievedResult.Result;

                if (deleteAppInfoEntity == null)
                {
                    return(false);
                }
                // AppInfo を削除
                TableOperation deleteOperation = TableOperation.Delete(deleteAppInfoEntity);
                await appInfoTable.ExecuteAsync(deleteOperation);

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                return(false);
            }
        }
Ejemplo n.º 3
0
        public async Task <(AppInfo appInfo, UploadStatusType status)> Upload(Application application)
        {
            try
            {
                // Blob にパッケージを保存
                CloudBlobContainer container = blobClient.GetContainerReference(PackageContainerName);
                await container.CreateIfNotExistsAsync();

                var            appPackageName   = GetAppPackageName(application);
                var            appPackageId     = $"{appPackageName}_{application.AppPackage.Name}";
                CloudBlockBlob blockBlob_upload = container.GetBlockBlobReference(appPackageId);
                await blockBlob_upload.UploadFromFileAsync(application.AppPackage);

                // 依存ファイルを保存
                var dependencyIds = new List <string>();
                foreach (var dep in application.Dependencies)
                {
                    var parent       = System.IO.Directory.GetParent(dep.Path);
                    var architecture = SupportedArchitectureHelper.StringToSupportedArchitectureType(parent.Name);
                    var dependencyId = $"{appPackageName}_{architecture}_{dep.Name}";
                    dependencyIds.Add(dependencyId);
                    CloudBlockBlob depBlockBlob = container.GetBlockBlobReference(dependencyId);
                    await depBlockBlob.UploadFromFileAsync(dep);
                }

                // Table にバージョンごとのパッケージのデータを保存
                {
                    CloudTable table = tableClient.GetTableReference(PackageContainerName);
                    await table.CreateIfNotExistsAsync();

                    // Create the TableOperation object that inserts the customer entity.
                    var appPackageEntity = new AppPackageEntity(application.Name, application.Version.ToString())
                    {
                        Developer             = application.DeveloperName,
                        Name                  = application.Name,
                        AppVersion            = application.Version,
                        AppPackageId          = appPackageId,
                        DependencyIds         = dependencyIds,
                        SupportedArchitecture = application.SupportedArchitecture
                    };
                    TableOperation insertOperation = TableOperation.InsertOrReplace(appPackageEntity);
                    // Execute the insert operation.
                    await table.ExecuteAsync(insertOperation);
                }

                var     isNewlyUploaded = true;
                AppInfo appInfo;

                // appinfo テーブルにパッケージのデータを保存
                {
                    CloudTable appInfoTable = tableClient.GetTableReference(AppInfoTableName);
                    await appInfoTable.CreateIfNotExistsAsync();

                    // SupportedArchitecture は最新のものに設定
                    var appInfoEntry = new AppInfoEntity(application.Name)
                    {
                        Description           = "",
                        Developer             = application.DeveloperName,
                        SupportedArchitecture = application.SupportedArchitecture
                    };

                    // すでにデータが保存されているかどうかチェック
                    TableOperation retrieveOperation = TableOperation.Retrieve <AppInfoEntity>(application.Name, "");
                    TableResult    retrievedResult   = await appInfoTable.ExecuteAsync(retrieveOperation);

                    AppInfoEntity updateEntity = (AppInfoEntity)retrievedResult.Result;

                    if (updateEntity == null)
                    {
                        appInfoEntry.CreateAt = DateTime.Now;
                    }
                    else
                    {
                        appInfoEntry.CreateAt    = updateEntity.CreateAt;
                        appInfoEntry.Description = updateEntity.Description;
                        appInfoEntry.AppVersions = updateEntity.AppVersions;
                        isNewlyUploaded          = false;
                    }

                    if (appInfoEntry.AppVersions == null)
                    {
                        appInfoEntry.AppVersions = new HashSet <AppVersion>();
                    }
                    appInfoEntry.AppVersions.Add(application.Version);

                    TableOperation insertOperation = TableOperation.InsertOrReplace(appInfoEntry);
                    await appInfoTable.ExecuteAsync(insertOperation);

                    appInfo = appInfoEntry.ConvertToAppInfo();
                }

                if (isNewlyUploaded)
                {
                    return(appInfo, UploadStatusType.NewlyUploaded);
                }
                else
                {
                    return(appInfo, UploadStatusType.Updated);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                return(null, UploadStatusType.NetworkError);
            }
        }
Ejemplo n.º 4
0
        public async Task <bool> DeleteApplication(string appName, string version)
        {
            try
            {
                Application application;
                // Application の情報を取得
                {
                    CloudTable     table             = tableClient.GetTableReference(PackageContainerName);
                    TableOperation retrieveOperation = TableOperation.Retrieve <AppPackageEntity>(appName, version);

                    // Execute the retrieve operation.
                    TableResult retrievedResult = await table.ExecuteAsync(retrieveOperation);

                    // Print the phone number of the result.
                    if (retrievedResult.Result == null)
                    {
                        return(false);
                    }
                    var appPackageEntity = (AppPackageEntity)retrievedResult.Result;
                    application = appPackageEntity.ConvertToApplication();
                }


                // appinfo テーブルからパッケージの情報を削除
                {
                    CloudTable appInfoTable = tableClient.GetTableReference(AppInfoTableName);

                    // すでにデータが保存されているかどうかチェック
                    TableOperation retrieveOperation = TableOperation.Retrieve <AppInfoEntity>(application.Name, "");
                    TableResult    retrievedResult   = await appInfoTable.ExecuteAsync(retrieveOperation);

                    AppInfoEntity appInfoEntity = (AppInfoEntity)retrievedResult.Result;

                    if (appInfoEntity != null)
                    {
                        appInfoEntity.AppVersions?.Remove(application.Version);
                        TableOperation insertOperation = TableOperation.InsertOrReplace(appInfoEntity);
                        await appInfoTable.ExecuteAsync(insertOperation);
                    }
                }

                // バージョンごとのパッケージのデータを削除
                {
                    CloudTable appPackageTable = tableClient.GetTableReference(PackageContainerName);

                    TableOperation retrieveOperation = TableOperation.Retrieve <AppPackageEntity>(application.Name, application.Version.ToString());
                    TableResult    retrievedResult   = await appPackageTable.ExecuteAsync(retrieveOperation);

                    AppPackageEntity appPackageEntity = (AppPackageEntity)retrievedResult.Result;

                    if (appPackageEntity != null)
                    {
                        TableOperation deleteOperation = TableOperation.Delete(appPackageEntity);
                        await appPackageTable.ExecuteAsync(deleteOperation);
                    }
                }

                // app package を削除
                var appPackage = await DeleteBrob(application.AppPackageId);

                foreach (var depId in application.DependencyIds)
                {
                    var dep = await DeleteBrob(depId);
                }
                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }