示例#1
0
        private void Page_Load(object sender, EventArgs e)
        {
            TextData = Request.QueryString ["text"];

            SecurityKey = Request.QueryString ["key"];

            FolderName = Request.QueryString ["folder"];

            FileName = Request.QueryString ["file"];

            Action = (PostAction)Enum.Parse (typeof(PostAction), Request.QueryString ["action"]);

            var dataFolder = ConfigurationSettings.AppSettings ["DataFolder"];

            var contentFolder = ConfigurationSettings.AppSettings ["ContentFolder"];

            if (!String.IsNullOrEmpty (TextData)) {
                var manager = new PostFolderManager (dataFolder, contentFolder, FolderName, SecurityKey);

                manager.Post (FileName, TextData, Action);

                CreateUrl (FolderName, FileName);

                DidPublish = true;
            }
        }
        public void SetUp()
        {
            writer = new StringWriter();
            var htmlHelper = MvcTestHelpers.CreateMockHtmlHelper(writer);
            var entity = new TestEntity {Id = 4};

            postAction = new PostAction<TestController>(htmlHelper, c => c.DoSomething(entity), "the button text");
        }
示例#3
0
        public async Task <PostShortVersion> GetPostByIdAsync(int postId, int userId)
        {
            using (ShapeAppDbContext ctx = new ShapeAppDbContext())
            {
                Post post = await ctx.Posts
                            .Include(p => p.Owner)
                            .FirstOrDefaultAsync(p => p.Id == postId);

                if (post == null)
                {
                    return(null);
                }

                UserShortVersion owner = new UserShortVersion
                {
                    UserId       = post.Owner.Id,
                    UserFullName = post.Owner.Name,
                };
                int countComments = ctx.Posts.Where(p => p.Id == post.Id)
                                    .Include(p => p.Comments).First().Comments.Count;
                Console.WriteLine("Post " + post.Id + " has " + countComments + " comments");

                int countLikes = ctx.PostActions.Count(pa => pa.PostId == post.Id && pa.IsLike);
                Console.WriteLine("Post " + post.Id + " has " + countLikes + " likes");

                PostAction postAction = await ctx.PostActions.FirstOrDefaultAsync(pa =>
                                                                                  pa.PostId == postId && pa.UserId == userId);

                bool[] postStatus = new bool[2];

                if (postAction == null)
                {
                    for (int i = 0; i < postStatus.Length; i++)
                    {
                        postStatus[i] = false;
                    }
                }
                else
                {
                    postStatus[0] = postAction.IsLike;
                    postStatus[1] = postAction.IsReport;
                }

                return(new PostShortVersion
                {
                    Id = post.Id,
                    Title = post.Title,
                    Content = post.Content,
                    Owner = owner,
                    TimeStamp = post.TimeStamp,
                    HasImage = post.HasImage,
                    NumberOfComments = countComments,
                    NumberOfLikes = countLikes,
                    PostStatus = postStatus
                });
            }
        }
示例#4
0
        public void AddCustomerInformation(INFORMATION information)
        {
            var        postObject = new PostObject <object>();
            PostAction action     = Config.PostActions.Where(o => o.Code == ActionCode.AddInformation).SingleOrDefault();

            postObject.PostAction = action;

            postObject.Data = information;
            this._service.PostObject(this, postObject);
        }
示例#5
0
        public void SetUp()
        {
            writer = new StringWriter();
            var htmlHelper = MvcTestHelpers.CreateMockHtmlHelper(writer);
            var entity     = new TestEntity {
                Id = 4
            };

            postAction = new PostAction <TestController>(htmlHelper, c => c.DoSomething(entity), "the button text");
        }
