コード例 #1
0
ファイル: SimpleNotifyTest.cs プロジェクト: rog1039/crux
        public async Task SimpleNotifyLogicSignup()
        {
            var data  = new FakeApiDataEntityHandler <NotifyTemplate>();
            var logic = new FakeApiLogicHandler();
            var cloud = new FakeCloudHandler();

            var template = NotifyTemplateData.GetFirst();
            var tenant   = TenantData.GetFirst();
            var config   = UserConfigData.GetFirst();

            data.Result.Setup(m => m.Execute(It.IsAny <NotifyTemplateByName>())).Returns(template);
            data.Result.Setup(m => m.Execute(It.IsAny <Loader <Tenant> >())).Returns(tenant);
            data.Result.Setup(m => m.Execute(It.IsAny <Loader <UserConfig> >())).Returns(config);
            cloud.Result.Setup(m => m.Execute(It.IsAny <EmailTemplateCmd>()))
            .Returns(ActionConfirm.CreateSuccess("Sent"));

            var command = new SimpleNotify
            {
                DataHandler  = data,
                CurrentUser  = StandardUser,
                TemplateName = "signup",
                CloudHandler = cloud,
                LogicHandler = logic,
                Model        = tenant
            };

            await command.Execute();

            cloud.HasExecuted.Should().BeTrue();

            data.HasExecuted.Should().BeTrue();
            data.HasCommitted.Should().BeFalse();
            data.Result.Verify(s => s.Execute(It.IsAny <NotifyTemplateByName>()), Times.Once());
            data.Result.Verify(s => s.Execute(It.IsAny <Loader <Tenant> >()), Times.Once());
        }
コード例 #2
0
ファイル: FileDeleteTest.cs プロジェクト: rog1039/crux
        public async Task FileDeleteLogicFail()
        {
            var data  = new FakeApiDataEntityHandler <VisibleFile>();
            var logic = new FakeApiLogicHandler();
            var cloud = new FakeCloudHandler();

            var model = VisibleData.GetFirst();

            cloud.Result.Setup(m => m.Execute(It.IsAny <DeleteCmd>()))
            .Returns(ActionConfirm.CreateFailure(("Delete Failed")));

            var command = new FileDelete
            {
                DataHandler  = data,
                File         = model,
                CloudHandler = cloud,
                LogicHandler = logic
            };

            await command.Execute();

            cloud.HasExecuted.Should().BeTrue();

            data.HasExecuted.Should().BeFalse();
            data.HasCommitted.Should().BeFalse();
            data.Result.Verify(s => s.Execute(It.IsAny <Delete <VisibleFile> >()), Times.Never());
        }
コード例 #3
0
ファイル: ForgotControllerTest.cs プロジェクト: rog1039/crux
        public async Task ForgotControllerCodeTest()
        {
            var data  = new ForgotDataHandler();
            var logic = new CoreApiLogicHandler();

            data.ResultConfig = new UserConfig();

            var confirm = ModelConfirm <UserConfig> .CreateSuccess(data.ResultConfig);

            var start = ForgotData.GetStart();

            data.Result.Setup(m => m.Execute(It.IsAny <UserByEmail>())).Returns(StandardUser);
            data.Result.Setup(m => m.Execute(It.IsAny <Persist <UserConfig> >())).Returns(confirm);
            logic.Result.Setup(m => m.Execute(It.IsAny <SimpleNotify>())).Returns(ActionConfirm.CreateSuccess("ok"));

            var controller = new ForgotController(data, Cloud, logic);
            var result     = await controller.Code(start) as OkObjectResult;

            result.Should().NotBeNull();
            result.Should().BeOfType <OkObjectResult>();

            logic.HasExecuted.Should().BeTrue();
            logic.Result.Verify(s => s.Execute(It.IsAny <SimpleNotify>()), Times.Once);

            data.HasExecuted.Should().BeTrue();
            data.HasCommitted.Should().BeTrue();
            data.Result.Verify(s => s.Execute(It.IsAny <UserByEmail>()), Times.Once);
        }
