Irony.Net allow two prefixes for variables - c#

I try to use Irony.Net with this syntax:
!!test
!test1
where !!test - global variable
and !test1 - local variable
I wrote this code:
var local_identifier = new IdentifierTerminal("localidentifier","","!");
var global_identifier = new IdentifierTerminal("globalidentifier","","!!");
var param_identifier = new NonTerminal("paramidentifier");
param_identifier.Rule = local_identifier | global_identifier;
and I get shift-reduce error
What I am doing wrong?
With help from codeplex (https://irony.codeplex.com/discussions/546013) i solve the problem.
Result code is:
public static IdentifierTerminal CreateLocalIdentifier(string name)
{
var id = new IdentifierTerminal(name, IdOptions.None);
id.AddPrefix("!", IdOptions.IsNotKeyword);
id.StartCharCategories.AddRange(new[]
{
UnicodeCategory.UppercaseLetter, //Ul
UnicodeCategory.LowercaseLetter, //Ll
UnicodeCategory.TitlecaseLetter, //Lt
UnicodeCategory.ModifierLetter, //Lm
UnicodeCategory.OtherLetter, //Lo
UnicodeCategory.LetterNumber //Nl
});
id.CharCategories.AddRange(new[]
{
UnicodeCategory.DecimalDigitNumber, //Nd
UnicodeCategory.ConnectorPunctuation, //Pc
UnicodeCategory.SpacingCombiningMark, //Mc
UnicodeCategory.NonSpacingMark, //Mn
UnicodeCategory.Format //Cf
});
id.CharsToRemoveCategories.Add(UnicodeCategory.Format);
return id;
}
public static IdentifierTerminal CreateGlobalIdentifier(string name)
{
var id = new IdentifierTerminal(name, IdOptions.None);
id.AddPrefix("!!", IdOptions.IsNotKeyword);
id.StartCharCategories.AddRange(new[]
{
UnicodeCategory.UppercaseLetter, //Ul
UnicodeCategory.LowercaseLetter, //Ll
UnicodeCategory.TitlecaseLetter, //Lt
UnicodeCategory.ModifierLetter, //Lm
UnicodeCategory.OtherLetter, //Lo
UnicodeCategory.LetterNumber //Nl
});
id.CharCategories.AddRange(new[]
{
UnicodeCategory.DecimalDigitNumber, //Nd
UnicodeCategory.ConnectorPunctuation, //Pc
UnicodeCategory.SpacingCombiningMark, //Mc
UnicodeCategory.NonSpacingMark, //Mn
UnicodeCategory.Format //Cf
});
id.CharsToRemoveCategories.Add(UnicodeCategory.Format);
return id;
}

Related

GraphQLClient could not be found

var v = new { email = "test1#yahoo.com", password = "fdsafsdfsdf" };
var request = new GraphQLRequest
{
Query = #"mutation customerCreate($input: CustomerCreateInput!) {
customerCreate(input: $input) {
userErrors {
field
message
}
customer {
id
}
}
}",
Variables = new
{
input = v
}
};
var client = new GraphQLClient("https://kitkatco.myshopify.com/api/graphql");
client.DefaultRequestHeaders.Add("X-Shopify-Storefront-Access-Token", new List<string> { "XXXXXXXXXXXXXXXXXXXXXX" });
var response = await client.PostAsync(request);
When I run this code, it says, GraphQLClient could not be found. So please have a look and let me know which nuggest package should I install?

Using ValueTuple returns Item1,Item2 why?