示例#6
0
        public void GetExpressionDetails_should_work()
        {
            var entity = new TestEntity {
                Id = 4
            };
            Expression <Action <TestController> > action = c => c.DoSomething(entity);

            var expressionDetails = PostAction <TestController> .GetExpressionDetails(action);

            expressionDetails.MethodName.ShouldEqual("DoSomething");
            expressionDetails.IdValue.ShouldEqual(4);
        }
        public async Task InteractWithPost(int postId, int userId, UserActionTypes actionType, bool value)
        {
            PostAction postAction = new PostAction
            {
                PostId     = postId,
                UserId     = userId,
                Value      = value,
                ActionType = actionType.ToString()
            };

            await client.PostAsync($"{uri}/actions", PrepareObjectForRequest(postAction));
        }
示例#8
0
        /// <summary>
        /// بررسی کاربر که اینکه مدیای جاری رو قبلا لایک کرده یا نه
        /// </summary>
        /// <returns></returns>
        ///
        public bool CheckLastActionPost(int PostID, int ActivityType)
        {
            string CurrIP = objNetworkOperation.ClientIPaddress();
            string CurrHN = objNetworkOperation.ClientHostName();
            string CurrDT = objNetworkOperation.ClientDeviceType();
            string CurrBr = objNetworkOperation.ClientBrowser();

            using (var _Context = new ApplicationDbContext())
            {
                var _objEntityAction = new RepositoryPattern <Activity>(_Context);
                var PostLikeState    = _objEntityAction.SearchFor(x =>
                                                                  x.Posts.ID == PostID &&
                                                                  x.IP_Address == CurrIP &&
                                                                  x.HostName == CurrHN &&
                                                                  x.Device == CurrDT &&
                                                                  x.Browser == CurrBr &&
                                                                  x.ActivityType.ID == ActivityType)
                                       .ToList()
                                       .LastOrDefault();

                if (PostLikeState != null)
                {
                    return(true);
                }
            }
            //Search In RAM List
            var _LikeView = C_LikeViewList.GetAllLikeView();

            if (!(_LikeView == null || _LikeView.Count() == 0))
            {
                PostAction CurrItem = _LikeView.FirstOrDefault(x =>
                                                               x.PostID == PostID &&
                                                               x.Browser == CurrBr &&
                                                               x.Device == CurrDT &&
                                                               x.HostName == CurrHN &&
                                                               x.IP_Address == CurrIP &&
                                                               x.ActionTypeID == ActivityType);
                if (CurrItem != null)
                {
                    //در صورتي كه توي ليست (رم) باشد
                    return(true);
                }
            }
            return(false);
        }
示例#9
0
        /// <exception cref="T:System.Exception">Condition.</exception>
        public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
        {
            try
            {
                PreAction?.Invoke();

                base.TryInvokeMember(binder, args, out result);

                PostAction?.Invoke();

                return(true);
            }
            catch (Exception e)
            {
                ResponseOnFailure?.Invoke(e);
                throw;
            }
        }
示例#10
0
        /// <summary>
        /// 发送HTTP请求
        /// </summary>
        /// <param name="guid">用户机器的唯一识别码,POST给服务器以供服务器计算密钥</param>
        /// <param name="action">请求动作类型</param>
        /// <returns>动作所需密钥</returns>
        public static async Task <string> httpreq(byte[] guid, PostAction action)
        {
            string url = baseUrl;

            switch (action)
            {
            case PostAction.Blackmail:
                url += "blackmail";
                break;

            case PostAction.Redemption:
                url += "redemption";
                break;

            case PostAction.BTCAddress:
                url += "btcaddress";
                break;

            default:
                break;
            }

            Debug.WriteLine(url);

            using (HttpClient client = new HttpClient())
            {
                FormUrlEncodedContent content = new FormUrlEncodedContent(new[] {
                    new KeyValuePair <string, string>("guid", Hex.ToHexString(guid))
                });

                HttpResponseMessage response = await client.PostAsync(url, content);

                response.EnsureSuccessStatusCode();

                string rsp = await response.Content.ReadAsStringAsync();

                Debug.WriteLine(rsp);

                return(rsp);
            }
        }
        public string NewPost(int topicID, PostAction postAction, int postID, Dictionary <string, string> additionalParams)
        {
            string result = Settings.NewPostPageAbsolutePath.ToQuery() + Settings.TopicParamName + "=" + topicID.ToString();

            if (postAction == PostAction.Quote)
            {
                result += "&" + Settings.PostParamName + "=" + postID.ToString() + "&" + Settings.ActionParamName + "=1";
            }

            else if (postAction == PostAction.Reply)
            {
                result += "&" + Settings.PostParamName + "=" + postID.ToString() + "&" + Settings.ActionParamName + "=2";
            }

            else if (postAction == PostAction.Edit)
            {
                result += "&" + Settings.PostParamName + "=" + postID.ToString() + "&" + Settings.ActionParamName + "=3";
            }


            return(AddParams(result, additionalParams));
        }
