Exemplo n.º 1
0
        /// <summary>
        /// Will attempt to load the build history from a file.
        /// If the file cannot be found, the string will be assumed to contain Xml data and an attempt will be made to parse it for history data.
        /// </summary>
        /// <param name="XmlFile"></param>
        /// <returns>True if the History object has changed.</returns>
        public bool LoadHistory(string XmlFile)
        {
            /*
             * if (File.Exists(XmlFile))
             *  return History.ImportHistory(new FileStream(XmlFile, FileMode.Open, FileAccess.Read));
             *
             * //This means we don't see a file by that name.  Maybe it's just an Xml string?
             * return History.ImportHistory(XmlFile);
             */
            if (XmlFile == null || XmlFile.Equals(String.Empty))
            {
                if (History == null)
                {
                    History = new BuildHistory();
                    History.Builds.CollectionChanged += CollectionChanged;
                    return(true);
                }
                return(false);
            }

            if (File.Exists(XmlFile))
            {
                UrlEncodedMessage uem = new UrlEncodedMessage(File.ReadAllText(XmlFile), AutoBuild.SerialSeperator, true);
                History = uem.DeserializeTo <BuildHistory>() ?? new BuildHistory();
                History.Builds.CollectionChanged += CollectionChanged;
                return(true);
            }

            History = new BuildHistory();
            UrlEncodedMessage UEM = new UrlEncodedMessage(XmlFile, AutoBuild.SerialSeperator, true);

            UEM.DeserializeTo(History);
            History.Builds.CollectionChanged += CollectionChanged;
            return(true);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Loads the master config file from disk.
 /// This will first check for a registry key to locate the config.conf.
 /// If the file cannot be opened or cannot be found, a default config will be loaded
 /// </summary>
 /// <returns>True if a config file was successfully loaded.  False if a default config had to be generated.</returns>
 public bool LoadConfig()
 {
     try
     {
         var regKey = Registry.LocalMachine.CreateSubKey(@"Software\CoApp\AutoBuild Service") ??
                      Registry.LocalMachine.OpenSubKey(@"Software\CoApp\AutoBuild Service");
         if (regKey == null)
         {
             throw new Exception("Unable to load registry key.");
         }
         string configfile = (string)(regKey.GetValue("ConfigFile", null));
         if (configfile == null)
         {
             configfile = @"C:\AutoBuild\config.conf";
             regKey.SetValue("ConfigFile", configfile);
         }
         UrlEncodedMessage UEM = new UrlEncodedMessage(File.ReadAllText(configfile), AutoBuild.SerialSeperator, true);
         UEM.DeserializeTo(MasterConfig);
         MasterConfig.Changed += MasterChanged;
         return(true);
     }
     catch (Exception e)
     {
         WriteEvent("Unable to load master config:\n" + e.Message + "\n\nDefault config loaded.", EventLogEntryType.Error, 0, 0);
         MasterConfig          = new AutoBuild_config();
         MasterConfig.Changed += MasterChanged;
         return(false);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Loads a project configuration from disk.
        /// </summary>
        /// <param name="projectName">The name of the project to load.</param>
        /// <param name="overwrite">If true, will reload the project config data even if the project already has a configuration loaded.  (False by default)</param>
        /// <returns>True if the project was loaded successfully.  False otherwise.</returns>
        public bool LoadProject(string projectName, bool overwrite = false)
        {
            if (Projects.ContainsKey(projectName) && !overwrite)
            {
                return(false);
            }

            try
            {
                if (projectName == null)
                {
                    throw new ArgumentException("ProjectName cannot be null.");
                }

                Projects[projectName] = new ProjectData();
                if (!Projects.ContainsKey(projectName))
                {
                    throw new ArgumentException("Project not found: " + projectName);
                }

                string            file = Path.Combine(MasterConfig.ProjectRoot, projectName, "config.conf");
                UrlEncodedMessage UEM  = new UrlEncodedMessage(File.ReadAllText(file), AutoBuild.SerialSeperator, true);
                UEM.DeserializeTo(Projects[projectName]);
                Projects[projectName].SetName(projectName);
                string logPath = Path.Combine(MasterConfig.ProjectRoot, projectName, "Log.log");
                if (!File.Exists(logPath))
                {
                    logPath = String.Empty;
                }
                Projects[projectName].LoadHistory(logPath);
                Projects[projectName].Changed2 += ProjectChanged;
                return(true);
            }
            catch (Exception e)
            {
                WriteEvent("Unable to load project config (" + projectName + "):\n" + e.Message, EventLogEntryType.Error, 0, 0);
                return(false);
            }
        }
Exemplo n.º 4
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (ConfigTree.Nodes.Count > 0)
            {
                var ans = EditorUtil.ConfirmPrompt("Save before closing existing work?");
                if (ans == true)
                {
                    saveToolStripMenuItem_Click(sender, e);
                }
                if (ans == null)
                {
                    return;
                }
            }

            ConfigTree.Nodes.Clear();

            string loc = String.Empty;
            var regKey = Registry.LocalMachine.OpenSubKey(@"Software\CoApp\AutoBuild Service");
            if (regKey == null)
                loc = @"C:\AutoBuild";
            else
                loc = Path.GetDirectoryName((string) (regKey.GetValue("ConfigFile", @"C:\AutoBuild\config.conf")));

            var OFD = new OpenFileDialog();
            OFD.InitialDirectory = loc;
            OFD.Filter = @"AutoBuild Config files|config.conf|All Files (*.*)|*.*";
            OFD.FilterIndex = 1;
            OFD.RestoreDirectory = true;

            if (OFD.ShowDialog() != DialogResult.OK)
                return;

            try
            {
                if (!File.Exists(OFD.FileName))
                {
                    throw new FileNotFoundException("Unable to open specified file.", OFD.FileName);
                }
                TreeNode root = new TreeNode(RootNodeName);
                root.Tag = OFD.FileName;
                ConfigTree.Nodes.Add(root);

                // open file, produce and attach subnodes to root node for file
                UrlEncodedMessage UEM = new UrlEncodedMessage(File.ReadAllText(OFD.FileName),
                                                              AutoBuild.SerialSeperator, true);

                TreeNode top;

                if (UEM[".$T$"].Contains("AutoBuild_config"))
                {
                    var input = UEM.DeserializeTo<AutoBuild_config>();
                    top = new TreeNode(input.GetType().Name);
                    top.Tag = input;
                }
                else if (UEM[".$T$"].Contains("ProjectData"))
                {
                    var input = UEM.DeserializeTo<ProjectData>();
                    top = new TreeNode(input.GetType().Name);
                    top.Tag = input;
                }
                else
                {
                    Type type = Type.GetType(UEM[".$T$"]);
                    var obj = Activator.CreateInstance(type, true);
                    var input = UEM.DeserializeTo(obj);
                    top = new TreeNode(input.GetType().Name);
                    top.Tag = input;
                }

                root.AddChild(top);
                FillData(top);
            }
            catch (Exception E)
            {
                MessageBox.Show("Unable to open file.\n\n" + E.Message);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Loads a project configuration from disk.
        /// </summary>
        /// <param name="projectName">The name of the project to load.</param>
        /// <param name="overwrite">If true, will reload the project config data even if the project already has a configuration loaded.  (False by default)</param>
        /// <returns>True if the project was loaded successfully.  False otherwise.</returns>
        public bool LoadProject(string projectName, bool overwrite = false)
        {
            if (Projects.ContainsKey(projectName) && !overwrite)
                return false;

            try
            {
                if (projectName == null)
                    throw new ArgumentException("ProjectName cannot be null.");

                Projects[projectName] = new ProjectData();
                if (!Projects.ContainsKey(projectName))
                    throw new ArgumentException("Project not found: " + projectName);

                string file = Path.Combine(MasterConfig.ProjectRoot, projectName, "config.conf");
                UrlEncodedMessage UEM = new UrlEncodedMessage(File.ReadAllText(file), AutoBuild.SerialSeperator, true);
                UEM.DeserializeTo(Projects[projectName]);
                Projects[projectName].SetName(projectName);
                string logPath = Path.Combine(MasterConfig.ProjectRoot, projectName, "Log.log");
                if (!File.Exists(logPath))
                    logPath = String.Empty;
                Projects[projectName].LoadHistory(logPath);
                Projects[projectName].Changed2 += ProjectChanged;
                return true;
            }
            catch (Exception e)
            {
                WriteEvent("Unable to load project config (" + projectName + "):\n" + e.Message, EventLogEntryType.Error, 0, 0);
                return false;
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Loads the master config file from disk.
 /// This will first check for a registry key to locate the config.conf.
 /// If the file cannot be opened or cannot be found, a default config will be loaded
 /// </summary>
 /// <returns>True if a config file was successfully loaded.  False if a default config had to be generated.</returns>
 public bool LoadConfig()
 {
     try
     {
         var regKey = Registry.LocalMachine.CreateSubKey(@"Software\CoApp\AutoBuild Service") ??
                      Registry.LocalMachine.OpenSubKey(@"Software\CoApp\AutoBuild Service");
         if (regKey == null)
             throw new Exception("Unable to load registry key.");
         string configfile = (string)(regKey.GetValue("ConfigFile", null));
         if (configfile == null)
         {
             configfile = @"C:\AutoBuild\config.conf";
             regKey.SetValue("ConfigFile", configfile);
         }
         UrlEncodedMessage UEM = new UrlEncodedMessage(File.ReadAllText(configfile), AutoBuild.SerialSeperator, true);
         UEM.DeserializeTo(MasterConfig);
         MasterConfig.Changed += MasterChanged;
         return true;
     }
     catch (Exception e)
     {
         WriteEvent("Unable to load master config:\n" + e.Message + "\n\nDefault config loaded.", EventLogEntryType.Error, 0, 0);
         MasterConfig = new AutoBuild_config();
         MasterConfig.Changed += MasterChanged;
         return false;
     }
 }
Exemplo n.º 7
0
        /// <summary>
        /// Will attempt to load the build history from a file.
        /// If the file cannot be found, the string will be assumed to contain Xml data and an attempt will be made to parse it for history data.
        /// </summary>
        /// <param name="XmlFile"></param>
        /// <returns>True if the History object has changed.</returns>
        public bool LoadHistory(string XmlFile)
        {
            /*
            if (File.Exists(XmlFile))
                return History.ImportHistory(new FileStream(XmlFile, FileMode.Open, FileAccess.Read));

            //This means we don't see a file by that name.  Maybe it's just an Xml string?
            return History.ImportHistory(XmlFile);
             */
            if (XmlFile == null || XmlFile.Equals(String.Empty))
            {
                if (History == null)
                {
                    History = new BuildHistory();
                    History.Builds.CollectionChanged += CollectionChanged;
                    return true;
                }
                return false;
            }

            if (File.Exists(XmlFile))
            {
                UrlEncodedMessage uem = new UrlEncodedMessage(File.ReadAllText(XmlFile), AutoBuild.SerialSeperator, true);
                History = uem.DeserializeTo<BuildHistory>() ?? new BuildHistory();
                History.Builds.CollectionChanged += CollectionChanged;
                return true;
            }

            History = new BuildHistory();
            UrlEncodedMessage UEM = new UrlEncodedMessage(XmlFile, AutoBuild.SerialSeperator, true);
            UEM.DeserializeTo(History);
            History.Builds.CollectionChanged += CollectionChanged;
            return true;
        }