예제 #1
0
        public void UpdateStatus(int id)
        {
            AppInstaller installer = cdb.findById <AppInstaller>(id);

            if (installer == null)
            {
                throw new NullReferenceException();
            }

            String name        = ctx.Post("Name");
            String description = strUtil.CutString(ctx.Post("Description"), 150);

            if (strUtil.IsNullOrEmpty(name))
            {
                errors.Add("请填写名称");
                run(EditStatus, id);
                return;
            }

            if (strUtil.IsNullOrEmpty(description))
            {
                errors.Add("请填写简介");
                run(EditStatus, id);
                return;
            }

            int closeMode = ctx.PostInt("closeMode");

            installer.Name        = name;
            installer.Description = description;
            installer.CloseMode   = closeMode;

            installer.update();


            String val = ctx.Post("appCheckboxList");

            appService.UpdateStatus(installer, val);

            echoToParentPart(lang("opok"), to(App), 0);
        }
예제 #2
0
        private void bindAppAdminLink(IBlock block, String lbl, object obj)
        {
            AppInstaller installer = obj as AppInstaller;

            block.Set("app.StatusAdminName", "修改");
            block.Set("app.StatusAdminLink", to(EditStatus, installer.Id));

            // 绑定安装主题
            List <ITheme> themeList = ThemeHelper.GetThemeList(installer);

            if (themeList.Count > 0)
            {
                block.Set("app.ThemeInfo", string.Format("{0}个安装主题", themeList.Count));
                block.Set("app.ThemeAdminLink", to(new AppThemeController().Index, installer.Id));
            }
            else
            {
                block.Set("app.ThemeInfo", "");
                block.Set("app.ThemeAdminLink", "#");
            }
        }
예제 #3
0
        private void bindAppAdder(IList apps, IBlock listBlock, AppInstaller app)
        {
            String addGif  = strUtil.Join(sys.Path.Img, "add.gif");
            String downGif = strUtil.Join(sys.Path.Img, "downWhite.gif");

            List <AppInstaller> childApps = getChildApp(app, apps);

            if (childApps.Count <= 0)
            {
                String lnk     = to(NewApp, app.Id);
                String addInfo = string.Format("<a href=\"{0}\" class=\"cmd frmBox\" title=\"{1}\"><img src=\"{2}\"> {3}</a>",
                                               lnk, lang("appAddTip"), addGif, lang("appadd"));

                listBlock.Set("app.AddInfo", addInfo);
            }
            else
            {
                String addInfo = getSubApps(app, childApps);
                listBlock.Set("app.AddInfo", addInfo);
            }
        }
예제 #4
0
        public void EditPermission(int id)
        {
            Boolean isUserPrivacyClose = Component.IsClose(typeof(UserPrivacy));

            if (isUserPrivacyClose)
            {
                echo("对不起,本功能已经停用");
                return;
            }

            //---------------------------------------------------------


            target(SavePermission, id);

            IMemberApp   app  = userAppService.FindById(id, ctx.owner.Id);
            AppInstaller info = getAppInfo(app.AppInfoId);

            bindAppInfo(info);

            set("app.FriendlyName", app.Name);
            set("app.AccessStatus", AccessStatusUtil.GetRadioList(app.AccessStatus));
        }
예제 #5
0
        private String getSubApps(AppInstaller app, List <AppInstaller> childApps)
        {
            String addGif  = strUtil.Join(sys.Path.Img, "add.gif");
            String downGif = strUtil.Join(sys.Path.Img, "down.gif");

            String addInfo = "<span class=\"cmd menuMore\" list=\"subApps" + app.Id + "\"><img src=\"" + addGif + "\"> " + lang("appadd") + " <img src=\"" + downGif + "\"/>";

            addInfo += "<ul class=\"menuItems\" style=\"width:250px;text-align:left\" id=\"subApps" + app.Id + "\">";

            String lnk = string.Format("<a href=\"{0}\" class=\"frmBox\" title=\"{1}\"><img src=\"" + addGif + "\"> ", to(NewApp, app.Id), lang("appAddTip"));

            addInfo += "<li><div><strong>" + lnk + app.Name + "</a></strong><span class=\"note\">(基本型)</span></div></li>";

            foreach (AppInstaller a in childApps)
            {
                String alnk = string.Format("<a href=\"{0}\" class=\"frmBox\" title=\"{1}\"><img src=\"" + addGif + "\"> ", to(NewApp, a.Id), lang("appAddTip"));

                addInfo += "<li><div><strong>" + alnk + a.Name + "</a></strong><span class=\"note\">(" + a.Description + ")</span></div></li>";
            }

            addInfo += "</ul></span>";
            return(addInfo);
        }
예제 #6
0
        private IMemberApp createApp()
        {
            int          appInfoId = 4;
            AppInstaller info      = appinfoService.GetById(appInfoId);

            IMember owner   = this.user;
            User    creator = this.user;
            String  name    = lang.get("homepage");

            IMemberApp myuserApp = appService.Add(creator, owner, name, info.Id, AccessStatus.Public);
            //String appUrl = UrlConverter.clearUrl( myuserApp, ctx );
            String appUrl = UrlConverter.clearUrl(myuserApp, ctx, owner);

            IMenu menu = menuService.AddMenuByApp(myuserApp, name, "", appUrl);

            menu.Url     = "default";
            menu.OrderId = 99;
            menuService.Update(menu);

            this.app = ContentApp.findById(myuserApp.AppOid);

            return(myuserApp);
        }
