コード例 #1
0
ファイル: EntityType.cs プロジェクト: BrookHuang/XYCMS
 static void EntityType_BeforeDel(Xy.Data.Procedure procedure, Xy.Data.DataBase DB)
 {
     short inID = Convert.ToInt16(procedure.GetItem("ID"));
     EntityType _type = GetInstance(inID);
     System.Data.DataTable _childTypies = GetChildType(inID);
     foreach (System.Data.DataRow _childTypeRow in _childTypies.Rows) {
         EntityType _childType = new EntityType();
         _childType.Fill(_childTypeRow);
         Del(_childType.ID);
     }
     StringBuilder _dropTableProcedure = new StringBuilder();
     foreach (System.Data.DataRow _multiAttrsRow in EntityAttribute.GetByTypeID(inID).Rows) {
         EntityAttribute _attr = new EntityAttribute();
         _attr.Fill(_multiAttrsRow);
         if (_attr.IsMultiple) {
             _dropTableProcedure.AppendLine(string.Format(_commandPartern_Del, "Entity_" + _type.Key + "_" + _attr.Key));
         }
     }
     _dropTableProcedure.AppendLine(string.Format(_commandPartern_Del, "Entity_" + _type.Key));
     Xy.Data.Procedure _deleteRelativeTable = new Xy.Data.Procedure("DeleteRelativeTable", _dropTableProcedure.ToString());
     Xy.Data.Procedure _deleteRelativeEntityBase = new Xy.Data.Procedure("DeleteRelativeEntityBase", "Delete from [EntityBase] where [TypeID] = @ID", new Xy.Data.ProcedureParameter[] { new Xy.Data.ProcedureParameter("ID", System.Data.DbType.Int64) });
     _deleteRelativeEntityBase.SetItem("ID", inID);
     _deleteRelativeTable.InvokeProcedure(DB);
     _deleteRelativeEntityBase.InvokeProcedure(DB);
 }
コード例 #2
0
ファイル: EntityType.cs プロジェクト: BrookHuang/XYCMS
 static void EntityType_AfterAdd(Xy.Data.ProcedureResult result, Xy.Data.Procedure procedure, Xy.Data.DataBase DB)
 {
     string _tableName = Convert.ToString(procedure.GetItem("Key"));
     short _parentTypeID = Convert.ToInt16(procedure.GetItem("ParentTypeID"));
     if (string.IsNullOrEmpty(_tableName)) throw new Exception("Empty type name");
     StringBuilder _addTableProcedure = new StringBuilder();
     _addTableProcedure.AppendLine(string.Format(_commandPartern_Add, "Entity_" + _tableName));
     Xy.Data.Procedure _addBaseTable = new Xy.Data.Procedure("AddBaseTable", _addTableProcedure.ToString());
     _addBaseTable.InvokeProcedure(DB);
 }
コード例 #3
0
ファイル: InstallAction.cs プロジェクト: BrookHuang/XYCMS
        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;
                }
            }
        }
コード例 #4
0
ファイル: EntityAttribute.cs プロジェクト: BrookHuang/XYCMS
 static void EntityAttribute_BeforeEdit(Xy.Data.Procedure procedure, Xy.Data.DataBase DB)
 {
     EntityAttribute _oldAttr = EntityAttribute.GetInstance(Convert.ToInt64(procedure.GetItem("ID")));
     bool _isMultiple = Convert.ToBoolean(procedure.GetItem("IsMultiple"));
     if (_oldAttr.IsMultiple != _isMultiple) throw new Exception("can not switch attribute multiple mode");
     StringBuilder _editAttrCommand = new StringBuilder();
     string _default = Convert.ToString(procedure.GetItem("Default"));
     if (!string.IsNullOrEmpty(_oldAttr.Default) && string.IsNullOrEmpty(_default)) {
         _editAttrCommand.AppendLine(string.Format(_commandPartern_DelConstraintDefault, _oldAttr.Table, _oldAttr.Key));
     }
     if (!string.IsNullOrEmpty(_default)) {
         _editAttrCommand.AppendLine(string.Format(_commandPartern_UpdateDefault, _oldAttr.Table, _oldAttr.Key, _default));
         _editAttrCommand.AppendLine(string.Format(_commandPartern_AddConstraintDefault, _oldAttr.Table, _oldAttr.Key, _default));
     }
     string _editAttrDBType = GetTypeName(Convert.ToString(procedure.GetItem("Type")));
     if (!Convert.ToBoolean(procedure.GetItem("IsNull"))) {
         _editAttrDBType += " NOT NULL";
     }
     _editAttrCommand.AppendLine(string.Format(_commandPartern_EditAttribute, _oldAttr.Table, _oldAttr.Key, _editAttrDBType));
     string _key = Convert.ToString(procedure.GetItem("Key"));
     if (string.Compare(_key, _oldAttr.Key) != 0) {
         _editAttrCommand.AppendLine(string.Format(_commandPartern_EditAttributeName, _oldAttr.Table, _oldAttr.Key, _key));
     }
     Xy.Data.Procedure _editAttrColumn = new Xy.Data.Procedure("EditAttribute", _editAttrCommand.ToString());
     _editAttrColumn.InvokeProcedure();
 }
