public void DistinctBy_ReturnsDistinctElements_AndResetsIteratorCorrectly() { // Arrange var tuple1 = new System.Tuple<string, string>("fruit", "apple"); var tuple2 = new System.Tuple<string, string>("fruit", "orange"); var tuple3 = new System.Tuple<string, string>("fruit", "banana"); var tuple4 = new System.Tuple<string, string>("fruit", "banana"); // Should be filtered out var list = new List<System.Tuple<string, string>>() { tuple1, tuple2, tuple3, tuple4 }; // Act var iteratorSource = list.DistinctBy(x => x.Item2); // Assert // First check distinction Assert.AreEqual(3, iteratorSource.Count()); // Check for iterator block mistakes - reset to original query first iteratorSource = list.DistinctBy(x => x.Item2); Assert.AreEqual(iteratorSource.Count(), iteratorSource.ToList().Count()); }
public JournalMissionCompleted(JObject evt ) : base(evt, JournalTypeEnum.MissionCompleted) { Name = JSONHelper.GetStringDef(evt["Name"]); Faction = JSONHelper.GetStringDef(evt["Faction"]); Commodity = JSONHelper.GetStringDef(evt["Commodity"]); Count = JSONHelper.GetIntNull(evt["Count"]); Target = JSONHelper.GetStringDef(evt["Target"]); TargetType = JSONHelper.GetStringDef(evt["TargetType"]); TargetFaction = JSONHelper.GetStringDef(evt["TargetFaction"]); Reward = JSONHelper.GetLongNull(evt["Reward"]) ?? 0; Donation = JSONHelper.GetLongNull(evt["Donation"]) ?? 0; MissionId = JSONHelper.GetInt(evt["MissionID"]); if (!JSONHelper.IsNullOrEmptyT(evt["PermitsAwarded"])) PermitsAwarded = evt.Value<JArray>("PermitsAwarded").Values<string>().ToArray(); if (!JSONHelper.IsNullOrEmptyT(evt["CommodityReward"])) { JArray rewards = (JArray)evt["CommodityReward"]; if (rewards.Count > 0) { CommodityReward = new System.Tuple<string, int>[rewards.Count]; int i = 0; foreach (JToken jc in rewards.Children()) { if (!JSONHelper.IsNullOrEmptyT(jc["Name"]) && !JSONHelper.IsNullOrEmptyT(jc["Count"])) CommodityReward[i++] = new System.Tuple<string, int>(jc["Name"].Value<string>(), jc["Count"].Value<int>()); //System.Diagnostics.Trace.WriteLine(string.Format(" >> Child {0} {1}", jc.Path, jc.Type.ToString())); } } } }
public UnpackingContext(System.Tuple <MsgPack.Serialization.FileSystemEntry, string, string, string, string, string, string> Tuple7FirstPolymorphic) { this.Tuple7FirstPolymorphic = Tuple7FirstPolymorphic; }
public static System.ValueTuple <T1, T2, T3, T4, T5, T6, T7, System.ValueTuple <T8, T9, T10> > ToValueTuple <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(this System.Tuple <T1, T2, T3, T4, T5, T6, T7, System.Tuple <T8, T9, T10> > value) { throw null; }
static void AddTexture(Flood.GUI.Font font, System.String text, Flood.GUI.Texture texture) { System.Tuple<System.String, Flood.GUI.Font> key = new System.Tuple<System.String, Flood.GUI.Font>(text, font); m_StringCache.Add(key,texture); }
protected internal override MsgPack.Serialization.PolymorphicMemberTypeKnownType_Tuple_Tuple7AllStaticPrivateSetterPropertyAndConstructor UnpackFromCore(MsgPack.Unpacker unpacker) { MsgPack.Serialization.PolymorphicMemberTypeKnownType_Tuple_Tuple7AllStaticPrivateSetterPropertyAndConstructor result = default(MsgPack.Serialization.PolymorphicMemberTypeKnownType_Tuple_Tuple7AllStaticPrivateSetterPropertyAndConstructor); result = new MsgPack.Serialization.PolymorphicMemberTypeKnownType_Tuple_Tuple7AllStaticPrivateSetterPropertyAndConstructor(); if (unpacker.IsArrayHeader) { int unpacked = default(int); int itemsCount = default(int); itemsCount = MsgPack.Serialization.UnpackHelpers.GetItemsCount(unpacker); System.Tuple <string, string, string, string, string, string, string> nullable = default(System.Tuple <string, string, string, string, string, string, string>); if ((unpacked < itemsCount)) { if ((unpacker.Read() == false)) { throw MsgPack.Serialization.SerializationExceptions.NewMissingItem(0); } if (((unpacker.IsArrayHeader == false) && (unpacker.IsMapHeader == false))) { nullable = this._serializer1.UnpackFrom(unpacker); } else { MsgPack.Unpacker disposable = default(MsgPack.Unpacker); disposable = unpacker.ReadSubtree(); try { nullable = this._serializer1.UnpackFrom(disposable); } finally { if (((disposable == null) == false)) { disposable.Dispose(); } } } } if (((nullable == null) == false)) { this._methodBasePolymorphicMemberTypeKnownType_Tuple_Tuple7AllStaticPrivateSetterPropertyAndConstructor_set_Tuple7AllStatic0.Invoke(result, new object[] { nullable }); } unpacked = (unpacked + 1); } else { int itemsCount0 = default(int); itemsCount0 = MsgPack.Serialization.UnpackHelpers.GetItemsCount(unpacker); for (int i = 0; (i < itemsCount0); i = (i + 1)) { string key = default(string); string nullable0 = default(string); nullable0 = MsgPack.Serialization.UnpackHelpers.UnpackStringValue(unpacker, typeof(MsgPack.Serialization.PolymorphicMemberTypeKnownType_Tuple_Tuple7AllStaticPrivateSetterPropertyAndConstructor), "MemberName"); if (((nullable0 == null) == false)) { key = nullable0; } else { throw MsgPack.Serialization.SerializationExceptions.NewNullIsProhibited("MemberName"); } if ((key == "Tuple7AllStatic")) { System.Tuple <string, string, string, string, string, string, string> nullable1 = default(System.Tuple <string, string, string, string, string, string, string>); if ((unpacker.Read() == false)) { throw MsgPack.Serialization.SerializationExceptions.NewMissingItem(i); } if (((unpacker.IsArrayHeader == false) && (unpacker.IsMapHeader == false))) { nullable1 = this._serializer1.UnpackFrom(unpacker); } else { MsgPack.Unpacker disposable0 = default(MsgPack.Unpacker); disposable0 = unpacker.ReadSubtree(); try { nullable1 = this._serializer1.UnpackFrom(disposable0); } finally { if (((disposable0 == null) == false)) { disposable0.Dispose(); } } } if (((nullable1 == null) == false)) { this._methodBasePolymorphicMemberTypeKnownType_Tuple_Tuple7AllStaticPrivateSetterPropertyAndConstructor_set_Tuple7AllStatic0.Invoke(result, new object[] { nullable1 }); } } else { unpacker.Skip(); } } } return(result); }
public UnpackingContext(System.Tuple <MsgPack.Serialization.FileSystemEntry> Tuple1Polymorphic) { this.Tuple1Polymorphic = Tuple1Polymorphic; }
private void SetUnpackedValueOfTuple7AllStatic(MsgPack.Serialization.PolymorphicMemberTypeKnownType_Tuple_Tuple7AllStaticReadWriteProperty unpackingContext, System.Tuple <string, string, string, string, string, string, string> unpackedValue) { unpackingContext.Tuple7AllStatic = unpackedValue; }
protected internal override MsgPack.Serialization.PolymorphicMemberTypeKnownType_Tuple_Tuple7LastPolymorphicReadWriteField UnpackFromCore(MsgPack.Unpacker unpacker) { MsgPack.Serialization.PolymorphicMemberTypeKnownType_Tuple_Tuple7LastPolymorphicReadWriteField result = default(MsgPack.Serialization.PolymorphicMemberTypeKnownType_Tuple_Tuple7LastPolymorphicReadWriteField); result = new MsgPack.Serialization.PolymorphicMemberTypeKnownType_Tuple_Tuple7LastPolymorphicReadWriteField(); if (unpacker.IsArrayHeader) { int unpacked = default(int); int itemsCount = default(int); itemsCount = MsgPack.Serialization.UnpackHelpers.GetItemsCount(unpacker); System.Tuple <string, string, string, string, string, string, MsgPack.Serialization.FileSystemEntry> nullable = default(System.Tuple <string, string, string, string, string, string, MsgPack.Serialization.FileSystemEntry>); if ((unpacked < itemsCount)) { if ((unpacker.Read() == false)) { throw MsgPack.Serialization.SerializationExceptions.NewMissingItem(0); } if (((unpacker.IsArrayHeader == false) && (unpacker.IsMapHeader == false))) { nullable = this._serializer1.UnpackFrom(unpacker); } else { MsgPack.Unpacker disposable = default(MsgPack.Unpacker); disposable = unpacker.ReadSubtree(); try { nullable = this._serializer1.UnpackFrom(disposable); } finally { if (((disposable == null) == false)) { disposable.Dispose(); } } } } if (((nullable == null) == false)) { result.Tuple7LastPolymorphic = nullable; } unpacked = (unpacked + 1); } else { int itemsCount0 = default(int); itemsCount0 = MsgPack.Serialization.UnpackHelpers.GetItemsCount(unpacker); for (int i = 0; (i < itemsCount0); i = (i + 1)) { string key = default(string); string nullable0 = default(string); nullable0 = MsgPack.Serialization.UnpackHelpers.UnpackStringValue(unpacker, typeof(MsgPack.Serialization.PolymorphicMemberTypeKnownType_Tuple_Tuple7LastPolymorphicReadWriteField), "MemberName"); if (((nullable0 == null) == false)) { key = nullable0; } else { throw MsgPack.Serialization.SerializationExceptions.NewNullIsProhibited("MemberName"); } if ((key == "Tuple7LastPolymorphic")) { System.Tuple <string, string, string, string, string, string, MsgPack.Serialization.FileSystemEntry> nullable1 = default(System.Tuple <string, string, string, string, string, string, MsgPack.Serialization.FileSystemEntry>); if ((unpacker.Read() == false)) { throw MsgPack.Serialization.SerializationExceptions.NewMissingItem(i); } if (((unpacker.IsArrayHeader == false) && (unpacker.IsMapHeader == false))) { nullable1 = this._serializer1.UnpackFrom(unpacker); } else { MsgPack.Unpacker disposable0 = default(MsgPack.Unpacker); disposable0 = unpacker.ReadSubtree(); try { nullable1 = this._serializer1.UnpackFrom(disposable0); } finally { if (((disposable0 == null) == false)) { disposable0.Dispose(); } } } if (((nullable1 == null) == false)) { result.Tuple7LastPolymorphic = nullable1; } } else { unpacker.Skip(); } } } return(result); }
private void SetUnpackedValueOfTuple1ObjectItem(MsgPack.Serialization.PolymorphicMemberTypeRuntimeType_Tuple_Tuple1ObjectItemReadWriteProperty unpackingContext, System.Tuple <object> unpackedValue) { unpackingContext.Tuple1ObjectItem = unpackedValue; }
public Icon(byte directionAndType, System.Tuple <byte, byte> position) { this.directionAndType = directionAndType; this.position = position; }
public System.Threading.Tasks.Task <bool> ChangeInfoAsync(string tagId, System.Tuple <string, string> newVal) { return(base.Channel.ChangeInfoAsync(tagId, newVal)); }
public static Microsoft.AspNetCore.DiagnosticsViewPage.Views.AttributeValue FromTuple(System.Tuple<string, string, bool> value) { throw null; }
public bool ChangeInfo(string tagId, System.Tuple <string, string> newVal) { return(base.Channel.ChangeInfo(tagId, newVal)); }
private void SetUnpackedValueOfValue(MsgPack.Serialization.TupleAbstractType unpackingContext, System.Tuple <MsgPack.Serialization.AbstractFileSystemEntry, MsgPack.Serialization.IFileSystemEntry, MsgPack.Serialization.AbstractFileSystemEntry, MsgPack.Serialization.IFileSystemEntry> unpackedValue) { unpackingContext.Value = unpackedValue; }
public bool TryReceive(System.Predicate <System.Tuple <T1, T2> >?filter, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out System.Tuple <T1, T2>?item) { throw null; }
public bool TryReceive(System.Predicate <System.Tuple <System.Collections.Generic.IList <T1>, System.Collections.Generic.IList <T2> > >?filter, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out System.Tuple <System.Collections.Generic.IList <T1>, System.Collections.Generic.IList <T2> >?item) { throw null; }
private void SetUnpackedValueOfTuple7LastPolymorphic(MsgPack.Serialization.PolymorphicMemberTypeKnownType_Tuple_Tuple7LastPolymorphicReadWriteField unpackingContext, System.Tuple <string, string, string, string, string, string, MsgPack.Serialization.FileSystemEntry> unpackedValue) { unpackingContext.Tuple7LastPolymorphic = unpackedValue; }
private void SetUnpackedValueOfTuple1ObjectItem(MsgPack.Serialization.PolymorphicMemberTypeRuntimeType_Tuple_Tuple1ObjectItemPrivateSetterPropertyAndConstructor unpackingContext, System.Tuple <object> unpackedValue) { this._methodBasePolymorphicMemberTypeRuntimeType_Tuple_Tuple1ObjectItemPrivateSetterPropertyAndConstructor_set_Tuple1ObjectItem0.Invoke(unpackingContext, new object[] { unpackedValue }); }
private void SetUnpackedValueOfTuple1ObjectItem(UnpackingContext unpackingContext, System.Tuple <object> unpackedValue) { unpackingContext.Tuple1ObjectItem = unpackedValue; }
private void SetUnpackedValueOfTuple8AllPolymorphic(MsgPack.Serialization.PolymorphicMemberTypeKnownType_Tuple_Tuple8AllPolymorphicReadWriteProperty unpackingContext, System.Tuple <MsgPack.Serialization.FileSystemEntry, MsgPack.Serialization.FileSystemEntry, MsgPack.Serialization.FileSystemEntry, MsgPack.Serialization.FileSystemEntry, MsgPack.Serialization.FileSystemEntry, MsgPack.Serialization.FileSystemEntry, MsgPack.Serialization.FileSystemEntry, System.Tuple <MsgPack.Serialization.FileSystemEntry> > unpackedValue) { unpackingContext.Tuple8AllPolymorphic = unpackedValue; }
public UnpackingContext(System.Tuple <object> Tuple1ObjectItem) { this.Tuple1ObjectItem = Tuple1ObjectItem; }
private void SetUnpackedValueOfTuple8LastPolymorphic(MsgPack.Serialization.PolymorphicMemberTypeRuntimeType_Tuple_Tuple8LastPolymorphicPrivateSetterPropertyAndConstructor unpackingContext, System.Tuple <string, string, string, string, string, string, string, System.Tuple <MsgPack.Serialization.FileSystemEntry> > unpackedValue) { this._methodBasePolymorphicMemberTypeRuntimeType_Tuple_Tuple8LastPolymorphicPrivateSetterPropertyAndConstructor_set_Tuple8LastPolymorphic0.Invoke(unpackingContext, new object[] { unpackedValue }); }
protected internal override MsgPack.Serialization.PolymorphicMemberTypeRuntimeType_Tuple_Tuple8AllPolymorphicReadOnlyFieldAndConstructor UnpackFromCore(MsgPack.Unpacker unpacker) { UnpackingContext unpackingContext = default(UnpackingContext); System.Tuple <MsgPack.Serialization.FileSystemEntry, MsgPack.Serialization.FileSystemEntry, MsgPack.Serialization.FileSystemEntry, MsgPack.Serialization.FileSystemEntry, MsgPack.Serialization.FileSystemEntry, MsgPack.Serialization.FileSystemEntry, MsgPack.Serialization.FileSystemEntry, System.Tuple <MsgPack.Serialization.FileSystemEntry> > ctorArg0 = default(System.Tuple <MsgPack.Serialization.FileSystemEntry, MsgPack.Serialization.FileSystemEntry, MsgPack.Serialization.FileSystemEntry, MsgPack.Serialization.FileSystemEntry, MsgPack.Serialization.FileSystemEntry, MsgPack.Serialization.FileSystemEntry, MsgPack.Serialization.FileSystemEntry, System.Tuple <MsgPack.Serialization.FileSystemEntry> >); ctorArg0 = null; unpackingContext = new UnpackingContext(ctorArg0); if (unpacker.IsArrayHeader) { return(MsgPack.Serialization.UnpackHelpers.UnpackFromArray(unpacker, unpackingContext, this.this_CreateInstanceFromContextDelegate, this._memberNames, this._unpackOperationList)); } else { return(MsgPack.Serialization.UnpackHelpers.UnpackFromMap(unpacker, unpackingContext, this.this_CreateInstanceFromContextDelegate, this._unpackOperationTable)); } }
private void SetUnpackedValueOfTuple8AllStatic(MsgPack.Serialization.PolymorphicMemberTypeRuntimeType_Tuple_Tuple8AllStaticReadWriteField unpackingContext, System.Tuple <string, string, string, string, string, string, string, System.Tuple <string> > unpackedValue) { unpackingContext.Tuple8AllStatic = unpackedValue; }
private void SetUnpackedValueOfTuple1Static(MsgPack.Serialization.PolymorphicMemberTypeKnownType_Tuple_Tuple1StaticPrivateSetterPropertyAndConstructor unpackingContext, System.Tuple <string> unpackedValue) { this._methodBasePolymorphicMemberTypeKnownType_Tuple_Tuple1StaticPrivateSetterPropertyAndConstructor_set_Tuple1Static0.Invoke(unpackingContext, new object[] { unpackedValue }); }
private void SetUnpackedValueOfTuple1Polymorphic(UnpackingContext unpackingContext, System.Tuple <MsgPack.Serialization.FileSystemEntry> unpackedValue) { unpackingContext.Tuple1Polymorphic = unpackedValue; }
private void SetUnpackedValueOfTuple8AllStatic(UnpackingContext unpackingContext, System.Tuple <string, string, string, string, string, string, string, System.Tuple <string> > unpackedValue) { unpackingContext.Tuple8AllStatic = unpackedValue; }
public static void Deconstruct <T1, T2, T3, T4, T5, T6, T7, T8, T9>(this System.Tuple <T1, T2, T3, T4, T5, T6, T7, System.Tuple <T8, T9> > value, out T1 item1, out T2 item2, out T3 item3, out T4 item4, out T5 item5, out T6 item6, out T7 item7, out T8 item8, out T9 item9) { throw null; }
protected internal override MsgPack.Serialization.PolymorphicMemberTypeKnownType_Tuple_Tuple8AllStaticGetOnlyPropertyAndConstructor UnpackFromCore(MsgPack.Unpacker unpacker) { UnpackingContext unpackingContext = default(UnpackingContext); System.Tuple <string, string, string, string, string, string, string, System.Tuple <string> > ctorArg0 = default(System.Tuple <string, string, string, string, string, string, string, System.Tuple <string> >); ctorArg0 = null; unpackingContext = new UnpackingContext(ctorArg0); if (unpacker.IsArrayHeader) { return(MsgPack.Serialization.UnpackHelpers.UnpackFromArray(unpacker, unpackingContext, this.this_CreateInstanceFromContextDelegate, this._memberNames, this._unpackOperationList)); } else { return(MsgPack.Serialization.UnpackHelpers.UnpackFromMap(unpacker, unpackingContext, this.this_CreateInstanceFromContextDelegate, this._unpackOperationTable)); } }
public static System.ValueTuple <T1, T2, T3, T4, T5, T6, T7, System.ValueTuple <T8, T9, T10, T11, T12, T13, T14, System.ValueTuple <T15, T16, T17> > > ToValueTuple <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17>(this System.Tuple <T1, T2, T3, T4, T5, T6, T7, System.Tuple <T8, T9, T10, T11, T12, T13, T14, System.Tuple <T15, T16, T17> > > value) { throw null; }
public UnpackingContext(System.Tuple <string, string, string, string, string, string, string, System.Tuple <string> > Tuple8AllStatic) { this.Tuple8AllStatic = Tuple8AllStatic; }
static Flood.GUI.Texture GetTexture(Flood.GUI.Font font, System.String text) { System.Tuple<System.String, Flood.GUI.Font> key = new System.Tuple<System.String, Flood.GUI.Font>(text, font); if (m_StringCache.ContainsKey(key)) return m_StringCache[key]; return null; }
protected internal override System.Threading.Tasks.Task <MsgPack.Serialization.PolymorphicMemberTypeRuntimeType_Tuple_Tuple7LastPolymorphicGetOnlyPropertyAndConstructor> UnpackFromAsyncCore(MsgPack.Unpacker unpacker, System.Threading.CancellationToken cancellationToken) { UnpackingContext unpackingContext = default(UnpackingContext); System.Tuple <string, string, string, string, string, string, MsgPack.Serialization.FileSystemEntry> ctorArg0 = default(System.Tuple <string, string, string, string, string, string, MsgPack.Serialization.FileSystemEntry>); ctorArg0 = null; unpackingContext = new UnpackingContext(ctorArg0); if (unpacker.IsArrayHeader) { return(MsgPack.Serialization.UnpackHelpers.UnpackFromArrayAsync(unpacker, unpackingContext, this.this_CreateInstanceFromContextDelegate, this._memberNames, this._unpackOperationListAsync, cancellationToken)); } else { return(MsgPack.Serialization.UnpackHelpers.UnpackFromMapAsync(unpacker, unpackingContext, this.this_CreateInstanceFromContextDelegate, this._unpackOperationTableAsync, cancellationToken)); } }
private bool Save() { System.Data.SQLite.SQLiteTransaction transaction = null; using (AutomaticOpenClose aoc = new AutomaticOpenClose(connection)) { try { transaction = connection.BeginTransaction(); // -------------------------------------------------- // Deadline if (DeadlineIsSelectedDateRadioButton.IsChecked.Value) { var command = new System.Data.SQLite.SQLiteCommand("INSERT INTO deadlines(deadline) VALUES(@deadline); SELECT last_insert_rowid()", connection); command.Parameters.Add(new System.Data.SQLite.SQLiteParameter("@deadline", DeadlineDatePicker.SelectedDate)); var reader = command.ExecuteReader(); if (reader.Read()) { row["deadline_id"] = reader.GetInt64(0); } } else if (DeadlineIsEventRadioButton.IsChecked.Value) { row["deadline_id"] = (EventsComboBox.SelectedValue != null) ? EventsComboBox.SelectedValue : System.DBNull.Value; } else { row["deadline_id"] = System.DBNull.Value; } taskDataAdapter.Update(dataSet, "task"); // -------------------------------------------------- // Tags var currentTags = new System.Collections.Generic.List<string>(Util.SplitTags(TagsTextBox.Text)); var whereInTuple = Util.SqlParametersList(currentTags); var rows = new System.Collections.Generic.List<System.Tuple<System.Nullable<long>, System.Nullable<long>, System.Nullable<long>, string>>(); { var command = new System.Data.SQLite.SQLiteCommand(@" SELECT tasks_tags.ID, tasks_tags.task_id, tasks_tags.tag_id, tags.name FROM tasks_tags LEFT JOIN tags ON tags.ID = tasks_tags.tag_id WHERE tasks_tags.task_id=@id AND tags.name IN(" + whereInTuple.Item1 + @") UNION ALL SELECT NULL, NULL, ID, name FROM tags WHERE ID NOT IN(SELECT tag_id FROM tasks_tags WHERE task_id=@id) AND name IN(" + whereInTuple.Item1 + ")", connection); command.Parameters.Add(new System.Data.SQLite.SQLiteParameter("@id", id)); foreach (var parameter in whereInTuple.Item2) command.Parameters.Add(parameter); var reader = command.ExecuteReader(); while (reader.Read()) { var tuple = new System.Tuple<System.Nullable<long>, System.Nullable<long>, System.Nullable<long>, string>(null, null, null, ""); System.Nullable<long> tasksTagsID = null; System.Nullable<long> taskID = null; System.Nullable<long> tagID = null; string name = ""; if (!reader.IsDBNull(0)) tasksTagsID = reader.GetInt64(0); if (!reader.IsDBNull(1)) taskID = reader.GetInt64(1); if (!reader.IsDBNull(2)) tagID = reader.GetInt64(2); if (!reader.IsDBNull(3)) name = reader.GetString(3); rows.Add(System.Tuple.Create(tasksTagsID, taskID, tagID, name)); } } // delete all old tasks_tags not need for new tags { var oldTasksTagsIDs = new System.Collections.Generic.List<long>(); foreach (var tuple in rows) { if (tuple.Item1.HasValue) oldTasksTagsIDs.Add(tuple.Item1.Value); } var whereInTuple2 = Util.SqlParametersList(oldTasksTagsIDs); var command = new System.Data.SQLite.SQLiteCommand("DELETE FROM tasks_tags WHERE task_id=@id AND ID NOT IN(" + whereInTuple2.Item1 + ")", connection); command.Parameters.Add(new System.Data.SQLite.SQLiteParameter("@id", id)); foreach (var parameter in whereInTuple2.Item2) command.Parameters.Add(parameter); command.ExecuteNonQuery(); } // link existing new tags foreach (var tuple in rows) { if (!tuple.Item1.HasValue && tuple.Item3.HasValue) { var tagID = tuple.Item3.Value; long newTasksTagsID = Util.InsertInto(connection, "tasks_tags", System.Tuple.Create("task_id", id), System.Tuple.Create("tag_id", tagID)); } } // create and link new tags { var newTags = new System.Collections.Generic.List<string>(); foreach (var tagName in currentTags) { bool found = false; foreach (var row in rows) { if (row.Item4 == tagName) { found = true; break; } } if (!found) { long newTagID = Util.InsertInto(connection, "tags", System.Tuple.Create("name", tagName)); long newTasksTagsID = Util.InsertInto(connection, "tasks_tags", System.Tuple.Create("task_id", id), System.Tuple.Create("tag_id", newTagID)); } } } // -------------------------------------------------- // Alerts foreach (System.Data.DataRow row in dataSet.Tables["alerts"].Rows) { if (row.RowState == System.Data.DataRowState.Added) row["task_id"] = id; } alertsDataAdapter.Update(dataSet, "alerts"); dataSet.Tables["alerts"].Clear(); alertsDataAdapter.Fill(dataSet, "alerts"); // -------------------------------------------------- // Sub-Tasks foreach (System.Data.DataRow row in dataSet.Tables["sub_tasks"].Rows) { if (row.RowState == System.Data.DataRowState.Added) row["child_of"] = id; } subTasksDataAdapter.Update(dataSet, "sub_tasks"); dataSet.Tables["sub_tasks"].Clear(); subTasksDataAdapter.Fill(dataSet, "sub_tasks"); // -------------------------------------------------- // Clean state IsDirty = false; transaction.Commit(); } catch (System.Data.SQLite.SQLiteException e) { if (transaction != null) transaction.Rollback(); switch (e.ErrorCode) { case System.Data.SQLite.SQLiteErrorCode.Constraint: Util.ShowFieldMustBeUniqueMessage(this, Util.ExtractColumnName(e.Message)); break; } } } try { this.parent.MassReloadTasks(); } catch { } return !IsDirty; }
private void Save() { // -------------------------------------------------- // Deadline using (AutomaticOpenClose aoc = new AutomaticOpenClose(connection)) { var command = new System.Data.SQLite.SQLiteCommand("INSERT INTO deadlines(deadline) VALUES(@deadline); SELECT last_insert_rowid()", connection); command.Parameters.Add(new System.Data.SQLite.SQLiteParameter("@deadline", DeadlineDatePicker.SelectedDate)); var reader = command.ExecuteReader(); if (reader.Read()) { row["deadline_id"] = reader.GetInt64(0); } else { row["deadline_id"] = System.DBNull.Value; } } taskDataAdapter.Update(dataSet, "event"); // -------------------------------------------------- // Tags using (AutomaticOpenClose aoc = new AutomaticOpenClose(connection)) { var currentTags = new System.Collections.Generic.List<string>(Util.SplitTags(TagsTextBox.Text)); var whereInTuple = Util.SqlParametersList(currentTags); var rows = new System.Collections.Generic.List<System.Tuple<System.Nullable<long>, System.Nullable<long>, System.Nullable<long>, string>>(); { var command = new System.Data.SQLite.SQLiteCommand(@" SELECT events_tags.ID, events_tags.event_id, events_tags.tag_id, tags.name FROM events_tags LEFT JOIN tags ON tags.ID = events_tags.tag_id WHERE events_tags.event_id=@id AND tags.name IN(" + whereInTuple.Item1 + @") UNION ALL SELECT NULL, NULL, ID, name FROM tags WHERE ID NOT IN(SELECT tag_id FROM events_tags WHERE event_id=@id) AND name IN(" + whereInTuple.Item1 + ")", connection); command.Parameters.Add(new System.Data.SQLite.SQLiteParameter("@id", id)); foreach (var parameter in whereInTuple.Item2) command.Parameters.Add(parameter); var reader = command.ExecuteReader(); while (reader.Read()) { var tuple = new System.Tuple<System.Nullable<long>, System.Nullable<long>, System.Nullable<long>, string>(null, null, null, ""); System.Nullable<long> tasksTagsID = null; System.Nullable<long> taskID = null; System.Nullable<long> tagID = null; string name = ""; if (!reader.IsDBNull(0)) tasksTagsID = reader.GetInt64(0); if (!reader.IsDBNull(1)) taskID = reader.GetInt64(1); if (!reader.IsDBNull(2)) tagID = reader.GetInt64(2); if (!reader.IsDBNull(3)) name = reader.GetString(3); rows.Add(System.Tuple.Create(tasksTagsID, taskID, tagID, name)); } } // delete all old tasks_tags not need for new tags { var oldTasksTagsIDs = new System.Collections.Generic.List<long>(); foreach (var tuple in rows) { if (tuple.Item1.HasValue) oldTasksTagsIDs.Add(tuple.Item1.Value); } var whereInTuple2 = Util.SqlParametersList(oldTasksTagsIDs); var command = new System.Data.SQLite.SQLiteCommand("DELETE FROM events_tags WHERE event_id=@id AND ID NOT IN(" + whereInTuple2.Item1 + ")", connection); command.Parameters.Add(new System.Data.SQLite.SQLiteParameter("@id", id)); foreach (var parameter in whereInTuple2.Item2) command.Parameters.Add(parameter); command.ExecuteNonQuery(); } // link existing new tags foreach (var tuple in rows) { if (!tuple.Item1.HasValue && tuple.Item3.HasValue) { var tagID = tuple.Item3.Value; long newTasksTagsID = Util.InsertInto(connection, "events_tags", System.Tuple.Create("event_id", id), System.Tuple.Create("tag_id", tagID)); } } // create and link new tags { var newTags = new System.Collections.Generic.List<string>(); foreach (var tagName in currentTags) { bool found = false; foreach (var row in rows) { if (row.Item4 == tagName) { found = true; break; } } if (!found) { long newTagID = Util.InsertInto(connection, "tags", System.Tuple.Create("name", tagName)); long newTasksTagsID = Util.InsertInto(connection, "events_tags", System.Tuple.Create("event_id", id), System.Tuple.Create("tag_id", newTagID)); } } } // Alerts foreach (System.Data.DataRow row in dataSet.Tables["alerts"].Rows) { if (row.RowState == System.Data.DataRowState.Added) row["event_id"] = id; } alertsDataAdapter.Update(dataSet, "alerts"); dataSet.Tables["alerts"].Clear(); alertsDataAdapter.Fill(dataSet, "alerts"); } // -------------------------------------------------- // Clean state IsDirty = false; try { this.parent.MassReloadEvents(); } catch { } }