I am beginning to use the google data API (specifically for the finance app). I can read my portfolio's just fine, so I am authenticating correctly (or so I think). However, when I try and create a portfolio, I get a 'feed is read-only' error. The constructor for the service:
public class FinanceService : Service, IService
{
public FinanceService(string applicationName)
: base ("finance", applicationName)
{
this.RequestFactory = new GDataGAuthRequestFactory("finance", applicationName) { ProtocolMajor = 3 };
}
}
and saving it is
private const string _schema = "http://schemas.google.com/finance/2007";
private const string _feed = "http://finance.google.com/finance/feeds/default/portfolios";
AtomFeed atomFeed = new AtomFeed(new Uri(_feed), this.FinanceService);
return this.FinanceService.Insert(atomFeed, this as AtomEntry) as PortfolioEntry;
Any idea why the atomFeed would come back ReadOnly? The credentials are legit, and I can get my current portfolios without a problem.
Related
I'm making some dApp using Unity & Nethereum.
I deployed one contract to the Ropsten Test Net using Remix. And I had abi & bytecode of that, so I made Definition & Service C# code using solodity package of VS Code.
I wanted to mint new NFT, and below is the code that I tried.
string url = "my infura - ropsten url";
string privateKey = "private Key of my MetaMask account";
string userAddress = "public address of my MetaMask account";
string contractAddress = "address of deployed contract";
var account = new Account(privateKey);
var web3 = new Web3(account, url);
var service = new MyNFTService(web3, contractAddress);
var mintReceipt = await service.MintRequestAndWaitForReceiptAsync(userAddress, "address of metadata");
But I can't get receipt even after a long time... Why is this happening? I can't get any answer about that, and I just have to wait.
I have tried everything that I can do, like SendTransactionAndWaitForReceiptAsnyc(), SignAndSendTransaction(), and so on.
The version of Nethereum is 4.1.1, and the version of Unity is 2019.4.21f1.
Below is the part of definition code. (mint)
public partial class MintFunction : MintFunctionBase { }
[Function("mint", "uint256")]
public class MintFunctionBase : FunctionMessage
{
[Parameter("address", "user", 1)]
public virtual string User { get; set; }
[Parameter("string", "tokenURI", 2)]
public virtual string TokenURI { get; set; }
}
And below is the part of service code. (mint)
public Task<string> MintRequestAsync(MintFunction mintFunction)
{
return ContractHandler.SendRequestAsync(mintFunction);
}
public Task<TransactionReceipt> MintRequestAndWaitForReceiptAsync(MintFunction mintFunction, CancellationTokenSource cancellationToken = null)
{
return ContractHandler.SendRequestAndWaitForReceiptAsync(mintFunction, cancellationToken);
}
public Task<string> MintRequestAsync(string user, string tokenURI)
{
var mintFunction = new MintFunction();
mintFunction.User = user;
mintFunction.TokenURI = tokenURI;
return ContractHandler.SendRequestAsync(mintFunction);
}
public Task<TransactionReceipt> MintRequestAndWaitForReceiptAsync(string user, string tokenURI, CancellationTokenSource cancellationToken = null)
{
var mintFunction = new MintFunction();
mintFunction.User = user;
mintFunction.TokenURI = tokenURI;
return ContractHandler.SendRequestAndWaitForReceiptAsync(mintFunction, cancellationToken);
}
I am struggle with this problem for five days... Please help me..
I solved it today! (But I didn't use my service code)
In my opinion, the reason why the transaction didn't work is that the miner can't mine my transaction. (Exactly, they can mine, but they didn't because mining other transaction will give them more money.)
In the document of Netherum, they speak nethereum can set the gas price as the average, but I though it didn't work. After I added a code to estimate and set the gas price, SendRequestAndWaitForReceiptAsync() worked very well. (And I could receive transaction hash.)
Below is the code that I used to solve this problem.
var mintHandler = web3.Eth.GetContractTransactionHandler<MintFunction>();
var mint = new MintFunction()
{
User = userAddress,
TokenURI = "Token URI"
};
mint.GasPrice = Web3.Convert.ToWei(25, UnitConversion.EthUnit.Gwei);
var estimate = await mintHandler.EstimateGasAsync(contractAddress, mint);
mint.Gas = estimate.Value;
var mintReceipt = await mintHandler.SendRequestAndWaitForReceiptAsync(contractAddress, mint);
Debug.Log(mintReceipt.TransactionHash);
I am writing a self-hosting server on .NET based on REST architecture with Nancy(version 1.4.4). I preferred to do self-hosting(Nancy.Hosting.Self is version 1.4.1) and one of requires functionalities is to respond for a request with a video file. To make picture clear, my partner writes React application and he needs this video.
I've tried different options:
First I tried Response.AsFile() but when I try to access it by a link, I get 404 with label "The resource you have requested cannot be found." and I have no idea why...
public class HelloModule : NancyModule
{
public HelloModule()
{
Get["/"] = parameters =>
{
return Response.AsFile(#"C:\7\video112018.mp4","video/mp4");
};
}
}
Second variant was to use GenericFileResponce like in the code below, but it leads to the same problem:
public class HelloModule : NancyModule
{
public HelloModule()
{
Get["/"] = parameters =>
{
GenericFileResponse fileResponse = new GenericFileResponse(#"C:\7\video112018.mp4");
return fileResponse;
};
}
}
Last option I tried was to write directly to response stream like in the code below, but in this case an error "The specified network name is no longer available" occurs. And what makes it tricky is that this error occurs sometimes but I didn't find any dependency where it comes from...
public class HelloModule : NancyModule
{
public HelloModule()
{
Get["/"] = parameters =>
{
return new Response
{
ContentType = "video/mp4",
Contents = s =>
{
String fileName = #"C:\7\video112018.mp4";
using (var stream = new FileStream(fileName, FileMode.Open))
stream.CopyTo(s);
s.Flush();
s.Close();
}
};
};
}
}
I would really appreciate if you have any suggestions about these solutions or give another one.
P. S. I also tried to send an image, it works with third approach but not with first or second
P.P. S. don't judge the code strictly, because it's only an example)
I was able to do very basic streaming of video files by doing this:
Get["/"] = p =>
{
var file = new FileStream(#"PATH_TO_FILE", FileMode.Open);
return new StreamResponse(() => file, "video/mp4");
}
This allowed video files to play, but there was no seeking.
In the end I found this post. Adding these extensions allows for the video to be seeked.
Sorry If i confuse anyone with the question, I am trying hard to make the scenario clear.
Am writing Test Cases for a method that invoke HttpClient Methods.So, I ended up writing following Test Method.
[TestMethod]
public async Task CallComplexRefTypeParamAPI_Get_GetResponseWithParamatersNameValueAppended()
{
#region Arrange
//var resourceURL = #"http://localhost:32662/api/user/ComplexReferenceTypeParamStringResponse";
var resourceURL = #"/api/user/ComplexReferenceTypeParamStringResponse";
var restHelper = new RestHelper(_BaseAddress);
string ParameterKey1 = "VariableStr";
string ParameterValueStr = "Jia";
string ParameterKey2 = "VariableInt";
int ParameterValueInt = 1;
string ParameterKey3 = "VariableBool";
bool ParameterValueBool = true;
string ParameterKey4 = "VariableDateTime";
DateTime ParameterValueDateTime = DateTime.Now;
ComplexRefType ParameterComplexRefType = new ComplexRefType()
{
VariableBool = ParameterValueBool,
VariableDateTime = ParameterValueDateTime,
VariableInt = ParameterValueInt,
VariableStr = ParameterValueStr
};
string result;
#endregion
#region Act
using (WebApp.Start<WebApiStartup>(_BaseAddress))
{
restHelper.AddURLParameters("VariableComplexRef", ParameterComplexRefType);
restHelper.AddURLParameters("DummyStr", "DummyStr");
result = await restHelper.ExecuteAsync<string>(HttpMethod.Get, resourceURL);
}
#endregion
#region Assert
Assert.AreEqual<string>(string.Format("{0}={1}&{2}={3}&{4}={5}&{6}={7}",
ParameterKey1, ParameterValueStr,
ParameterKey2, ParameterValueInt,
ParameterKey3, ParameterValueBool,
ParameterKey4, ParameterValueDateTime), result);
#endregion
}
On other side, I have my Test Controller with following 2 methods.
public string GetMultipleTypeParamStringResponse(string VariableStr, int VariableInt, DateTime VariableDateTime)
{
return string.Format("VariableStr={0}&VariableInt={1}&VariableDateTime={2}", VariableStr, VariableInt, VariableDateTime);
}
public string GetComplexReferenceTypeParamStringResponse([FromUri]ComplexRefType VariableComplexRef, string DummyStr)
{
return string.Format("VariableStr={0}&VariableInt={1}&VariableBool={2}&VariableDateTime={3}",
VariableComplexRef.VariableStr,
VariableComplexRef.VariableInt,
VariableComplexRef.VariableBool,
VariableComplexRef.VariableDateTime);
}
I have the same Controller replicated in an Web API application. If run the test method, pointing to the Self-Hosted API, the application hits "GetMultipleTypeParamStringResponse" instead of "GetComplexReferenceTypeParamStringResponse". However, if I run it against the Web API, it hits the rightful "GetComplexReferenceTypeParamStringResponse" method.
Could someone please help me understand why this behavior ? On both cases, the Query String generated looks to be similar.
Self Hosted
http://localhost:8888/api/user/ComplexReferenceTypeParamStringResponse?VariableStr=Jia&VariableInt=1&VariableBool=True&VariableDateTime=1%2F5%2F2017 3:49:10 PM&DummyStr=DummyStr
Web API
http://localhost:32662/api/user/ComplexReferenceTypeParamStringResponse?VariableStr=Jia&VariableInt=1&VariableBool=True&VariableDateTime=1%2F5%2F2017 3:50:58 PM&DummyStr=DummyStr
Change the routetemplate in your route configuration to
routeTemplate: "api/{controller}/{action}/{id}"
Mark the methods with explicit Route attribute and HttpGet verb like below
[HttpGet]
[Route("api/user/ComplexReferenceTypeParamStringResponse")]
I'm writing an application where, upon receipt of a username, the AD is queried and the information I need is returned. When I write this function just as part of a Windows Forms class, it works perfectly. When I write it as part of a separate class, it fails.
This works
public partial class frmBlockCO : Form
{
public frmBlockCO()
{
InitializeComponent();
}
private void tbId_Leave(object sender, EventArgs e)
{
this.tbName.Text = getADInfo(this.tbId.Text, "displayName");
this.tbBlock.Text = getADInfo(this.tbId.Text, "department");
}
private string getADInfo(string userName, string requestedInfo)
{
DirectoryEntry AD = new DirectoryEntry();
DirectorySearcher ADSearch = new DirectorySearcher(AD);
AD.Username = (string)System.Security.Principal.WindowsIdentity.GetCurrent().Name;
AD.Path = "LDAP://path";
ADSearch.Filter = String.Format("SAMAccountName={0}", userName);
ADSearch.PropertiesToLoad.Add(requestedInfo);
SearchResult result = ADSearch.FindOne();
return (string)result.Properties[requestedInfo][0];
}
}
I put it in it's own class, below, which doesn't work.
static class adSearch
{
public static string getADInfo(string userName, string requestedInfo)
{
DirectoryEntry AD = new DirectoryEntry();
DirectorySearcher ADSearch = new DirectorySearcher(AD);
AD.Username = (string)System.Security.Principal.WindowsIdentity.GetCurrent().Name;
AD.Path = "LDAP://path";
ADSearch.Filter = String.Format("SAMAccountName={0}", userName);
ADSearch.PropertiesToLoad.Add(requestedInfo);
SearchResult result = ADSearch.FindOne();
return (string)result.Properties[requestedInfo][0];
}
}
Now, the weird thing is that when I first took it out of the form and put it into it's own class, it worked fine for a while. It stopped working out of nowhere, and I'm too much of a amateur to figure out why. Now when I run it, I get this:
System.Runtime.InteropServices.COMException was unhandled
ErrorCode -2147024843
HResult -2147024843
Message The network path was not found.
Source System.DirectoryServices
I can run these two programs side by side, and every time, top version works - bottom version doesn't. Exact same LDAP string, exact same system, exact same inputs.
Any help would be appreciated.
I have created a REST Web Service that in all other ways is working how I want it to work.
I have a main class that contains contacts, in that class, there are 2 other lists of classes that I have created.
My main class, and one of the lists comes through the call with all information intact. However, the second class is comming through as empty. It has each item in the list, but each list item is empty.
Web Service Function
[OperationContract]
[WebGet(UriTemplate = "/Login/{IQPid}/{Password}")]
public IQP_Contacts Login(string IQPid, string password)
{
int iqpID = 0;
try
{
iqpID = int.Parse(IQPid);
}
catch { return null; }
IQP_Contacts contact = this.Repository.Contacts.Find(delegate(IQP_Contacts c) { return c.IqpID == iqpID; });
if (contact.Password == password)
{
return contact;
}
else return null;
}
Code calling the web service
WebClient proxy = new WebClient();
byte[] abc = proxy.DownloadData((new Uri("http://localhost:53468/IQP_Service.svc/Login/" + ID + "/" + password )));
Stream strm = new MemoryStream(abc);
DataContractSerializer obj = new DataContractSerializer(typeof(IQP_Contacts));
IQP_Contacts contact = (IQP_Contacts)obj.ReadObject(strm);
As you can see below, my webservice's class contains the information, but the the webpage does not
If anyone has any ideas, Please let me know. I am lost on this one. Something this simple shouldn't be this broken. Thanks
Check out the documentation about DataContractSerializer to see what does and does not get serialized by default:
http://msdn.microsoft.com/en-us/library/cc656732.aspx
It is hard to tell without seeing your classes. But it is possible that your Files property is readonly (only has a get accesser with no set) then it would not get serialized.
It could also depend on if you have selectively applied [DataContract]/[DataMember] attributes on your classes. This affects the behavior of what DataContractSerializer will serialize/deserialize. You would need to indicate that your "Files" property on IQP_RestWebService.Entitys.IQP_Contacts class is marked with a [DataMember] attribute and that you have a [DataContract] on the IQP_RestWebService.Entitys.Files class.