예제 #1
0
        public void LoadArmoryData(String simcString)
        {
            SimC simc;

            Label = "Acquiring SimC Executable";
            ThreadPool.QueueUserWorkItem((_) =>
            {
                try
                {
                    simc = SimCManager.AcquireSimC();
                }
                catch (Exception e)
                {
                    MessageBox.Show("Could not acquire SimC because of an Exception: " + e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    App.Current.Dispatcher.Invoke(() =>
                    {
                        PreloadingFailed(this, new EventArgs());
                    });
                    return;
                }
                Label = "Generating SimC Profile";
                if (!Directory.Exists("characters"))
                {
                    Directory.CreateDirectory("characters");
                }
                Regex nameRegex = new Regex("(warrior|paladin|hunter|rogue|priest|deathknight|shaman|mage|warlock|monk|druid|demonhunter)+=\"?([^\r\n\"]+)\"?");
                String name     = nameRegex.Match(simcString).Groups[2].Value;
                if (File.Exists("characters/" + name))
                {
                    File.Delete("characters/" + name);
                }
                String text = simcString + "\nsave=./characters/" + name + ".simc";
                File.WriteAllText("characters/" + name + ".simc", text);
                if (simc.RunSim("characters/" + name + ".simc"))
                {
                    Label    = "SimC Profile Generated";
                    charName = name;
                    App.Current.Dispatcher.Invoke(() =>
                    {
                        PreloadingComplete(this, new EventArgs());
                    });
                }
                else
                {
                    Label = "Failed to Generate Profile";
                    MessageBox.Show("Failed to generate profile. Please check your input and try again.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);

                    App.Current.Dispatcher.Invoke(() =>
                    {
                        PreloadingFailed(this, new EventArgs());
                    });
                }
            });
        }
예제 #2
0
        public void LoadArmoryData(String region, String server, String name)
        {
            SimC simc = null;

            Label = "Acquiring SimC Executable";
            ThreadPool.QueueUserWorkItem((_) =>
            {
                try
                {
                    simc = SimCManager.AcquireSimC();
                    if (simc == null)
                    {
                        MessageBox.Show("Could not acquire SimC. Please try again.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        App.Current.Dispatcher.Invoke(() =>
                        {
                            PreloadingFailed(this, new EventArgs());
                        });
                        return;
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show("Could not acquire SimC because of an Exception: " + e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    App.Current.Dispatcher.Invoke(() =>
                    {
                        PreloadingFailed(this, new EventArgs());
                    });
                    return;
                }
                Label    = "Generating Armory Profile";
                var text = File.ReadAllText("templates/armory.simc").Replace("%region%", region).Replace("%realm%", server).Replace("%name%", name);
                if (!Directory.Exists("characters"))
                {
                    Directory.CreateDirectory("characters");
                }
                if (File.Exists("characters/" + name + ".simc"))
                {
                    File.Delete("characters/" + name + ".simc");
                }
                File.WriteAllText("characters/" + name + ".simc", text);
                if (simc.RunSim("characters/" + name + ".simc"))
                {
                    Label    = "Armory Profile Generated";
                    charName = name;
                    App.Current.Dispatcher.Invoke(() =>
                    {
                        PreloadingComplete(this, new EventArgs());
                    });
                }
                else
                {
                    Label = "Failed to Generate Profile";
                    MessageBox.Show("Failed to generate profile. Please check your input and try again.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);

                    App.Current.Dispatcher.Invoke(() =>
                    {
                        PreloadingFailed(this, new EventArgs());
                    });
                }
            });
        }
예제 #3
0
        public void ExecuteSimRun(List <string> profiles, Regex filenameRegex, int processCount, EventHandler failureHandler, EventHandler successHandler, String writeDir, String resultDir, Boolean hasGuid)
        {
            RunningComplete += successHandler;
            RunningFailed   += failureHandler;
            SimC simc;

            Total     = profiles.Count();
            Completed = 0;
            Label     = "Acquiring SimC Executable";
            var topHandle = 0;

            if (0 == Total)
            {
                App.Current.Dispatcher.Invoke(() =>
                {
                    Label = "All Sims Completed";
                    RunningComplete(this, new EventArgs());
                });
                return;
            }
            ThreadPool.QueueUserWorkItem((_) =>
            {
                try
                {
                    simc = SimCManager.AcquireSimC();
                    for (int i = 0; i < processCount; i++)
                    {
                        Label = "Running Simc Profiles";
                        ThreadPool.QueueUserWorkItem((__) =>
                        {
                            while (true)
                            {
                                var profile = "";
                                lock (simLock)
                                {
                                    if (topHandle == profiles.Count)
                                    {
                                        return;
                                    }
                                    profile = profiles[topHandle];
                                    topHandle++;
                                }
                                var fileName = filenameRegex.Match(profile).Groups[1].Value;
                                if (!Directory.Exists(resultDir + Path.DirectorySeparatorChar))
                                {
                                    Directory.CreateDirectory(resultDir + Path.DirectorySeparatorChar);
                                }


                                if (hasGuid)
                                {
                                    guid  = fileName.Split(Path.DirectorySeparatorChar)[0];
                                    Label = "Running Sim Set " + guid;
                                    if (!Directory.Exists(writeDir + Path.DirectorySeparatorChar + guid))
                                    {
                                        Directory.CreateDirectory(writeDir + Path.DirectorySeparatorChar + guid);
                                    }
                                    if (!Directory.Exists(resultDir + Path.DirectorySeparatorChar + guid))
                                    {
                                        Directory.CreateDirectory(resultDir + Path.DirectorySeparatorChar + guid);
                                    }
                                }

                                File.WriteAllText(writeDir + Path.DirectorySeparatorChar + fileName + ".simc", profile);
                                if (simc.RunSim(writeDir + Path.DirectorySeparatorChar + fileName + ".simc"))
                                {
                                    Completed++;
                                    App.Current.Dispatcher.Invoke(() =>
                                    {
                                        if (Completed == Total)
                                        {
                                            Label = "All Sims Completed";
                                            RunningComplete(this, new EventArgs());
                                            WindowCleanup(this, new EventArgs());
                                            RunningComplete -= successHandler;
                                            RunningFailed   -= failureHandler;
                                        }
                                    });
                                }
                                else
                                {
                                    Label = "Failed to Run a Sim";
                                    MessageBox.Show("Sims failed to be ran. Try again.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                                    App.Current.Dispatcher.Invoke(() =>
                                    {
                                        RunningFailed(this, new EventArgs());
                                        WindowCleanup(this, new EventArgs());
                                        RunningComplete -= successHandler;
                                        RunningFailed   -= failureHandler;
                                    });
                                    return;
                                }
                            }
                        });
                    }
                }
                catch (Exception e)
                {
                    Label = "Failed to Run a Sim";
                    MessageBox.Show("Sims failed to be ran because SimC could not be acquired. Try again.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    App.Current.Dispatcher.Invoke(() =>
                    {
                        RunningFailed(this, new EventArgs());
                        WindowCleanup(this, new EventArgs());
                        RunningComplete -= successHandler;
                        RunningFailed   -= failureHandler;
                    });
                    return;
                }
            });
        }