コード例 #4
0
        public async Task SignupUserLogic()
        {
            var data  = new SignupDataHandler();
            var logic = new CoreApiLogicHandler();
            var cloud = new FakeCloudHandler();

            var tenant    = TenantData.GetFirst();
            var viewModel = LoginData.GetSignup();

            data.Result.Setup(m => m.Execute(It.IsAny <Loader <Tenant> >())).Returns(tenant);
            data.Result.Setup(m => m.Execute(It.IsAny <UserSave>())).Returns(StandardUser);

            logic.Result.Setup(m => m.Execute(It.IsAny <SimpleNotify>())).Returns(ActionConfirm.CreateSuccess("Worked"));

            var command = new SignupUser
            {
                DataHandler  = data,
                CloudHandler = cloud,
                LogicHandler = logic,
                Input        = viewModel
            };

            await command.Execute();

            logic.HasExecuted.Should().BeTrue();
            logic.Result.Verify(s => s.Execute(It.IsAny <SimpleNotify>()), Times.Once());

            data.HasExecuted.Should().BeTrue();
            data.HasCommitted.Should().BeTrue();
            data.Result.Verify(s => s.Execute(It.IsAny <Loader <Tenant> >()), Times.Once());
            data.Result.Verify(s => s.Execute(It.IsAny <UserSave>()), Times.AtLeastOnce());
        }
コード例 #5
0
ファイル: FileDeleteTest.cs プロジェクト: rog1039/crux
        public async Task FileDeleteLogicDoc()
        {
            var data  = new FakeApiDataEntityHandler <VisibleFile>();
            var logic = new FakeApiLogicHandler();
            var cloud = new FakeCloudHandler();

            var model = VisibleData.GetFirst();

            model.IsImage    = false;
            model.IsDocument = true;

            data.Result.Setup(m => m.Execute(It.IsAny <Delete <VisibleFile> >())).Returns(true);
            cloud.Result.Setup(m => m.Execute(It.IsAny <DeleteCmd>()))
            .Returns(ActionConfirm.CreateSuccess("File Loaded"));

            var command = new FileDelete
            {
                DataHandler  = data,
                File         = model,
                CloudHandler = cloud,
                LogicHandler = logic
            };

            await command.Execute();

            cloud.HasExecuted.Should().BeTrue();

            data.HasExecuted.Should().BeTrue();
            data.HasCommitted.Should().BeFalse();
            data.Result.Verify(s => s.Execute(It.IsAny <Delete <VisibleFile> >()), Times.Once());
        }
コード例 #6
0
        public async Task SignupUserLogicMissingEntry()
        {
            var data  = new LoginDataHandler();
            var logic = new CoreApiLogicHandler();
            var cloud = new FakeCloudHandler();

            var viewModel = LoginData.GetSignup();

            data.Result.Setup(m => m.Execute(It.IsAny <Loader <Tenant> >())).Returns(null);

            var command = new SignupUser
            {
                DataHandler  = data,
                CloudHandler = cloud,
                LogicHandler = logic,
                Input        = viewModel,
                Result       = ActionConfirm.CreateFailure("Failed")
            };

            await command.Execute();

            command.Result.Success.Should().BeFalse();

            logic.HasExecuted.Should().BeFalse();
            logic.Result.Verify(s => s.Execute(It.IsAny <SimpleNotify>()), Times.Never());

            data.HasExecuted.Should().BeTrue();
            data.HasCommitted.Should().BeFalse();
            data.Result.Verify(s => s.Execute(It.IsAny <Loader <Tenant> >()), Times.Once());
            data.Result.Verify(s => s.Execute(It.IsAny <UserSave>()), Times.Never());
        }
コード例 #7
0
ファイル: SimpleNotifyTest.cs プロジェクト: rog1039/crux
        public async Task SimpleNotifyLogicSignupMissingTemplate()
        {
            var data  = new FakeApiDataEntityHandler <NotifyTemplate>();
            var logic = new FakeApiLogicHandler();
            var cloud = new FakeCloudHandler();

            var template = NotifyTemplateData.GetFirst();
            var tenant   = TenantData.GetFirst();

            data.Result.Setup(m => m.Execute(It.IsAny <NotifyTemplateByName>())).Returns(null);

            var command = new SimpleNotify
            {
                DataHandler  = data,
                CurrentUser  = StandardUser,
                TemplateName = "signup",
                CloudHandler = cloud,
                LogicHandler = logic,
                Model        = tenant,
                Result       = ActionConfirm.CreateFailure("It failed")
            };

            await command.Execute();

            command.Result.Success.Should().BeFalse();

            cloud.HasExecuted.Should().BeFalse();

            data.HasExecuted.Should().BeTrue();
            data.HasCommitted.Should().BeFalse();
            data.Result.Verify(s => s.Execute(It.IsAny <NotifyTemplateByName>()), Times.Once());
            data.Result.Verify(s => s.Execute(It.IsAny <Loader <Tenant> >()), Times.Never());
        }
