private static string ToOptionalFieldName( OptionalFields optionalField ) { switch( optionalField ) { case OptionalFields.User_Email: return "email"; case OptionalFields.User_Name: return "name"; case OptionalFields.User_Workspaces: return "workspaces"; case OptionalFields.User_Workspaces_Name: return "workspaces.name"; case OptionalFields.Project_CreatedAt: return "created_at"; case OptionalFields.Project_ModifiedAt: return "modified_at"; case OptionalFields.Story_Source: return "source"; case OptionalFields.Story_Target: return "target"; case OptionalFields.Story_Target_Name: return "target.name"; } return ""; }
/// <summary> /// Reads and validates the header block from the map file. /// </summary> /// <param name="readBuffer"> /// the ReadBuffer for the file data. </param> /// <param name="fileSize"> /// the size of the map file in bytes. </param> /// <exception cref="IOException"> /// if an error occurs while reading the file. </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void readHeader(MapsforgeSharp.Reader.ReadBuffer readBuffer, long fileSize) throws java.io.IOException public virtual void ReadHeader(ReadBuffer readBuffer, long fileSize) { RequiredFields.ReadMagicByte(readBuffer); RequiredFields.ReadRemainingHeader(readBuffer); MapFileInfoBuilder mapFileInfoBuilder = new MapFileInfoBuilder(); RequiredFields.readFileVersion(readBuffer, mapFileInfoBuilder); RequiredFields.ReadFileSize(readBuffer, fileSize, mapFileInfoBuilder); RequiredFields.ReadMapDate(readBuffer, mapFileInfoBuilder); RequiredFields.ReadBoundingBox(readBuffer, mapFileInfoBuilder); RequiredFields.ReadTilePixelSize(readBuffer, mapFileInfoBuilder); RequiredFields.ReadProjectionName(readBuffer, mapFileInfoBuilder); OptionalFields.ReadOptionalFields(readBuffer, mapFileInfoBuilder); RequiredFields.ReadPoiTags(readBuffer, mapFileInfoBuilder); RequiredFields.ReadWayTags(readBuffer, mapFileInfoBuilder); ReadSubFileParameters(readBuffer, fileSize, mapFileInfoBuilder); this.mapFileInfo = mapFileInfoBuilder.Build(); }
public ActionResult UpdateField(OptionalFields field) { List <string> res = new List <string>(); bool status = false; if (ModelState.IsValid) { try { Commonhelper.UpdateFieldbyId(field); res.Add("Update Successfully."); status = true; } catch (Exception ex) { res.Add("Error in Field updation!"); status = false; } } else { foreach (var modelState in ModelState.Values) { foreach (var modelError in modelState.Errors) { res.Add(modelError.ErrorMessage); } } } return(Json(new { res, status }, JsonRequestBehavior.AllowGet)); }
private static string ToOptionalFieldName(OptionalFields optionalField) { switch (optionalField) { case OptionalFields.User_Email: return("email"); case OptionalFields.User_Name: return("name"); case OptionalFields.User_Workspaces: return("workspaces"); case OptionalFields.User_Workspaces_Name: return("workspaces.name"); case OptionalFields.Project_CreatedAt: return("created_at"); case OptionalFields.Project_ModifiedAt: return("modified_at"); case OptionalFields.Story_Source: return("source"); case OptionalFields.Story_Target: return("target"); case OptionalFields.Story_Target_Name: return("target.name"); } return(""); }
internal static string ToOptionalFieldNames( OptionalFields[] returnedFields ) { StringBuilder sb = new StringBuilder( returnedFields.Length * 10 ); for( int i = 0; i < returnedFields.Length; i++ ) { if( i > 0 ) { sb.Append( "," ); } sb.Append( ToOptionalFieldName( returnedFields[ i ] ) ); } return sb.ToString(); }
private void UpdatePersonOptionalField(Person person, OptionalFields optionalField, string value) { var personOptionalField = person.PersonOptionalFields.FirstOrDefault(c => c.OptionalFieldId == (int)optionalField); if (personOptionalField == null) { personOptionalField = new PersonOptionalField { OptionalFieldId = (int)optionalField, Created = DateTime.Now, Changed = DateTime.Now }; person.PersonOptionalFields.Add(personOptionalField); } if (personOptionalField.Value != (value ?? string.Empty)) personOptionalField.Changed = DateTime.Now; personOptionalField.Value = value ?? string.Empty; }
/// <summary> /// Appends the SREG required attributes to the request URL constructed on challenge. /// </summary> public Task OnChallengeAsync(Microsoft.Owin.Security.AuthenticationResponseChallenge challenge, OpenIDAuthorizationEndpointInfo endpoint) { endpoint.Url += "&openid.ns.sreg=" + Uri.EscapeDataString(sregNamespace); var requiredClaims = string.Join(",", RequiredFields.Select(f => claimsMap[f])); endpoint.Url += "&openid.sreg.required=" + Uri.EscapeDataString(requiredClaims); if (OptionalFields.Any()) { var optionalClaims = string.Join(",", OptionalFields.Select(f => claimsMap[f])); endpoint.Url += "&openid.sreg.optional=" + Uri.EscapeDataString(optionalClaims); } if (!string.IsNullOrEmpty(PolicyUrl)) { endpoint.Url += "&openid.sreg.policy_url=" + Uri.EscapeDataString(PolicyUrl); } return(Task.FromResult(0)); }
public IList <ReleaseInfo> ParseResponse(IndexerResponse indexerResponse) { var releases = new List <ReleaseInfo>(); _logger.Debug("Parsing"); var indexerLogging = _configService.LogIndexerResponse; if (indexerResponse.HttpResponse.StatusCode != HttpStatusCode.OK) { // Remove cookie cache if (indexerResponse.HttpResponse.HasHttpRedirect && indexerResponse.HttpResponse.RedirectUrl .ContainsIgnoreCase("login.php")) { CookiesUpdater(null, null); throw new IndexerException(indexerResponse, "We are being redirected to the login page. Most likely your session expired or was killed. Try testing the indexer in the settings."); } throw new IndexerException(indexerResponse, $"Unexpected response status {indexerResponse.HttpResponse.StatusCode} code from API request"); } var results = indexerResponse.Content; var request = indexerResponse.Request as CardigannRequest; var variables = request.Variables; var search = _definition.Search; var searchUrlUri = new Uri(request.Url.FullUri); if (request.SearchPath.Response != null && request.SearchPath.Response.Type.Equals("json")) { if (request.SearchPath.Response != null && request.SearchPath.Response.NoResultsMessage != null && (request.SearchPath.Response.NoResultsMessage.Equals(results) || (request.SearchPath.Response.NoResultsMessage == string.Empty && results == string.Empty))) { return(releases); } var parsedJson = JToken.Parse(results); if (parsedJson == null) { throw new IndexerException(indexerResponse, "Error Parsing Json Response"); } if (search.Rows.Count != null) { var countVal = HandleJsonSelector(search.Rows.Count, parsedJson, variables); if (int.TryParse(countVal, out var count)) { if (count < 1) { return(releases); } } } var rowsArray = JsonParseRowsSelector(parsedJson, search.Rows.Selector); if (rowsArray == null) { throw new IndexerException(indexerResponse, "Error Parsing Rows Selector"); } foreach (var row in rowsArray) { var selObj = search.Rows.Attribute != null?row.SelectToken(search.Rows.Attribute).Value <JToken>() : row; var mulRows = search.Rows.Multiple ? selObj.Values <JObject>() : new List <JObject> { selObj.Value <JObject>() }; foreach (var mulRow in mulRows) { var release = new TorrentInfo(); foreach (var field in search.Fields) { var fieldParts = field.Key.Split('|'); var fieldName = fieldParts[0]; var fieldModifiers = new List <string>(); for (var i = 1; i < fieldParts.Length; i++) { fieldModifiers.Add(fieldParts[i]); } string value = null; var variablesKey = ".Result." + fieldName; var isOptional = OptionalFields.Contains(field.Key) || fieldModifiers.Contains("optional") || field.Value.Optional; try { var parentObj = mulRow; if (field.Value.Selector != null && field.Value.Selector.StartsWith("..")) { parentObj = row.Value <JObject>(); } value = HandleJsonSelector(field.Value, parentObj, variables, !isOptional); if (isOptional && string.IsNullOrWhiteSpace(value)) { variables[variablesKey] = null; continue; } variables[variablesKey] = ParseFields(value, fieldName, release, fieldModifiers, searchUrlUri); } catch (Exception ex) { if (!variables.ContainsKey(variablesKey)) { variables[variablesKey] = null; } if (isOptional) { variables[variablesKey] = null; continue; } throw new CardigannException(string.Format("Error while parsing field={0}, selector={1}, value={2}: {3}", field.Key, field.Value.Selector, value ?? "<null>", ex.Message)); } var filters = search.Rows.Filters; var skipRelease = ParseRowFilters(filters, release, variables, row); if (skipRelease) { continue; } } releases.Add(release); } } } else { try { IHtmlCollection <IElement> rowsDom; if (request.SearchPath.Response != null && request.SearchPath.Response.Type.Equals("xml")) { var searchResultParser = new XmlParser(); var searchResultDocument = searchResultParser.ParseDocument(results); if (search.Preprocessingfilters != null) { results = ApplyFilters(results, search.Preprocessingfilters, variables); searchResultDocument = searchResultParser.ParseDocument(results); _logger.Trace(string.Format("CardigannIndexer ({0}): result after preprocessingfilters: {1}", _definition.Id, results)); } var rowsSelector = ApplyGoTemplateText(search.Rows.Selector, variables); rowsDom = searchResultDocument.QuerySelectorAll(rowsSelector); } else { var searchResultParser = new HtmlParser(); var searchResultDocument = searchResultParser.ParseDocument(results); if (search.Preprocessingfilters != null) { results = ApplyFilters(results, search.Preprocessingfilters, variables); searchResultDocument = searchResultParser.ParseDocument(results); _logger.Trace(string.Format("CardigannIndexer ({0}): result after preprocessingfilters: {1}", _definition.Id, results)); } var rowsSelector = ApplyGoTemplateText(search.Rows.Selector, variables); rowsDom = searchResultDocument.QuerySelectorAll(rowsSelector); } var rows = new List <IElement>(); foreach (var rowDom in rowsDom) { rows.Add(rowDom); } // merge following rows for After selector var after = search.Rows.After; if (after > 0) { for (var i = 0; i < rows.Count; i += 1) { var currentRow = rows[i]; for (var j = 0; j < after; j += 1) { var mergeRowIndex = i + j + 1; var mergeRow = rows[mergeRowIndex]; var mergeNodes = new List <INode>(); foreach (var node in mergeRow.ChildNodes) { mergeNodes.Add(node); } currentRow.Append(mergeNodes.ToArray()); } rows.RemoveRange(i + 1, after); } } foreach (var row in rows) { try { var release = new TorrentInfo(); // Parse fields foreach (var field in search.Fields) { var fieldParts = field.Key.Split('|'); var fieldName = fieldParts[0]; var fieldModifiers = new List <string>(); for (var i = 1; i < fieldParts.Length; i++) { fieldModifiers.Add(fieldParts[i]); } string value = null; var variablesKey = ".Result." + fieldName; var isOptional = OptionalFields.Contains(field.Key) || fieldModifiers.Contains("optional") || field.Value.Optional; try { value = HandleSelector(field.Value, row, variables, !isOptional); if (isOptional && string.IsNullOrWhiteSpace(value)) { variables[variablesKey] = null; continue; } variables[variablesKey] = ParseFields(value, fieldName, release, fieldModifiers, searchUrlUri); } catch (Exception ex) { if (!variables.ContainsKey(variablesKey)) { variables[variablesKey] = null; } if (OptionalFields.Contains(field.Key) || fieldModifiers.Contains("optional") || field.Value.Optional) { variables[variablesKey] = null; continue; } if (indexerLogging) { _logger.Trace("Error while parsing field={0}, selector={1}, value={2}: {3}", field.Key, field.Value.Selector, value == null ? "<null>" : value, ex.Message); } } } var filters = search.Rows.Filters; var skipRelease = ParseRowFilters(filters, release, variables, row); if (skipRelease) { continue; } // if DateHeaders is set go through the previous rows and look for the header selector var dateHeaders = _definition.Search.Rows.Dateheaders; if (release.PublishDate == DateTime.MinValue && dateHeaders != null) { var prevRow = row.PreviousElementSibling; string value = null; if (prevRow == null) { // continue with parent var parent = row.ParentElement; if (parent != null) { prevRow = parent.PreviousElementSibling; } } while (prevRow != null) { var curRow = prevRow; _logger.Debug(prevRow.OuterHtml); try { value = HandleSelector(dateHeaders, curRow); break; } catch (Exception) { // do nothing } prevRow = curRow.PreviousElementSibling; if (prevRow == null) { // continue with parent var parent = curRow.ParentElement; if (parent != null) { prevRow = parent.PreviousElementSibling; } } } if (value == null && dateHeaders.Optional == false) { throw new CardigannException(string.Format("No date header row found for {0}", release.ToString())); } if (value != null) { release.PublishDate = DateTimeUtil.FromUnknown(value); } } releases.Add(release); } catch (Exception ex) { _logger.Error(ex, "CardigannIndexer ({0}): Error while parsing row '{1}':\n\n{2}", _definition.Id, row.ToHtmlPretty()); } } } catch (Exception) { // OnParseError(results, ex); throw; } } /* * if (query.Limit > 0) * { * releases = releases.Take(query.Limit).ToList(); * }*/ releases.ForEach(c => { // generate magnet link from info hash (not allowed for private sites) if (((TorrentInfo)c).MagnetUrl == null && !string.IsNullOrWhiteSpace(((TorrentInfo)c).InfoHash) && _definition.Type != "private") { ((TorrentInfo)c).MagnetUrl = MagnetLinkBuilder.BuildPublicMagnetLink(((TorrentInfo)c).InfoHash, c.Title); } // generate info hash from magnet link if (((TorrentInfo)c).MagnetUrl != null && string.IsNullOrWhiteSpace(((TorrentInfo)c).InfoHash)) { ((TorrentInfo)c).InfoHash = MagnetLinkBuilder.GetInfoHashFromMagnet(((TorrentInfo)c).MagnetUrl); } }); _logger.Debug($"Got {releases.Count} releases"); return(releases); }
public ActionResult EditField(string Id) { OptionalFields field = Commonhelper.GetOptionalFieldbyId(Id); return(View(field)); }
/// <summary> /// See interface docs. /// </summary> /// <param name="message"></param> /// <returns></returns> public byte[] Compress(BaseStationMessage message) { byte[] result = null; if (IsMeaningfulMessage(message)) { using (var stream = new MemoryStream()) { using (var writer = new BinaryWriter(stream)) { stream.WriteByte(0); // <-- reserve a byte for the buffer length writer.Write((ushort)0); // <-- reserve a word for the checksum stream.WriteByte((byte)(int)message.TransmissionType); EncodeIcao(stream, message.Icao24); long optionalFlagsOffset = stream.Position; stream.WriteByte(0); // <-- reserve two bytes for the optional fields flags stream.WriteByte(0); // <-- " OptionalFields optionalFields = OptionalFields.None; if (!String.IsNullOrEmpty(message.Callsign)) { optionalFields |= OptionalFields.CallSign; EncodeString(stream, message.Callsign); } if (message.Altitude != null) { optionalFields |= OptionalFields.Altitude; EncodeFloatInt(stream, message.Altitude.Value); } if (message.GroundSpeed != null) { optionalFields |= OptionalFields.GroundSpeed; EncodeFloatShort(writer, message.GroundSpeed.Value); } if (message.Track != null) { optionalFields |= OptionalFields.Track; EncodeFloatShort(writer, message.Track.Value * 10f); } if (message.Latitude != null) { optionalFields |= OptionalFields.Latitude; EncodeFloat(writer, (float)message.Latitude.Value); } if (message.Longitude != null) { optionalFields |= OptionalFields.Longitude; EncodeFloat(writer, (float)message.Longitude.Value); } if (message.VerticalRate != null) { optionalFields |= OptionalFields.VerticalRate; EncodeFloatShort(writer, message.VerticalRate.Value); } if (message.Squawk != null) { optionalFields |= OptionalFields.Squawk; EncodeShort(writer, (short)Math.Max(short.MinValue, Math.Min(short.MaxValue, message.Squawk.Value))); } CompressedFlags flags = CompressedFlags.None; bool hasFlag = false; if (message.SquawkHasChanged != null) { optionalFields |= OptionalFields.SquawkHasChanged; hasFlag = true; if (message.SquawkHasChanged.Value) { flags |= CompressedFlags.SquawkHasChanged; } } if (message.Emergency != null) { optionalFields |= OptionalFields.Emergency; hasFlag = true; if (message.Emergency.Value) { flags |= CompressedFlags.Emergency; } } if (message.IdentActive != null) { optionalFields |= OptionalFields.IdentActive; hasFlag = true; if (message.IdentActive.Value) { flags |= CompressedFlags.IdentActive; } } if (message.OnGround != null) { optionalFields |= OptionalFields.OnGround; hasFlag = true; if (message.OnGround.Value) { flags |= CompressedFlags.OnGround; } } if (hasFlag) { stream.WriteByte((byte)flags); } stream.Seek(optionalFlagsOffset, SeekOrigin.Begin); EncodeShort(writer, (short)optionalFields); } result = stream.ToArray(); if (result.Length != 0) { result[0] = (byte)result.Length; var checksum = CalculateChecksum(result); result[1] = (byte)(checksum & 0x00ff); result[2] = (byte)((checksum & 0xff00) >> 8); } } } return(result ?? new byte[0]); }
/// <summary> /// See interface docs. /// </summary> /// <param name="buffer"></param> /// <returns></returns> public BaseStationMessage Decompress(byte[] buffer) { BaseStationMessage result = null; if (buffer.Length > 0 && (int)buffer[0] == buffer.Length) { using (var stream = new MemoryStream(buffer)) { using (var reader = new BinaryReader(stream)) { result = new BaseStationMessage(); stream.ReadByte(); // <-- length of buffer, we can skip this ushort checksum = reader.ReadUInt16(); // the checksum is skipped as well - caller should ensure it's a valid message before decompression result.MessageType = BaseStationMessageType.Transmission; result.StatusCode = BaseStationStatusCode.None; result.TransmissionType = (BaseStationTransmissionType)stream.ReadByte(); result.Icao24 = DecodeIcao(stream); result.MessageGenerated = result.MessageLogged = DateTime.Now; OptionalFields optionalFields = (OptionalFields)DecodeShort(reader); if ((optionalFields & OptionalFields.CallSign) != 0) { result.Callsign = DecodeString(stream); } if ((optionalFields & OptionalFields.Altitude) != 0) { result.Altitude = (int)DecodeFloatInt(stream); } if ((optionalFields & OptionalFields.GroundSpeed) != 0) { result.GroundSpeed = (int)DecodeFloatShort(reader); } if ((optionalFields & OptionalFields.Track) != 0) { result.Track = DecodeFloatShort(reader) / 10f; } if ((optionalFields & OptionalFields.Latitude) != 0) { result.Latitude = DecodeFloat(reader); } if ((optionalFields & OptionalFields.Longitude) != 0) { result.Longitude = DecodeFloat(reader); } if ((optionalFields & OptionalFields.VerticalRate) != 0) { result.VerticalRate = (int)DecodeFloatShort(reader); } if ((optionalFields & OptionalFields.Squawk) != 0) { result.Squawk = DecodeShort(reader); } bool hasSquawkHasChanged = (optionalFields & OptionalFields.SquawkHasChanged) != 0; bool hasEmergency = (optionalFields & OptionalFields.Emergency) != 0; bool hasIdentActive = (optionalFields & OptionalFields.IdentActive) != 0; bool hasOnGround = (optionalFields & OptionalFields.OnGround) != 0; if (hasSquawkHasChanged || hasEmergency || hasIdentActive || hasOnGround) { CompressedFlags flags = (CompressedFlags)stream.ReadByte(); if (hasSquawkHasChanged) { result.SquawkHasChanged = (flags & CompressedFlags.SquawkHasChanged) != 0; } if (hasEmergency) { result.Emergency = (flags & CompressedFlags.Emergency) != 0; } if (hasIdentActive) { result.IdentActive = (flags & CompressedFlags.IdentActive) != 0; } if (hasOnGround) { result.OnGround = (flags & CompressedFlags.OnGround) != 0; } } } } } return(result); }
private User[] GetUsers( string urlPath, OptionalFields[] returnedFields ) { return ObjectConversions.ToUsers( ExecuteRequest( urlPath, returnedFields, ",name,id" ) ); }
public User[] GetUsersInWorkspace( long workspaceId, OptionalFields[] returnedFields = null ) { return GetUsers( "/workspaces/" + workspaceId.ToString() + "/users", returnedFields ); }
public User[] GetUsers( OptionalFields[] returnedFields = null ) { return GetUsers( "/users", returnedFields ); }
public Story[] GetStories( Task target, OptionalFields[] returnedFields = null ) { return GetStories( target.Id, returnedFields ); }
private Story[] GetStories( string urlPath, OptionalFields[] returnedFields = null ) { return ObjectConversions.ToStories( ExecuteRequest( urlPath, returnedFields, ",created_at,id,text,source,type,created_by,created_by.name,target.completed" ) ); }
public Story[] GetStories( long taskId, OptionalFields[] returnedFields = null ) { return GetStories( "/tasks/" + taskId.ToString() + "/stories", returnedFields ); }