Exemplo n.º 1
0
        // Note: This is run on a separate thread, mostly so the status can be updated while it is being run
        void ProcessClasses(Object stateInfo)
        {
            bool successful = false;

            do
            {
                ClassData classData = (ClassData)stateInfo;

                if (classData.Classes == null || classData.Classes.Count == 0)
                {
                    AddStatus("There were no classes specified to process");
                    break;
                }

                try
                {
                    if (!Directory.Exists(classData.OutputDirectory))
                    {
                        AddStatus(string.Format("Creating output directory {0}", classData.OutputDirectory));
                        Directory.CreateDirectory(classData.OutputDirectory);
                        AddStatus(string.Format("Created output directory {0}", classData.OutputDirectory));
                    }
                }
                catch (Exception ex)
                {
                    AddStatus(string.Format("Failed trying to create output directory {0}: {1}", classData.OutputDirectory, ex));
                    break;
                }

                bool allClassesSuccessful = true;
                AddStatus(string.Format("Processing {0} classes", classData.Classes.Count));
                foreach (Object itemObject in classData.Classes)
                {
                    Type   type     = (Type)itemObject;
                    string filename = classData.FilenameFormat;
                    filename = filename.Replace("{ClassName}", type.Name);
                    filename = Path.Combine(classData.OutputDirectory, filename);

                    AddStatus(string.Format("Creating class description for {0} in {1}", type.FullName, filename));
                    try
                    {
                        ConfigMessageSerializerClass.WriteDefaultToFile(filename, type);
                        AddStatus(string.Format("Created class description for {0} in {1}", type.FullName, filename));
                    }
                    catch (Exception ex)
                    {
                        AddStatus(string.Format("Failed trying to create file for {0}: {1}", type.FullName, ex));
                        allClassesSuccessful = false;
                    }
                }

                successful = allClassesSuccessful;
            } while (false);

            AddStatus("Done processing classes");
            ProcessingComplete(successful);
        }
Exemplo n.º 2
0
        void DoProcessing()
        {
            ClassData classData = new ClassData();

            classData.Classes         = listBoxClasses.SelectedItems.Cast <Object>().ToList();
            classData.FilenameFormat  = textBoxOutputFilename.Text;
            classData.OutputDirectory = textBoxOutputDirectory.Text;

            ThreadPool.QueueUserWorkItem(ProcessClasses, classData);
        }