protected void OnGenerateCommonDaoFailed(FileInfo dbJsFile, SchemaResult result) { if (GenerateCommonDaoFailed != null) { GenerateCommonDaoFailed(dbJsFile, result); } }
/// <summary> /// Fetches the Tf2 Item schema. /// </summary> /// <param name="apiKey">The API key.</param> /// <returns>A deserialized instance of the Item Schema.</returns> /// <remarks> /// The schema will be cached for future use if it is updated. /// </remarks> public static TF2Schema FetchSchema(string apiKey) { var url = SchemaApiUrlBase + apiKey; // just let one thread/proc do the initial check/possible update. bool wasCreated; var mre = new EventWaitHandle(false, EventResetMode.ManualReset, SchemaMutexName, out wasCreated); // the thread that create the wait handle will be the one to // write the cache file. The others will wait patiently. if (!wasCreated) { bool signaled = mre.WaitOne(10000); if (!signaled) { return(null); } } HttpWebResponse response = SteamWeb.Request(url, "GET"); DateTime schemaLastModified = response.LastModified; string result = GetSchemaString(response, schemaLastModified); response.Close(); mre.Set(); SchemaResult schemaResult = JsonConvert.DeserializeObject <SchemaResult> (result); return(schemaResult.result ?? null); }
protected void OnGenerateAppDaoFailed(string appName, FileInfo dbJsFile, SchemaResult result) { if (GenerateAppDaoFailed != null) { GenerateAppDaoFailed(appName, dbJsFile, result); } }
public static Schema FetchSchema(string apiKey) { var url = "http://api.steampowered.com/IEconItems_440/GetSchema/v0001/?key=" + apiKey; string cachefile = "tf_schema.cache"; string result; HttpWebResponse response = SteamWeb.Request(url, "GET"); DateTime SchemaLastModified = DateTime.Parse(response.Headers["Last-Modified"]); if (!System.IO.File.Exists(cachefile) || (SchemaLastModified > System.IO.File.GetCreationTime(cachefile))) { StreamReader reader = new StreamReader(response.GetResponseStream()); result = reader.ReadToEnd(); File.WriteAllText(cachefile, result); System.IO.File.SetCreationTime(cachefile, SchemaLastModified); } else { TextReader reader = new StreamReader(cachefile); result = reader.ReadToEnd(); reader.Close(); } response.Close(); SchemaResult schemaResult = JsonConvert.DeserializeObject <SchemaResult> (result); return(schemaResult.result ?? null); }
public static Dota2 FetchSchema(string url) { HttpWebResponse response = Drop.SteamWeb.Request(url, "GET"); string result = Vdf2Json.ConvertVdf2Json(response.GetResponseStream()); response.Close(); SchemaResult schemaResult = JsonConvert.DeserializeObject <SchemaResult>(result); return(schemaResult.items_game ?? null); }
public static Schema FetchSchema(string apiKey) { var url = "http://api.steampowered.com/IEconItems_440/GetSchema/v0001/?key=" + apiKey; string result = SteamWeb.Fetch(url, "GET"); SchemaResult schemaResult = JsonConvert.DeserializeObject <SchemaResult> (result); return(schemaResult.result ?? null); }
public static void SchemaMgrAddTableShouldSuccess() { SchemaManager mgr = new SchemaManager(); SchemaDefinition s = mgr.SetSchema("test"); SchemaResult r = mgr.AddTable("tableOne"); Expect.IsTrue(r.Success); TryDeleteSchema(s); }
public static void SchemaMgrAddColumnShouldSuccess() { string tableName = "tableOne"; SchemaManager mgr = new SchemaManager(); SchemaDefinition s = mgr.SetSchema("test"); SchemaResult r = mgr.AddTable(tableName); r = mgr.AddColumn(tableName, new Column("ColumnOne", DataTypes.Long, false)); Expect.IsTrue(r.Success); }
/// <summary> /// Fetches the Tf2 Item schema. /// </summary> /// <param name="apiKey">The API key.</param> /// <returns>A deserialized instance of the Item Schema.</returns> /// <remarks> /// The schema will be cached for future use if it is updated. /// </remarks> public static Schema FetchSchema(string apiKey, string schemaLang = null) { var url = SchemaApiUrlBase + apiKey; if (schemaLang != null) { url += "&language=" + schemaLang; } // just let one thread/proc do the initial check/possible update. bool wasCreated; EventWaitHandle mre = new EventWaitHandle(false, EventResetMode.ManualReset, SchemaMutexName, out wasCreated); // the thread that create the wait handle will be the one to // write the cache file. The others will wait patiently. if (!wasCreated) { bool signaled = mre.WaitOne(10000); if (!signaled) { return(null); } } try { using (HttpWebResponse response = (new SteamWeb()).Request(url, "GET")) { DateTime schemaLastModified = response.LastModified; string result = GetSchemaString(response, schemaLastModified); // were done here. let others read. mre.Set(); SchemaResult schemaResult = JsonConvert.DeserializeObject <SchemaResult>(result); return(schemaResult?.result ?? null); } } catch (WebException e) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("[ERROR] Failed to download schema ({0}). Retrieving from file cache.", e.Message); Console.ForegroundColor = ConsoleColor.White; string result = GetSchemaString(null, DateTime.Now); mre.Set(); SchemaResult schemaResult = JsonConvert.DeserializeObject <SchemaResult>(result); return(schemaResult?.result ?? null); } }
public static void AddForeignKeyShouldFailIfColumnNotDefined() { SchemaManager mgr = new SchemaManager(); SchemaDefinition s = mgr.SetSchema("test"); mgr.AddTable("TableOne"); mgr.AddTable("ReferringTable"); SchemaResult r = mgr.SetForeignKey("TableOne", "ReferringTable", "TableOneID"); Expect.IsFalse(r.Success); OutLine(r.Message, ConsoleColor.Yellow); TryDeleteSchema(s); }
public static Schema FetchSchema(string apiKey) { var url = "http://api.steampowered.com/IEconItems_570/GetSchema/v0001/?key=" + apiKey + "&language=en"; string cachefile = "d2_schema.cache"; string result = ""; try { HttpWebResponse response = SteamWeb.Request(url, "GET"); DateTime SchemaLastModified = DateTime.Now; try { SchemaLastModified = DateTime.Parse(response.Headers["Last-Modified"]); } catch { SchemaLastModified = DateTime.Now; } if (!System.IO.File.Exists(cachefile) || (SchemaLastModified > System.IO.File.GetCreationTime(cachefile))) { StreamReader reader = new StreamReader(response.GetResponseStream()); result = reader.ReadToEnd(); File.WriteAllText(cachefile, result); System.IO.File.SetCreationTime(cachefile, SchemaLastModified); } else { TextReader reader = new StreamReader(cachefile); result = reader.ReadToEnd(); reader.Close(); } response.Close(); } catch (NullReferenceException ex) { //.net 4.5 will error out on Request. using (var wc = new WebClient()) { result = wc.DownloadString(url); } } SchemaResult schemaResult = JsonConvert.DeserializeObject <SchemaResult> (result); return(schemaResult.result ?? null); }
private void GenerateCommonDao(DirectoryInfo daoBinDir, DirectoryInfo daoTemp, FileInfo jsOrJsonDb) { OnGeneratingCommonDao(jsOrJsonDb, daoBinDir); SchemaResult schemaResult = GenerateDaoForFile(daoBinDir, daoTemp, jsOrJsonDb); if (!schemaResult.Success) { OnGenerateCommonDaoFailed(jsOrJsonDb, schemaResult); } else { OnGenerateCommonDaoSucceeded(jsOrJsonDb, daoBinDir, schemaResult); } }
private static SchemaManager GetTestSchemaManager() { SchemaManager mgr = new SchemaManager(); mgr.AddTable("Person"); mgr.AddColumn("Person", "Id", DataTypes.Long); mgr.AddColumn("Person", "Name", DataTypes.String); mgr.AddTable("Employee"); mgr.AddColumn("Employee", "Id", DataTypes.Long); mgr.AddColumn("Employee", "Salary", DataTypes.Decimal); SchemaResult result = mgr.SetForeignKey("Person", "Employee", "Id", "Id"); Expect.IsTrue(result.Success, $"Message: {result.Message}\r\nException: {result.ExceptionMessage}"); return(mgr); }
private void GenerateAppDao(string appName, DirectoryInfo daoBinDir, DirectoryInfo daoTemp, FileInfo jsOrJsonDb) { OnGeneratingAppDao(appName, jsOrJsonDb, daoBinDir); SchemaResult schemaResult = GenerateDaoForFile(daoBinDir, daoTemp, jsOrJsonDb); if (!schemaResult.Success) { OnGenerateAppDaoFailed(appName, jsOrJsonDb, schemaResult); } else { OnGerateAppDaoSucceeded(appName, jsOrJsonDb, daoBinDir, schemaResult); } }
private static void WriteSqlFile(SchemaResult result) { if (!Arguments.Contains("dll") || result.DaoAssembly == null) { OutLine("Unable to locate Dao assembly fro sql schema generation, specify dll argument", ConsoleColor.Red); } else { FileInfo sqlFile = new FileInfo(Arguments["sql"]); SqlDialect dialect = SqlDialect.MsSql; if (Arguments.Contains("dialect")) { dialect = (SqlDialect)Enum.Parse(typeof(SqlDialect), Arguments["dialect"]); } WriteSqlFile(result.DaoAssembly, sqlFile, dialect); OutLineFormat("Sql script written: {0}", sqlFile.FullName); } }
private static SchemaResult GenerateDaoForFile(DirectoryInfo daoBinDir, DirectoryInfo daoTemp, FileInfo dbJs) { SchemaManager schemaManager = new UuidSchemaManager(); DirectoryInfo partialsDir = new DirectoryInfo(Path.Combine(dbJs.Directory.FullName, "DaoPartials")); SchemaResult schemaResult = new SchemaResult("Generator Not Run, invalid file extension", false); if (dbJs.Extension.ToLowerInvariant().Equals(".js")) { schemaResult = schemaManager.GenerateDao(dbJs, daoBinDir, daoTemp, partialsDir); } else if (dbJs.Extension.ToLowerInvariant().Equals(".json")) { string json = File.ReadAllText(dbJs.FullName); schemaResult = schemaManager.GenerateDao(json, daoBinDir, daoTemp); } return(schemaResult); }
private void RegisterNewCommonDaoDll(FileInfo dbJs, DirectoryInfo daoBin, SchemaResult result) { FileInfo daoDll = new FileInfo(Path.Combine(daoBin.FullName, "{0}.dll"._Format(result.Namespace))); RegisterCommonDaoDll(daoDll); }
public PeekResult Peek(PeekParameters parameters) { try { if (parameters == null) { throw new ArgumentNullException("parameters"); } if (string.IsNullOrWhiteSpace(parameters.ItemUri)) { throw new ArgumentException(Resources.MissingItemUri); } if (Client.IsExistingObject(parameters.ItemUri)) { var readOptions = new ReadOptions { LoadFlags = LoadFlags.Expanded | LoadFlags.WebDavUrls }; var item = Client.Read(parameters.ItemUri, readOptions); switch (GetItemType(item.Id)) { case ItemType.Category: return(CategoryResult.From((CategoryData)item, Client, CurrentUserId)); case ItemType.Component: return(ComponentResult.From((ComponentData)item, CurrentUserId)); case ItemType.ComponentTemplate: return(ComponentTemplateResult.From((ComponentTemplateData)item, Client, CurrentUserId)); case ItemType.Folder: return(FolderResult.From((FolderData)item, CurrentUserId)); case ItemType.Group: return(GroupResult.From((GroupData)item)); case ItemType.Keyword: return(KeywordResult.From((KeywordData)item, CurrentUserId)); case ItemType.MultimediaType: return(MultimediaTypeResult.From((MultimediaTypeData)item)); case ItemType.Page: return(PageResult.From((PageData)item, Client, CurrentUserId)); case ItemType.PageTemplate: return(PageTemplateResult.From((PageTemplateData)item, Client, CurrentUserId)); case ItemType.Publication: return(PublicationResult.From((PublicationData)item, CurrentUserId)); case ItemType.PublicationTarget: return(PublicationTargetResult.From((PublicationTargetData)item)); case ItemType.Schema: return(SchemaResult.From((SchemaData)item, CurrentUserId)); case ItemType.StructureGroup: return(StructureGroupResult.From((StructureGroupData)item, CurrentUserId)); case ItemType.TargetGroup: return(TargetGroupResult.From((TargetGroupData)item, CurrentUserId)); case ItemType.TargetType: return(TargetTypeResult.From((TargetTypeData)item)); case ItemType.TemplateBuildingBlock: return(TemplateBuildingBlockResult.From((TemplateBuildingBlockData)item, Client, CurrentUserId)); case ItemType.User: return(UserResult.From((UserData)item, Client)); case ItemType.VirtualFolder: return(VirtualFolderResult.From((VirtualFolderData)item, CurrentUserId)); } } return(new EmptyResult()); } catch (Exception ex) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
/// <summary> /// Fetches the Tf2 Item schema. /// </summary> /// <param name="apiKey">The API key.</param> /// <returns>A deserialized instance of the Item Schema.</returns> /// <remarks> /// The schema will be cached for future use if it is updated. /// </remarks> public static Schema FetchSchema(string apiKey, string schemaLang = null) { var url = SchemaApiUrlBase + apiKey; if (schemaLang != null) { url += "&format=json&language=" + schemaLang; } // just let one thread/proc do the initial check/possible update. bool wasCreated; var mre = new EventWaitHandle(false, EventResetMode.ManualReset, SchemaMutexName, out wasCreated); // the thread that create the wait handle will be the one to // write the cache file. The others will wait patiently. if (!wasCreated) { bool signaled = mre.WaitOne(10000); if (!signaled) { return(null); } } bool keepUpdating = true; SchemaResult schemaResult = new SchemaResult(); string tmpUrl = url; do { if (schemaResult.result != null) { tmpUrl = url + "&start=" + schemaResult.result.Next; } string result = new SteamWeb().Fetch(tmpUrl, "GET"); if (schemaResult.result == null || schemaResult.result.Items == null) { schemaResult = JsonConvert.DeserializeObject <SchemaResult>(result); } else { SchemaResult tempResult = JsonConvert.DeserializeObject <SchemaResult>(result); var items = schemaResult.result.Items.Concat(tempResult.result.Items); schemaResult.result.Items = items.ToArray(); schemaResult.result.Next = tempResult.result.Next; } if (schemaResult.result.Next <= schemaResult.result.Items.Count()) { keepUpdating = false; } } while (keepUpdating); //Get origin names string itemOriginUrl = SchemaApiItemOriginNamesUrlBase + apiKey; if (schemaLang != null) { itemOriginUrl += "&format=json&language=" + schemaLang; } string resp = new SteamWeb().Fetch(itemOriginUrl, "GET"); var itemOriginResult = JsonConvert.DeserializeObject <SchemaResult>(resp); schemaResult.result.OriginNames = itemOriginResult.result.OriginNames; // were done here. let others read. mre.Set(); DateTime schemaLastModified = DateTime.Now; return(schemaResult.result ?? null); }
private void RegisterNewAppDaoDll(string appName, FileInfo dbJs, DirectoryInfo daoBin, SchemaResult result) { FileInfo daoDll = new FileInfo(Path.Combine(daoBin.FullName, "{0}.dll"._Format(result.Namespace))); DaoProxyRegistration reg = DaoProxyRegistration.Register(daoDll); string name = appName.ToLowerInvariant(); AppDaoProxyRegistrations[name].Add(reg); }
static void Main(string[] args) { SetArguments(args); if (Arguments.Contains("?")) { Usage(Assembly.GetExecutingAssembly()); return; } else if (Arguments.Contains("examples")) { Out("For extraction:\r\n"); Out("LaoTze /f:<file> /conn:<connectionNameFromConfig> /gen:<dirPath> /ns:<defaultNamespace> /dll:<assemblyName> [/v|/s]"); Out("\r\n or To generate from *.db.js\r\n"); Out("LaoTze /root:<project_root_to_search_for_database.db.js>\r\n"); return; } if (Arguments.Contains("pause")) { Pause("Press a key to continue..."); } if (Arguments.Contains("root")) { DirectoryInfo rootDirectory = new DirectoryInfo(Arguments["root"]); if (!rootDirectory.Exists) { OutLineFormat("Specified root directory does not exist: {0}", ConsoleColor.Red, rootDirectory.FullName); Pause(); Environment.Exit(1); } FileInfo[] dbjs = rootDirectory.GetFiles("*.db.js", SearchOption.AllDirectories); if (dbjs.Length > 0) { if (dbjs.Length > 1) { OutLine("Multiple *.db.js files found", ConsoleColor.Red); OutLineFormat("{0}", ConsoleColor.Yellow, dbjs.ToDelimited <FileInfo>(f => f.FullName, "\r\n")); string answer = Prompt("Process each? [y N]", ConsoleColor.Yellow); if (!answer.ToLowerInvariant().Equals("y")) { Exit(1); } } foreach (FileInfo file in dbjs) { try { OutLineFormat("Processing {0}...", ConsoleColor.Yellow, file.FullName); CuidSchemaManager manager = new CuidSchemaManager(); DirectoryInfo fileParent = file.Directory; DirectoryInfo genToDir = GetTargetDirectory(file); bool keep = Arguments.Contains("keep"); DirectoryInfo partialsDir = GetPartialsDir(genToDir); SchemaResult result = null; if (!Arguments.Contains("dll")) { bool compile = !keep; result = manager.GenerateDao(file, compile, keep, genToDir.FullName, partialsDir.FullName); } else { result = manager.GenerateDao(file, new DirectoryInfo(Arguments["dll"]), keep, genToDir.FullName, partialsDir.FullName); } if (!result.Success) { throw new Exception(result.Message); } if (Arguments.Contains("sql")) { WriteSqlFile(result); } OutLine(result.Message, ConsoleColor.Green); if (result.DaoAssembly != null) { OutLineFormat("Compiled to: {0}", result.DaoAssembly.FullName, ConsoleColor.Yellow); } } catch (Exception ex) { OutLineFormat("{0}\r\n\r\n***\r\n{1}", ConsoleColor.Red, ex.Message, ex.StackTrace ?? ""); Pause("Press enter to exit\r\n"); Exit(1); } } Pause("Press enter to exit...\r\n"); } else { OutLine("No *.db.js files were found", ConsoleColor.Yellow); } } else { if (string.IsNullOrEmpty(Arguments["conn"])) { OutLine("Please specify a connection name from the config or a directory to search", ConsoleColor.Yellow); Pause(); } else { Extract(); } } }
protected void OnGenerateCommonDaoSucceeded(FileInfo dbJsFile, DirectoryInfo daoBin, SchemaResult result) { if (GenerateCommonDaoSucceeded != null) { GenerateCommonDaoSucceeded(dbJsFile, daoBin, result); } }
protected void OnGerateAppDaoSucceeded(string appName, FileInfo dbJsFile, DirectoryInfo daoBin, SchemaResult result) { if (GenerateAppDaoSucceeded != null) { GenerateAppDaoSucceeded(appName, dbJsFile, daoBin, result); } }