Ejemplo n.º 1
0
 private bool TryValidatePackagesFile(string packagesFile, out IList <string> appPackages)
 {
     appPackages = new List <string>();
     if (!packagesFile.EndsWith(".zip"))
     {
         Logger.Error(string.Format(StringProvider.GetString(Strings.ValidatePackageNoZip), packagesFile));
         return(false);
     }
     if (!File.Exists(packagesFile))
     {
         Logger.Error(string.Format(StringProvider.GetString(Strings.ValidatePackageNonExistant), packagesFile));
         return(false);
     }
     using (var archive = new ZipArchive(new FileStream(packagesFile, FileMode.Open)))
     {
         var validPackages = archive.Entries.Where(x => x.Name.EndsWith(".appxupload"));
         if (!validPackages.Any())
         {
             Logger.Error(string.Format(StringProvider.GetString(Strings.ValidatePackageNoPackages), packagesFile));
             return(false);
         }
         foreach (var entry in archive.Entries.Where(x => x.Name.EndsWith(".appxupload")))
         {
             appPackages.Add(entry.Name);
         }
     }
     return(true);
 }
Ejemplo n.º 2
0
        public async Task TestSubmitSuccess()
        {
            var client = A.Fake <IStoreClient>();

            A.CallTo(() => client.Login("myId", "myKey", "myTenantId")).Returns(Task.Factory.StartNew(() => true));
            var json = File.ReadAllText($"{this.GetExecutingPath()}\\Files\\submission.json");

            A.CallTo(() => client.CreateSubmission("myapp")).Returns(Task.Factory.StartNew(() => new Tuple <JObject, HttpStatusCode>(JObject.Parse(json), HttpStatusCode.Created)));
            var updatedJson = File.ReadAllText($"{this.GetExecutingPath()}\\Files\\submissionupdate.json");

            A.CallTo(() => client.UpdateSubmission("myapp", "submissionid", JObject.Parse(updatedJson).ToString())).Returns(Task.Factory.StartNew(() => true));
            A.CallTo(() => client.Commit("myapp", "submissionid")).Returns(Task.Factory.StartNew(() => true));
            var logger              = new MockLogger();
            var stringprovider      = new StringProvider();
            var command             = new SubmitCommand(client, logger, stringprovider);
            var packageFileLocation = $"{this.GetExecutingPath()}\\Files\\package.zip";
            var options             = new SubmitOptions
            {
                PackagesFile = packageFileLocation,
                Application  = "myapp",
                ConfigFile   = $"{this.GetExecutingPath()}\\Files\\.valid_config"
            };
            var result = await command.CreateSubmission(options);

            result.Should().BeGreaterOrEqualTo(0, "the zip file contains app packages and everything worked out ok");
            logger.Message.Last().Should().Be(stringprovider.GetString(Strings.SubmitCommitSuccess), "everything went according to plan");
            A.CallTo(() => client.Login("myId", "myKey", "myTenantId")).MustHaveHappened();
            A.CallTo(() => client.CreateSubmission("myapp")).MustHaveHappened();
            A.CallTo(() => client.UpdateSubmission("myapp", "submissionid", JObject.Parse(updatedJson).ToString())).MustHaveHappened();
            A.CallTo(() => client.Commit("myapp", "submissionid")).MustHaveHappened();
        }
Ejemplo n.º 3
0
        public async Task TestSubmitNewFlightSubmissionFailure()
        {
            var client = A.Fake <IStoreClient>();

            A.CallTo(() => client.Login("myId", "myKey", "myTenantId")).Returns(Task.Factory.StartNew(() => true));
            var json = File.ReadAllText($"{this.GetExecutingPath()}\\Files\\submission.json");

            A.CallTo(() => client.CreateSubmission("myapp", "myflight")).Returns(Task.Factory.StartNew(() => new Tuple <JObject, HttpStatusCode>(JObject.Parse(json), HttpStatusCode.NotFound)));
            var logger              = new MockLogger();
            var stringprovider      = new StringProvider();
            var command             = new SubmitCommand(client, logger, stringprovider);
            var packageFileLocation = $"{this.GetExecutingPath()}\\Files\\package.zip";
            var options             = new SubmitOptions
            {
                PackagesFile = packageFileLocation,
                Application  = "myapp",
                ConfigFile   = $"{this.GetExecutingPath()}\\Files\\.valid_config",
                Flight       = "myflight"
            };
            var result = await command.CreateSubmission(options);

            result.Should().BeNegative("the creation of submission failed");
            logger.Message.Last().Should().Be(stringprovider.GetString(Strings.VerifyParameters), "there's something wrong with the parameters");
            A.CallTo(() => client.Login("myId", "myKey", "myTenantId")).MustHaveHappened();
            A.CallTo(() => client.CreateSubmission("myapp", "myflight")).MustHaveHappened();
        }