예제 #7
0
        private async Task <ExitCode> RunTest(
            ILogger logger,
            TestTarget target,
            Logs logs,
            ProcessManager processManager,
            IHardwareDeviceLoader deviceLoader,
            ISimulatorLoader simulatorLoader,
            ITunnelBore?tunnelBore,
            CancellationToken cancellationToken = default)
        {
            logger.LogInformation($"Starting test for {target.AsString()}{ (_arguments.DeviceName != null ? " targeting " + _arguments.DeviceName : null) }..");

            string mainLogFile = Path.Join(_arguments.OutputDirectory, $"run-{target}{(_arguments.DeviceName != null ? "-" + _arguments.DeviceName : null)}.log");
            ILog   mainLog     = logs.Create(mainLogFile, LogType.ExecutionLog.ToString(), true);
            int    verbosity   = GetMlaunchVerbosity(_arguments.Verbosity);

            string?deviceName = _arguments.DeviceName;

            var appBundleInformationParser = new AppBundleInformationParser(processManager);

            AppBundleInformation appBundleInfo;

            try
            {
                appBundleInfo = await appBundleInformationParser.ParseFromAppBundle(_arguments.AppPackagePath, target, mainLog, cancellationToken);
            }
            catch (Exception e)
            {
                logger.LogError($"Failed to get bundle information: {e.Message}");
                return(ExitCode.FAILED_TO_GET_BUNDLE_INFO);
            }

            if (!target.IsSimulator())
            {
                logger.LogInformation($"Installing application '{appBundleInfo.AppName}' on " + (deviceName != null ? $" on device '{deviceName}'" : target.AsString()));

                var appInstaller = new AppInstaller(processManager, deviceLoader, mainLog, verbosity);

                ProcessExecutionResult result;

                try
                {
                    (deviceName, result) = await appInstaller.InstallApp(_arguments.AppPackagePath, target, cancellationToken : cancellationToken);
                }
                catch (NoDeviceFoundException)
                {
                    logger.LogError($"Failed to find suitable device for target {target.AsString()}");
                    return(ExitCode.DEVICE_NOT_FOUND);
                }
                catch (Exception e)
                {
                    logger.LogError($"Failed to install the app bundle:{Environment.NewLine}{e}");
                    return(ExitCode.PACKAGE_INSTALLATION_FAILURE);
                }

                if (!result.Succeeded)
                {
                    // use the knowledge base class to decide if the error is known, if it is, let the user know
                    // the failure reason
                    if (_errorKnowledgeBase.IsKnownInstallIssue(mainLog, out var errorMessage))
                    {
                        logger.LogError($"Failed to install the app bundle (exit code={result.ExitCode}): {errorMessage}");
                    }
                    else
                    {
                        logger.LogError($"Failed to install the app bundle (exit code={result.ExitCode})");
                    }

                    return(ExitCode.PACKAGE_INSTALLATION_FAILURE);
                }

                logger.LogInformation($"Application '{appBundleInfo.AppName}' was installed successfully on device '{deviceName}'");
            }

            logger.LogInformation($"Starting application '{appBundleInfo.AppName}' on " + (deviceName != null ? $"device '{deviceName}'" : target.AsString()));

            var appRunner = new AppRunner(
                processManager,
                deviceLoader,
                simulatorLoader,
                new SimpleListenerFactory(tunnelBore),
                new CrashSnapshotReporterFactory(processManager),
                new CaptureLogFactory(),
                new DeviceLogCapturerFactory(processManager),
                new TestReporterFactory(processManager),
                mainLog,
                logs,
                new Helpers(),
                useXmlOutput: true); // the cli ALWAYS will get the output as xml

            try
            {
                string resultMessage;
                TestExecutingResult testResult;
                (deviceName, testResult, resultMessage) = await appRunner.RunApp(appBundleInfo,
                                                                                 target,
                                                                                 _arguments.Timeout,
                                                                                 _arguments.LaunchTimeout,
                                                                                 deviceName,
                                                                                 verbosity : verbosity,
                                                                                 xmlResultJargon : _arguments.XmlResultJargon,
                                                                                 cancellationToken : cancellationToken);

                switch (testResult)
                {
                case TestExecutingResult.Succeeded:
                    logger.LogInformation($"Application finished the test run successfully");
                    logger.LogInformation(resultMessage);

                    return(ExitCode.SUCCESS);

                case TestExecutingResult.Failed:
                    logger.LogInformation($"Application finished the test run successfully with some failed tests");
                    logger.LogInformation(resultMessage);

                    return(ExitCode.TESTS_FAILED);

                case TestExecutingResult.Crashed:

                    if (resultMessage != null)
                    {
                        logger.LogError($"Application run crashed:{Environment.NewLine}" +
                                        $"{resultMessage}{Environment.NewLine}{Environment.NewLine}" +
                                        $"Check logs for more information.");
                    }
                    else
                    {
                        logger.LogError($"Application run crashed. Check logs for more information");
                    }

                    return(ExitCode.APP_CRASH);

                case TestExecutingResult.TimedOut:
                    logger.LogWarning($"Application run timed out");

                    return(ExitCode.TIMED_OUT);

                default:

                    if (resultMessage != null)
                    {
                        logger.LogError($"Application run ended in an unexpected way: '{testResult}'{Environment.NewLine}" +
                                        $"{resultMessage}{Environment.NewLine}{Environment.NewLine}" +
                                        $"Check logs for more information.");
                    }
                    else
                    {
                        logger.LogError($"Application run ended in an unexpected way: '{testResult}'. Check logs for more information");
                    }

                    return(ExitCode.GENERAL_FAILURE);
                }
            }
            catch (NoDeviceFoundException)
            {
                logger.LogError($"Failed to find suitable device for target {target.AsString()}");
                return(ExitCode.DEVICE_NOT_FOUND);
            }
            catch (Exception e)
            {
                if (_errorKnowledgeBase.IsKnownTestIssue(mainLog, out var failureMessage))
                {
                    logger.LogError($"Application run failed:{Environment.NewLine}{failureMessage}");
                }
                else
                {
                    logger.LogError($"Application run failed:{Environment.NewLine}{e}");
                }

                return(ExitCode.APP_CRASH);
            }
            finally
            {
                if (!target.IsSimulator() && deviceName != null)
                {
                    logger.LogInformation($"Uninstalling the application '{appBundleInfo.AppName}' from device '{deviceName}'");

                    var appUninstaller  = new AppUninstaller(processManager, mainLog, verbosity);
                    var uninstallResult = await appUninstaller.UninstallApp(deviceName, appBundleInfo.BundleIdentifier, cancellationToken);

                    if (!uninstallResult.Succeeded)
                    {
                        logger.LogError($"Failed to uninstall the app bundle with exit code: {uninstallResult.ExitCode}");
                    }
                    else
                    {
                        logger.LogInformation($"Application '{appBundleInfo.AppName}' was uninstalled successfully");
                    }
                }
            }
        }
예제 #8
0
 private void bindAppInfo(AppInstaller info)
 {
     set("app.Name", info.Name);
     set("app.Description", info.Description);
     set("app.Id", info.Id);
 }
예제 #9
0
 private String getUserDataAdminLink(AppInstaller app)
 {
     return(string.Format("<a href='{1}' class='frmLink userDataLink' loadto='adminMainBody' nolayout=1>{0}</a>", app.Name, ToUserDataAdmin(app)));
 }
예제 #10
0
        public virtual void Create()
        {
            int          appInfoId = cvt.ToInt(ctx.Post("appInfoId"));
            AppInstaller info      = getAppInfo(appInfoId);

            if (info.IsClose(ctx.owner.obj.GetType()))
            {
                echo("app closed");
                return;
            }

            if (!checkInstall(info))
            {
                return;
            }

            String       name = ctx.Post("Name");
            AccessStatus accs = AccessStatus.Public;

            if (strUtil.IsNullOrEmpty(name))
            {
                echoError("请填写名称");
                return;
            }

            // 自定义安装
            Type appType = ObjectContext.Instance.TypeList[info.TypeFullName];

            if (rft.IsInterface(appType, typeof(IAppInstaller)))
            {
                // 主题ID
                String themeId = ctx.Post("themeId");

                IAppInstaller customInstaller = ObjectContext.Create(appType) as IAppInstaller;
                IMemberApp    capp            = customInstaller.Install(ctx, ctx.owner.obj, name, accs, themeId, "");
                intiAppPermission(capp);


                echoToParentPart(lang("opok"), to(Index), 1);
                return;
            }

            // 主题安装
            if (strUtil.HasText(info.InstallerType))
            {
                // 主题ID
                String themeId = ctx.Post("themeId");

                Type installerType = ObjectContext.GetType(info.InstallerType);

                IAppInstaller customInstaller = ObjectContext.Create(installerType) as IAppInstaller;
                IMemberApp    capp            = customInstaller.Install(ctx, ctx.owner.obj, name, accs, themeId, "");
                intiAppPermission(capp);

                echoToParentPart(lang("opok"), to(Index), 1);
                return;
            }

            // 默认安装
            IMember owner   = ctx.owner.obj;
            User    creator = (User)ctx.viewer.obj;

            // 1、添加一条 IMemberApp
            IMemberApp app = userAppService.Add(creator, owner, name, info.Id, accs);

            if (app != null)
            {
                // 2、添加菜单
                String appUrl = UrlConverter.clearUrl(app, ctx);
                menuService.AddMenuByApp(app, name, "", appUrl);

                // 3、初始化权限
                intiAppPermission(app);

                log(SiteLogString.InsertApp(), app);


                echoToParentPart(lang("opok"), to(Index), 1);
            }
            else
            {
                errors.Add(lang("exop"));

                run(NewApp, info.Id);
            }
        }