示例#12
0
        public void TestPostActionConditioning(bool condition1, bool condition2, int expectedActionCount, string[] firstResult, string[] secondResult)
        {
            SimpleConfigModel   configModel = SimpleConfigModel.FromJObject(TestTemplateJson);
            IVariableCollection vc          = new VariableCollection
            {
                ["ActionOneCondition"] = condition1,
                ["ActionTwoCondition"] = condition2
            };
            List <IPostAction> postActions = PostAction.ListFromModel(_logger, configModel.PostActionModels, vc);

            Assert.Equal(expectedActionCount, postActions.Count);
            if (firstResult != null && firstResult.Length > 0)
            {
                Assert.True(string.Equals(postActions[0].Description, firstResult[0]), $"expected '{firstResult[0]}', but got {postActions[0].Description}");
                Assert.Equal(firstResult[1], postActions[0].ManualInstructions);
            }

            if (secondResult != null && secondResult.Length > 0)
            {
                Assert.True(string.Equals(postActions[1].Description, secondResult[0]), $"expected '{secondResult[0]}', but got {postActions[1].Description}");
                Assert.Equal(secondResult[1], postActions[1].ManualInstructions);
            }
        }
示例#13
0
        public void TestPostActionInstructionsConditioning(bool condition1, bool condition2, int expectedActionCount, string operatingSystemValue, string firstInstruction, string secondInstruction)
        {
            SimpleConfigModel   configModel = SimpleConfigModel.FromJObject(TestTemplateJson);
            IVariableCollection vc          = new VariableCollection
            {
                ["ActionOneCondition"]  = condition1,
                ["ActionTwoCondition"]  = condition2,
                ["OperatingSystemKind"] = operatingSystemValue
            };

            List <IPostAction> postActions = PostAction.ListFromModel(_logger, configModel.PostActionModels, vc);

            Assert.Equal(expectedActionCount, postActions.Count);

            if (!string.IsNullOrEmpty(firstInstruction))
            {
                Assert.Equal(firstInstruction, postActions[0].ManualInstructions);
            }

            if (!string.IsNullOrEmpty(secondInstruction))
            {
                Assert.Equal(secondInstruction, postActions[1].ManualInstructions);
            }
        }
示例#14
0
        public void GetExpressionDetails_should_work_on_an_enumerated_type()
        {
            var entities = new List <TestEntity>
            {
                new TestEntity {
                    Id = 3
                },
                new TestEntity {
                    Id = 5
                },
                new TestEntity {
                    Id = 7
                }
            };

            foreach (var entity in entities)
            {
                Expression <Action <TestController> > action = c => c.DoSomething(entity);
                var expressionDetails = PostAction <TestController> .GetExpressionDetails(action);

                expressionDetails.MethodName.ShouldEqual("DoSomething");
                expressionDetails.IdValue.ShouldEqual(entity.Id);
            }
        }
 public string NewPost(int topicID, PostAction postAction, int postID)
 {
     return(NewPost(topicID, postAction, postID, GetCurrentParams()));
 }
