Ejemplo n.º 1
0
        protected void Submit_Click(object sender, EventArgs e)
        {
            NewsComponents newscomponents = new NewsComponents();
            newscomponents.Country = ddlCountry.SelectedValue;

            newscomponents.NewsHeadline = txtNewsHeadline.Text;
            newscomponents.NewsItem = txtNewsItem.Content;
            newscomponents.SummaryContent = txtSummaryContent.Content;
            newscomponents.Source = txtSource.Text;
            newscomponents.Category = ddlCategory.SelectedValue;
            newscomponents.Imagelabel = txtImageLabel.Text;
            newscomponents.TagName = "|";
            for (int i = 0; i < LstTags.Items.Count; i++)
            {
                if (LstTags.Items[i].Selected)
                {
                    newscomponents.TagName = newscomponents.TagName + LstTags.Items[i].Text + "|";
                }
            }
            newscomponents.Publish = "false";

            if (rbnNo.Checked)
                newscomponents.Publish = "false";
            if (rbnYes.Checked)
                newscomponents.Publish = "true";
            //if (FileUpload1.HasFile)
            //{
            //    uploadFiles = new UploadFiles();
            //    uploadFiles.ContentLength = Convert.ToString(FileUpload1.PostedFile.ContentLength);
            //    uploadFiles.ContentType = FileUpload1.PostedFile.ContentType;
            //    uploadFiles.FileName = FileUpload1.PostedFile.FileName;
            //    uploadFiles.Stream = FileUpload1.PostedFile.InputStream;
            //    listOffiles.Add(uploadFiles);
            //}
            //if (FileUpload2.HasFile)
            //{
            //    uploadFiles = new UploadFiles();
            //    uploadFiles.ContentLength = Convert.ToString(FileUpload2.PostedFile.ContentLength);
            //    uploadFiles.ContentType = FileUpload2.PostedFile.ContentType;
            //    uploadFiles.FileName = FileUpload2.PostedFile.FileName;
            //    uploadFiles.Stream = FileUpload2.PostedFile.InputStream;
            //    listOffiles.Add(uploadFiles);
            //}

            foreach (string file in Request.Files)
            {
                HttpPostedFile hpf = Request.Files[file] as HttpPostedFile;
                if (hpf.ContentLength == 0)
                    continue;
                Images images = new Images();
                images.fileName = Convert.ToString(Guid.NewGuid()) + hpf.FileName;
                images.photostreams = hpf.InputStream;
                Stream imagethumb;
                using (MemoryStream image = new MemoryStream())
                {
                    byte[] buffer = new byte[hpf.InputStream.Length];
                    int count;
                    int totalBytes = 0;
                    int len = Int32.Parse(Convert.ToString(hpf.InputStream.Length));
                    while ((count = hpf.InputStream.Read(buffer, 0, len)) > 0)
                    {
                        image.Write(buffer, 0, count);
                        totalBytes += count;
                    }
                    image.Position = 0;
                    byte[] transparentPng = new byte[totalBytes];
                    image.Read(transparentPng, 0, totalBytes);
                    imagethumb = CreateThumbNail(image);
                    newscomponents.ThumbNail = imagethumb;

                }
                switch (newscomponents.Country)
                {
                    case "kenya":

                        images.Url = Settings.Default.BucketNameURL + "/kenya/" + images.fileName;
                        break;
                    case "malawi":
                        images.Url = Settings.Default.BucketNameURL + "/malawi/" + images.fileName;
                        break;
                    case "tanzania":
                        images.Url = Settings.Default.BucketNameURL + "/tanzania/" + images.fileName;
                        break;
                    case "uganda":
                        images.Url = Settings.Default.BucketNameURL + "/uganda/" + images.fileName;
                        break;
                    case "zambia":
                        images.Url = Settings.Default.BucketNameURL + "/zambia/" + images.fileName;
                        break;
                    case "zimbabwe":
                        images.Url = Settings.Default.BucketNameURL + "/zimbabwe/" + images.fileName;
                        break;
                    case "southafrica":
                        images.Url = Settings.Default.BucketNameURL + "/southafrica/" + images.fileName;
                        break;
                }

                // images.Url=Settings.Default.
                newscomponents.Images.Add(images);
            }

            newscomponents.NewsAdded = DateTime.Now;
            newscomponents.NewsID = Guid.NewGuid();
            newscomponents.ThumbNailKey = Guid.NewGuid() + ".jpg";
            newscomponents.NewsItem = Server.HtmlEncode(newscomponents.NewsItem);

            switch (newscomponents.Country)
            {
                case "kenya":
                    if (newscomponents.ThumbNail != null)
                    {
                        newscomponents.ThumbNailBucketName = Settings.Default.BucketName + "/" + Settings.Default.Kenya;
                        newscomponents.ThumbNailUrl = Settings.Default.BucketNameURL + "/" + Settings.Default.Kenya + "/" +
                                                 newscomponents.ThumbNailKey;
                    }

                    newscomponents.BucketName = Settings.Default.BucketName + "/" + Settings.Default.Kenya;
                    newscomponents.Summary = Settings.Default.BucketNameURL + "/" + Settings.Default.Kenya + "/" +
                                             newscomponents.NewsID;
                    NewsEngine.LoadNewsintoTables(newscomponents, Settings.Default.Kenya);
                    break;
                case "malawi":
                    if (newscomponents.ThumbNail != null)
                    {
                        newscomponents.ThumbNailBucketName = Settings.Default.BucketName + "/" + Settings.Default.Malawi;
                        newscomponents.ThumbNailUrl = Settings.Default.BucketNameURL + "/" + Settings.Default.Malawi + "/" +
                                                 newscomponents.ThumbNailKey;
                    }
                    newscomponents.BucketName = Settings.Default.BucketName + "/" + Settings.Default.Malawi;
                    newscomponents.Summary = Settings.Default.BucketNameURL + "/" + Settings.Default.Malawi + "/" +
                                             newscomponents.NewsID;
                    NewsEngine.LoadNewsintoTables(newscomponents, Settings.Default.Malawi);

                    break;
                case "tanzania":
                    if (newscomponents.ThumbNail != null)
                    {
                        newscomponents.ThumbNailBucketName = Settings.Default.BucketName + "/" + Settings.Default.Tanzania;
                        newscomponents.ThumbNailUrl = Settings.Default.BucketNameURL + "/" + Settings.Default.Tanzania + "/" +
                                                 newscomponents.ThumbNailKey;
                    }
                    newscomponents.BucketName = Settings.Default.BucketName + "/" + Settings.Default.Tanzania;
                    newscomponents.Summary = Settings.Default.BucketNameURL + "/" + Settings.Default.Tanzania + "/" +
                                             newscomponents.NewsID;
                    NewsEngine.LoadNewsintoTables(newscomponents, Settings.Default.Tanzania);
                    break;
                case "uganda":
                    if (newscomponents.ThumbNail != null)
                    {
                        newscomponents.ThumbNailBucketName = Settings.Default.BucketName + "/" + Settings.Default.Uganda;
                        newscomponents.ThumbNailUrl = Settings.Default.BucketNameURL + "/" + Settings.Default.Uganda + "/" +
                                                newscomponents.ThumbNailKey;
                    }
                    newscomponents.BucketName = Settings.Default.BucketName + "/" + Settings.Default.Uganda;
                    newscomponents.Summary = Settings.Default.BucketNameURL + "/" + Settings.Default.Uganda + "/" +
                                             newscomponents.NewsID;
                    NewsEngine.LoadNewsintoTables(newscomponents, Settings.Default.Uganda);
                    break;
                case "southafrica":
                    if (newscomponents.ThumbNail != null)
                    {
                        newscomponents.ThumbNailBucketName = Settings.Default.BucketName + "/" + Settings.Default.SouthAfrica;
                        newscomponents.ThumbNailUrl = Settings.Default.BucketNameURL + "/" + Settings.Default.SouthAfrica + "/" +
                                                newscomponents.ThumbNailKey;
                    }
                    newscomponents.BucketName = Settings.Default.BucketName + "/" + Settings.Default.SouthAfrica;
                    newscomponents.Summary = Settings.Default.BucketNameURL + "/" + Settings.Default.SouthAfrica + "/" +
                                             newscomponents.NewsID;
                    NewsEngine.LoadNewsintoTables(newscomponents, Settings.Default.SouthAfrica);
                    break;
                case "bostwana":
                    if (newscomponents.ThumbNail != null)
                    {
                        newscomponents.ThumbNailBucketName = Settings.Default.BucketName + "/" + Settings.Default.Bostwana;
                        newscomponents.ThumbNailUrl = Settings.Default.BucketNameURL + "/" + Settings.Default.Bostwana + "/" +
                                                newscomponents.ThumbNailKey;
                    }
                    newscomponents.BucketName = Settings.Default.BucketName + "/" + Settings.Default.Bostwana;
                    newscomponents.Summary = Settings.Default.BucketNameURL + "/" + Settings.Default.Bostwana + "/" +
                                             newscomponents.NewsID;
                    NewsEngine.LoadNewsintoTables(newscomponents, Settings.Default.SouthAfrica);
                    break;
                case "zambia":
                    if (newscomponents.ThumbNail != null)
                    {
                        newscomponents.ThumbNailBucketName = Settings.Default.BucketName + "/" + Settings.Default.Zambia;
                        newscomponents.ThumbNailUrl = Settings.Default.BucketNameURL + "/" + Settings.Default.Zambia + "/" +
                                                newscomponents.ThumbNailKey;
                    }
                    newscomponents.BucketName = Settings.Default.BucketName + "/" + Settings.Default.Zambia;
                    newscomponents.Summary = Settings.Default.BucketNameURL + "/" + Settings.Default.Zambia + "/" +
                                             newscomponents.NewsID;
                    NewsEngine.LoadNewsintoTables(newscomponents, Settings.Default.Zambia);
                    break;
                case "zimbabwe":
                    if (newscomponents.ThumbNail != null)
                    {
                        newscomponents.ThumbNailBucketName = Settings.Default.BucketName + "/" + Settings.Default.Zimbabwe;
                        newscomponents.ThumbNailUrl = Settings.Default.BucketNameURL + "/" + Settings.Default.Zimbabwe + "/" +
                                                newscomponents.ThumbNailKey;
                    }
                    newscomponents.BucketName = Settings.Default.BucketName + "/" + Settings.Default.Zimbabwe;
                    newscomponents.Summary = Settings.Default.BucketNameURL + "/" + Settings.Default.Zimbabwe + "/" +
                                             newscomponents.NewsID;
                    NewsEngine.LoadNewsintoTables(newscomponents, Settings.Default.Zimbabwe);
                    break;
            }
            lblResults2.Visible = true;
            lblResult.Visible = true;
        }
