/// <summary> /// 执行写操作 /// </summary> public static WriteReturn Write(string name, DbParameter[] param, DataContext db = null, string key = null, bool isOutSql = false) { key = key == null?MapDb(name) : key; var config = db == null?DataConfig.Get(key) : db.config; if (config.IsUpdateCache) { InstanceMap(key); } if (DbCache.Exists(config.CacheType, name.ToLower())) { var sql = MapXml.GetMapSql(name, ref param, db, key); BaseAop.AopMapBefore(name, sql, param, config, AopType.Map_Write); isOutSql = isOutSql ? isOutSql : IsMapLog(name); var result = FastWrite.ExecuteSql(sql, param, db, key, isOutSql, false); BaseAop.AopMapAfter(name, sql, param, config, AopType.Map_Write, result); return(result); } else { BaseAop.AopMapBefore(name, "", param, config, AopType.Map_Write); var data = new WriteReturn(); BaseAop.AopMapAfter(name, "", param, config, AopType.Map_Write, data); return(data); } }
/// <summary> /// 初始化code first 2 /// </summary> /// <param name="list"></param> /// <param name="nameSpace">命名空间</param> /// <param name="dll">dll名称</param> public static void InstanceTable(string nameSpace, string dbKey = null, string dbFile = "db.json") { var projectName = Assembly.GetCallingAssembly().GetName().Name; var query = new DataQuery(); query.Config = DataConfig.Get(dbKey, projectName, dbFile); query.Key = dbKey; MapXml.CreateLogTable(query); var assembly = AppDomain.CurrentDomain.GetAssemblies().ToList().Find(a => a.FullName.Split(',')[0] == projectName); if (assembly == null) { assembly = Assembly.Load(projectName); } if (assembly != null) { assembly.ExportedTypes.ToList().ForEach(a => { var typeInfo = (a as TypeInfo); if (typeInfo.Namespace != null && typeInfo.Namespace == nameSpace) { BaseTable.Check(query, a.Name, typeInfo.DeclaredProperties.ToList(), typeInfo.GetCustomAttributes().ToList()); } }); } }
/// <summary> /// 验证xml /// </summary> /// <returns></returns> public static bool CheckMap(string xml, string dbKey = null) { var config = DataConfig.Get(dbKey); var info = new FileInfo(xml); return(MapXml.GetXmlList(info.FullName, "sqlMap", config).isSuccess); }
/// <summary> /// Создать XML файлы из данных, считанных из БД /// </summary> /// <param name="rep_year">Отчетный год</param> /// <param name="org">Организация</param> /// <param name="list_id">Список идентификаторов пакетов</param> /// <param name="connectionStr">Строка подключения</param> /// <param name="mapXml">Карта - выходной параметр</param> /// <param name="szv3Xml">Сводная ведомость - выходной параметр</param> /// <param name="szv2XmlArray">Описи - выходной параметр</param> /// <param name="szv1XmlArray">Документы СЗВ1 - выходной параметр</param> /// <returns></returns> public static int MakeXml(int repYear, Org org, IEnumerable <long> listId, string connectionStr, out XmlDocument mapXml, out XmlDocument szv3Xml, out IEnumerable <XmlDocument> szv2XmlArray, out IEnumerable <IEnumerable <XmlDocument> > szv1XmlArray) { int res = 0; XmlDocument szv3 = Szv3Xml.GetXml(org.idVal, repYear, connectionStr); LinkedList <XmlDocument> szv2Array = new LinkedList <XmlDocument>(); LinkedList <IEnumerable <XmlDocument> > szv1Array = new LinkedList <IEnumerable <XmlDocument> >(); foreach (long listID in listId) { XmlDocument szv2 = Szv2Xml.GetXml(listID, connectionStr); long[] docsID = Docs.GetDocsID(listID, connectionStr); IEnumerable <XmlDocument> szv1 = Szv1Xml.GetXml(docsID, org, connectionStr); if (szv1 != null && szv2 != null) { szv2Array.AddLast(szv2); szv1Array.AddLast(szv1); } else { res = -1; } } mapXml = MapXml.GetXml(szv2Array, szv1Array); szv3Xml = szv3; szv2XmlArray = szv2Array; szv1XmlArray = szv1Array; // return(res); }
private void worker_DoWork(object sender, DoWorkEventArgs e) { mapXml = null; szv3Xml = null; szv2Array = null; szv1Array = null; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); if (Convert.ToInt32(e.Argument) == 1) { long[] markedLists = MarkedLists(); Storage.MakeXml(_repYear, _organization, markedLists, _connection, out mapXml, out szv3Xml, out szv2Array, out szv1Array); } else if (Convert.ToInt32(e.Argument) == 2) { bool isCorrect; DirectoryInfo dir = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Settings.Default.TempFolder)); using (StreamWriter writer = new StreamWriter(Path.Combine(dir.FullName, "Ошибки XML.txt"), false)) { writer.AutoFlush = true; OrgPropXml orgProperties = GetOrgProperties(); isCorrect = Storage.ImportXml(xmlPathTextBox.Text, orgProperties, out szv3Xml, out szv2Array, out szv1Array, writer); } if (!isCorrect) { MainForm.ShowErrorMessage( "Импорт xml файлов прошел некорректно.\nФормирование электронного контейнера невозможно!"); Process.Start(Path.Combine(dir.FullName, "Ошибки XML.txt")); return; } mapXml = MapXml.GetXml(szv2Array, szv1Array); } if (mapXml != null && szv3Xml != null && szv2Array != null && szv1Array != null) { MakeContainer(mapXml, szv3Xml, szv2Array, szv1Array); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); MainForm.ShowInfoMessage( string.Format( "Файл с электронными данными успешно сформирован и готов к предоставлению в Фонд.\nДлительность операции: {0} ", elapsedTime), "Формирование завершено"); } }
internal void SetDeclaredExceptions(MapXml.Throws[] throws) { if(throws != null) { declaredExceptions = new string[throws.Length]; for(int i = 0; i < throws.Length; i++) { declaredExceptions[i] = throws[i].Class; } } }
/// <summary> /// maq 执行分页 /// </summary> public static PageResult QueryPage(PageModel pModel, string name, DbParameter[] param, DataContext db = null, string key = null, bool isOutSql = false) { key = key == null?MapDb(name) : key; var config = db == null?DataConfig.Get(key) : db.config; if (config.IsUpdateCache) { InstanceMap(key); } if (DbCache.Exists(config.CacheType, name.ToLower())) { var sql = MapXml.GetMapSql(name, ref param, db, key); isOutSql = isOutSql ? isOutSql : IsMapLog(name); BaseAop.AopMapBefore(name, sql, param, config, AopType.Map_Page_Dic); var result = ExecuteSqlPage(pModel, sql, param, db, key, isOutSql); if (MapXml.MapIsForEach(name, config)) { if (db == null) { using (var tempDb = new DataContext(key)) { for (var i = 1; i <= MapXml.MapForEachCount(name, config); i++) { result.list = MapXml.MapForEach(result.list, name, tempDb, key, config, i); } } } else { result.list = MapXml.MapForEach(result.list, name, db, key, config); } } BaseAop.AopMapAfter(name, sql, param, config, AopType.Map_Page_Dic, result.list); return(result); } else { BaseAop.AopMapBefore(name, "", param, config, AopType.Map_Page_Dic); var data = new PageResult(); BaseAop.AopMapAfter(name, "", param, config, AopType.Map_Page_Dic, data.list); return(data); } }
protected override void Initialize() { niveaux = MapXml.getListNiveauxName(); currentState = GameState.Start; nView = new NiveauxView(Content); nController = new NiveauxController(); mController = new MainController(); mView = new MainView(Content); menu = new Menu(Content); editor = new EditorMap(600, 600); viewEditor = new EditorMapView(Content); controllerEditor = new EditorMapController(); base.Initialize(); }
/// <summary> /// 验证xml /// </summary> /// <returns></returns> public bool CheckMap(string xml, string dbKey = null) { var config = DataConfig.Get(dbKey); var info = new FileInfo(xml); var key = new List <string>(); var sql = new List <string>(); var db = new Dictionary <string, object>(); var type = new Dictionary <string, object>(); var param = new Dictionary <string, object>(); var check = new Dictionary <string, object>(); var name = new Dictionary <string, object>(); var parameName = new Dictionary <string, object>(); return(MapXml.GetXmlList(info.FullName, "sqlMap", ref key, ref sql, ref db, ref type, ref check, ref param, ref name, ref parameName, config)); }
/// <summary> /// maq 执行返回结果 /// </summary> public List <T> Query <T>(string name, DbParameter[] param, DataContext db = null, string key = null, bool isOutSql = false) where T : class, new() { key = key == null?MapDb(name) : key; var config = db == null?DataConfig.Get(key) : db.config; if (config.IsUpdateCache) { InstanceMap(key); } if (DbCache.Exists(config.CacheType, name.ToLower())) { var sql = MapXml.GetMapSql(name, ref param, db, key); isOutSql = isOutSql ? isOutSql : IsMapLog(name); BaseAop.AopMapBefore(name, sql, param, config, AopType.Map_List_Model); var result = FastRead.ExecuteSql <T>(sql, param, db, key, isOutSql, false); if (MapXml.MapIsForEach(name, config)) { if (db == null) { using (var tempDb = new DataContext(key)) { for (var i = 1; i <= MapXml.MapForEachCount(name, config); i++) { result = MapXml.MapForEach <T>(result, name, tempDb, config, i); } } } else { result = MapXml.MapForEach <T>(result, name, db, config); } } BaseAop.AopMapAfter(name, sql, param, config, AopType.Map_List_Model, result); return(result); } else { BaseAop.AopMapBefore(name, "", param, config, AopType.Map_List_Model); var data = new List <T>(); BaseAop.AopMapAfter(name, "", param, config, AopType.Map_List_Model, data); return(data); } }
/// <summary> /// maq 执行返回 List<Dictionary<string, object>> /// </summary> public List <Dictionary <string, object> > Query(string name, DbParameter[] param, DataContext db = null, string key = null) { key = key == null?MapDb(name) : key; var config = db == null?DataConfig.Get(key) : db.config; if (config.IsUpdateCache) { InstanceMap(key); } if (DbCache.Exists(config.CacheType, name.ToLower())) { var sql = MapXml.GetMapSql(name, ref param, db, key); var result = FastRead.ExecuteSql(sql, param, db, key); if (MapXml.MapIsForEach(name, config)) { if (db == null) { using (var tempDb = new DataContext(key)) { for (var i = 1; i <= MapXml.MapForEachCount(name, config); i++) { result = MapXml.MapForEach(result, name, tempDb, key, config, i); } } } else { result = MapXml.MapForEach(result, name, db, key, config); } } return(result); } else { return(new List <Dictionary <string, object> >()); } }
/// <summary> /// maq 执行分页 /// </summary> public PageResult <T> QueryPage <T>(PageModel pModel, string name, DbParameter[] param, DataContext db = null, string key = null) where T : class, new() { key = key == null?MapDb(name) : key; var config = db == null?DataConfig.Get(key) : db.config; if (config.IsUpdateCache) { InstanceMap(key); } if (DbCache.Exists(config.CacheType, name.ToLower())) { var sql = MapXml.GetMapSql(name, ref param, db, key); var result = ExecuteSqlPage <T>(pModel, sql, param, db, key); if (MapXml.MapIsForEach(name, config)) { if (db == null) { using (var tempDb = new DataContext(key)) { for (var i = 1; i <= MapXml.MapForEachCount(name, config); i++) { result.list = MapXml.MapForEach <T>(result.list, name, tempDb, config, i); } } } else { result.list = MapXml.MapForEach <T>(result.list, name, db, config); } } return(result); } else { return(new PageResult <T>()); } }
protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape) || currentState == GameState.Exit) //bug chez certains ordis { Exit(); } // Appel du contrôleur approprié if (currentState == GameState.MapEditor) { currentState = controllerEditor.Update(editor, currentState, ref oldMouseState, ref oldKeyboardState); } //controleur des menus, par élimination else if (currentState != GameState.Playing) { if (currentState == GameState.Niveau) { niveaux = MapXml.getListNiveauxName(); currentState = nController.Update(currentState, ref oldKeyboardState, niveaux.Count); } if (currentState == GameState.Death) //la seule différence avec gameover, en attente de niveaux, est le reset du score { niveau.getJoueur().resetHealth(); niveau.getJoueur().ResetPos(); niveau.resetMap(); } currentState = menu.Update(currentState, ref oldMouseState, ref oldKeyboardState); } //controleur jeu else { currentState = mController.Update(niveau, currentState, ref oldMouseState, ref oldKeyboardState, niveau.getJoueur().getPosX(), niveau.getJoueur().getPosY()); } // TODO: Add your update logic here base.Update(gameTime); }
/// <summary> /// 执行写操作 /// </summary> public WriteReturn Write(string name, DbParameter[] param, DataContext db = null, string key = null) { key = key == null?MapDb(name) : key; var config = db == null?DataConfig.Get(key) : db.config; if (config.IsUpdateCache) { InstanceMap(key); } if (DbCache.Exists(config.CacheType, name.ToLower())) { var sql = MapXml.GetMapSql(name, ref param, db, key); return(FastWrite.ExecuteSql(sql, param, db, key)); } else { return(new WriteReturn()); } }
/// <summary> /// 初始化code first 2 /// </summary> /// <param name="list"></param> /// <param name="nameSpace">命名空间</param> /// <param name="dll">dll名称</param> public static void InstanceTable(string nameSpace, string dbKey = null, string dbFile = "db.json", string projectName = null) { var query = new DataQuery(); query.Config = DataConfig.Get(dbKey, projectName, dbFile); query.Key = dbKey; MapXml.CreateLogTable(query); AppDomain.CurrentDomain.GetAssemblies().ToList().ForEach(assembly => { try { assembly.ExportedTypes.ToList().ForEach(a => { var typeInfo = (a as TypeInfo); if (typeInfo.Namespace != null && typeInfo.Namespace == nameSpace && typeInfo.GetCustomAttribute <TableAttribute>() != null) { BaseTable.Check(query, a.Name, typeInfo.DeclaredProperties.ToList(), typeInfo.GetCustomAttributes().ToList()); } }); } catch (Exception ex) { } }); }
public static Font ToFontXml(CopticFont font) { var xml = new Font() { Name = font.Name, FontName = font.FontName, IsJenkimBefore = font.IsJenkimBefore, IsCopticStandard = font.IsCopticStandard, Charmap = new List <MapXml>() }; foreach (string key in font.Charmap.Keys) { string value; font.Charmap.TryGetValue(key, out value); var pair = new MapXml() { BaseCharacter = key, NewCharacter = value }; xml.Charmap.Add(pair); } return(xml); }
private static void MapModifiers(MapXml.MapModifiers mapmods, bool isConstructor, out bool setmodifiers, ref MethodAttributes attribs) { setmodifiers = false; Modifiers modifiers = (Modifiers)mapmods; if((modifiers & Modifiers.Public) != 0) { attribs |= MethodAttributes.Public; } else if((modifiers & Modifiers.Protected) != 0) { attribs |= MethodAttributes.FamORAssem; } else if((modifiers & Modifiers.Private) != 0) { attribs |= MethodAttributes.Private; } else { attribs |= MethodAttributes.Assembly; } if((modifiers & Modifiers.Static) != 0) { attribs |= MethodAttributes.Static; if((modifiers & Modifiers.Final) != 0) { setmodifiers = true; } } else if(!isConstructor) { // NOTE we're abusing the MethodAttributes.NewSlot and Modifiers.Final combination to mean non-virtual if((modifiers & Modifiers.Final) != 0 && (attribs & MethodAttributes.NewSlot) != 0 && (attribs & MethodAttributes.Virtual) == 0) { // remove NewSlot, because it doesn't make sense on a non-virtual method attribs &= ~MethodAttributes.NewSlot; } else { if((modifiers & Modifiers.Private) == 0) { attribs |= MethodAttributes.Virtual; } if((modifiers & Modifiers.Final) != 0) { attribs |= MethodAttributes.Final; } else if((modifiers & Modifiers.Abstract) != 0) { attribs |= MethodAttributes.Abstract; } } } if((modifiers & Modifiers.Synchronized) != 0) { throw new NotImplementedException(); } }
public object Invoke(object proxy, MethodInfo method, object[] args) { var pModel = new PageModel(); var param = new List <DbParameter>(); var config = DataConfig.GetConfig(); var key = string.Format("{0}.{1}", method.DeclaringType.FullName, method.Name); if (DbCache.Exists(config.CacheType, key)) { var model = DbCache.Get <ServiceModel>(config.CacheType, key); if (model.isPage) { pModel = (PageModel)args.ToList().Find(a => a.GetType() == typeof(PageModel)); } config = DataConfig.GetConfig(model.dbKey); if (model.isSysType) { for (int i = 0; i < args.Length; i++) { if (args[i].GetType() == typeof(PageModel)) { continue; } var temp = DbProviderFactories.GetFactory(config.ProviderName).CreateParameter(); temp.ParameterName = model.param.GetValue(i.ToString()).ToStr(); temp.Value = args[i]; param.Add(temp); } } else if (model.isDic) { if (!args.ToList().Exists(a => a.GetType() == typeof(Dictionary <string, object>))) { throw new Exception($"error: service {method.DeclaringType.Name} , method {method.Name} , param type {args[0].GetType().Name} is not support"); } var dic = (Dictionary <string, object>)args.ToList().Find(a => a.GetType() == typeof(Dictionary <string, object>)); var tempDic = new Dictionary <int, string>(); foreach (KeyValuePair <string, object> keyValue in dic) { key = string.Format("{0}{1}", config.Flag, keyValue.Key).ToLower(); if (model?.sql.IndexOf(key) > 0 || model.isXml) { tempDic.Add((int)(model?.sql.IndexOf(key)), keyValue.Key); } } var list = tempDic.OrderBy(d => d.Key).ToList(); foreach (KeyValuePair <int, string> keyValue in list) { var temp = DbProviderFactories.GetFactory(config.ProviderName).CreateParameter(); temp.ParameterName = keyValue.Value; temp.Value = dic.GetValue(keyValue.Value); param.Add(temp); } } else { var data = args.ToList().Find(a => a.GetType() != typeof(PageModel)); var type = method.GetParameters().ToList().Find(a => a.ParameterType != typeof(PageModel)).ParameterType; for (int i = 0; i < model.param.Count; i++) { var temp = DbProviderFactories.GetFactory(config.ProviderName).CreateParameter(); temp.ParameterName = model.param.GetValue(i.ToString()).ToStr(); temp.Value = BaseEmit.Get(data, temp.ParameterName); temp.ParameterName = temp.ParameterName.ToLower(); param.Add(temp); } } if (model.isXml) { model.sql = MapXml.GetFastMapSql(method, config, ref param); } using (var db = new DataContext(config.Key)) { if (model.isWrite) { return(db.ExecuteSql(model.sql, param.ToArray(), Aop.AopType.FaseWrite).writeReturn); } else { return(db.FastReadAttribute(model, param, pModel)); } } } throw new Exception($"error: service {method.DeclaringType.Name} , method {method.Name} not exists"); }
private void viewDataButton_Click(object sender, EventArgs e) { string errMessage; bool checkRes = CheckDrives(out errMessage); if (!checkRes) { MainForm.ShowErrorFlexMessage(errMessage, "Внимание"); return; } string filename = ""; if (flashRButton.Checked) { string flashRoot = flashBox.Text.Substring(0, 1); filename = string.Format(@"{0}:\\Государственный пенсионный фонд ПМР\{1}.{2}\edatacon.pfs", flashRoot, _organization.regnumVal, _repYear); } else if (internetRButton.Checked) { filename = Path.Combine(Path.GetTempPath(), Settings.Default.TempFolder); filename = Path.Combine(filename, "edatacon.pfs"); } try { if (!ReadDisk(out errMessage)) { MainForm.ShowWarningMessage(errMessage, "Внимание"); } } catch { if (cdRButton.Checked) { errMessage = "Не удалось считать ключевые данные с диска!\nВозможно Вы вставили неверный диск."; } else { errMessage = "Не удалось считать ключевые данные с файла!\nВозможно Вы вставили неверный файл."; } MainForm.ShowWarningMessage(errMessage, "Внимание"); return; } if (!File.Exists(filename)) { MainForm.ShowInfoMessage("Сначала необходимо сформировать электронный файл для обмена с ЕГФСС", "Внимание"); return; } if (_container != null) { _container.Close(); } _container = new CompoundFile(filename); CFStream mapStream = _container.RootStorage.GetStream("map"); byte[] mapBytes = Storage.DecryptStream(mapStream, _diskKey, _diskTable); //string mapStr = Encoding.GetEncoding(1251).GetString(mapBytes); CFStorage stylesDir = _container.RootStorage.GetStorage("styles"); CFStream mapStyleStream = stylesDir.GetStream("map_style"); byte[] mapStyleBytes = Storage.DecryptStream(mapStyleStream, _diskKey, _diskTable); //string styleStr = Encoding.GetEncoding(1251).GetString(mapStyleBytes); _container.Close(); OrgPropXml props = CfProperties.ReadProperty(filename); string propHtml = props.GetHTML(); string htmlStr; try { htmlStr = MapXml.GetHTML(mapBytes, mapStyleBytes); } catch (XsltException ex) { #region Текст сообщения всплывающего сообщения MainForm.ShowWarningFlexMessage( "Электронный контейнер был сформирован программой версси 3.2.06 или ниже.\nБудет использован файл стиля из текущей версии программы.\n" + ex.Message, "Внимание"); #endregion htmlStr = MapXml.GetHTML(mapBytes); } catch (Exception ex) { MainForm.ShowWarningFlexMessage(ex.Message, "Необработанная ошибка"); htmlStr = MapXml.GetHTML(mapBytes); } WebBrowser reportWb = new WebBrowser(); htmlStr = htmlStr.Replace("<DIV class=\"insert_here\" />", propHtml); reportWb.DocumentText = htmlStr; MyPrinter.ShowWebPage(reportWb); reportWb.Navigating += new WebBrowserNavigatingEventHandler(reportWB_Navigating); }
protected void loadXml() { m_mapXml = Ctx.m_instance.m_xmlCfgMgr.getXmlCfg <MapXml>(XmlCfgID.eXmlMapCfg); }
void BeginRequest(object sender, EventArgs e) { var success = true; var dic = new Dictionary <string, object>(); var param = new List <DbParameter>(); var context = ((HttpApplication)sender); var key = context.Request.CurrentExecutionFilePath; key = string.IsNullOrEmpty(key) ? "" : key.Substring(1, key.Length - 1); if (FastMap.IsExists(key)) { context.Response.StatusCode = 200; context.Response.ContentType = "application/Json"; var data = new List <Dictionary <string, object> >(); var pageInfo = new PageResult(); var dbKey = FastMap.MapDb(key).ToStr(); var type = FastMap.MapType(key).ToStr(); var config = FastMap.DbConfig(dbKey); var url = context.Request.Form; if (url.Count == 0) { url = context.Request.QueryString; } var pageSize = url.GetValues("pageSize").ToStr().ToInt(10); var pageId = url.GetValues("pageId").ToStr().ToInt(1); foreach (var item in url) { var temp = DbProviderFactories.GetFactory(config.ProviderName).CreateParameter(); temp.ParameterName = item.ToStr(); temp.Value = url.Get(item.ToStr()); param.Add(temp); var existsKey = FastMap.MapExists(key, temp.ParameterName); var checkKey = FastMap.MapCheck(key, temp.ParameterName); //required if (!string.IsNullOrEmpty(FastMap.MapRequired(key, temp.ParameterName))) { dic.Add("success", false); dic.Add("error", string.Format("{0}不能为空", item)); param.Remove(temp); break; } //max length if (FastMap.MapMaxlength(key, temp.ParameterName).ToInt(0) != 0) { if (!(FastMap.MapMaxlength(key, temp.ParameterName).ToInt(0) >= temp.Value.ToStr().Length)) { dic.Add("success", false); dic.Add("error", string.Format("{0}:{1},最大长度{2}", item, temp.Value.ToStr(), FastMap.MapMaxlength(key, temp.ParameterName))); param.Remove(temp); break; } } //exists if (!string.IsNullOrEmpty(existsKey)) { var existsListParam = new List <DbParameter>(); var existsParam = DbProviderFactories.GetFactory(config.ProviderName).CreateParameter(); existsParam.ParameterName = temp.ParameterName; existsParam.Value = temp.Value; existsListParam.Add(existsParam); var checkData = FastMap.Query(existsKey, existsListParam.ToArray())?.First() ?? new Dictionary <string, object>(); if (checkData.GetValue("count").ToStr().ToInt(0) >= 1) { dic.Add("success", false); dic.Add("error", string.Format("{0}:{1}已存在", item, temp.Value)); param.Remove(temp); break; } } //check if (!string.IsNullOrEmpty(checkKey)) { var checkListParam = new List <DbParameter>(); var checkParam = DbProviderFactories.GetFactory(config.ProviderName).CreateParameter(); checkParam.ParameterName = temp.ParameterName; checkParam.Value = temp.Value; checkListParam.Add(checkParam); var checkData = FastMap.Query(existsKey, checkListParam.ToArray())?.First() ?? new Dictionary <string, object>(); if (checkData.GetValue("count").ToStr().ToInt(0) < 1) { dic.Add("success", false); dic.Add("error", string.Format("{0}:{1}不存在", item, temp.Value)); param.Remove(temp); break; } } //date if (string.Compare(FastMap.MapDate(key, temp.ParameterName).ToStr(), "true", true) == 0) { if (!BaseRegular.IsDate(temp.Value.ToStr())) { dic.Add("success", false); dic.Add("error", string.Format("{0}:{1},不是日期类型", item, temp.Value)); param.Remove(temp); break; } temp.Value = temp.Value.ToDate(); temp.DbType = System.Data.DbType.DateTime; } } if (dic.Count > 0) { context.Response.StatusCode = 200; context.Response.ContentType = "application/Json"; context.Response.Write(BaseJson.ModelToJson(dic)); context.Response.End(); } else { using (var db = new DataContext(dbKey)) { var tempParam = param.ToArray(); var sql = MapXml.GetMapSql(key, ref tempParam, db, dbKey); if (string.Compare(type, AppConfig.PageAll, true) == 0 || string.Compare(type, AppConfig.Page, true) == 0) { success = true; var page = new PageModel(); page.PageSize = pageSize == 0 ? 10 : pageSize; page.PageId = pageId == 0 ? 1 : pageId; pageInfo = db.GetPageSql(page, sql, tempParam).PageResult; dic.Add("data", pageInfo.list); dic.Add("page", pageInfo.pModel); } else if (string.Compare(type, AppConfig.All, true) == 0) { success = true; data = db.ExecuteSqlList(sql, tempParam, false).DicList; dic.Add("data", data); } else if (string.Compare(type, AppConfig.Write, true) == 0 && param.Count > 0) { var result = db.ExecuteSqlList(sql, tempParam, false).writeReturn; if (result.IsSuccess) { success = true; } else { success = false; dic.Add("error", result.Message); } } else { if (param.Count > 0) { success = true; data = db.ExecuteSqlList(sql, tempParam, false).DicList; dic.Add("data", data); } else { success = false; } } } } //if (FastMap.MapView(key).ToStr() != "") //{ // context.Response.ContentType = "text/html;charset=utf-8"; //} //else { dic.Add("success", success); context.Response.Write(BaseJson.ModelToJson(dic)); context.Response.End(); } } }
protected void loadXml() { m_mapXml = Ctx.m_instance.m_xmlCfgMgr.getXmlCfg<MapXml>(XmlCfgID.eXmlMapCfg); }
public async Task ContentAsync(HttpContext context, IFastRepository IFast, bool IsResource, string dbFile = "db.json") { var name = context.Request.Path.Value.ToStr().Substring(1, context.Request.Path.Value.ToStr().Length - 1).ToLower(); var urlParam = HttpUtility.UrlDecode(GetUrlParam(context)); var success = true; var dic = new Dictionary <string, object>(); var data = new List <Dictionary <string, object> >(); var dbKey = IFast.MapDb(name).ToStr(); var pageInfo = new PageResult(); context.Response.StatusCode = 200; context.Response.ContentType = "application/Json"; if (!IFast.IsExists(name)) { dic.Add("success", false); dic.Add("error", "接口不存在"); await context.Response.WriteAsync(BaseJson.ModelToJson(dic), Encoding.UTF8).ConfigureAwait(false); } else if (dbKey == "") { dic.Add("success", false); dic.Add("error", string.Format("map id {0}的db没有配置", name)); await context.Response.WriteAsync(BaseJson.ModelToJson(dic), Encoding.UTF8).ConfigureAwait(false); } else if (IFast.IsExists(name)) { var param = new List <DbParameter>(); foreach (var item in IFast.MapParam(name)) { var checkKey = IFast.MapCheck(name, item); var existsKey = IFast.MapExists(name, item); var tempParam = DbProviderFactories.GetFactory(IFast.MapDb(name), IsResource, dbFile).CreateParameter(); tempParam.ParameterName = item; tempParam.Value = GetUrlParam(urlParam, item); param.Add(tempParam); if (!string.IsNullOrEmpty(IFast.MapRequired(name, item))) { if (!(string.Compare(IFast.MapRequired(name, item), "true", true) == 0 && !string.IsNullOrEmpty(tempParam.Value.ToStr()))) { dic.Add("success", false); dic.Add("error", string.Format("{0}不能为空", item)); param.Remove(tempParam); break; } } if (IFast.MapMaxlength(name, item).ToInt(0) != 0) { if (!(IFast.MapMaxlength(name, item).ToInt(0) >= tempParam.Value.ToStr().Length)) { dic.Add("success", false); dic.Add("error", string.Format("{0}:{1},最大长度{2}", item, tempParam.Value.ToStr(), IFast.MapMaxlength(name, item))); param.Remove(tempParam); break; } } if (!string.IsNullOrEmpty(existsKey)) { var existsListParam = new List <DbParameter>(); var existsParam = DbProviderFactories.GetFactory(IFast.MapDb(existsKey), IsResource, dbFile).CreateParameter(); existsParam.ParameterName = item; existsParam.Value = tempParam.Value; existsListParam.Add(existsParam); var checkData = IFast.Query(existsKey, existsListParam.ToArray())?.First() ?? new Dictionary <string, object>(); if (checkData.GetValue("count").ToStr().ToInt(0) >= 1) { dic.Add("success", false); dic.Add("error", string.Format("{0}:{1}已存在", item, tempParam.Value)); param.Remove(tempParam); break; } } if (!string.IsNullOrEmpty(checkKey)) { var checkListParam = new List <DbParameter>(); var checkParam = DbProviderFactories.GetFactory(IFast.MapDb(checkKey), IsResource, dbFile).CreateParameter(); checkParam.ParameterName = item; checkParam.Value = GetUrlParam(urlParam, item); checkListParam.Add(checkParam); var checkData = IFast.Query(existsKey, checkListParam.ToArray())?.First() ?? new Dictionary <string, object>(); if (checkData.GetValue("count").ToStr().ToInt(0) < 1) { dic.Add("success", false); dic.Add("error", string.Format("{0}:{1}不存在", item, tempParam.Value)); param.Remove(tempParam); break; } } if (string.Compare(IFast.MapDate(name, item).ToStr(), "true", true) == 0) { if (!BaseRegular.IsDate(tempParam.Value.ToStr())) { dic.Add("success", false); dic.Add("error", string.Format("{0}:{1},不是日期类型", item, tempParam.Value)); param.Remove(tempParam); break; } tempParam.Value = tempParam.Value.ToDate(); tempParam.DbType = System.Data.DbType.DateTime; } if (tempParam.Value.ToStr() == "") { param.Remove(tempParam); } } using (var db = new DataContext(dbKey)) { var tempParam = param.ToArray(); var sql = MapXml.GetMapSql(name, ref tempParam, db, dbKey); if (dic.Count > 0) { await context.Response.WriteAsync(BaseJson.ModelToJson(dic), Encoding.UTF8).ConfigureAwait(false); } else if (string.Compare(IFast.MapType(name).ToStr(), AppConfig.PageAll, true) == 0 || string.Compare(IFast.MapType(name).ToStr(), AppConfig.Page, true) == 0) { success = true; var pageSize = GetUrlParam(urlParam, "PageSize"); var pageId = GetUrlParam(urlParam, "PageId"); var page = new PageModel(); page.PageSize = pageSize.ToInt(0) == 0 ? 10 : pageSize.ToInt(0); page.PageId = pageId.ToInt(0) == 0 ? 1 : pageId.ToInt(0); pageInfo = db.GetPageSql(page, sql, tempParam).PageResult; if (IFast.MapView(name).ToStr() == "") { dic.Add("data", pageInfo.list); dic.Add("page", pageInfo.pModel); } } else if (string.Compare(IFast.MapType(name).ToStr(), AppConfig.All, true) == 0) { success = true; data = db.ExecuteSqlList(sql, tempParam, false).DicList; dic.Add("data", data); } else if (string.Compare(IFast.MapType(name).ToStr(), AppConfig.Write, true) == 0 && param.Count > 0) { var result = db.ExecuteSqlList(sql, tempParam, false).writeReturn; if (result.IsSuccess) { success = true; } else { success = false; dic.Add("error", result.Message); } } else { if (param.Count > 0) { success = true; data = db.ExecuteSqlList(sql, tempParam, false).DicList; dic.Add("data", data); } else { success = false; } } } dic.Add("success", success); await context.Response.WriteAsync(BaseJson.ModelToJson(dic), Encoding.UTF8).ConfigureAwait(false); } }
/// <summary> /// 初始化map 3 /// </summary> /// <returns></returns> private void InstanceMap(string dbKey = null, string dbFile = "db.json", string mapFile = "map.json") { var list = BaseConfig.GetValue <MapConfigModel>(AppSettingKey.Map, mapFile); var config = DataConfig.Get(dbKey, null, dbFile); var db = new DataContext(dbKey); var query = new DataQuery { Config = config, Key = dbKey }; list.Path.ForEach(p => { var info = new FileInfo(p); var key = BaseSymmetric.Generate(info.FullName); if (!DbCache.Exists(config.CacheType, key)) { var temp = new MapXmlModel(); temp.LastWrite = info.LastWriteTime; temp.FileKey = MapXml.ReadXml(info.FullName, config, info.Name.ToLower().Replace(".xml", "")); temp.FileName = info.FullName; if (MapXml.SaveXml(dbKey, key, info, config, db)) { DbCache.Set <MapXmlModel>(config.CacheType, key, temp); } } else if ((DbCache.Get <MapXmlModel>(config.CacheType, key).LastWrite - info.LastWriteTime).Milliseconds != 0) { DbCache.Get <MapXmlModel>(config.CacheType, key).FileKey.ForEach(a => { DbCache.Remove(config.CacheType, a); }); var model = new MapXmlModel(); model.LastWrite = info.LastWriteTime; model.FileKey = MapXml.ReadXml(info.FullName, config, info.Name.ToLower().Replace(".xml", "")); model.FileName = info.FullName; if (MapXml.SaveXml(dbKey, key, info, config, db)) { DbCache.Set <MapXmlModel>(config.CacheType, key, model); } } }); if (config.IsMapSave) { query.Config.DesignModel = FastData.Core.Base.Config.CodeFirst; if (query.Config.DbType == DataDbType.Oracle) { var listInfo = typeof(FastData.Core.DataModel.Oracle.Data_MapFile).GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly).ToList(); var listAttribute = typeof(FastData.Core.DataModel.Oracle.Data_MapFile).GetTypeInfo().GetCustomAttributes().ToList(); BaseTable.Check(query, "Data_MapFile", listInfo, listAttribute); } if (query.Config.DbType == DataDbType.MySql) { var listInfo = typeof(FastData.Core.DataModel.MySql.Data_MapFile).GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly).ToList(); var listAttribute = typeof(FastData.Core.DataModel.MySql.Data_MapFile).GetTypeInfo().GetCustomAttributes().ToList(); BaseTable.Check(query, "Data_MapFile", listInfo, listAttribute); } if (query.Config.DbType == DataDbType.SqlServer) { var listInfo = typeof(FastData.Core.DataModel.SqlServer.Data_MapFile).GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly).ToList(); var listAttribute = typeof(FastData.Core.DataModel.SqlServer.Data_MapFile).GetTypeInfo().GetCustomAttributes().ToList(); BaseTable.Check(query, "Data_MapFile", listInfo, listAttribute); } } db.Dispose(); }
/// <summary> /// Получить ссылку на объект контейнера с заполненными данными /// </summary> /// <param name="mapXml">Карта</param> /// <param name="szv3Xml">Сводная ведомость</param> /// <param name="szv2XmlArray">Описи пакетов</param> /// <param name="szv1XmlArray">Документы СЗВ-1</param> /// <param name="diskKey">Ключ</param> /// <param name="diskTable">Таблица</param> /// <returns></returns> public static CompoundFile MakeContainer(XmlDocument mapXml, XmlDocument szv3Xml, IEnumerable <XmlDocument> szv2XmlArray, IEnumerable <IEnumerable <XmlDocument> > szv1XmlArray, byte[] diskKey, byte[] diskTable) { XmlElement rootMap = mapXml[MapXml.tagTopics]; XmlElement svodRootMap = rootMap[MapXml.tagSvod]; XmlNodeList lists = rootMap.GetElementsByTagName(MapXml.tagTopics); if (lists.Count != szv2XmlArray.Count() || lists.Count != szv1XmlArray.Count()) { return(null); } CompoundFile container = new CompoundFile(CFSVersion.Ver_3, false, false); CFStorage dir4 = container.RootStorage.AddStorage(rootMap.GetAttribute(MapXml.paramID)); for (int i = 0; i < szv2XmlArray.Count(); i++) { XmlElement curList = lists[i] as XmlElement; XmlElement curOpis = curList[MapXml.tagOpis]; CFStorage curDir = dir4.AddStorage(curList.GetAttribute(MapXml.paramID)); XmlDocument szv2Xml = szv2XmlArray.ElementAt(i); CFStream opisStream = AddStream(curDir, szv2Xml, diskKey, diskTable); curOpis[MapXml.tagFilename].InnerText = opisStream.Name; XmlNodeList docs = curList.GetElementsByTagName(MapXml.tagTopic); if (docs.Count != szv1XmlArray.ElementAt(i).Count()) { continue; } for (int j = 0; j < szv1XmlArray.ElementAt(i).Count(); j++) { /*if (i >= 10 && j >= 51) * { * Console.WriteLine("Packet {0}, Doc {1}", i, j); * }*/ XmlDocument szv1Xml = szv1XmlArray.ElementAt(i).ElementAt(j); XmlElement curDoc = docs[j] as XmlElement; CFStream docStream = AddStream(curDir, szv1Xml, diskKey, diskTable); curDoc[MapXml.tagFilename].InnerText = docStream.Name; } } CFStream svod = AddStream(dir4, szv3Xml, diskKey, diskTable); svodRootMap[MapXml.tagFilename].InnerText = svod.Name; CFStream map = container.RootStorage.AddStream("map"); SetDataToStream(map, mapXml.InnerXml, diskKey, diskTable); CFStorage styleDir = container.RootStorage.AddStorage("styles"); CFStream mapStyleStream = styleDir.AddStream("map_style"); CFStream szv1StyleStream = styleDir.AddStream("szv_style"); CFStream szv3StyleStream = styleDir.AddStream("svod_style"); CFStream szv2StyleStream = styleDir.AddStream("szv_opis_style"); SetDataToStream(mapStyleStream, File.ReadAllBytes(MapXml.GetXslUrl()), diskKey, diskTable); SetDataToStream(szv1StyleStream, File.ReadAllBytes(Szv1Xml.GetXslUrl()), diskKey, diskTable); SetDataToStream(szv3StyleStream, File.ReadAllBytes(Szv3Xml.GetXslUrl()), diskKey, diskTable); SetDataToStream(szv2StyleStream, File.ReadAllBytes(Szv2Xml.GetXslUrl()), diskKey, diskTable); return(container); }
public static void InstanceService(IServiceCollection serviceCollection, string nameSpace) { var handler = new ProxyHandler(); AppDomain.CurrentDomain.GetAssemblies().ToList().ForEach(assembly => { try { assembly.ExportedTypes.ToList().ForEach(a => { if (a.Namespace == nameSpace) { var isRegister = false; a.GetMethods().ToList().ForEach(m => { ConfigModel config = new ConfigModel(); var model = new ServiceModel(); var read = m.GetCustomAttribute <FastReadAttribute>(); var write = m.GetCustomAttribute <FastWriteAttribute>(); var map = m.GetCustomAttribute <FastMapAttribute>(); if (read != null) { isRegister = true; model.isWrite = false; model.sql = read.sql.ToLower(); model.dbKey = read.dbKey; config = DataConfig.Get(model.dbKey); model.isPage = read.isPage; model.type = m.ReturnType; ServiceParam(m, model, config); } if (write != null) { isRegister = true; model.isWrite = true; model.sql = write.sql.ToLower(); model.dbKey = write.dbKey; model.type = m.ReturnType; config = DataConfig.Get(model.dbKey); ServiceParam(m, model, config); model.isList = false; } if (map != null) { isRegister = true; model.isWrite = false; model.isXml = true; model.dbKey = map.dbKey; model.isPage = map.isPage; model.type = m.ReturnType; config = DataConfig.Get(model.dbKey); MapXml.ReadFastMap(map.xml, m, config); ServiceParam(m, model, config); } if (isRegister) { var key = string.Format("{0}.{1}", a.FullName, m.Name); DbCache.Set <ServiceModel>(config.CacheType, key, model); } }); if (isRegister) { var service = FastProxy.Invoke(a, handler); serviceCollection.AddSingleton(a, service); } } }); } catch (Exception ex) { } }); }
public static void InstanceMapResource(string dbKey = null, string dbFile = "db.json", string mapFile = "map.json") { var projectName = Assembly.GetCallingAssembly().GetName().Name; var config = DataConfig.Get(dbKey, projectName, dbFile); var db = new DataContext(dbKey); var assembly = Assembly.Load(projectName); var map = new MapConfigModel(); using (var resource = assembly.GetManifestResourceStream(string.Format("{0}.{1}", projectName, mapFile))) { if (resource != null) { using (var reader = new StreamReader(resource)) { var content = reader.ReadToEnd(); map.Path = BaseJson.JsonToModel <List <string> >(BaseJson.JsonToDic(BaseJson.ModelToJson(BaseJson.JsonToDic(content).GetValue(AppSettingKey.Map))).GetValue("Path").ToStr()); } } else { map = BaseConfig.GetValue <MapConfigModel>(AppSettingKey.Map, mapFile); } } if (map.Path == null) { return; } map.Path.ForEach(a => { using (var resource = assembly.GetManifestResourceStream(string.Format("{0}.{1}", projectName, a.Replace("/", ".")))) { var xml = ""; if (resource != null) { using (var reader = new StreamReader(resource)) { xml = reader.ReadToEnd(); } } var info = new FileInfo(a); var key = BaseSymmetric.Generate(info.FullName); if (!DbCache.Exists(config.CacheType, key)) { var temp = new MapXmlModel(); temp.LastWrite = info.LastWriteTime; temp.FileKey = MapXml.ReadXml(info.FullName, config, info.Name.ToLower().Replace(".xml", ""), xml); temp.FileName = info.FullName; if (MapXml.SaveXml(dbKey, key, info, config, db)) { DbCache.Set <MapXmlModel>(config.CacheType, key, temp); } } else if ((DbCache.Get <MapXmlModel>(config.CacheType, key).LastWrite - info.LastWriteTime).Milliseconds != 0) { DbCache.Get <MapXmlModel>(config.CacheType, key).FileKey.ForEach(f => { DbCache.Remove(config.CacheType, f); }); var model = new MapXmlModel(); model.LastWrite = info.LastWriteTime; model.FileKey = MapXml.ReadXml(info.FullName, config, info.Name.ToLower().Replace(".xml", ""), xml); model.FileName = info.FullName; if (MapXml.SaveXml(dbKey, key, info, config, db)) { DbCache.Set <MapXmlModel>(config.CacheType, key, model); } } } }); }