示例#16
0
        public async Task <int> PostPostActionAsync(PostActionSockets postActionSockets)
        {
            using (ShapeAppDbContext ctx = new ShapeAppDbContext())
            {
                PostAction postAction = await ctx.PostActions.FirstOrDefaultAsync(pa =>
                                                                                  pa.PostId == postActionSockets.PostId && pa.UserId == postActionSockets.UserId);

                PostAction ifNullPostAction = new PostAction();
                if (postAction == null)
                {
                    ifNullPostAction = new PostAction
                    {
                        PostId = postActionSockets.PostId,
                        UserId = postActionSockets.UserId
                    };
                }

                switch (postActionSockets.ActionType)
                {
                case "POST_LIKE":
                    if (postAction != null)
                    {
                        postAction.IsLike = postActionSockets.Value;
                    }
                    else
                    {
                        ifNullPostAction.IsLike = postActionSockets.Value;
                    }
                    break;

                case "POST_REPORT":
                    if (postAction != null)
                    {
                        postAction.IsReport = postActionSockets.Value;
                    }
                    else
                    {
                        ifNullPostAction.IsReport = postActionSockets.Value;
                    }
                    break;
                }

                if (postAction == null)
                {
                    await ctx.PostActions.AddAsync(ifNullPostAction);
                }
                else
                {
                    if (postAction.IsLike || postAction.IsReport)
                    {
                        ctx.PostActions.Update(postAction);
                    }
                    else
                    {
                        ctx.PostActions.Remove(postAction);
                    }
                }

                try {
                    await ctx.SaveChangesAsync();
                }
                catch (Exception e) {
                    return(-1);
                }

                return(0);
            }
        }
        public void Post(string filePath, string text, PostAction action)
        {
            Authentication.Authenticate (FolderId, SecurityKey);

            if (action == PostAction.Overwrite)
                Overwriter.Overwrite(filePath, text);
            else
                Appender.AppendLine (filePath, text); // TODO: Should AppendLine or Append be used by default?
        }
示例#18
0
 public SheduleController(IServiceShedule serviceLecturer, PostAction postAction)
 {
     _serviceLecturer = serviceLecturer;
        _postAction = postAction;
 }
 /// <summary>
 /// ctor
 /// </summary>
 /// <param name="action"></param>
 public Action(PostAction action)
 {
     mAction = action;
 }
示例#20
0
 public PostNotification(int postId, PostAction postAction)
 {
     PostId = postId;
     Action = postAction;
 }
示例#21
0
        public ActionResult List(long[] ids, PostAction postAction)
        {
            if (!IsUserizedRequest)
            {
                return(AccessDeniedView());
            }

            if (postAction == PostAction.Unknown)
            {
                ResourceErrorNotification(CrudSharedConstants.Systematic.InvalidParameter);
                return(RedirectToAction(KnownActionNames.List, RouteParameter.Add(KnownParameterNames.Page, 1)));
            }

            if (!ids.Any())
            {
                ResourceErrorNotification(CrudSharedConstants.Systematic.InvalidParameter);
                return(RedirectToAction(KnownActionNames.List, RouteParameter.Add(KnownParameterNames.Page, 1)));
            }

            var isSuccess = false;

            foreach (var id in ids)
            {
                var entity = LoadEntityById(id)();

                if (entity == null)
                {
                    return(HandleUnknown(id));
                }

                ServiceOperationResult operationResult;

                switch (postAction)
                {
                case PostAction.PublishAll:
                    entity.IsPublished = true;
                    operationResult    = UpdateEntityAndReturnOperationResult(entity)();
                    break;

                case PostAction.UnpublishAll:
                    entity.IsPublished = false;
                    operationResult    = UpdateEntityAndReturnOperationResult(entity)();
                    break;

                case PostAction.TemporarilyDeleteAll:
                    operationResult = DeleteEntityAndReturnOperationResult(entity)();
                    break;

                case PostAction.UnDeleteAll:
                    entity.IsDeleted = false;
                    operationResult  = UpdateEntityAndReturnOperationResult(entity)();
                    break;

                default:
                    operationResult = DeleteEntityAndReturnOperationResult(entity, false)();
                    break;
                }

                if (!isSuccess)
                {
                    isSuccess = operationResult.Success;
                }
            }

            if (!isSuccess)
            {
                string key;

                switch (postAction)
                {
                case PostAction.PublishAll:
                case PostAction.UnpublishAll:
                case PostAction.TemporarilyDeleteAll:
                case PostAction.UnDeleteAll:
                    key = CommonConstants.Systematic.NotUpdated;
                    break;

                default:
                    key = CommonConstants.Systematic.NotDeleted;
                    break;
                }

                ResourceErrorNotification(key);
            }
            else
            {
                string key;

                switch (postAction)
                {
                case PostAction.PublishAll:
                case PostAction.UnpublishAll:
                case PostAction.TemporarilyDeleteAll:
                case PostAction.UnDeleteAll:
                    key = CommonConstants.Systematic.Updated;
                    break;

                default:
                    key = CommonConstants.Systematic.Deleted;
                    break;
                }

                ResourceSuccessNotification(key);
            }

            return(RedirectToAction(KnownActionNames.List, RouteParameter.Add(KnownParameterNames.Page, 1)));
        }
