Beispiel #1
0
        public static bool Validate(string challenge, string response, string userHostAddress)
        {
            StringBuilder postData = new StringBuilder();

            postData.AppendFormat("{0}={1}", "privatekey", OgdiConfiguration.GetValue("RecaptchaPrivateKey"));
            postData.AppendFormat("&{0}={1}", "remoteip", userHostAddress);
            postData.AppendFormat("&{0}={1}", "challenge", challenge);
            postData.AppendFormat("&{0}={1}", "response", response);

            HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create("http://api-verify.recaptcha.net/verify");

            myReq.Method        = WebRequestMethods.Http.Post;
            myReq.ContentType   = "application/x-www-form-urlencoded";
            myReq.ContentLength = postData.Length;

            using (StreamWriter postwriter = new StreamWriter(myReq.GetRequestStream()))
            {
                postwriter.Write(postData);
            }

            string          recaptchaResponse;
            HttpWebResponse myResp = myReq.GetResponse() as HttpWebResponse;

            using (StreamReader reader = new StreamReader(myResp.GetResponseStream()))
            {
                recaptchaResponse = reader.ReadLine();
                return(recaptchaResponse.ToLower() == "true");
            }
        }
Beispiel #2
0
        internal static CloudBlockBlob CreateBlob(string containerName, string tableName, string ext)
        {
            IsdkStorageProviderInterface service            = Helper.ServiceObject;
            CloudBlobDirectory           ContainerDirectory = convertedData.GetDirectoryReference(containerName);

            switch (ext)
            {
            case ".xml":
                // Get dbf data and save to blob
                XDocument      dataInDbfFormat = service.GetDataAsDaisy(containerName, tableName, null);
                CloudBlockBlob dbfBlob         = ContainerDirectory.GetBlockBlobReference(tableName + ext);
                using (MemoryStream xmlStream = new MemoryStream())
                {
                    using (XmlWriter xmlWriter = XmlWriter.Create(xmlStream))
                    {
                        dataInDbfFormat.Save(xmlWriter);
                        xmlWriter.Close();
                        xmlStream.Position = 0;
                        dbfBlob.UploadFromStream(xmlStream);
                    }
                }
                return(dbfBlob);

            case ".csv":
                // Get csv data and save to blob
                string dataInCsvFormat = service.GetdDataAsCsv(containerName, tableName, null);

                CloudBlockBlob csvBlob = ContainerDirectory.GetBlockBlobReference(tableName + ext);
                using (MemoryStream csvStream = new MemoryStream())
                {
                    using (StreamWriter sw = new StreamWriter(csvStream))
                    {
                        sw.Write(dataInCsvFormat);
                        sw.Flush();
                        csvStream.Position = 0;
                        csvBlob.UploadFromStream(csvStream);
                        sw.Close();
                    }
                }
                return(csvBlob);

            case ".ANSI.csv":
                // Get csv data and save to blob for Excel
                string dataInANSICsvFormat = service.GetdDataAsCsv(containerName, tableName, null);

                //Encoding winLatinCodePage = Encoding.GetEncoding(1252);
                Encoding winLatinCodePage = Encoding.GetEncoding(Convert.ToInt32(OgdiConfiguration.GetValue("ANSICodePage")));

                CloudBlockBlob ANSIcsvBlob   = ContainerDirectory.GetBlockBlobReference(tableName + ext);
                MemoryStream   ANSIcsvStream = new MemoryStream(Encoding.Convert(Encoding.Unicode, winLatinCodePage, Encoding.Unicode.GetBytes(dataInANSICsvFormat)));

                ANSIcsvStream.Position = 0;
                ANSIcsvBlob.UploadFromStream(ANSIcsvStream);

                return(ANSIcsvBlob);
            }

            return(null);
        }
        static DatasetInfoDataSource()
        {
            StorageAccount = CloudStorageAccount.Parse(OgdiConfiguration.GetValue("DataConnectionString"));

            CloudTableClient.CreateTablesFromModel(
                typeof(DatasetInfoDataContext),
                StorageAccount.TableEndpoint.AbsoluteUri,
                StorageAccount.Credentials);
        }
Beispiel #4
0
        static BlobRepositary()
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(OgdiConfiguration.GetValue("DataConnectionString"));

            // initialize blob storage
            CloudBlobClient blobStorage = storageAccount.CreateCloudBlobClient();

            convertedData = blobStorage.GetContainerReference("converteddata");
        }
        private void SendNotification(NotifyInfo ni)
        {
            var ce = ni.CommentEntry;

            var storageAccount = CloudStorageAccount.Parse(OgdiConfiguration.GetValue("DataConnectionString"));
            var queueStorage   = storageAccount.CreateCloudQueueClient();
            var queue          = queueStorage.GetQueueReference("workercommands");

            foreach (string subscriber in CommentRepository.GetSubscribers(ce.ParentName, ce.ParentContainer, ce.ParentType, ce.RowKey))
            {
                string unsubscribeLink = string.Format("{0}://{1}:{2}/comments/unsubscribe/?id={3}&type={4}&user={5}",
                                                       Request.UrlReferrer.Scheme,
                                                       Request.UrlReferrer.Host,
                                                       Request.UrlReferrer.Port,
                                                       ce.RowKey,
                                                       ce.ParentType,
                                                       subscriber);
                string datasetName = ni.DatasetName;
                string userName    = !string.IsNullOrEmpty(ni.CommentEntry.Author) ? ni.CommentEntry.Author : "Anonymous";
                string link        = ni.Link;
                string commentLink = ni.Link;
                string siteName    = "OGDI site";

                var body = new StringBuilder();
                body.AppendFormat("{0} posted new comment to <a href=\"{1}\">{2}</a>", userName, link, datasetName);
                body.AppendLine("<br/><br/>");
                body.AppendLine("<div style='font-family:Verdana;text-transform:uppercase;font-size:14pt;'><b>");
                body.AppendLine(ni.CommentEntry.Subject);
                body.AppendLine("</div></b>");
                body.AppendLine("<br/>");
                body.AppendLine(ni.CommentEntry.Body);
                body.AppendLine("<br/><br/><br/>");
                body.AppendLine("<div style='font-family:Verdana;font-size:7pt;'>");
                body.AppendFormat("<a href=\"{0}\">Stop following</a>", unsubscribeLink);
                body.AppendLine("<br/><hr/>");
                body.AppendFormat("You received this notification because you subscribed to comment updates on {0} on the {1}", datasetName, siteName);
                body.AppendLine("<div>");

                var messageXml = new XDocument(
                    new XElement("command",
                                 new XAttribute("commandname", "SendMail"),
                                 new XElement("EMailMessage",
                                              new XElement("To", subscriber),
                                              new XElement("Subject", "OGDI: " + datasetName),
                                              new XElement("Body", body.ToString()),
                                              new XElement("IsBodyHtml", "true")
                                              )));

                var message = new CloudQueueMessage(messageXml.ToString());
                queue.AddMessage(message);
            }
        }
        static public void RegisterView(String itemKey, String url, String user)
        {
            DatasetInfoDataSource datasetInfoDataSource = new DatasetInfoDataSource();
            ViewDataSource        viewDS = new ViewDataSource();

            datasetInfoDataSource.IncrementView(itemKey);

            // No logging if analytics are disabled
            if (OgdiConfiguration.GetValue("IsAnalytics") == "0")
            {
                return;
            }

            viewDS.AddView(new ViewEntry()
            {
                Date         = DateTime.Now,
                ItemKey      = itemKey,
                User         = user,
                RequestedUrl = url,
            });
        }