コード例 #1
0
        public async Task <IActionResult> Story(StoryWriteModel storyWriteModel)
        {
            if (ModelState.IsValid)
            {
                var cancellationToken = CancellationToken.None;
                var existing          = await _writeRepository.FindByQuery(new StoryQuery()
                {
                    StoryId = storyWriteModel.StoryID
                }, cancellationToken);

                if (existing == null)
                {
                    existing = new StoryContent
                    {
                        AuthorID      = _contextService.LoggedInPerson.Id,
                        PersonID      = storyWriteModel.PersonID,
                        ID            = Guid.NewGuid(),
                        StoryContents = storyWriteModel.Story,
                        Title         = storyWriteModel.Title
                    }
                }
                ;
                await _writeRepository.Save(existing, cancellationToken);
            }

            return(View(storyWriteModel));
        }
コード例 #2
0
 private void PingStory(StoryContent content, IStory story, string detailUrl)
 {
     if (_settings.SendPing && !string.IsNullOrEmpty(content.TrackBackUrl))
     {
         _contentService.Ping(content.TrackBackUrl, story.Title, detailUrl, "Dziêkujemy za publikacjê - Trackback z {0}".FormatWith(_settings.SiteTitle), _settings.SiteTitle);
     }
 }
コード例 #3
0
        public static async Task <bool> DownloadVideoAsync(StoryContent story, string FolderDestinationPath)
        {
            try
            {
                HttpClient client   = new HttpClient();
                var        response = await client.GetAsync(story.Uri);

                var    filetype  = response.Content.Headers.ContentType.MediaType;
                string FileTitle = $"{DateTime.Now.Year} {DateTime.Now.Month} {DateTime.Now.Day} [ {DateTime.Now.Hour}h {DateTime.Now.Minute}m {DateTime.Now.Second}s ] Id[{story.Id}]";
                byte[] Response  = await response.Content.ReadAsByteArrayAsync();

                if (filetype.Contains("image"))
                {
                    File.WriteAllBytes($"{FolderDestinationPath}\\{FileTitle}.jpeg", Response);
                    return(true);
                }
                else if (filetype.Contains("video"))
                {
                    File.WriteAllBytes($"{FolderDestinationPath}\\{FileTitle}.mp4", Response);
                    return(true);
                }
                else
                {
                    File.WriteAllBytes($"{FolderDestinationPath}\\{FileTitle}.unknownfiletype", Response);
                    return(true);
                }
            }
            catch (Exception) { return(false); }
        }
コード例 #4
0
 public static Story MapToIndex(StoryContent story)
 {
     return(new Story
     {
         StoryObject = story.PersonID,
         StoryTitle = story.Title,
         ID = story.ID,
         StoryContent = story.StoryContents
     });
 }
コード例 #5
0
        public async Task Save(StoryContent entity, CancellationToken cancellationToken)
        {
            if (entity.ID == Guid.Empty)
            {
                entity.ID = Guid.NewGuid();
            }
            var dbContext = _clientFactory.GetDynamoDBContext();

            entity.LastUpdated = DateTime.Now;
            await dbContext.SaveAsync(entity, _dynamoDBOperationConfig, cancellationToken);
        }
コード例 #6
0
 public static Story Map(StoryContent story, ClanAndPeopleService clanAndPeopleService)
 {
     return(new Story
     {
         StoryObject = story.PersonID,
         StoryTitle = story.Title,
         ID = story.ID,
         StoryContent = story.StoryContents,
         StoryPerson = clanAndPeopleService.People.FirstOrDefault(t => t.Id == story.PersonID)
     });
 }
コード例 #7
0
        private Mock <IStory> Setup()
        {
            var story = new Mock <IStory>();

            story.SetupGet(s => s.Title).Returns("Dummy Title");

            var content = new StoryContent("Dummy story", "Dummy content", "http://dummyurl.com");

            _contentService.Setup(cs => cs.Get(It.IsAny <string>())).Returns(content).Verifiable();
            _httpForm.Setup(h => h.PostAsync(It.IsAny <HttpFormPostRequest>())).Verifiable();

            return(story);
        }