예제 #11
0
        /***************************************************************************
        *
        * Private Methods
        *
        ***************************************************************************/

        private async void Generate_File_Button_Click(object sender, RoutedEventArgs e)
        {
            //Check that all required fields have been filled
            if (!_validateInput())
            {
                return;
            }

            var savePicker = new Windows.Storage.Pickers.FileSavePicker
            {
                SuggestedStartLocation =
                    Windows.Storage.Pickers.PickerLocationId.Desktop
            };

            // Dropdown of file types the user can save the file as
            savePicker.FileTypeChoices.Add("APPINSTALLER file", new List <string>()
            {
                ".appinstaller"
            });
            // Default file name if the user does not type one in or select a file to replace

            Windows.Storage.StorageFile file = await savePicker.PickSaveFileAsync();

            try
            {
                var t = Task.Run(async() =>
                {
                    var fileStream = await file.OpenAsync(FileAccessMode.ReadWrite);

                    //Create file
                    //FileStream writer = new FileStream(file.Path, FileMode.OpenOrCreate);

                    AppInstaller appInstaller = new AppInstaller(App.AppInstallerFilePath, App.AppInstallerVersionNumber);

                    XmlWriterSettings settings = new XmlWriterSettings
                    {
                        Indent              = true,
                        OmitXmlDeclaration  = false,
                        NewLineOnAttributes = true,
                        Encoding            = Encoding.UTF8,
                        NamespaceHandling   = NamespaceHandling.OmitDuplicates
                    };

                    var fs = fileStream.AsStreamForWrite();
                    fs.SetLength(0);


                    XmlWriter xdw = XmlWriter.Create(fs, settings);

                    //DataContractSerializer appInstallerDCS = new DataContractSerializer(typeof(AppInstaller));

                    //AppInstaller Content
                    //appInstallerDCS.WriteStartObject(xdw, appInstaller);
                    xdw.WriteStartElement("", "AppInstaller", App.AppInstallerFileSchemaNamespace);

                    //xdw.WriteAttributeString("xmlns", );
                    xdw.WriteAttributeString("Version", App.AppInstallerVersionNumber);
                    xdw.WriteAttributeString("Uri", App.AppInstallerFilePath);


                    //Main Package Content
                    if (App.MainPackage.PackageType == PackageType.MSIX)
                    {
                        //DataContractSerializer mainPackageDCS = new DataContractSerializer(typeof(MainPackage));

                        //mainPackageDCS.WriteStartObject(xdw, _mainPackage);

                        xdw.WriteStartElement("MainPackage");

                        xdw.WriteAttributeString("Name", _mainPackage.Name);
                        xdw.WriteAttributeString("Publisher", _mainPackage.Publisher);
                        xdw.WriteAttributeString("Version", _mainPackage.Version);
                        if (_mainPackage.ResourceId != "")
                        {
                            xdw.WriteAttributeString("ResourceId", _mainPackage.ResourceId);
                        }
                        if (_mainPackage.ProcessorArchitecture != "" && _mainPackage.PackageType != PackageType.MSIXBUNDLE)
                        {
                            xdw.WriteAttributeString("ProcessorArchitecture", _mainPackage.ProcessorArchitecture.ToString());
                        }
                        xdw.WriteAttributeString("Uri", _mainPackage.FilePath);
                        xdw.WriteEndElement();
                        //mainPackageDCS.WriteEndObject(xdw);
                    }
                    else if (App.MainPackage.PackageType == PackageType.MSIXBUNDLE)
                    {
                        //DataContractSerializer mainBundleDCS = new DataContractSerializer(typeof(MainBundle));
                        MainBundle mainBundle = new MainBundle(App.MainPackage.FilePath, App.MainPackage.Version, App.MainPackage.Publisher, App.MainPackage.Name);
                        //mainBundleDCS.WriteStartObject(xdw, mainBundle);
                        xdw.WriteStartElement("MainBundle");

                        xdw.WriteAttributeString("Name", mainBundle.Name);
                        xdw.WriteAttributeString("Publisher", mainBundle.Publisher);
                        xdw.WriteAttributeString("Version", mainBundle.Version);
                        xdw.WriteAttributeString("Uri", mainBundle.FilePath);
                        //mainBundleDCS.WriteEndObject(xdw);
                        xdw.WriteEndElement();
                    }

                    //Optional Packages Content
                    ObservableCollection <OptionalPackage> optionalPackages = App.OptionalPackages;
                    //DataContractSerializer optionalPackageDCS = new DataContractSerializer(typeof(OptionalPackage));

                    //Modification Packages Content
                    ObservableCollection <ModificationPackage> modificationPackages = App.ModificationPackages;

                    bool hasOptionalPackage     = (optionalPackages.Count > 0 && App.IsOptionalPackages);
                    bool hasModificationPackage = (modificationPackages.Count > 0 && App.IsModificationPackages);

                    if (hasOptionalPackage || hasModificationPackage)
                    {
                        xdw.WriteStartElement("OptionalPackages");
                        //optionalPackageDCS.WriteStartObject(xdw, optionalPackages[0]);
                        if (hasOptionalPackage)
                        {
                            for (int i = 0; i < optionalPackages.Count; i++)
                            {
                                //Write package or bundle element
                                if (optionalPackages[i].PackageType == PackageType.MSIX)
                                {
                                    Package package = new Package(
                                        optionalPackages[i].FilePath,
                                        optionalPackages[i].Version,
                                        optionalPackages[i].Publisher,
                                        optionalPackages[i].Name,
                                        optionalPackages[i].PackageType,
                                        optionalPackages[i].ProcessorArchitecture
                                        );

                                    //DataContractSerializer packageDCS = new DataContractSerializer(typeof(Package));
                                    xdw.WriteStartElement("Package");
                                    //packageDCS.WriteStartObject(xdw, package);
                                    xdw.WriteAttributeString("Version", package.Version);
                                    xdw.WriteAttributeString("Uri", package.FilePath);
                                    xdw.WriteAttributeString("Publisher", package.Publisher);
                                    if (package.ProcessorArchitecture != "" && package.PackageType != PackageType.MSIXBUNDLE)
                                    {
                                        xdw.WriteAttributeString("ProcessorArchitecture", package.ProcessorArchitecture.ToString());
                                    }
                                    xdw.WriteAttributeString("Name", package.Name);
                                    //packageDCS.WriteEndObject(xdw);
                                    xdw.WriteEndElement();
                                }
                                else if (optionalPackages[i].PackageType == PackageType.MSIXBUNDLE)
                                {
                                    Bundle bundle = new Bundle(
                                        optionalPackages[i].FilePath,
                                        optionalPackages[i].Version,
                                        optionalPackages[i].Publisher,
                                        optionalPackages[i].Name,
                                        optionalPackages[i].PackageType
                                        );

                                    //DataContractSerializer bundleDCS = new DataContractSerializer(typeof(Bundle));
                                    //bundleDCS.WriteStartObject(xdw, bundle);
                                    xdw.WriteStartElement("Bundle");
                                    xdw.WriteAttributeString("Version", bundle.Version);
                                    xdw.WriteAttributeString("Uri", bundle.FilePath);
                                    xdw.WriteAttributeString("Publisher", bundle.Publisher);
                                    xdw.WriteAttributeString("Name", bundle.Name);
                                    //bundleDCS.WriteEndObject(xdw);
                                    xdw.WriteEndElement();
                                }
                            }
                        }

                        if (hasModificationPackage)
                        {
                            for (int i = 0; i < modificationPackages.Count; i++)
                            {
                                //Write package or bundle element
                                if (modificationPackages[i].PackageType == PackageType.MSIX)
                                {
                                    Package package = new Package(
                                        modificationPackages[i].FilePath,
                                        modificationPackages[i].Version,
                                        modificationPackages[i].Publisher,
                                        modificationPackages[i].Name,
                                        modificationPackages[i].PackageType,
                                        modificationPackages[i].ProcessorArchitecture
                                        );

                                    //DataContractSerializer packageDCS = new DataContractSerializer(typeof(Package));
                                    //packageDCS.WriteStartObject(xdw, package);
                                    xdw.WriteStartElement("Package");
                                    xdw.WriteAttributeString("Version", package.Version);
                                    xdw.WriteAttributeString("Uri", package.FilePath);
                                    xdw.WriteAttributeString("Publisher", package.Publisher);
                                    if (package.ProcessorArchitecture != "" && package.PackageType != PackageType.MSIXBUNDLE)
                                    {
                                        xdw.WriteAttributeString("ProcessorArchitecture", package.ProcessorArchitecture.ToString());
                                    }
                                    xdw.WriteAttributeString("Name", package.Name);
                                    //packageDCS.WriteEndObject(xdw);
                                    xdw.WriteEndElement();
                                }
                                else if (modificationPackages[i].PackageType == PackageType.MSIXBUNDLE)
                                {
                                    Bundle bundle = new Bundle(
                                        modificationPackages[i].FilePath,
                                        modificationPackages[i].Version,
                                        modificationPackages[i].Publisher,
                                        modificationPackages[i].Name,
                                        modificationPackages[i].PackageType
                                        );

                                    //DataContractSerializer bundleDCS = new DataContractSerializer(typeof(Bundle));
                                    //bundleDCS.WriteStartObject(xdw, bundle);
                                    xdw.WriteStartElement("Bundle");
                                    xdw.WriteAttributeString("Version", bundle.Version);
                                    xdw.WriteAttributeString("Uri", bundle.FilePath);
                                    xdw.WriteAttributeString("Publisher", bundle.Publisher);
                                    xdw.WriteAttributeString("Name", bundle.Name);
                                    //bundleDCS.WriteEndObject(xdw);
                                    xdw.WriteEndElement();
                                }
                            }
                        }
                        //optionalPackageDCS.WriteEndObject(xdw);
                        xdw.WriteEndElement();
                    }

                    //Related Packages Content
                    ObservableCollection <RelatedPackage> relatedPackages = App.RelatedPackages;
                    //DataContractSerializer relatedPackageDCS = new DataContractSerializer(typeof(RelatedPackage));
                    if (relatedPackages.Count > 0 && App.IsRelatedPackages)
                    {
                        //relatedPackageDCS.WriteStartObject(xdw, relatedPackages[0]);
                        xdw.WriteStartElement("RelatedPackages");
                        for (int i = 0; i < relatedPackages.Count; i++)
                        {
                            //Write package or bundle element
                            if (relatedPackages[i].PackageType == PackageType.MSIX)
                            {
                                Package package = new Package(
                                    relatedPackages[i].FilePath,
                                    relatedPackages[i].Version,
                                    relatedPackages[i].Publisher,
                                    relatedPackages[i].Name,
                                    relatedPackages[i].PackageType,
                                    relatedPackages[i].ProcessorArchitecture
                                    );

                                //DataContractSerializer packageDCS = new DataContractSerializer(typeof(Package));
                                xdw.WriteStartElement("Package");
                                //packageDCS.WriteStartObject(xdw, package);
                                xdw.WriteAttributeString("Version", package.Version);
                                xdw.WriteAttributeString("Uri", package.FilePath);
                                xdw.WriteAttributeString("Publisher", package.Publisher);
                                if (package.ProcessorArchitecture != "" && package.PackageType != PackageType.MSIXBUNDLE)
                                {
                                    xdw.WriteAttributeString("ProcessorArchitecture", package.ProcessorArchitecture.ToString());
                                }
                                xdw.WriteAttributeString("Name", package.Name);
                                //packageDCS.WriteEndObject(xdw);
                                xdw.WriteEndElement();
                            }
                            else if (relatedPackages[i].PackageType == PackageType.MSIXBUNDLE)
                            {
                                Bundle bundle = new Bundle(
                                    relatedPackages[i].FilePath,
                                    relatedPackages[i].Version,
                                    relatedPackages[i].Publisher,
                                    relatedPackages[i].Name,
                                    relatedPackages[i].PackageType
                                    );

                                //DataContractSerializer bundleDCS = new DataContractSerializer(typeof(Bundle));
                                //bundleDCS.WriteStartObject(xdw, bundle);
                                xdw.WriteStartElement("Bundle");
                                xdw.WriteAttributeString("Version", bundle.Version);
                                xdw.WriteAttributeString("Uri", bundle.FilePath);
                                xdw.WriteAttributeString("Publisher", bundle.Publisher);
                                xdw.WriteAttributeString("Name", bundle.Name);
                                //bundleDCS.WriteEndObject(xdw);
                                xdw.WriteEndElement();
                            }
                        }
                        //relatedPackageDCS.WriteEndObject(xdw);
                        xdw.WriteEndElement();
                    }


                    //Dependency Content

                    ObservableCollection <Dependency> dependencies = App.Dependencies;
                    //DataContractSerializer dependencyDCS = new DataContractSerializer(typeof(Dependency));
                    if (dependencies.Count > 0 && App.IsDependencies)
                    {
                        //dependencyDCS.WriteStartObject(xdw, dependencies[0]);
                        xdw.WriteStartElement("Dependencies");
                        for (int i = 0; i < dependencies.Count; i++)
                        {
                            //Write package or bundle element
                            if (dependencies[i].PackageType == PackageType.MSIX)
                            {
                                Package package = new Package(
                                    dependencies[i].FilePath,
                                    dependencies[i].Version,
                                    dependencies[i].Publisher,
                                    dependencies[i].Name,
                                    dependencies[i].PackageType,
                                    dependencies[i].ProcessorArchitecture
                                    );

                                //DataContractSerializer packageDCS = new DataContractSerializer(typeof(Package));
                                //packageDCS.WriteStartObject(xdw, package);
                                xdw.WriteStartElement("Package");
                                xdw.WriteAttributeString("Version", package.Version);
                                xdw.WriteAttributeString("Uri", package.FilePath);
                                xdw.WriteAttributeString("Publisher", package.Publisher);
                                if (package.ProcessorArchitecture != "" && package.PackageType != PackageType.MSIXBUNDLE)
                                {
                                    xdw.WriteAttributeString("ProcessorArchitecture", package.ProcessorArchitecture.ToString());
                                }
                                xdw.WriteAttributeString("Name", package.Name);
                                //packageDCS.WriteEndObject(xdw);
                                xdw.WriteEndElement();
                            }
                            else if (dependencies[i].PackageType == PackageType.MSIXBUNDLE)
                            {
                                Bundle bundle = new Bundle(
                                    dependencies[i].FilePath,
                                    dependencies[i].Version,
                                    dependencies[i].Publisher,
                                    dependencies[i].Name,
                                    dependencies[i].PackageType
                                    );

                                //DataContractSerializer bundleDCS = new DataContractSerializer(typeof(Bundle));
                                //bundleDCS.WriteStartObject(xdw, bundle);
                                xdw.WriteStartElement("Bundle");
                                xdw.WriteAttributeString("Version", bundle.Version);
                                xdw.WriteAttributeString("Uri", bundle.FilePath);
                                xdw.WriteAttributeString("Publisher", bundle.Publisher);
                                xdw.WriteAttributeString("Name", bundle.Name);
                                //bundleDCS.WriteEndObject(xdw);
                                xdw.WriteEndElement();
                            }
                        }
                        //dependencyDCS.WriteEndObject(xdw);
                        xdw.WriteEndElement();
                    }


                    //Update Settings
                    UpdateSettings updateSettings = new UpdateSettings();

                    //OnLaunch
                    OnLaunch onLaunch = new OnLaunch(App.IsCheckUpdates, App.HoursBetweenUpdates, App.IsShowPrompt, App.IsBlockUpdate);

                    //ForceUpdateFromAnyVersion
                    ForceUpdateFromAnyVersion forceUpdate = new ForceUpdateFromAnyVersion(App.IsForceUpdate);

                    //AutomaticBackgroundTask
                    AutomaticBackgroundTask automaticBackgroundTask = new AutomaticBackgroundTask(App.IsAutoUpdate);

                    if (onLaunch.IsCheckUpdates)
                    {
                        //DataContractSerializer updateSettingsDCS = new DataContractSerializer(typeof(UpdateSettings));
                        //updateSettingsDCS.WriteStartObject(xdw, updateSettings);
                        xdw.WriteStartElement("UpdateSettings");

                        //DataContractSerializer onLaunchDCS = new DataContractSerializer(typeof(OnLaunch));
                        //onLaunchDCS.WriteStartObject(xdw, onLaunch);
                        xdw.WriteStartElement("OnLaunch");

                        //HoursBetweenUpdate checks is only available AFTER 1709
                        if (!App.AppInstallerFileSchemaNamespace.Equals("http://schemas.microsoft.com/appx/appinstaller/2017"))
                        {
                            xdw.WriteAttributeString("HoursBetweenUpdateChecks", onLaunch.HoursBetweenUpdateChecks.ToString());
                        }

                        if (onLaunch.IsShowPrompt)
                        {
                            xdw.WriteAttributeString("ShowPrompt", onLaunch.IsShowPrompt.ToString().ToLower());
                        }
                        if (onLaunch.IsBlockUpdate)
                        {
                            xdw.WriteAttributeString("UpdateBlocksActivation", onLaunch.IsBlockUpdate.ToString().ToLower());
                        }
                        //onLaunchDCS.WriteEndObject(xdw);
                        xdw.WriteEndElement();

                        if (forceUpdate.IsForceUpdate)
                        {
                            //DataContractSerializer forceUpdateDCS = new DataContractSerializer(typeof(ForceUpdateFromAnyVersion));
                            //forceUpdateDCS.WriteStartObject(xdw, forceUpdate);
                            xdw.WriteStartElement("ForceUpdateFromAnyVersion");
                            xdw.WriteString(forceUpdate.IsForceUpdate.ToString().ToLower());
                            //forceUpdateDCS.WriteEndObject(xdw);
                            xdw.WriteEndElement();
                        }

                        if (automaticBackgroundTask.IsAutoUpdate)
                        {
                            //DataContractSerializer autoUpdateDCS = new DataContractSerializer(typeof(AutomaticBackgroundTask));
                            //autoUpdateDCS.WriteStartObject(xdw, automaticBackgroundTask);
                            xdw.WriteStartElement("AutomaticBackgroundTask");
                            //autoUpdateDCS.WriteEndObject(xdw);
                            xdw.WriteEndElement();
                        }

                        //updateSettingsDCS.WriteEndObject(xdw);
                        xdw.WriteEndElement();
                    }


                    //xdw.WriteEndElement();
                    //appInstallerDCS.WriteEndObject(xdw);
                    xdw.Dispose();
                });
                t.Wait();
            }
            catch (Exception exc)
            {
                Debug.WriteLine("The serialization operation failed: {0} StackTrace: {1}",
                                exc.Message, exc.StackTrace);
            }

            //Display dialog
            _displaySuccessDialog(file);
        }
