public List <BOM> SplitOverPolygons(List <Primitives.PolyLine> polygons) { List <BOM> Res = new List <BOM>(); List <BOMNumberSet> Ns = new List <BOMNumberSet>(); foreach (var p in polygons) { BOM SubBom = new BOM(); Res.Add(SubBom); Ns.Add(new BOMNumberSet()); } foreach (var packagepair in DeviceTree) { foreach (var devicevalue in packagepair.Value) { foreach (var n in devicevalue.Value.RefDes) { int i = 0; int added = 0; foreach (var p in polygons) { if (p.PointInPoly(new Primitives.PointD(n.x, n.y))) { OptionalOut <BOMEntry> bom = new OptionalOut <BOMEntry>(); Res[i].AddBOMItemInt(devicevalue.Value.PackageName, devicevalue.Value.Name, devicevalue.Value.Value, n.NameOnBoard, Ns[i], n.SourceBoard, n.x, n.y, n.angle, n.Side, bom); bom.Result.SetCombined(devicevalue.Value.Combined()); added++; } i++; } if (added == 0) { Console.WriteLine("part skipped for some reason: {0}", n.NameOnBoard); } if (added > 1) { Console.WriteLine("part doublebooked for some reason: {0}", n.NameOnBoard); } } } } return(Res); }
public void MergeBOM(BOM B, BOMNumberSet set, double dx, double dy, double cx, double cy, double angle) { foreach (var a in B.DeviceTree) { foreach (var b in a.Value) { foreach (var c in b.Value.RefDes) { double X = c.x; double Y = c.y; Helpers.Transform(dx, dy, cx, cy, angle, ref X, ref Y); OptionalOut <BOMEntry> bom = new OptionalOut <BOMEntry>(); AddBOMItemInt(b.Value.PackageName, b.Value.Name, b.Value.Value, c.OriginalName, set, c.SourceBoard, X, Y, (c.angle + angle) % 360, c.Side, bom); bom.Result.SetCombined(b.Value.Combined()); } } } }
public void ValidateTest() { CommandLineArgs args = new CommandLineArgs(); args.RegisterArgument("flag", new FlagArgument(true, true)); Assert.IsFalse(args.Validate(string.Empty)); args = new CommandLineArgs(); args.RegisterHelpArgument(); args.RegisterArgument("flag", new FlagArgument()); Assert.IsTrue(args.Validate(new[] { "/help", "/flag" })); Assert.IsTrue(args.GetValue <bool>("help")); Assert.IsTrue(args.GetValue <bool>("flag")); OptionalOut <string[]> outErrors = new OptionalOut <string[]>(); Assert.IsFalse(args.Validate("/unknown", outErrors)); Assert.AreEqual(1, outErrors.Result.Length); Assert.AreEqual("Unknown option: 'unknown'", outErrors.Result[0]); args.RegisterArgument("option", new OptionArgument(null)); Assert.IsFalse(args.Validate("/option", outErrors)); Assert.AreEqual(1, outErrors.Result.Length); Assert.AreEqual("Missing value for option 'option'", outErrors.Result[0]); Assert.IsFalse(args.Validate("/option /flag", outErrors)); Assert.AreEqual(1, outErrors.Result.Length); Assert.AreEqual("Missing value for option 'option'", outErrors.Result[0]); args = new CommandLineArgs(); args.RegisterArgument("option", new OptionArgument(null, true)); Assert.IsFalse(args.Validate("")); Assert.IsTrue(args.Validate("/option=value")); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); if (IsFinishing) { return; } SetResult(KeePass.ExitNormal); Log.Warn(Tag, "Creating group view"); Intent intent = Intent; PwUuid id = RetrieveGroupId(intent); Database db = App.Kp2a.CurrentDb; if (id == null) { Group = db.Root; } else { Group = db.GroupsById[id]; } Log.Warn(Tag, "Retrieved group"); if (Group == null) { Log.Warn(Tag, "Group was null"); return; } if (AddGroupEnabled) { // Add Group button View addGroup = FindViewById(Resource.Id.fabAddNewGroup); addGroup.Click += (sender, e) => { GroupEditActivity.Launch(this, Group); }; } if (AddEntryEnabled) { View addEntry = FindViewById(Resource.Id.fabAddNewEntry); addEntry.Click += (sender, e) => { if (App.Kp2a.CurrentDb.DatabaseFormat.SupportsTemplates && !AddTemplateEntries.ContainsAllTemplates(App.Kp2a.CurrentDb) && PreferenceManager.GetDefaultSharedPreferences(this).GetBoolean(Askaddtemplates, true)) { App.Kp2a.AskYesNoCancel(UiStringKey.AskAddTemplatesTitle, UiStringKey.AskAddTemplatesMessage, UiStringKey.yes, UiStringKey.no, (o, args) => { //yes ProgressTask pt = new ProgressTask(App.Kp2a, this, new AddTemplateEntries(this, App.Kp2a, new ActionOnFinish(this, (success, message, activity) => ((GroupActivity)activity)?.StartAddEntry()))); pt.Run(); }, (o, args) => { var edit = PreferenceManager.GetDefaultSharedPreferences(this).Edit(); edit.PutBoolean(Askaddtemplates, false); edit.Commit(); //no StartAddEntry(); }, null, this); } else { StartAddEntry(); } }; } SetGroupTitle(); SetGroupIcon(); FragmentManager.FindFragmentById <GroupListFragment>(Resource.Id.list_fragment).ListAdapter = new PwGroupListAdapter(this, Group); Log.Warn(Tag, "Finished creating group"); var ioc = App.Kp2a.CurrentDb.Ioc; OptionalOut <UiStringKey> reason = new OptionalOut <UiStringKey>(); if (App.Kp2a.GetFileStorage(ioc).IsReadOnly(ioc, reason)) { bool hasShownReadOnlyReason = PreferenceManager.GetDefaultSharedPreferences(this) .GetBoolean(App.Kp2a.CurrentDb.IocAsHexString() + "_readonlyreason", false); if (!hasShownReadOnlyReason) { var b = new AlertDialog.Builder(this); b.SetTitle(Resource.String.FileReadOnlyTitle); b.SetMessage(GetString(Resource.String.FileReadOnlyMessagePre) + " " + App.Kp2a.GetResourceString(reason.Result)); b.SetPositiveButton(Android.Resource.String.Ok, (sender, args) => { PreferenceManager.GetDefaultSharedPreferences(this). Edit().PutBoolean(App.Kp2a.CurrentDb.IocAsHexString() + "_readonlyreason", true).Commit(); }); b.Show(); } } }
// <param name="peerUri">the peer uri of the conversation participant</param> // <param name="usingDisplayName">the display name the participant is claiming to be</param> // <param name="usingAvatarUrl">the avatar the participant is claiming to be</param> // <param name="outContacts">optional returned list of existing contacts matching to this peer URI and the value is set to null if no existing contacts were found</param> // <param name="outPreviousName">optionally returned if contacts were not found the this value will be set with the last known display name (if a record was found)</param> // <param name="outPreviousAvatarUrl">optionally returned if contacts were not found the this value will be set with the last known avatar url (if a record was found)</param> public int GetOrCreateParticipantIdForConversation ( string peerUri, string usingDisplayName, string usingAvatarUrl, ContactDatabase contactDb, OptionalOut< IList<Contact> > outContacts = null, OptionalOut<string> outPreviousName = null, OptionalOut<string> outPreviousAvatarUrl = null ) { Contract.Requires (!String.IsNullOrEmpty(peerUri)); Contract.Requires (contactDb != null); int resultParticipantId = 0; IList<Contact> resultContacts = null; string previousName = usingDisplayName; string previousAvatar = usingAvatarUrl; try { lock (this) { #region this needs to change #warning needs to do proper split using op stack char[] delimiterChars = {'/'}; string[] split = peerUri.Split (delimiterChars, StringSplitOptions.RemoveEmptyEntries); Contract.Assert (split.Length > 2); string contactId = split [2]; Contract.Assert (!String.IsNullOrEmpty (contactId)); #endregion // find any contacts which are associated to this peer URI contact id resultContacts = contactDb.GetByPeerUriContactId (contactId); IList<ConversationPartipantRecord> existingRecordsForContactId = GetParticipantRecordByPeerUriContactId (contactId); if (!Helper.IsNullOrEmpty(existingRecordsForContactId)) { ConversationPartipantRecord record = existingRecordsForContactId.First (); // if we found a contact id that means the user is the same user as there cannot be any two users sharing the same contact id (ever) resultParticipantId = record.ParticipantId; previousName = record.LastKnownDisplayName; previousAvatar = record.LastKnownAvatarUrl; Logger.Debug("found existing participant record for contact id, participant id={0}, peer uri={1}", resultParticipantId, peerUri); } List<Contact> contactsMissingRecords = new List<Contact> (); // search all contacts to see if any have existing records (and which records are missing) foreach (Contact contact in resultContacts) { bool foundRecordForThisIdentity = false; IList<ConversationPartipantRecord> records = GetParticipantRecordByIdentityUri(contact.IdentityUri); foreach (ConversationPartipantRecord record in records) { if ((!String.IsNullOrEmpty(record.StableId)) && (!String.IsNullOrEmpty(contact.StableId))) { if (record.StableId != contact.StableId) { Logger.Trace ("previous participant record was found for identity uri but stable id doesn't match thus skipping, identity uri={0}, contact stable id={1}, record stable id={2}", contact.IdentityUri, contact.StableId, record.StableId); continue; } foundRecordForThisIdentity = foundRecordForThisIdentity || String.Equals(contact.PeerUri, peerUri); // make sure it's the same peer URI (they can be different) bool updated = false; // if the record display name / avatar have changed, update the record if (!String.Equals (contact.DisplayName, record.LastKnownDisplayName)) { updated = true; record.LastKnownDisplayName = contact.DisplayName; } if (!String.Equals (contact.AvatarUrl, record.LastKnownAvatarUrl)) { updated = true; record.LastKnownAvatarUrl = contact.AvatarUrl; } if (updated) { record.LastUpdated = DateTime.UtcNow; Update (record); } if (0 == resultParticipantId) { resultParticipantId = record.ParticipantId; Logger.Debug("found participant record for contact based on identity uri, participant id={0}, peer uri={1}, identity uri={2}", resultParticipantId, peerUri, contact.IdentityUri); continue; } Logger.Debug("found participant record for contact based on identity uri higher priority used, participant id={0}, peer uri={1}, identity uri={2}", resultParticipantId, peerUri, contact.IdentityUri); } } if (!foundRecordForThisIdentity) { contactsMissingRecords.Add (contact); } } bool createdNewParticipantId = false; // check to see if a participant id was chosen (needs one to be able to add any missing records) if (0 == resultParticipantId) { createdNewParticipantId = true; ++lastParticipantId; resultParticipantId = lastParticipantId; } // scan over missing records to add them now if (!Helper.IsNullOrEmpty(resultContacts)) { foreach (Contact contact in contactsMissingRecords) { ConversationPartipantRecord record = new ConversationPartipantRecord (); record.IdentityUri = contact.IdentityUri; record.PeerUri = peerUri; record.PeerUriContactId = contactId; record.StableId = contact.StableId; record.ParticipantId = resultParticipantId; record.LastKnownDisplayName = contact.DisplayName; record.LastKnownAvatarUrl = contact.AvatarUrl; Insert (record); Logger.Trace ("added missing participant record for idenity, participant id={0}, identity={1}, stable id={2}, peer uri={3}", record.ParticipantId, record.IdentityUri, record.StableId, record.PeerUri); } } else { if (createdNewParticipantId) { ConversationPartipantRecord record = new ConversationPartipantRecord (); record.IdentityUri = ""; record.PeerUri = peerUri; record.PeerUriContactId = contactId; record.StableId = ""; record.ParticipantId = resultParticipantId; record.LastKnownDisplayName = usingDisplayName; record.LastKnownAvatarUrl = usingAvatarUrl; Insert (record); Logger.Trace ("added missing participant record for peer uri, participant id={0}, peer uri={1}", record.ParticipantId, record.PeerUri); } } } } finally { if (null != outContacts) { if (!Helper.IsNullOrEmpty (resultContacts)) { outContacts.Result = resultContacts; } else { outContacts.Result = new List<Contact> (); } } if (Helper.IsNullOrEmpty (resultContacts)) { if (null != outPreviousName) { outPreviousName.Result = previousName; } if (null != outPreviousAvatarUrl) { outPreviousAvatarUrl.Result = previousAvatar; } } } return resultParticipantId; }
// <param name="peerUri">the peer uri of the conversation participant</param> // <param name="usingDisplayName">the display name the participant is claiming to be</param> // <param name="usingAvatarUrl">the avatar the participant is claiming to be</param> // <param name="outContacts">optional returned list of existing contacts matching to this peer URI and the value is set to null if no existing contacts were found</param> // <param name="outPreviousName">optionally returned if contacts were not found the this value will be set with the last known display name (if a record was found)</param> // <param name="outPreviousAvatarUrl">optionally returned if contacts were not found the this value will be set with the last known avatar url (if a record was found)</param> public int GetOrCreateParticipantIdForConversation( string peerUri, string usingDisplayName, string usingAvatarUrl, ContactDatabase contactDb, OptionalOut <IList <Contact> > outContacts = null, OptionalOut <string> outPreviousName = null, OptionalOut <string> outPreviousAvatarUrl = null ) { Contract.Requires(!String.IsNullOrEmpty(peerUri)); Contract.Requires(contactDb != null); int resultParticipantId = 0; IList <Contact> resultContacts = null; string previousName = usingDisplayName; string previousAvatar = usingAvatarUrl; try { lock (this) { #region this needs to change #warning needs to do proper split using op stack char[] delimiterChars = { '/' }; string[] split = peerUri.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries); Contract.Assert(split.Length > 2); string contactId = split [2]; Contract.Assert(!String.IsNullOrEmpty(contactId)); #endregion // find any contacts which are associated to this peer URI contact id resultContacts = contactDb.GetByPeerUriContactId(contactId); IList <ConversationPartipantRecord> existingRecordsForContactId = GetParticipantRecordByPeerUriContactId(contactId); if (!Helper.IsNullOrEmpty(existingRecordsForContactId)) { ConversationPartipantRecord record = existingRecordsForContactId.First(); // if we found a contact id that means the user is the same user as there cannot be any two users sharing the same contact id (ever) resultParticipantId = record.ParticipantId; previousName = record.LastKnownDisplayName; previousAvatar = record.LastKnownAvatarUrl; Logger.Debug("found existing participant record for contact id, participant id={0}, peer uri={1}", resultParticipantId, peerUri); } List <Contact> contactsMissingRecords = new List <Contact> (); // search all contacts to see if any have existing records (and which records are missing) foreach (Contact contact in resultContacts) { bool foundRecordForThisIdentity = false; IList <ConversationPartipantRecord> records = GetParticipantRecordByIdentityUri(contact.IdentityUri); foreach (ConversationPartipantRecord record in records) { if ((!String.IsNullOrEmpty(record.StableId)) && (!String.IsNullOrEmpty(contact.StableId))) { if (record.StableId != contact.StableId) { Logger.Trace("previous participant record was found for identity uri but stable id doesn't match thus skipping, identity uri={0}, contact stable id={1}, record stable id={2}", contact.IdentityUri, contact.StableId, record.StableId); continue; } foundRecordForThisIdentity = foundRecordForThisIdentity || String.Equals(contact.PeerUri, peerUri); // make sure it's the same peer URI (they can be different) bool updated = false; // if the record display name / avatar have changed, update the record if (!String.Equals(contact.DisplayName, record.LastKnownDisplayName)) { updated = true; record.LastKnownDisplayName = contact.DisplayName; } if (!String.Equals(contact.AvatarUrl, record.LastKnownAvatarUrl)) { updated = true; record.LastKnownAvatarUrl = contact.AvatarUrl; } if (updated) { record.LastUpdated = DateTime.UtcNow; Update(record); } if (0 == resultParticipantId) { resultParticipantId = record.ParticipantId; Logger.Debug("found participant record for contact based on identity uri, participant id={0}, peer uri={1}, identity uri={2}", resultParticipantId, peerUri, contact.IdentityUri); continue; } Logger.Debug("found participant record for contact based on identity uri higher priority used, participant id={0}, peer uri={1}, identity uri={2}", resultParticipantId, peerUri, contact.IdentityUri); } } if (!foundRecordForThisIdentity) { contactsMissingRecords.Add(contact); } } bool createdNewParticipantId = false; // check to see if a participant id was chosen (needs one to be able to add any missing records) if (0 == resultParticipantId) { createdNewParticipantId = true; ++lastParticipantId; resultParticipantId = lastParticipantId; } // scan over missing records to add them now if (!Helper.IsNullOrEmpty(resultContacts)) { foreach (Contact contact in contactsMissingRecords) { ConversationPartipantRecord record = new ConversationPartipantRecord(); record.IdentityUri = contact.IdentityUri; record.PeerUri = peerUri; record.PeerUriContactId = contactId; record.StableId = contact.StableId; record.ParticipantId = resultParticipantId; record.LastKnownDisplayName = contact.DisplayName; record.LastKnownAvatarUrl = contact.AvatarUrl; Insert(record); Logger.Trace("added missing participant record for idenity, participant id={0}, identity={1}, stable id={2}, peer uri={3}", record.ParticipantId, record.IdentityUri, record.StableId, record.PeerUri); } } else { if (createdNewParticipantId) { ConversationPartipantRecord record = new ConversationPartipantRecord(); record.IdentityUri = ""; record.PeerUri = peerUri; record.PeerUriContactId = contactId; record.StableId = ""; record.ParticipantId = resultParticipantId; record.LastKnownDisplayName = usingDisplayName; record.LastKnownAvatarUrl = usingAvatarUrl; Insert(record); Logger.Trace("added missing participant record for peer uri, participant id={0}, peer uri={1}", record.ParticipantId, record.PeerUri); } } } } finally { if (null != outContacts) { if (!Helper.IsNullOrEmpty(resultContacts)) { outContacts.Result = resultContacts; } else { outContacts.Result = new List <Contact> (); } } if (Helper.IsNullOrEmpty(resultContacts)) { if (null != outPreviousName) { outPreviousName.Result = previousName; } if (null != outPreviousAvatarUrl) { outPreviousAvatarUrl.Result = previousAvatar; } } } return(resultParticipantId); }
string AddBOMItemInt(string package, string device, string value, string refdes, BOMNumberSet set, string SourceBoard, double x, double y, double angle, BoardSide side = BoardSide.Top, OptionalOut <BOMEntry> bom = null) { string ID = GetID(package, device, refdes); if (DeviceTree.ContainsKey(ID) == false) { DeviceTree[ID] = new Dictionary <string, BOMEntry>(); } if (DeviceTree[ID].ContainsKey(value) == false) { DeviceTree[ID][value] = new BOMEntry() { Name = device, Value = value, PackageName = package } } ; BOMEntry BE = DeviceTree[ID][value]; if (bom != null) { bom.Result = BE; } ; return(BE.AddRef(refdes, SourceBoard, set, x, y, angle, side)); }
public void LoadJLC(string bOMFile, string pnPFile) { Dictionary <string, BOMEntry.RefDesc> positions = new Dictionary <string, BOMEntry.RefDesc>(); var bomlines = File.ReadAllLines(bOMFile); var pnplines = File.ReadAllLines(pnPFile); //outlinesBOM.Add("Comment,Designator,Footprint,LCSC Part #"); var regex = new Regex("(?<=^|,)(\"(?:[^\"]|\"\")*\"|[^,]*)"); //outlinesPNP.Add("Designator,Mid X,Mid Y,Layer,Rotation"); for (int i = 1; i < pnplines.Count(); i++) { var s = pnplines[i]; List <string> items = new List <string>(); foreach (Match m in regex.Matches(s)) { items.Add(m.Value); } var rd = items[0]; var X = ConvertDimension(items[1]); var Y = ConvertDimension(items[2]); var Side = items[3] == "T" ? BoardSide.Top : BoardSide.Bottom; var Angle = Double.Parse(items[4]); positions[rd] = new BOMEntry.RefDesc() { angle = Angle, x = X, y = Y, OriginalName = rd, NameOnBoard = rd, SourceBoard = bOMFile, Side = Side }; } BOMNumberSet Set = new BOMNumberSet(); var headers = bomlines[0].Split(','); for (int i = 1; i < bomlines.Count(); i++) { var s = bomlines[i]; List <string> items = new List <string>(); foreach (Match m in regex.Matches(s)) { items.Add(m.Value.Trim()); } var refdesc = items[1].Trim();; if (refdesc.StartsWith("\"")) { refdesc = refdesc.Substring(1, refdesc.Length - 2); } var rd = refdesc.Split(','); var value = items[0]; var package = items[2]; foreach (var rd_ in rd) { var S = positions[rd_.Trim()]; if (headers.Count() > 5) { OptionalOut <BOMEntry> Entr = new OptionalOut <BOMEntry>();; string name = items[5]; string combined = items[4]; AddBOMItemInt(package, name, value, rd_, Set, bOMFile, S.x, S.y, S.angle, S.Side, Entr); Entr.Result.SetCombined(combined); //AddBOMItemExt(package, name, value, rd_, Set, bOMFile, S.x, S.y, S.angle, S.Side); } else { AddBOMItemExt(package, "", value, rd_, Set, bOMFile, S.x, S.y, S.angle, S.Side); } } } }