Ejemplo n.º 1
0
        private void TranslateModel(FileInfo kplFileName, FileInfo outputPathName, out FileInfo tempFolder)
        {
            KpModel kpModel = null;

            try
            {
                kpModel = KP.FromKpl(kplFileName.FullName);
            }
            catch (KplParseException kplException)
            {
                new Exception(string.Format("Failed to parse input file {0}. Reason: {1}", kplFileName, kplException.Message));
            }

            KPsystemXMLWriter kPsystemXML = new KPsystemXMLWriter(kpModel.KPsystem);

            try
            {
                Directory.CreateDirectory(outputPathName + "ite");
            }
            catch (KplParseException kplException)
            {
                new Exception(string.Format("Failed to parse create directory {0}. Reason: {1}", kplFileName, kplException.Message));
            }
            using (StreamWriter writer = new StreamWriter(outputPathName + modelGeneratedFile))
            {
                writer.Write(kPsystemXML.ToXML());
            }
            kPsystemXML.SaveCFiles(outputPathName.FullName);
            int  i = 0;
            bool b;

            do
            {
                tempFolder = new FileInfo(i == 0 ? outputPathName + "tmp" : outputPathName + "tmp" + i);
                i++;
                b = Directory.Exists(tempFolder.FullName);
            } while (b);
            try
            {
                Directory.CreateDirectory(tempFolder.FullName);
                tempFolder = new FileInfo(tempFolder + @"/");
            }
            catch (KplParseException kplException)
            {
                new Exception(string.Format("Failed to parse create directory {0}. Reason: {1}", kplFileName, kplException.Message));
            }
            using (StreamWriter writer = new StreamWriter(tempFolder + modelGeneratedFile))
            {
                writer.Write(kPsystemXML.ToXML());
            }
            kPsystemXML.SaveCFiles(tempFolder.FullName);
            using (StreamWriter writer = new StreamWriter(outputPathName + @"ite/0.xml"))
            {
                writer.Write(kPsystemXML.ToAgentsInitialConfiguration());
            }
            using (StreamWriter writer = new StreamWriter(outputPathName + @"ite/map.txt"))
            {
                writer.Write(kPsystemXML.MapObjectIds);
            }
            monitor.LogProgress(2, "KP model translated FLAME model successfully.");
        }
Ejemplo n.º 2
0
        private static void PerformFlameTransation(string[] args)
        {
            var argIndex = 1;

            if (args.Length < 2)
            {
                throw new Exception("Source file with kP system model not specified.");
            }

            string   kplFileName = args[argIndex];
            FileInfo fi          = new FileInfo(kplFileName);

            if (!fi.Exists)
            {
                throw new Exception(string.Format("File '{0}' does not exist. Please specify a valid input file.", kplFileName));
            }

            string outPathName = args[2];

            if (!Directory.Exists(outPathName))
            {
                throw new Exception(string.Format("Path '{0}' does not exist. Please specify a valid path.", kplFileName));
            }

            KpModel kpModel = null;

            try
            {
                Console.WriteLine("-- KP model is loading");
                kpModel = KP.FromKpl(kplFileName);
                Console.WriteLine("---- KP model loaded");
            }
            catch (KplParseException kplException)
            {
                throw new Exception(string.Format("Failed to parse input file {0}. Reason: {1}", kplFileName, kplException.Message));
            }

            Console.WriteLine("-- Translation to FLAME is starting");
            KPsystemXMLWriter kPsystemXML = new KPsystemXMLWriter(kpModel.KPsystem);

            try
            {
                Directory.CreateDirectory(outPathName + @"/ite");
            }
            catch (KplParseException kplException)
            {
                throw new Exception(string.Format("Failed to parse create directory {0}. Reason: {1}", kplFileName, kplException.Message));
            }
            using (StreamWriter writer = new StreamWriter(outPathName + "model_generated.xml"))
            {
                writer.Write(kPsystemXML.ToXML());
            }
            kPsystemXML.SaveCFiles(outPathName);
            using (StreamWriter writer = new StreamWriter(outPathName + @"ite/0.xml"))
            {
                writer.Write(kPsystemXML.ToAgentsInitialConfiguration());
            }
            using (StreamWriter writer = new StreamWriter(outPathName + @"ite/map.txt"))
            {
                writer.Write(kPsystemXML.MapObjectIds);
            }
            Console.WriteLine("---- KP model translated FLAME model successfully.");
        }