예제 #12
0
        public virtual IMemberApp GetByApp(Type t, long appId)
        {
            AppInstaller appInfo = appInfoService.GetByType(t);

            return(GetByApp(appInfo.Id, appId));
        }
예제 #13
0
        public IMemberApp GetByApp(Type t, int appId)
        {
            AppInstaller appInfo = appInfoService.GetByType(t);

            return(GetByApp(appInfo.Id, appId));
        }
예제 #14
0
        private async Task <ExitCode> RunTest(TestTarget target,
                                              Logs logs,
                                              ProcessManager processManager,
                                              IHardwareDeviceLoader deviceLoader,
                                              ISimulatorLoader simulatorLoader,
                                              CancellationToken cancellationToken = default)
        {
            _log.LogInformation($"Starting test for {target.AsString()}{ (_arguments.DeviceName != null ? " targeting " + _arguments.DeviceName : null) }..");

            string mainLogFile = Path.Join(_arguments.OutputDirectory, $"run-{target}{(_arguments.DeviceName != null ? "-" + _arguments.DeviceName : null)}.log");
            ILog   mainLog     = logs.Create(mainLogFile, LogType.ExecutionLog.ToString(), true);
            int    verbosity   = _arguments.Verbosity.ToInt();

            string deviceName = _arguments.DeviceName;

            var appBundleInformationParser = new AppBundleInformationParser(processManager);

            AppBundleInformation appBundleInfo;

            try
            {
                appBundleInfo = await appBundleInformationParser.ParseFromAppBundle(_arguments.AppPackagePath, target, mainLog, cancellationToken);
            }
            catch (Exception e)
            {
                _log.LogError($"Failed to get bundle information: {e.Message}");
                return(ExitCode.FAILED_TO_GET_BUNDLE_INFO);
            }

            if (!target.IsSimulator())
            {
                _log.LogInformation($"Installing application '{appBundleInfo.AppName}' on " + (deviceName != null ? " on device '{deviceName}'" : target.AsString()));

                var appInstaller = new AppInstaller(processManager, deviceLoader, mainLog, verbosity);

                ProcessExecutionResult result;

                try
                {
                    (deviceName, result) = await appInstaller.InstallApp(_arguments.AppPackagePath, target, cancellationToken : cancellationToken);
                }
                catch (NoDeviceFoundException)
                {
                    _log.LogError($"Failed to find suitable device for target {target.AsString()}");
                    return(ExitCode.DEVICE_NOT_FOUND);
                }
                catch (Exception e)
                {
                    _log.LogError($"Failed to install the app bundle:{Environment.NewLine}{e}");
                    return(ExitCode.PACKAGE_INSTALLATION_FAILURE);
                }

                if (!result.Succeeded)
                {
                    _log.LogError($"Failed to install the app bundle (exit code={result.ExitCode})");
                    return(ExitCode.PACKAGE_INSTALLATION_FAILURE);
                }

                _log.LogInformation($"Application '{appBundleInfo.AppName}' was installed successfully on device '{deviceName}'");
            }

            _log.LogInformation($"Starting application '{appBundleInfo.AppName}' on " + (deviceName != null ? " on device '{deviceName}'" : target.AsString()));

            int exitCode;

            try
            {
                var appRunner = new AppRunner(
                    processManager,
                    deviceLoader,
                    simulatorLoader,
                    new SimpleListenerFactory(),
                    new CrashSnapshotReporterFactory(processManager),
                    new CaptureLogFactory(),
                    new DeviceLogCapturerFactory(processManager),
                    new TestReporterFactory(processManager),
                    mainLog,
                    logs,
                    new Helpers());

                (deviceName, exitCode) = await appRunner.RunApp(appBundleInfo,
                                                                target,
                                                                _arguments.Timeout,
                                                                _arguments.LaunchTimeout,
                                                                deviceName,
                                                                verbosity : verbosity,
                                                                xmlResultJargon : XmlResultJargon.xUnit);

                if (exitCode != 0)
                {
                    _log.LogError($"App bundle run failed with exit code {exitCode}. Check logs for more information");
                }
                else
                {
                    _log.LogInformation("Application finished the run successfully");
                }

                return(0);
            }
            catch (NoDeviceFoundException)
            {
                _log.LogError($"Failed to find suitable device for target {target.AsString()}");
                return(ExitCode.DEVICE_NOT_FOUND);
            }
            catch (Exception e)
            {
                _log.LogError($"Application run failed:{Environment.NewLine}{e}");
                return(ExitCode.APP_CRASH);
            }
            finally
            {
                if (!target.IsSimulator())
                {
                    _log.LogInformation($"Uninstalling the application '{appBundleInfo.AppName}' from device '{deviceName}'");

                    var appUninstaller  = new AppUninstaller(processManager, mainLog, verbosity);
                    var uninstallResult = await appUninstaller.UninstallApp(deviceName, appBundleInfo.BundleIdentifier, cancellationToken);

                    if (!uninstallResult.Succeeded)
                    {
                        _log.LogError($"Failed to uninstall the app bundle with exit code: {uninstallResult.ExitCode}");
                    }
                    else
                    {
                        _log.LogInformation($"Application '{appBundleInfo.AppName}' was uninstalled successfully");
                    }
                }
            }
        }