コード例 #8
0
ファイル: LoginControllerTest.cs プロジェクト: rog1039/crux
        public async Task LoginControllerAuthTwoFactor()
        {
            var data  = new LoginDataHandler();
            var logic = new CoreApiLogicHandler();

            data.ResultConfig = new UserConfig()
            {
                IsTwoFactor = true
            };

            var login   = LoginData.GetLogin();
            var confirm = ModelConfirm <UserConfig> .CreateSuccess(data.ResultConfig);

            data.Result.Setup(m => m.Execute(It.IsAny <UserByEmail>())).Returns(StandardUser);
            data.Result.Setup(m => m.Execute(It.IsAny <Persist <UserConfig> >())).Returns(confirm);
            logic.Result.Setup(m => m.Execute(It.IsAny <SimpleNotify>())).Returns(ActionConfirm.CreateSuccess("ok"));

            var controller = new LoginController(data, Cloud, logic);
            var result     = await controller.Auth(login) as OkObjectResult;

            result.Should().NotBeNull();
            result.Should().BeOfType <OkObjectResult>();

            logic.HasExecuted.Should().BeTrue();
            logic.Result.Verify(s => s.Execute(It.IsAny <SigninAuth>()), Times.Never);
            logic.Result.Verify(s => s.Execute(It.IsAny <SimpleNotify>()), Times.Once);

            data.HasExecuted.Should().BeTrue();
            data.HasCommitted.Should().BeTrue();
            data.Result.Verify(s => s.Execute(It.IsAny <UserByEmail>()), Times.Once);
        }
コード例 #9
0
ファイル: VisibleControllerTest.cs プロジェクト: rog1039/crux
        public async Task VisibleControllerDeleteFailed()
        {
            var data  = new VisibleApiDataHandler();
            var logic = new CoreApiLogicHandler();
            var model = VisibleData.GetFirst();

            data.Result.Setup(m => m.Execute(It.IsAny <Loader <VisibleFile> >())).Returns(model);

            logic.Result.Setup(m => m.Execute(It.IsAny <FileDelete>()))
            .Returns(ActionConfirm.CreateFailure("It went wrong"));

            var controller = new VisibleController(data, Cloud, logic)
            {
                CurrentUser = StandardUser
            };
            var result = await controller.Delete(VisibleData.FirstId) as OkObjectResult;

            result.Should().NotBeNull();
            result.Should().BeOfType <OkObjectResult>();

            var check = result.Value as ConfirmViewModel;

            check.Success.Should().BeFalse();

            logic.Result.Verify(s => s.Execute(It.IsAny <FileDelete>()), Times.Once());

            data.HasExecuted.Should().BeTrue();
            data.HasCommitted.Should().BeFalse();
            data.Result.Verify(s => s.Execute(It.IsAny <Loader <VisibleFile> >()), Times.Once);
        }
コード例 #10
0
        public override async Task Execute()
        {
            if (string.IsNullOrEmpty(SenderEmail))
            {
                SenderEmail = "*****@*****.**";
                SenderName  = "Crux";
            }

            var from       = new EmailAddress(SenderEmail, SenderName);
            var to         = new EmailAddress(RecipientEmail);
            var email      = MailHelper.CreateSingleEmail(from, to, Subject, BodyText, BodyHtml);
            var mailClient = new SendGridClient(Settings.Value.SendGridMailKey, Settings.Value.SendGridEndpoint);

            var response = await mailClient.SendEmailAsync(email);

            if (response.StatusCode == HttpStatusCode.Created || response.StatusCode == HttpStatusCode.OK ||
                response.StatusCode == HttpStatusCode.Accepted)
            {
                Result = ActionConfirm.CreateSuccess(response.StatusCode);
            }
            else
            {
                Result = ActionConfirm.CreateFailure(response.StatusCode.ToString());
            }
        }
コード例 #11
0
ファイル: ProcessFileTest.cs プロジェクト: rog1039/crux
        public async Task ProcessFileLogicImgNoTag()
        {
            var file = new FakeFile {
                ContentType = string.Empty
            };

            var data  = new FakeApiDataEntityHandler <VisibleFile>();
            var logic = new CoreApiLogicHandler();
            var cloud = new FakeCloudHandler();

            logic.Result.Setup(m => m.Execute(It.IsAny <ProcessImage>()))
            .Returns(ActionConfirm.CreateSuccess("File Processed"));

            var command = new ProcessFile
            {
                DataHandler  = data,
                Source       = file,
                CloudHandler = cloud,
                LogicHandler = logic,
                CurrentUser  = StandardUser
            };

            await command.Execute();

            cloud.HasExecuted.Should().BeFalse();
            logic.HasExecuted.Should().BeTrue();

            data.HasExecuted.Should().BeFalse();
            data.HasCommitted.Should().BeFalse();
            logic.Result.Verify(s => s.Execute(It.IsAny <ProcessImage>()), Times.Once());
        }