コード例 #5
0
ファイル: EntityAttribute.cs プロジェクト: BrookHuang/XYCMS
 static void EntityAttribute_BeforeDel(Xy.Data.Procedure procedure, Xy.Data.DataBase DB)
 {
     long _attrID = Convert.ToInt64(procedure.GetItem("ID"));
     EntityAttribute _attr = GetInstance(_attrID);
     StringBuilder _delAttrCommand = new StringBuilder();
     if (_attr.IsMultiple) {
         _delAttrCommand.AppendLine(string.Format(_commandPartern_DelAttributeTable, _attr.Table));
     } else {
         _delAttrCommand.AppendLine(string.Format(_commandPartern_DelAttributeColumn, _attr.Table, _attr.Key));
     }
     if (!string.IsNullOrEmpty(_attr.Default)) {
         _delAttrCommand.AppendLine(string.Format(_commandPartern_DelConstraintDefault, _attr.Table, _attr.Key));
     }
     Xy.Data.Procedure _delAttrColumn = new Xy.Data.Procedure("DelAttribute", _delAttrCommand.ToString());
     _delAttrColumn.InvokeProcedure();
 }
コード例 #6
0
ファイル: EntityAttribute.cs プロジェクト: BrookHuang/XYCMS
        private static void EntityAttribute_BeforeAdd(Xy.Data.Procedure produce, Xy.Data.DataBase DB)
        {
            string _attrName = Convert.ToString(produce.GetItem("Key"));
            EntityType _type = EntityType.GetInstance(Convert.ToInt16(produce.GetItem("TypeID")));
            System.Data.DataTable _attrs = GetByTypeID(_type.ID);
            foreach (System.Data.DataRow _attr in _attrs.Rows) {
                if (string.Compare(_attr["Name"].ToString(), _attrName, true) == 0) throw new Exception(string.Format("\"{0}\" already existed", _attrName));
            }
            string _addAttrCommand;
            if (Convert.ToBoolean(produce.GetItem("IsMultiple"))) {
                _addAttrCommand = _commandPartern_AddMultipleAttribute;
            } else {
                _addAttrCommand = _commandPartern_AddSimpleAttribute;
            }
            string _addAttrDBType = GetTypeName(Convert.ToString(produce.GetItem("Type")));
            if (!Convert.ToBoolean(produce.GetItem("IsNull"))) {
                _addAttrDBType += " NOT NULL";
            }
            _addAttrCommand = string.Format(_addAttrCommand, "Entity_" + _type.Key, _attrName, _addAttrDBType);

            Xy.Data.Procedure _addAttrColumn = new Xy.Data.Procedure("AddAttribute", _addAttrCommand);
            _addAttrColumn.InvokeProcedure(DB);
        }
コード例 #7
0
ファイル: EntityHelper.cs プロジェクト: BrookHuang/XYCMS
 public long Add(System.Collections.Specialized.NameValueCollection inValues)
 {
     bool _isActive = false;
     if (inValues["IsActive"] != null && Convert.ToBoolean(inValues["IsActive"])) _isActive = true;
     StringBuilder _command = new StringBuilder();
     StringBuilder _field, _value, _commandFormMultiplyAttribute;
     bool _hasSimpleField;
     foreach (string _table in _cache.RelatedTables) {
         _hasSimpleField = false;
         _commandFormMultiplyAttribute = new StringBuilder();
         _field = new StringBuilder(); _field.Append("[EntityID]");
         _value = new StringBuilder(); _value.Append("@EntityID");
         foreach (EntityAttribute _attr in _cache.Attributes) {
             if (_attr.ID == -1) continue;
             if (string.Compare(_attr.Table, _table) == 0) {
                 string _tempValue = inValues[_attr.Key];
                 if (string.IsNullOrEmpty(_tempValue)) {
                     if (!string.IsNullOrEmpty(_attr.Default)) {
                         _tempValue = _attr.Default;
                     } else if (!_attr.IsNull) {
                         throw new Exception(string.Format("can not put Null on the field '{0}'", _attr.Key));
                     } else {
                         continue;
                     }
                 }
                 if (_attr.IsMultiple) {
                     foreach (string mulAttrValue in inValues[_attr.Key].Split(_attr.Split[0])) {
                         _commandFormMultiplyAttribute.AppendLine(string.Format("Insert [{0}]([EntityID],[{1}])values(@EntityID,'{2}')", _attr.Table, _attr.Key, mulAttrValue));
                     }
                 } else {
                     _hasSimpleField = true;
                     _field.AppendFormat(",[{0}]", _attr.Key);
                     _value.AppendFormat(",'{0}'", _tempValue);
                 }
             }
         }
         if (_hasSimpleField) {
             _command.AppendLine(string.Format("Insert into [{0}](", _table));
             _command.AppendLine(_field.ToString());
             _command.AppendLine(")values(");
             _command.AppendLine(_value.ToString());
             _command.AppendLine(")");
         }
         _command.Append(_commandFormMultiplyAttribute.ToString());
     }
     if (_command.Length > 0) {
         Xy.Data.Procedure _procedure = new Xy.Data.Procedure("AddEntity" + _cache.TypeInstance.Key, _command.ToString());
         _procedure.AddItem("EntityID", System.Data.DbType.Int64);
         _db.Open();
         _db.StartTransaction();
         try {
             long _entityID = EntityBase.Add(_cache.TypeInstance.ID, _isActive, _db);
             _procedure.SetItem("EntityID", _entityID);
             _procedure.InvokeProcedure(_db);
             _db.CommitTransaction();
             return _entityID;
         } catch {
             _db.RollbackTransation();
             throw;
         } finally {
             _db.Close();
         }
     }
     return 0;
 }
