Storing templates using dictionary in c# - c#-3.0

I have to store some templates based on the statecode.I cannot store them in database. So i thought of creating a dictionary with statecode as key and list as value. I have chosen a list because i need a template line by line.So each string in list is a line. Is there any better way of dealing with this kind of situation. Please comment.
private static readonly Dictionary<string, List<string>> NotaryForStates = new Dictionary<string, List<string>>()
{
{"AR",new List<string> {"Per Steve Hollowell, ESQ from the Legal Division of the AR, SOS. Telephone number for the Legal Division of the SOS: (501)-682-3012. Arkansas Code 16-47-101.", "State of Arkansas", "County of <notary county>","On this day, <sign date> before me, <name of notary>, the undersigned notary, personally appeared, <name of signer> who acknowledged he/she is the <title of signer> of <name of company> and that he/she as such <title of signer>, being authorized so to do, executed the foregoing instrument for the purposes therein contained, by signing the name of the corporation by himself/herself as <title of signer>.","In witness whereof I hereunto set my hand and official seal.","______________________","Notary Public","<Notary name>","My Commission expires: <notary commission date>"}},
{"CA",new List<string>{"State of California","County of <Notary County>","On <sign date> before me, <Notary Name>, Notary Public, personally appeared <Signing Party Name>, who proved to me on the basis of satisfactory evidence to be the person(s) whose name is subscribed to the within instrument and acknowledged to me that he/she executed the same in his/her authorized capacity, and that by his/her signature on the instrument the person, or the entity upon behalf of which the person acted, executed the instrument.","I certify under PENALTY OF PERJURY under the laws of the State of California that the foregoing paragraph is true and correct.","WITNESS my hand and official seal.","______________________________","Notary Public: «NotaryName»","My Comm. Expires: «NotaryCommExp»"}},
{"FL",new List<string>{"State of Florida","County of <Notary County>","On <sign date> before me, the undersigned, a Notary Public, for said County and State, personally appeared <Signing Party Name>, personally known to me to be the person that executed the foregoing instrument and acknowledged that is a <signer title> of <name of company> and that he/she did execute the foregoing instrument. <Name of Signer> is personally known to me.","_____________________","Notary Public: «NotaryName»","My Comm. Expires: «NotaryCommExp»"}}
};

First alternative: You may use a simple string instead of a list and separate the individual lines with Environment.NewLine ("\n"). You can create such strings easily with a StringBuilder object and split it again (if you need to) with the string.Split() method. This is also (slightly) faster than the List<string> approach.
Second alternative: You may use files and store only the filename in your dictionary.
Whether or not one of the above options is a better alternative to your original approach, depends on the concrete project you're working on. All in all, the List<string> approach might well be ok...
HTH!

Another alternative is to use resource files (which are commonly used for localization). Resource files provide a location for storing text or other types of objects which can be used across a Web site, WPF or Windows Forms application, thus creating a central location for maintaining the text. Using resource files can also simplify maintenance of your application.

Related

VS Code Regex search to remove references based on containing text in string

I am attempting to remove all references of a managed package that is going to be uninstalled that spans throughout code base in VS Code
I have using a query to find the field permissions but am wondering if there is a way to search for the reference outside of specifying the exact field name compared to the field containing only "agf" since they are all using it.
Below is the search query:
<fieldPermissions>
<editable>false</editable>
<field>User.agf_Certified_Product_Owner__c</field>
<readable>false</readable>
</fieldPermissions>
In the field, I want to be able to find and delete the 5 associated lines from multiple files if they match "agf" in any combination. Something like the below:
<fieldPermissions>
<editable>false</editable>
<field>agf</field>
<readable>false</readable>
</fieldPermissions>
With any combination of agf in the field, delete all from any file it appears in.
Not an answer but too long for a comment
You don't have to? Profiles/perm sets don't block package's delete. Probably neither do reports.
You'd use your time better by searching for all instances of agf__ (that's with double underscore), should find fields, objects... used in classes, flows, page layouts etc. And search for agf. (with dot) should find all instances where your Apex code calls their classes marked as global.
Alternatively Apex / VF pages with dependencies on package will have it listed in their "meta.xml", for example
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>54.0</apiVersion>
<packageVersions>
<majorNumber>236</majorNumber>
<minorNumber>1</minorNumber>
<namespace>SBQQ</namespace>
</packageVersions>
<status>Active</status>
</ApexClass>
Last but not least - why not just spawn a dev sandbox and attempt the delete there? If it succeeds - great. If not - it'll list the dependencies that blocked the delete. It'll be "the real thing", it'll smite you even if your VSCode project doesn't contain all flows, layouts and thus could lull you into false sense of security. I'd seriously do it in sandbox and then run all tests for good measure, just in case there are some dynamic soql queries that don't count as hard, delete-blocking references.
After delete's done - fetch Profiles / Permsets from this org and the field references will be gone from the xml.