Ejemplo n.º 4
0
        public async Task TestCommitFlightFailure()
        {
            var client = A.Fake <IStoreClient>();

            A.CallTo(() => client.Login("myId", "myKey", "myTenantId")).Returns(Task.Factory.StartNew(() => true));
            var json = File.ReadAllText($"{this.GetExecutingPath()}\\Files\\flight.json");

            A.CallTo(() => client.CreateSubmission("myapp", "myflight")).Returns(Task.Factory.StartNew(() => new Tuple <JObject, HttpStatusCode>(JObject.Parse(json), HttpStatusCode.Created)));
            var updatedJson = File.ReadAllText($"{this.GetExecutingPath()}\\Files\\flightupdate.json");

            A.CallTo(() => client.UpdateSubmission("myapp", "myflight", "submissionid", JObject.Parse(updatedJson).ToString())).Returns(Task.Factory.StartNew(() => true));
            A.CallTo(() => client.Commit("myapp", "myflight", "submissionid")).Returns(Task.Factory.StartNew(() => false));
            var logger              = new MockLogger();
            var stringprovider      = new StringProvider();
            var command             = new SubmitCommand(client, logger, stringprovider);
            var packageFileLocation = $"{this.GetExecutingPath()}\\Files\\package.zip";
            var options             = new SubmitOptions
            {
                PackagesFile = packageFileLocation,
                Application  = "myapp",
                ConfigFile   = $"{this.GetExecutingPath()}\\Files\\.valid_config",
                Flight       = "myflight"
            };
            var result = await command.CreateSubmission(options);

            result.Should().BeNegative("committing the submission failed");
            logger.Message.Last().Should().Be(stringprovider.GetString(Strings.SubmitCommitError), "committing the submission failed");
            A.CallTo(() => client.Login("myId", "myKey", "myTenantId")).MustHaveHappened();
            A.CallTo(() => client.CreateSubmission("myapp", "myflight")).MustHaveHappened();
            A.CallTo(() => client.UpdateSubmission("myapp", "myflight", "submissionid", JObject.Parse(updatedJson).ToString())).MustHaveHappened();
            A.CallTo(() => client.Commit("myapp", "myflight", "submissionid")).MustHaveHappened();
        }
Ejemplo n.º 5
0
 protected override Task <int> CommandLogic()
 {
     return(Task <int> .Factory.StartNew(() =>
     {
         Logger.Info(StringProvider.GetString(Strings.CommandNotYetImplemented));
         return -1;
     }));
 }
        private void ResetStatExecuted()
        {
            string title   = StringProvider.GetString("Stat_Reset_Title");
            string message = StringProvider.GetString("Stat_Reset_Message");

            if (MessageBoxHelper.ShowYesNo(title, message))
            {
                service.ResetStatistics();
                OnPropertyChanged("");
            }
        }
Ejemplo n.º 7
0
        private async Task SetupDependencies()
        {
            var stringProvider = new StringProvider(Windows.ApplicationModel.Resources.ResourceLoader.GetForViewIndependentUse());
            var exportProvider = new ControlPaletteExportProvider();

            var paletteModel = new ControlPaletteModel();
            await paletteModel.InitializeData(stringProvider, stringProvider.GetString("ControlPaletteDataPath"));

            var navModel = new MainNavModel(stringProvider);
            await navModel.InitializeData(stringProvider.GetString("MainDataPath"), paletteModel, exportProvider);

            lock (_initLock)
            {
                _stringProvider = stringProvider;
                _exportProvider = exportProvider;

                _paletteModel = paletteModel;

                _mainNavModel      = navModel;
                _outerNavViewModel = new OuterNavViewModel(_mainNavModel.NavItems, _mainNavModel.DefaultNavItem);
            }
        }
Ejemplo n.º 8
0
        private async Task <bool> UpdateSubmission(SubmitOptions submitOptions, string submissionId, JObject body)
        {
            bool updateResult;

            Logger.InfoWithProgress(StringProvider.GetString(Strings.SubmitUpdating));
            if (string.IsNullOrWhiteSpace(submitOptions.Flight))
            {
                updateResult = await Client.UpdateSubmission(submitOptions.Application, submissionId, body.ToString());
            }
            else
            {
                updateResult = await Client.UpdateSubmission(submitOptions.Application, submitOptions.Flight, submissionId, body.ToString());
            }
            Logger.StopProgress();
            return(updateResult);
        }
