public ExportImportReply ExportDatabase(ExportImportRequest request, ILambdaContext ctx)
        {
            processor.Logger = new LambdaLogger(ctx.Logger);
            processor.Logger.Info($"Version : {Version}");
            processor.Logger.Info(JsonTools.Serialize(request));

            string filename = Utils.GetValue(request.FileName, "DefaultExportImportFile", null);

            List <ExportRecord> export = processor.ExportData(request.IncludeSignals);
            AwsClient           client = new AwsClient();
            ZephyrFile          file   = new AwsS3ZephyrFile(client, filename);

            file.Create(true, false);
            file.WriteAllText(JsonTools.Serialize(export, true));

            // Build Reply Message
            ExportImportReply reply = new ExportImportReply();

            reply.Action   = "Export";
            reply.FileName = filename;
            foreach (ExportRecord record in export)
            {
                ExportImportType type = new ExportImportType();
                type.Type  = record.type;
                type.Count = record.records.Count;
                reply.Records.Add(type);
            }

            return(reply);
        }
Ejemplo n.º 2
0
        public void AwsS3FileDelete()
        {
            if (!Global.TestAws)
            {
                throw new Exception("Amazon S3 Tests Are Not Enabled.  Set Global.TestAws To True To Enable.");
            }

            String path = $"{Global.AwsS3WorkingPath}{Global.RandomFile}";

            Console.WriteLine(path);
            ZephyrFile file = new AwsS3ZephyrFile(Global.Clients.aws, path);

            file.Create();
            file.Close();
            file.Delete();
            Assert.That(!Utilities.Exists(path, Global.Clients));
        }
Ejemplo n.º 3
0
        public void AwsS3FileClose()
        {
            if (!Global.TestAws)
            {
                throw new Exception("Amazon S3 Tests Are Not Enabled.  Set Global.TestAws To True To Enable.");
            }

            String path = $"{Global.AwsS3WorkingPath}{Global.RandomFile}";

            Console.WriteLine(path);
            ZephyrFile file = new AwsS3ZephyrFile(Global.Clients.aws, path);

            file.Open(AccessType.Write);
            Assert.That(file.Stream.CanWrite);
            file.Close();
            Assert.IsNull(file.Stream);
            file.Delete();
        }
Ejemplo n.º 4
0
        public void AwsS3FileCreateDirectoryMethod()
        {
            if (!Global.TestAws)
            {
                throw new Exception("Amazon S3 Tests Are Not Enabled.  Set Global.TestAws To True To Enable.");
            }

            String path = $"{Global.AwsS3WorkingPath}{Global.RandomFile}";

            Console.WriteLine(path);
            ZephyrFile file = new AwsS3ZephyrFile(Global.Clients.aws, path);

            ZephyrDirectory dir = Global.AwsS3WorkingDirectory.CreateDirectory(path);

            Assert.That(!dir.Exists);
            dir.Create();
            Assert.That(dir.Exists);
            dir.Delete();
            file.Delete();
        }
Ejemplo n.º 5
0
        public void AwsS3FileProperties()
        {
            if (!Global.TestAws)
            {
                throw new Exception("Amazon S3 Tests Are Not Enabled.  Set Global.TestAws To True To Enable.");
            }

            String fileName = Global.RandomFile;
            String path     = $"{Global.AwsS3WorkingPath}/{fileName}";

            Console.WriteLine(path);
            ZephyrFile file = new AwsS3ZephyrFile(Global.Clients.aws, path);

            file.Create();
            file.Close();
            file.Open(AccessType.Write);

            Console.WriteLine($"FullName : {file.FullName}");
            Assert.AreEqual(file.FullName, path);

            Console.WriteLine($"Name     : {file.Name}");
            Assert.AreEqual(file.Name, fileName);

            Console.WriteLine($"Exists   : {file.Exists}");
            Assert.That(file.Exists);

            Console.WriteLine($"Stream   : {(file.Stream.CanWrite ? "Writable" : "Not Writable")}");
            Assert.That(file.Stream.CanWrite);

            Console.WriteLine($"IsOpen   : {file.IsOpen}");
            Assert.That(file.IsOpen);

            Console.WriteLine($"CanRead  : {file.CanRead}");
            Assert.That(!file.CanRead);

            Console.WriteLine($"CanWrite : {file.CanWrite}");
            Assert.That(file.CanWrite);

            file.Close();
            file.Delete();
        }
