How can I add a proxy to my source to exclude filtering?
my file image
public class TeleShrap
{
private WebRequest r;
public event OnMessage NewMessageFromUser;
public event OnMessage NewMessageFromChat;
private bool Start { get; set; }
private long UpdateId { get; set; }
private string addres = "https://api.telegram.org/bot";
public string filepth_addres = "https://api.telegram.org/file/bot";
public string token = string.Empty;
public void StartUpdates()
{
Start = true;
new Task(Updating).Start();
}
The TeleSharp project seems to be abandoned for years now.
I'd suggest you use the Telegram.Bot library. You can find information about adding a proxy on the Wiki.
Related
Im new to System.Net with C#
I want a way to get info from this website api: https://fn-api.glitch.me/api/aes
from its json to a C# string
I have this so far
I don't know how to get each item and where to put the url (im really new to this).
I want the url in a string:
public class Data
{
public string build { get; set; }
public string netCL { get; set; }
public string manifestID { get; set; }
public string aes { get; set; }
}
public class RootObject
{
public Data data { get; set; }
}
Okay, this is how you get about it. I am showing you an example using HttpClient to first read the content from the API and then de-serialize it using Newtonsoft package.
HttpClient class:
public class HttpClientFactory
{
private string webServiceUrl = "https://fn-api.glitch.me/";
public HttpClient CreateClient()
{
var client = new HttpClient();
SetupClientDefaults(client);
return client;
}
protected virtual void SetupClientDefaults(HttpClient client)
{
//This is global for all REST web service calls
client.Timeout = TimeSpan.FromSeconds(60);
client.BaseAddress = new Uri(webServiceUrl);
}
}
Your Model class:
public class Data
{
public string build { get; set; }
public string netCL { get; set; }
public string manifestID { get; set; }
public string aes { get; set; }
}
public class RootObject
{
public Data data { get; set; }
}
Now, you can call this class and create an instance of the HttpClient like this:
public RootObject InvokeAPI()
{
RootObject apiresponse = new RootObject();
string result = string.Empty;
HttpClientFactory clientFactory = new HttpClientFactory();
var client = clientFactory.CreateClient();
HttpResponseMessage response = client.GetAsync("api/aes").Result;
if (response.IsSuccessStatusCode)
{
result = response.Content.ReadAsStringAsync().Result;
apiresponse = JsonConvert.DeserializeObject<RootObject>(result);
}
return apiresponse;
}
Hope this helps you out.
EDIT:
As per your code, you need to call the API on your Button click:
private void metroButton2_Click_1(object sender, EventArgs e)
{
//You need to invoke the API method !!!!
var apiresponse=InvokeAPI();
metroTextBox1.Text = apiresponse.data.aes;
}
Be sure to put try-catch blocks on your code for error handling.
I'd recommend using a 3rd party library like RestSharp. It'll give you a client that's easy to work with and does the converting into objects automatically.
Alternatively you could use the WebClient and download the JSON. Using something like Json.NET allows you to deserialize the JSON into an object.
Easiest way to read from a URL into a string in .NET
I use JSON.Net.
I'm currently working on my final project which contains the use of WCF, WPF and C# and I'm having a hard time transfering an object through wcf.
I get an error after a while which says that the server did not provide a meaningful response.
The classes that are in use in the method that crashes are:
[DataContract]
public class Player
{
//public static int clientID = 0;
[DataMember]
public int Wins { get; set; }
[DataMember]
public int Loses { get; set; }
[DataMember]
public int realID { get; }
[DataMember]
public string nickName { get; set; }
public Player(int Wins, int Loses, string nickName)
{
this.Wins = Wins;
this.Loses = Loses;
this.nickName = nickName;
//clientID++;
realID = 1; //clientID;
}
}
[DataContract]
public class Run
{
[DataMember]
public List<Player> Players { get; set; }
[DataMember]
public bool isActive { get; set; }
public Run()
{
Players = new List<Player>();
}
public void playerJoined(Player player)
{
Players.Add(player);
}
public void playerLeft(Player player)
{
if (Players.Contains(player)) Players.Remove(player);
}
public void generateRun()
{
// TODO: get a random map from the DB and pass it to all players
return;
}
}
and the method that crashes the code is:
public Run getRunDetails(int runNumber)
{
runNumber = runNumber - 1;
return Runs[runNumber];
}
the code at the client side is:
ListBoxItem tempItem = ((ListBoxItem)allRuns.SelectedItem);
if(tempItem != null && !tempItem.Content.Equals("There are no runs available, create one now."))
{
string numString = ((string)tempItem.Content);
numString = numString.Substring(4, numString.Length - 4);
run = Service.getRunDetails(int.Parse(numString));
}
After some time of debugging I've found out the problem is in the list variable, I've tried to change it only to a Player variable -> getting the same error. Same goes for making my buffer and message sizes bigger.
The only way the code wont crash and send my Run object is when the List is not a data member..
//[DataMember]
public List<Player> Players { get; set; }
If I do the above the code works perfectly but I desperately need the List passed to the client side.
Sorry for the long post but I don't have a very long time and I need it done, any help will be very appreciated.
(Also, sorry for the poor formatting, I did my best)
I'm pretty sure the problem here is that you don't have a parameterless constructor in your Player...
try to add a
public Player() {}
to your class...
Either that or because your 'realId' [DataMember] has no setter, see this link for tips on correctly serializing readonly members.
WCF: Exposing readonly DataMember properties without set?
Also, dont forget to 'Update Service Reference' on the WCF Service in the Visual Studio client Project if you have changed members in classes that are passed across the WCF Channel.
I have a DLL written in C#.NET which exposes a COM interface, so a vb6 application can call my DLL. This interface looks like:
[System.Runtime.InteropServices.Guid("3D2C106C-097F-4ED7-9E4F-CDBC6A43BDC4")]
public interface IZDPharmaManager {
[System.Runtime.InteropServices.DispId(2)]
SearchPatientEventArgs FoundPatient { get; set; }
[System.Runtime.InteropServices.DispId(3)]
IntPtr Start(string server, string database, string user, string password, bool integrated, int praktijkID, string userGUID, int userID, string userName, bool hasRightToSearchPatient);
[System.Runtime.InteropServices.DispId(4)]
void Stop();
[System.Runtime.InteropServices.DispId(5)]
void InitializeSkinner(System.Object skinnerFramework);
}
[System.Runtime.InteropServices.Guid("4438852E-CF2D-4DB0-8E6E-428F65A6B16C")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface IZDPharmaManagerEvents {
[DispId(1)]
void SearchPatient(ZDPharmaManager sender, SearchPatientEventArgs e);
}
[System.Runtime.InteropServices.Guid("9297D43F-C581-3F0F-AA60-9506C6B77B5F")]
[ClassInterface(ClassInterfaceType.None)]
public class SearchPatientEventArgs : WebHIS.ZDPharmaceutisch.ISearchPatientEventArgs {
public SearchPatientEventArgs() {
//Nodig voor COM.
}
public int ID { get; set; }
public string FullName { get; set; }
public string OwnName { get; set; }
public string PartnerName { get; set; }
public string DateOfBirth { get; set; }
public string ZipCode { get; set; }
public string HouseNumber { get; set; }
public string BSN { get; set; }
}
public delegate void SearchPatientEventHandler(ZDPharmaManager sender, SearchPatientEventArgs e);
[System.Runtime.InteropServices.Guid("465AC7EC-27EF-3D95-AAA6-29D01FCF15A1")]
[ClassInterface(ClassInterfaceType.None)]
[ComSourceInterfaces(typeof(IZDPharmaManagerEvents))]
public class ZDPharmaManager : WebHIS.ZDPharmaceutisch.IZDPharmaManager {
public event SearchPatientEventHandler SearchPatient = null;
public SearchPatientEventArgs FoundPatient { get; set; }
//private MainForm GraphicalInterface { get; set; }
private ChoosePatient GraphicalInterface { get; set; }
public ZDPharmaManager() {
//Nodig voor COM.
}
#region IZDPharmaManager Members
public IntPtr Start(string server,
string database,
string user,
string password,
bool integrated,
int praktijkID,
string userGUID,
int userID,
string userName,
bool hasRightToSearchPatient) {
//Zet connectiestring.
DAL.DAC.CnnInfo = new System.Data.SqlClient.SqlConnectionStringBuilder() {
DataSource = server,
InitialCatalog = database,
UserID = user,
Password = password,
IntegratedSecurity = integrated
};
DAL.DAC.PracticeID = praktijkID;
DAL.DAC.UserGUID = userGUID;
DAL.DAC.UserID = userID;
DAL.DAC.UserName = userName;
DAL.DAC.HasRightToSearchPatient = hasRightToSearchPatient;
//Apotheek IDs ophalen en bewaren.
DAL.DAC.PharmacyIDs = DAL.PracticeDAO.GetPharmacyByPracticeID(praktijkID);
//Initialiseer grafische interface.
//this.GraphicalInterface = new MainForm();
this.GraphicalInterface = new ChoosePatient();
//Haal ongekoppelde afhaalberichten op.
this.GraphicalInterface.Patients = new VML.PatientsVM(this);
//Toon grafische interface.
this.GraphicalInterface.Show();
return this.GraphicalInterface.Handle;
}
public void Stop() {
foreach (var item in this.SearchPatient.GetInvocationList()) {
this.SearchPatient -= (SearchPatientEventHandler)item;
}
this.GraphicalInterface.Close();
this.GraphicalInterface = null;
this.FoundPatient = null;
}
public void InitializeSkinner(System.Object skinnerFramework) {
WebHIS.ZDPharmaceutisch.SkinnerModule.SkinFramework = (XtremeSkinFramework.SkinFramework)skinnerFramework;
}
#endregion
internal virtual void OnSearchPatient(SearchPatientEventArgs e) {
if (this.SearchPatient != null) {
this.SearchPatient(this, e);
}
}
}
This works fine. But each time I build this DLL without changing the interface (because I had to fix something somewhere in the logic) the reference with the vb6 application is broken and we need to recompile the vb6 application.
Does anyone know what I am doing wrong? 'Cause we had vb.net DLL's which didn't break the reference after recompile due to fixed GUIDs. Any help would be much appreciated.
Update
Both vb6 app and DLL are operational. But when I recompile the DLL and test it on our testserver via the vb6 application I get an automation error (which usually means the reference is broken and you need to recompile the vb6 app aswell)
I don't see any strong leads that could explain this problem. The [Guid] attribute for the assembly matters, that sets the type library ID. And the [AssemblyVersion] matters, that sets the type library version number. The attributes are declared in the project's AssemblyInfo.cs file. Make sure your build system doesn't monkey with these attributes.
Best way to go about it is to find out what exactly changes. Run the OleView.exe utility from the Visual Studio Command Prompt. File + View Typelib and select the .tlb file. Copy/paste the content of the right panel into a text file.
Rebuild the project and repeat the OleView exercise. You can now simply use a diffing tool to see what exactly changed. Update your question with what you found out if you need more help.
This is the first time that I'm doing this, so I need a little bit of help,
I have this code behind:
List<Trucks> FinalListOfTrucks = new List<Trucks>();
public class Trucks
{
public string Placa;
public string Lock;
public string Event;
public DateTime Date;
public string TipoCamion;
public string Person;
public string MissedDate;
}
protected void btnProcess_Click(object sender, EventArgs e)
{
Trucks item = new Trucks();
item.Placa = "MA2323";
item.Lock = "lock1";
item.Event = "Event1";
item.Date = DateTime.Now;
item.TipoCamion = "TRUCK1";
item.Person = "JULIAN";
item.MissedDate = "";
FinalListOfTrucks.Add(item);
gvOriginal.DataSource = FinalListOfTrucks;
gvOriginal.DataBind();
}
in design:
<asp:Button ID="btnProcess" runat="server" Text="Process"
onclick="btnProcess_Click" />
<asp:GridView ID="gvOriginal" runat="server"></asp:GridView>
But trying to run the web app, I'm getting the following error:
The data source for GridView with id 'gvOriginal' did not have any properties or attributes from which to generate columns. Ensure that your data source has content.
Do I have to do anything else, to make this work?
Databinding relies on using properties rather than fields, as the error message you got indicates. You can easily change your code so that Trucks uses properties instead:
public class Trucks
{
public string Placa { get; set; }
public string Lock { get; set; }
public string Event { get; set; }
public DateTime Date { get; set; }
public string TipoCamion { get; set; }
public string Person { get; set; }
public string MissedDate { get; set; }
}
If you make that change everything should work.
Note that there are a number of subtle differences between properties and public fields. A property is effectively syntactic sugar around methods, so public string Placa {get;set;} would be transformed into something similar to:
private string _placa;
public string GetPlaca() { return _placa; }
public void SetPlaca(string value) { _placa = value; }
As for the differences between methods and fields, that's probably beyond the scope of this question.
You can bind to lists gridviews, but your class has to use PROPERTIES, not variables.
public class Trucks
{
public string Placa{get;set;}
public string Lock{get;set;}
public string Event{get;set;}
public DateTime Date{get;set;}
public string TipoCamion{get;set;}
public string Person{get;set;}
public string MissedDate{get;set;}
}
I was created this return from WCF and may i know how could i read the data specifically ??
[DataContract]
public class UserData
{
[DataMember]
public int userID { get; set; }
[DataMember]
public string name { get; set; }
[DataMember]
public string email { get; set; }
[DataMember]
public string contact { get; set; }
[DataMember]
public string status { get; set; }
}
This is WCF side and returning from WCF, i want to read this from Window phone. may i know is there some example ? Thank you for reply
Update
The code in phone part where i want to use the data
private Service1Client _serviceClient;
public Login()
{
InitializeComponent();
_serviceClient = new Service1Client();
_serviceClient.LoginUserCompleted += new EventHandler<LoginUserCompletedEventArgs>(_serviceClient_LoginUserCompleted);
}
private void loginBtn_Click(object sender, RoutedEventArgs e)
{
_serviceClient.LoginUserAsync(txtEmail.Text, txtPassword.Password);
}
private void _serviceClient_LoginUserCompleted(object sender, LoginUserCompletedEventArgs e)
{
if (e.Error == null && e.Result != null)
{
(App.Current as App).MyUserID = 16;
MessageBox.Show("Welcome " + e.Result + "!");
//ContentPanel.Visibility = Visibility.Collapsed;
//Data.Visibility = Visibility.Visible;
//Testing.ItemsSource = e.Result;
Wondering how could i make this few line of code to read the data accordingly, make it into list or can be extract specific data and currently this few lines of codes giving me this answer ::
WCFReference.UserData
}
else
{
MessageBox.Show(e.Error.InnerException.Message + " Couldn't Login, Please try again =D");
}
}
If you are using the SOAP protocol you could either build an WSDL to describe the webservice or you could create the custom class right on the client based on your knowledge of the webservice.
If you are using the REST protocol (Which would be the best alternative for an WP7 Application) you have to create the class on the client based on your knowledge because there are no such thing as WSDL that can describe an REST webservice.
Here is an start for you.
public class UserData
{
public int userID { get; set; }
public string name { get; set; }
public string email { get; set; }
public string contact { get; set; }
public string status { get; set; }
}
Now you just have to parse the response from the webservice request as an UserData class and whoala you are all set.
And as some people pointed out, you can use the webservice as an service reference if you prefer that but sometimes it just messes things up.
You can consume exposed web services by creating service reference (proxy).
Check out following URLs
BLOG
POST
MSDN
LINK