public bool Check(OleDbConnection connection) { var reader = ADOSQLHelper.ExecuteReader(connection, _SQL); if (reader == null) { return(false); } while (reader.Read()) { var keyValue = reader[0].ToString().Trim(); var checkValue = reader[0].ToString().Trim(); if (string.IsNullOrEmpty(keyValue) == false) { if (Values.Contains(checkValue) == false) { Messages2.Add(new Models.VillageMessage { Value = keyValue, Description = string.Format("【{0}={1}】不符合【{2}】", Key, keyValue, Name), WhereClause = string.Format("[{0}] = '{1}'", Key, keyValue) }); //Messages.Add(keyValue); } } } return(true); }
/// <summary> /// Translates the number format to RTF. /// </summary> protected void TranslateFormat() { switch (_numericField.Format) { case "": break; case "ROMAN": _rtfWriter.WriteText(@" \*ROMAN"); break; case "roman": _rtfWriter.WriteText(@" \*roman"); break; case "ALPHABETIC": _rtfWriter.WriteText(@" \*ALPHABETIC"); break; case "alphabetic": _rtfWriter.WriteText(@" \*alphabetic"); break; default: Debug.WriteLine(Messages2.InvalidNumericFieldFormat(_numericField.Format), "warning"); break; } }
private void SendMessage2(IMessage message) { if (message.Key.Equals(string.Empty) == false && props.Contains(message.Key.ToString()) && biDirectional == true) { message = new Message(message.From, node1.Key, message.Key, message.Content); if (message.Key.Equals(nameof(node1.X))) { RaisePropertyChanged(nameof(this.X2)); } if (message.Key.Equals(nameof(node1.Y))) { RaisePropertyChanged(nameof(this.Y2)); message = Modify(message, node2.Size); } MovePoint2To1(); Task.Delay(Delay).ContinueWith(a => { Messages2.Add(message); node1.NextMessage(message); }, TaskScheduler.FromCurrentSynchronizationContext()); } }
public bool Check(OleDbConnection connection) { var reader = ADOSQLHelper.ExecuteReader(connection, _SQL); if (reader == null) { return(false); } var list = new List <string>(); while (reader.Read()) { var keyValue = reader[0].ToString().Trim(); if (string.IsNullOrEmpty(keyValue) == false) { var str = string.Format("{0}:{1}", reader[2].ToString().Trim(), reader[1].ToString().Trim()); if (list.Contains(str)) { Messages2.Add(new Models.VillageMessage { Value = keyValue, CheckValue = str, Description = string.Format("【{0} ={1}】对应的数据不符合【{2}】", Key, keyValue, Name), WhereClause = string.Format("[{0}] = '{1}'", Key, keyValue) }); } else { list.Add(str); } } } return(true); }
/// <summary> /// Renders an image to RTF. /// </summary> internal override void Render() { bool renderInParagraph = RenderInParagraph(); DocumentElements elms = DocumentRelations.GetParent(_image) as DocumentElements; if (elms != null && !renderInParagraph && !(DocumentRelations.GetParent(elms) is Section || DocumentRelations.GetParent(elms) is HeaderFooter)) { Debug.WriteLine(Messages2.ImageFreelyPlacedInWrongContext(_image.Name), "warning"); return; } if (renderInParagraph) { StartDummyParagraph(); } if (!_isInline) { StartShapeArea(); } RenderImage(); if (!_isInline) { EndShapeArea(); } if (renderInParagraph) { EndDummyParagraph(); } }
private void CheckMessage(int message, Socket clientSocket) { Messages2 mess = Messages2.Null; mess = (Messages2)message; switch (mess) { case Messages2.GetUserCards: Debug.WriteLine("GetUserCards message received!"); SendCards(clientSocket); break; case Messages2.GetOtherPlayerNames: Debug.WriteLine("GetOtherPlayerNames message received!"); SendOtherPlayerNames(clientSocket); break; case Messages2.GetCurrentCard: Debug.WriteLine("GetCurrentCard received!"); SendCurrentCard(clientSocket); break; case Messages2.GetOtherPlayerCards: Debug.WriteLine("GetOtherPlayerCards received!"); SendOtherPlayerCards(clientSocket); break; } }
void PrepareDocumentRenderer() { if (_document == null) { throw new InvalidOperationException(Messages2.PropertyNotSetBefore("DocumentRenderer", MethodInfo.GetCurrentMethod().Name)); } _documentRenderer = new DocumentRenderer(_document); _documentRenderer.WorkingDirectory = this.workingDirectory; _documentRenderer.PrepareDocument(); }
void PrepareDocumentRenderer(bool prepareCompletely) { if (_document == null) { throw new InvalidOperationException(Messages2.PropertyNotSetBefore("DocumentRenderer", MethodBase.GetCurrentMethod().Name)); } if (_documentRenderer == null) { _documentRenderer = new DocumentRenderer(_document); _documentRenderer.WorkingDirectory = _workingDirectory; } if (prepareCompletely && _documentRenderer.FormattedDocument == null) { _documentRenderer.PrepareDocument(); } }
public bool Check(OleDbConnection connection) { var reader = ADOSQLHelper.ExecuteReader(connection, _SQL); if (reader == null) { return(false); } while (reader.Read()) { var keyValue = reader[0].ToString().Trim(); if (string.IsNullOrEmpty(keyValue) == false) { var temp = new List <string>(); for (var i = 0; i < CheckFields.Count(); i++) { var a = reader[i + 1].ToString().Trim(); if (string.IsNullOrEmpty(RegexString) == false && Is_Nullable == false) { if (Regex.IsMatch(a, RegexString) == false) { temp.Add(CheckFields[i]); } } else { if (Is_Nullable ^ string.IsNullOrEmpty(a)) { temp.Add(CheckFields[i]); } } } if (temp.Count > 0) { Messages2.Add(new Models.VillageMessage { Value = keyValue, Description = string.Format("【{0} = {1}】对应的字段【{2}】值不符合【{3}】", Key, keyValue, string.Join(",", temp.ToArray()), Name), WhereClause = string.Format("[{0}] = '{1}'", Key, keyValue) }); } } } return(true); }
internal override void Format(Area area, FormatInfo previousFormatInfo) { _imageFilePath = _image.GetFilePath(_documentRenderer.WorkingDirectory); // The Image is stored in the string if path starts with "base64:", otherwise we check whether the file exists. if (!_imageFilePath.StartsWith("base64:") && !XImage.ExistsFile(_imageFilePath)) { _failure = ImageFailure.FileNotFound; Debug.WriteLine(Messages2.ImageNotFound(_image.Name), "warning"); } ImageFormatInfo formatInfo = (ImageFormatInfo)_renderInfo.FormatInfo; formatInfo.Failure = _failure; formatInfo.ImagePath = _imageFilePath; CalculateImageDimensions(); base.Format(area, previousFormatInfo); }
static string AsRoman(int number, bool lowercase) { if (Math.Abs(number) > 32768) { Debug.WriteLine(Messages2.NumberTooLargeForRoman(number), "warning"); return(number.ToString(CultureInfo.InvariantCulture)); } if (number == 0) { return("0"); } string res = ""; if (number < 0) { res += "-"; } number = Math.Abs(number); string[] roman; if (lowercase) { roman = new string[] { "m", "cm", "d", "cd", "c", "xc", "l", "xl", "x", "ix", "v", "iv", "i" } } ; else { roman = new string[] { "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I" } }; int[] numberValues = new int[] { 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 }; for (int i = 0; i < numberValues.Length; ++i) { while (number >= numberValues[i]) { res += roman[i]; number -= numberValues[i]; } } return(res); }
private void RenderSourceType() { string extension = Path.GetExtension(_filePath); if (extension == null) { _imageFile = null; Debug.WriteLine("No Image type given.", "warning"); return; } switch (extension.ToLower()) { case ".jpeg": case ".jpg": _rtfWriter.WriteControl("jpegblip"); break; case ".png": _rtfWriter.WriteControl("pngblip"); break; case ".gif": _rtfWriter.WriteControl("pngblip"); break; case ".pdf": // Show a PDF logo in RTF document #if !NETFX_CORE && !NETCORE _imageFile = Assembly.GetExecutingAssembly().GetManifestResourceStream("MigraDoc.RtfRendering.Resources.PDF.png"); #else _imageFile = typeof(ImageRenderer).GetTypeInfo().Assembly.GetManifestResourceStream("MigraDoc.RtfRendering.Resources.PDF.png"); #endif _rtfWriter.WriteControl("pngblip"); break; default: Debug.WriteLine(Messages2.ImageTypeNotSupported(_image.Name), "warning"); _imageFile = null; break; } }
private void ReceiveCallback(IAsyncResult ar) { List <int> message_list = (List <int>)ar.AsyncState; int message_int = message_list.Last(); int receivedSize = clientState.clientSocket.EndReceive(ar); try { Debug.WriteLine("Client received a message, size: " + receivedSize); Messages2 message = (Messages2)message_int; switch (message) { case (Messages2.GetCurrentCard): UpdateCurrentCard(receivedSize); OnCurrentCardReceived(); SendMessage(message_list); break; case (Messages2.GetOtherPlayerCards): UpdateOtherPlayerCards(receivedSize); OnOtherPlayerCardsReceived(); SendMessage(message_list); break; case (Messages2.GetOtherPlayerNames): UpdateOtherPlayerNames(receivedSize); OnOtherPlayerNamesReceived(); SendMessage(message_list); break; case (Messages2.GetUserCards): UpdateUserCards(receivedSize); OnUserCardsReceived(); SendMessage(message_list); break; } } catch (Exception e) { Debug.WriteLine(e.ToString()); } }
static string AsLetters(int number, bool lowercase) { if (Math.Abs(number) > 32768) { Debug.WriteLine(Messages2.NumberTooLargeForLetters(number)); return(number.ToString()); } if (number == 0) { return("0"); } string str = ""; if (number < 0) { str += "-"; } number = Math.Abs(number); char cr; if (lowercase) { cr = (char)('a' + (number - 1) % 26); } else { cr = (char)('A' + (number - 1) % 26); } for (int n = 0; n <= (number - 1) / 26; ++n) { str += cr; } return(str); }
public bool Check(OleDbConnection connection) { var reader = ADOSQLHelper.ExecuteReader(connection, _SQL); if (reader == null) { return(false); } while (reader.Read()) { var keyValue = reader[0].ToString().Trim(); if (string.IsNullOrEmpty(keyValue) == false) { var value = reader[1].ToString().Trim(); var flag = false; foreach (var item in RegexStrings) { if (Regex.IsMatch(value, item)) { flag = true; break; } } if (flag == false) { Messages2.Add(new Models.VillageMessage { Value = keyValue, CheckValue = value, Description = string.Format("【{0}={1}】对应的数据不符合【{2}】", Key, keyValue, Name), WhereClause = string.Format("[{0}] = '{1}'", Key, keyValue) }); } } } return(true); }
public bool Check(OleDbConnection connection) { var reader = ADOSQLHelper.ExecuteReader(connection, _SQL); if (reader == null) { return(false); } while (reader.Read()) { var keyValue = reader[0].ToString().Trim(); if (string.IsNullOrEmpty(keyValue) == false) { var value1 = reader[1].ToString().Trim(); var value2 = reader[2].ToString().Trim(); if (string.IsNullOrEmpty(value1) == false && string.IsNullOrEmpty(value2) == false) { if (CurrentDict.ContainsKey(value1)) { if (CurrentDict[value1].ToLower() != value2.ToLower()) { Messages2.Add(new Models.VillageMessage { Value = keyValue, CheckValue = value1 + ";" + value2, Description = string.Format("【{0}={1}】对应的数据不符合【{2}】", Key, keyValue, Name), WhereClause = string.Format("[{0}] = '{1}'", Key, keyValue) }); } } } } } return(true); }
private void CalculateImageDimensions() { XImage bip = null; try { _imageFile = File.OpenRead(_filePath); //System.Drawing.Bitmap bip2 = new System.Drawing.Bitmap(imageFile); bip = XImage.FromFile(_filePath); float horzResolution; float vertResolution; string ext = Path.GetExtension(_filePath).ToLower(); float origHorzRes = (float)bip.HorizontalResolution; float origVertRes = (float)bip.VerticalResolution; _originalHeight = bip.PixelHeight * 72 / origVertRes; _originalWidth = bip.PixelWidth * 72 / origHorzRes; if (_image.IsNull("Resolution")) { horzResolution = (ext == ".gif") ? 72 : (float)bip.HorizontalResolution; vertResolution = (ext == ".gif") ? 72 : (float)bip.VerticalResolution; } else { horzResolution = (float)GetValueAsIntended("Resolution"); vertResolution = horzResolution; } Unit origHeight = bip.Size.Height * 72 / vertResolution; Unit origWidth = bip.Size.Width * 72 / horzResolution; _imageHeight = origHeight; _imageWidth = origWidth; bool scaleWidthIsNull = _image.IsNull("ScaleWidth"); bool scaleHeightIsNull = _image.IsNull("ScaleHeight"); float sclHeight = scaleHeightIsNull ? 1 : (float)GetValueAsIntended("ScaleHeight"); _scaleHeight = sclHeight; float sclWidth = scaleWidthIsNull ? 1 : (float)GetValueAsIntended("ScaleWidth"); _scaleWidth = sclWidth; bool doLockAspectRatio = _image.IsNull("LockAspectRatio") || _image.LockAspectRatio; if (doLockAspectRatio && (scaleHeightIsNull || scaleWidthIsNull)) { if (!_image.IsNull("Width") && _image.IsNull("Height")) { _imageWidth = _image.Width; _imageHeight = origHeight * _imageWidth / origWidth; } else if (!_image.IsNull("Height") && _image.IsNull("Width")) { _imageHeight = _image.Height; _imageWidth = origWidth * _imageHeight / origHeight; } else if (!_image.IsNull("Height") && !_image.IsNull("Width")) { _imageWidth = _image.Width; _imageHeight = _image.Height; } if (scaleWidthIsNull && !scaleHeightIsNull) { _scaleWidth = _scaleHeight; } else if (scaleHeightIsNull && !scaleWidthIsNull) { _scaleHeight = _scaleWidth; } } else { if (!_image.IsNull("Width")) { _imageWidth = _image.Width; } if (!_image.IsNull("Height")) { _imageHeight = _image.Height; } } return; } catch (FileNotFoundException) { Debug.WriteLine(Messages2.ImageNotFound(_image.Name), "warning"); } catch (Exception exc) { Debug.WriteLine(Messages2.ImageNotReadable(_image.Name, exc.Message), "warning"); } finally { if (bip != null) { bip.Dispose(); } } //Setting defaults in case an error occured. _imageFile = null; _imageHeight = (Unit)GetValueOrDefault("Height", Unit.FromInch(1)); _imageWidth = (Unit)GetValueOrDefault("Width", Unit.FromInch(1)); _scaleHeight = (double)GetValueOrDefault("ScaleHeight", 1.0); _scaleWidth = (double)GetValueOrDefault("ScaleWidth", 1.0); }
private void CalculateImageDimensions() { ImageFormatInfo formatInfo = (ImageFormatInfo)_renderInfo.FormatInfo; if (formatInfo.Failure == ImageFailure.None) { XImage xImage = null; try { //xImage = XImage.FromFile(_imageFilePath); xImage = CreateXImage(_imageFilePath); } catch (InvalidOperationException ex) { Debug.WriteLine(Messages2.InvalidImageType(ex.Message)); formatInfo.Failure = ImageFailure.InvalidType; } if (formatInfo.Failure == ImageFailure.None) { try { XUnit usrWidth = _image.Width.Point; XUnit usrHeight = _image.Height.Point; bool usrWidthSet = !_image._width.IsNull; bool usrHeightSet = !_image._height.IsNull; XUnit resultWidth = usrWidth; XUnit resultHeight = usrHeight; Debug.Assert(xImage != null); double xPixels = xImage.PixelWidth; bool usrResolutionSet = !_image._resolution.IsNull; double horzRes = usrResolutionSet ? _image.Resolution : xImage.HorizontalResolution; double vertRes = usrResolutionSet ? _image.Resolution : xImage.VerticalResolution; // ReSharper disable CompareOfFloatsByEqualityOperator if (horzRes == 0 && vertRes == 0) { horzRes = 72; vertRes = 72; } else if (horzRes == 0) { Debug.Assert(false, "How can this be?"); horzRes = 72; } else if (vertRes == 0) { Debug.Assert(false, "How can this be?"); vertRes = 72; } // ReSharper restore CompareOfFloatsByEqualityOperator XUnit inherentWidth = XUnit.FromInch(xPixels / horzRes); double yPixels = xImage.PixelHeight; XUnit inherentHeight = XUnit.FromInch(yPixels / vertRes); //bool lockRatio = _image.IsNull("LockAspectRatio") ? true : _image.LockAspectRatio; bool lockRatio = _image._lockAspectRatio.IsNull || _image.LockAspectRatio; double scaleHeight = _image.ScaleHeight; double scaleWidth = _image.ScaleWidth; //bool scaleHeightSet = !_image.IsNull("ScaleHeight"); //bool scaleWidthSet = !_image.IsNull("ScaleWidth"); bool scaleHeightSet = !_image._scaleHeight.IsNull; bool scaleWidthSet = !_image._scaleWidth.IsNull; if (lockRatio && !(scaleHeightSet && scaleWidthSet)) { if (usrWidthSet && !usrHeightSet) { resultHeight = inherentHeight / inherentWidth * usrWidth; } else if (usrHeightSet && !usrWidthSet) { resultWidth = inherentWidth / inherentHeight * usrHeight; } // ReSharper disable once ConditionIsAlwaysTrueOrFalse else if (!usrHeightSet && !usrWidthSet) { resultHeight = inherentHeight; resultWidth = inherentWidth; } if (scaleHeightSet) { resultHeight = resultHeight * scaleHeight; resultWidth = resultWidth * scaleHeight; } if (scaleWidthSet) { resultHeight = resultHeight * scaleWidth; resultWidth = resultWidth * scaleWidth; } } else { if (!usrHeightSet) { resultHeight = inherentHeight; } if (!usrWidthSet) { resultWidth = inherentWidth; } if (scaleHeightSet) { resultHeight = resultHeight * scaleHeight; } if (scaleWidthSet) { resultWidth = resultWidth * scaleWidth; } } formatInfo.CropWidth = (int)xPixels; formatInfo.CropHeight = (int)yPixels; if (_image._pictureFormat != null && !_image._pictureFormat.IsNull()) { PictureFormat picFormat = _image.PictureFormat; //Cropping in pixels. XUnit cropLeft = picFormat.CropLeft.Point; XUnit cropRight = picFormat.CropRight.Point; XUnit cropTop = picFormat.CropTop.Point; XUnit cropBottom = picFormat.CropBottom.Point; formatInfo.CropX = (int)(horzRes * cropLeft.Inch); formatInfo.CropY = (int)(vertRes * cropTop.Inch); formatInfo.CropWidth -= (int)(horzRes * ((XUnit)(cropLeft + cropRight)).Inch); formatInfo.CropHeight -= (int)(vertRes * ((XUnit)(cropTop + cropBottom)).Inch); //Scaled cropping of the height and width. double xScale = resultWidth / inherentWidth; double yScale = resultHeight / inherentHeight; cropLeft = xScale * cropLeft; cropRight = xScale * cropRight; cropTop = yScale * cropTop; cropBottom = yScale * cropBottom; resultHeight = resultHeight - cropTop - cropBottom; resultWidth = resultWidth - cropLeft - cropRight; } if (resultHeight <= 0 || resultWidth <= 0) { formatInfo.Width = XUnit.FromCentimeter(2.5); formatInfo.Height = XUnit.FromCentimeter(2.5); Debug.WriteLine(Messages2.EmptyImageSize); _failure = ImageFailure.EmptySize; } else { formatInfo.Width = resultWidth; formatInfo.Height = resultHeight; } } catch (Exception ex) { Debug.WriteLine(Messages2.ImageNotReadable(_image.Name, ex.Message)); formatInfo.Failure = ImageFailure.NotRead; } finally { if (xImage != null) { xImage.Dispose(); } } } } if (formatInfo.Failure != ImageFailure.None) { if (!_image._width.IsNull) { formatInfo.Width = _image.Width.Point; } else { formatInfo.Width = XUnit.FromCentimeter(2.5); } if (!_image._height.IsNull) { formatInfo.Height = _image.Height.Point; } else { formatInfo.Height = XUnit.FromCentimeter(2.5); } } }
/// <summary> /// Renders a barcode to RTF. /// </summary> internal override void Render() { Debug.WriteLine(Messages2.BarcodeNotSupported(_barcode.Code), "warning"); }
/// <summary> /// Translates the date field format to RTF. /// </summary> private void TranslateFormat() { string domFrmt = _dateField.Format; string rtfFrmt = domFrmt; //The format is translated using the current culture. DateTimeFormatInfo dtfInfo = CultureInfo.CurrentCulture.DateTimeFormat; if (domFrmt == "") { rtfFrmt = dtfInfo.ShortDatePattern + " " + dtfInfo.LongTimePattern; } else if (domFrmt.Length == 1) { switch (domFrmt) { case "d": rtfFrmt = dtfInfo.ShortDatePattern; break; case "D": rtfFrmt = dtfInfo.LongDatePattern; break; case "T": rtfFrmt = dtfInfo.LongTimePattern; break; case "t": rtfFrmt = dtfInfo.ShortTimePattern; break; case "f": rtfFrmt = dtfInfo.LongDatePattern + " " + dtfInfo.ShortTimePattern; break; case "F": rtfFrmt = dtfInfo.FullDateTimePattern; break; case "G": rtfFrmt = dtfInfo.ShortDatePattern + " " + dtfInfo.LongTimePattern; break; case "g": rtfFrmt = dtfInfo.ShortDatePattern + " " + dtfInfo.ShortTimePattern; break; case "M": case "m": rtfFrmt = dtfInfo.MonthDayPattern; break; case "R": case "r": rtfFrmt = dtfInfo.RFC1123Pattern; break; case "s": rtfFrmt = dtfInfo.SortableDateTimePattern; break; //TODO: Output universal time for u und U. case "u": rtfFrmt = dtfInfo.UniversalSortableDateTimePattern; break; case "U": rtfFrmt = dtfInfo.FullDateTimePattern; break; case "Y": case "y": rtfFrmt = dtfInfo.YearMonthPattern; break; default: break; } } bool isEscaped = false; bool isQuoted = false; bool isSingleQuoted = false; string rtfFrmt2 = "\\@ \""; foreach (char c in rtfFrmt) { switch (c) { case '\\': if (isEscaped) { rtfFrmt2 += "'" + '\\' + "'"; } isEscaped = !isEscaped; break; case '\'': if (isEscaped) { //Doesn't work in word format strings. Debug.WriteLine(Messages2.CharacterNotAllowedInDateFormat(c), "warning"); isEscaped = false; } else if (!isSingleQuoted && !isQuoted) { isSingleQuoted = true; rtfFrmt2 += c; } else if (isQuoted) { rtfFrmt2 += @"\'"; } else if (isSingleQuoted) { isSingleQuoted = false; rtfFrmt2 += c; } break; case '"': if (isEscaped) { rtfFrmt2 += c; isEscaped = false; } else if (!isQuoted && !isSingleQuoted) { isQuoted = true; rtfFrmt2 += '\''; } else if (isQuoted) { isQuoted = false; rtfFrmt2 += '\''; } else if (isSingleQuoted) { rtfFrmt2 += "\\\""; } break; case '/': if (isEscaped || isQuoted || isSingleQuoted) { isEscaped = false; rtfFrmt2 += c; } else { rtfFrmt2 += dtfInfo.DateSeparator; } break; case ':': if (isEscaped || isQuoted || isSingleQuoted) { isEscaped = false; rtfFrmt2 += c; } else { rtfFrmt2 += dtfInfo.TimeSeparator; } break; default: if (isEscaped) { rtfFrmt2 += "'" + c + "'"; } else if (!isQuoted && !isSingleQuoted) { rtfFrmt2 += TranslateCustomFormatChar(c); } else { rtfFrmt2 += c; } isEscaped = false; break; } } _rtfWriter.WriteText(rtfFrmt2 + @""" \* MERGEFORMAT"); }