private void buttonSaveAlignment_Click(object sender, EventArgs e) { if (!alignment_.IsAligned) { return; } SaveFileDialog savefile = new SaveFileDialog(); savefile.FileName = MakeProfileName(); savefile.Filter = "XML files (*.xml)|*.xml|All files (*.*)|*.*"; try { DialogResult res = savefile.ShowDialog(); if (res != DialogResult.OK) { return; } XmlProfile profile = new XmlProfile(savefile.FileName); profile.AddTypes = AddType.Short; using (profile.Buffer()) { profile.SetValue("entries", "AlignmentStars", alignment_.Stars); profile.SetValue("entries", "AlignmentEquAxis", alignment_.EquAxis); } } catch (Exception ex) { MessageBox.Show(ex.Message); return; } }
private void buttonSave_Click(object sender, EventArgs e) { if (settings_ == null) { return; } SaveFileDialog savefile = new SaveFileDialog(); savefile.InitialDirectory = Application.StartupPath + @"\"; savefile.FileName = MakeProfileName(); savefile.Filter = "XML files (*.xml)|*.xml|All files (*.*)|*.*"; try { DialogResult res = savefile.ShowDialog(); if (res != DialogResult.OK) { return; } XmlProfile profile = new XmlProfile(savefile.FileName); profile.AddTypes = AddType.Short; using (profile.Buffer()) { { ScopeGotoClient.MotorOptions opt = settings_.AltMotorOptions; if (opt.Valid) { profile.SetValue("entriesGoTo", "AltMotorOptions", opt); } opt = settings_.AzmMotorOptions; if (opt.Valid) { profile.SetValue("entriesGoTo", "AzmMotorOptions", opt); } } { ScopeGotoClient.AdapterOptions opt = settings_.AltAdapterOptions; if (opt.Valid) { profile.SetValue("entriesGoTo", "AltAdapterOptions", opt); } opt = settings_.AzmAdapterOptions; if (opt.Valid) { profile.SetValue("entriesGoTo", "AzmAdapterOptions", opt); } } } } catch (Exception ex) { MessageBox.Show(ex.Message); return; } }
/// <summary> /// /// </summary> /// <param name="userName"></param> /// <param name="svc"></param> protected internal void GetPropertyValues(string userName, SettingsPropertyValueCollection svc, bool isAuthenticated) { XmlProfile profile = null; if (isAuthenticated) { profile = this.Store.GetByUserName(userName); } else { Guid g = new Guid(userName); profile = this.Store.GetByUserKey(g); } if (profile != null) { /// decode Encoding encoding = Encoding.UTF8; string[] names = encoding.GetString(Convert.FromBase64String(profile.Names)).Split(':'); byte[] valuesBinary = null; if (!string.IsNullOrEmpty(profile.ValuesBinary)) { valuesBinary = Convert.FromBase64String(profile.ValuesBinary); } string valuesString = null; if (!string.IsNullOrEmpty(profile.ValuesString)) { valuesString = encoding.GetString(Convert.FromBase64String(profile.ValuesString)); } /// ParseProfileData(names, valuesString, valuesBinary, svc); } }
public void SaveProfile(bool silent) { if (!Environment.GetCommandLineArgs().Contains("--disable-save")) { if ((txtInputDirectory.Text != string.Empty) && (txtOutputDirectory.Text != string.Empty)) { try { SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "XML Profile|*.prof"; if (sfd.ShowDialog() == DialogResult.OK) { var subReq = new XmlProfile(); subReq.Locations = new AppLocations { Cr2Folder = txtInputDirectory.Text, JpgFolder = txtOutputDirectory.Text }; subReq.Options = Settings; subReq.Watermark = WmContext; subReq.AppInfo.AppVersion = GetBuildInfo(false); XmlProfile.SaveFile(subReq, sfd.FileName); if (!silent) { MessageBox.Show("Successfully saved profile!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } catch (Exception ex) { if (!silent) { MessageBox.Show(ex.ToString(), "Error in saving XML Profile", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { if (!silent) { MessageBox.Show("You need to specify input and output folders before saving a profile", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
private void buttonLoadAlignment_Click(object sender, EventArgs e) { OpenFileDialog openfile = new OpenFileDialog(); openfile.InitialDirectory = Application.StartupPath + @"\"; openfile.Filter = "XML files (*.xml)|*.xml|All files (*.*)|*.*"; openfile.FilterIndex = 1; openfile.RestoreDirectory = true; try { DialogResult res = openfile.ShowDialog(); if (res != DialogResult.OK) { return; } XmlProfile profile = new XmlProfile(openfile.FileName); AlignStar[] stars = (AlignStar[])profile.GetValue("entries", "AlignmentStars", null, typeof(AlignStar[])); Vect3 alignmentEquAxis = (Vect3)profile.GetValue("entries", "AlignmentEquAxis", new Vect3()); if (stars != null) { alignment_ = new DSCAlignment(alignmentEquAxis, Precisions.Default); for (int i = 0; i < stars.Length; ++i) { alignment_.AddStar(stars[i]); } alignment_.ForceAlignment(); AlignmentChanged(); } } catch (Exception ex) { MessageBox.Show(ex.Message); return; } }
private void buttonApply_Click(object sender, EventArgs e) { if (!parent_.CanConfigureMotorsAndAdapters() || settings_ == null) { return; } OpenFileDialog openfile = new OpenFileDialog(); //openfile.InitialDirectory = Application.StartupPath + @"\"; openfile.Filter = "XML files (*.xml)|*.xml|All files (*.*)|*.*"; openfile.FilterIndex = 1; openfile.RestoreDirectory = true; try { DialogResult res = openfile.ShowDialog(); if (res != DialogResult.OK) { return; } XmlProfile profile = new XmlProfile(openfile.FileName); parent_.ConfigureMotor(ScopeGotoClient.M_ALT, (ScopeGotoClient.MotorOptions)profile.GetValue("entriesGoTo", "AltMotorOptions", new ScopeGotoClient.MotorOptions())); parent_.ConfigureMotor(ScopeGotoClient.M_AZM, (ScopeGotoClient.MotorOptions)profile.GetValue("entriesGoTo", "AzmMotorOptions", new ScopeGotoClient.MotorOptions())); parent_.ConfigureAdapter(ScopeGotoClient.A_ALT, (ScopeGotoClient.AdapterOptions)profile.GetValue("entriesGoTo", "AltAdapterOptions", new ScopeGotoClient.AdapterOptions())); parent_.ConfigureAdapter(ScopeGotoClient.A_AZM, (ScopeGotoClient.AdapterOptions)profile.GetValue("entriesGoTo", "AzmAdapterOptions", new ScopeGotoClient.AdapterOptions())); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } }
protected override bool Execute(IIntegrationResult result) { result.BuildProgressInformation.SignalStartRunTask( string.Format("Running virtual machine profile '{0}' declared in configuration file '{1}'.", Profile, Configuration)); string configurationFullPath = result.BaseFromWorkingDirectory(Configuration); XmlConfiguration xmlConfiguration = ConfigurationFileHelper.LoadConfiguration(configurationFullPath); XmlProfile xmlProfile = xmlConfiguration.GetProfileById(Profile); if (xmlProfile == null) { throw new BuilderException(this, string.Format("Did not find profile '{0}' in configuration file '{1}'.", Profile, configurationFullPath)); } global::VMTool.Core.Profile profile = xmlProfile.ToProfile(); using (CCNetController controller = new CCNetController(profile)) { controller.ConnectionTimeout = TimeSpan.FromSeconds(ConnectionTimeout); using (RemoteContext remoteContext = new RemoteContext(controller)) { remoteContext.RemoteArtifactDirectory = RemoteArtifactDirectory; remoteContext.RemoteWorkingDirectory = RemoteWorkingDirectory; Status status = controller.GetStatus(); switch (ConfiguredStartAction) { case StartAction.Auto: if (xmlProfile.Snapshot != null) { Restart(controller, status); } else { StartOrResume(controller, status); } break; case StartAction.StartOrResume: StartOrResume(controller, status); break; case StartAction.Restart: Restart(controller, status); break; } try { if (Tasks != null) { foreach (ITask task in Tasks) { RunTaskAndMergeResult(task, result); if (result.Status != IntegrationStatus.Success) { break; } } } if (Publishers != null) { foreach (ITask task in Publishers) { RunTaskAndMergeResult(task, result); } } } finally { switch (ConfiguredStopAction) { case StopAction.Auto: if (xmlProfile.Snapshot != null) { controller.PowerOff(); } else { controller.SaveState(); } break; case StopAction.SaveState: controller.SaveState(); break; case StopAction.Pause: controller.Pause(); break; case StopAction.Shutdown: controller.Shutdown(); break; case StopAction.PowerOff: controller.PowerOff(); break; } } } } return(true); }
public void LoadProfile(bool silent) { try { if (!Environment.GetCommandLineArgs().Contains("--disable-load")) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "XML Profile|*.prof"; if (ofd.ShowDialog() == DialogResult.OK) { XmlProfile subReq = XmlProfile.FromFile(ofd.FileName); if (!Environment.GetCommandLineArgs().Contains("--nvc")) { if ((subReq.AppInfo.AppVersion != string.Empty) && (subReq.AppInfo.AppVersion != null)) { //Make sure the XML Profile is compatible int compareResult = CompareVersion(subReq.AppInfo.AppVersion); //MessageBox.Show(compareResult.ToString()); if (compareResult > 0) { MessageBox.Show("This profile was saved with an earlier version (" + subReq.AppInfo.AppVersion + ").\nIt may not be compatible with this version of CR2 To JPG. You can still use it, but we can't guarantee its compatibility.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else if (compareResult < 0) { MessageBox.Show("This profile was saved with a later version (" + subReq.AppInfo.AppVersion + ").\nIt may not be compatible with this version of CR2 To JPG. You can still use it, but we can't guarantee its compatibility.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } else { MessageBox.Show("We couldn't be certain what version this profile was saved with. You can still use it, but we can't guarantee its compatibility.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } if ((subReq.Options.Quality <= 100) && (subReq.Options.Quality >= 10)) { if ((Directory.Exists(subReq.Locations.Cr2Folder)) && (Directory.Exists(subReq.Locations.JpgFolder))) { Settings.Quality = subReq.Options.Quality; Settings.Subfolders = subReq.Options.Subfolders; txtInputDirectory.Text = subReq.Locations.Cr2Folder; txtOutputDirectory.Text = subReq.Locations.JpgFolder; if (subReq.Watermark != null) { WmContext = subReq.Watermark; } if (!silent) { MessageBox.Show("Successfully loaded profile!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("One or more profile-defined directories do not exist", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Quality level in profile exceeds defined range: 10.00 - 100.00 (10% - 100%)", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } catch (Exception ex) { if (!silent) { MessageBox.Show(ex.ToString(), "Error in loading XML Profile", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public static int Main(string[] args) { try { var options = new ClientOptions(); var parser = new CommandLineParser(); if (!parser.ParseArguments(args, options, Console.Error)) { return(1); } if (options.Values == null || options.Values.Count == 0) { PrintErrorMessageAndHelp(options, "Must specify a command."); return(1); } string commandName = options.Values[0]; Command command = CreateCommand(commandName); if (command == null) { PrintErrorMessageAndHelp(options, "Unrecognized command name."); return(1); } bool haveMaster = options.Master != null; bool haveProfile = options.Configuration != null || options.Profile != null; if (haveMaster && haveProfile || !haveMaster && !haveProfile || (options.Configuration != null) != (options.Profile != null)) { PrintErrorMessageAndHelp(options, "Must specify either --master or both --configuration and --profile."); return(1); } Profile profile; if (options.Configuration != null && options.Profile != null) { XmlConfiguration xmlConfiguration = ConfigurationFileHelper.LoadConfiguration(options.Configuration); XmlProfile xmlProfile = xmlConfiguration.GetProfileById(options.Profile); if (xmlProfile == null) { PrintErrorMessageAndHelp(options, "Profile not found in configuration file."); return(1); } profile = xmlProfile.ToProfile(); } else { profile = new Profile() { Master = options.Master, MasterPort = options.MasterPort, Slave = options.Slave, SlavePort = options.SlavePort, VM = options.VM, Snapshot = options.Snapshot }; } if (!command.Validate(profile, options)) { return(1); } using (var controller = new ClientController(profile)) { controller.Quiet = options.Quiet; controller.ConnectionTimeout = TimeSpan.FromSeconds(options.ConnectionTimeout); try { return(command.Execute(controller, options)); } catch (OperationFailedException ex) { Console.Error.WriteLine("Operation failed."); Console.Error.WriteLine(ex.Why); if (ex.__isset.details) { Console.Error.WriteLine("Details:"); Console.Error.WriteLine(ex.Details); } return(1); } } } catch (Exception ex) { Console.WriteLine("Fatal exception: " + ex); return(1); } }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <param name="collection"></param> public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection) { try { string userName = context["UserName"] as string; bool isAuthenticated = Convert.ToBoolean(context["IsAuthenticated"]); if (!string.IsNullOrEmpty(userName) && collection.Count > 0) { string names = string.Empty; string valuesString = string.Empty; byte[] valuesBinary = null; /// prepare data for saving PrepareDataForSaving(ref names, ref valuesString, ref valuesBinary, true, collection, isAuthenticated); /// save data if (!string.IsNullOrEmpty(valuesString) || valuesBinary != null) { lock (SyncRoot) { XmlProfile profile = null; if (isAuthenticated) { MembershipUser user = Membership.GetUser(userName); if (user != null) { profile = this.Store.GetByUserKey((Guid)user.ProviderUserKey); } if (profile == null) { profile = new XmlProfile(); profile.UserKey = (user != null) ? (Guid)user.ProviderUserKey : Guid.NewGuid(); this.Store.Profiles.Add(profile); } } else { Guid g = new Guid(userName); profile = this.Store.GetByUserKey(g); if (profile == null) { profile = new XmlProfile(); profile.UserKey = g; this.Store.Profiles.Add(profile); } } profile.LastUpdated = DateTime.Now; /// encode Encoding encoding = Encoding.UTF8; profile.Names = Convert.ToBase64String(encoding.GetBytes(names)); profile.ValuesBinary = (valuesBinary != null) ? Convert.ToBase64String(valuesBinary) : ""; profile.ValuesString = Convert.ToBase64String(encoding.GetBytes(valuesString)); /// this.Store.Save(); } } } } catch { throw; } }