private static HtmlBuilder Title( this HtmlBuilder hb, SiteSettings ss, long siteId, string text) { if (!text.IsNullOrEmpty()) { if (BinaryUtilities.ExistsSiteImage(ss, siteId, ImageData.SizeTypes.Icon)) { hb.Img( src: Locations.Get( "Items", siteId.ToString(), "Binaries", "SiteImageIcon", BinaryUtilities.SiteImagePrefix( ss, siteId, ImageData.SizeTypes.Icon)), css: "site-image-icon"); } return(hb.Header(id: "HeaderTitleContainer", action: () => hb .H(number: 1, id: "HeaderTitle", action: () => hb .Text(text: text)))); } else { return(hb); } }
public static HtmlBuilder HeaderLogo( this HtmlBuilder hb, Context context, SiteSettings ss) { var existsImage = BinaryUtilities.ExistsTenantImage( context: context, ss: ss, referenceId: context.TenantId, sizeType: Images.ImageData.SizeTypes.Logo); var title = Title(context: context); return(hb.H(number: 2, id: "Logo", action: () => hb .A( attributes: new HtmlAttributes().Href(context.Publish ? ss.ReferenceType == "Wikis" ? Locations.ItemEdit( context: context, id: context.Id) : Locations.ItemIndex( context: context, id: context.SiteId) : Locations.Top(context: context)), action: () => hb .LogoImage( context: context, showTitle: !title.IsNullOrEmpty(), existsTenantImage: existsImage) .Span(id: "ProductLogo", action: () => hb .Text(text: title))))); }
/// <summary> /// Returns the number of bytes to read from the stream. /// </summary> /// <param name="state">Instance of <see cref="T:NavtelecomProtocol.SessionState" />.</param> /// <param name="reader"><see cref="T:SharpStructures.BinaryListReader" /> linked to a FLEX message body.</param> /// <param name="writer"><see cref="T:SharpStructures.MemoryBufferWriter" /> with data to be sent to the client.</param> /// <param name="token">The token to monitor for cancellation requests.</param> /// <returns>A task that represents the asynchronous operation. Contains the total number of bytes to read from the socket. Zero bytes to stop reading and send the response.</returns> public Task <int> GetPendingBytesAsync(SessionState state, BinaryListReader reader, MemoryBufferWriter writer, CancellationToken token) { switch (reader.ByteList.Count) { case 2: return(Task.FromResult(1)); case 3: var messageSize = FlexMessageTable.GetFlexMessageSize(state); var messageCount = reader.ByteList[2]; writer.Write(Response); writer.Write(messageCount); writer.Write(BinaryUtilities.GetCrc8(writer.Buffer)); return(Task.FromResult(messageSize * messageCount + 1)); default: if (reader.ByteList.Last() != BinaryUtilities.GetCrc8(reader.ByteList.Take(reader.ByteList.Count - 1))) { throw new ArgumentException("Invalid FLEX message CRC."); } return(Task.FromResult(0)); } }
public static HtmlBuilder SiteImageIcon( this HtmlBuilder hb, Context context, SiteSettings ss, long siteId) { return(BinaryUtilities.ExistsSiteImage( context: context, ss: ss, referenceId: siteId, sizeType: ImageData.SizeTypes.Icon) ? hb.Img( src: Locations.Get( context: context, parts: new string[] { "Items", siteId.ToString(), "Binaries", "SiteImageIcon", BinaryUtilities.SiteImagePrefix( context: context, ss: ss, referenceId: siteId, sizeType: ImageData.SizeTypes.Icon) }), css: "site-image-icon") : hb); }
private static HtmlBuilder LogoImage( this HtmlBuilder hb, Context context, bool showTitle, bool existsTenantImage) { return(existsTenantImage && !context.Publish ? hb.Img( id: "CorpLogo", src: Locations.Get( context: context, parts: new string[] { "Binaries", "TenantImageLogo", BinaryUtilities.TenantImagePrefix( context, SiteSettingsUtilities.TenantsSiteSettings(context), context.TenantId, Images.ImageData.SizeTypes.Logo) })) : hb.Img( id: "CorpLogo", src: Locations.Images( context: context, parts: showTitle ? "logo-corp.png" : "logo-corp-with-title.png"))); }
/// <summary> /// Processes the body of the message. /// </summary> /// <param name="state">Instance of <see cref="T:NavtelecomProtocol.SessionState" />.</param> /// <param name="reader"><see cref="T:SharpStructures.BinaryListReader" /> linked to an NTCB message body.</param> /// <param name="writer"><see cref="T:SharpStructures.MemoryBufferWriter" /> with data to be sent to the client.</param> public void ProcessBody(SessionState state, BinaryListReader reader, MemoryBufferWriter writer) { if (!reader.ReadBytes(MessageIdentifier.Length).Select(x => (char)x).SequenceEqual(MessageIdentifier)) { throw new ArgumentException("NTCB identity message prefix does not match."); } if (reader.ReadByte() != ProtocolIdentifier) { throw new ArgumentException("Unknown NTCB protocol identifier."); } state.ProtocolVersion = reader.ReadByte(); state.StructVersion = reader.ReadByte(); var dataSize = reader.ReadByte(); state.FieldMask = new bool[dataSize]; var maskBytes = reader.ReadBytes(BinaryUtilities.GetByteCountFromBitCount(dataSize)); for (var i = 0; i < dataSize; ++i) { var targetByte = maskBytes[i >> 3]; var mask = 1 << (7 - i & 7); state.FieldMask[i] = (targetByte & mask) != 0; } writer.Write(BinaryUtilities.StringToBytes("*<FLEX")); writer.Write(ProtocolIdentifier); writer.Write(state.ProtocolVersion); writer.Write(state.StructVersion); }
protected override async Task HandleConnection(TcpClient client) { // Create our stream reader & writer NetworkStream stream = client.GetStream(); BinaryReader reader = new BinaryReader(stream); BinaryWriter writer = new BinaryWriter(stream); Logger.Info("Accepted connection!"); // Read the RSConnectionReason byte connectionReason = reader.ReadByte(); // Handle the connection based on the RSConnectionReason switch ((RSConnectionReason)connectionReason) { case RSConnectionReason.Login: Logger.Verbose("Login request"); // Read the initial handshake LoginHandshakeRequest handshakeRequest; handshakeRequest.UserNameHash = reader.ReadByte(); // Write our response and send it to the client LoginHandshakeResponse handshakeResponse = new LoginHandshakeResponse(RSLoginResponseCode.ExchangeInformation, 110); BinaryUtilities.WriteStructure <LoginHandshakeResponse>(writer, handshakeResponse); writer.Flush(); // Read the actual login request LoginDataRequest dataRequest; dataRequest.ConnectionStatus = reader.ReadByte(); dataRequest.Size1 = reader.ReadByte(); dataRequest.Magic1 = reader.ReadByte(); dataRequest.ProtocolVersion = IPAddress.NetworkToHostOrder(reader.ReadInt16()); dataRequest.ClientVersion = reader.ReadByte(); dataRequest.CRC = new int[9]; for (int i = 0; i < dataRequest.CRC.Length; i++) { dataRequest.CRC[i] = IPAddress.NetworkToHostOrder(reader.ReadInt32()); } dataRequest.Size2 = reader.ReadByte(); dataRequest.Magic2 = reader.ReadByte(); dataRequest.ClientSessionKey = IPAddress.NetworkToHostOrder(reader.ReadInt64()); dataRequest.ServerSessionKey = IPAddress.NetworkToHostOrder(reader.ReadInt64()); dataRequest.UserID = IPAddress.NetworkToHostOrder(reader.ReadInt32()); dataRequest.UserName = BinaryUtilities.ReadRSString(reader); dataRequest.Password = BinaryUtilities.ReadRSString(reader); Logger.Info($"Username: {dataRequest.UserName}"); Logger.Info($"Password: {dataRequest.Password}"); break; default: int printableReason = connectionReason; Logger.Error($"Unknown RSConnectionReason: {printableReason.ToString()}"); break; } }
public static bool FindIs64Bit(ICollection <string> dlls) { dlls = dlls ?? throw new ArgumentNullException(nameof(dlls)); dlls = dlls.Any() ? dlls : throw new ArgumentException(@"Array is empty", nameof(dlls)); return(BinaryUtilities.Is64Bit(dlls.FirstOrDefault())); }
public static String ToBase64(this Object input, Base64FormattingOptions base64FormattingOptions = Base64FormattingOptions.None) { if (input == null) { return(String.Empty); } Type type = input.GetType(); // typeof(TObject); // Add support for Nullable types if (type.IsNullable()) { type = type.GetGenericArguments()[0]; } MethodInfo methodInfo; // Throw in a little static reflection caching if (!ParserUtilities._byteArrayMap.TryGetValue(type, out methodInfo)) { // Attempt to find inbuilt ToByteArray methods methodInfo = type.GetMethod("ToByteArray", new Type[] { }); // Null the mapping if the return type is wrong if ((methodInfo == null) || (methodInfo.ReturnType != typeof(Byte[]))) { ParserUtilities._byteArrayMap[type] = null; } else { ParserUtilities._byteArrayMap[type] = methodInfo; } } // Then use the inbuilt methods if (methodInfo != null) { return(Convert.ToBase64String((Byte[])methodInfo.Invoke(input, null), base64FormattingOptions)); } // Throw in a little static reflection caching if (!ParserUtilities._parserMap.TryGetValue(type, out methodInfo)) { // Attempt to find inbuilt parsing methods methodInfo = type.GetMethod("Parse", new Type[] { typeof(String) }); ParserUtilities._parserMap[type] = methodInfo; } // If there's inbuilt parsing methods, assume there is a useful ToString method if (methodInfo != null) { return(Convert.ToBase64String(Encoding.UTF8.GetBytes(input.ToString()), base64FormattingOptions)); } return(BinaryUtilities.ToBinary(input, base64FormattingOptions)); }
public string MultiUpload(string reference, long id, ICollection <IFormFile> file) { var log = new SysLogModel(); var json = BinaryUtilities.MultiUpload(file, id); log.Finish(json.Length); return(json); }
public void Delete() { var reference = Provider.CreateRandomBinary(); Assert.True(BinaryUtilities.Exists(reference)); Provider.Delete(reference); Assert.True(!BinaryUtilities.Exists(reference)); }
public string DeleteImage(IContext context, string reference, string guid) { var log = new SysLogModel(context: context); var json = BinaryUtilities.DeleteImage(context: context, guid: guid); log.Finish(context: context, responseSize: json.Length); return(json); }
public FileContentResult Show(Context context, string guid) { var log = new SysLogModel(context: context); var file = BinaryUtilities.Donwload(context: context, guid: guid); log.Finish(context: context, responseSize: file?.FileContents.Length ?? 0); return(file); }
public string DeleteTemp(string reference, long id) { var log = new SysLogModel(); var json = BinaryUtilities.DeleteTemp(); log.Finish(json.Length); return(json.ToString()); }
public FileContentResult DownloadTemp(IContext context, string reference, string guid) { var log = new SysLogModel(context: context); var file = BinaryUtilities.DownloadTemp(context: context, guid: guid); log.Finish(context: context, responseSize: file?.FileContents.Length ?? 0); return(file); }
public string MultiUpload(string reference, long id, HttpPostedFileBase[] file) { var log = new SysLogModel(); var json = BinaryUtilities.MultiUpload(file, id); log.Finish(json.Length); return(json); }
public string DeleteImage(string reference, string guid) { var log = new SysLogModel(); var json = BinaryUtilities.DeleteImage(guid); log.Finish(json.Length); return(json); }
public FileContentResult DownloadTemp(string reference, string guid) { var log = new SysLogModel(); var file = BinaryUtilities.DownloadTemp(guid); log.Finish(file?.FileContents.Length ?? 0); return(file); }
public string DeleteTemp(IContext context, string reference, long id) { var log = new SysLogModel(context: context); var json = BinaryUtilities.DeleteTemp(context: context); log.Finish(context: context, responseSize: json.Length); return(json.ToString()); }
/// <summary> /// Returns the number of bytes to read from the stream. /// </summary> /// <param name="state">Instance of <see cref="T:NavtelecomProtocol.SessionState" />.</param> /// <param name="reader"><see cref="T:SharpStructures.BinaryListReader" /> linked to a FLEX message body.</param> /// <param name="writer"><see cref="T:SharpStructures.MemoryBufferWriter" /> with data to be sent to the client.</param> /// <param name="token">The token to monitor for cancellation requests.</param> /// <returns>A task that represents the asynchronous operation. Contains the total number of bytes to read from the socket. Zero bytes to stop reading and send the response.</returns> public async Task <int> GetPendingBytesAsync(SessionState state, BinaryListReader reader, MemoryBufferWriter writer, CancellationToken token) { switch (reader.ByteList.Count) { case 2: return(13); case 15: reader.SetPosition(13); return(reader.ReadUInt16() + 1); default: if (reader.ByteList.Last() != BinaryUtilities.GetCrc8(reader.ByteList.Take(reader.ByteList.Count - 1))) { throw new ArgumentException("Invalid FLEX message CRC."); } reader.SetPosition(4); var result = reader.ReadByte(); var crashTime = reader.ReadUInt32(); var offset = reader.ReadUInt32(); var sizeRead = reader.ReadUInt16(); if (state.CrashInfo != null && result == 0x00 && state.CrashInfo.Timestamp == crashTime) { for (var i = 0; i < sizeRead; ++i) { state.CrashInfo.Data[offset + i] = reader.ByteList[15 + i]; } state.CrashInfo.Offset = offset + sizeRead; var bytesLeft = state.CrashInfo.Data.Length - state.CrashInfo.Offset; writer.Write(CrashInformation.CrashDataQuery); writer.Write(crashTime); writer.Write(state.CrashInfo.Offset); writer.Write(bytesLeft > ushort.MaxValue ? ushort.MaxValue : (ushort)bytesLeft); writer.Write(BinaryUtilities.GetCrc8(writer.Buffer)); if (bytesLeft == 0) { if (_onReadyCrash != null) { await _onReadyCrash(state, token).ConfigureAwait(false); } state.CrashInfo = null; } } return(0); } }
public void GetStream() { var inStream = BinaryUtilities.GenerateRandomStream(1024); var reference = Provider.CreateRandomBinary(stream: inStream); using var outStream = Provider.GetStream(reference); Assert.True(outStream.Length == inStream.Length); inStream.Seek(0, System.IO.SeekOrigin.Begin); Assert.True(outStream.StreamEquals(inStream)); }
public string UpdateSiteImage(string reference, long id) { var log = new SysLogModel(); var json = reference.ToLower() == "items" ? BinaryUtilities.UpdateSiteImage(new SiteModel(id)) : new ResponseCollection().ToJson(); log.Finish(0); return(json); }
public string MultiUpload(IContext context, string reference, long id, IHttpPostedFile[] file) { var log = new SysLogModel(context: context); var json = BinaryUtilities.MultiUpload( context: context, id: id); log.Finish(context: context, responseSize: json.Length); return(json); }
public FileContentResult ShowTemp(Context context, string reference, string guid) { var log = new SysLogModel(context: context); var file = BinaryUtilities.DownloadTemp(context: context, guid: guid); log.Finish(context: context, responseSize: file?.FileContents?.Length ?? 0); return(file != null ? new FileContentResult(System.Text.Encoding.UTF8.GetBytes(file.FileContents), file.ContentType) : null); }
public string Upload(Context context, long id, ContentRangeHeaderValue contentRange) { var log = new SysLogModel(context: context); var result = context.Authenticated ? BinaryUtilities.UploadFile(context, id, contentRange) : Messages.ResponseAuthentication(context: context).ToJson(); log.Finish(context: context, responseSize: result.Length); return(result); }
public ActionResult Show(string reference, string guid) { var log = new SysLogModel(); var file = BinaryUtilities.Donwload(guid); log.Finish(file?.FileContents.Length ?? 0); return(file != null ? File(file.FileContents, file.ContentType) : null); }
public string UploadImage(string reference, long id, HttpPostedFileBase[] file) { var context = new Context(files: file); var log = new SysLogModel(context: context); var json = BinaryUtilities.UploadImage( context: context, id: id); log.Finish(context: context, responseSize: json.Length); return(json); }
public ActionResult Show(string guid) { var context = new Context(); var log = new SysLogModel(context: context); var file = BinaryUtilities.Donwload(context: context, guid: guid); log.Finish(context: context, responseSize: file?.FileContents.Length ?? 0); return(file != null ? File(file.FileContents, file.ContentType) : null); }
public ActionResult SiteImageIcon(string reference, long id) { if (reference.ToLower() == "items") { var bytes = BinaryUtilities.SiteImageIcon(new SiteModel(id)); return(new FileContentResult(bytes, "image/png")); } else { return(null); } }
public string DeleteTenantImage(IContext context) { var ss = SiteSettingsUtilities.TenantsSiteSettings(context); var tenantModel = new TenantModel(context, ss).Get(context, ss); var log = new SysLogModel(context: context); var json = BinaryUtilities.DeleteTenantImage( context: context, tenantModel: tenantModel); log.Finish(context: context); return(json); }