예제 #15
0
        private async Task <ExitCode> RunTest(
            ILogger logger,
            TestTargetOs target,
            Logs logs,
            MLaunchProcessManager processManager,
            IHardwareDeviceLoader deviceLoader,
            ISimulatorLoader simulatorLoader,
            ITunnelBore?tunnelBore,
            CancellationToken cancellationToken = default)
        {
            var isLldbEnabled = IsLldbEnabled();

            if (isLldbEnabled && !_arguments.EnableLldb)
            {
                // the file is present, but the user did not set it, warn him about it
                logger.LogWarning("Lldb will be used since '~/.mtouch-launch-with-lldb' was found in the system but it was not created by xharness.");
            }
            else if (_arguments.EnableLldb)
            {
                if (!File.Exists(s_mlaunchLldbConfigFile))
                {
                    // create empty file
                    File.WriteAllText(s_mlaunchLldbConfigFile, string.Empty);
                    _createdLldbFile = true;
                }
            }

            logger.LogInformation($"Starting test for {target.AsString()}{ (_arguments.DeviceName != null ? " targeting " + _arguments.DeviceName : null) }..");

            string mainLogFile = Path.Join(_arguments.OutputDirectory, $"run-{target.AsString()}{(_arguments.DeviceName != null ? "-" + _arguments.DeviceName : null)}.log");

            IFileBackedLog mainLog = Log.CreateReadableAggregatedLog(
                logs.Create(mainLogFile, LogType.ExecutionLog.ToString(), true),
                new CallbackLog(message => logger.LogDebug(message.Trim()))
            {
                Timestamp = false
            });

            int verbosity = GetMlaunchVerbosity(_arguments.Verbosity);

            string?deviceName = _arguments.DeviceName;

            var appBundleInformationParser = new AppBundleInformationParser(processManager);

            AppBundleInformation appBundleInfo;

            try
            {
                appBundleInfo = await appBundleInformationParser.ParseFromAppBundle(_arguments.AppPackagePath, target.Platform, mainLog, cancellationToken);
            }
            catch (Exception e)
            {
                logger.LogError($"Failed to get bundle information: {e.Message}");
                return(ExitCode.FAILED_TO_GET_BUNDLE_INFO);
            }

            if (!target.Platform.IsSimulator())
            {
                logger.LogInformation($"Installing application '{appBundleInfo.AppName}' on " + (deviceName != null ? $" on device '{deviceName}'" : target.AsString()));

                var appInstaller = new AppInstaller(processManager, deviceLoader, mainLog, verbosity);

                ProcessExecutionResult result;

                try
                {
                    (deviceName, result) = await appInstaller.InstallApp(appBundleInfo, target, cancellationToken : cancellationToken);
                }
                catch (NoDeviceFoundException)
                {
                    logger.LogError($"Failed to find suitable device for target {target.AsString()}" + Environment.NewLine +
                                    "Please make sure the device is connected and unlocked.");
                    return(ExitCode.DEVICE_NOT_FOUND);
                }
                catch (Exception e)
                {
                    logger.LogError($"Failed to install the app bundle:{Environment.NewLine}{e}");
                    return(ExitCode.PACKAGE_INSTALLATION_FAILURE);
                }

                if (!result.Succeeded)
                {
                    // use the knowledge base class to decide if the error is known, if it is, let the user know
                    // the failure reason
                    if (_errorKnowledgeBase.IsKnownInstallIssue(mainLog, out var errorMessage))
                    {
                        var msg = $"Failed to install the app bundle (exit code={result.ExitCode}): {errorMessage.Value.HumanMessage}.";
                        if (errorMessage.Value.IssueLink != null)
                        {
                            msg += $" Find more information at {errorMessage.Value.IssueLink}";
                        }

                        logger.LogError(msg);
                    }
                    else
                    {
                        logger.LogError($"Failed to install the app bundle (exit code={result.ExitCode})");
                    }

                    return(ExitCode.PACKAGE_INSTALLATION_FAILURE);
                }

                logger.LogInformation($"Application '{appBundleInfo.AppName}' was installed successfully on device '{deviceName}'");
            }

            logger.LogInformation($"Starting application '{appBundleInfo.AppName}' on " + (deviceName != null ? $"device '{deviceName}'" : target.AsString()));

            // only add the extra callback if we do know that the feature was indeed enabled
            Action <string>?logCallback = isLldbEnabled ? (l) => NotifyUserLldbCommand(logger, l) : (Action <string>?)null;

            var appRunner = new AppRunner(
                processManager,
                deviceLoader,
                simulatorLoader,
                new SimpleListenerFactory(tunnelBore),
                new CrashSnapshotReporterFactory(processManager),
                new CaptureLogFactory(),
                new DeviceLogCapturerFactory(processManager),
                new TestReporterFactory(processManager),
                new XmlResultParser(),
                mainLog,
                logs,
                new Helpers(),
                logCallback: logCallback,
                appArguments: PassThroughArguments);

            try
            {
                string resultMessage;
                TestExecutingResult testResult;
                (deviceName, testResult, resultMessage) = await appRunner.RunApp(appBundleInfo,
                                                                                 target,
                                                                                 _arguments.Timeout,
                                                                                 _arguments.LaunchTimeout,
                                                                                 deviceName,
                                                                                 verbosity : verbosity,
                                                                                 xmlResultJargon : _arguments.XmlResultJargon,
                                                                                 cancellationToken : cancellationToken,
                                                                                 skippedMethods : _arguments.SingleMethodFilters?.ToArray(),
                                                                                 skippedTestClasses : _arguments.ClassMethodFilters?.ToArray());

                switch (testResult)
                {
                case TestExecutingResult.Succeeded:
                    logger.LogInformation($"Application finished the test run successfully");
                    logger.LogInformation(resultMessage);

                    return(ExitCode.SUCCESS);

                case TestExecutingResult.Failed:
                    logger.LogInformation($"Application finished the test run successfully with some failed tests");
                    logger.LogInformation(resultMessage);

                    return(ExitCode.TESTS_FAILED);

                case TestExecutingResult.LaunchFailure:

                    if (resultMessage != null)
                    {
                        logger.LogError($"Failed to launch the application:{Environment.NewLine}" +
                                        $"{resultMessage}{Environment.NewLine}{Environment.NewLine}" +
                                        $"Check logs for more information.");
                    }
                    else
                    {
                        logger.LogError($"Failed to launch the application. Check logs for more information");
                    }

                    return(ExitCode.APP_LAUNCH_FAILURE);

                case TestExecutingResult.Crashed:

                    if (resultMessage != null)
                    {
                        logger.LogError($"Application run crashed:{Environment.NewLine}" +
                                        $"{resultMessage}{Environment.NewLine}{Environment.NewLine}" +
                                        $"Check logs for more information.");
                    }
                    else
                    {
                        logger.LogError($"Application run crashed. Check logs for more information");
                    }

                    return(ExitCode.APP_CRASH);

                case TestExecutingResult.TimedOut:
                    logger.LogWarning($"Application run timed out");

                    return(ExitCode.TIMED_OUT);

                default:

                    if (resultMessage != null)
                    {
                        logger.LogError($"Application run ended in an unexpected way: '{testResult}'{Environment.NewLine}" +
                                        $"{resultMessage}{Environment.NewLine}{Environment.NewLine}" +
                                        $"Check logs for more information.");
                    }
                    else
                    {
                        logger.LogError($"Application run ended in an unexpected way: '{testResult}'. Check logs for more information");
                    }

                    return(ExitCode.GENERAL_FAILURE);
                }
            }
            catch (NoDeviceFoundException)
            {
                logger.LogError($"Failed to find suitable device for target {target.AsString()}" +
                                (target.Platform.IsSimulator() ? Environment.NewLine + "Please make sure suitable Simulator is installed in Xcode" : string.Empty));

                return(ExitCode.DEVICE_NOT_FOUND);
            }
            catch (Exception e)
            {
                if (_errorKnowledgeBase.IsKnownTestIssue(mainLog, out var failureMessage))
                {
                    var msg = $"Application run failed:{Environment.NewLine}{failureMessage.Value.HumanMessage}.";
                    if (failureMessage.Value.IssueLink != null)
                    {
                        msg += $" Find more information at {failureMessage.Value.IssueLink}";
                    }

                    logger.LogError(msg);
                }
                else
                {
                    logger.LogError($"Application run failed:{Environment.NewLine}{e}");
                }

                return(ExitCode.APP_CRASH);
            }
            finally
            {
                mainLog.Dispose();

                if (!target.Platform.IsSimulator() && deviceName != null)
                {
                    logger.LogInformation($"Uninstalling the application '{appBundleInfo.AppName}' from device '{deviceName}'");

                    var appUninstaller  = new AppUninstaller(processManager, mainLog, verbosity);
                    var uninstallResult = await appUninstaller.UninstallApp(deviceName, appBundleInfo.BundleIdentifier, cancellationToken);

                    if (!uninstallResult.Succeeded)
                    {
                        logger.LogError($"Failed to uninstall the app bundle with exit code: {uninstallResult.ExitCode}");
                    }
                    else
                    {
                        logger.LogInformation($"Application '{appBundleInfo.AppName}' was uninstalled successfully");
                    }
                }

                if (_createdLldbFile) // clean after the setting
                {
                    File.Delete(s_mlaunchLldbConfigFile);
                }
            }
        }
