I am getting below error while deploying my project in tomcat 7.
I am using struts 1.1 and commons-validator 1.3.1, compiling with jdk 7.
java.lang.NoSuchMethodError: org.apache.struts.validator.FieldChecks.validateRequired(Ljava/lang/Object;Lorg/apache/commons/validator/ValidatorAction;Lorg/apache/commons/validator/Field;Lorg/apache/struts/action/ActionErrors;Ljavax/servlet/http/HttpServletRequest;)Z
at org.apache.struts.util.StrutsValidator.validateRequired(StrutsValidator.java:114)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.commons.validator.ValidatorAction.executeValidationMethod(ValidatorAction.java:544)
at org.apache.commons.validator.Field.validateForRule(Field.java:796)
at org.apache.commons.validator.Field.validate(Field.java:876)
at org.apache.commons.validator.Form.validate(Form.java:288)
at org.apache.commons.validator.Validator.validate(Validator.java:351)
at org.apache.struts.validator.ValidatorForm.validate(ValidatorForm.java:116)
at com.mj.metal.form.administration.SignInForm.validate(SignInForm.java:158)
at org.apache.struts.action.RequestProcessor.processValidate(RequestProcessor.java:945)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:198)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
below is my validator-rules.xml
<global>
<validator name="required" classname="org.apache.struts.util.StrutsValidator" method="validateRequired" methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionErrors,
javax.servlet.http.HttpServletRequest" msg="errors.required">
<javascript>
<![CDATA[
function validateRequired(form) {
var bValid = true;
var focusField = null;
var i = 0;
var fields = new Array();
oRequired = new required();
for (x in oRequired) {
if ((form[oRequired[x][0]].type == 'text' ||
form[oRequired[x][0]].type == 'textarea' ||
form[oRequired[x][0]].type == 'select-one' ||
form[oRequired[x][0]].type == 'radio' ||
form[oRequired[x][0]].type == 'password') &&
(form[oRequired[x][0]].value == '')) {
if (i == 0) {
focusField = form[oRequired[x][0]];
}
fields[i++] = oRequired[x][1];
bValid = false;
}
}
if (fields.length > 0) {
focusField.focus();
alert(fields.join('\n'));
}
return bValid;
}]]>
</javascript>
</validator>
<validator name="requiredif" classname="org.apache.struts.validator.FieldChecks" method="validateRequiredIf" methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionMessages,
org.apache.commons.validator.Validator,
javax.servlet.http.HttpServletRequest" msg="errors.required" />
<validator name="validwhen" msg="errors.required" classname="org.apache.struts.validator.validwhen.ValidWhen" method="validateValidWhen" methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionMessages,
org.apache.commons.validator.Validator,
javax.servlet.http.HttpServletRequest" />
<validator name="minlength" classname="org.apache.struts.util.StrutsValidator" method="validateMinLength" methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionErrors,
javax.servlet.http.HttpServletRequest" depends="required" msg="errors.minlength">
<javascript>
<![CDATA[
function validateMinLength(form) {
var bValid = true;
var focusField = null;
var i = 0;
var fields = new Array();
oMinLength = new minlength();
for (x in oMinLength) {
if (form[oMinLength[x][0]].type == 'text' ||
form[oMinLength[x][0]].type == 'textarea') {
var iMin = parseInt(oMinLength[x][2]("minlength"));
if (!(form[oMinLength[x][0]].value.length >= iMin)) {
if (i == 0) {
focusField = form[oMinLength[x][0]];
}
fields[i++] = oMinLength[x][1];
bValid = false;
}
}
}
if (fields.length > 0) {
focusField.focus();
alert(fields.join('\n'));
}
return bValid;
}]]>
</javascript>
</validator>
...
Related
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index:
62, Size: 62
I can't fix this annoying error. I use indexes = size of List but have this exception
import java.io.File
fun main(args: Array<String>) {
fun markdownToHtmlSimple(inputName: String) {
val writer = File("out.txt").bufferedWriter()
val str = File(inputName).readLines()
var countTagI = 0
var countTagB = 0
var countTagS = 0
var openedTagI = false
var openedTagB = false
var openedTagS = false
writer.write("<html>\n\t<body>\n\t\t<p>")
for (i in 0..str.size) {
if (str[i] == "") writer.newLine()
else {
Regex("""\*\*""").replace(str[i], "☺") //временная замена для облегчения поиcка
Regex("""\~\~""").replace(str[i], "☻") //аналогично
val currentStr = str[i].toList()
for (j in 0..currentStr.size) {
when {
currentStr[j] == '*' -> countTagI++
currentStr[j] == '☺' -> countTagB++
currentStr[j] == '☻' -> countTagS++
}
}
if ((countTagB % 2 == 0) && (countTagI % 2 == 0) && (countTagS % 2 == 0)) for (j in 0..currentStr.size) {
when {
(currentStr[j] == '*') && !openedTagI -> {
writer.write("<i>")
openedTagI = true
}
(currentStr[j] == '*') && openedTagI -> {
writer.write("</i>")
openedTagI = false
}
(currentStr[j] == '☺') && !openedTagB -> {
writer.write("<b>")
openedTagI = true
}
(currentStr[j] == '☺') && openedTagB -> {
writer.write("</b>")
openedTagI = false
}
(currentStr[j] == '☻') && !openedTagS -> {
writer.write("<s>")
openedTagS = true
}
(currentStr[j] == '☻') && openedTagS -> {
writer.write("</s>")
openedTagS = false
}
else -> writer.write(currentStr[j].toString())
}
}
}
}
}
markdownToHtmlSimple("input.txt")
}
I use only three constructions for and they are limited with size of Arrays
Please help where is my error?
Replace
0..str.size
with
0 until str.size
I am trying to have pull the DisplayAttribute and the DescriptionAttribute from parts of the Swagger Model. For example I may have a Body Parameter which has properties with attributes, which I would also want to be generated in the swagger.json and visible in SwaggerUI.
So far I think the approach that should work would be using a custom filter with swashbuckle. I got a proof of concept using the IParameterFilter which displays the description attribute, not sure if another filter would be better.
Issues:
Finding the key for the schemaRegistry fails for some types, like list.
Need to get the key for the parameter to be generated the same as swagger.
Might need recursion to loop through child properties that contain complex objects.
public class SwaggerParameterFilter : IParameterFilter
{
private SchemaRegistrySettings _settings;
private SchemaIdManager _schemaIdManager;
public SwaggerParameterFilter(SchemaRegistrySettings settings = null)
{
this._settings = settings ?? new SchemaRegistrySettings();
this._schemaIdManager = new SchemaIdManager(this._settings.SchemaIdSelector);
}
public void Apply(IParameter parameter, ParameterFilterContext context)
{
try
{
if (context.ApiParameterDescription?.ModelMetadata?.Properties == null) return;
if (parameter is BodyParameter bodyParameter)
{
string idFor = _schemaIdManager.IdFor(context.ApiParameterDescription.Type);
var schemaRegistry = (SchemaRegistry)context.SchemaRegistry;
//not perfect, crashes with some cases
var schema = schemaRegistry.Definitions[idFor];
//bodyParameter.Schema, this doesn't seem right, no properties
foreach (var modelMetadata in context.ApiParameterDescription.ModelMetadata.Properties)
{
if (modelMetadata is DefaultModelMetadata defaultModelMetadata)
{
//not sure right now how to get the right key for the schema.Properties...
var name = defaultModelMetadata.Name;
name = Char.ToLowerInvariant(name[0]) + name.Substring(1);
if (schema.Properties.ContainsKey(name))
{
var subSchema = schema.Properties[name];
var attributes = defaultModelMetadata.Attributes.Attributes.Select(x => (Attribute)x);
var descriptionAttribute = (DescriptionAttribute)attributes.FirstOrDefault(x => x is DescriptionAttribute);
if (descriptionAttribute != null)
subSchema.Description = descriptionAttribute.Description;
}
}
}
}
}
catch (Exception e)
{
//eat because above is broken
}
}
}
Edit add looping.
public class SwaggerParameterFilter : IParameterFilter
{
private SchemaRegistrySettings _settings;
private SchemaIdManager _schemaIdManager;
public SwaggerParameterFilter(SchemaRegistrySettings settings = null)
{
this._settings = settings ?? new SchemaRegistrySettings();
this._schemaIdManager = new SchemaIdManager(this._settings.SchemaIdSelector);
}
public void Apply(IParameter parameter, ParameterFilterContext context)
{
try
{
if (context.ApiParameterDescription?.ModelMetadata?.Properties == null) return;
//Only BodyParameters are complex and stored in the schema
if (parameter is BodyParameter bodyParameter)
{
var idFor = _schemaIdManager.IdFor(context.ApiParameterDescription.Type);
//not perfect, crashes with some cases
var schema = context.SchemaRegistry.Definitions[idFor];
UpdateSchema(schema, (SchemaRegistry) context.SchemaRegistry, context.ApiParameterDescription.ModelMetadata);
}
}
catch (Exception e)
{
//eat because above is broken
}
}
private void UpdateSchema(Schema schema, SchemaRegistry schemaRegistry, ModelMetadata modelMetadata)
{
if (schema.Ref != null)
{
var schemaReference = schema.Ref.Replace("#/definitions/", "");
UpdateSchema(schemaRegistry.Definitions[schemaReference], schemaRegistry, modelMetadata);
return;
}
if (schema.Properties == null) return;
foreach (var properties in modelMetadata.Properties)
{
if (properties is DefaultModelMetadata defaultModelMetadata)
{
//not sure right now how to get the right key for the schema.Properties...
var name = defaultModelMetadata.Name;
name = Char.ToLowerInvariant(name[0]) + name.Substring(1);
if (schema.Properties.ContainsKey(name) == false) return;
var subSchema = schema.Properties[name];
var attributes = defaultModelMetadata.Attributes.Attributes.Select(x => (Attribute) x).ToList();
var descriptionAttribute =
(DescriptionAttribute) attributes.FirstOrDefault(x => x is DescriptionAttribute);
if (descriptionAttribute != null)
subSchema.Description = descriptionAttribute.Description;
var displayAttribute = (DisplayAttribute) attributes.FirstOrDefault(x => x is DisplayAttribute);
if (displayAttribute != null)
subSchema.Title = displayAttribute.Name;
if (modelMetadata.ModelType.IsPrimitive) return;
UpdateSchema(subSchema, schemaRegistry, defaultModelMetadata);
}
}
}
}
Operation Filter
public class SwaggerOperationFilter : IOperationFilter
{
private SchemaRegistrySettings _settings;
private SchemaIdManager _schemaIdManager;
private IModelMetadataProvider _metadataProvider;
public SwaggerOperationFilter(IModelMetadataProvider metadataProvider, SchemaRegistrySettings settings = null)
{
this._metadataProvider = metadataProvider;
this._settings = settings ?? new SchemaRegistrySettings();
this._schemaIdManager = new SchemaIdManager(this._settings.SchemaIdSelector);
}
public void Apply(Operation operation, OperationFilterContext context)
{
try
{
foreach (var paramDescription in context.ApiDescription.ParameterDescriptions)
{
if (paramDescription?.ModelMetadata?.Properties == null)
{
continue;
}
if (paramDescription.ModelMetadata.ModelType.IsPrimitive)
{
continue;
}
if (paramDescription.ModelMetadata.ModelType == typeof(string))
{
continue;
}
var idFor = _schemaIdManager.IdFor(paramDescription.Type);
var schema = context.SchemaRegistry.Definitions[idFor];
UpdateSchema(schema, (SchemaRegistry)context.SchemaRegistry, paramDescription.ModelMetadata);
}
}
catch (Exception e)
{
//eat because above is broken
}
}
private void UpdateSchema(Schema schema, SchemaRegistry schemaRegistry, ModelMetadata modelMetadata)
{
if (schema.Ref != null)
{
var schemaReference = schema.Ref.Replace("#/definitions/", "");
UpdateSchema(schemaRegistry.Definitions[schemaReference], schemaRegistry, modelMetadata);
return;
}
if (schema.Type == "array")
{
if (schema.Items.Ref != null)
{
var schemaReference = schema.Items.Ref.Replace("#/definitions/", "");
var modelTypeGenericTypeArgument = modelMetadata.ModelType.GenericTypeArguments[0];
modelMetadata = _metadataProvider.GetMetadataForType(modelTypeGenericTypeArgument);
UpdateSchema(schemaRegistry.Definitions[schemaReference], schemaRegistry, modelMetadata);
}
return;
}
if (schema.Properties == null) return;
foreach (var properties in modelMetadata.Properties)
{
if (properties is DefaultModelMetadata defaultModelMetadata)
{
//not sure right now how to get the right key for the schema.Properties...
var name = defaultModelMetadata.Name;
name = Char.ToLowerInvariant(name[0]) + name.Substring(1);
if (schema.Properties.ContainsKey(name) == false) return;
var subSchema = schema.Properties[name];
var attributes = defaultModelMetadata.Attributes.Attributes.Select(x => (Attribute)x).ToList();
var descriptionAttribute =
(DescriptionAttribute)attributes.FirstOrDefault(x => x is DescriptionAttribute);
if (descriptionAttribute != null)
subSchema.Description = descriptionAttribute.Description;
var displayAttribute = (DisplayAttribute)attributes.FirstOrDefault(x => x is DisplayAttribute);
if (displayAttribute != null)
subSchema.Title = displayAttribute.Name;
if (defaultModelMetadata.ModelType.IsPrimitive) return;
UpdateSchema(subSchema, schemaRegistry, defaultModelMetadata);
}
}
}
}
So after some troubleshooting this seems to work for me but may need modification for other cases.
public class SwashbuckleAttributeReaderDocumentFilter : IDocumentFilter
{
private readonly SchemaIdManager _schemaIdManager;
private readonly IModelMetadataProvider _metadataProvider;
private List<string> _updatedSchemeList;
public SwashbuckleAttributeReaderDocumentFilter(IModelMetadataProvider metadataProvider, SchemaRegistrySettings settings = null)
{
_metadataProvider = metadataProvider;
var registrySettings = settings ?? new SchemaRegistrySettings();
_schemaIdManager = new SchemaIdManager(registrySettings.SchemaIdSelector);
}
public void Apply(SwaggerDocument swaggerDoc, DocumentFilterContext context)
{
_updatedSchemeList = new List<string>();
foreach (var apiDescription in context.ApiDescriptions)
{
foreach (var responseTypes in apiDescription.SupportedResponseTypes)
{
ProcessModelMetadata(context, responseTypes.ModelMetadata);
}
foreach (var paramDescription in apiDescription.ParameterDescriptions)
{
ProcessModelMetadata(context, paramDescription.ModelMetadata);
}
}
}
private void ProcessModelMetadata(DocumentFilterContext context, ModelMetadata currentModelMetadata)
{
if (currentModelMetadata?.Properties == null)
{
return;
}
if (currentModelMetadata.ModelType.IsValueType)
{
return;
}
if (currentModelMetadata.ModelType == typeof(string))
{
return;
}
if (currentModelMetadata.ModelType.IsGenericType)
{
foreach (var modelType in currentModelMetadata.ModelType.GenericTypeArguments)
{
var modelMetadata = _metadataProvider.GetMetadataForType(modelType);
UpdateSchema(context.SchemaRegistry, modelMetadata);
}
}
else if (currentModelMetadata.IsCollectionType)
{
var modelType = currentModelMetadata.ModelType.GetElementType();
var modelMetadata = _metadataProvider.GetMetadataForType(modelType);
UpdateSchema(context.SchemaRegistry, modelMetadata);
}
else
{
UpdateSchema(context.SchemaRegistry, currentModelMetadata);
}
}
public static void SetSchema(Schema schema, ModelMetadata modelMetadata)
{
if (!(modelMetadata is DefaultModelMetadata metadata)) return;
var attributes = GetAtributes(metadata);
SetDescription(attributes, schema);
SetTitle(attributes, schema);
}
private static List<Attribute> GetAtributes(DefaultModelMetadata modelMetadata)
{
return modelMetadata.Attributes.Attributes.Select(x => (Attribute)x).ToList();
}
private static void SetTitle(List<Attribute> attributes, Schema schema)
{
//LastOrDefault because we want the attribute from the dervived class.
var displayAttribute = (DisplayNameAttribute)attributes.LastOrDefault(x => x is DisplayNameAttribute);
if (displayAttribute != null)
schema.Title = displayAttribute.DisplayName;
}
private static void SetDescription(List<Attribute> attributes, Schema schema)
{
//LastOrDefault because we want the attribute from the dervived class. not sure if this works.
var descriptionAttribute = (DescriptionAttribute)attributes.LastOrDefault(x => x is DescriptionAttribute);
if (descriptionAttribute != null)
schema.Description = descriptionAttribute.Description;
}
private void UpdateSchema(ISchemaRegistry schemaRegistry, ModelMetadata modelMetadata, Schema schema = null)
{
if (modelMetadata.ModelType.IsValueType) return;
if (modelMetadata.ModelType == typeof(string)) return;
var idFor = _schemaIdManager.IdFor(modelMetadata.ModelType);
if (_updatedSchemeList.Contains(idFor))
return;
if (schema == null || schema.Ref != null)
{
if (schemaRegistry.Definitions.ContainsKey(idFor) == false) return;
schema = schemaRegistry.Definitions[idFor];
}
_updatedSchemeList.Add(idFor);
SetSchema(schema, modelMetadata);
if (schema.Type == "array")//Array Schema
{
var metaData = _metadataProvider.GetMetadataForType(modelMetadata.ModelType.GenericTypeArguments[0]);
UpdateSchema(schemaRegistry, metaData);
}
else//object schema
{
if (schema.Properties == null)
{
return;
}
foreach (var properties in modelMetadata.Properties)
{
if (!(properties is DefaultModelMetadata defaultModelMetadata))
{
continue;
}
var name = ToLowerCamelCase(defaultModelMetadata.Name);
if (schema.Properties.ContainsKey(name) == false)
{
//when this doesn't match the json object naming.
return;
}
var subSchema = schema.Properties[name];
SetSchema(subSchema, defaultModelMetadata);
UpdateSchema(schemaRegistry, defaultModelMetadata, subSchema);
}
}
}
private static string ToLowerCamelCase(string inputString)
{
if (inputString == null) return null;
if (inputString == string.Empty) return string.Empty;
if (char.IsLower(inputString[0])) return inputString;
return inputString.Substring(0, 1).ToLower() + inputString.Substring(1);
}
}
I made A Maze and Action script 3.0 and everything works except when the player touches the exit box (a movie clip called exit) the maze wont go to my win screen.
If someone could help me that'd be great because this is a final project for school
here's my code
var rightArrow:Boolean = false;
var leftArrow:Boolean = false;
var upArrow:Boolean = false;
var downArrow:Boolean = false;
var speed:int = 5;
stage.addEventListener(KeyboardEvent.KEY_DOWN, stage_onKeyDown);
stage.addEventListener(KeyboardEvent.KEY_UP, stage_onKeyUp);
stage.addEventListener(Event.ENTER_FRAME, stage_onEnterFrame);
function stage_onKeyDown(event:KeyboardEvent):void {
if(event.keyCode == Keyboard.RIGHT) rightArrow = true;
if(event.keyCode == Keyboard.LEFT) leftArrow = true;
if(event.keyCode == Keyboard.UP) upArrow = true;
if(event.keyCode == Keyboard.DOWN) downArrow = true;
}
function stage_onKeyUp(event:KeyboardEvent):void {
if(event.keyCode == Keyboard.RIGHT) rightArrow = false;
if(event.keyCode == Keyboard.LEFT) leftArrow = false;
if(event.keyCode == Keyboard.UP) upArrow = false;
if(event.keyCode == Keyboard.DOWN) downArrow = false;
}
function stage_onEnterFrame(event:Event):void {
var rect:Rectangle = player.getBounds(this);
var i:int = 0;
var xBump:int = 0;
var yBump:int = 0;
if(rightArrow) {
xBump = speed;
for(i = 0; i < speed; i++) {
if(maze.hitTestPoint(rect.right + i, player.y, true)) {
xBump = i - 1;
break;
}
}
}
if(leftArrow) {
xBump = -speed;
for(i = 0; i < speed; i++) {
if(maze.hitTestPoint(rect.left - i, player.y, true)) {
xBump = -i + 1;
break;
}
}
}
if(upArrow) {
yBump = -speed;
for(i = 0; i < speed; i++) {
if(maze.hitTestPoint(player.x, rect.top - i, true)) {
yBump = -i + 1;
break;
}
}
}
if(downArrow) {
yBump = speed;
for(i = 0; i < speed; i++) {
if(maze.hitTestPoint(player.x, rect.bottom + i, true)) {
yBump = i - 1;
break;
}
}
}
player.x += xBump;
player.y += yBump;
}
if(player.hitTestObject(exit)) {
gotoAndStop("win");
}
stop();
Your test:
if(player.hitTestObject(exit)) {
gotoAndStop("win");
}
appears to be outside the function stage_onEnterFrame and is thus only executed once. Make sure the closing brace of the function:
player.x += xBump;
player.y += yBump;
} // this one
Comes after the test, like so:
}
player.x += xBump;
player.y += yBump;
if(player.hitTestObject(exit)) {
gotoAndStop("win");
}
} // closing function here, NOT above
Please Guys, I have a forum and I want users to be able to reply comments so that the reply would appear with the comment.
This is what I have:
public ActionResult Quote(int? id)
{
var user = User.Identity.Name;
var userId = WebSecurity.CurrentUserId;
//var userId = db.UserProfiles.FirstOrDefault(x => x.UserName == user).UserId;
if (User.Identity.Name == null)
{
return RedirectToAction("Login", "Account");
}
if (id == null)
{
return RedirectToAction("topics", "forum");
}
//var p = db.Posts.FirstOrDefault(x => x.PostId == id.Value);
var post = db.Posts.Find(id.Value);
var comment = db.UserComments.FirstOrDefault();
var usercomment = db.UserComments.Find(comment.UserCommentId);
if (usercomment == null)
{
return RedirectToAction("topics");
}
return View(new Quote { UserId = WebSecurity.CurrentUserId, PostId = id.Value, UserCommentId = usercomment.UserCommentId });
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Quote(Quote quote, int id = 0)
{
if (ModelState.IsValid)
{
if (Request.Files.Count > 0)
{
System.Random randomInteger = new System.Random();
int genNumber = randomInteger.Next(1000000);
HttpPostedFileBase file = Request.Files[0];
if (file.ContentLength > 0 && file.ContentType.ToUpper().Contains("JPEG") || file.ContentType.ToUpper().Contains("PNG") || file.ContentType.ToUpper().Contains("JPG"))
{
WebImage img = new WebImage(file.InputStream);
if (img.Width > 500)
{
img.Resize(width: 500, height: 400, preserveAspectRatio: true, preventEnlarge: true);
}
if (img.Height > 700)
{
img.Resize(width: 500, height: 400, preserveAspectRatio: true, preventEnlarge: true);
}
string fileName = Path.Combine(Server.MapPath("~/Uploads/"), Path.GetFileName(genNumber + file.FileName));
img.Save(fileName);
if (fileName == null)
{
ViewBag.image = "True";
}
quote.QuoteFile = fileName;
}
}
var user = WebSecurity.CurrentUserId;
//var userId = db.UserProfiles.FirstOrDefault(a => a.UserId == user);
db.Quotes.Add(quote);
quote.QuotedBy = User.Identity.Name;
var post = db.Quotes.Include(f => f.Posts).Where(x=>x.UserCommentId == quote.UserCommentId).OrderByDescending(s => s.QuoteId);
quote.DateQuoted = DateTime.Now;
db.SaveChanges();
return RedirectToAction("topics", "forum", new { id = quote.PostId});
}
return View(quote);
}
public ActionResult _Quote(int id = 0)
{
//var comment = db.UserComments.FirstOrDefault(x => x.PostId == id);
var user = WebSecurity.CurrentUserId;
var comments = db.Quotes.Where(x => x.PostId == id).ToList();
//var quotes = db.UserComments.Where(x => x.PostId == id).ToList();
var p = new UserComment();
p.DateUserCommented = DateTime.Now;
DateTime dt = Convert.ToDateTime(p.DateUserCommented);
string strDate = dt.ToString("dd MMMM yyyy - hh:mm tt");
ViewBag.p = strDate;
ViewBag.data = comments;
return PartialView(comments);
}
I am making a web application in asp.net with MVC 4 and i'm trying to show the user twitter home feed. To get the user home feed i'm using twitterizer2. Everything work fine and i have the user home feed and the feed photo link but it doesn't display in the browser. If i open the picture link from the browser address bar it is displayed and also if i use another photo link not related with twitter everything works fine. So i'm guessing it has something to do with twitter.
My view is this:
<div class="NoBullets" style="font-size:#Model.TextSize">
<ul style="list-style-type:none">
#foreach (var status in Model.TStatusCollection)
{
<li>
<img src=#status.User.ProfileImageLocation style="float:left" width="48" height="48" align="bottom"> #status.Text<br />
#string.Format("{0:dd MMMM yyyy} {0:H:mm}", status.CreatedDate)
</li>
}
</ul>
</div>
And the model:
public class PortletMyTwitter : PortletBase
{
private int noOfTweets = 15;
private string textSize = "medium";
private string userExtAppID;
private TwitterStatusCollection tStatusCollection;
private IList<object> noOfTweetsList = new List<object>()
{
new {value = 5},
new {value = 10},
new {value = 15},
new {value = 20},
new {value = 25}
};
private IList<object> textSizeList = new List<object>()
{
new {value = "small"},
new {value = "medium"},
new {value = "large"}
};
public string UserExtAppID
{
get { return userExtAppID; }
set { userExtAppID = value; }
}
public IList<object> NoOfTweetsList
{
get { return noOfTweetsList; }
}
public int NoOfTweets
{
get { return noOfTweets; }
set { noOfTweets = value; }
}
public IList<object> TextSizeList
{
get { return textSizeList; }
}
public string TextSize
{
get { return textSize; }
set { textSize = value; }
}
public TwitterStatusCollection TStatusCollection
{
get { return tStatusCollection; }
}
public void GetSettings(XmlDocument xmlPortletState)
{
if (xmlPortletState.GetElementsByTagName("UserExtAppID").Count > 0)
{
if (xmlPortletState.GetElementsByTagName("UserExtAppID")[0].FirstChild != null)
UserExtAppID = ((System.Xml.XmlText)(xmlPortletState.GetElementsByTagName("UserExtAppID")[0]).FirstChild).Value;
}
if (xmlPortletState.GetElementsByTagName("HideHeader").Count > 0)
{
if (xmlPortletState.GetElementsByTagName("HideHeader")[0].FirstChild != null)
HideHeader = bool.Parse(((System.Xml.XmlText)(xmlPortletState.GetElementsByTagName("HideHeader")[0]).FirstChild).Value);
}
if (xmlPortletState.GetElementsByTagName("TextSize").Count > 0)
{
if (xmlPortletState.GetElementsByTagName("TextSize")[0].FirstChild != null)
try
{
TextSize = ((System.Xml.XmlText)(xmlPortletState.GetElementsByTagName("TextSize")[0]).FirstChild).Value;
}
catch
{
TextSize = "medium";
}
}
if (xmlPortletState.GetElementsByTagName("NoOfTweets").Count > 0)
{
if (xmlPortletState.GetElementsByTagName("NoOfTweets")[0].FirstChild != null)
try
{
NoOfTweets = Convert.ToInt32(((System.Xml.XmlText)(xmlPortletState.GetElementsByTagName("NoOfTweets")[0]).FirstChild).Value);
}
catch
{
NoOfTweets = 10;
}
}
UpdateFeed();
}
protected void UpdateFeed()
{
try
{
OAuthTokens oauthTokens = new OAuthTokens()
{
AccessToken = "",
AccessTokenSecret = "",
ConsumerKey = "",
ConsumerSecret = ""
};
TimelineOptions myOptions = new TimelineOptions();
myOptions.IncludeRetweets = false;
myOptions.UseSSL = true;
myOptions.APIBaseAddress = "https://api.twitter.com/1.1/";
myOptions.Count = NoOfTweets;
TwitterResponse<TwitterStatusCollection> twitterDataSource = TwitterTimeline.HomeTimeline(oauthTokens, myOptions);
tStatusCollection = twitterDataSource.ResponseObject;
}
catch (Exception)
{
}
}
}