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 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 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(); } } }
public void ReIndex() { writerInUse = true; using (var repository = new TradelrRepository()) { // get subdomains var subdomains = repository.GetSubDomains(); foreach (var subdomain in subdomains) { // index contacts writer = CreateWriter(LuceneIndexType.CONTACTS, subdomain.name); if (writer != null) { var contacts = repository.GetAllContacts(subdomain.id); foreach (var contact in contacts) { try { var action = new ContactItem(contact); var doc = IndexContact(action); writer.AddDocument(doc); } catch (Exception ex) { Syslog.Write(ex); } } writer.Optimize(); CloseWriter(); } // index products writer = CreateWriter(LuceneIndexType.PRODUCTS, subdomain.name); if (writer != null) { var products = repository.GetProducts(subdomain.id); foreach (var product in products) { try { var action = new ProductItem(product); var doc = IndexProduct(action); writer.AddDocument(doc); } catch (Exception ex) { Syslog.Write(ex); } } writer.Optimize(); CloseWriter(); } // orders writer = CreateWriter(LuceneIndexType.TRANSACTION, subdomain.name); if (writer != null) { MASTERsubdomain subdomain1 = subdomain; var orders = repository.GetOrders().Where(x => x.user1.organisation1.subdomain == subdomain1.id); foreach (var order in orders) { try { var acttion = new TransactionItem(order); var doc = IndexTransaction(acttion); writer.AddDocument(doc); } catch (Exception ex) { Syslog.Write("Lucene index error: order ID =" + order.id); Syslog.Write(ex); } } writer.Optimize(); CloseWriter(); } } } writerInUse = false; }