Ejemplo n.º 9
0
        public async Task TestSubmitZipfileNoPackages()
        {
            var client = A.Fake <IStoreClient>();

            A.CallTo(() => client.Login("myId", "myKey", "myTenantId")).Returns(Task.Factory.StartNew(() => true));
            var logger              = new MockLogger();
            var stringprovider      = new StringProvider();
            var command             = new SubmitCommand(client, logger, stringprovider);
            var packageFileLocation = $"{this.GetExecutingPath()}\\Files\\nopackage.zip";
            var options             = new SubmitOptions
            {
                PackagesFile = packageFileLocation,
                Application  = "myapp",
                ConfigFile   = $"{this.GetExecutingPath()}\\Files\\.valid_config"
            };
            var result = await command.CreateSubmission(options);

            result.Should().BeNegative("the zip file does not contain app packages");
            logger.Message.Last().Should().Be(Format(stringprovider.GetString(Strings.ValidatePackageNoPackages), packageFileLocation), "The provided zip file does not contain any packages");
            A.CallTo(() => client.Login("myId", "myKey", "myTenantId")).MustHaveHappened();
        }
Ejemplo n.º 10
0
        private async Task <JObject> NewSubmission(SubmitOptions submitOptions)
        {
            Tuple <JObject, HttpStatusCode> deployResult;

            Logger.InfoWithProgress(StringProvider.GetString(Strings.SubmitCreating));
            if (string.IsNullOrWhiteSpace(submitOptions.Flight))
            {
                deployResult = await Client.CreateSubmission(submitOptions.Application);
            }
            else
            {
                deployResult = await Client.CreateSubmission(submitOptions.Application, submitOptions.Flight);
            }
            Logger.StopProgress();
            if (deployResult.Item2.Equals(HttpStatusCode.Created))
            {
                return(deployResult.Item1);
            }
            Logger.Error(StringProvider.GetString(Strings.SubmitCreateError));
            Logger.Info(StringProvider.GetString(Strings.VerifyParameters));
            return(null);
        }
        /// <summary>
        /// Convert a travel type to text.
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value != null)
            {
                TravelType travelType = (TravelType)value;
                switch (travelType)
                {
                case TravelType.Unknown:
                    return(StringProvider.GetString("TravelTypeUnkown"));

                case TravelType.OneWay:
                    return(StringProvider.GetString("TravelTypeOneWay"));

                case TravelType.Roundtrip:
                    return(StringProvider.GetString("TravelTypeRoundTrip"));

                default:
                    break;
                }
            }

            return(null);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Flow:
        ///  <para>* Create new submission using POST (Success == HttpStatusCode 201 Created)</para>
        ///  <para>* Get the JSON object and mark all packages as PendingDelete</para>
        ///  <para>* Add the new packages from the zip as PendingUpload</para>
        ///  <para>* Upload the changes using PUT (entire JSON in body)</para>
        ///  <para>* Upload the zip file</para>
        ///  <para>* Commit the changes to trigger the submission</para>
        /// </summary>
        /// <returns>StatusCode of the command.</returns>
        protected override async Task <int> CommandLogic()
        {
            IList <string> packages;

            if (!TryValidatePackagesFile(_submitOptions.PackagesFile, out packages))
            {
                return(-1);
            }
            //Create new submission using POST(Success == HttpStatusCode 201 Created)
            var submission = await NewSubmission(_submitOptions);

            if (submission == null)
            {
                return(-1);
            }
            // Get the JSON object and mark all packages as PendingDelete
            submission = UpdatePackages(_submitOptions, submission, packages);
            // Add the changes using PUT(entire JSON in body)
            var idReference   = string.IsNullOrWhiteSpace(_submitOptions.Flight) ? "id" : "submissionId";
            var updateSuccess = await UpdateSubmission(_submitOptions, submission[idReference].ToString(), submission);

            if (updateSuccess)
            {
                // Upload the zip file
                Logger.InfoWithProgress(StringProvider.GetString(Strings.SubmitUploading));
                await Client.UploadPackages(_submitOptions.PackagesFile, submission["fileUploadUrl"].ToString());

                Logger.StopProgress();
                // Commit the changes
                var commitResult = await CommitSubmission(_submitOptions, submission[idReference].ToString());

                return(commitResult ? 0 : -1);
            }
            Logger.Error(StringProvider.GetString(Strings.SubmitUpdateError));
            return(-1);
        }