Ejemplo n.º 2
0
        private static void UsingSyndicationFeed(List<NewsComponents> listNews, Dictionary<string, List<NewsComponents>> newsdictionary, Urls item, XmlReader reader)
        {
            SyndicationFeed feed = SyndicationFeed.Load(reader);

            var fed = (from f in feed.Items
                      orderby f.LastUpdatedTime descending

                      select f).Take(10);

            foreach (var newsItem in fed)
            {
                NewsComponents newsComponents = new NewsComponents();
                newsComponents.NewsID = Guid.NewGuid();
                newsComponents.NewsHeadline = newsItem.Title.Text;
                newsComponents.Summary = string.IsNullOrWhiteSpace(newsItem.Summary.Text) ? "" : newsItem.Summary.Text;
                newsComponents.Source = item.key;
                newsComponents.Section = "";
                //newsComponents. = "";
                newsComponents.Category = item.Category;
                newsComponents.NewsAdded = newsItem.PublishDate.DateTime;
                newsComponents.TimeStamp = DateTime.Now;

                try
                {
                    foreach (var link in newsItem.Links)
                    {

                        if (link.MediaType == null)
                        {

                            var stream = GetStreamInternet(link);
                            StreamReader strReader = new StreamReader(stream);
                            string newsContent = strReader.ReadToEnd();
                            newsComponents.NewsItem = StripHtmlStuff(newsContent, newsComponents.NewsHeadline);
                        }
                        else if (link.MediaType.Contains("image"))
                        {
                            var stream = GetStreamInternet(link);
                            Images image = new Images();
                            image.photostreams = stream;
                            image.fileName = Guid.NewGuid() + ".jpg";
                            image.Url = URL + image.fileName;
                            newsComponents.Images.Add(image);
                            newsComponents.NewsPhotoUrl = image.Url + ";" + newsComponents.NewsPhotoUrl;
                        }
                    }
                    SaveImageToSC(newsComponents.Images);

                }
                catch (Exception e)
                {
                }
                finally
                {
                    listNews.Add(newsComponents);

                    //}

                }

            }
            newsdictionary.Add(item.key, listNews);
        }