コード例 #12
0
        public void ActionConfirmTestFailure()
        {
            var msg = ActionConfirm.CreateFailure("Message");

            msg.Message.Should().Be("Message");

            msg.Success.Should().BeFalse();
        }
コード例 #13
0
ファイル: GiphyCmd.cs プロジェクト: rog1039/crux
        public override async Task Execute()
        {
            var tenant  = new RestClient(Settings.Value.GiphyEndpoint);
            var request = new RestRequest(Method.GET);

            request.AddHeader("api_key", Settings.Value.GiphyApiKey);
            request.AddHeader("tag", Tags);
            var result = await tenant.ExecuteAsync <GiphyGif>(request);

            ImageUrl = result.Data.Data.Images.FixedWidth.Url;
            Result   = ActionConfirm.CreateSuccess(ImageUrl);
        }
コード例 #14
0
        public void ActionConfirmTestSuccess()
        {
            var msg = ActionConfirm.CreateSuccess("Message");

            msg.Message.Should().Be("Message");

            var obj = ActionConfirm.CreateSuccess(new Tenant());

            obj.Value.Should().NotBeNull();

            msg.Success.Should().BeTrue();
            obj.Success.Should().BeTrue();
        }
コード例 #15
0
        public override async Task Execute()
        {
            if (!string.IsNullOrEmpty(AccountConnection))
            {
                Account = CloudStorageAccount.Parse(AccountConnection);
            }
            else if (Account == null)
            {
                Account = CloudStorageAccount.Parse(Settings.Value.AzureAccountKey);
            }

            Result = ActionConfirm.CreateSuccess("ok");
            await Task.CompletedTask;
        }
コード例 #16
0
        public override async Task Execute()
        {
            try
            {
                await base.Execute();

                var blob = Container.GetBlockBlobReference(Key.ToLower());
                await blob.DeleteAsync();

                Confirm = ActionConfirm.CreateSuccess(Key);
            }
            catch (Exception exception)
            {
                Confirm = ActionConfirm.CreateFailure(exception.Message);
            }
        }
コード例 #17
0
ファイル: ScrapeImageCmd.cs プロジェクト: rog1039/crux
        public override async Task Execute()
        {
            try
            {
                using (WebClient webClient = new WebClient())
                {
                    Data = new MemoryStream(await webClient.DownloadDataTaskAsync(new Uri(Url)));
                }

                Result = ActionConfirm.CreateSuccess(Url);
            }
            catch (Exception exception)
            {
                Result = ActionConfirm.CreateFailure(exception.Message);
            }
        }
コード例 #18
0
        public async Task LoaderControllerGiphyFail()
        {
            var cloud = new FakeCloudHandler();

            cloud.Result.Setup(m => m.Execute(It.IsAny <GiphyCmd>()))
            .Returns(ActionConfirm.CreateFailure("Something went wrong"));

            var controller = new LoaderController(Data, cloud, Logic)
            {
                CurrentUser = StandardUser
            };
            var result = await controller.Gif(UserData.FirstId) as NotFoundResult;

            result.Should().NotBeNull();
            result.Should().BeOfType <NotFoundResult>();

            cloud.HasExecuted.Should().BeTrue();
        }
コード例 #19
0
        public async Task LoaderControllerGiphySuccess()
        {
            var cloud = new FakeCloudHandler();

            cloud.Result.Setup(m => m.Execute(It.IsAny <GiphyCmd>()))
            .Returns(ActionConfirm.CreateSuccess("https://image.com/img.png"));

            var controller = new LoaderController(Data, cloud, Logic)
            {
                CurrentUser = StandardUser
            };
            var result = await controller.Gif(UserData.FirstId) as JsonResult;

            result.Should().NotBeNull();
            result.Should().BeOfType <JsonResult>();

            cloud.HasExecuted.Should().BeTrue();
        }