Ejemplo n.º 13
0
        private async Task <bool> CommitSubmission(SubmitOptions submitOptions, string submissionId)
        {
            bool commitResult;

            Logger.InfoWithProgress(StringProvider.GetString(Strings.SubmitCommitting));
            if (string.IsNullOrWhiteSpace(submitOptions.Flight))
            {
                commitResult = await Client.Commit(submitOptions.Application, submissionId);
            }
            else
            {
                commitResult = await Client.Commit(submitOptions.Application, submitOptions.Flight, submissionId);
            }
            Logger.StopProgress();
            if (commitResult)
            {
                Logger.Info(StringProvider.GetString(Strings.SubmitCommitSuccess));
            }
            else
            {
                Logger.Error(StringProvider.GetString(Strings.SubmitCommitError));
            }
            return(commitResult);
        }
Ejemplo n.º 14
0
 private void UpdateElement(int year)
 {
     //GD.Print("Year changed");
     _yearLabel.Text = _stringProvider.GetString("TOOLBAR_YEAR", _gameController.CurrentYear);
 }
Ejemplo n.º 15
0
        static void Main(string[] args)
        {
            var stringProvider = new StringProvider();

            Console.WriteLine(stringProvider.GetString());
        }
Ejemplo n.º 16
0
        public async Task TestConfigFailure(string fileName, Strings expectedMessage)
        {
            var client         = A.Fake <IStoreClient>();
            var logger         = new MockLogger();
            var stringprovider = new StringProvider();
            var command        = new MockCommandBase(client, logger, stringprovider);
            var options        = new OptionsBase
            {
                ConfigFile = $"{this.GetExecutingPath()}\\Files\\{fileName}"
            };
            var result = await command.DoCommand(options);

            logger.Message.ElementAt(logger.Message.Count - 2).Should().Be(string.Format(stringprovider.GetString(expectedMessage), options.ConfigFile), "because there is something wrong with the config file");
            result.Should().BeNegative("the config file is invalid");
        }
