// Token: 0x0600642E RID: 25646 RVA: 0x0023D190 File Offset: 0x0023B590 public static PostObjectRequest UploadFile(string fileName, string s3FolderName = "other", Action<string> onSuccess = null) { if (Uploader.uploadManager == null) { Uploader.uploadManager = new GameObject(); Uploader.uploadManager.name = "UploadManager"; } S3Manager orAddComponent = Uploader.uploadManager.GetOrAddComponent<S3Manager>(); return orAddComponent.PostObject(fileName, s3FolderName, onSuccess); }
public static Amazon.S3.Model.PostObjectRequest UploadFile(string fileName, string s3FolderName = "other", Action <string> onSuccess = null) { if (uploadManager == null) { uploadManager = new GameObject(); uploadManager.name = "UploadManager"; } S3Manager s3Manager = uploadManager.GetOrAddComponent <S3Manager>(); return(s3Manager.PostObject(fileName, s3FolderName, onSuccess)); }
/// <summary> /// A simple function that takes a string and does a ToUpper /// </summary> /// <param name="input"></param> /// <param name="context"></param> /// <returns></returns> public void FunctionHandler(Amazon.Lambda.SQSEvents.SQSEvent sqsEvent, ILambdaContext context) { string storageConnectionString; if (!ssmParameterManager.TryGetValue(Constants.StorageConnectionStringSSMPath, out storageConnectionString)) { throw new Exception("Storage connection path not defined."); } else { Console.WriteLine($"Storage connection path is set at '{storageConnectionString}'"); } if (!S3Manager.CheckS3Parameters()) { return; } // Check whether the connection string can be parsed. if (CloudStorageAccount.TryParse(storageConnectionString, out storageAccount)) { foreach (var record in sqsEvent.Records) { if (string.IsNullOrEmpty(record.Body)) { continue; } var copyItem = JsonConvert.DeserializeObject <CopyItem>(record.Body); if (copyItem == null || copyItem.BlobItem == null) { continue; } Console.WriteLine($"Trying to download item {copyItem.BlobItem.BlobName} from Azure blob storage to S3."); using (MemoryStream msS3Stream = new MemoryStream()) using (BufferedStream stmS3 = new BufferedStream(msS3Stream)) { AzureManager.GetBlobStream(storageAccount, copyItem.BlobItem.ContainerName, copyItem.BlobItem.BlobName, stmS3); S3Manager.PutObject(copyItem.BlobItem.BlobName, stmS3); Console.WriteLine($"Successfully copied item {copyItem.BlobItem.BlobName} to S3"); } } } else { throw new Exception("Azure storage account not properly configured."); } }
/// <summary> /// A simple function that takes a string and does a ToUpper /// </summary> /// <param name="input"></param> /// <param name="context"></param> /// <returns></returns> public void FunctionHandler(ILambdaContext context) { string storageConnectionString; if (!ssmParameterManager.TryGetValue(Constants.StorageConnectionStringSSMPath, out storageConnectionString)) { throw new Exception("Storage connection path not defined."); } else { Console.WriteLine($"Storage connection path is set at '{storageConnectionString}'"); } if (!S3Manager.CheckS3Parameters()) { return; } // Check whether the connection string can be parsed. if (CloudStorageAccount.TryParse(storageConnectionString, out storageAccount)) { string ContainerNames; if (ssmParameterManager.TryGetValue(Constants.StorageContainerNamesSSMPath, out ContainerNames)) { var arrContainerNames = ContainerNames.Split(',', StringSplitOptions.RemoveEmptyEntries); List <Task> lstTasks = new List <Task>(); foreach (var ContainerName in arrContainerNames) { var t = Task.Factory.StartNew(() => { var lstBlobItems = AzureManager.ListBlobContainer(storageAccount, ContainerName, null); if (lstBlobItems.Count > 0) { Console.WriteLine("Listing S3 items."); var S3Objects = S3Manager.GetS3Items(); Console.WriteLine($"{S3Objects.Count.ToString()} items retrieved from S3."); foreach (var S3Object in S3Objects) { Console.WriteLine($"Item retrieved from S3: {S3Object.BucketName} - {S3Object.Key} ({S3Object.Size.ToString()} bytes) - ETag {S3Object.ETag}"); } StringBuilder sb = new StringBuilder(); Amazon.SQS.AmazonSQSClient sqsClient = new Amazon.SQS.AmazonSQSClient(); lstBlobItems.ForEach((a) => { if (!S3Objects.Any(s => s.Key == a.BlobName && s.Size == a.Size)) { CopyItem copyItem = new CopyItem { BlobItem = a }; // No S3 objects that match the Azure blob, copy it over var strCopyItem = JsonConvert.SerializeObject(copyItem); SendMessageRequest sendRequest = new SendMessageRequest { MessageBody = strCopyItem, QueueUrl = System.Environment.GetEnvironmentVariable("QueueName") }; var sendMessageResult = sqsClient.SendMessageAsync(sendRequest).GetAwaiter().GetResult(); Console.WriteLine($"Item not found in S3, adding to copy queue - {a.BlobName} - send message result: {sendMessageResult.HttpStatusCode.ToString()}"); } }); } }); lstTasks.Add(t); } Task.WaitAll(lstTasks.ToArray()); } } else { // Otherwise, let the user know that they need to define the environment variable. throw new Exception("Storage connection path not defined."); } }
public static void Main(string[] args) { XmlConfigurator.Configure(); System.Net.ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true; Console.Title = string.Format("[{0}] D2MP Master", version); log.Info("Master server starting v." + version + "."); log.Info("Initializing database..."); log.Debug(Settings.Default.MongoURL); Mongo.Setup(); Task.Factory.StartNew(Mongo.UpdateOldMatchResults); log.Info("Caching mods..."); Mods.Mods.InitCache(); log.Info(Mods.Mods.ModCache.Count + " mods cached."); log.Info("Generating server addon list..."); ServerAddons.Init(Mods.Mods.ModCache.Values); log.Info("Initializing Amazon S3..."); S3 = new S3Manager(); log.Info("Initializing match result server..."); Uri[] urilist = null; { IList <Uri> uris = new List <Uri>(); #if DEBUG || DEV uris.Add(new Uri("http://127.0.0.1:" + Settings.Default.WebserverBind)); //uris.Add(new Uri("http://10.0.1.3:" + Settings.Default.WebserverBind)); #else //uris.Add(new Uri("http://net1.d2modd.in:" + Settings.Default.WebserverBind)); uris.Add(new Uri("http://" + Settings.Default.WebAddress + ":" + Settings.Default.WebserverBind)); #endif urilist = uris.ToArray(); } foreach (var uri in urilist) { log.Debug(uri); } var config = new HostConfiguration(); using (var nancyServer = new NancyHost(config, urilist)) { nancyServer.Start(); log.Info("Initializing xsockets..."); Console.CancelKeyPress += delegate { shutdown = true; }; using (var server = Composable.GetExport <IXSocketServerContainer>()) { server.StartServers(); Mods.Mods.StartUpdateTimer(); Lobbies.LobbyManager.Start(); log.Info("Server running!"); while (!shutdown) { Thread.Sleep(100); } BrowserController.cts.Cancel(); ClientController.cts.Cancel(); ServerController.cts.Cancel(); Lobbies.LobbyManager.Stop(); Mods.Mods.StopUpdateTimer(); server.StopServers(); } nancyServer.Stop(); } log.Info("Done, shutting down..."); //wserver.Stop(); }