示例#1
0
        public void AddLanguages(params string[] languages)
        {
            Assembly assembly = GetType().Assembly;

            foreach (string language in languages)
            {
                using (Stream stream = assembly.GetManifestResourceStream(ResourceNamePrefix + language))
                    using (var sw = new StreamReader(stream))
                    {
                        LanguageProfile profile = new LanguageProfile();

                        string json = sw.ReadToEnd();
                        JsonLanguageProfile jsonProfile = JsonConvert.DeserializeObject <JsonLanguageProfile>(json);

                        profile.Code        = jsonProfile.name;
                        profile.Frequencies = jsonProfile.freq;
                        profile.WordCount   = jsonProfile.n_words;

                        //profile.Load(stream);
                        AddLanguageProfile(profile);
                    }
            }
        }
        public override bool Execute()
        {
            try
            {
                string json = File.ReadAllText(InputFilename);
                JsonLanguageProfile jsonProfile = JsonConvert.DeserializeObject <JsonLanguageProfile>(json);

                LanguageProfile profile = new LanguageProfile();
                profile.Code        = jsonProfile.name;
                profile.Frequencies = jsonProfile.freq;
                profile.WordCount   = jsonProfile.n_words;

                using (Stream stream = new FileStream(OutputFilename, FileMode.Create, FileAccess.Write))
                    using (Stream compressedStream = new GZipStream(stream, CompressionMode.Compress))
                        profile.Save(compressedStream);

                return(true);
            }
            catch (Exception e)
            {
                Log.LogErrorFromException(e);
                return(false);
            }
        }