示例#1
0
        public static ApplicationBuild SaveBuild(string BuildNotes, string FilePath, string CurrentUserName, int environmentId)
        {
            ApplicationBuild retval        = null;
            string           BuildType     = Platforms.Common.GetFilesBuildPlatform(Path.GetFileName(FilePath));
            Guid             uniqueBuildId = new Guid(System.IO.Path.GetFileNameWithoutExtension(FilePath));

            if (BuildType.ToUpper() == Constants.BUILD_PLATFORM_ANDROID)
            {
                Platforms.Android.AndroidManifestData data = Platforms.Android.AndroidPackage.GetManifestData(FilePath);
                CreateAndGetApplicationIfNoExists(data.ApplicationName, data.PackageName, Constants.BUILD_PLATFORM_ANDROID, CurrentUserName);

                using (var context = new Repository.BetaDepotContext())
                {
                    Repository.ApplicationBuild buildToSave = new Repository.ApplicationBuild()
                    {
                        AddedDtm         = DateTime.UtcNow,
                        Application      = context.Applications.Where(w => w.ApplicationIdentifier == data.PackageName).FirstOrDefault(),
                        UniqueIdentifier = uniqueBuildId,
                        Notes            = BuildNotes,
                        versionNumber    = data.VersionName,
                        versionCode      = data.VersionCode,
                        Platform         = Constants.BUILD_PLATFORM_ANDROID,
                        AddedBy          = context.TeamMembers.Where(w => w.UserName == CurrentUserName).FirstOrDefault(),
                        Environment      = context.Environments.Where(w => w.Id == environmentId).FirstOrDefault()
                    };
                    context.Builds.Add(buildToSave);
                    context.SaveChanges();
                    retval = buildToSave;
                }
            }
            else if (BuildType.ToUpper() == Constants.BUILD_PLATFORM_IOS)
            {
                Platforms.iOS.iOSBundleData data = Platforms.iOS.iOSBundle.GetIPABundleData(FilePath);
                CreateAndGetApplicationIfNoExists(data.BundleAppName, data.BundleIdentifier, Constants.BUILD_PLATFORM_IOS, CurrentUserName);

                using (var context = new Repository.BetaDepotContext())
                {
                    Repository.ApplicationBuild buildToSave = new Repository.ApplicationBuild()
                    {
                        AddedDtm         = DateTime.UtcNow,
                        Application      = context.Applications.Where(w => w.ApplicationIdentifier == data.BundleIdentifier).FirstOrDefault(),
                        UniqueIdentifier = Guid.NewGuid(),
                        Notes            = BuildNotes,
                        versionNumber    = data.BundleVersion,
                        Platform         = Constants.BUILD_PLATFORM_IOS,
                        AddedBy          = context.TeamMembers.Where(w => w.UserName == CurrentUserName).FirstOrDefault(),
                        Environment      = context.Environments.Where(w => w.Id == environmentId).FirstOrDefault()
                    };

                    context.Builds.Add(buildToSave);
                    context.SaveChanges();
                    retval = buildToSave;
                }
            }

            return(retval);
        }
示例#2
0
        public ActionResult Upload(IEnumerable <HttpPostedFileBase> files)
        {
            String name     = "";
            String filePath = "";

            if (files == null || files.Count() == 0)
            {
                return(Json(new { Status = "ERROR", Message = "No file was uploaded" }));
            }
            else if (files.Count() > 1)
            {
                return(Json(new { Status = "ERROR", Message = "Only one file upload is supported" }));
            }
            //else if (!Platforms.Common.isBuildFileSupported(files.ElementAt(0).FileName))
            //    return Json(new {  Status = "ERROR",  Message = string.Format("This file '{0}' is not supported", files.ElementAt(0).FileName) });


            try
            {
                name     = string.Format("{0}{1}", Guid.NewGuid(), Path.GetExtension(files.ElementAt(0).FileName));
                filePath = Path.Combine(Server.MapPath("~/App_Data/Files"), name);
                files.ElementAt(0).SaveAs(filePath);
            }
            catch (Exception ex)
            {
                return(Json(new { Status = "ERROR", Message = "An error occured reading the file." }));
            }

            if (Platforms.Common.GetFilesBuildPlatform(files.ElementAt(0).FileName) == Constants.BUILD_PLATFORM_ANDROID)
            {
                //Android
                Platforms.Android.AndroidManifestData data = Platforms.Android.AndroidPackage.GetManifestData(filePath);
                Platforms.Android.AndroidPackage.ExtractPackageAppIconIfNotExists(filePath, Server.MapPath("~/App_Data/Files/Icons"), data.PackageName);
                return(Json(new
                {
                    Status = "OK",
                    FileName = name,
                    Platform = Constants.BUILD_PLATFORM_ANDROID,
                    PackageName = data.PackageName,
                    AppName = data.ApplicationName,
                    VersionName = data.VersionName
                }));
            }
            else if (Platforms.Common.GetFilesBuildPlatform(files.ElementAt(0).FileName) == Constants.BUILD_PLATFORM_IOS)
            {
                //iOS
                Platforms.iOS.iOSBundleData bundleData = Platforms.iOS.iOSBundle.GetIPABundleData(filePath);
                Platforms.iOS.iOSBundle.ExtractBundleAppIconIfNotExists(filePath, Server.MapPath("~/App_Data/Files/Icons"), bundleData.BundleIdentifier);
                return(Json(new
                {
                    Status = "OK",
                    FileName = name,
                    Platform = Constants.BUILD_PLATFORM_IOS,
                    PackageName = bundleData.BundleIdentifier,
                    AppName = bundleData.BundleAppName,
                    VersionName = bundleData.BundleVersion
                }));
            }
            else
            {
                return(Json(new { Status = "ERROR", Message = string.Format("This file '{0}' is not supported", files.ElementAt(0).FileName) }));
            }
        }