Esempio n. 1
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);
            }
        }
Esempio n. 2
0
        public async Task <List <AppInfo> > GetAppInfoListAsync()
        {
            var dummyAppVersion = new HashSet <AppVersion>()
            {
                new AppVersion("1.0.0.0")
            };

            var appInfoList = new List <AppInfo>();

            var firstApp = new AppInfo
            {
                Name                  = "DummyApplication1",
                DeveloperName         = "DummyDeveloper1",
                Description           = "This app targets x86",
                SupportedArchitecture = SupportedArchitectureType.X86,
                Versions              = dummyAppVersion
            };

            var secondApp = new AppInfo
            {
                Name                  = "DummyApplication2",
                DeveloperName         = "DummyDeveloper2",
                Description           = "This app targets arm",
                SupportedArchitecture = SupportedArchitectureType.Arm,
                Versions              = dummyAppVersion
            };

            var thirdApp = new AppInfo
            {
                Name                  = "DummyApplication3",
                DeveloperName         = "DummyDeveloper3",
                Description           = "This app targets x86 and arm",
                SupportedArchitecture = SupportedArchitectureType.X86 | SupportedArchitectureType.Arm,
                Versions              = dummyAppVersion,
                UpdateAt              = DateTime.MinValue,
            };

            var fourthApp = new AppInfo
            {
                Name                  = "DummyApplication4",
                DeveloperName         = "DummyDeveloper4",
                Description           = "This app targets all",
                SupportedArchitecture = SupportedArchitectureType.X64 | SupportedArchitectureType.X86 | SupportedArchitectureType.Arm | SupportedArchitectureType.Arm64,
                Versions              = dummyAppVersion,
                UpdateAt              = DateTime.MaxValue,
            };

            var fifthApp = new AppInfo
            {
                Name                  = "DummyApplication5",
                DeveloperName         = "DummyDeveloper5",
                Description           = "This app targets all",
                SupportedArchitecture = SupportedArchitectureType.X64 | SupportedArchitectureType.X86 | SupportedArchitectureType.Arm | SupportedArchitectureType.Arm64,
                Versions              = dummyAppVersion,
                UpdateAt              = DateTime.Today,
            };

            appInfoList.Add(firstApp);
            appInfoList.Add(secondApp);
            appInfoList.Add(thirdApp);
            appInfoList.Add(fourthApp);
            appInfoList.Add(fifthApp);

            return(appInfoList);
        }