//Action to redirect to public ActionResult Go(string id = null) { //Get the db instance var dbInstance = LinkDatabase.getInstance(); if (id != null) { int decoding = Shortener.GetLongDecoding(id); try { string longUrl = dbInstance.getLongUrl(decoding.ToString()); //Ideally, with the above ID we will query the DB and get the respective url and redirect to that page //Response.Redirect(longUrl); return(new RedirectResult(longUrl)); } catch (ArgumentException) { //If long url couldn't be found, redirect back to our homepage return(RedirectToAction("LinkShortener", "Home")); } } else { //Otherwise, redirect back to our homepage return(RedirectToAction("LinkShortener", "Home")); } }
/// <summary> /// Runs the processor. /// </summary> /// <param name="args">The arguments.</param> public override void Process(ConfigurationPipelineArgs args) { object container = Context.Entity.Resolve(args.ConfigurationItemType, null); if (!(container is IEntity)) { return; } Item item = args.CustomData["item"] as Item; if (item == null) { return; } LinkDatabase linkDatabase = Globals.LinkDatabase; ItemLink[] links = linkDatabase.GetReferrers(item); foreach (ItemLink link in links) { Item source = link.GetSourceItem(); if (source.Parent.TemplateID != new ID(Configuration.Settings.GetSetting("Ecommerce.Settings.SettingsRootTemplateId"))) { continue; } this.RegisterInstance(args, (IEntity)container, source); args.AbortPipeline(); break; } }
public void Update_ItemPassed_ShouldReplaceLinks([Substitute] LinkDatabase linkDb, Db db) { var datasourceItemId = ID.NewID; db.Add(new DbItem("source") { Children = { new DbItem("_Local") { new DbItem("DatasourceItem") } }, Fields = { "testField" } }); ; db.Add(new DbItem("target") { Children = { new DbItem("_Local") { new DbItem("DatasourceItem") } }, Fields = { "testField" } }); ; var sourceItem = db.GetItem("/sitecore/content/source"); var targetItem = db.GetItem("/sitecore/content/target"); var datasourceItem = db.GetItem("/sitecore/content/source/_Local/DatasourceItem"); var targetDatasourceItem = db.GetItem("/sitecore/content/target/_Local/DatasourceItem"); var itemLinks = new[] { new ItemLink(sourceItem, FieldIDs.LayoutField, datasourceItem, string.Empty) }; linkDb.GetReferences(sourceItem).Returns(itemLinks.ToArray()); using (new LinkDatabaseSwitcher(linkDb)) { using (new EditContext(targetItem)) { targetItem["__Renderings"] = datasourceItem.ID.ToString(); } var referenceReplacer = new UpdateLocalDatasourceReferencesService(sourceItem, targetItem); referenceReplacer.Update(); var expectedValue = targetDatasourceItem.ID.ToString(); targetItem["__Renderings"].Should().Be(expectedValue); } }
public void LinkManager_Multilist_UpdatesReferences() { using (new SecurityDisabler()) { var test1Object = _sitecore.GetItem <MiscFixtureNS.SubClass>(_test1.ID.Guid); var test2Object = _sitecore.GetItem <MiscFixtureNS.SubClass>(_demo.ID.Guid); var newItem = _sitecore.Create <MiscFixtureNS.LinkTest, MiscFixtureNS.SubClass>(test1Object, "MultilistLinkTest"); Assert.IsNotNull(newItem); newItem.Multilist = new[] { test1Object, test2Object }; _sitecore.Save <MiscFixtureNS.LinkTest>(newItem); string path = newItem.Path; Item item = _db.GetItem(path); LinkDatabase linkDb = global::Sitecore.Configuration.Factory.GetLinkDatabase(); int count = linkDb.GetReferenceCount(item); Assert.AreEqual(3, count); //the additional one is the link to the template try { item.Delete(); } catch (NullReferenceException ex) { //we need to catch a null reference exception raised by the Sitecore.Tasks.ItemEventHandler.OnItemDeleted } } }
// GET: Reviews/GetCompanyReviews/{"companyName":"SEARCH NAME HERE"} public JsonResult GetCompanyReviews(string id) { List <CompanyReview> result = null; try { LinkDatabase db = LinkDatabase.getInstance(); JObject JsonObj = JObject.Parse(id); string companyName = JsonObj.GetValue("companyName").ToObject <string>(); result = db.readReview(companyName); } catch (Exception e) { return(Json(new { response = "operation failed" }, JsonRequestBehavior.AllowGet)); } if (result == null || result.Count == 0) { return(Json(new { response = "company does not exist" }, JsonRequestBehavior.AllowGet)); } else { return(Json(result, "application/json", JsonRequestBehavior.AllowGet)); } }
public ActionResult About() { LinkDatabase database = LinkDatabase.getInstance(); //Creates DB instance string resultLong = database.getLongUrl(Request.QueryString["id"]); //Returns long URL based on key return(new RedirectResult(resultLong)); //Redirects user to intended page }
public FakeLinkDatabaseTest() { this.item = ItemHelper.CreateInstance(this.database); this.behavior = Substitute.For<LinkDatabase>(); this.linkDatabase = new FakeLinkDatabase(); this.linkDatabase.LocalProvider.Value = this.behavior; }
public ActionResult GetCompanyReview(string id) { LinkDatabase database = LinkDatabase.getInstance(); ViewBag.Json = database.getReview(id); return(Json(database.getReview(id))); }
public FakeLinkDatabaseTest() { this.item = ItemHelper.CreateInstance(this.database); this.behavior = Substitute.For <LinkDatabase>(); this.linkDatabase = new FakeLinkDatabase(); this.linkDatabase.LocalProvider.Value = this.behavior; }
public virtual void SearchPropLinked() { LinkDatabase lLinkDatabase = LinkDatabase.Instance; List <GameObject> foundObjs = lLinkDatabase.GetLinkObjects(buildingLink, typeof(MainItemProp)); if (foundObjs.Count == 1) { propLinked = foundObjs[0]; } }
public override void SearchPropLinked() { _carsList = new List <GameObject>(); LinkDatabase lLinkDatabase = LinkDatabase.Instance; _carsList = lLinkDatabase.GetLinkObjects(buildingLink, typeof(CarItemProp)); _carsCompany = lLinkDatabase.GetLinkObjects(buildingLink, typeof(CarsCompanyProp))[0]; propLinked = lLinkDatabase.GetLinkObjects(buildingLink, typeof(CarsCompanyProp))[0]; }
public override void SearchPropLinked() { base.SearchPropLinked(); normalHousesLinked = new List <GameObject>(); metroLinked = new List <GameObject>(); citizensList = new List <GameObject>(); LinkDatabase lLinkDatabase = LinkDatabase.Instance; normalHousesLinked = lLinkDatabase.GetLinkObjects(buildingLink, typeof(HouseProp)); citizensList = lLinkDatabase.GetLinkObjects(buildingLink, typeof(CitizenProp)); metroLinked = lLinkDatabase.GetLinkObjects(buildingLink, typeof(MetroProp)); }
public ActionResult SaveCompanyReview(int?id) { Stream req = Request.InputStream; req.Seek(0, System.IO.SeekOrigin.Begin); string json = new StreamReader(req).ReadToEnd(); LinkDatabase database = LinkDatabase.getInstance(); //Creates DB instance ViewBag.Json = database.saveReview(json); return(View()); }
public ActionResult Index(string URL) { LinkDatabase dataBase = LinkDatabase.getInstance(); //Create DB instance string key = dataBase.saveLongURL(URL); //Saves long URL to DB and returns ID key string valueShort = Globals.getIp() + "/home/about?id=" + key; //Appends key returned from DB to shortened URL ViewBag.MyMessage = valueShort; //Places shortened URL in view bag to be dislayed in view return(View()); }
private static IEnumerable <Item> GetAliasItems(Item item) { LinkDatabase linkDatabase = Factory.GetLinkDatabase(); IEnumerable <ItemLink> source = from link in linkDatabase.GetReferrers(item) where link.SourceDatabaseName.Equals(item.Database.Name) where link.SourceFieldID.Equals(RedirectManager.FieldIDs.AliasLinkedItem) where link.GetSourceItem().TemplateID.Equals(Sitecore.TemplateIDs.Alias) select link; return (from link in source select link.GetSourceItem()); }
public void Go(string id = null) { var dbInstance = LinkDatabase.getInstance(); if (id != null) { string origUrl = dbInstance.getLongUrl(id); //Ideally, with the above ID we will squery the DB and get the respective url and redirect to that page Response.Redirect(origUrl); } else { //Otherwise, redirect back to our homepage Response.Redirect(HttpContext.Request.Url.Host); } }
public ActionResult LinkShortener(string longURL) { var dbInstance = LinkDatabase.getInstance(); dbInstance.createDB(); string shortURL = longURL; ViewData["Title"] = "Link Shortener"; //If string from post was null, then this field isn't displayed if (longURL != null) { //Randomly choose and int... This will actually be the PK value in the DB string shortUrl_iD = dbInstance.saveLongURL(longURL); string urlHost = HttpContext.Request.Url.Host; shortURL = urlHost + "/Home/Go/" + shortUrl_iD; } ViewData["shortURL"] = shortURL; return(View()); }
//Defualt action of home controller is linkshortener rather than index (changed in route config) //Action takes an optional parameter (longURL) - The url to be shortened public ActionResult LinkShortener(string longURL = null) { //Save the short url as the long url (currently) string shortURL = longURL; //Add the current title to the view bag (for display in the tab on a web broswer) ViewBag.Title = "Link Shortener"; //If string from post was null, then this if statement is never entered if (longURL != null) { //Get the DB instance (and if necessary the DB itself) var dbInstance = LinkDatabase.getInstance(); dbInstance.createDB(); //Save the longurl in the db and save the return as primary key string pk = dbInstance.saveLongURL(longURL); //Encode the PK string encoding = Shortener.GetShortEncoding(Int32.Parse(pk)); //Get the host and port parts of our website url string urlHost = HttpContext.Request.Url.Host; int urlPort = HttpContext.Request.Url.Port; //If no port, ignore adding it to the shortened url if (urlPort == 80) { //Short url looks like: <website name>:<port>/Home/Go/<encoded pk> shortURL = urlHost + "/Home/Go/" + encoding; } else { //Short url looks like: <website name>/Home/Go/<encoded pk> shortURL = urlHost + ":" + urlPort.ToString() + "/Home/Go/" + encoding; } } //Return the shortened (or null) short url to the view ViewBag.shortURL = shortURL; //Render the view return(View()); }
public JsonResult SaveCompanyReview(ReviewHolder data) { if (data == null) { return(Json(new { response = "Error: Invalid body JSON" })); } else if (!data.Review.CheckStars()) { return(Json(new { response = "Error: Stars must be a value between 0 and 5" })); } else if (!data.Review.CheckTimeStamp()) { return(Json(new { response = "Error: Invalid UNIX Timestamp" })); } else if (!data.Review.CheckCompanyName()) { return(Json(new { response = "Error: Empty Company Name Supplied" })); } else if (!data.Review.CheckUsername()) { return(Json(new { response = "Error: Empty Username Supplied" })); } else { try { LinkDatabase db = LinkDatabase.getInstance(); db.SaveReview(data.Review); return(Json(new { response = "success" })); } catch (Exception e) { return(Json(new { response = "exception thrown", exception = e.Message })); } } }
public void GetLocalDatasourceDependencies_HasDatasourceFolder_ShouldReturnLinkedItem([Substitute] LinkDatabase linkDb, [Content] Item item, [Content] Item[] refItems, [Content] DbTemplate template) { var itemLinks = refItems.Select(x => new ItemLink(item, FieldIDs.LayoutField, x, string.Empty)).ToList(); var datasourceFolder = item.Add("_Local", new TemplateID(template.ID)); var datasourceItem = datasourceFolder.Add("DatasourceItem", new TemplateID(item.TemplateID)); itemLinks.Add(new ItemLink(item, FieldIDs.LayoutField, datasourceItem, string.Empty)); linkDb.GetReferences(item).Returns(itemLinks.ToArray()); using (new LinkDatabaseSwitcher(linkDb)) { var linkItem = item.GetLocalDatasourceDependencies().Single(); linkItem.ID.Should().Be(datasourceItem.ID); } }
public SitecoreService(Database database) { InstanceContext = Context.GetContext(); _linkDb = global::Sitecore.Configuration.Factory.GetLinkDatabase(); _database = database; }
public void Session_OnStart() { LinkDatabase LD = LinkDatabase.getInstance(); HttpContext.Current.Session.Add("user", "Not Logged In"); }