Ejemplo n.º 6
0
        public void AwsS3FileCopyToAwsS3File()
        {
            if (!Global.TestAws)
            {
                throw new Exception("Amazon S3 Tests Are Not Enabled.  Set Global.TestAws To True To Enable.");
            }

            ZephyrDirectory source = Global.StageTestFilesToAws();

            List <ZephyrFile> files = (List <ZephyrFile>)source.GetFiles();

            Assert.IsNotEmpty(files);
            foreach (ZephyrFile file in files)
            {
                String     path = $"{Global.AwsS3WorkingPath}{Global.RandomFile}";
                ZephyrFile dest = new AwsS3ZephyrFile(Global.Clients.aws, path);
                file.CopyTo(dest);
                Assert.That(Utilities.Exists(path, Global.Clients));
                dest.Delete();
            }

            source.Delete();
        }
        public ExportImportReply ImportDatabase(ExportImportRequest request, ILambdaContext ctx)
        {
            processor.Logger = new LambdaLogger(ctx.Logger);
            processor.Logger.Info($"Version : {Version}");
            processor.Logger.Info(JsonTools.Serialize(request));

            string filename = Utils.GetValue(request.FileName, "DefaultExportImportFile", null);

            AwsClient  client = new AwsClient();
            ZephyrFile file   = new AwsS3ZephyrFile(client, filename);

            file.Open(AccessType.Read, false);
            string importText           = file.ReadAllText();
            List <ExportRecord> records = JsonTools.Deserialize <List <ExportRecord> >(importText);

            processor.ImportData(records, request.IncludeSignals);

            // Build Reply Message
            ExportImportReply reply = new ExportImportReply();

            reply.Action   = "Import";
            reply.FileName = filename;
            foreach (ExportRecord record in records)
            {
                if (!request.IncludeSignals && record.type == "SignalDbRecord")
                {
                    continue;
                }
                ExportImportType type = new ExportImportType();
                type.Type  = record.type;
                type.Count = record.records.Count;
                reply.Records.Add(type);
            }

            return(reply);
        }
Ejemplo n.º 8
0
        public static void Main(string[] args)
        {
            /*** Export Database Records ***/
            DynamoDbEngine db        = new DynamoDbEngine();
            Processor      processor = new Processor(db);

            processor.Logger = new ConsoleLogger();

            /*** Export To S3 Bucket ***/
            //List<ExportRecord> export = processor.ExportData(false);
            //AwsClient client = new AwsClient();
            //ZephyrFile file = new AwsS3ZephyrFile(client, "s3://guywaguespack/export.json");
            //file.Create();
            //file.WriteAllText(JsonTools.Serialize(export, true));

            /*** Import From S3 Bucket ***/
            AwsClient  client = new AwsClient();
            ZephyrFile file   = new AwsS3ZephyrFile(client, "s3://guywaguespack/export.json");

            file.Open(AccessType.Read);
            string importText           = file.ReadAllText();
            List <ExportRecord> records = JsonTools.Deserialize <List <ExportRecord> >(importText);

            processor.ImportData(records, false);


            Console.WriteLine("Completed");


            /*** Send Signal Message ***/
            //int signalCount = 1;
            //TextReader reader = new StreamReader(new FileStream(@"/Users/guy/Documents/Source/syntinel.core.net/Syntinel.Tester/TestFiles/Signal-UsingTemplate.json", FileMode.Open));
            //string fileStr = reader.ReadToEnd();
            //Signal signal = JsonConvert.DeserializeObject<Signal>(fileStr);
            //Parallel.For(0, signalCount, index =>
            //{
            //    SignalReply reply = processor.ProcessSignal(signal);
            //    Console.WriteLine($"Status : {reply.StatusCode}");
            //    foreach (SignalStatus status in reply.Results)
            //        Console.WriteLine($"     {status.ChannelId} : {status.Code} - {status.Message}");
            //});


            /*** Send Teams Cue Response ***/
            //int cueCount = 1;
            //TextReader reader = new StreamReader(new FileStream(@"/Users/guy/Documents/Source/syntinel.core.net/Syntinel.Tester/TestFiles/Cue-Teams.json", FileMode.Open));
            //string fileStr = reader.ReadToEnd();
            //Dictionary<string, object> reply = JsonConvert.DeserializeObject<Dictionary<string, object>>(fileStr);
            //Cue cue = Teams.CreateCue(reply);
            //Parallel.For(0, cueCount, index =>
            // {
            //     string num = $"{index}".PadLeft(4, '0');
            //     CueReply cueReply = processor.ReceiveCue(cue);
            //     Console.WriteLine($"{num} - {JsonTools.Serialize(cueReply)}");
            // });


            /*** Stress Test Status Messages ***/
            //int statusCount = 1;
            //string signalId = "000000000";
            //string actionId = "0ZC6BJ28Z";

            //Parallel.For(1, statusCount, index =>
            //{
            //    Status status = new Status();
            //    status.Id = signalId;
            //    status.ActionId = actionId;
            //    status.NewStatus = StatusType.InProgress;
            //    string num = $"{index}".PadLeft(4, '0');
            //    status.Message = $"Message {num}";
            //    StatusReply reply = processor.ProcessStatus(status);
            //    Console.WriteLine($"{num} - {reply.StatusCode}");
            //});

            //Status status = new Status();
            //status.Id = signalId;
            //status.ActionId = actionId;
            //status.Message = "Last Message";
            //status.NewStatus = StatusType.Completed;
            //status.SendToChannels = false;
            //processor.ProcessStatus(status);


            /*** Test Syntinel.Version ***/
            //string[] vArgs = { "/Users/guy/Documents/Source/syntinel.core.net/Syntinel.Aws" };
            //Syntinel.Version.Program.Main(vArgs);
        }