Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace ImdbLoader
- {
- class Program
- {
- private static DocumentStore Store;
- private static Encoding encoding = Encoding.GetEncoding(1252);
- static void Main(string[] args)
- {
- Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
- Reinitialize();
- Test();
- Console.WriteLine("Press any key to close...");
- Console.ReadLine();
- }
- private static void Reinitialize()
- {
- if (Store != null)
- {
- Store.Dispose();
- Store = null;
- }
- Store = new DocumentStore { ConnectionStringName = "RavenDB" };
- Store.Conventions.IdentityPartsSeparator = "-";
- Store.Initialize();
- }
- private static void Test()
- {
- Console.WriteLine(@"Exporting all MediaIds to file...");
- var mediaIdsPath = Path.GetTempFileName();
- var mediaIdsOrderedPath = Path.GetTempFileName();
- using (var f = File.Open(mediaIdsPath, FileMode.Truncate, FileAccess.Write, FileShare.Read))
- {
- using (var sw = new StreamWriter(f, encoding))
- {
- int offset = 0, num = 0, i = 0, batchSize = 1024;
- while (true)
- {
- if ((num = WriteDocs(offset, batchSize, sw)) == 0) break;
- offset += num;
- //uncomment to fix OutOfMemoryException
- //if (++i % 10 == 0) Reinitialize();
- }
- }
- }
- }
- private static int WriteDocs(int offset, int batchSize, StreamWriter sw)
- {
- int num = 0;
- using (var session = Store.OpenSession())
- {
- using (var foo = session.Advanced.DocumentStore.DisableAggressiveCaching())
- {
- var batch = session.Query<ImdbMedia>("Raven/DocumentsByEntityName")
- .Skip(offset)
- .Take(batchSize)
- .Select(x => new { GlobalId = x.Id, ImdbFullTitle = x.ImdbFullTitle });
- foreach (var item in batch)
- {
- sw.Write(string.Format("{0}{1}\t\t\t{2}", (offset + num++ > 0 ? "\n" : ""), item.ImdbFullTitle, item.GlobalId));
- }
- sw.Flush();
- }
- }
- return num;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment