static void Main () { string str = "123"; object o = int.Parse (str); Console.WriteLine ("1: {0}", o != null); Console.WriteLine ("2: {0}", o.GetType ().FullName); Console.WriteLine ("3: {0}", o.ToString ()); Console.WriteLine (); Conv c = new Conv (int.Parse); o = c (str); Console.WriteLine ("4: {0}", o != null); Console.WriteLine ("5: {0}", o.GetType ().FullName); Console.WriteLine ("6: {0}", o.ToString ()); }
private void AddConversationToDb(Message message) { var db = new TuzobotModelContainer(); var conv = db.ConvSet.SingleOrDefault(c=>c.ConversationId == message.ConversationId); if(conv==null) { Conv newConversation = new Conv(); newConversation.ConversationId = message.ConversationId; newConversation.UserAddress = message.From.Address; newConversation.BotAddress = message.To.Address; newConversation.LastActive = DateTime.UtcNow; newConversation.ChannelId = message.From.ChannelId; db.ConvSet.Add(newConversation); } else { conv.LastActive = DateTime.UtcNow; } db.SaveChanges(); }
public static void Main() { Conv c = new Conv(int.Parse); }
private void show() { int num = 15; GUIStyle style = GUI.skin.GetStyle("Label"); style.fontSize = GuiBase.FontSize(14); style.alignment = TextAnchor.UpperLeft; GUI.BeginGroup(new Rect(GuiBase.Width(290f), GuiBase.Height(110f), GuiBase.Width(660f), GuiBase.Height(480f))); style.fontStyle = FontStyle.Bold; GUI.Box(new Rect(GuiBase.Width(0f), GuiBase.Height(0f), GuiBase.Width(660f), GuiBase.Height(480f)), string.Empty); Application.targetFrameRate = App.State.GameSettings.Framerate; QualitySettings.vSyncCount = 0; string text = "Lower Framerate means less cpu usage but the gui updates the values less frequently."; if (App.CurrentPlattform == Plattform.Kongregate) { text += "\nSomehow it seems to affect the whole browser so if you use the same browser for other things, don't set it lower than 30."; } GUI.Label(new Rect(GuiBase.Width(20f), GuiBase.Height((float)num), GuiBase.Width(300f), GuiBase.Height(30f)), new GUIContent("Current Framerate: " + App.State.GameSettings.Framerate + " Fps", text)); App.State.GameSettings.Framerate = (int)GUI.HorizontalSlider(new Rect(GuiBase.Width(20f), GuiBase.Height(50f), GuiBase.Width(280f), GuiBase.Height(30f)), (float)App.State.GameSettings.Framerate, 5f, 60f); num += 55; GUI.Label(new Rect(GuiBase.Width(20f), GuiBase.Height((float)num), GuiBase.Width(300f), GuiBase.Height(30f)), new GUIContent("UI Style")); num += 30; App.State.GameSettings.UIStyle = GUI.Toolbar(new Rect(GuiBase.Width(20f), GuiBase.Height((float)num), GuiBase.Width(280f), GuiBase.Height(30f)), App.State.GameSettings.UIStyle, this.UIStyleLeftStrings); num += 35; GUI.Label(new Rect(GuiBase.Width(20f), GuiBase.Height((float)num), GuiBase.Width(300f), GuiBase.Height(30f)), new GUIContent("Font")); num += 28; int num2 = GUI.Toolbar(new Rect(GuiBase.Width(20f), GuiBase.Height((float)num), GuiBase.Width(280f), GuiBase.Height(30f)), App.State.GameSettings.FontType, this.FontStrings); if (num2 != App.State.GameSettings.FontType) { App.State.GameSettings.FontType = num2; Gui.SetFont = true; } num += 35; GUI.Label(new Rect(GuiBase.Width(20f), GuiBase.Height((float)num), GuiBase.Width(300f), GuiBase.Height(30f)), new GUIContent("Progressbars")); num += 28; this.progressBarType = GUI.Toolbar(new Rect(GuiBase.Width(20f), GuiBase.Height((float)num), GuiBase.Width(280f), GuiBase.Height(30f)), this.progressBarType, this.ProgressbarStrings); num += 10; style.fontStyle = FontStyle.Normal; if (!App.State.PossibleCheater) { num += 30; string text2 = "kongregate"; if (App.CurrentPlattform == Plattform.Steam) { text2 = "Steam"; if (App.State.Ext.ImportedSaveFromKongToSteam || App.IsTimeTooOldForSteam) { text2 += ". Highscores for your Save are disabled, so it won't turn in highscores even if you turn this on."; } } App.State.ShouldSubmitScore = GUI.Toggle(new Rect(GuiBase.Width(20f), GuiBase.Height((float)num), GuiBase.Width(235f), GuiBase.Height(25f)), App.State.ShouldSubmitScore, new GUIContent("Submit Highscore", "If this is on, your rebirths, gods defeated and total achievements will be submitted to the highscore in " + text2 + ".")); } num += 30; App.State.GameSettings.SyncScrollbars = GUI.Toggle(new Rect(GuiBase.Width(20f), GuiBase.Height((float)num), GuiBase.Width(260f), GuiBase.Height(25f)), App.State.GameSettings.SyncScrollbars, new GUIContent("Sync Scrollbars", "If this is on, scrollbars from training are synced together.")); num += 30; App.State.GameSettings.ShowAchievementPopups = GUI.Toggle(new Rect(GuiBase.Width(20f), GuiBase.Height((float)num), GuiBase.Width(260f), GuiBase.Height(25f)), App.State.GameSettings.ShowAchievementPopups, new GUIContent("Show Achievement Popups", "If this is on, achievements will show a popup, else not.")); num += 30; App.State.GameSettings.AchievementsOnTop = GUI.Toggle(new Rect(GuiBase.Width(20f), GuiBase.Height((float)num), GuiBase.Width(260f), GuiBase.Height(25f)), App.State.GameSettings.AchievementsOnTop, new GUIContent("Achievements on Top ", "If this is on, the info after an achievement is obtained will be shown top right.")); num += 30; App.State.GameSettings.ShowToolTipsOnTop = GUI.Toggle(new Rect(GuiBase.Width(20f), GuiBase.Height((float)num), GuiBase.Width(260f), GuiBase.Height(25f)), App.State.GameSettings.ShowToolTipsOnTop, new GUIContent("Show Tooltips on Top", "If this is on, tooltips will be shown on top else left to the mouse position.")); num += 30; string text3 = "Tooltips on right click"; string tooltip = "If this is on, tooltips will only be shown if you press the right mouse button."; if (App.CurrentPlattform == Plattform.Android) { text3 = "Disable Tooltips"; tooltip = "If this is on, no tooltips will be shown."; } App.State.GameSettings.ShowToolTipsOnRightClick = GUI.Toggle(new Rect(GuiBase.Width(20f), GuiBase.Height((float)num), GuiBase.Width(260f), GuiBase.Height(25f)), App.State.GameSettings.ShowToolTipsOnRightClick, new GUIContent(text3, tooltip)); num += 30; App.State.GameSettings.StickyClones = GUI.Toggle(new Rect(GuiBase.Width(20f), GuiBase.Height((float)num), GuiBase.Width(260f), GuiBase.Height(25f)), App.State.GameSettings.StickyClones, new GUIContent("Sticky Clones ", "If this is on, Clones will be left on monuments / div gen, even if you don't have enough ressources to build it.")); num = 320; App.State.GameSettings.SoundOn = GUI.Toggle(new Rect(GuiBase.Width(330f), GuiBase.Height((float)num), GuiBase.Width(300f), GuiBase.Height(25f)), App.State.GameSettings.SoundOn, new GUIContent("Music", "If this is on, the game will play some background music.")); num += 30; App.State.GameSettings.UseStopAt = GUI.Toggle(new Rect(GuiBase.Width(330f), GuiBase.Height((float)num), GuiBase.Width(260f), GuiBase.Height(25f)), App.State.GameSettings.UseStopAt, new GUIContent("'Stop at' or 'Next at'", "If this is turned on, clones from the related training will be removed when the value is reached instead of moving to the next one.")); num += 30; this.exponentSettings = GUI.Toggle(new Rect(GuiBase.Width(330f), GuiBase.Height((float)num), GuiBase.Width(260f), GuiBase.Height(25f)), this.exponentSettings, new GUIContent("Use scientific notation", "If this is on, scientific notation will be used instead of spoken names.")); num += 30; App.State.GameSettings.IgnoreCloneCountOn = GUI.Toggle(new Rect(GuiBase.Width(330f), GuiBase.Height((float)num), GuiBase.Width(220f), GuiBase.Height(25f)), App.State.GameSettings.IgnoreCloneCountOn, new GUIContent("Ignore Clonecount", "If this is on, the 'stop at' or 'next at' setting will let up to the count in the input field stay to train.")); num += 30; GUI.Label(new Rect(GuiBase.Width(330f), GuiBase.Height((float)num), GuiBase.Width(210f), GuiBase.Height(30f)), new GUIContent("Save Clones for Fight", "The number of Clones you can't adjust to anything but fighting monsters or pets. So you can use the MAX Button and still have enough clones left to use for fights.")); num -= 30; if (App.CurrentPlattform == Plattform.Android) { GUIStyle textField = Gui.ChosenSkin.textField; if (GUI.Button(new Rect(GuiBase.Width(550f), GuiBase.Height((float)num), GuiBase.Width(65f), GuiBase.Height(25f)), App.State.GameSettings.TrainIgnoreCount + string.Empty, textField)) { base.ShowNumberInput("Ignore Clonecount", App.State.GameSettings.TrainIgnoreCount, 50000, delegate(CDouble x) { App.State.GameSettings.TrainIgnoreCount = x.ToInt(); }); } num += 30; if (GUI.Button(new Rect(GuiBase.Width(550f), GuiBase.Height((float)num), GuiBase.Width(65f), GuiBase.Height(25f)), App.State.GameSettings.SavedClonesForFight + string.Empty, textField)) { base.ShowNumberInput("Save Clones for Fight", App.State.GameSettings.SavedClonesForFight, App.State.Clones.MaxShadowClones, delegate(CDouble x) { App.State.GameSettings.SavedClonesForFight = x.ToInt(); }); } } else { SettingsUi.ignoreClonesString = GUI.TextField(new Rect(GuiBase.Width(550f), GuiBase.Height((float)num), GuiBase.Width(65f), GuiBase.Height(25f)), SettingsUi.ignoreClonesString); num += 30; SettingsUi.IdleClonesString = GUI.TextField(new Rect(GuiBase.Width(550f), GuiBase.Height((float)num), GuiBase.Width(65f), GuiBase.Height(25f)), SettingsUi.IdleClonesString); } int.TryParse(SettingsUi.ignoreClonesString, out App.State.GameSettings.TrainIgnoreCount); if (App.State.GameSettings.TrainIgnoreCount > 50000) { App.State.GameSettings.TrainIgnoreCount = 50000; } if (App.State.GameSettings.TrainIgnoreCount < 1) { App.State.GameSettings.TrainIgnoreCount = 1; } int.TryParse(SettingsUi.IdleClonesString, out App.State.GameSettings.SavedClonesForFight); if (App.State.GameSettings.SavedClonesForFight > App.State.Clones.MaxShadowClones.ToInt()) { App.State.GameSettings.SavedClonesForFight = App.State.Clones.MaxShadowClones.ToInt(); } if (App.State.GameSettings.SavedClonesForFight < 0) { App.State.GameSettings.SavedClonesForFight = 0; } if (this.exponentSettings != App.State.GameSettings.UseExponentNumbers) { App.State.GameSettings.UseExponentNumbers = this.exponentSettings; App.State.InitAchievementNames(); foreach (Creation current in App.State.AllCreations) { current.GodToDefeat.InitPowerLevelText(); } } if (this.progressBarType != App.State.GameSettings.ProgressbarType) { App.State.GameSettings.ProgressbarType = this.progressBarType; GuiBase.InitImages(); } num = 15; style.fontStyle = FontStyle.Bold; GUI.Label(new Rect(GuiBase.Width(330f), GuiBase.Height((float)num), GuiBase.Width(300f), GuiBase.Height(30f)), new GUIContent("Adjust Color")); if (GUI.Button(new Rect(GuiBase.Width(525f), GuiBase.Height((float)num), GuiBase.Width(90f), GuiBase.Height(35f)), new GUIContent("Default", "Reverts to the default color of the style."))) { this.Red = (this.Blue = (this.Green = 1f)); } style.fontStyle = FontStyle.Normal; num += 50; GUI.Label(new Rect(GuiBase.Width(330f), GuiBase.Height((float)(num - 7)), GuiBase.Width(60f), GuiBase.Height(30f)), new GUIContent("Red")); this.Red = GUI.HorizontalSlider(new Rect(GuiBase.Width(380f), GuiBase.Height((float)num), GuiBase.Width(235f), GuiBase.Height(30f)), this.Red, 0f, 1f); num += 35; GUI.Label(new Rect(GuiBase.Width(330f), GuiBase.Height((float)(num - 7)), GuiBase.Width(60f), GuiBase.Height(30f)), new GUIContent("Green")); this.Green = GUI.HorizontalSlider(new Rect(GuiBase.Width(380f), GuiBase.Height((float)num), GuiBase.Width(235f), GuiBase.Height(30f)), this.Green, 0f, 1f); num += 35; GUI.Label(new Rect(GuiBase.Width(330f), GuiBase.Height((float)(num - 7)), GuiBase.Width(60f), GuiBase.Height(30f)), new GUIContent("Blue")); this.Blue = GUI.HorizontalSlider(new Rect(GuiBase.Width(380f), GuiBase.Height((float)num), GuiBase.Width(235f), GuiBase.Height(30f)), this.Blue, 0f, 1f); this.UiColor.r = this.Red; this.UiColor.b = this.Blue; this.UiColor.g = this.Green; App.State.GameSettings.CustomColor = Conv.ColorToString(this.UiColor); style.fontStyle = FontStyle.Bold; num += 30; GUI.Label(new Rect(GuiBase.Width(330f), GuiBase.Height((float)num), GuiBase.Width(300f), GuiBase.Height(30f)), new GUIContent("Background Color")); style.fontStyle = FontStyle.Normal; num += 40; GUI.Label(new Rect(GuiBase.Width(330f), GuiBase.Height((float)(num - 7)), GuiBase.Width(60f), GuiBase.Height(30f)), new GUIContent("Red")); this.RedBG = GUI.HorizontalSlider(new Rect(GuiBase.Width(380f), GuiBase.Height((float)num), GuiBase.Width(235f), GuiBase.Height(30f)), this.RedBG, 0f, 1f); num += 35; GUI.Label(new Rect(GuiBase.Width(330f), GuiBase.Height((float)(num - 7)), GuiBase.Width(60f), GuiBase.Height(30f)), new GUIContent("Green")); this.GreenBG = GUI.HorizontalSlider(new Rect(GuiBase.Width(380f), GuiBase.Height((float)num), GuiBase.Width(235f), GuiBase.Height(30f)), this.GreenBG, 0f, 1f); num += 35; GUI.Label(new Rect(GuiBase.Width(330f), GuiBase.Height((float)(num - 7)), GuiBase.Width(60f), GuiBase.Height(30f)), new GUIContent("Blue")); this.BlueBG = GUI.HorizontalSlider(new Rect(GuiBase.Width(380f), GuiBase.Height((float)num), GuiBase.Width(235f), GuiBase.Height(30f)), this.BlueBG, 0f, 1f); this.BGColor.r = this.RedBG; this.BGColor.b = this.BlueBG; this.BGColor.g = this.GreenBG; App.State.GameSettings.CustomBackground = Conv.ColorToString(this.BGColor); GUI.EndGroup(); }
private void ImportItems(string fileName) { List <Items> con; List <Copies> copies; if (Path.GetExtension(fileName) == "csv") { con = global.ImportItemsCSV(fileName, out copies); } else { con = global.ImportItemsXML(fileName, out copies); } if (con == null) { Dialogs.ShowErr(Lng.Get("ParseFileError", "Parse file error") + ".", Lng.Get("Error")); return; } databaseEntities db = new databaseEntities(); foreach (var item in con) { Items itm; // ----- ID ----- if (item.ID != Guid.Empty) { itm = db.Items.Find(item.ID); if (itm != null) { Conv.CopyClassPropetries(itm, item); } else { db.Items.Add(item); } } else { item.ID = Guid.NewGuid(); db.Items.Add(item); } } foreach (var item in copies) { Copies itm; // ----- ID ----- if (item.ID != Guid.Empty) { itm = db.Copies.Find(item.ID); if (itm != null) { FillCopy(ref itm, item); } else { db.Copies.Add(item); } } else { item.ID = Guid.NewGuid(); db.Copies.Add(item); } } db.SaveChanges(); UpdateItemsOLV(); Dialogs.ShowInfo(Lng.Get("SuccesfullyImport", "Import was succesfully done") + ".", Lng.Get("Import")); }
public static void ShowError(Exception ex) { ShowError(System.Windows.Forms.Form.ActiveForm, Conv.GetErrorMessage(ex, IsDebug)); }
ILInstruction MakeDynamicInstruction(CallSiteInfo callsite, CallVirt targetInvokeCall, List <ILInstruction> deadArguments) { switch (callsite.Kind) { case BinderMethodKind.BinaryOperation: deadArguments.AddRange(targetInvokeCall.Arguments.Take(2)); return(new DynamicBinaryOperatorInstruction( binderFlags: callsite.Flags, operation: callsite.Operation, context: callsite.Context, leftArgumentInfo: callsite.ArgumentInfos[0], left: targetInvokeCall.Arguments[2], rightArgumentInfo: callsite.ArgumentInfos[1], right: targetInvokeCall.Arguments[3] )); case BinderMethodKind.Convert: deadArguments.AddRange(targetInvokeCall.Arguments.Take(2)); ILInstruction result = new DynamicConvertInstruction( binderFlags: callsite.Flags, context: callsite.Context, type: callsite.ConvertTargetType, argument: targetInvokeCall.Arguments[2] ); if (result.ResultType == StackType.Unknown) { // if references are missing, we need to coerce the primitive type to None. // Otherwise we will get loads of assertions. result = new Conv(result, PrimitiveType.None, ((DynamicConvertInstruction)result).IsChecked, Sign.None); } return(result); case BinderMethodKind.GetIndex: deadArguments.AddRange(targetInvokeCall.Arguments.Take(2)); return(new DynamicGetIndexInstruction( binderFlags: callsite.Flags, context: callsite.Context, argumentInfo: callsite.ArgumentInfos, arguments: targetInvokeCall.Arguments.Skip(2).ToArray() )); case BinderMethodKind.GetMember: deadArguments.AddRange(targetInvokeCall.Arguments.Take(2)); return(new DynamicGetMemberInstruction( binderFlags: callsite.Flags, name: callsite.MemberName, context: callsite.Context, targetArgumentInfo: callsite.ArgumentInfos[0], target: targetInvokeCall.Arguments[2] )); case BinderMethodKind.Invoke: deadArguments.AddRange(targetInvokeCall.Arguments.Take(2)); return(new DynamicInvokeInstruction( binderFlags: callsite.Flags, context: callsite.Context, argumentInfo: callsite.ArgumentInfos, arguments: targetInvokeCall.Arguments.Skip(2).ToArray() )); case BinderMethodKind.InvokeConstructor: var arguments = targetInvokeCall.Arguments.Skip(2).ToArray(); // Extract type information from targetInvokeCall: // Must either be an inlined type or // a reference to a variable that is initialized with a type. if (!TransformExpressionTrees.MatchGetTypeFromHandle(arguments[0], out var type)) { if (!(arguments[0].MatchLdLoc(out var temp) && temp.IsSingleDefinition && temp.StoreInstructions.FirstOrDefault() is StLoc initStore)) { return(null); } if (!TransformExpressionTrees.MatchGetTypeFromHandle(initStore.Value, out type)) { return(null); } } deadArguments.AddRange(targetInvokeCall.Arguments.Take(2)); return(new DynamicInvokeConstructorInstruction( binderFlags: callsite.Flags, type: type ?? SpecialType.UnknownType, context: callsite.Context, argumentInfo: callsite.ArgumentInfos, arguments: arguments )); case BinderMethodKind.InvokeMember: deadArguments.AddRange(targetInvokeCall.Arguments.Take(2)); return(new DynamicInvokeMemberInstruction( binderFlags: callsite.Flags, name: callsite.MemberName, typeArguments: callsite.TypeArguments, context: callsite.Context, argumentInfo: callsite.ArgumentInfos, arguments: targetInvokeCall.Arguments.Skip(2).ToArray() )); case BinderMethodKind.IsEvent: deadArguments.AddRange(targetInvokeCall.Arguments.Take(2)); return(new DynamicIsEventInstruction( binderFlags: callsite.Flags, name: callsite.MemberName, context: callsite.Context, argument: targetInvokeCall.Arguments[2] )); case BinderMethodKind.SetIndex: deadArguments.AddRange(targetInvokeCall.Arguments.Take(2)); return(new DynamicSetIndexInstruction( binderFlags: callsite.Flags, context: callsite.Context, argumentInfo: callsite.ArgumentInfos, arguments: targetInvokeCall.Arguments.Skip(2).ToArray() )); case BinderMethodKind.SetMember: deadArguments.AddRange(targetInvokeCall.Arguments.Take(2)); return(new DynamicSetMemberInstruction( binderFlags: callsite.Flags, name: callsite.MemberName, context: callsite.Context, targetArgumentInfo: callsite.ArgumentInfos[0], target: targetInvokeCall.Arguments[2], valueArgumentInfo: callsite.ArgumentInfos[1], value: targetInvokeCall.Arguments[3] )); case BinderMethodKind.UnaryOperation: deadArguments.AddRange(targetInvokeCall.Arguments.Take(2)); return(new DynamicUnaryOperatorInstruction( binderFlags: callsite.Flags, operation: callsite.Operation, context: callsite.Context, operandArgumentInfo: callsite.ArgumentInfos[0], operand: targetInvokeCall.Arguments[2] )); default: throw new ArgumentOutOfRangeException($"Value {callsite.Kind} is not supported!"); } }
public void TestTo_DateTimeOrNull_Invalid() { Assert.IsNull(Conv.To <DateTime?>("1A")); }
public void UpdateDuration(long ms) { if (App.State == null) { return; } if (this.CreationDuration == 0) { this.InitDuration(App.State); } if (this.isCreating) { if (App.State.CreatingPowerBase <= 0) { GuiBase.ShowToast("You need more creating power to create a " + this.CreationName); this.isCreating = false; this.GoBackToCreating(); return; } if (this.CurrentCreationDuration <= 0) { Creation creation = App.State.AllCreations.FirstOrDefault((Creation x) => x.TypeEnum == this.CreationNeeded); if (creation.count == 0) { this.isCreating = false; GuiBase.ShowToast("You need one " + creation.Name + " to create a " + this.CreationName); this.GoBackToCreating(); return; } Creation expr_EB = creation; expr_EB.count = --expr_EB.count; } CDouble rightSide = App.State.CreationSpeed(ms); this.CurrentCreationDuration += rightSide; CDouble cDouble = (this.CreationDuration - this.CurrentCreationDuration) * 30 / rightSide; string text = "Time to finish: " + Conv.MsToGuiText(cDouble.ToLong(), true); CDouble cDouble2 = this.CreationLoss / this.CreationDuration * rightSide; App.State.CreatingPowerBase -= cDouble2; if (App.State.CreatingPowerBase < 0) { App.State.CreatingPowerBase = 0; } CDouble cDouble3 = cDouble2 * App.State.Multiplier.CurrentMultiCreating * (100 + App.State.PremiumBoni.GpBoniCreating); cDouble3 = App.State.AdditionalMultis(cDouble3); if (this.CreationDuration > 0 && this.CurrentCreationDuration > this.CreationDuration) { this.CurrentCreationDuration = 0; this.CreationCount = ++this.CreationCount; if (this.CreationCount >= this.StopAt && this.StopAt != 0) { this.isCreating = false; this.GoBackToCreating(); } } this.CreationDescription = string.Concat(new string[] { this.CreationDescriptionBase, "\nYou will lose ", cDouble3.ToGuiText(true), " Creating every second while creating this.\n", text }); } if (this.HPPercent < 100) { this.HPPercent += 1.67E-05 * (double)ms; } }
public void TestTo_Double_Invalid() { Assert.AreEqual(0, Conv.To <double>("1A")); }
public void TestTo_DoubleOrNull_Invalid() { Assert.IsNull(Conv.To <double?>("1A")); }
public void TestTo_GuidOrNull() { Assert.AreEqual(new Guid("B9EB56E9-B720-40B4-9425-00483D311DDC"), Conv.To <Guid?>("B9EB56E9-B720-40B4-9425-00483D311DDC")); }
public void TestTo_String() { Assert.AreEqual("123", Conv.To <string>(123)); }
public void TestTo_GuidOrNull_Invalid() { Assert.IsNull(Conv.To <Guid?>("1A")); }
public void TestTo_Guid_Invalid() { Assert.AreEqual(Guid.Empty, Conv.To <Guid>("1A")); }
public void TestTo_IntOrNull() { Assert.AreEqual(1, Conv.To <int?>("1")); }
public void TestTo_IntOrNull_Invalid() { Assert.IsNull(Conv.To <int?>("1A")); }
public void TestTo_DoubleOrNull() { Assert.AreEqual(12.5, Conv.To <double?>("12.5")); }
public void TestTo_DateTime_Invalid() { Assert.AreEqual(DateTime.MinValue, Conv.To <DateTime>("1A")); }
public void TestTo_Decimal_Invalid() { Assert.AreEqual(0, Conv.To <decimal>("1A")); }
public void TestTo_DateTimeOrNull() { Assert.AreEqual(new DateTime(2000, 1, 1), Conv.To <DateTime?>("2000-1-1")); }
public void TestTo_DecimalOrNull_Invalid() { Assert.IsNull(Conv.To <decimal?>("1A")); }
ILInstruction MakeDynamicInstruction(CallSiteInfo callsite, CallVirt targetInvokeCall, List <ILInstruction> deadArguments) { switch (callsite.Kind) { case BinderMethodKind.BinaryOperation: deadArguments.AddRange(targetInvokeCall.Arguments.Take(2)); return(new DynamicBinaryOperatorInstruction( binderFlags: callsite.Flags, operation: callsite.Operation, context: callsite.Context, leftArgumentInfo: callsite.ArgumentInfos[0], left: targetInvokeCall.Arguments[2], rightArgumentInfo: callsite.ArgumentInfos[1], right: targetInvokeCall.Arguments[3] )); case BinderMethodKind.Convert: deadArguments.AddRange(targetInvokeCall.Arguments.Take(2)); ILInstruction result = new DynamicConvertInstruction( binderFlags: callsite.Flags, context: callsite.Context, type: callsite.ConvertTargetType, argument: targetInvokeCall.Arguments[2] ); if (result.ResultType == StackType.Unknown) { // if references are missing, we need to coerce the primitive type to None. // Otherwise we will get loads of assertions. result = new Conv(result, PrimitiveType.None, ((DynamicConvertInstruction)result).IsChecked, Sign.None); } return(result); case BinderMethodKind.GetIndex: deadArguments.AddRange(targetInvokeCall.Arguments.Take(2)); return(new DynamicGetIndexInstruction( binderFlags: callsite.Flags, context: callsite.Context, argumentInfo: callsite.ArgumentInfos, arguments: targetInvokeCall.Arguments.Skip(2).ToArray() )); case BinderMethodKind.GetMember: deadArguments.AddRange(targetInvokeCall.Arguments.Take(2)); return(new DynamicGetMemberInstruction( binderFlags: callsite.Flags, name: callsite.MemberName, context: callsite.Context, targetArgumentInfo: callsite.ArgumentInfos[0], target: targetInvokeCall.Arguments[2] )); case BinderMethodKind.Invoke: deadArguments.AddRange(targetInvokeCall.Arguments.Take(2)); return(new DynamicInvokeInstruction( binderFlags: callsite.Flags, context: callsite.Context, argumentInfo: callsite.ArgumentInfos, arguments: targetInvokeCall.Arguments.Skip(2).ToArray() )); case BinderMethodKind.InvokeConstructor: deadArguments.AddRange(targetInvokeCall.Arguments.Take(2)); return(new DynamicInvokeConstructorInstruction( binderFlags: callsite.Flags, context: callsite.Context, argumentInfo: callsite.ArgumentInfos, arguments: targetInvokeCall.Arguments.Skip(2).ToArray() )); case BinderMethodKind.InvokeMember: deadArguments.AddRange(targetInvokeCall.Arguments.Take(2)); return(new DynamicInvokeMemberInstruction( binderFlags: callsite.Flags, name: callsite.MemberName, typeArguments: callsite.TypeArguments, context: callsite.Context, argumentInfo: callsite.ArgumentInfos, arguments: targetInvokeCall.Arguments.Skip(2).ToArray() )); case BinderMethodKind.IsEvent: deadArguments.AddRange(targetInvokeCall.Arguments.Take(2)); return(new DynamicIsEventInstruction( binderFlags: callsite.Flags, name: callsite.MemberName, context: callsite.Context, argument: targetInvokeCall.Arguments[2] )); case BinderMethodKind.SetIndex: deadArguments.AddRange(targetInvokeCall.Arguments.Take(2)); return(new DynamicSetIndexInstruction( binderFlags: callsite.Flags, context: callsite.Context, argumentInfo: callsite.ArgumentInfos, arguments: targetInvokeCall.Arguments.Skip(2).ToArray() )); case BinderMethodKind.SetMember: deadArguments.AddRange(targetInvokeCall.Arguments.Take(2)); return(new DynamicSetMemberInstruction( binderFlags: callsite.Flags, name: callsite.MemberName, context: callsite.Context, targetArgumentInfo: callsite.ArgumentInfos[0], target: targetInvokeCall.Arguments[2], valueArgumentInfo: callsite.ArgumentInfos[1], value: targetInvokeCall.Arguments[3] )); case BinderMethodKind.UnaryOperation: deadArguments.AddRange(targetInvokeCall.Arguments.Take(2)); return(new DynamicUnaryOperatorInstruction( binderFlags: callsite.Flags, operation: callsite.Operation, context: callsite.Context, operandArgumentInfo: callsite.ArgumentInfos[0], operand: targetInvokeCall.Arguments[2] )); default: throw new NotSupportedException(); } throw new NotImplementedException(); }
public void TestTo_DecimalOrNull() { Assert.AreEqual(12.5M, Conv.To <decimal?>("12.5")); }
public static void ShowError(IWin32Window owner, Exception ex) { ShowError(owner, Conv.GetErrorMessage(ex, IsDebug)); }
public void TestTo_Bool_Invalid() { Assert.AreEqual(false, Conv.To <bool>("1A")); }
/// <summary> /// 文件切割 /// </summary> /// <param name="filePath">文件路径</param> /// <param name="outPutPath">输出文件路径</param> /// <param name="kbLength">单个子文件最大长度。单位:KB</param> /// <param name="delete">标识文件分割完成后是否删除原文件</param> /// <param name="change">加密密钥</param> private void FileSplit(string filePath, string outPutPath, int kbLength, bool delete, int change) { if (filePath == null || !File.Exists(filePath)) { return; } //// 加密初始化 //short sign = 1; //int num = 0, tmp; //if (change < 0) //{ // sign = -1; // change = -change; //} var fileName = Path.GetFileNameWithoutExtension(filePath); var fileSize = FileUtil.GetFileSize(filePath); var total = Conv.ToInt(fileSize.GetSizeByK() / kbLength); using (FileStream readStream = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { byte[] data = new byte[1024]; // 流读取,缓存空间 int len = 0, i = 1; // 记录子文件累积读取的KB大小,分割的子文件序号 int readLen = 0; // 每次实际读取的字节大小 FileStream writeStream = null; // 读取数据 while (readLen > 0 || (readLen = readStream.Read(data, 0, data.Length)) > 0) { // 创建分割后的子文件,已有则覆盖 if (len == 0 || writeStream == null) { writeStream = new FileStream($"{outPutPath}\\{fileName}.{i++}.{total}.bin", FileMode.Create); } //// 加密逻辑,对data的首字节进行逻辑偏移加密 //if (num == 0) //{ // num = change; //} //tmp = data[0] + sign * (num % 3 + 3); //if (tmp > 255) //{ // tmp -= 255; //} //else if(tmp<0) //{ // tmp += 255; //} //data[0] = (byte) tmp; //num /= 3; // 输出,缓存数据写入子文件 writeStream.Write(data, 0, readLen); writeStream.Flush(); // 预读下一轮缓存数据 readLen = readStream.Read(data, 0, data.Length); if (++len >= kbLength || readLen == 0) //子文件达到指定大小,或文件已读完 { writeStream.Close(); // 关闭当前输出流 len = 0; } } } if (delete) { FileUtil.Delete(filePath); } }
public void TestTo_Bool() { Assert.AreEqual(true, Conv.To <bool>(1)); }
public RrMx(string name, uint ttl, ushort preference, string mailExchangerHost) : base(name, DnsType.Mx, ttl, Bytes.Create(Conv.GetBytes(preference), DnsUtil.Str2DnsName(mailExchangerHost))) { }
public async Task SendMessage(Conv c, string Text) { string appId = System.Configuration.ConfigurationManager.AppSettings["appId"]; string appSecret = System.Configuration.ConfigurationManager.AppSettings["appSecret"]; string url = "https://api.botframework.com/bot/v1.0/messages"; using (var client = new HttpClient()) { var content = new StringContent( $"{{\"conversationId\": \"{c.ConversationId}\",\"text\": \"{Text}\",\"from\": {{\"channelId\": \"{c.ChannelId}\",\"address\": \"{c.BotAddress}\"}},\"to\": {{\"channelId\": \"{c.ChannelId}\",\"address\": \"{c.UserAddress}\"}}}}", Encoding.UTF8, "application/json"); var byteArray = Encoding.ASCII.GetBytes($"{appId}:{appSecret}"); client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", appSecret); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray)); var response = await client.PostAsync(url, content); var responseString = await response.Content.ReadAsStringAsync(); } }
public Conversation(Message msg) { Conv.Add(msg); Usr1 = msg.From; Usr2 = msg.To; }
public void TestTo_BoolOrNull() { Assert.AreEqual(true, Conv.To <bool?>("true")); }
public void TestTo_BoolOrNull_Invalid() { Assert.IsNull(Conv.To <bool?>("1A")); }
public void TestTo_Int() { Assert.AreEqual(1, Conv.To <int>("1")); }