示例#22
0
 public AppVeyorListener(string uri, PostAction postAction)
 {
     this.postAction = postAction;
     this.uri        = new Uri(new Uri(uri), "api/tests").ToString();
 }
示例#23
0
 public string NewPost(int topicID, PostAction postAction, int postID)
 {
     return NewPost(topicID, postAction, postID, GetCurrentParams());
 }
示例#24
0
        public string NewPost(int topicID, PostAction postAction, int postID, Dictionary<string, string> additionalParams)
        {
            string result = Settings.NewPostPageAbsolutePath.ToQuery() + Settings.TopicParamName + "=" + topicID.ToString();

            if (postAction == PostAction.Quote)
                result += "&" + Settings.PostParamName + "=" + postID.ToString() + "&" + Settings.ActionParamName + "=1";

            else if (postAction == PostAction.Reply)
                result += "&" + Settings.PostParamName + "=" + postID.ToString() + "&" + Settings.ActionParamName + "=2";

            else if (postAction == PostAction.Edit)
                result += "&" + Settings.PostParamName + "=" + postID.ToString() + "&" + Settings.ActionParamName + "=3";


            return AddParams(result, additionalParams);
        }
示例#25
0
        private void CreatePostUrl(string text, string folder, string file, string key, PostAction action)
        {
            var url = String.Format ("~/HttpGet.aspx?folder={0}&file={1}&key={2}&action={3}&text={4}", HttpUtility.UrlEncode(folder), HttpUtility.UrlEncode(file), HttpUtility.UrlDecode(key), action, HttpUtility.UrlEncode(text));

            PostUrl = HttpTool.Absolute (url);
        }
示例#26
0
        protected async Task SavePost(PostAction postAction)
        {
            try
            {
                var content = await JSRuntime.InvokeAsync <string>("commonJsFunctions.getEditorValue", "");

                Post.Content = content;

                if (string.IsNullOrEmpty(Post.Title))
                {
                    Toaster.Error("Post title required");
                }
                else if (string.IsNullOrEmpty(Post.Content))
                {
                    Toaster.Error("Post content required");
                }
                else
                {
                    PostItem saved;
                    if (Post.Id == 0)
                    {
                        var authState = await AuthenticationStateTask;
                        var author    = await DataService.Authors.GetItem(
                            a => a.AppUserName == authState.User.Identity.Name);

                        Post.Author      = author;
                        Post.Slug        = GetSlug(Post.Title);
                        Post.Description = Post.Title;

                        saved = await DataService.BlogPosts.SaveItem(Post);
                    }
                    else
                    {
                        var item = await DataService.BlogPosts.GetItem(p => p.Id == Post.Id);

                        item.Content     = Post.Content;
                        item.Title       = Post.Title;
                        item.Description = Post.Description;
                        item.Categories  = Post.Categories;

                        if (postAction == PostAction.Unpublish)
                        {
                            item.Published = DateTime.MinValue;
                        }

                        if (postAction == PostAction.Publish)
                        {
                            item.Published = SystemClock.Now();
                        }

                        saved = await DataService.BlogPosts.SaveItem(item);
                    }

                    if (saved != null && saved.Id > 0)
                    {
                        if (postAction == PostAction.Publish && FeatureManager.IsEnabledAsync(nameof(AppFeatureFlags.Email)).Result)
                        {
                            var pager = new Pager(1, 10000);
                            var items = await DataService.Newsletters.GetList(e => e.Id > 0, pager);

                            var emails   = items.Select(i => i.Email).ToList();
                            var blogPost = DataService.BlogPosts.Single(p => p.Id == saved.Id);

                            int count = await EmailService.SendNewsletters(blogPost, emails, NavigationManager.BaseUri);

                            if (count > 0)
                            {
                                Toaster.Success(string.Format(Localizer["email-sent-count"], count));
                            }
                        }
                        Toaster.Success("Saved");
                        Post   = saved;
                        PostId = Post.Id;
                        StateHasChanged();
                    }
                    else
                    {
                        Toaster.Error("Post was not saved");
                    }
                }
            }
            catch (Exception ex)
            {
                Toaster.Error(ex.Message);
            }
        }