Adding signingCertificateV2 attribute to SignedCms

ContentInfo content = new ContentInfo(new Oid("1.2.840.113549.1.7.5"), Encoding.UTF8.GetBytes(str.ToString()));
SignedCms signedCms = new SignedCms(content, true);
CmsSigner cmsSigner = new CmsSigner(cert);
cmsSigner.IncludeOption = X509IncludeOption.EndCertOnly;
cmsSigner.DigestAlgorithm = new Oid("2.16.840.1.101.3.4.2.1");
cmsSigner.SignerIdentifierType = SubjectIdentifierType.IssuerAndSerialNumber;
Pkcs9AttributeObject att = new Pkcs9AttributeObject();
AsnEncodedData data = new AsnEncodedData(new SHA1Managed().ComputeHash(cert.RawData));
cmsSigner.SignedAttributes.Add(new Pkcs9SigningTime(DateTime.UtcNow));
//cmsSigner.SignedAttributes.Add(new Pkcs9ContentType());
//cmsSigner.SignedAttributes.Add(new Pkcs9MessageDigest());
signedCms.ComputeSignature(cmsSigner);
return Convert.ToBase64String(signedCms.Encode());
I have used this code to sign a document and this code is working fine but my problem is that there is another requirement needed to add "SigningCertificateV2" attribute as a signed attribute...
I have already added ContentType, MessageDigest and SigningTime. But i dont know how to add "SigningCertificateV2" attribute.. (1.2.840.113549.1.9.16.2.47)
Can You please help me with this?
(It seems this question's been sitting unanswered for more than a year and a half, so I really hope Asharf managed to comply with the new requirement somehow. There's been more than 300 views though, so hopefully a late answer would still be helpful.)
The types in System.Security.Cryptography.Pkcs do not provide support for the full range of attributes defined by various Cryptographic Message Syntax (CMS) specs like CMS Advanced Electronic Signatures (CAdES) and Enhanced Security Services Update (ESSCertIdUpdate), but only for the most commonly used attribs like Pkcs9ContentType, Pkcs9MessageDigest, Pkcs9SigningTime, etc.
Specifically, there's no "strongly-typed" wrapper around the SigningCertificatev2 attribute, defined by ESSCertIdUpdate (RFC 5035). In that case, one has to use the "generic" CryptographicAttributeObject type and construct the ASN.1 encoded data for the attribute "by hand", that is, concoct a raw byte[], typically by using System.Formats.Asn1.AsnWriter (and thoroughly reading the relevant RFC -- that's always a good idea, btw).
Defining a wrapper for the SigningCertificatev2 attrib requires a fair amount of code as several other related RFC types like ESSCertIDv2 and PolicyInformation need also be defined.
Luckily, there's a well-known open-source software project that already does exactly that -- it can be used for "inspiration" ;-). That's NuGet, and specifically the NuGet client.
(I know link-only answers are frowned upon on SO, but I guess a link-mostly answer is better than no answer, so here goes...).
Here are the links to the relevant parts in the GutHub repo.
CreateSigningCertificateV2() in AttributeUtility
The SigningCertificateV2 type itself.
The EssCertIdV2 type, used by SigningCertificateV2.
The NuGet client's attribute implementation can't be used directly as a library, but it should provide a nice guideline about how to construct the PKCS attribute.