コード例 #20
0
ファイル: SmsCmd.cs プロジェクト: rog1039/crux
        public override async Task Execute()
        {
            TwilioClient.Init(Settings.Value.TwilioAccountSid, Settings.Value.TwilioAuthToken);

            try
            {
                var message = await MessageResource.CreateAsync(
                    body : Message,
                    from : new Twilio.Types.PhoneNumber(SenderPhone),
                    to : new Twilio.Types.PhoneNumber(RecipientPhone)
                    );

                Result = ActionConfirm.CreateSuccess(message.Sid);
            }
            catch (Exception e)
            {
                Result = ActionConfirm.CreateFailure(e.Message);
            }
        }
コード例 #21
0
        public async Task LoaderControllerUploadSuccess()
        {
            var data  = new VisibleApiDataHandler();
            var logic = new CoreApiLogicHandler();
            var model = VisibleData.GetFirst();

            logic.Result.Setup(m => m.Execute(It.IsAny <ProcessFile>())).Returns(ActionConfirm.CreateSuccess(model));

            var controller = new LoaderController(data, Cloud, logic)
            {
                CurrentUser = StandardUser
            };
            var result = await controller.Upload(VisibleData.GetFile()) as JsonResult;

            result.Should().NotBeNull();
            result.Should().BeOfType <JsonResult>();

            data.HasExecuted.Should().BeFalse();
            logic.HasExecuted.Should().BeTrue();
        }
コード例 #22
0
ファイル: FileDelete.cs プロジェクト: rog1039/crux
        public override async Task Execute()
        {
            var deleteThumb = new DeleteCmd {
                Key = File.ThumbKey, ContainerName = "thb"
            };
            await CloudHandler.Execute(deleteThumb);

            if (!deleteThumb.Confirm.Success)
            {
                Result = ActionConfirm.CreateFailure("Thumb blob failed to delete -> " + File.Id);
                return;
            }

            var delete = new DeleteCmd {
                Key = File.UrlKey
            };

            if (File.IsImage)
            {
                delete.ContainerName = "ful";
            }

            if (File.IsVideo)
            {
                delete.ContainerName = "vid";
            }

            if (File.IsDocument)
            {
                delete.ContainerName = "doc";
            }

            await CloudHandler.Execute(delete);

            var persist = new Delete <VisibleFile> {
                Id = File.Id
            };
            await DataHandler.Execute(persist);

            Result = ActionConfirm.CreateSuccess("File deleted");
        }
コード例 #23
0
        public override async Task Execute()
        {
            try
            {
                await SourceContainerCmd.Execute();

                await DestContainerCmd.Execute();

                var source = SourceContainerCmd.Container.GetBlockBlobReference(SourceKey.ToLower());
                var dest   = DestContainerCmd.Container.GetBlockBlobReference(DestKey.ToLower());

                dest.Properties.ContentType = source.Properties.ContentType;
                await dest.StartCopyAsync(source);

                Confirm = ActionConfirm.CreateSuccess(DestKey.ToLower());
            }
            catch (Exception exception)
            {
                Confirm = ActionConfirm.CreateFailure(exception.Message);
            }
        }
コード例 #24
0
        public override async Task Execute()
        {
            IProcessCommand processor = null;

            if (IsImage())
            {
                processor = new ProcessImage
                {
                    Source      = Source, CurrentUser = CurrentUser, LoadType = "File Upload", CloudHandler = CloudHandler,
                    DataHandler = DataHandler
                };
            }

            else if (IsVideo())
            {
            }

            else if (IsDocument())
            {
            }

            if (processor != null)
            {
                await LogicHandler.Execute(processor);

                if (processor.Result != null && processor.Result.Success)
                {
                    Model  = processor.Result.Value as VisibleFile;
                    Result = processor.Result;
                }
                else
                {
                    Result = ActionConfirm.CreateFailure("File " + Source.FileName + " -> failed to load");
                }
            }
            else
            {
                Result = ActionConfirm.CreateFailure("File " + Source.FileName + " -> type not supported");
            }
        }
コード例 #25
0
        public override async Task Execute()
        {
            try
            {
                await base.Execute();

                var blob = Container.GetBlockBlobReference(Key.ToLower());

                blob.Properties.ContentType = ContentType;
                Data.Position = 0;

                await blob.UploadFromStreamAsync(Data);

                Url     = blob.Uri;
                Length  = blob.Properties.Length;
                Confirm = ActionConfirm.CreateSuccess(Key.ToLower());
            }
            catch (Exception exception)
            {
                Confirm = ActionConfirm.CreateFailure(exception.Message);
            }
        }
