"The name does not exist in the current context" - c#

I get the following error;
The name 'Request' does not exist in the current context
using System;
using System.Web;
using System.Web.UI;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using Microsoft.Exchange.WebServices.Data;
namespace Exchange101
{
// This sample is for demonstration purposes only. Before you run this sample, make sure that the code meets the coding requirements of your organization.
class Ex15_CreateMeetingOnBehalfOfPrinciple_CS
{
static ExchangeService service = Service.ConnectToService(UserDataFromConsole.GetUserData(), new TraceListener());
protected void Page_Load(object sender, EventArgs e)
{
var request = HttpContext.Current.Request.QueryString["source"];
HttpRequest q = Request;
NameValueCollection n = q.QueryString;
if (n.HasKeys())
{
string k = n.GetKey(0);
if (k == "one")
{
string v = n.Get(0);
}
if (k == "two")
{
string v = n.Get(0);
}
}
}
I'm an absolute newbie and have researched the error but am confused as to which assembly I might be missing as a reference.

issue may be here
var request = HttpContext.Current.Request.QueryString["source"];
HttpRequest q = Request;
your variable name is request bt you are using Request
change this as
var request = HttpContext.Current.Request.QueryString["source"];
HttpRequest q = request;
this wil solve your issue

Change this line:
class Ex15_CreateMeetingOnBehalfOfPrinciple_CS
to this:
class Ex15_CreateMeetingOnBehalfOfPrinciple_CS : System.Web.UI.Page
It looks like the problems you're getting are from properties you should be inheriting from that class.

If you are meaning HttpWebRequest, you should include the namespace
using System.Net;

Related

Refresh Page with new data from APi by searchHandler Xamarin C#

I have a question about the function search Handler in xamarin. I am just starting to learn xamarin, and I am trying in my project with search handler in xamarin to refresh my page with new data from the API. Currently, I am already lucky to retrieve the data, but when I do this, it creates a new page so to speak, but this is not what I want. He would kind of reload the page with new data. I have also already tried to delete previous page with "Shell.Current.Navigation.PopAsync();" But with no residual result. Anyone knows how I can achieve what I want? In addition, I would also like to remove that blur you get after the search. Thanks in advance!
using Eindproject.Models;
using Eindproject.Repository;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace Eindproject.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class Weather : ContentPage
{
private string icao = "EBBR";
public Weather()
{
InitializeComponent();
}
public Weather(string icao)
{
InitializeComponent();
this.icao = icao;
frontend(icao);
}
public async void frontend(string par_icao)
{
// Get weather
Models.WeatherModel weather = await DataRepository.GetWeatherAsync(par_icao);
// Set data to labels
lblLocation.Text = weather.Station.Name;
lblCode.Text = weather.Code;
lblTemp.Text = weather.Temperature.C.ToString();
lblHumidity.Text = weather.Humidity.Percent.ToString();
lblWind.Text = weather.Wind.Degrees.ToString();
lblPressure.Text = weather.Presure.Hpa.ToString();
lblDate.Text = weather.Date.ToString("G");
lblMetar.Text = weather.Metar;
lblCloud.Text = weather.Clouds[0].text;
// Get sunrise and sunset
SunTimes sunrise = await DataRepository.GetSunTimesAsync("EHBK");
// Set data to labels
lblSunrise.Text = sunrise.Sunrise.ToString("G");
lblSunset.Text = sunrise.Sunset.ToString("G");
}
private void ToolbarItem_Clicked(object sender, EventArgs e)
{
}
}
public class CustomSearchHandler : SearchHandler
{
// When user press enter and confirm get the icao code and search for the weather
protected override void OnQueryConfirmed()
{
// Get the icao code
string icao = Query;
// Call wheather object
Weather weather = new Weather();
// Call frontend
weather.frontend(icao);
}
}
}
this is creating a new instance of Weather and calling its frontend method. That won't do anything useful.
Weather weather = new Weather();
weather.frontend(icao);
Instead you need to use the existing instance that is already displayed to the user
there are many ways to do this, but this might be the simplest
// get the current page
var page = App.Current.MainPage;
// cast it to the correct type
var weather = (Weather)page;
// call its frontend method
page.frontend(icao);

How to send a simple message using a twilio number with an ASP.NET MVC project?

I am trying to change and edit the code but it returns with exceptions errors in regards authentication errors. The username cannot be null as well as the category is not able to load the code. Another exception that is running on it is the Twilio.Exceptions.ApiExecution that requires a phone number.
The documentation is here: https://www.twilio.com/docs/sms/tutorials/server-notifications-csharp-mvc?code-sample=code-csv-list-of-phone-numbers-to-notify&code-language=csv&code-sdk-version=default
The video to build the code for integrating Twilio in an ASP.net MVC project is here: https://www.youtube.com/watch?v=ndxQXnoDIj8
The code excerpt is here:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Configuration;
using Twilio;
using Twilio.Rest.Api.V2010.Account;
using Twilio.Types;
using Twilio.TwiML;
using Twilio.AspNet.Mvc;
namespace SendandReceiveSms.Controllers
{
public class SMSController : TwilioController
{
// GET: SMS
public ActionResult SendSms()
{
var accountSid = ConfigurationManager.AppSettings["TwilioAccountSid"];
var authToken = ConfigurationManager.AppSettings["TwilioAuthToken"];
TwilioClient.Init("ACa4XXXXXXXXXX","77XXXXXXXXXX");
var to = new PhoneNumber(ConfigurationManager.AppSettings["+65XXXXXXXX"]);
var from = new PhoneNumber("+12053016835");
var message = MessageResource.Create(
to: to,
from: from,
body: "Conserve with us and save the Wolrd ");
return Content(message.Sid);
}
public ActionResult ReceiveSms()
{
var response = new MessagingResponse();
response.Message(" We turn waste into environmental assets");
return TwiML(response);
}
}
}
You can try this also.
using DocGen.Notifications.Contract;
using DocGen.Notifications.Models;
using System;
using System.Configuration;
using System.Linq;
using System.Text;
using Twilio;
using Twilio.Rest.Api.V2010.Account;
using Twilio.Types;
namespace DocGen.Notifications.Providers
{
public class SmsNotificationProvider : INotificationProtocolContract
{
NotificationResponseModel notificationResponseModel = new NotificationResponseModel();
public NotificationResponseModel SendNotification(NotificationRequestModel notificationRequestModel)
{
if (notificationRequestModel.SmsTo == null || notificationRequestModel.SmsTo.Count() == 0)
throw new ArgumentNullException(nameof(notificationRequestModel.SmsTo));
TwilioClient.Init(ConfigurationManager.AppSettings["accountSid"], ConfigurationManager.AppSettings["authToken"]);
foreach (var Sms_to in notificationRequestModel.SmsTo)
{
var to = new PhoneNumber(Sms_to);
var message = MessageResource.Create(
to,
from: new PhoneNumber(ConfigurationManager.AppSettings["senderNumber"]),//"+12563054795"
body: Encoding.UTF8.GetString(notificationRequestModel.Message));
notificationResponseModel.ResponseMessage = message.Status.ToString();
}
//notificationResponseModel.ResponseMessage = "Message Successfully sent.";
return notificationResponseModel;
}
}
}

How do I retrieve a Dictionary data type in a web form?

I have a WCF service that returns a Dictionary object. I have created an ASP .NET Web Application and added a web form to test this service. I have added my WCF service reference in the web application. Now, while writing the code for Button1_Click in web form, I am not able to access the Dictionary object that my service returns. The code is as shown below:
Please suggest a solution asap.
Thanks.
`using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebApplication1.wsHashOps;
namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string input = TextBox1.Text;
Service1 client = new Service1();
string data = "";
Dictionary<int, string> hh = client.getWsHashOperations(input);
string input = TextBox1.Text;
Service1 client = new Service1();
string data = "";
Dictionary<int, string> hh = client.getWsHashOperations(input);
}
}
}
KeyValuePair<int,string>[] hh = client.getWsHashOperations(input);
string input = TextBox1.Text;
Service1 client = new Service1();
string data = "";
KeyValuePair<int,string>[] hh2 = client.getWsHashOperations(input);
You can't declare two variables with the same name. Rename one of them.
Also, looks like it resolves to KeyValuePair arrays based on your error message. Try the above
You can also use the var key word in cases like these
var hh = client.getWsHashOperations(input);
This will resolve the data type for you implicitly, while still maintaining type safety

RallyApi.Net Getting Workspaces from a Subscription Version 2.0

Following this link How to obtain a list of workspaces using Rally REST .NET
I tried the example however when I try to query against sub["Workspaces"] I get the error
RuntimeBinderException was unhandled;
The best overloaded method match for 'Rally.RestApi.RallyRestApi.Query(Rally.RestApi.Request)' has some invalid arguments
I cannot find any other ways to gather a list of workspaces from the subscription using the RallyApi dll for .Net which I obtained from the link provided.
Any help will be much appreciated.
Try to modify that code as follows:
Request wRequest = new Request(sub["Workspaces"]);
QueryResult queryResult = restApi.Query(wRequest);
Here is an entire app:
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using Rally.RestApi;
using Rally.RestApi.Response;
namespace Rest_v2._0_test
{
class Program
{
static void Main(string[] args)
{
//Initialize the REST API
RallyRestApi restApi;
restApi = new RallyRestApi("user#co.com", "secret", "https://rally1.rallydev.com", "v2.0");
//get the current subscription
DynamicJsonObject sub = restApi.GetSubscription("Workspaces");
Request wRequest = new Request(sub["Workspaces"]);
//query the Workspaces collection
QueryResult queryResult = restApi.Query(wRequest);
foreach (var result in queryResult.Results)
{
var workspaceReference = result["_ref"];
var workspaceName = result["Name"];
Console.WriteLine( workspaceName + " " + workspaceReference);
}
}
}
}

StructureMap Exception Code: 202 No Default Instance defined for PluginFamily NServiceBus.IBus, NServiceBus, Version=2.6.0.1504

Ex me,,,
I have a problem in my code,
I want to create POS in my program,,
but i have message error
StructureMap Exception Code: 202 No Default Instance defined for PluginFamily NServiceBus.IBus, NServiceBus, Version=2.6.0.1504, Culture=neutral, PublicKeyToken=9fc386479f8a226
Here my script,,
can anyone help me,,,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Nancy;
using Nancy.Security;
using dokuku.pos.setting;
using StructureMap;
using NServiceBus;
using dokuku.sales.pos.messages;
using System.IO;
using Nancy.IO;
namespace dokuku.pos.web.modules
{
public class PosSettingModule : Nancy.NancyModule
{
public PosSettingModule()
{
this.RequiresAuthentication();
Post["card/addcard.json"] = p =>
{
string addCard = getJson(this.Request.Body);
try
{
POSCard cards = this.CardService().Insert(addCard, this.CurrentAccount().OwnerId);
PublishCardCreated(cards);
return Response.AsJson(cards);
}
catch (Exception ex)
{
return Response.AsJson(new { error = true, message = ex.Message });
}
};
private void PublishCardCreated(POSCard cards)
{
ObjectFactory.GetInstance<IBus>().Publish(new CardCreated()
{
_id = cards._id,
OwnerId = cards.OwnerId,
Code = cards.Code,
Name = cards.Name,
Cost = cards.Cost,
Discount = cards.Discount
});
}
if i running this program and click create button,,
the system sent message error
StructureMap Exception Code: 202 No Default Instance defined for PluginFamily NServiceBus.IBus, NServiceBus, Version=2.6.0.1504, Culture=neutral, PublicKeyToken=9fc386479f8a226c
you need to configure structuremap to use a concrete instance. this is where you would set the configurationsof the bus. An example is in this question

Categories

Resources