예제 #16
0
        /***************************************************************************
        *
        * Private Methods
        *
        ***************************************************************************/

        private void Generate_File_Button_Click(object sender, RoutedEventArgs e)
        {
            //Check that all required fields have been filled
            if (!_validateInput())
            {
                return;
            }

            try
            {
                var t = Task.Run(() =>
                {
                    //Create file
                    FileStream writer = new FileStream(ApplicationData.Current.LocalFolder.Path + "//Your_AppInstaller_File_Name.xml", FileMode.Create);

                    AppInstaller appInstaller = new AppInstaller(App.AppInstallerFilePath, App.AppInstallerVersionNumber);

                    //Initialize DCS of type AppInstallerModel
                    XmlDictionaryWriter xdw = XmlDictionaryWriter.CreateTextWriter(writer, Encoding.UTF8);

                    DataContractSerializer appInstallerDCS = new DataContractSerializer(typeof(AppInstaller));

                    //AppInstaller Content
                    appInstallerDCS.WriteStartObject(xdw, appInstaller);
                    xdw.WriteAttributeString("xmlns", "http://schemas.microsoft.com/appx/appinstaller/2017");
                    xdw.WriteAttributeString("Uri", App.AppInstallerFilePath);
                    xdw.WriteAttributeString("Version", App.AppInstallerVersionNumber);

                    //Main Package Content
                    if (App.MainPackage.PackageType == PackageType.MSIX)
                    {
                        DataContractSerializer mainPackageDCS = new DataContractSerializer(typeof(MainPackage));
                        MainPackage mainPackage = new MainPackage(App.MainPackage.FilePath, App.MainPackage.Version, App.MainPackage.Publisher, App.MainPackage.Name, App.MainPackage.PackageType, App.MainPackage.ProcessorArchitecture, App.MainPackage.ResourceId);
                        mainPackageDCS.WriteStartObject(xdw, mainPackage);
                        xdw.WriteAttributeString("Uri", mainPackage.FilePath);
                        xdw.WriteAttributeString("Version", mainPackage.Version);
                        xdw.WriteAttributeString("Publisher", mainPackage.Publisher);
                        if (mainPackage.ResourceId != "")
                        {
                            xdw.WriteAttributeString("ResourceId", mainPackage.ResourceId);
                        }
                        if (mainPackage.ProcessorArchitecture != ProcessorArchitecture.none && mainPackage.PackageType != PackageType.msixbundle)
                        {
                            xdw.WriteAttributeString("ProcessorArchitecture", mainPackage.ProcessorArchitecture.ToString());
                        }
                        xdw.WriteAttributeString("Name", mainPackage.Name);
                        mainPackageDCS.WriteEndObject(xdw);
                    }
                    else if (App.MainPackage.PackageType == PackageType.msixbundle)
                    {
                        DataContractSerializer mainBundleDCS = new DataContractSerializer(typeof(MainBundle));
                        MainBundle mainBundle = new MainBundle(App.MainPackage.FilePath, App.MainPackage.Version, App.MainPackage.Publisher, App.MainPackage.Name);
                        mainBundleDCS.WriteStartObject(xdw, mainBundle);
                        xdw.WriteAttributeString("Uri", mainBundle.FilePath);
                        xdw.WriteAttributeString("Version", mainBundle.Version);
                        xdw.WriteAttributeString("Publisher", mainBundle.Publisher);
                        xdw.WriteAttributeString("Name", mainBundle.Name);
                        mainBundleDCS.WriteEndObject(xdw);
                    }

                    //Optional Packages Content
                    ObservableCollection <OptionalPackage> optionalPackages = App.OptionalPackages;
                    DataContractSerializer optionalPackageDCS = new DataContractSerializer(typeof(OptionalPackage));
                    if (optionalPackages.Count > 0 && App.IsOptionalPackages)
                    {
                        optionalPackageDCS.WriteStartObject(xdw, optionalPackages[0]);
                        for (int i = 0; i < optionalPackages.Count; i++)
                        {
                            //Write package or bundle element
                            if (optionalPackages[i].PackageType == PackageType.MSIX)
                            {
                                Package package = new Package(
                                    optionalPackages[i].FilePath,
                                    optionalPackages[i].Version,
                                    optionalPackages[i].Publisher,
                                    optionalPackages[i].Name,
                                    optionalPackages[i].PackageType,
                                    optionalPackages[i].ProcessorArchitecture
                                    );

                                DataContractSerializer packageDCS = new DataContractSerializer(typeof(Package));
                                packageDCS.WriteStartObject(xdw, package);
                                xdw.WriteAttributeString("Version", package.Version);
                                xdw.WriteAttributeString("Uri", package.FilePath);
                                xdw.WriteAttributeString("Publisher", package.Publisher);
                                if (package.ProcessorArchitecture != ProcessorArchitecture.none && package.PackageType != PackageType.msixbundle)
                                {
                                    xdw.WriteAttributeString("ProcessorArchitecture", package.ProcessorArchitecture.ToString());
                                }
                                xdw.WriteAttributeString("Name", package.Name);
                                packageDCS.WriteEndObject(xdw);
                            }
                            else if (optionalPackages[i].PackageType == PackageType.msixbundle)
                            {
                                Bundle bundle = new Bundle(
                                    optionalPackages[i].FilePath,
                                    optionalPackages[i].Version,
                                    optionalPackages[i].Publisher,
                                    optionalPackages[i].Name,
                                    optionalPackages[i].PackageType
                                    );

                                DataContractSerializer bundleDCS = new DataContractSerializer(typeof(Bundle));
                                bundleDCS.WriteStartObject(xdw, bundle);
                                xdw.WriteAttributeString("Version", bundle.Version);
                                xdw.WriteAttributeString("Uri", bundle.FilePath);
                                xdw.WriteAttributeString("Publisher", bundle.Publisher);
                                xdw.WriteAttributeString("Name", bundle.Name);
                                bundleDCS.WriteEndObject(xdw);
                            }
                        }
                        optionalPackageDCS.WriteEndObject(xdw);
                    }


                    //Modification Packages Content
                    ObservableCollection <ModificationPackage> modificationPackages = App.ModificationPackages;
                    DataContractSerializer modificationPackageDCS = new DataContractSerializer(typeof(ModificationPackage));
                    if (modificationPackages.Count > 0 && App.IsModificationPackages)
                    {
                        modificationPackageDCS.WriteStartObject(xdw, modificationPackages[0]);
                        for (int i = 0; i < modificationPackages.Count; i++)
                        {
                            //Write package or bundle element
                            if (modificationPackages[i].PackageType == PackageType.MSIX)
                            {
                                Package package = new Package(
                                    modificationPackages[i].FilePath,
                                    modificationPackages[i].Version,
                                    modificationPackages[i].Publisher,
                                    modificationPackages[i].Name,
                                    modificationPackages[i].PackageType,
                                    modificationPackages[i].ProcessorArchitecture
                                    );

                                DataContractSerializer packageDCS = new DataContractSerializer(typeof(Package));
                                packageDCS.WriteStartObject(xdw, package);
                                xdw.WriteAttributeString("Version", package.Version);
                                xdw.WriteAttributeString("Uri", package.FilePath);
                                xdw.WriteAttributeString("Publisher", package.Publisher);
                                if (package.ProcessorArchitecture != ProcessorArchitecture.none && package.PackageType != PackageType.msixbundle)
                                {
                                    xdw.WriteAttributeString("ProcessorArchitecture", package.ProcessorArchitecture.ToString());
                                }
                                xdw.WriteAttributeString("Name", package.Name);
                                packageDCS.WriteEndObject(xdw);
                            }
                            else if (modificationPackages[i].PackageType == PackageType.msixbundle)
                            {
                                Bundle bundle = new Bundle(
                                    modificationPackages[i].FilePath,
                                    modificationPackages[i].Version,
                                    modificationPackages[i].Publisher,
                                    modificationPackages[i].Name,
                                    modificationPackages[i].PackageType
                                    );

                                DataContractSerializer bundleDCS = new DataContractSerializer(typeof(Bundle));
                                bundleDCS.WriteStartObject(xdw, bundle);
                                xdw.WriteAttributeString("Version", bundle.Version);
                                xdw.WriteAttributeString("Uri", bundle.FilePath);
                                xdw.WriteAttributeString("Publisher", bundle.Publisher);
                                xdw.WriteAttributeString("Name", bundle.Name);
                                bundleDCS.WriteEndObject(xdw);
                            }
                        }
                        modificationPackageDCS.WriteEndObject(xdw);
                    }

                    //Related Packages Content
                    ObservableCollection <RelatedPackage> relatedPackages = App.RelatedPackages;
                    DataContractSerializer relatedPackageDCS = new DataContractSerializer(typeof(RelatedPackage));
                    if (relatedPackages.Count > 0 && App.IsRelatedPackages)
                    {
                        relatedPackageDCS.WriteStartObject(xdw, relatedPackages[0]);
                        for (int i = 0; i < relatedPackages.Count; i++)
                        {
                            //Write package or bundle element
                            if (relatedPackages[i].PackageType == PackageType.MSIX)
                            {
                                Package package = new Package(
                                    relatedPackages[i].FilePath,
                                    relatedPackages[i].Version,
                                    relatedPackages[i].Publisher,
                                    relatedPackages[i].Name,
                                    relatedPackages[i].PackageType,
                                    relatedPackages[i].ProcessorArchitecture
                                    );

                                DataContractSerializer packageDCS = new DataContractSerializer(typeof(Package));
                                packageDCS.WriteStartObject(xdw, package);
                                xdw.WriteAttributeString("Version", package.Version);
                                xdw.WriteAttributeString("Uri", package.FilePath);
                                xdw.WriteAttributeString("Publisher", package.Publisher);
                                if (package.ProcessorArchitecture != ProcessorArchitecture.none && package.PackageType != PackageType.msixbundle)
                                {
                                    xdw.WriteAttributeString("ProcessorArchitecture", package.ProcessorArchitecture.ToString());
                                }
                                xdw.WriteAttributeString("Name", package.Name);
                                packageDCS.WriteEndObject(xdw);
                            }
                            else if (relatedPackages[i].PackageType == PackageType.msixbundle)
                            {
                                Bundle bundle = new Bundle(
                                    relatedPackages[i].FilePath,
                                    relatedPackages[i].Version,
                                    relatedPackages[i].Publisher,
                                    relatedPackages[i].Name,
                                    relatedPackages[i].PackageType
                                    );

                                DataContractSerializer bundleDCS = new DataContractSerializer(typeof(Bundle));
                                bundleDCS.WriteStartObject(xdw, bundle);
                                xdw.WriteAttributeString("Version", bundle.Version);
                                xdw.WriteAttributeString("Uri", bundle.FilePath);
                                xdw.WriteAttributeString("Publisher", bundle.Publisher);
                                xdw.WriteAttributeString("Name", bundle.Name);
                                bundleDCS.WriteEndObject(xdw);
                            }
                        }
                        relatedPackageDCS.WriteEndObject(xdw);
                    }


                    //Dependency Content

                    ObservableCollection <Dependency> dependencies = App.Dependencies;
                    DataContractSerializer dependencyDCS           = new DataContractSerializer(typeof(Dependency));
                    if (dependencies.Count > 0 && App.IsDependencies)
                    {
                        dependencyDCS.WriteStartObject(xdw, dependencies[0]);
                        for (int i = 0; i < dependencies.Count; i++)
                        {
                            //Write package or bundle element
                            if (dependencies[i].PackageType == PackageType.MSIX)
                            {
                                Package package = new Package(
                                    dependencies[i].FilePath,
                                    dependencies[i].Version,
                                    dependencies[i].Publisher,
                                    dependencies[i].Name,
                                    dependencies[i].PackageType,
                                    dependencies[i].ProcessorArchitecture
                                    );

                                DataContractSerializer packageDCS = new DataContractSerializer(typeof(Package));
                                packageDCS.WriteStartObject(xdw, package);
                                xdw.WriteAttributeString("Version", package.Version);
                                xdw.WriteAttributeString("Uri", package.FilePath);
                                xdw.WriteAttributeString("Publisher", package.Publisher);
                                if (package.ProcessorArchitecture != ProcessorArchitecture.none && package.PackageType != PackageType.msixbundle)
                                {
                                    xdw.WriteAttributeString("ProcessorArchitecture", package.ProcessorArchitecture.ToString());
                                }
                                xdw.WriteAttributeString("Name", package.Name);
                                packageDCS.WriteEndObject(xdw);
                            }
                            else if (dependencies[i].PackageType == PackageType.msixbundle)
                            {
                                Bundle bundle = new Bundle(
                                    dependencies[i].FilePath,
                                    dependencies[i].Version,
                                    dependencies[i].Publisher,
                                    dependencies[i].Name,
                                    dependencies[i].PackageType
                                    );

                                DataContractSerializer bundleDCS = new DataContractSerializer(typeof(Bundle));
                                bundleDCS.WriteStartObject(xdw, bundle);
                                xdw.WriteAttributeString("Version", bundle.Version);
                                xdw.WriteAttributeString("Uri", bundle.FilePath);
                                xdw.WriteAttributeString("Publisher", bundle.Publisher);
                                xdw.WriteAttributeString("Name", bundle.Name);
                                bundleDCS.WriteEndObject(xdw);
                            }
                        }
                        dependencyDCS.WriteEndObject(xdw);
                    }


                    //Update Settings
                    UpdateSettings updateSettings = new UpdateSettings();

                    //OnLaunch
                    OnLaunch onLaunch = new OnLaunch(App.IsCheckUpdates, App.HoursBetweenUpdates);

                    if (onLaunch.IsCheckUpdates)
                    {
                        DataContractSerializer updateSettingsDCS = new DataContractSerializer(typeof(UpdateSettings));
                        updateSettingsDCS.WriteStartObject(xdw, updateSettings);

                        DataContractSerializer onLaunchDCS = new DataContractSerializer(typeof(OnLaunch));
                        onLaunchDCS.WriteStartObject(xdw, onLaunch);
                        xdw.WriteAttributeString("HoursBetweenUpdateChecks", onLaunch.HoursBetweenUpdateChecks.ToString());
                        onLaunchDCS.WriteEndObject(xdw);
                        updateSettingsDCS.WriteEndObject(xdw);
                    }


                    appInstallerDCS.WriteEndObject(xdw);
                    xdw.Dispose();
                });
                t.Wait();
            }
            catch (Exception exc)
            {
                Debug.WriteLine("The serialization operation failed: {0} StackTrace: {1}",
                                exc.Message, exc.StackTrace);
            }

            //Display dialog
            _displaySuccessDialog();
        }