コード例 #26
0
        public async Task ProcessImageLogicExists()
        {
            var file = new FakeFile();

            var data  = new FakeApiDataEntityHandler <ImageFile>();
            var logic = new CoreApiLogicHandler();
            var cloud = new FakeCloudHandler();

            var model = VisibleData.GetFirst();

            data.Result.Setup(m => m.Execute(It.IsAny <Loader <ImageFile> >())).Returns(model);
            data.Result.Setup(m => m.Execute(It.IsAny <Persist <ImageFile> >())).Returns(model);
            cloud.Result.Setup(m => m.Execute(It.IsAny <UploadCmd>()))
            .Returns(ActionConfirm.CreateSuccess("File Uploaded"));

            var command = new ProcessImage
            {
                DataHandler  = data,
                Source       = file,
                CloudHandler = cloud,
                LogicHandler = logic,
                CurrentUser  = StandardUser,
                Model        = model,
                LoadType     = "test",
                ExistingId   = model.Id
            };

            await command.Execute();

            cloud.HasExecuted.Should().BeTrue();
            cloud.Result.Verify(s => s.Execute(It.IsAny <UploadCmd>()), Times.AtLeastOnce());

            command.Result.Success.Should().BeTrue();

            data.HasExecuted.Should().BeTrue();
            data.HasCommitted.Should().BeFalse();
            data.Result.Verify(s => s.Execute(It.IsAny <Loader <ImageFile> >()), Times.Once());
            data.Result.Verify(s => s.Execute(It.IsAny <Persist <ImageFile> >()), Times.Once());
        }
コード例 #27
0
ファイル: SignupControllerTest.cs プロジェクト: rog1039/crux
        public async Task SignupControllerPostTest()
        {
            var data  = new SignupDataHandler();
            var logic = new CoreApiLogicHandler();

            var signup = SignupData.GetSignup();
            var auth   = LoginData.GetAuth();

            data.Result.Setup(m => m.Execute(It.IsAny <UserByEmail>())).Returns(null);
            logic.Result.Setup(m => m.Execute(It.IsAny <SignupUser>())).Returns(ActionConfirm.CreateSuccess(auth));

            var controller = new SignupController(data, Cloud, logic);
            var result     = await controller.Post(signup) as OkObjectResult;

            result.Should().NotBeNull();
            result.Should().BeOfType <OkObjectResult>();

            logic.HasExecuted.Should().BeTrue();
            logic.Result.Verify(s => s.Execute(It.IsAny <SignupUser>()), Times.Once);

            data.HasExecuted.Should().BeTrue();
            data.HasCommitted.Should().BeFalse();
            data.Result.Verify(s => s.Execute(It.IsAny <UserByEmail>()), Times.Once);
        }
コード例 #28
0
        public override async Task Execute()
        {
            try
            {
                var thumbKey = Guid.NewGuid().ToString().Replace("-", string.Empty).ToLower() +
                               Path.GetExtension(Source.FileName).ToLower();
                var fullKey = Guid.NewGuid().ToString().Replace("-", string.Empty).ToLower() +
                              Path.GetExtension(Source.FileName).ToLower();

                Model = new ImageFile
                {
                    TenantId    = CurrentUser.TenantId,
                    TenantName  = CurrentUser.TenantName,
                    AuthorId    = CurrentUser.Id,
                    AuthorName  = CurrentUser.Name,
                    RegionKey   = CurrentUser.RegionKey,
                    ContentType = Source.ContentType,
                    LoadType    = LoadType,
                    Name        = Source.FileName,
                    Extension   = Path.GetExtension(Source.FileName).ToLower(),
                    FullUrl     = CloudHandler.Settings.Value.MediaRoot + "ful/" + fullKey,
                    ThumbUrl    = CloudHandler.Settings.Value.MediaRoot + "thb/" + thumbKey,
                    ThumbKey    = thumbKey,
                    UrlKey      = fullKey
                };

                if (!string.IsNullOrEmpty(ExistingId))
                {
                    var existing = new Loader <ImageFile> {
                        Id = ExistingId
                    };
                    await DataHandler.Execute(existing);

                    if (existing.Result != null)
                    {
                        Model = existing.Result;

                        if (!string.IsNullOrEmpty(Model.ThumbKey))
                        {
                            thumbKey = Model.ThumbKey;
                        }
                        else
                        {
                            Model.ThumbKey = new Uri(Model.ThumbUrl).Segments.Last();
                        }

                        if (!string.IsNullOrEmpty(Model.UrlKey))
                        {
                            fullKey = Model.UrlKey;
                        }
                        else
                        {
                            Model.UrlKey = new Uri(Model.ThumbUrl).Segments.Last();
                        }
                    }
                }

                var mainUpload = new UploadCmd {
                    Key = fullKey, ContainerName = "ful"
                };
                var thumbUpload = new UploadCmd {
                    Key = thumbKey, ContainerName = "thb"
                };

                using (var stream = Source.OpenReadStream())
                {
                    var format = Image.DetectFormat(stream);
                    var image  = Image.Load(stream, out format);

                    Model.Width    = image.Width;
                    Model.Height   = image.Height;
                    Model.MimeType = Source.ContentType;

                    if (image.Width > 1920)
                    {
                        image = ResizeImageToWidth(image, 1920);
                    }

                    if (image.Height > 1920)
                    {
                        image = ResizeImageToHeight(image, 1920);
                    }

                    image.Save(mainUpload.Data, format);
                    image = ResizeImageToWidth(image);
                    image.Save(thumbUpload.Data, format);

                    image.Dispose();
                }

                await CloudHandler.Execute(mainUpload);

                await CloudHandler.Execute(thumbUpload);

                Model.Length = mainUpload.Length;

                var persist = new Persist <ImageFile> {
                    Model = Model
                };
                await DataHandler.Execute(persist);

                Result       = ActionConfirm.CreateSuccess("File " + Model.Name + " Loaded");
                Result.Value = persist.Model;
            }
            catch (Exception exception)
            {
                Result = ActionConfirm.CreateFailure(exception.Message);
            }
        }
