Example #1
0
        /// <summary>
        /// saves mapping
        /// </summary>
        /// <returns></returns>
        public ActionResult Configure(string address, string ownerid, string viewerid, bool isCanvas)
        {
            if (string.IsNullOrEmpty(address))
            {
                Syslog.Write(ErrorLevel.ERROR, "os: address is empty");
                return(new EmptyResult());
            }

            // parse address
            Uri storeAddress = null;

            try
            {
                storeAddress = new Uri(address);
            }
            catch (Exception ex)
            {
                Syslog.Write(ex);
                return(new EmptyResult());
            }


            string subdomain = "";

            if (storeAddress.Host.Split('.').Length > 2)
            {
                int lastIndex = storeAddress.Host.LastIndexOf(".");
                int index     = storeAddress.Host.LastIndexOf(".", lastIndex - 1);
                subdomain = storeAddress.Host.Substring(0, index);
            }
            else
            {
                Syslog.Write(ErrorLevel.ERROR, "os: no subdomain");
                return(new EmptyResult());
            }

            var mastersd = db.MASTERsubdomains.Where(x => x.name == subdomain).SingleOrDefault();

            if (mastersd == null)
            {
                Syslog.Write(ErrorLevel.ERROR, "os: subdomain does not exist");
                return(new EmptyResult());
            }

            // check if there's already an entry, we ignore if there's already an entry
            var existing =
                db.opensocialPages.Where(x => x.osid == ownerid && x.subdomainid == mastersd.id).SingleOrDefault();

            if (existing == null)
            {
                var newEntry = new opensocialPage()
                {
                    subdomainid = mastersd.id, osid = ownerid
                };
                db.opensocialPages.InsertOnSubmit(newEntry);
                db.SubmitChanges();
            }
            return(RedirectToAction("Index", new { ownerid, viewerid, isCanvas }));
        }