コード例 #8
0
ファイル: EntityHelper.cs プロジェクト: BrookHuang/XYCMS
 public int Edit(System.Collections.Specialized.NameValueCollection inValues, params long[] inEntityID)
 {
     if (inEntityID.Length == 0) throw new Exception("Entity ID not found");
     StringBuilder _command = new StringBuilder();
     bool _ifCode = false;
     foreach (long _currentID in inEntityID) {
         EntityBase _base = EntityBase.GetInstance(_currentID);
         _ifCode = false;
         foreach (string _valueKeys in inValues.AllKeys) {
             string _valueName = _valueKeys, _valueID = string.Empty;
             if (_attrTest.IsMatch(_valueKeys)) {
                 System.Text.RegularExpressions.Match _result = _attrTest.Match(_valueKeys);
                 _valueName = _result.Groups["name"].Value;
                 _valueID = _result.Groups["id"].Value;
             }
             foreach (XiaoYang.Entity.EntityAttribute _attr in _cache.Attributes) {
                 if (string.Compare(_attr.Key, _valueName) == 0) {
                     if (_attr.ID == -1) {
                         continue;
                     }
                     if (!_ifCode) {
                         _command.AppendLine(string.Format("if exists(select [ID] from [EntityBase] where {1} [ID] = {0})", _currentID, _applyToChild ? string.Empty : _childQueryWhere));
                         _command.AppendLine("begin");
                         _ifCode = true;
                     }
                     if (_attr.IsMultiple) {
                         if (_applyToChild) {
                             _command.AppendLine(string.Format("if exists(select [ID] from [EntityBase] where {1} [ID] = {0})", _currentID, _childQueryWhere));
                             _command.AppendLine("begin");
                         }
                         if (!string.IsNullOrEmpty(_valueID)) {
                             _command.AppendLine(string.Format("Update [{0}] set [{1}] = '{2}' where [ID] = {3}", _attr.Table, _attr.Key, inValues[_valueKeys], _valueID));
                         } else {
                             _command.AppendLine(string.Format("Delete from [{0}] where [EntityID] = {1}", _attr.Table, _currentID));
                             foreach (string mulAttrValue in inValues[_valueKeys].Split(_attr.Split[0])) {
                                 _command.AppendLine(string.Format("Insert [{0}]([EntityID],[{1}])values({2},'{3}')", _attr.Table, _attr.Key, _currentID, mulAttrValue));
                             }
                         }
                         if (_applyToChild) _command.AppendLine("end");
                     } else {
                         _command.AppendLine(string.Format("Update [{0}] set [{1}] = '{2}' where [EntityID] = {3}", _attr.Table, _attr.Key, inValues[_valueKeys], _currentID));
                     }
                 }
             }
         }
         if (inValues["IsActive"] != null) _base.IsActive = Convert.ToBoolean(inValues["IsActive"]);
         _command.AppendLine(string.Format("Update [EntityBase] set [IsActive] = '{0}' where [ID] = {1}", _base.IsActive, _currentID));
         _command.AppendLine(string.Format("Update [EntityBase] set [UpdateTime] = GetDate() where [ID] = {0}", _currentID));
         if (_ifCode) _command.AppendLine("end");
     }
     if (_command.Length > 0) {
         Xy.Data.Procedure _procedure = new Xy.Data.Procedure("EditEntity" + _cache.TypeInstance.Key, _command.ToString());
         return _procedure.InvokeProcedure(_db);
     }
     return 0;
 }
コード例 #9
0
ファイル: EntityHelper.cs プロジェクト: BrookHuang/XYCMS
 public int Del(params long[] inEntityID)
 {
     StringBuilder _command = new StringBuilder();
     _command.AppendLine("Delete From [EntityBase] Where [ID] = @ID");
     foreach (string _tableName in _cache.RelatedTables) {
         _command.AppendLine(string.Format("Delete From [{0}] Where [ID] = @ID", _tableName));
     }
     Xy.Data.Procedure _procedure = new Xy.Data.Procedure("DelEntity" + _cache.TypeInstance.Key, _command.ToString());
     _procedure.AddItem("ID", System.Data.DbType.Int64);
     return _procedure.InvokeProcedure(_db);
 }