Ejemplo n.º 1
0
        public static void convertToBinaryCSV(string source, string target, VariabilityModel vm)
        {
            List <Configuration>        confs = ConfigurationReader.readConfigurations(source, vm);
            Dictionary <string, string> index = new Dictionary <string, string>();

            GlobalState.varModel.getOptions().ForEach(opt =>
            {
                if (opt is BinaryOption)
                {
                    index.Add(opt.Name, opt.Name);
                }
                else
                {
                    ((NumericOption)opt).getAllValues().ForEach(val => index.Add(opt.Name + "_" + (int)val, opt.Name));
                    index.Add(opt.Name, opt.Name);
                }
            });
            GlobalState.nfProperties.Keys.ToList().ForEach(k => index.Add(k, k));
            StreamWriter sw = new StreamWriter(target);

            sw.WriteLine(string.Join(";", index.Keys));
            foreach (Configuration conf in confs)
            {
                List <string> values = new List <string>();
                index.Keys.ToList().ForEach(x =>
                {
                    ConfigurationOption opt = vm.getOption(index[x]);
                    if (opt != null)
                    {
                        if (opt is BinaryOption)
                        {
                            if (conf.BinaryOptions.ContainsKey((BinaryOption)opt))
                            {
                                values.Add(conf.BinaryOptions[(BinaryOption)opt] == BinaryOption.BinaryValue.Selected ? "1" : "0");
                            }
                            else
                            {
                                values.Add("0");
                            }
                        }
                        else
                        {
                            if (x == opt.Name + "_" + (int)conf.NumericOptions[(NumericOption)opt] || x == opt.Name)
                            {
                                values.Add("1");
                            }
                            else
                            {
                                values.Add("0");
                            }
                        }
                    }
                    else
                    {
                        values.Add(conf.GetNFPValue(GlobalState.nfProperties[x]).ToString());
                    }
                });
                sw.WriteLine(string.Join(";", values));
            }
            sw.Flush();
            sw.Close();
        }