コード例 #8
0
        public ActionResult Retrieve(string url)
        {
            JsonViewData viewData = Validate <JsonViewData>(
                new Validation(() => string.IsNullOrEmpty(url), "Url nie mo¿e byæ pusty."),
                new Validation(() => !url.IsWebUrl(), "Niepoprawny format Url.")
                );

            if (viewData == null)
            {
                try
                {
                    IStory story = _storyRepository.FindByUrl(url);

                    if (story != null)
                    {
                        string existingUrl = Url.RouteUrl("Detail", new { name = story.UniqueName });

                        viewData = new JsonContentViewData {
                            alreadyExists = true, existingUrl = existingUrl
                        };
                    }
                    else
                    {
                        StoryContent content = _contentService.Get(url);

                        viewData = (content == StoryContent.Empty) ?
                                   new JsonViewData {
                            errorMessage = "Podany Url nie istnieje."
                        } :
                        new JsonContentViewData {
                            isSuccessful = true, title = content.Title.HtmlDecode(), description = content.Description.HtmlDecode()
                        };
                    }
                }
                catch (Exception e)
                {
                    Log.Exception(e);

                    viewData = new JsonViewData {
                        errorMessage = FormatStrings.UnknownError.FormatWith("pobierania strony.")
                    };
                }
            }

            return(Json(viewData));
        }
コード例 #9
0
ファイル: StoryController.cs プロジェクト: aoki1210/kigg
        public ActionResult Retrieve(string url)
        {
            JsonViewData viewData = Validate <JsonViewData>(
                new Validation(() => string.IsNullOrEmpty(url), "Url cannot be blank."),
                new Validation(() => !url.IsWebUrl(), "Invalid Url format.")
                );

            if (viewData == null)
            {
                try
                {
                    IStory story = _storyRepository.FindByUrl(url);

                    if (story != null)
                    {
                        string existingUrl = Url.RouteUrl("Detail", new { name = story.UniqueName });

                        viewData = new JsonContentViewData {
                            alreadyExists = true, existingUrl = existingUrl
                        };
                    }
                    else
                    {
                        StoryContent content = _contentService.Get(url);

                        viewData = (content == StoryContent.Empty) ?
                                   new JsonViewData {
                            errorMessage = "Specified url does not exist."
                        } :
                        new JsonContentViewData {
                            isSuccessful = true, title = content.Title.HtmlDecode(), description = content.Description.HtmlDecode()
                        };
                    }
                }
                catch (Exception e)
                {
                    Log.Exception(e);

                    viewData = new JsonViewData {
                        errorMessage = FormatStrings.UnknownError.FormatWith("retrieving url")
                    };
                }
            }

            return(Json(viewData, JsonRequestBehavior.AllowGet));
        }
コード例 #10
0
        public ActionResult Submit(string url, string title)
        {
            bool isValidUrl = url.IsWebUrl();

            if (isValidUrl)
            {
                IStory story = _storyRepository.FindByUrl(url);

                if (story != null)
                {
                    // Story already exist, so take the user to that story
                    return(RedirectToRoute("Detail", new { name = story.UniqueName }));
                }
            }

            bool autoDiscover = Settings.AutoDiscoverContent || (IsCurrentUserAuthenticated && !CurrentUser.IsPublicUser());

            StoryContentViewData viewData = CreateViewData <StoryContentViewData>();

            viewData.Url            = url;
            viewData.Title          = title;
            viewData.AutoDiscover   = autoDiscover;
            viewData.CaptchaEnabled = !CurrentUser.ShouldHideCaptcha();

            if (isValidUrl)
            {
                StoryContent content = _contentService.Get(url);

                if (content != StoryContent.Empty)
                {
                    // Only replace when no title is specified
                    if (string.IsNullOrEmpty(title))
                    {
                        viewData.Title = content.Title;
                    }

                    if (autoDiscover)
                    {
                        viewData.Description = content.Description;
                    }
                }
            }

            return(View("New", viewData));
        }