Ejemplo n.º 3
0
        public static void LoadNewsintoTables(NewsComponents components, string domainName)
        {
            foreach (var img in components.Images)
            {
                components.NewsPhotoUrl = components.NewsPhotoUrl + "|" + img.Url;
            }

            NewsMethods.SaveNewItems(domainName, Settings.Default.BucketName + "/" + components.Country.ToLower(), components, sdbClient, s3Client);
        }
Ejemplo n.º 4
0
        public static void SaveNewItems(string domainName, string bucketName, NewsComponents newsItem, AmazonSimpleDBClient sdbClient, AmazonS3Client s3Client)
        {
            try
            {

                foreach (var stream in newsItem.Images)
                {
                    PutObjectRequest putObjectRequest = new PutObjectRequest();
                    putObjectRequest.WithBucketName(bucketName);
                    putObjectRequest.CannedACL = S3CannedACL.PublicRead;
                    putObjectRequest.Key = stream.fileName;
                    putObjectRequest.InputStream = stream.photostreams;

                    using (S3Response response = s3Client.PutObject(putObjectRequest))
                    {
                        WebHeaderCollection headers = response.Headers;
                        foreach (string key in headers.Keys)
                        {
                            //log headers ("Response Header: {0}, Value: {1}", key, headers.Get(key));
                        }
                    }
                }

                PutObjectRequest putObjectNewsItem = new PutObjectRequest();
                putObjectNewsItem.WithBucketName(newsItem.BucketName);
                putObjectNewsItem.CannedACL = S3CannedACL.PublicRead;
                putObjectNewsItem.Key = Convert.ToString(newsItem.NewsID);
                putObjectNewsItem.ContentType = "text/html";
                putObjectNewsItem.ContentBody = newsItem.NewsItem;

                using (S3Response response = s3Client.PutObject(putObjectNewsItem))
                {
                    WebHeaderCollection headers = response.Headers;
                    foreach (string key in headers.Keys)
                    {
                        //log headers ("Response Header: {0}, Value: {1}", key, headers.Get(key));
                    }
                }

                PutAttributesRequest putAttrRequest = new PutAttributesRequest()
                .WithDomainName(domainName)
                .WithItemName(Convert.ToString(newsItem.NewsID));

                putAttrRequest.WithAttribute(
                     new ReplaceableAttribute
                        {
                            Name = "NewsID",
                            Value = Convert.ToString(newsItem.NewsID),
                            Replace = false
                        },
                        new ReplaceableAttribute
                        {
                            Name = "Source",
                            Value = newsItem.Source,
                            Replace = false
                        },
                        new ReplaceableAttribute
                        {
                            Name = "NewsHeadline",
                            Value = newsItem.NewsHeadline,
                            Replace = true
                        },
                        new ReplaceableAttribute
                        {
                            Name = "NewsAdded",
                            Value = Convert.ToString(newsItem.NewsAdded),
                            Replace = true
                        }
                        ,
                         new ReplaceableAttribute
                         {
                             Name = "Summary",
                             Value = newsItem.Summary,
                             Replace = true
                         }
                         ,
                         new ReplaceableAttribute
                         {
                             Name = "SummaryContent",
                             Value = newsItem.SummaryContent,
                             Replace = true
                         }
                          ,
                         new ReplaceableAttribute
                         {
                             Name = "Imagelabel",
                             Value = newsItem.Imagelabel,
                             Replace = true
                         },
                         new ReplaceableAttribute
                         {
                             Name = "Photos",
                             Value = newsItem.NewsPhotoUrl,
                             Replace = true
                         }
                        ,
                         new ReplaceableAttribute
                         {
                             Name = "Category",
                             Value = newsItem.Category,
                             Replace = true
                         }
                         ,
                         new ReplaceableAttribute
                         {
                             Name = "TimeStamp",
                             Value = Convert.ToString(newsItem.TimeStamp),
                             Replace = true
                         });

                sdbClient.PutAttributes(putAttrRequest);
            }
            catch (AmazonS3Exception amazonS3Exception)
            {
                if (amazonS3Exception.ErrorCode != null && (amazonS3Exception.ErrorCode.Equals("InvalidAccessKeyId") || amazonS3Exception.ErrorCode.Equals("InvalidSecurity")))
                {
                    //log exception - ("Please check the provided AWS Credentials.");
                }
                else
                {
                    //log exception -("An error occurred with the message '{0}' when writing an object", amazonS3Exception.Message);
                }
            }
            catch (AmazonSimpleDBException amazonSimpleDBException)
            {
                string val = amazonSimpleDBException.ErrorCode;
            }
        }
