private void AddAuctionItem() { var call = service.AddItem(ebay_site); // insert into database using (var repository = new TradelrRepository()) { var product = repository.GetProduct(ProductId); product.ebay_product = ebayProduct; product.ebay_product.ebayid = call.ItemID; product.ebay_product.siteid = ebay_site.ToString(); product.ebay_product.startTime = call.Item.ListingDetails.StartTime; product.ebay_product.endTime = call.Item.ListingDetails.EndTime; product.ebay_product.isActive = true; foreach (FeeType fee in call.FeeList) { if (fee.Name == "ListingFee") { product.ebay_product.listingFees = Currency.symbol + fee.Fee.Value.ToString("n" + Currency.decimalCount); } } repository.Save("AddEbayItem"); } }
private user SaveEbayBuyer(UserType buyer, string buyeremail) { // check if buyer already exists using (var repository = new TradelrRepository()) { var newuser = new user() { role = UserRole.USER.ToInt(), email = buyeremail.Contains("@")?buyeremail:"", // this might be invalid request firstName = buyer.UserID, lastName = "", viewid = Crypto.Utility.GetRandomString(), permissions = (int)UserPermission.USER, organisation1 = new organisation { subdomain = sd.id, name = buyer.UserID }, ebay_user = new ebay_user { ebayuserid = buyer.UserID, feedback = buyer.FeedbackScore } }; repository.AddUser(newuser); return(newuser); } }
public static void SendEmails() { var myLock = new object(); lock (myLock) { try { using (var repository = new TradelrRepository()) { bool haveChanges = false; var mails = repository.GetMails(); foreach (var mail in mails.ToList()) { Email.Email.SendMail(mail, true, false); repository.DeleteMail(mail); haveChanges = true; } if (haveChanges) { repository.Save("SendEmails"); } } } catch (Exception ex) { Syslog.Write(ex); } } }
public ActionResult Yahoo(long subdomainid, long appid) { var client = new OAuthClient(OAuthTokenType.YAHOO, OAuthClient.OAUTH_YAHOO_CONSUMER_KEY, OAuthClient.OAUTH_YAHOO_CONSUMER_SECRET, "secure".ToTradelrDomainUrl("/oauth/yahoo"), "plaintext"); if (!client.GetRequestToken()) { return(Redirect("/Error")); } var oauthdb = new oauth_token { token_key = client.oauth_token, token_secret = client.oauth_secret, type = OAuthTokenType.YAHOO.ToString(), subdomainid = subdomainid, appid = appid.ToString(), authorised = false }; using (var repository = new TradelrRepository()) { repository.AddOAuthToken(oauthdb); } return(Redirect(client.authorize_url)); }
public static void UpdateFlatrateShipping(long profileid, decimal?[] shipping_cost, int?[] shipping_destination, long subdomainid) { using (var repository = new TradelrRepository()) { repository.DeleteShippingRules(profileid, subdomainid); for (int i = 0; i < shipping_destination.Length; i++) { var dest = shipping_destination[i]; var cost = shipping_cost[i]; if (cost.HasValue) { var rule = new shippingRule() { cost = cost.Value, secondaryCost = cost.Value, country = dest, matchvalue = 0, name = ShippingProfileType.FLATRATE.ToDescriptionString(), profileid = profileid, ruletype = (byte)RuleType.PRICE, state = "" }; repository.AddShippingRule(rule); } } } }
public static string GenerateAffiliateID() { string code = ""; int count = 0; while (true) { code = Crypto.Utility.GetRandomString(10, true); using (var repository = new TradelrRepository()) { if (!repository.GetSubDomains().Any(x => x.affiliateID == code)) { break; } } if (count++ >= 32) { Syslog.Write("Unable to generate affilliate ID"); break; } } return(code); }
public ActionResult Ebay(string username, string sid) { using (var repository = new TradelrRepository()) { var odb = repository.GetOAuthToken(sid, OAuthTokenType.EBAY); if (odb == null) { throw new Exception("Could not locate ebay token entry"); } try { var ebayservice = new EbayService(); var token = ebayservice.GetToken(odb.token_key); odb.token_key = token; odb.token_secret = ""; odb.guid = username; odb.authorised = true; odb.expires = ebayservice.TokenExpires; repository.Save(); // sync with ebay var ebay = new NetworksEbay(odb.MASTERsubdomain.id); new Thread(() => ebay.StartSynchronisation(false)).Start(); } catch (Exception ex) { Syslog.Write(ex); } return(Redirect(odb.MASTERsubdomain.ToHostName().ToDomainUrl("/dashboard/networks#ebay"))); } }
public static void PollGoogleBase() { var myLock = new object(); lock (myLock) { var date = DateTime.UtcNow; using (var repository = new TradelrRepository()) { // check for expired items foreach (var sd in repository.GetSubDomains()) { var products = repository.GetProducts(sd.id).Where(x => x.gbase.HasValue); foreach (var p in products) { var gb = new GoogleBaseExporter(sd.id, sd.ToHostName()); if (date > p.gbase_product.expirydate) { gb.InitValues(p); #if !DEBUG IEnumerable <Photo> productPhotos = repository.GetImages(PhotoType.PRODUCT, p.id).ToModel(Imgsize.LARGE); gb.AddProductImages(productPhotos); #endif gb.AddToGoogleBase(); // delete old entry gb.DeleteFromGoogleBase(p.gbase_product.externalid); // update gbase entry p.gbase_product.externalid = gb.entry.Id.AbsoluteUri; p.gbase_product.expirydate = gb.entry.ExpirationDate; p.gbase_product.externallink = NetworksGbase.URLFromEntry(gb.entry); } else { // get status if (gb.GetFromGoogleBase(p.gbase_product.externalid)) { p.gbase_product.expirydate = gb.entry.ExpirationDate; if (gb.entry.IsDraft) { p.gbase_product.flags |= (int)InventoryItemFlag.DRAFT; } else { p.gbase_product.flags &= ~(int)InventoryItemFlag.DRAFT; } } } } } repository.Save("PollGoogleBase"); } } }
public static image ReadAndSaveFromUrl(this string url, long subdomainid, long ownerid, long contextid, PhotoType type) { var req = WebRequest.Create(url); WebResponse resp = null; try { resp = req.GetResponse(); } catch (Exception ex) { Syslog.Write(ex); } if (resp == null) { return(null); } try { var image = new image(); using (var repository = new TradelrRepository()) { var sd = repository.GetSubDomain(subdomainid); var extension = url.ToImageFormat().ToStringExtension(); var filename = BuildFilename(ownerid, extension); var handler = new FileHandler(filename, UploadFileType.IMAGE, sd.uniqueid); image.imageType = type.ToString(); image.subdomain = subdomainid; image.contextID = contextid; image.url = handler.Save(resp.GetResponseStream()); repository.AddImage(image); switch (type) { case PhotoType.PROFILE: var usr = repository.GetUserById(ownerid); if (usr != null) { usr.profilePhoto = image.id; } repository.Save("ReadAndSaveFromUrl:Profile"); break; default: break; } } return(image); } catch (Exception ex) { Syslog.Write(ex); return(null); } }
public static string ToSavedImageUrl(this string datauri, long sessionid, long subdomainid) { var segments = datauri.Split(new[] { ',' }); if (segments.Length != 2) { Syslog.Write("Invalid datauri: " + datauri); return(""); } var type = segments[0]; var data = segments[1]; Regex datauriRegex = new Regex("data:image/(.+);base64"); var match = datauriRegex.Match(type); string extension = ""; switch (match.Groups[1].Value) { case "jpeg": extension = ".jpg"; break; case "png": extension = ".png"; break; case "gif": extension = ".gif"; break; default: break; } if (String.IsNullOrEmpty(extension)) { Syslog.Write("Invalid datauri: " + datauri); return(""); } var bytes = Convert.FromBase64String(data); var ms = new MemoryStream(bytes); var filename = BuildFilename(sessionid, extension); string url = ""; using (var repository = new TradelrRepository()) { var sd = repository.GetSubDomain(subdomainid); var handler = new FileHandler(filename, UploadFileType.IMAGE, sd.uniqueid); url = handler.Save(ms); } return(url); }
private bool saveToken(OAuthTokenType tokenType, string oauth_token, string oauth_verifier) { using (var repository = new TradelrRepository()) { // oauth_token here would match request token saved in db // normally access token is different from request token var odb = repository.GetOAuthToken(oauth_token, tokenType); if (odb == null) { return(false); } accountHostName = odb.MASTERsubdomain.ToHostName(); OAuthClient client = null; switch (tokenType) { case OAuthTokenType.YAHOO: client = new OAuthClient(tokenType, OAuthClient.OAUTH_YAHOO_CONSUMER_KEY, OAuthClient.OAUTH_YAHOO_CONSUMER_SECRET, odb.token_key, odb.token_secret, oauth_verifier); break; case OAuthTokenType.TRADEME: client = new OAuthClient(tokenType, OAuthClient.OAUTH_TRADEME_CONSUMER_KEY, OAuthClient.OAUTH_TRADEME_CONSUMER_SECRET, odb.token_key, odb.token_secret, oauth_verifier, "HMAC-SHA1", "MyTradeMeRead,MyTradeMeWrite"); break; default: break; } if (client == null || !client.GetAccessToken()) { return(false); } odb.token_key = client.oauth_token; odb.token_secret = client.oauth_secret; odb.guid = client.guid; odb.authorised = true; repository.Save(); } return(true); }
public void UpdateProductGbaseID(string gbaseid) { using (var repository = new TradelrRepository()) { var p = repository.GetProduct(ProductId); if (p != null) { p.gbaseID = gbaseid; repository.Save(); } } }
public static product_image ReadAndSaveProductImageFromUrl(this string url, long subdomainid, long ownerid, long?productid) { var req = WebRequest.Create(url); WebResponse resp = null; try { resp = req.GetResponse(); } catch (Exception ex) { Syslog.Write(ex); } if (resp == null) { return(null); } try { var image = new product_image(); using (var repository = new TradelrRepository()) { var sd = repository.GetSubDomain(subdomainid); var extension = url.ToImageFormat().ToStringExtension(); var filename = BuildFilename(ownerid, extension); var handler = new FileHandler(filename, UploadFileType.IMAGE, sd.uniqueid); image.productid = productid; image.subdomainid = subdomainid; image.url = handler.Save(resp.GetResponseStream()); if (productid.HasValue) { repository.AddProductImage(image); var product = repository.GetProduct(productid.Value, subdomainid); if (product != null && !product.thumb.HasValue) { product.thumb = image.id; } repository.Save("ReadAndSaveProductImageFromUrl"); } } return(image); } catch (Exception ex) { Syslog.Write(ex); return(null); } }
private void AddShippingDetails(product p, long shipping_profileid) { // currently only support flat rate using (var repository = new TradelrRepository()) { var profile = repository.GetEbayShippingProfile(shipping_profileid); if (profile != null) { PopulateFlatRateShippingOptions(profile.ebay_shippingrules); } } service.AddShippingDetails(ShippingTypeCodeType.Flat, shipping_domestic, shipping_international); }
public ActionResult Single(long?id, string title, bool isJson = false) { if (!id.HasValue) { return(Content(CreatePageMissingTemplate().Render())); } // if store disabled then hide the product if (!IsStoreEnabled && !sessionid.HasValue) { return(RedirectToAction("Index", "login")); } LiquidTemplate template; using (var repo = new TradelrRepository()) { repo.SetIsolationToNoLock(); var p = repo.GetProduct(id.Value, subdomainid.Value); if (p == null) { return(Content(CreatePageMissingTemplate().Render())); } var liquidmodel = p.ToLiquidModel(sessionid, ""); if (isJson) { return(Json(liquidmodel, JsonRequestBehavior.AllowGet)); } if (p.hits.HasValue) { p.hits += 1; } else { p.hits = 1; } repo.Save(); template = CreateLiquidTemplate("product", p.title); // opengraph var opengraph = MASTERdomain.organisation.ToOpenGraph(p, null); template.AddHeaderContent(this.RenderViewToString("~/Views/store/liquid/defaultHeader.ascx", opengraph)); template.InitContentTemplate("templates/product.liquid"); template.AddParameters("product", liquidmodel); } return(Content(template.Render())); }
public void UpdateID(int postid) { Debug.Assert(ProductId != 0); using (var repository = new TradelrRepository()) { var w = repository.GetProduct(ProductId).wordpressPosts; if (w == null) { w = new wordpressPost(); repository.AddWordpressPost(w); } w.productid = ProductId; w.postid = postid; repository.Save(); } }
public void UpdateEbayItem(string itemid) { // todo: get fields which were deletedd // http://developer.ebay.com/DevZone/xml/docs/Reference/ebay/ReviseItem.html#Request.DeletedField service.ReviseItem(itemid, Enumerable.Empty <string>(), ebay_site); // insert into database using (var repository = new TradelrRepository()) { var product = repository.GetProduct(ProductId); product.ebay_product = ebayProduct; product.ebay_product.ebayid = itemid; repository.Save("Ebay.UpdateEbayItem"); } }
public string AddToGoogleBase() { UpdateEntry(); // try insert string gbaseId = ""; bool hasError = false; try { entry = service.Insert(feed, entry); gbaseId = entry.Id.AbsoluteUri; } catch (WebException ex) { var resp = ex.Response; hasError = true; if (resp != null) { using (var sr = new StreamReader(resp.GetResponseStream())) { var err = sr.ReadToEnd(); Syslog.Write(string.Concat("ADD: ", err, " ", hostName, " ", ProductId)); } } } catch (Exception ex) { Syslog.Write(ex); Syslog.Write(string.Concat("ADD: ", ex.Message, " ", hostName, " ", ProductId)); hasError = true; } if (hasError && ownerid.HasValue) { using (var repository = new TradelrRepository()) { repository.AddActivity(ownerid.Value, new ActivityMessage(ProductId, ownerid, ActivityMessageType.AUTOPOST_GBASE_FAIL, string.Format("<a href='{0}'>{1}</a>", producturl, productname)), subdomainid); repository.Save(); } } return gbaseId; }
public bool UpdateToGoogleBase() { bool hasError = false; try { var atomid = service.Update(entry).Id.AbsoluteUri; if (AtomID != atomid) { Syslog.Write(string.Format("Inserted GBASE not equal, productid {0} :{1} {2}", ProductId, AtomID, atomid)); } } catch(WebException ex) { var resp = ex.Response; hasError = true; if (resp != null) { using (var sr = new StreamReader(resp.GetResponseStream())) { var err = sr.ReadToEnd(); Syslog.Write(string.Format("Update err: {0}, hostname: {1}", err, hostName)); } } } catch (Exception ex) { Syslog.Write(ex); hasError = true; } if (hasError && ownerid.HasValue) { using (var repository = new TradelrRepository()) { repository.AddActivity(ownerid.Value, new ActivityMessage(ProductId, ownerid, ActivityMessageType.AUTOPOST_GBASE_FAIL, string.Format("<a href='{0}'>{1}</a>", producturl, productname)), subdomainid); repository.Save(); } return false; } return true; }
public int?PostEntry() { Debug.Assert(post != null); bool hasError = false; int? postid = null; try { #if DEBUG postid = wrapper.NewPost(post, false); #else postid = wrapper.NewPost(post, true); #endif } catch (WebException ex) { var resp = ex.Response; if (resp != null) { using (var sr = new StreamReader(resp.GetResponseStream())) { var err = sr.ReadToEnd(); hasError = true; Syslog.Write(string.Concat("Wordpress Post: ", err, " ", hostName, " ", postid)); } } } catch (Exception ex) { hasError = true; Syslog.Write(string.Concat("Wordpress Post: ", ex.Message, " ", hostName, " ", postid)); } if (hasError) { using (var repository = new TradelrRepository()) { repository.AddActivity(ownerid.Value, new ActivityMessage(ProductId, ownerid, ActivityMessageType.AUTOPOST_WORDPRESS_FAIL, string.Format("<a href='{0}'>{1}</a>", producturl, productname)), subdomainid); repository.Save(); } } return(postid); }
public void GetBlogEntry(product p, int postid) { bool hasError = false; try { post = wrapper.GetPost(postid); } catch (WebException ex) { var resp = ex.Response; if (resp != null) { using (var sr = new StreamReader(resp.GetResponseStream())) { var err = sr.ReadToEnd(); Syslog.Write(string.Concat("Wordpress Get entry: ", err, " ", hostName, " ")); } } hasError = true; } catch (Exception ex) { hasError = true; Syslog.Write(string.Concat("Wordpress Get entry: ", ex.Message, " ", hostName, " ")); } if (hasError) { using (var repository = new TradelrRepository()) { repository.AddActivity(ownerid.Value, new ActivityMessage(ProductId, ownerid, ActivityMessageType.AUTOPOST_WORDPRESS_FAIL, string.Format("<a href='{0}'>{1}</a>", producturl, productname)), subdomainid); repository.Save(); } } FillBlogEntry(p); }
public static void PollEbayOrders() { var myLock = new object(); lock (myLock) { try { using (var repository = new TradelrRepository()) { EbayPollForOrders(repository); } } catch (Exception ex) { Syslog.Write(ex); } } }
public static void ShipwirePollForInventoryUpdates() { using (var repository = new TradelrRepository()) { var cryptor = new AESCrypt(); var sds = repository.GetSubDomains().Where( x => x.shipwireEmail != null && x.shipwirePassword != null && x.shipwireEmail != "" && x.shipwirePassword != ""); foreach (var sd in sds) { var email = sd.shipwireEmail; var pass = cryptor.Decrypt(sd.shipwirePassword, sd.id.ToString()); var shipwire = new ShipwireService(email, pass); var updater = new InventoryUpdate(shipwire, sd.id); new Thread(() => updater.Update(WarehouseLocation.Values)).Start(); } } }
private void CheckInventoryLevel() { // log activity if is stock below or equals alarm level if (item.alarmLevel.HasValue && item.available.HasValue && item.product_variant != null && item.inventoryLocation != null && item.available <= item.alarmLevel) { using (var repository = new TradelrRepository()) { repository.AddActivity(subdomainid, new ActivityMessage(item.product_variant.productid, subdomainid, ActivityMessageType.PRODUCT_ALARM, item.inventoryLocation.name, new HtmlLink(item.product_variant.product.title, item.product_variant.productid). ToProductString()), subdomainid); } } }
public static void PollForShipwireShippedStatus() { var myLock = new object(); lock (myLock) { try { using (var repository = new TradelrRepository()) { bool haveChanges = ShipwirePollForShippedStatus(repository); if (haveChanges) { repository.Save("PollForShipwireShippedStatus"); } } } catch (Exception ex) { Syslog.Write(ex); } } }