Connection shape script shows GUID not a name of reference element

In my MDG technology I have a my own type of connection "MyConn" extended of InformationFlow. "MyConn" has tag "ServiceRef" which is linked via tagged value to another MDG element «MyService».
When I use in "MyConn" shape script the construction
print(" -> ");
print("#TAG:ServiceRef#");
the shape depicts GUID of "MyService", not a "Name", as I experienced in other cases (for element, not connections).
Is there a way to show name of referenced element, not a GUID ? Sparx 13.5
That's obviously a(nother) bug in EA. It's still broken in 15.1. You might report that (or use your time for something more useful). Eventually post the question on Sparx' forum and one of the nice Sparxian (KP if any) will have an idea.
Since shape script is so limited the only way around would be to use an add-in call to decipher the name from the GUID, just like
print("#yourAddin:decipherGUID#");
You would need to implement that decipherGUID operation in your add-in. If you desperately need that be aware that for each connector to be rendered EA will call that add-in. That can easily drop performance to non-usability.

REST avoid duplication of efforts

Consider the example scheme below, as you can see a Regiment has a many-to-many relationship with contractors which can be the same for several regiments.
If I have to create two regiments with several hundreds of common contractors I will basically upload two times the same contractors to the server:
<regiments>
<regiment>
<contractors>
<conctractor>
<id>1</id>
...
</contractor>
<conctractor>
<id>2</id>
...
</contractor>
</contractors>
</regiment>
<regiment>
<contractors>
<conctractor>
<id>2</id>
...
</contractor>
<conctractor>
<id>5</id>
...
</contractor>
</contractors>
</regiment>
</regiments>
I am using a PUT where regiments and contractors have a predefined ID because I'm using REST to synchronize a desktop application to a web application and both have to use the same IDs for their entities.
Notice the contractor object is very big and has sublists of its own so re-uploading even a single contractor is a big loss of time and resources for the server.
How can I avoid uploading the same contractors over and over?
There is no reason you can't use a representation that allows you to link to an existing Contractor which has previously been PUT:
<regiments>
<regiment>
<contractors>
<contractor-ref uri="/contractors/1"/>
<contractor-ref uri="/contractors/2"/>
</contractors>
</regiment>
<regiment>
<contractors>
<contractor-ref uri="/contractors/2"/>
<contractor-ref uri="/contractors/5"/>
</contractors>
</regiment>
</regiments>

RESTful urls for restore operation from a trash bin

I've been implementing a RESTful web service which has these operations:
List articles:
GET /articles
Delete articles (which should remove only selected articles to a trash bin):
DELETE /articles
List articles in the trash bin:
GET /trash/articles
I have to implement an operation for restoring "articles" from "/trash/articles" back to "/articles".
And here is the question. Ho do you usually do it? What url do I have to use?
I came up to the 2 ways of doing it. The first is:
DELETE /trash/articles
But it feels strange and a user can read it like "delete it permanently, don't restore".
And the second way is
PUT /trash/articles
Which is more odd and a user will be confused what this operation does.
I'm new to REST, so please advice how you do it normally. I tried to search in google but I don't know how to ask it right, so I didn't get something useful.
Another option could be to use "query params" to define a "complementary action/verb" to cover this "special condition" you have (given that this is not very easily covered by the HTTP verbs). This then could be done for example by:
PUT /trash/articles?restore=true
This would make the URI path still complaint with REST guideline (referring to a resource, and not encoding "actions" - like "restore") and would shift the "extra semantics" of what you want to do (which is a very special situation) to the "query parameter". "Query params" are very commonly used for "filtering" resources in REST, not so much for this kind of situation... but maybe this is a reasonable assumption given your requirements.
I would recommend using
PUT /restore/articles
or
PUT /restore/trash/articles
Late answer but, in my opinion, the best way is to change the resource itself.
For instance:
<article is_in_trash="true">
<title>come title</title>
<body>the article body</body>
<date>1990-01-01</date>
</article>
So, in order to remove the article from Trash, you would simple use PUT an updated version of the article, where is_in_trash="false".