public override void Validate() { if (!string.IsNullOrEmpty(Request.GroupString["type"])) { switch (Request.GroupString["type"]) { case "start": if (!hasUpdate()) { throw new Exception("There is no update file."); } if (updateStarted()) { throw new Exception("There is a update started already."); } writeUpdateProcess("Loading..."); XiaoYang.Installation.InstallationCollection _installCollection = new Installation.InstallationCollection(); _installCollection.LoadInstalled(); System.Xml.XmlDocument _updateDom = new System.Xml.XmlDocument(); _updateDom.Load(updateFilePath); foreach (System.Xml.XmlNode _item in _updateDom.SelectNodes("Install/Item")) { XiaoYang.Installation.Installation _install = new Installation.Installation(); _install.Name = _item.SelectSingleNode("Label").InnerText; _install.Version = _item.SelectSingleNode("Version").InnerText; _install.Depend = _item.SelectSingleNode("Depend") == null ? string.Empty : _item.SelectSingleNode("Depend").InnerText; _install.SQL = _item.SelectSingleNode("SQL") == null ? string.Empty : _item.SelectSingleNode("SQL").InnerText; _install.Code = _item.SelectSingleNode("Code") == null ? string.Empty : _item.SelectSingleNode("Code").InnerText; if (!string.IsNullOrEmpty(_install.Code)) { _install.CodeLanguage = _item.SelectSingleNode("Code").Attributes["Language"] == null ? "CSharp" : _item.SelectSingleNode("Code").Attributes["Language"].Value; } _install.Message = _item.SelectSingleNode("Message") == null ? "No message" : _item.SelectSingleNode("Message").InnerText; _installCollection.Add(_install); } _installCollection.Arrange(true); writeUpdateProcess("Install list:"); for (int i = 0; i < _installCollection.Count; i++) { writeUpdateProcess(string.Format("\t{0}({1}):", _installCollection[i].Name, _installCollection[i].Version)); writeUpdateProcess(string.Format("\t\t{0}", _installCollection[i].Message)); } writeUpdateProcess("Preparing..."); for (int i = 0; i < _installCollection.Count; i++) { XiaoYang.Installation.Installation _updateItem = _installCollection[i]; if (!string.IsNullOrEmpty(_updateItem.Code)) { _updateItem.GeneratedAssembly = buildAssembly(_updateItem.CodeLanguage, _updateItem.Code, _updateItem.Depend); } } writeUpdateProcess("Updating..."); Xy.Data.DataBase DB = new Xy.Data.DataBase("Update"); for (int i = 0; i < _installCollection.Count; i++) { DB.Open(); DB.StartTransaction(); XiaoYang.Installation.Installation _updateItem = _installCollection[i]; try { if (!string.IsNullOrEmpty(_updateItem.SQL)) { Xy.Data.Procedure _updateSQL = new Xy.Data.Procedure("UpdateSQL", _updateItem.SQL); _updateSQL.InvokeProcedure(DB); } if (!string.IsNullOrEmpty(_updateItem.Code)) { XiaoYang.Installation.IInstallItem _installItem = (XiaoYang.Installation.IInstallItem)_updateItem.GeneratedAssembly.CreateInstance("XyUpdate.XyUpdate"); _installItem.Update(DB); } XiaoYang.Installation.Installation.Add(_updateItem, DB); DB.CommitTransaction(); writeUpdateProcess(string.Format("{0}({1}) is updated",_updateItem.Name,_updateItem.Version)); } catch { DB.RollbackTransation(); throw; } finally { DB.Close(); } } System.IO.File.Delete(updateFilePath); writeUpdateProcess("All Updated!"); Response.Write("{status:'success'}"); break; case "check": Response.Write("{status:'" + (System.IO.File.Exists(updateFilePath) ? (System.IO.File.Exists(logFilePath) ? "processing" : "success" ) : "failure") + "'}"); break; case "process": if (!System.IO.File.Exists(logFilePath)) break; System.IO.FileStream _updateLog = System.IO.File.Open(logFilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Write); System.IO.StreamReader _sr = new System.IO.StreamReader(_updateLog); Response.Write(_sr.ReadToEnd()); _sr.Close(); _updateLog.Close(); if (!System.IO.File.Exists(updateFilePath) && System.IO.File.Exists(logFilePath)) { System.IO.File.Delete(logFilePath); } break; case "test": try { System.Web.HttpRuntime.UnloadAppDomain(); //Response.Write(Xy.Tools.LogTools.DumpObjectTableHTML(System.Web.HttpContext.Current.ApplicationInstance), true, true); //System.DirectoryServices.DirectoryEntry de = new System.DirectoryServices.DirectoryEntry(AppDomain.CurrentDomain.BaseDirectory); //Response.Write(de.Name, true, true); //Response.Write(de.ToString(), true, true); } catch (Exception ex) { Response.Write(ex.Message.ToString()); } break; } } }
public static Measurement Create(int currentDisplayValue, MeasurementItem current, List <MeasurementItem> history, List <MeasurementItem> forecast, Installation.Installation installation) => new Measurement(null, currentDisplayValue, current, history, forecast, installation);