コード例 #11
0
    // Use this for initialization
    void Start()
    {
        foreach (TextAsset t in Resources.LoadAll <TextAsset>("Story/" + storyChapter))
        {
            StoryContent s = StoryContent.CreateFromJSON(t.text);
            storyContentList.Add(s);
        }

        for (int i = 0; i < storyContentList.Count; i++)
        {
            if (storyContentList[i].title.Equals(story))
            {
                n = i;
                break;
            }
        }

        foreach (TextAsset t in Resources.LoadAll <TextAsset>("Achievement/" + achiChapter))
        {
            AchievementContent a = AchievementContent.CreateFromJSON(t.text);
            achiContentList.Add(a);
        }

        if (!hideStory)
        {
            StartCoroutine("ShowContent");
        }
        else
        {
            if (Menu.instance != null)
            {
                storyPanel.transform.parent.gameObject.SetActive(false);
                Menu.instance.isGameOn = true;
            }
        }
    }
コード例 #12
0
 public StoryContentFixture()
 {
     storyContent = new StoryContent(Title, Description, TrackBackUrl);
 }
コード例 #13
0
        public virtual StoryCreateResult Create(IUser byUser, string url, string title, string category, string description, string tags, string userIPAddress, string userAgent, string urlReferer, NameValueCollection serverVariables, Func <IStory, string> buildDetailUrl)
        {
            StoryCreateResult result = ValidateCreate(byUser, url, title, category, description, userIPAddress, userAgent);

            if (result == null)
            {
                if (_contentService.IsRestricted(url))
                {
                    result = new StoryCreateResult {
                        ErrorMessage = "Podany url jest zablokowany."
                    };
                }
            }

            if (result == null)
            {
                using (IUnitOfWork unitOfWork = UnitOfWork.Begin())
                {
                    IStory alreadyExists = _storyRepository.FindByUrl(url);

                    if (alreadyExists != null)
                    {
                        return(new StoryCreateResult {
                            ErrorMessage = "Artykuł z danym url już istnieje.", DetailUrl = buildDetailUrl(alreadyExists)
                        });
                    }

                    ICategory storyCategory = _categoryRepository.FindByUniqueName(category);

                    if (storyCategory == null)
                    {
                        return(new StoryCreateResult {
                            ErrorMessage = "\"{0}\" nie istnieje.".FormatWith(category)
                        });
                    }
                    if (storyCategory.IsActive == false)
                    {
                        return(new StoryCreateResult
                        {
                            ErrorMessage = "\"{0}\" jest tylko do odczytu.".FormatWith(category)
                        });
                    }

                    StoryContent content = _contentService.Get(url);

                    if (content == StoryContent.Empty)
                    {
                        return(new StoryCreateResult {
                            ErrorMessage = "Podany Url wydaje się być wadliwy."
                        });
                    }

                    var splittedTags = tags.NullSafe().Split(',');
                    if (splittedTags.Length == 1) //only one tag
                    {
                        var tag = splittedTags[0].Trim();
                        if (String.Compare(".net", tag, StringComparison.OrdinalIgnoreCase) == 0 || String.Compare("c#", tag, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            return(new StoryCreateResult {
                                ErrorMessage = "Proszę, pomyśl chwilę nad lepszymi tagami."
                            });
                        }
                    }
                    if (splittedTags.Length == 2) //two tags, maybe not .net and C#
                    {
                        var tag1 = splittedTags[0].Trim();
                        var tag2 = splittedTags[1].Trim();
                        if (
                            (String.Compare(".net", tag1, StringComparison.OrdinalIgnoreCase) == 0 && String.Compare("c#", tag2, StringComparison.OrdinalIgnoreCase) == 0) ||
                            (String.Compare(".net", tag1, StringComparison.OrdinalIgnoreCase) == 0 && String.Compare("c#", tag2, StringComparison.OrdinalIgnoreCase) == 0)
                            )
                        {
                            return(new StoryCreateResult {
                                ErrorMessage = "Tagi: .Net i C#. Srsly?"
                            });
                        }
                    }

                    description = _htmlSanitizer.Sanitize(description);

                    if (!_settings.AllowPossibleSpamStorySubmit && ShouldCheckSpamForUser(byUser))
                    {
                        result = EnsureNotSpam <StoryCreateResult>(byUser, userIPAddress, userAgent, url, urlReferer, description, "social news", serverVariables, "Artykuł odrzucony: {0}, {1}".FormatWith(url, byUser), "Twój artykuł wydaje się być spamem.");

                        if (result != null)
                        {
                            return(result);
                        }
                    }

                    // If we are here which means story is not spam
                    IStory story = _factory.CreateStory(storyCategory, byUser, userIPAddress, title.StripHtml(), description, url);

                    _storyRepository.Add(story);

                    // The Initial vote;
                    story.Promote(story.CreatedAt, byUser, userIPAddress);

                    // Capture the thumbnail, might speed up the thumbnail generation process
                    _thumbnail.Capture(story.Url);

                    // Subscribe comments by default
                    story.SubscribeComment(byUser);

                    AddTagsToContainers(tags, new ITagContainer[] { story, byUser });

                    string detailUrl = buildDetailUrl(story);

                    if (_settings.AllowPossibleSpamStorySubmit && _settings.SendMailWhenPossibleSpamStorySubmitted && ShouldCheckSpamForUser(byUser))
                    {
                        unitOfWork.Commit();
                        _spamProtection.IsSpam(CreateSpamCheckContent(byUser, userIPAddress, userAgent, url, urlReferer, description, "social news", serverVariables), (source, isSpam) => _spamPostprocessor.Process(source, isSpam, detailUrl, story));
                    }
                    else
                    {
                        story.Approve(SystemTime.Now());
                        _eventAggregator.GetEvent <StorySubmitEvent>().Publish(new StorySubmitEventArgs(story, detailUrl));
                        unitOfWork.Commit();
                    }

                    result = new StoryCreateResult {
                        NewStory = story, DetailUrl = detailUrl
                    };
                }
            }

            return(result);
        }
コード例 #14
0
        public async void Update()
        {
            IsLoading = true;

            var t1 = _api.GetStoryContent(_story_id);
            var t2 = _api.GetStoryExtra(_story_id);

            StoryContent sc = await t1;
            StoryExtra   se = await t2;

            if (sc != null)
            {
                ID                 = sc.ID;
                Title              = sc.Title;
                Image              = sc.Image;
                ImageSource        = sc.Image_Source;
                RecommenderAvatars = sc.RecommnderAvatars;
                ShareUrl           = sc.Share_URL;
                string css = "<style>"
                             + "html{-ms-content-zooming:none;font-family:微软雅黑;}"
                             + ".author{font-weight:bold;} .bio{color:gray;}"
                             + "body{padding:20px;word-break:break-all;} p{margin:30px auto;} a{color:skyblue;} .content img{width:95%;}"
                             + "body{line-height:150%;}"
                             + "</style>"; //基础css
                string ex_mark = "<base target='_blank'/>";
                string css2    = "";       //主题css
                string css3    = "";       //字体css
                string js      = "";       //图片加载脚本
                string body    = "";

                if (DataShareManager.Current.APPTheme == Windows.UI.Xaml.ElementTheme.Dark) //夜间主题
                {
                    css2 = "<style>"
                           + "body{background-color:black !important;color:gray !important;}"
                           + "</style>";
                }
                else
                {
                    css2 = "";
                }
                if (DataShareManager.Current.BigFont)  //大字号
                {
                    css3 = "<style>body{font-size:52px;} h1{font-size:62px;} h2{font-size:58px;} h3{font-size:52px;} h4,h5,h6{font-size:48px;}</style>";
                }
                else
                {
                    css3 = "<style>body{font-size:44px;} h1{font-size:55px;} h2{font-size:50px;} h3{font-size:45px;} h4,h5,h6{font-size:40px;}</style>";
                }

                if (DataShareManager.Current.NOImagesMode)   //无图模式
                {
                    if (NetworkManager.Current.Network != 3) //非wifi
                    {
                        body = Regex.Replace(sc.Body, @"<img.*?src=(['""]?)(?<url>[^'"" ]+)(?=\1)[^>]*>", (m) =>
                        {
                            if (m.Value.Contains("avatar"))
                            {
                                return(m.Value);
                            }
                            else
                            {
                                Match match = Regex.Match(m.Value.ToString(), @"<img\b[^<>]*?\bsrc[\s\t\r\n]*=[\s\t\r\n]*[""']?[\s\t\r\n]*(?<imgUrl>[^\s\t\r\n""'<>]*)[^<>]*?/?[\s\t\r\n]*>");
                                if (match.Success)
                                {
                                    return(@"<img src=""ms-appx-web:///Assets/default_image.png"" onclick=""click2loadimage(this,'" + match.Groups["imgUrl"].Value + @"');""/>");
                                }
                                else
                                {
                                    return(m.Value);
                                }
                            }
                        }, RegexOptions.IgnoreCase); //替换所有img标签 为本地图片

                        js = "<script>"              //点击加载图片
                             + "function click2loadimage(obj,source)"
                             + "{"
                             + "obj.setAttribute('src','ms-appx-web:///Assets/default_image_loading.png');"
                             + "obj.setAttribute('src',source);"
                             + "}"
                             + "</script>";
                    }
                    else
                    {
                        body = sc.Body;
                    }
                }
                else
                {
                    body = sc.Body;
                }
                // <link rel='stylesheet' type='text/css' href='" + sc.CSS + "'/> 官方css文件不好控制  所以没有使用

                //合并
                BodyHtml = "<html><head>" + ex_mark + css + css2 + css3 + js + "</head>" + "<body>" + body + "</body></html>";   //附加css
            }
            if (se != null)
            {
                Comments     = se.Comments;
                Popularities = se.Polularity;
                Favorite     = se.Favorite;
                _se          = se;
            }

            IsLoading = false;
        }
コード例 #15
0
        public virtual StoryCreateResult Create(IUser byUser, string url, string title, string category, string description, string tags, string userIPAddress, string userAgent, string urlReferer, NameValueCollection serverVariables, Func <IStory, string> buildDetailUrl)
        {
            StoryCreateResult result = ValidateCreate(byUser, url, title, category, description, userIPAddress, userAgent);

            if (result == null)
            {
                using (IUnitOfWork unitOfWork = UnitOfWork.Get())
                {
                    IStory alreadyExists = _storyRepository.FindByUrl(url);

                    if (alreadyExists != null)
                    {
                        return(new StoryCreateResult {
                            ErrorMessage = "Wpis z takim samym url ju¿ istnieje.", DetailUrl = buildDetailUrl(alreadyExists)
                        });
                    }

                    ICategory storyCategory = _categoryRepository.FindByUniqueName(category);

                    if (storyCategory == null)
                    {
                        return(new StoryCreateResult {
                            ErrorMessage = "\"{0}\" - kategoria nie istnieje.".FormatWith(category)
                        });
                    }

                    StoryContent content = _contentService.Get(url);

                    if (content == StoryContent.Empty)
                    {
                        return(new StoryCreateResult {
                            ErrorMessage = "Podany url wydaje siê nie byæ poprawnym."
                        });
                    }

                    description = _htmlSanitizer.Sanitize(description);

                    if (!_settings.AllowPossibleSpamStorySubmit && ShouldCheckSpamForUser(byUser))
                    {
                        result = EnsureNotSpam <StoryCreateResult>(byUser, userIPAddress, userAgent, url, urlReferer, description, "social news", serverVariables, "Spamowy wpis odrzucony : {0}, {1}".FormatWith(url, byUser), "Twój wpis wydaje siê byæ spamem.");

                        if (result != null)
                        {
                            return(result);
                        }
                    }

                    // If we are here which means story is not spam
                    IStory story = _factory.CreateStory(storyCategory, byUser, userIPAddress, title.StripHtml(), description, url);

                    _storyRepository.Add(story);

                    // The Initial vote;
                    story.Promote(story.CreatedAt, byUser, userIPAddress);

                    // Capture the thumbnail, might speed up the thumbnail generation process
                    _thumbnail.Capture(story.Url);

                    // Subscribe comments by default
                    story.SubscribeComment(byUser);

                    AddTagsToContainers(tags, new ITagContainer[] { story, byUser });

                    _userScoreService.StorySubmitted(byUser);

                    string detailUrl = buildDetailUrl(story);

                    if (_settings.AllowPossibleSpamStorySubmit && _settings.SendMailWhenPossibleSpamStorySubmitted && ShouldCheckSpamForUser(byUser))
                    {
                        unitOfWork.Commit();
                        _spamProtection.IsSpam(CreateSpamCheckContent(byUser, userIPAddress, userAgent, url, urlReferer, description, "social news", serverVariables),
                                               (source, isSpam) => _spamPostprocessor.Process(source, isSpam, detailUrl, story));
                    }
                    else
                    {
                        story.Approve(SystemTime.Now());
                    }

                    // Ping the Story
                    PingStory(content, story, detailUrl);

                    result = new StoryCreateResult {
                        NewStory = story, DetailUrl = detailUrl
                    };
                }
            }

            return(result);
        }
コード例 #16
0
ファイル: Controller.cs プロジェクト: christuart/Meet-EDSAC
 public void ActivateInformationContent(StoryContent _story)
 {
     infoHolder.PlaceObjectInInfoUI((InformationContent)(int)_story);
 }
コード例 #17
0
ファイル: StoryService.cs プロジェクト: aoki1210/kigg
        public virtual StoryCreateResult Create(IUser byUser, string url, string title, string category, string description, string tags, string userIPAddress, string userAgent, string urlReferer, NameValueCollection serverVariables, Func <IStory, string> buildDetailUrl)
        {
            StoryCreateResult result = ValidateCreate(byUser, url, title, category, description, userIPAddress, userAgent);

            if (result == null)
            {
                if (_contentService.IsRestricted(url))
                {
                    result = new StoryCreateResult {
                        ErrorMessage = "Specifed url has match with our banned url list."
                    };
                }
            }

            if (result == null)
            {
                using (IUnitOfWork unitOfWork = UnitOfWork.Begin())
                {
                    IStory alreadyExists = _storyRepository.FindByUrl(url);

                    if (alreadyExists != null)
                    {
                        return(new StoryCreateResult {
                            ErrorMessage = "Story with the same url already exists.", DetailUrl = buildDetailUrl(alreadyExists)
                        });
                    }

                    ICategory storyCategory = _categoryRepository.FindByUniqueName(category);

                    if (storyCategory == null)
                    {
                        return(new StoryCreateResult {
                            ErrorMessage = "\"{0}\" category does not exist.".FormatWith(category)
                        });
                    }

                    StoryContent content = _contentService.Get(url);

                    if (content == StoryContent.Empty)
                    {
                        return(new StoryCreateResult {
                            ErrorMessage = "Specified url appears to be broken."
                        });
                    }

                    description = _htmlSanitizer.Sanitize(description);

                    if (!_settings.AllowPossibleSpamStorySubmit && ShouldCheckSpamForUser(byUser))
                    {
                        result = EnsureNotSpam <StoryCreateResult>(byUser, userIPAddress, userAgent, url, urlReferer, description, "social news", serverVariables, "Spam story rejected : {0}, {1}".FormatWith(url, byUser), "Your story appears to be a spam.");

                        if (result != null)
                        {
                            return(result);
                        }
                    }

                    // If we are here which means story is not spam
                    IStory story = _factory.CreateStory(storyCategory, byUser, userIPAddress, title.StripHtml(), description, url);

                    _storyRepository.Add(story);

                    // The Initial vote;
                    story.Promote(story.CreatedAt, byUser, userIPAddress);

                    // Capture the thumbnail, might speed up the thumbnail generation process
                    _thumbnail.Capture(story.Url);

                    // Subscribe comments by default
                    story.SubscribeComment(byUser);

                    AddTagsToContainers(tags, new ITagContainer[] { story, byUser });

                    string detailUrl = buildDetailUrl(story);

                    if (_settings.AllowPossibleSpamStorySubmit && _settings.SendMailWhenPossibleSpamStorySubmitted && ShouldCheckSpamForUser(byUser))
                    {
                        unitOfWork.Commit();
                        _spamProtection.IsSpam(CreateSpamCheckContent(byUser, userIPAddress, userAgent, url, urlReferer, description, "social news", serverVariables), (source, isSpam) => _spamPostprocessor.Process(source, isSpam, detailUrl, story));
                    }
                    else
                    {
                        story.Approve(SystemTime.Now());
                        _eventAggregator.GetEvent <StorySubmitEvent>().Publish(new StorySubmitEventArgs(story, detailUrl));
                        unitOfWork.Commit();
                    }

                    result = new StoryCreateResult {
                        NewStory = story, DetailUrl = detailUrl
                    };
                }
            }

            return(result);
        }