Ejemplo n.º 17
0
        public async Task InitializeData(StringProvider stringProvider, string dataPath)
        {
            _stringProvider = stringProvider;

            StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(dataPath));

            string dataString = await FileIO.ReadTextAsync(file);

            JsonObject rootObject = JsonObject.Parse(dataString);

            _whiteColor = new ColorPaletteEntry(Colors.White, _stringProvider.GetString("DarkThemeTextContrastTitle"), null, FluentEditorShared.Utils.ColorStringFormat.PoundRGB, null);
            _blackColor = new ColorPaletteEntry(Colors.Black, _stringProvider.GetString("LightThemeTextContrastTitle"), null, FluentEditorShared.Utils.ColorStringFormat.PoundRGB, null);

            var lightRegionNode = rootObject["LightRegion"].GetObject();

            _lightRegion = ColorPaletteEntry.Parse(lightRegionNode, null);

            var darkRegionNode = rootObject["DarkRegion"].GetObject();

            _darkRegion = ColorPaletteEntry.Parse(darkRegionNode, null);

            var lightBaseNode = rootObject["LightBase"].GetObject();

            _lightBase = ColorPalette.Parse(lightBaseNode, null);

            var darkBaseNode = rootObject["DarkBase"].GetObject();

            _darkBase = ColorPalette.Parse(darkBaseNode, null);

            var lightPrimaryNode = rootObject["LightPrimary"].GetObject();

            _lightPrimary = ColorPalette.Parse(lightPrimaryNode, null);

            var darkPrimaryNode = rootObject["DarkPrimary"].GetObject();

            _darkPrimary = ColorPalette.Parse(darkPrimaryNode, null);

            _presets = new ObservableList <Preset>();
            if (rootObject.ContainsKey("Presets"))
            {
                var presetsNode = rootObject["Presets"].GetArray();
                foreach (var presetNode in presetsNode)
                {
                    _presets.Add(Preset.Parse(presetNode.GetObject()));
                }
            }
            if (_presets.Count >= 1)
            {
                ApplyPreset(_presets[0]);
            }

            UpdateActivePreset();

            _lightRegion.ContrastColors = new List <ContrastColorWrapper>()
            {
                new ContrastColorWrapper(_whiteColor, false, false), new ContrastColorWrapper(_blackColor, true, true), new ContrastColorWrapper(_lightBase.BaseColor, true, false), new ContrastColorWrapper(_lightPrimary.BaseColor, true, false)
            };
            _darkRegion.ContrastColors = new List <ContrastColorWrapper>()
            {
                new ContrastColorWrapper(_whiteColor, true, true), new ContrastColorWrapper(_blackColor, false, false), new ContrastColorWrapper(_darkBase.BaseColor, true, false), new ContrastColorWrapper(_darkPrimary.BaseColor, true, false)
            };
            _lightBase.ContrastColors = new List <ContrastColorWrapper>()
            {
                new ContrastColorWrapper(_whiteColor, false, false), new ContrastColorWrapper(_blackColor, true, true), new ContrastColorWrapper(_lightRegion, true, false), new ContrastColorWrapper(_lightPrimary.BaseColor, true, false)
            };
            _darkBase.ContrastColors = new List <ContrastColorWrapper>()
            {
                new ContrastColorWrapper(_whiteColor, true, true), new ContrastColorWrapper(_blackColor, false, false), new ContrastColorWrapper(_darkRegion, true, false), new ContrastColorWrapper(_darkPrimary.BaseColor, true, false)
            };
            _lightPrimary.ContrastColors = new List <ContrastColorWrapper>()
            {
                new ContrastColorWrapper(_whiteColor, true, true), new ContrastColorWrapper(_blackColor, false, false), new ContrastColorWrapper(_lightRegion, true, false), new ContrastColorWrapper(_lightBase.BaseColor, true, false)
            };
            _darkPrimary.ContrastColors = new List <ContrastColorWrapper>()
            {
                new ContrastColorWrapper(_whiteColor, true, true), new ContrastColorWrapper(_blackColor, false, false), new ContrastColorWrapper(_darkRegion, true, false), new ContrastColorWrapper(_darkBase.BaseColor, true, false)
            };

            _lightColorMappings = ColorMapping.ParseList(rootObject["LightPaletteMapping"].GetArray(), _lightRegion, _darkRegion, _lightBase, _darkBase, _lightPrimary, _darkPrimary, _whiteColor, _blackColor);
            _lightColorMappings.Sort((a, b) =>
            {
                return(a.Target.ToString().CompareTo(b.Target.ToString()));
            });

            _darkColorMappings = ColorMapping.ParseList(rootObject["DarkPaletteMapping"].GetArray(), _lightRegion, _darkRegion, _lightBase, _darkBase, _lightPrimary, _darkPrimary, _whiteColor, _blackColor);
            _darkColorMappings.Sort((a, b) =>
            {
                return(a.Target.ToString().CompareTo(b.Target.ToString()));
            });

            _lightRegion.ActiveColorChanged            += PaletteEntry_ActiveColorChanged;
            _darkRegion.ActiveColorChanged             += PaletteEntry_ActiveColorChanged;
            _lightBase.BaseColor.ActiveColorChanged    += PaletteEntry_ActiveColorChanged;
            _darkBase.BaseColor.ActiveColorChanged     += PaletteEntry_ActiveColorChanged;
            _lightPrimary.BaseColor.ActiveColorChanged += PaletteEntry_ActiveColorChanged;
            _darkPrimary.BaseColor.ActiveColorChanged  += PaletteEntry_ActiveColorChanged;
            foreach (var entry in _lightBase.Palette)
            {
                entry.ActiveColorChanged += PaletteEntry_ActiveColorChanged;
            }
            foreach (var entry in _darkBase.Palette)
            {
                entry.ActiveColorChanged += PaletteEntry_ActiveColorChanged;
            }
            foreach (var entry in _lightPrimary.Palette)
            {
                entry.ActiveColorChanged += PaletteEntry_ActiveColorChanged;
            }
            foreach (var entry in _darkPrimary.Palette)
            {
                entry.ActiveColorChanged += PaletteEntry_ActiveColorChanged;
            }

            if (_lightRegion.Description == null)
            {
                _lightRegion.Description = GenerateMappingDescription(_lightRegion, _lightColorMappings);
            }
            if (_darkRegion.Description == null)
            {
                _darkRegion.Description = GenerateMappingDescription(_darkRegion, _darkColorMappings);
            }
            foreach (var entry in _lightBase.Palette)
            {
                if (entry.Description == null)
                {
                    entry.Description = GenerateMappingDescription(entry, _lightColorMappings);
                }
            }
            foreach (var entry in _darkBase.Palette)
            {
                if (entry.Description == null)
                {
                    entry.Description = GenerateMappingDescription(entry, _darkColorMappings);
                }
            }
            foreach (var entry in _lightPrimary.Palette)
            {
                if (entry.Description == null)
                {
                    entry.Description = GenerateMappingDescription(entry, _lightColorMappings);
                }
            }
            foreach (var entry in _darkPrimary.Palette)
            {
                if (entry.Description == null)
                {
                    entry.Description = GenerateMappingDescription(entry, _darkColorMappings);
                }
            }
        }