The next api returns in Postmen and to the client item1,item2
While I am using ValueTuple to change the names (the names not so important, but I can’t return item1,item2)
public async Task<(List<CategoryFilterResponseDTO> categoryFilters, string MetaDataDescription)> GetCategoryFilterPage([FromBody]categoryFilterRequestDTO categoryFilterRequest)
{
var logItem = new LogDTO();
var result = await _service.GetCategoryFilterPage(categoryFilterRequest);
try
{
OnStart(logItem, new object[] { categoryFilterRequest });
var categoryFilters = result.categoryFilters;
var MetaDataDescription = result.MetaDataDescription;
return (categoryFilters: categoryFilters, MetaDataDescription: MetaDataDescription);
}
}
the method:
public async Task<(List<CategoryFilterResponseDTO> categoryFilters, string MetaDataDescription)> GetCategoryFilterPage(categoryFilterRequestDTO categoryFilterRequestDTO)
{
List<CategoryFilterResponseDTO> categoryFilter = new List<CategoryFilterResponseDTO>();
List<FavoriteDTO> isFavorite = null;
string MetaDataDescription = "";
(List<FilterSortDTO<FlatSearchCategory>>, int) searchCategory = await _clubRepo.CategoryFilterPage(categoryFilterRequestDTO);//BranchesCount
if (searchCategory.Item2 == 0)
{
MetaDataDescription = GetCategoryDetails(categoryFilterRequestDTO.CategoryFirstFatherID.Value).CategoryName;
return (categoryFilters: categoryFilter, MetaDataDescription: MetaDataDescription);
}
You can change your return to the following:
return Ok(new
{
categoryFilters = categoryFilter,
metaDataDescription = MetaDataDescription
});
You will need to change your return type to ActionResult or similar as well.
Because that's the name of the fields on a ValueTuple<,>.
The names given to the values are only available to source code.

POST data using POSTMAN

so I've been having trouble using the POST method with C# and POSTMAN.
The GET works pretty fine but I'm getting an error on the POST method.
Here's my code:
public SaveProfileResponseDTO SaveProfileQuery(SaveProfileRequestDTO objProfileRequest)
{
SaveProfileResponseDTO objSaveProfileResponse;
try
{
XElement xElement = XElement.Load(Path);
XElement Student = (from u in xElement.Elements("Student")
where (string)u.Attribute("id") == objProfileRequest.StudentID.ToString()
select (u)).FirstOrDefault();
Student.Element("Name").Value = objProfileRequest.Name;
Student.Element("Gender").Value = objProfileRequest.Gender;
xElement.Save(Path);
objSaveProfileResponse = new SaveProfileResponseDTO()
{
Status = new ResponseCode()
{
Code = StatusCodes.Success,
Message = StatusMessages.Success
}
};
}
catch (Exception ex)
{
objSaveProfileResponse = new SaveProfileResponseDTO()
{
Status = new ResponseCode()
{
Code = StatusCodes.Error,
Message = StatusMessages.Error
}
};
}
return objSaveProfileResponse;
}
This is my Controller:
[Route("Profile")]
[HttpPost]
public HttpResponseMessage Profile(SaveProfileRequestModel objSaveProfileRequestModel)
{
StudentManager = new StudentManager();
SaveProfileRequestDTO objSaveProfileRequestDTO = new SaveProfileRequestDTO()
{
Gender = objSaveProfileRequestModel.Gender,
Name = objSaveProfileRequestModel.Name,
StudentID = objSaveProfileRequestModel.StudentID
};
SaveProfileResponseDTO objSavePofileResponse = StudentManager.SaveProfile(objSaveProfileRequestDTO);
SaveProfileResponseModel objSaveProfileResponseModel = new SaveProfileResponseModel()
{
Status = objSavePofileResponse.Status
};
return Request.CreateResponse(HttpStatusCode.OK, objSavePofileResponse);
}
Any help would be appreciated.
I can also provide the GET method code if you want.
Thank you in advance.
XElement Student = (from u in xElement.Elements("Student")
where (string)u.Attribute("id") == objProfileRequest.StudentID.ToString()
select (u)).FirstOrDefault();
Student.Element("Name").Value = objProfileRequest.Name;
This last line will cause a NullReferenceException if there is no student in the XML file matching the ID you're passing in.

Sony Camera API with C#

I have asked a previous question on SO with regards to the Sony Camera API and I did get some help but I am still having a problem. I found the following library https://github.com/kazyx/kz-remote-api that someone made to use with the Sony Camera API but I had to make changes to it to work with a WPF app as it was optimized for windows store apps.
I am now resorting to do everything myself but I am unsure if I need to attach a Camera API file to my solution and if I do where can I find the exact file because the one the API file that I downloaded only has files for Android and iOS in which won't help me.
I finally got my thing working and I tried to put it in such a manner so that it is easily understandable. If anyone would like my Sony Library that I wrote that please let me know as I also tried the Kazyx library and that didn't work for me.
My code is below.
private string cameraURL;
private bool recModeActive;
public void ControlCamera(string cameraResp)
{
cameraURL = string.Format("{0}/{1}", GetCameraURL(cameraResp), GetActionType(cameraResp));
}
private string CameraRequest(string cameraUrl, string cameraRequest)
{
Uri urlURI = new Uri(cameraURL);
HttpWebRequest cameraReq = (HttpWebRequest)WebRequest.Create(cameraURL);
cameraReq.Method = "POST";
cameraReq.AllowWriteStreamBuffering = false;
cameraReq.ContentType = "application/json; charset=utf-8";
cameraReq.Accept = "Accept-application/json";
cameraReq.ContentLength = cameraRequest.Length;
using (var cameraWrite = new StreamWriter(cameraReq.GetRequestStream()))
{
cameraWrite.Write(cameraRequest);
}
var cameraResp = (HttpWebResponse)cameraReq.GetResponse();
Stream cameraStream = cameraResp.GetResponseStream();
StreamReader cameraRead = new StreamReader(cameraStream);
string readCamera = cameraRead.ReadToEnd();
return readCamera;
}
public string GetCameraURL(string cameraResp)
{
string[] cameraXML = cameraResp.Split('\n');
string cameraURL = "";
foreach (string cameraString in cameraXML)
{
string getCameraURL = "";
if (cameraString.Contains("<av:X_ScalarWebAPI_ActionList_URL>"))
{
getCameraURL = cameraString.Substring(cameraString.IndexOf('>') + 1);
cameraURL = getCameraURL.Substring(0, getCameraURL.IndexOf('<'));
}
}
return cameraURL;
}
public string GetActionType(string cameraResp)
{
string[] cameraXML = cameraResp.Split('\n');
string actionType = "";
foreach (string cameraString in cameraXML)
{
string getType = "";
if (cameraString.Contains("<av:X_ScalarWebAPI_ServiceType>"))
{
getType = cameraString.Substring(cameraString.IndexOf('>') + 1);
actionType = getType.Substring(0, getType.IndexOf('<'));
if (actionType == "camera")
{
break;
}
}
}
return actionType;
}
public string StartRecMode()
{
string startRecMode = JsonConvert.SerializeObject(new Camera.CameraSetup
{
method = "startRecMode",
#params = new List<string> { },
id = 1,
version = "1.0"
});
recModeActive = true;
return CameraRequest(cameraURL, startRecMode);
}
public string TriggerCamera()
{
string _triggerCamera = JsonConvert.SerializeObject(new Camera.StillCapture
{
method = "actTakePicture",
#params = new List<string> { },
id = 1,
version = "1.0"
});
return CameraRequest(cameraURL, _triggerCamera);
}
public string EchoRequest()
{
string _echoRequest = JsonConvert.SerializeObject(new Camera.TestCameraComm
{
method = "getEvent",
#params = new List<bool> { true },
id = 1,
version = "1.0"
});
return CameraRequest(cameraURL, _echoRequest);
}
public string StopRecMode()
{
string stopRecMode = JsonConvert.SerializeObject(new Camera.CameraSetup
{
method = "stopRecMode",
#params = new List<string> { },
id = 1,
version = "1.0"
});
recModeActive = false;
return CameraRequest(cameraURL, stopRecMode);
}
public string SetImageQuality()
{
string qualityReq = JsonConvert.SerializeObject(new Camera.CameraSetup
{
method = "setStillSize",
#params = new List<string> { "4:3", "20M"},
id = 1,
version = "1.0"
});
recModeActive = false;
return CameraRequest(cameraURL, qualityReq);
}`

Understanding a java class of a wsdl service

i am trying to write a test code of wsdl web service in java. This code return me some values of variables and have to place an order. Of this code i have en equivalent on C# but i don't understand how to convert in java. This is my code in Java:
package betdaqclient;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.xml.bind.JAXBElement;
public class test
{
public static void main(String[] args)
{
ExternalApiHeader externalAPIHeader = new ExternalApiHeader();
externalAPIHeader.languageCode = "en";
externalAPIHeader.username = "myusername";
externalAPIHeader.password = "mypassword";
externalAPIHeader.version = new BigDecimal ("2.0");
ReadOnlyService_Service ro = new ReadOnlyService_Service();
ReadOnlyService readOnlyService = ro.getReadOnlyService();
SecureService_Service ss = new SecureService_Service();
SecureService secureService = ss.getSecureService();
GetAccountBalancesRequest getAccountBalanceRequest = new GetAccountBalancesRequest();
GetAccountBalancesResponse2 getAccountBalanceResponse = secureService.getAccountBalances(getAccountBalanceRequest, externalAPIHeader);
System.out.printf("%n%nUser : " + externalAPIHeader.username);
System.out.printf("%nBalance : " + getAccountBalanceResponse.balance.toString());
System.out.printf("%nExposure : " + getAccountBalanceResponse.exposure.toString());
System.out.printf("%nAvailable: " + getAccountBalanceResponse.availableFunds.toString()+"%n");
SimpleOrderRequest bet = new SimpleOrderRequest();
bet.selectionId = (long) IdMarket;
bet.polarity = (byte) 1 ; //<-----BACK?
bet.stake = new BigDecimal("1.00") ;
bet.price = new BigDecimal("1.01") ;
bet.cancelOnInRunning = true ;
PlaceOrdersNoReceiptRequest request = new PlaceOrdersNoReceiptRequest();
/* Lacking Code */
PlaceOrdersNoReceiptResponse2 response = secureService.placeOrdersNoReceipt(request,externalAPIHeader);
}
}
I guess that my bet has to be converted in a list and then passed to request. This is the code in C# that i have found in the examples:
public long[] PlaceOrdersNoReceipt(long selectionId, byte polarity, decimal amount
, decimal odds, byte resetCount)
{
SimpleOrderRequest order = new SimpleOrderRequest();
order.SelectionId = selectionId;
order.Polarity = polarity;
order.Stake = amount;
order.Price = odds;
order.ExpectedSelectionResetCount = resetCount;
PlaceOrdersNoReceiptRequest request = new PlaceOrdersNoReceiptRequest();
request.Orders = new SimpleOrderRequest[1] {order};
PlaceOrdersNoReceiptResponse response = _proxy.PlaceOrdersNoReceipt(request);
if (response.ReturnStatus.Code != 0)
throw new Exception(response.ReturnStatus.Description);
return response.OrderHandles;
}
This is the definition of the class built from wsdl:
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "PlaceOrdersNoReceiptRequest", propOrder = {
"orders",
"wantAllOrNothingBehaviour"
})
public class PlaceOrdersNoReceiptRequest {
#XmlElement(name = "Orders", required = true)
protected PlaceOrdersNoReceiptRequest.Orders orders;
#XmlElement(name = "WantAllOrNothingBehaviour")
protected boolean wantAllOrNothingBehaviour;
public PlaceOrdersNoReceiptRequest.Orders getOrders() {return orders;}
public void setOrders(PlaceOrdersNoReceiptRequest.Orders value) {this.orders = value;}
public boolean isWantAllOrNothingBehaviour() { return wantAllOrNothingBehaviour; }
public void setWantAllOrNothingBehaviour(boolean value) {this.wantAllOrNothingBehaviour = value;}
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "", propOrder = {"order"})
public static class Orders {
#XmlElement(name = "Order", required = true)
protected List<SimpleOrderRequest> order;
public List<SimpleOrderRequest> getOrder() {
if (order == null) {
order = new ArrayList<SimpleOrderRequest>();
}
return this.order;
}
}
}
The question is how i have to convert bet element of thee class SimpleOrderRequest into request of the class PlaceOrderNoRecepeit ?
May be a very stupid question but i am a newbie in java programming.
Lacked code should be
PlaceOrdersNoReceiptRequest.Orders orders = new PlaceOrdersNoReceiptRequest.Orders();
orders.getOrder().add(bet);
PlaceOrdersNoReceiptRequest request = new PlaceOrdersNoReceiptRequest();
request.setOrders(orders);

Categories

Resources