/// <summary> /// Process response for request details. /// </summary> /// <param name="strResponse">Response received from request for TOR detail.</param> /// <returns>Response object.</returns> private Response ProcessSwapShiftResponse(string strResponse) { XDocument xDoc = XDocument.Parse(strResponse); var xResponse = xDoc.Root.Descendants().FirstOrDefault(d => d.Name.LocalName.Equals(ApiConstants.Response, StringComparison.Ordinal)); return(XmlConvertHelper.DeserializeObject <Response>(xResponse.ToString())); }
/// <summary> /// Shows punches request /// </summary> /// <param name="personNumber">Person Number</param> /// <param name="startDate">Start Date</param> /// <param name="endDate">End Date</param> /// <param name="payPeriodMonthly">Monthly pay period</param> /// <returns>Punches request string</returns> private string ShowPunchesRequest(string personNumber, string startDate, string endDate) { Request request = new Request { Timesheet = new Models.RequestEntities.Punch.ShowPunches.Timesheet { Employee = new Models.RequestEntities.Punch.ShowPunches.Employee { PersonIdentity = new Models.RequestEntities.Punch.ShowPunches.PersonIdentity { PersonNumber = personNumber } }, Period = new Models.RequestEntities.Punch.ShowPunches.Period { TimeFramePeriod = new Models.RequestEntities.Punch.ShowPunches.TimeFramePeriod { PeriodDateSpan = $"{startDate} - {endDate}" } } }, Action = ApiConstants.LoadAction }; return(XmlConvertHelper.XmlSerialize(request)); }
/// <summary> /// Creates punch request /// </summary> /// <param name="personNumber">Person number</param> /// <param name="localTimestamp">local timestamp</param> /// <param name="workRuleName">Workrule name</param> /// <returns>Punch request response</returns> public string CreatePunchRequest(string personNumber, DateTimeOffset?localTimestamp, string workRuleName) { var tzOffset = Timezone.GetLocalTimeZoneOffset(localTimestamp); var kTimeZone = Timezone.GetKronosTimeZone().Where(t => t.Contains(tzOffset)).FirstOrDefault(); addReq.Request request = new addReq.Request { Punch = new addReq.Punch { Date = localTimestamp.Value.Date.ToString(ApiConstants.DateFormat, CultureInfo.InvariantCulture), Time = localTimestamp.Value.ToString("HH:mm:ss", CultureInfo.InvariantCulture), KronosTimeZone = kTimeZone, Employee = new addReq.Employee { PersonIdentity = new addReq.PersonIdentity { PersonNumber = personNumber } } }, Action = ApiConstants.AddOnlyAction }; if (!string.IsNullOrWhiteSpace(workRuleName)) { request.Punch.WorkRuleName = workRuleName; } return(XmlConvertHelper.XmlSerialize(request)); }
public Models.ResponseEntities.PersonInformation.Response ProcessPIResponse(string strResponse) { XDocument xDoc = XDocument.Parse(strResponse); var xResponse = xDoc.Root.Descendants().FirstOrDefault(d => d.Name.LocalName.Equals(ApiConstants.Response)); return(XmlConvertHelper.DeserializeObject <Models.ResponseEntities.PersonInformation.Response>(xResponse.ToString())); }
/// <summary> /// Read the xml response into Response object. /// </summary> /// <param name="strResponse">xml response string.</param> /// <returns>Response object.</returns> public Response.Response ProcessResponse(string strResponse) { XDocument xDoc = XDocument.Parse(strResponse); var xResponse = xDoc.Root.Descendants().FirstOrDefault(d => d.Name.LocalName.Equals(ApiConstants.Response)); return(XmlConvertHelper.DeserializeObject <Response.Response>(xResponse.ToString())); }
private Models.ResponseEntities.OpenShiftRequest.ApproveDecline.Response ProcessOpenShiftsApprovedDeclinedResponse(string strResponse) { XDocument xDoc = XDocument.Parse(strResponse); var xResponse = xDoc.Root.Descendants().FirstOrDefault(d => d.Name.LocalName.Equals(ApiConstants.Response, StringComparison.Ordinal)); return(XmlConvertHelper.DeserializeObject <Models.ResponseEntities.OpenShiftRequest.ApproveDecline.Response>( xResponse.ToString())); }
public WXReqBaseMsg GetRequest(string postStr) { //XML文档处理对象 XmlDocument postObj = new XmlDocument(); //加载xml格式请求数据 postObj.LoadXml(postStr); //获取xml结构根目录 XmlElement postElement = postObj.DocumentElement; //获取请求消息类型 string msgtype = postElement.SelectSingleNode("MsgType").InnerText; WXReqBaseMsg entitybase = null; //判断接收消息类型 switch (msgtype) { //文本消息 case WXReqMsgType.text: entitybase = XmlConvertHelper.DeserializeObject <WXReqTextMsg>(postStr); break; //图片消息 case WXReqMsgType.image: entitybase = XmlConvertHelper.DeserializeObject <WXReqImageMsg>(postStr); break; //语音消息 case WXReqMsgType.voice: entitybase = XmlConvertHelper.DeserializeObject <WXReqVoiceMsg>(postStr); break; //视频消息 case WXReqMsgType.video: entitybase = XmlConvertHelper.DeserializeObject <WXReqVideoMsg>(postStr); break; //地理位置消息 case WXReqMsgType.location: entitybase = XmlConvertHelper.DeserializeObject <WXReqLocationMsg>(postStr); break; //链接消息 case WXReqMsgType.url: entitybase = XmlConvertHelper.DeserializeObject <WXReqLinkMsg>(postStr); break; //事件消息 case WXReqMsgType.wxevent: entitybase = XmlConvertHelper.DeserializeObject <WXReqEventMsg>(postStr); break; } return(entitybase); }
/// <summary> /// Creates work rule request /// </summary> /// <param name="personNumber">Person Number</param> /// <returns>workrule request string</returns> public string CreateWorkRuleRequest(string personNumber) { workRuleReq.Request request = new workRuleReq.Request { WorkRule = string.Empty, Action = ApiConstants.WorkRuleAction }; return(XmlConvertHelper.XmlSerialize(request)); }
/// <summary> /// 微信客服回复序列化 /// </summary> /// <param name="wxRequest"></param> /// <returns></returns> public string GetWXResponseMsg(WXReqBaseMsg wxRequest) { WXRepBaseMsg wXRepTextReply = new WXRepBaseMsg(); wXRepTextReply.CreateTime = DateTime.Now.Ticks; wXRepTextReply.FromUserName = wxRequest.ToUserName; wXRepTextReply.ToUserName = wxRequest.FromUserName; wXRepTextReply.MsgType = "transfer_customer_service"; return(XmlConvertHelper.SerializeObject <WXRepBaseMsg>(wXRepTextReply)); }
/// <summary> /// 获取推送的调用凭据 /// </summary> /// <returns></returns> public WXOpenCmptVerifyTicket GetCmptVerifyTicket() { using (ISession s = SessionFactory.Instance.CreateSession()) { //当前凭据参数是否存在 WXOpenAuth entity = s.Get <WXOpenAuth>("where auth_key = @0 ", WXOpenAuthKey.cmpt_verify_ticket.ToString()); if (entity != null) { return(XmlConvertHelper.DeserializeObject <WXOpenCmptVerifyTicket>(entity.val)); } return(null); } }
/// <summary> /// Process response class. /// </summary> /// <param name="strResponse">String response.</param> /// <returns>Process response.</returns> private Response ProcessResponse(string strResponse) { var telemetryProps = new Dictionary <string, string>() { { "AssemblyName", Assembly.GetExecutingAssembly().FullName }, }; this.telemetryClient.TrackTrace(MethodBase.GetCurrentMethod().Name, telemetryProps); XDocument xDoc = XDocument.Parse(strResponse); var xResponse = xDoc.Root.Descendants().FirstOrDefault(d => d.Name.LocalName.Equals(ApiConstants.Response, StringComparison.Ordinal)); return(XmlConvertHelper.DeserializeObject <Response>(xResponse.ToString())); }
/// <summary> /// 获取文本响应信息 /// </summary> /// <param name="wxRequest"></param> /// <param name="account"></param> /// <param name="id"></param> /// <returns></returns> public string GetWXResponseMsg(WXReqBaseMsg wxRequest, WeChatAccountTmp account, long id) { TextReply textReply = base.GetById(id); WXRepTextReply wXRepTextReply = new WXRepTextReply(); wXRepTextReply.CreateTime = DateTime.Now.Ticks; wXRepTextReply.FromUserName = wxRequest.ToUserName; wXRepTextReply.ToUserName = wxRequest.FromUserName; wXRepTextReply.MsgType = WXRepMsgType.text; //文本回复内容 wXRepTextReply.Content = textReply.reply_contents; return(XmlConvertHelper.SerializeObject <WXRepTextReply>(wXRepTextReply)); }
/// <summary> /// 获取文本响应信息 /// </summary> /// <param name="wxRequest"></param> /// <param name="account"></param> /// <param name="content"></param> /// <param name="globalConfig"></param> /// <returns></returns> public string GetWXResponseMsg(WXReqBaseMsg wxRequest, string content) { if (!string.IsNullOrEmpty(content)) { WXRepTextReply wXRepTextReply = new WXRepTextReply(); wXRepTextReply.CreateTime = DateTime.Now.Ticks; wXRepTextReply.FromUserName = wxRequest.ToUserName; wXRepTextReply.ToUserName = wxRequest.FromUserName; wXRepTextReply.MsgType = WXRepMsgType.text; //文本回复内容 wXRepTextReply.Content = content; return(XmlConvertHelper.SerializeObject <WXRepTextReply>(wXRepTextReply)); } return(string.Empty); }
/// <summary> /// Get person information request /// </summary> /// <param name="personNumber">Person Number</param> /// <returns>Person information request</returns> private string GetPersonInformationRequest(string personNumber) { Request request = new Request { PersonInformation = new Models.RequestEntities.PresentEmployees.PersonInformation { Identity = new Identity { PersonIdentity = new PersonIdentity { PersonNumber = personNumber } } }, Action = ApiConstants.LoadAction }; return(XmlConvertHelper.XmlSerialize(request)); }
/// <summary> /// Create view balance request class. /// </summary> /// <param name="personNumber">Person number</param> /// <returns>View balance request</returns> public string CreateViewBalanceRequest(string personNumber) { Request request = new Request { AccrualData = new req.AccrualData { BalanceDate = DateTime.Now.Date.ToString("MM/d/yyyy", CultureInfo.InvariantCulture), Employee = new req.Employee { PersonIdentity = new req.PersonIdentity { PersonNumber = personNumber } } }, Action = ApiConstants.LoadAction }; return(XmlConvertHelper.XmlSerialize(request)); }
/// <summary> /// Gets current Property/ScoredProperty's integer value from its "Value" child-element /// </summary> /// <exception cref="FormatException">either can't find the value or find invalid value number</exception> /// <exception cref="XmlException">XML is not well-formed.</exception> public int GetCurrentPropertyIntValueWithException() { // Do the assignment outside of try-catch so the FormatException of value-not-found could be thrown properly. string textValue = GetCurrentPropertyFullValueWithException(); int intValue = 0; try { intValue = XmlConvertHelper.ConvertStringToInt32(textValue); } catch (FormatException e) { throw NewPrintCapFormatException(String.Format(CultureInfo.CurrentCulture, PTUtility.GetTextFromResource("FormatException.InvalidXMLIntValue"), CurrentElementTextValue, _xmlReader.LineNumber, _xmlReader.LinePosition), e); } return(intValue); }
/// <summary> /// 微信多图文回复序列化 /// </summary> /// <param name="request"></param> /// <param name="wXRepImgTextReply"></param> /// <returns></returns> public string GetWXResponseMsg(WXReqBaseMsg request, List <WXRepImgTextReply> wXRepImgTextReply) { //多图文信息 if (wXRepImgTextReply != null && wXRepImgTextReply.Count > 0) { WXRepNews wXRepBaseMsg = new WXRepNews(); //接收人 wXRepBaseMsg.ToUserName = request.FromUserName; //发送人 wXRepBaseMsg.FromUserName = request.ToUserName; //创建时间 wXRepBaseMsg.CreateTime = DateTime.Now.Ticks; //消息类型 wXRepBaseMsg.MsgType = WXRepMsgType.news; //多图文数量 wXRepBaseMsg.imgTextReplys = wXRepImgTextReply; //多图文数量 wXRepBaseMsg.ArticleCount = wXRepImgTextReply.Count; return(XmlConvertHelper.SerializeObject <WXRepNews>(wXRepBaseMsg)); } return(string.Empty); }
/// <summary> /// Instantiates a reader object for the given XML PrintCapabilities /// </summary> /// <remarks>Constructor verifies the root element is valid</remarks> /// <exception cref="FormatException">thrown if XML PrintCapabilities is not well-formed</exception> public XmlPrintCapReader(Stream xmlStream) { // Internally the XML PrintCapabilities reader uses XmlTextReader _xmlReader = new XmlTextReader(xmlStream); // We need namespace support from the reader. _xmlReader.Namespaces = true; // Don't resolve external resources. _xmlReader.XmlResolver = null; // Verify root element is <PrintCapabilities> in our standard namespace if ((_xmlReader.MoveToContent() != XmlNodeType.Element) || (_xmlReader.LocalName != PrintSchemaTags.Framework.PrintCapRoot) || (_xmlReader.NamespaceURI != PrintSchemaNamespaces.Framework)) { throw NewPrintCapFormatException(String.Format(CultureInfo.CurrentCulture, PTUtility.GetTextFromResource("FormatException.InvalidRootElement"), _xmlReader.NamespaceURI, _xmlReader.LocalName)); } // Verify the XML PrintCapabilities version is supported // For XML attribute without a prefix (e.g. <... name="prn:PageMediaSize">), // even though the XML document has default namespace defined as our standard // Print Schema framework namespace, the XML atribute still has NULL namespaceURI. // It will only have the correct namespaceURI when a prefix is used. This doesn't // apply to XML element, whose namespaceURI works fine with default namespace. // GetAttribute doesn't move the reader cursor away from the current element string version = _xmlReader.GetAttribute(PrintSchemaTags.Framework.RootVersionAttr, PrintSchemaNamespaces.FrameworkAttrForXmlReader); if (version == null) { throw NewPrintCapFormatException(String.Format(CultureInfo.CurrentCulture, PTUtility.GetTextFromResource("FormatException.RootMissingAttribute"), PrintSchemaTags.Framework.RootVersionAttr)); } // Convert string to number to verify decimal versionNum; try { versionNum = XmlConvertHelper.ConvertStringToDecimal(version); } catch (FormatException e) { throw NewPrintCapFormatException(String.Format(CultureInfo.CurrentCulture, PTUtility.GetTextFromResource("FormatException.RootInvalidAttribute"), PrintSchemaTags.Framework.RootVersionAttr, version), e); } if (versionNum != PrintSchemaTags.Framework.SchemaVersion) { throw NewPrintCapFormatException(String.Format(CultureInfo.CurrentCulture, PTUtility.GetTextFromResource("FormatException.VersionNotSupported"), versionNum)); } // Reset internal states to be ready for client's reading of the PrintCapabilities XML ResetCurrentElementState(); }
/// <exception cref="XmlException">XML is not well-formed.</exception> internal override sealed bool OptionPropCallback(PrintCapabilityOption baseOption, XmlPrintCapReader reader) { FixedMediaSizeOption option = baseOption as FixedMediaSizeOption; bool handled = false; if (reader.CurrentElementNodeType == PrintSchemaNodeTypes.ScoredProperty) { handled = true; string sPropertyName = reader.CurrentElementNameAttrValue; if ((sPropertyName == PrintSchemaTags.Keywords.PageMediaSizeKeys.MediaSizeWidth) || (sPropertyName == PrintSchemaTags.Keywords.PageMediaSizeKeys.MediaSizeHeight)) { if (reader.MoveToNextSchemaElement(reader.CurrentElementDepth + 1, PrintSchemaNodeTypes.ScoredPropertyLevelTypes)) { if (reader.CurrentElementNodeType == PrintSchemaNodeTypes.Value) { // Child property is Value for fixed media size int intValue = 0; bool convertOK = false; try { intValue = XmlConvertHelper.ConvertStringToInt32(reader.CurrentElementTextValue); convertOK = true; } // We want to catch internal FormatException to skip recoverable XML content syntax error #pragma warning suppress 56502 #if _DEBUG catch (FormatException e) #else catch (FormatException) #endif { #if _DEBUG Trace.WriteLine("-Error- Invalid int value '" + reader.CurrentElementTextValue + "' at line number " + reader._xmlReader.LineNumber + ", line position " + reader._xmlReader.LinePosition + ": " + e.Message); #endif } if (convertOK) { if (sPropertyName == PrintSchemaTags.Keywords.PageMediaSizeKeys.MediaSizeWidth) { option._mediaSizeWidth = intValue; } else { option._mediaSizeHeight = intValue; } } } } else { #if _DEBUG Trace.WriteLine("-Error- Missing required Value or ParameterRef child-element at line number " + reader._xmlReader.LineNumber + ", line position " + reader._xmlReader.LinePosition); #endif } } else { handled = false; #if _DEBUG Trace.WriteLine("-Warning- skip unknown ScoredProperty '" + reader.CurrentElementNameAttrValue + "' at line " + reader._xmlReader.LineNumber + ", position " + reader._xmlReader.LinePosition); #endif } } return(handled); }
/// <summary> /// Verifies if the PrintTicket is well-formed /// </summary> /// <exception cref="FormatException"> /// The PrintTicket is not well-formed. /// </exception> public static void CheckIsWellFormedPrintTicket(InternalPrintTicket pt) { XmlElement root = pt.XmlDoc.DocumentElement; // Root element should be in our standard namespace and should be <PrintTicket>. if ((root.NamespaceURI != PrintSchemaNamespaces.Framework) || (root.LocalName != PrintSchemaTags.Framework.PrintTicketRoot)) { throw NewPTFormatException(String.Format(CultureInfo.CurrentCulture, PTUtility.GetTextFromResource("FormatException.InvalidRootElement"), root.NamespaceURI, root.LocalName)); } string version = root.GetAttribute(PrintSchemaTags.Framework.RootVersionAttr, PrintSchemaNamespaces.FrameworkAttrForXmlDOM); // Root element should have the "version" attribute // (XmlElement.GetAttribute returns empty string when the attribute is not found, but // (XmlTextReader.GetAttribute returns null when the attribute is not found) if ((version == null) || (version.Length == 0)) { throw NewPTFormatException(String.Format(CultureInfo.CurrentCulture, PTUtility.GetTextFromResource("FormatException.RootMissingAttribute"), PrintSchemaTags.Framework.RootVersionAttr)); } decimal versionNum; try { versionNum = XmlConvertHelper.ConvertStringToDecimal(version); } catch (FormatException e) { throw NewPTFormatException(String.Format(CultureInfo.CurrentCulture, PTUtility.GetTextFromResource("FormatException.RootInvalidAttribute"), PrintSchemaTags.Framework.RootVersionAttr, version), e); } // and the "version" attribute value should be what we support if (versionNum != PrintSchemaTags.Framework.SchemaVersion) { throw NewPTFormatException(String.Format(CultureInfo.CurrentCulture, PTUtility.GetTextFromResource("FormatException.VersionNotSupported"), versionNum)); } // Now go through each root child element and verify they are valid children XmlNode rootChild = root.FirstChild; // It's recommended that traversing the node in forward-only movement by using NextSibling // is best for XmlDocument performance. This is because the list is not double-linked. while (rootChild != null) { // If the root child doesn't live in our standard namespace, we should ignore it // rather than rejecting it since it's acceptable to have private elements under // the root. if (rootChild.NamespaceURI == PrintSchemaNamespaces.Framework) { // For <PrintTicket> root, our Framework schema only allow these children elements: // <Feature> <AttributeSet> <Property> <ParameterInit> if ((rootChild.NodeType != XmlNodeType.Element) || ((rootChild.LocalName != PrintSchemaTags.Framework.Feature) && (rootChild.LocalName != PrintSchemaTags.Framework.ParameterInit) && (rootChild.LocalName != PrintSchemaTags.Framework.Property))) { throw NewPTFormatException(String.Format(CultureInfo.CurrentCulture, PTUtility.GetTextFromResource("FormatException.RootInvalidChildElement"), rootChild.Name)); } string childName = ((XmlElement)rootChild).GetAttribute(PrintSchemaTags.Framework.NameAttr, PrintSchemaNamespaces.FrameworkAttrForXmlDOM); // All the recognized root child element should have an XML attribut "name" if ((childName == null) || (childName.Length == 0)) { throw NewPTFormatException(String.Format(CultureInfo.CurrentCulture, PTUtility.GetTextFromResource("FormatException.RootChildMissingAttribute"), rootChild.Name, PrintSchemaTags.Framework.NameAttr)); } } rootChild = rootChild.NextSibling; } // We will end the verification at the root child level here. Instead of traversing the whole tree // to find violations in this construtor, we will delay detecting violations under root child level // until information of an individual feature/property subtree is requested. }