private void btnSave_Click(object sender, EventArgs e) { Bitmap[] currentBitmaps = tbViewer.GetSelectedBitmaps(); if (currentBitmaps.Count() == 1) { if (sfdSprite.ShowDialog() == DialogResult.OK) { currentBitmaps[0].Save(sfdSprite.FileName, System.Drawing.Imaging.ImageFormat.Bmp); } } else if (currentBitmaps.Count() > 1) { if (fbdSprites.ShowDialog() == DialogResult.OK) { MemoryBoxResult result = MemoryBoxResult.Null; for (int i = 0; i < currentBitmaps.Count(); i++) { string filename = String.Format("{0}\\Sprite_{1}.bmp", fbdSprites.SelectedPath, i.ToString("000")); if (File.Exists(filename)) { if (result == MemoryBoxResult.Null) { MemoryBox memoryBox = new MemoryBox(); result = memoryBox.ShowMemoryDialog( String.Format("The file \"Sprite_{0}.bmp\" already exists, overwrite?", i.ToString("000")), "Overwrite Files?"); } else { if (result == MemoryBoxResult.Cancel) { break; } switch ((MemoryBoxResult)result) { case MemoryBoxResult.Yes: currentBitmaps[i].Save(filename, System.Drawing.Imaging.ImageFormat.Bmp); result = MemoryBoxResult.Null; break; case MemoryBoxResult.YesToAll: currentBitmaps[i].Save(filename, System.Drawing.Imaging.ImageFormat.Bmp); break; case MemoryBoxResult.No: result = MemoryBoxResult.Null; break; } } } else { currentBitmaps[i].Save(filename, System.Drawing.Imaging.ImageFormat.Bmp); } // End - if (File.Exists(filename)) } // End - for (int i = 0; i < currentBitmaps.Count(); i++) { } // End - if (fbdSprites.ShowDialog() == DialogResult.OK) } // End - else if (currentBitmaps.Count() > 1) }
private static void Main(string[] args) { // unless otherwise stated, all values presented are the default if not specified var memory = MemoryBox.GetInstance( new MemoryConfiguration { DefaultTimeToLive = new TimeSpan(1, 0, 0, 0), DefaultTimeToRefresh = new TimeSpan(0, 0, 5, 0), ExpirationScanFrequency = new TimeSpan(0, 1, 0, 0), PoolSize = 1 // hardcoded to 1 on creation of connectionpool }); // redis connection assumes SSL is enabled; if not you must adjust port and UseSSL var redis = RedisBox.GetInstance( new RedisConfiguration { DatabaseID = 0, DefaultTimeToLive = new TimeSpan(1, 0, 0, 0), DefaultTimeToRefresh = new TimeSpan(0, 0, 5, 0), Host = "<host>", // defaults to 127.0.0.1 Password = "******", // only required if using ssl, defaults to "" PoolSize = 5, Port = 6379, // defaults to 6380 UseSSL = false // defaults to true }); // for documentDB you must replace the string values with whatever you have setup // the backing DB of your cosmosDB MUST be SQL and partitioned/sharded based on /_partitionKey var documentDB = DocumentDBBox.GetInstance( new DocumentDBConfiguration { Collection = "<collection>", ConnectionPolicy = new ConnectionPolicy(), // defaults to nothing configured Database = "<database>", DefaultTimeToLive = new TimeSpan(1, 0, 0, 0), DefaultTimeToRefresh = new TimeSpan(0, 0, 5, 0), EndpointURI = new Uri("https://<account>.documents.azure.com:443"), PartitionKey = "cache", // defaults to cache, but you can specify what you want PoolSize = 5, PrimaryKey = "<auth_key>" }); // create a new tenancy object` var tenancy = new Tenancy( new ILitterBox[] { memory, redis, documentDB }); // subscribe to internal errors tenancy.ExceptionEvent += TenancyOnExceptionEvent; // set an item (will backfill all three caches) var x = tenancy.SetItem( "foo", new LitterBoxItem <dynamic> { Value = new { Args = "boo" } }).GetAwaiter().GetResult(); // get item from cache, checks in order of array initialization. in this case memory -> redis -> documentDB var y = tenancy.GetItem <dynamic>("foo").GetAwaiter().GetResult(); Console.ReadKey(); }