Ejemplo n.º 5
0
        public ActionResult EnterNews(NewsComponents newscomponents)
        {
            foreach (string file in Request.Files)
            {
                HttpPostedFileBase hpf = Request.Files[file] as HttpPostedFileBase;
                if (hpf.ContentLength == 0)
                    continue;
                Images images = new Images();
                images.fileName = Convert.ToString(Guid.NewGuid()) + hpf.FileName;
                images.photostreams = hpf.InputStream;
                switch (newscomponents.Country)
                {
                    case "Kenya":

                        images.Url = Settings.Default.BucketNameURL + "/kenya/" + images.fileName;
                        break;
                    case "Malawi":
                        images.Url = Settings.Default.BucketNameURL + "/malawi/" + images.fileName;
                        break;
                    case "Tanzania":
                        images.Url = Settings.Default.BucketNameURL + "/tanzania/" + images.fileName;
                        break;
                    case "Uganda":
                        images.Url = Settings.Default.BucketNameURL + "/uganda/" + images.fileName;
                        break;
                    case "Zambia":
                        images.Url = Settings.Default.BucketNameURL + "/zambia/" + images.fileName;
                        break;
                    case "Zimbabwe":
                        images.Url = Settings.Default.BucketNameURL + "/zimbabwe/" + images.fileName;
                        break;
                }

                // images.Url=Settings.Default.
                newscomponents.Images.Add(images);
            }

            newscomponents.NewsAdded = DateTime.Now;
            newscomponents.NewsID = Guid.NewGuid();
            newscomponents.NewsItem = Server.HtmlEncode(newscomponents.NewsItem);

            switch (newscomponents.Country)
            {
                case "Kenya":
                    newscomponents.BucketName = Settings.Default.BucketName + "/" + Settings.Default.Kenya;
                    newscomponents.Summary = Settings.Default.BucketNameURL + "/" + Settings.Default.Kenya + "/" + newscomponents.NewsID;
                    NewsEngine.LoadNewsintoTables(newscomponents, Settings.Default.Kenya);
                    break;
                case "Malawi":
                    newscomponents.BucketName = Settings.Default.BucketName + "/" + Settings.Default.Malawi;
                    newscomponents.Summary = Settings.Default.BucketNameURL + "/" + Settings.Default.Malawi + "/" + newscomponents.NewsID;
                    NewsEngine.LoadNewsintoTables(newscomponents, Settings.Default.Malawi);

                    break;
                case "Tanzania":
                    newscomponents.BucketName = Settings.Default.BucketName + "/" + Settings.Default.Uganda;
                    newscomponents.Summary = Settings.Default.BucketNameURL + "/" + Settings.Default.Uganda + "/" + newscomponents.NewsID;
                    NewsEngine.LoadNewsintoTables(newscomponents, Settings.Default.Tanzania);
                    break;
                case "Uganda":
                    newscomponents.BucketName = Settings.Default.BucketName + "/" + Settings.Default.Uganda;
                    newscomponents.Summary = Settings.Default.BucketNameURL + "/" + Settings.Default.Uganda + " /" + newscomponents.NewsID;
                    NewsEngine.LoadNewsintoTables(newscomponents, Settings.Default.Uganda);
                    break;
                case "SouthAfrica":
                    newscomponents.BucketName = Settings.Default.BucketName + "/" + Settings.Default.SouthAfrica;
                    newscomponents.Summary = Settings.Default.BucketNameURL + "/" + Settings.Default.SouthAfrica + " /" + newscomponents.NewsID;
                    NewsEngine.LoadNewsintoTables(newscomponents, Settings.Default.SouthAfrica);
                    break;
                case "Bostwana":
                    newscomponents.BucketName = Settings.Default.BucketName + "/" + Settings.Default.Bostwana;
                    newscomponents.Summary = Settings.Default.BucketNameURL + "/" + Settings.Default.Bostwana + " /" + newscomponents.NewsID;
                    NewsEngine.LoadNewsintoTables(newscomponents, Settings.Default.SouthAfrica);
                    break;
                case "Zambia":
                    newscomponents.BucketName = Settings.Default.BucketName + "/" + Settings.Default.Zambia;
                    newscomponents.Summary = Settings.Default.BucketNameURL + "/" + Settings.Default.Zambia + "/" + newscomponents.NewsID;
                    NewsEngine.LoadNewsintoTables(newscomponents, Settings.Default.Zambia);
                    break;
                case "Zimbabwe":
                    newscomponents.BucketName = Settings.Default.BucketName + "/" + Settings.Default.Zimbabwe;
                    newscomponents.Summary = Settings.Default.BucketNameURL + "/" + Settings.Default.Zimbabwe + "/" + newscomponents.NewsID;
                    NewsEngine.LoadNewsintoTables(newscomponents, Settings.Default.Zimbabwe);
                    break;
            }

            return View();
        }
Ejemplo n.º 6
0
 public ActionResult Save(NewsComponents news)
 {
     return View();
 }