Example #2
0
        public static void PollIndexingQueue()
        {
            var myLock = new object();

            lock (myLock)
            {
                using (var db = new tradelrDataContext())
                {
                    try
                    {
                        var queueItems = db.indexingQueues.Take(10);
                        foreach (var item in queueItems)
                        {
                            var action = item.ToModel();

                            if (LuceneUtil.Instance.ModifyIndex(action))
                            {
                                db.indexingQueues.DeleteOnSubmit(item);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Syslog.Write(ex);
                    }
                    finally
                    {
                        db.SubmitChanges();
                    }
                }
            }
        }
Example #3
0
 /*
  * public static long addTestMember()
  * {
  *
  *  using (var db = new tradelrDataContext())
  *  {
  *      user u = new user();
  *      u.fullName = "test test";
  *      u.role = (int)UserRole.ALL;
  *      u.created = DateTime.Now;
  *      u.lastLogin = DateTime.Now;
  *      db.users.InsertOnSubmit(u);
  *      db.SubmitChanges();
  *      return u.id;
  *  }
  *
  * }
  * */
 public static void deleteTestMember()
 {
     using (var db = new tradelrDataContext())
     {
         var result = db.users.Where(x => x.fullName == "test test").SingleOrDefault();
         if (result != null)
         {
             db.users.DeleteOnSubmit(result);
             db.SubmitChanges();
         }
     }
 }
Example #4
0
        private static void SendCompletedCallback(object sender, AsyncCompletedEventArgs e)
        {
            // get the identifier
            var token = (mail)e.UserState;

            if (e.Error != null)
            {
                Syslog.Write(e.Error);
                if (e.Error.GetType() != typeof(SmtpFailedRecipientException))
                {
                    // reinsert back into database
                    using (var db = new tradelrDataContext())
                    {
                        db.mails.InsertOnSubmit(token);
                        db.SubmitChanges();
                    }
                }
            }

            // update order status
            //ITradelrRepository repository = new TradelrRepository();
            //repository.UpdateOrderStatus(token.orderID, token.userID, OrderStatus.SENT);
        }
Example #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="entry"></param>
        /// <param name="isAsync"></param>
        /// <param name="repository">if specified, email is queued</param>
        public static void SendMail(mail entry, bool isAsync, bool queueMail)
        {
            // need to check for invalid email address
            if (!entry.toEmail.IsEmail())
            {
                return;
            }

            if (queueMail)
            {
                // queue it instead
                using (var db = new tradelrDataContext())
                {
                    db.mails.InsertOnSubmit(entry);
                    db.SubmitChanges();
                }
                return;
            }

            var         from    = new MailAddress(MAIL_SOURCE_ADDRESS, "tradelr", Encoding.UTF8);
            MailAddress replyto = null;

            if (!string.IsNullOrEmpty(entry.fromEmail))
            {
                replyto = new MailAddress(entry.fromEmail, entry.fromName, Encoding.UTF8);
            }
            else
            {
                entry.fromEmail = MAIL_SOURCE_ADDRESS;
                entry.fromName  = "tradelr";
            }
            var to  = new MailAddress(entry.toEmail, entry.toName, Encoding.UTF8);
            var msg = new MailMessage(from, to)
            {
                Body            = entry.body,
                IsBodyHtml      = true,
                BodyEncoding    = Encoding.UTF8,
                Subject         = entry.subject,
                SubjectEncoding = Encoding.UTF8
            };

            if (replyto != null)
            {
                msg.ReplyToList.Add(replyto);
            }

#if DEBUG
            var smtp = new SmtpClient(MAIL_SERVER, 587)
            {
                EnableSsl = true
            };
            var cred = new NetworkCredential("*****@*****.**", MAIL_PASSWORD);
            //smtp.Timeout = 10000;
#else
            SmtpClient        smtp = new SmtpClient(MAIL_SERVER);
            NetworkCredential cred = new NetworkCredential(MAIL_SOURCE_ADDRESS, MAIL_PASSWORD);
#endif
            new Thread(() =>
            {
                smtp.Credentials = cred;
                if (isAsync)
                {
                    smtp.SendCompleted += SendCompletedCallback;
                    smtp.SendAsync(msg, entry);
                }
                else
                {
                    try
                    {
                        smtp.Send(msg);
                    }
                    catch (Exception ex)
                    {
                        Syslog.Write(ex);
                    }
                }
            }).Start();
        }
Example #6
0
        // actual file download
        public ActionResult Index(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(Redirect(GeneralConstants.HTTP_HOST));
            }

            string filename;
            string path;
            string contentType;

            using (var db = new tradelrDataContext())
            {
                var digitalOrder = db.orderItems_digitals.SingleOrDefault(x => x.downloadid == id);
                if (digitalOrder == null)
                {
                    return(Redirect(GeneralConstants.HTTP_HOST));
                }

                // check download limit
                var spec = digitalOrder.orderItem.product_variant.product.products_digitals;

                if (spec.limit.HasValue && spec.limit.Value <= digitalOrder.downloadCount)
                {
                    return(Redirect(digitalOrder.orderItem.product_variant.product.MASTERsubdomain.ToHostName().ToDomainUrl()));
                }

                // check expiry
                if (spec.expiryDate.HasValue && DateTime.UtcNow > spec.expiryDate.Value)
                {
                    return(Redirect(digitalOrder.orderItem.product_variant.product.MASTERsubdomain.ToHostName().ToDomainUrl()));
                }

                filename = spec.filename;
                path     = GeneralConstants.APP_ROOT_DIR + spec.filepath;

                if (!System.IO.File.Exists(path))
                {
                    return(Redirect(digitalOrder.orderItem.product_variant.product.MASTERsubdomain.ToHostName().ToDomainUrl()));
                }

                // no need to store cookie as user may use different device, makes it easier to define the term download limit
                digitalOrder.downloadCount++;

                db.SubmitChanges();
            }

            var buffer = new byte[256];
            var fs     = new FileStream(path, FileMode.Open);

            // try get mimetype
            if (fs.Length >= 256)
            {
                fs.Read(buffer, 0, 256);
            }
            else
            {
                fs.Read(buffer, 0, (int)fs.Length);
            }

            // reset to beginning of stream
            fs.Seek(0, SeekOrigin.Begin);

            try
            {
                UInt32 mimetype;
                FindMimeFromData(0, null, buffer, 256, null, 0, out mimetype, 0);
                var mimeTypePtr = new IntPtr(mimetype);
                contentType = Marshal.PtrToStringUni(mimeTypePtr);
                Marshal.FreeCoTaskMem(mimeTypePtr);
            }
            catch (Exception ex)
            {
                Syslog.Write(ex);
                contentType = "unknown/unknown";
            }

            // return file
            return(File(fs, contentType, filename));
        }