示例#27
0
 public void RunAction()
 {
     PreAction?.Invoke(this, new MessageEventArgs("Pre - RunAction"));
     //Action();
     PostAction?.Invoke(this, new MessageEventArgs("Post - RunAction"));
 }
示例#28
0
 public override void Apply()
 {
     ps.SetValue(sender, value_new);
     PostAction?.Invoke();
 }
示例#29
0
        protected async Task SavePost(PostAction postAction)
        {
            try
            {
                var content = await JSRuntime.InvokeAsync <string>("commonJsFunctions.getEditorValue", "");

                Post.Content = content;

                if (string.IsNullOrEmpty(Post.Title))
                {
                    Toaster.Error("Post title required");
                }
                else if (string.IsNullOrEmpty(Post.Content))
                {
                    Toaster.Error("Post content required");
                }
                else
                {
                    PostItem saved;
                    if (Post.Id == 0)
                    {
                        var authState = await AuthenticationStateTask;
                        var author    = await DataService.Authors.GetItem(
                            a => a.AppUserName == authState.User.Identity.Name);

                        Post.Author      = author;
                        Post.Slug        = Post.Title.ToSlug();
                        Post.Description = Post.Title;

                        saved = await DataService.BlogPosts.SaveItem(Post);
                    }
                    else
                    {
                        var item = await DataService.BlogPosts.GetItem(p => p.Id == Post.Id);

                        item.Content     = Post.Content;
                        item.Title       = Post.Title;
                        item.Description = Post.Description;
                        item.Categories  = Post.Categories;

                        if (postAction == PostAction.Unpublish)
                        {
                            item.Published = DateTime.MinValue;
                        }

                        saved = await DataService.BlogPosts.SaveItem(item);
                    }
                    DataService.Complete();

                    if (postAction == PostAction.Publish && !AppSettings.DemoMode)
                    {
                        var section = Configuration.GetSection(Constants.ConfigSectionKey);
                        if (section != null)
                        {
                            var apiKey = section.GetValue <string>("SendGridApiKey");
                            if (!string.IsNullOrEmpty(apiKey) && apiKey != "YOUR-SENDGRID-API-KEY")
                            {
                                var pager = new Pager(1, 10000);
                                var items = await DataService.Newsletters.GetList(e => e.Id > 0, pager);

                                var emails   = items.Select(i => i.Email).ToList();
                                var blogPost = DataService.BlogPosts.Single(p => p.Id == saved.Id);

                                int count = await EmailService.SendNewsletters(blogPost, emails, NavigationManager.BaseUri);

                                if (count > 0)
                                {
                                    Toaster.Success(string.Format(Localizer["email-sent-count"], count));
                                }
                            }
                        }
                    }

                    Toaster.Success("Saved");
                    Post   = saved;
                    PostId = Post.Id;
                    StateHasChanged();
                }
            }
            catch (Exception ex)
            {
                Toaster.Error(ex.Message);
            }
        }