コード例 #29
0
ファイル: PushCmd.cs プロジェクト: rog1039/crux
        public override async Task Execute()
        {
            var options = new PushCreateOptions
            {
                AppId   = new Guid(Settings.Value.OneSignalAppId),
                Filters = new List <IPushFilter>(),
                Data    = new Dictionary <string, string>()
            };

            options.Data.Add(new KeyValuePair <string, string>("Action", Action));

            if (IncludeUser)
            {
                options.Filters.Add(new PushFilterField
                {
                    Key = "userId", Value = UserId, Field = "tag", Relation = "="
                });
            }

            foreach (var clientExclude in IncludeClients)
            {
                if (options.Filters.Any())
                {
                    options.Filters.Add(new PushFilterOperator {
                        Operator = "OR"
                    });
                }

                options.Filters.Add(new PushFilterField
                {
                    Key = "tenantId", Value = clientExclude.TenantId, Field = "tag", Relation = "="
                });

                foreach (var userId in clientExclude.ExcludedUsers)
                {
                    options.Filters.Add(new PushFilterOperator {
                        Operator = "AND"
                    });
                    options.Filters.Add(new PushFilterField
                    {
                        Key = "userId", Value = userId, Field = "tag", Relation = "!="
                    });
                }

                if (ExcludeUser && TenantId == clientExclude.TenantId)
                {
                    options.Filters.Add(new PushFilterOperator {
                        Operator = "AND"
                    });
                    options.Filters.Add(new PushFilterField
                    {
                        Key = "userId", Value = UserId, Field = "tag", Relation = "!="
                    });
                }
            }

            foreach (var userId in IncludeUsers)
            {
                if (!ExcludeUser || UserId != userId)
                {
                    if (options.Filters.Any())
                    {
                        options.Filters.Add(new PushFilterOperator {
                            Operator = "OR"
                        });
                    }

                    options.Filters.Add(new PushFilterField
                    {
                        Key = "userId", Value = userId, Field = "tag", Relation = "="
                    });
                }
            }

            if (!string.IsNullOrEmpty(Identity))
            {
                options.Data.Add(new KeyValuePair <string, string>("Identity", Identity));
            }

            if (!string.IsNullOrEmpty(Message))
            {
                options.Contents.Add("en", Message);
            }

            if (!string.IsNullOrEmpty(Title))
            {
                options.Headings = new Dictionary <string, string>
                {
                    { "en", Title }
                };
            }

            if (!string.IsNullOrEmpty(Url))
            {
                options.Url = Url;
            }

            RestClient  RestClient  = new RestClient(Settings.Value.OneSignalEndpoint);
            RestRequest restRequest = new RestRequest("notifications", Method.POST);

            restRequest.AddHeader("Authorization", string.Format("Basic {0}", Settings.Value.OneSignalClientKey));
            restRequest.RequestFormat  = DataFormat.Json;
            restRequest.JsonSerializer = new SimpleSerializer();
            restRequest.AddJsonBody(options);

            var restResponse = RestClient.Execute <PushCreateResult>(restRequest);

            if (!(restResponse.StatusCode != HttpStatusCode.Created || restResponse.StatusCode != HttpStatusCode.OK))
            {
                if (restResponse.ErrorException != null)
                {
                    throw restResponse.ErrorException;
                }
                else if (restResponse.StatusCode != HttpStatusCode.OK && restResponse.Content != null)
                {
                    throw new Exception(restResponse.Content);
                }
            }

            var result = restResponse.Data;

            if (!string.IsNullOrEmpty(result.Id))
            {
                Result = ActionConfirm.CreateSuccess("Notification successful " + result.Id);
            }
            else
            {
                Result = ActionConfirm.CreateFailure("Notification failed " + Identity);
            }

            await Task.CompletedTask;
        }
コード例 #30
0
        public override async Task Execute()
        {
            var regionKey = "GLA";
            var tenant    = new Tenant()
            {
                Name       = Input.TenantName, TenantName = Input.TenantName, EntryKey = StringHelper.GenerateCode(16),
                AuthorName = Input.Name, RegionKey = regionKey
            };
            var isNew = true;

            if (string.IsNullOrEmpty(Input.TenantId))
            {
                var persistClient = new Persist <Tenant>()
                {
                    Model = tenant
                };
                await DataHandler.Execute(persistClient);

                tenant = persistClient.Model;
            }
            else
            {
                var loaderClient = new Loader <Tenant>()
                {
                    Id = Input.TenantId
                };
                await DataHandler.Execute(loaderClient);

                tenant = loaderClient.Result;
                isNew  = false;
            }

            if (tenant != null && !string.IsNullOrEmpty(tenant.Id))
            {
                var user = new User()
                {
                    TenantId     = tenant.Id, TenantName = Input.TenantName, Name = Input.Name, Email = Input.Email,
                    EncryptedPwd = EncryptHelper.Encrypt(Input.Pwd), AuthorName = Input.Name,
                    Right        = new UserRight()
                    {
                        CanAuth = isNew, CanAdmin = isNew, CanSuperuser = false
                    },
                    RegionKey = regionKey
                };

                var persistUser = new UserSave {
                    Model = user
                };
                await DataHandler.Execute(persistUser);

                if (persistUser.Confirm.Success)
                {
                    if (isNew)
                    {
                        tenant.AuthorId = persistUser.Model.Id;
                        tenant.TenantId = tenant.Id;

                        var persistClient = new Persist <Tenant>()
                        {
                            Model = tenant
                        };
                        await DataHandler.Execute(persistClient);

                        tenant = persistClient.Model;

                        var meetingType = new MeetingType()
                        {
                            TenantId = tenant.Id, TenantName = tenant.Name, Name = "Standard", IsRecur = false,
                            Pretext  = "Standard Meeting Type", RegionKey = regionKey, Prename = "Meeting",
                            AuthorId = persistUser.Model.Id, AuthorName = persistUser.Model.Name
                        };
                        var persistType = new Persist <MeetingType>()
                        {
                            Model = meetingType
                        };
                        await DataHandler.Execute(persistType);
                    }

                    persistUser.Model.AuthorId = persistUser.Model.Id;
                    await DataHandler.Execute(persistUser);

                    await DataHandler.Commit();

                    var signin = new SigninAuth()
                    {
                        Tenant      = tenant, Login = persistUser.Model, LogicHandler = LogicHandler,
                        DataHandler = DataHandler, Config = persistUser.ResultConfig, Settings = CloudHandler.Settings
                    };
                    await LogicHandler.Execute(signin);

                    ResultAuth = signin.Result;

                    Result = ActionConfirm.CreateSuccess(persistUser.Model);

                    var notify = new SimpleNotify
                    {
                        CloudHandler = CloudHandler, DataHandler = DataHandler, CurrentUser = persistUser.Model,
                        LogicHandler = LogicHandler, Model = persistUser.Model,
                        TemplateName = isNew ? "welcomeclient" : "welcomeuser"
                    };
                    await LogicHandler.Execute(notify);
                }
                else
                {
                    Result = ActionConfirm.CreateFailure(persistUser.Confirm.Message);
                }
            }
            else
            {
                Result = ActionConfirm.CreateFailure("Error connecting organisation");
            }
        }