/// <summary> /// Main entry point of Startup to begin logic of this application. /// </summary> /// <param name="scope">Service scope.</param> public void Run(IServiceScope scope) { Precondition.NotNull(scope); // execute the migration of the database when required scope.ServiceProvider.GetRequiredService <IDatabaseMigrationService>().MigrateDatabase(); }
public static IEnumerable <KeyValuePair <string, string> > BuildBasicParameters(string consumerKey, string consumerSecret, string url, HttpMethod method, Token token = null, IEnumerable <KeyValuePair <string, string> > optionalParameters = null) { Precondition.NotNull(url, "url"); var parameters = new List <KeyValuePair <string, string> >(capacity: 7) { new KeyValuePair <string, string>("oauth_consumer_key", consumerKey), new KeyValuePair <string, string>("oauth_nonce", Random.Next().ToString()), new KeyValuePair <string, string>("oauth_timestamp", DateTime.UtcNow.ToUnixTime().ToString()), new KeyValuePair <string, string>("oauth_signature_method", "HMAC-SHA1"), new KeyValuePair <string, string>("oauth_version", "1.0") }; if (token != null) { parameters.Add(new KeyValuePair <string, string>("oauth_token", token.Key)); } if (optionalParameters == null) { optionalParameters = Enumerable.Empty <KeyValuePair <string, string> >(); } var signature = GenerateSignature(consumerSecret, new Uri(url), method, token, parameters.Concat(optionalParameters)); parameters.Add(new KeyValuePair <string, string>("oauth_signature", signature)); return(parameters); }
public async Task <TokenResponse <AccessToken> > GetAccessTokenAsync(string accessTokenUrl, AuthToken authToken, string grantType, IEnumerable <KeyValuePair <string, string> > parameters = null, HttpContent postValue = null) { Precondition.NotNull(accessTokenUrl, "accessTokenUrl"); Precondition.NotNull(authToken, "authToken"); Precondition.NotNull(grantType, "grantType"); Precondition.NotNull(_clientId, "clientId"); Precondition.NotNull(_clientSecret, "clientSecret"); var sendParameters = new List <KeyValuePair <string, string> >(8) { new KeyValuePair <string, string>(OAuthConstants.CODE, authToken.Code), new KeyValuePair <string, string>(OAuthConstants.CLIENT_SECRET, _clientSecret), new KeyValuePair <string, string>(OAuthConstants.REDIRECT_URI, _redirectUrl), new KeyValuePair <string, string>(OAuthConstants.GRANT_TYPE, grantType), new KeyValuePair <string, string>(OAuthConstants.SCOPE, _scope) }; if (parameters == null) { parameters = Enumerable.Empty <KeyValuePair <string, string> >(); } var handler = new OAuthMessageHandler(_clientId, _redirectUrl, parameters.Concat(sendParameters)); return(await GetTokenResponseAsync(accessTokenUrl, handler, postValue, (code, data) => new AccessToken(code, data))); }
/// <summary>construct AuthrizeUrl + RequestTokenKey</summary> public string BuildAuthorizeUrl(string authUrl, RequestToken requestToken) { Precondition.NotNull(authUrl, "authUrl"); Precondition.NotNull(requestToken, "accessToken"); return(authUrl + "?oauth_token=" + requestToken.Key); }
/// <summary> /// Initializes a new instance of the <see cref="DatabaseMigrationService"/> class. /// </summary> /// <param name="connectionOptions">Configuration of the database.</param> public DatabaseMigrationService(IOptions <Connection> connectionOptions) { Precondition.NotNull(connectionOptions, "Connection options must be provided."); Precondition.NotNull(connectionOptions.Value, "Connection options must be provided."); this.connectionOptions = connectionOptions.Value; }
public string BuildAuthorizeUrl(string authUrl, string responseType, IEnumerable <KeyValuePair <string, string> > optionalParameters = null) { Precondition.NotNull(authUrl, "authUrl"); var parameters = new List <KeyValuePair <string, string> >(capacity: 8) { new KeyValuePair <string, string>(OAuthConstants.RESPONSE_TYPE, responseType), new KeyValuePair <string, string>(OAuthConstants.CLIENT_ID, _clientId), new KeyValuePair <string, string>(OAuthConstants.REDIRECT_URI, _redirectUrl), new KeyValuePair <string, string>(OAuthConstants.SCOPE, _scope), }; if (optionalParameters == null) { optionalParameters = Enumerable.Empty <KeyValuePair <string, string> >(); } var stringParameter = optionalParameters .Where(x => x.Key.ToLower() != OAuthConstants.REALM) .Concat(parameters) .Select(p => new { Key = p.Key.UrlEncode(), Value = p.Value.UrlEncode() }) .OrderBy(p => p.Key, StringComparer.Ordinal) .ThenBy(p => p.Value, StringComparer.Ordinal) .Select(p => p.Key + "=" + p.Value) .ToString("&"); return(string.Format("{0}?{1}", authUrl, stringParameter)); }
public Token(string code, ILookup <string, string> extraData) { Precondition.NotNull(code); this.Code = code; base.ExtraData = extraData; }
public void NotNull_ObjectNotNull_DoesNotThrowException() { // Arrange object test = new object(); // Act Precondition.NotNull(test); }
public Token(string key, string secret) { Precondition.NotNull(key, "key"); Precondition.NotNull(secret, "secret"); this.Key = key; this.Secret = secret; }
/// <summary> /// Called to create a new document processor from the given initialization parameters /// </summary> /// <param name="parameters">The parameters used to configure the processor</param> /// <returns>The created processor </returns> public override IDocumentProcessor Create(IDictionary <string, string> parameters) { Precondition.NotNull(parameters, "parameters"); string applicationPath = this.GetParameterOrThrow(parameters, "applicationPath"); return(new LaunchApplicationCommand(applicationPath)); }
/// <summary>asynchronus get RequestToken</summary> public Task <TokenResponse <RequestToken> > GetRequestToken(string requestTokenUrl, IEnumerable <KeyValuePair <string, string> > parameters = null, HttpContent postValue = null) { Precondition.NotNull(requestTokenUrl, "requestTokenUrl"); var handler = new OAuthMessageHandler(Client, token: null, optionalOAuthHeaderParameters: parameters); return(GetTokenResponse(requestTokenUrl, handler, postValue, (key, secret) => new RequestToken(key, secret))); }
/// <summary> /// Called to create a new document processor from the given initialization parameters /// </summary> /// <param name="parameters">The parameters used to configure the processor</param> /// <returns>The created processor </returns> public override IDocumentProcessor Create(IDictionary <string, string> parameters) { Precondition.NotNull(parameters, "parameters"); string destinationDirectory = this.GetParameterOrThrow(parameters, "destinationDirectory"); return(new MoveFileProcessor(destinationDirectory)); }
public TokenResponse(T token, ILookup <string, string> extraData) { Precondition.NotNull(token, "token"); Precondition.NotNull(extraData, "extraData"); this.Token = token; this.ExtraData = extraData; }
/// <inheritdoc /> public object ComputeFieldValue(IIndexable p_Indexable) { s_Logger.TraceEntering("ComputeFieldValue"); Precondition.NotNull(p_Indexable, () => () => p_Indexable); IItem item = new ItemWrapper(new IndexableWrapper(p_Indexable)); object value = GetItemTagsNames(item); s_Logger.TraceExiting("ComputeFieldValue"); return(value); }
internal static void Save(string path, Account account, Settings settings) { Precondition.NotNull(account); Precondition.NotNull(settings); Directory.CreateDirectory(Path.GetDirectoryName(path) ?? ""); using (var file = File.Open(path, FileMode.Create)) using (var cs = EncryptedStream.CreateEncryptionStream(key, file)) using (var bw = new BinaryWriter(cs)) { account.WriteTo(bw); settings.WriteTo(bw); } }
public async Task <TokenResponse <AccessToken> > GetAccessTokenAsync(string accessTokenUrl, IEnumerable <KeyValuePair <string, string> > parameters = null, HttpContent postValue = null) { Precondition.NotNull(accessTokenUrl, "accessTokenUrl"); if (parameters == null) { parameters = Enumerable.Empty <KeyValuePair <string, string> >(); } var handler = new OAuthMessageHandler(_clientId, _redirectUrl, parameters); return(await GetTokenResponseAsync(accessTokenUrl, handler, postValue, (code, data) => new AccessToken(code, data))); }
/// <summary> /// Cleans the Coveo indexable item's HTML content set by previous processors. /// </summary> /// <param name="p_Args">The pipeline arguments in which the original HTML content is defined.</param> public void Process(CoveoPostItemProcessingPipelineArgs p_Args) { s_Logger.TraceEntering(); Precondition.NotNull(p_Args, () => () => p_Args); if (ShouldProcess(p_Args)) { string originalHtmlContent = Encoding.UTF8.GetString(p_Args.CoveoItem.BinaryData); string cleanedHtmlContent = CleanHtmlContent(originalHtmlContent); p_Args.CoveoItem.BinaryData = Encoding.UTF8.GetBytes(cleanedHtmlContent); } s_Logger.TraceExiting(); }
public AesCipher(byte[] aesKey) { Precondition.NotNull(aesKey, nameof(aesKey)); Precondition.Check <ArgumentOutOfRangeException>(aesKey.Length == 32, "Key length needs to be 32"); var aes = new RijndaelManaged { Key = aesKey, Mode = CipherMode.ECB, Padding = PaddingMode.PKCS7 }; using (aes) { crypto = aes.CreateEncryptor(); } }
/// <summary>asynchronus get GetAccessToken</summary> public Task <TokenResponse <AccessToken> > GetAccessToken(string accessTokenUrl, RequestToken requestToken, string verifier, IEnumerable <KeyValuePair <string, string> > parameters = null, HttpContent postValue = null) { Precondition.NotNull(accessTokenUrl, "accessTokenUrl"); Precondition.NotNull(requestToken, "requestToken"); Precondition.NotNull(verifier, "verifier"); var verifierParam = new KeyValuePair <string, string>("oauth_verifier", verifier.Trim()); if (parameters == null) { parameters = Enumerable.Empty <KeyValuePair <string, string> >(); } var handler = new OAuthMessageHandler(Client, token: requestToken, optionalOAuthHeaderParameters: parameters.Concat(new[] { verifierParam })); return(GetTokenResponse(accessTokenUrl, handler, postValue, (key, secret) => new AccessToken(key, secret))); }
private static ReadOnlyDictionary <int, string> LoadNames(string filename) { using (var file = assembly.GetManifestResourceStream("MapleCLB.Resources.Item." + filename)) { Precondition.NotNull(file); var br = new BinaryReader(file); int count = br.ReadInt32(); Dictionary <int, string> names = new Dictionary <int, string>(count); for (int i = 0; i < count; i++) { int key = br.ReadInt32(); names[key] = br.ReadString(); } return(new ReadOnlyDictionary <int, string>(names)); } }
/// <summary> /// Called to create a new document processor from the given initialization parameters /// </summary> /// <param name="parameters">The parameters used to configure the processor</param> /// <returns>The created processor </returns> public override IDocumentProcessor Create(IDictionary <string, string> parameters) { Precondition.NotNull(parameters, "parameters"); string executablePath = this.GetParameterOrThrow(parameters, "executablePath"); string outputFolderName = this.GetParameterOrThrow(parameters, "outputFolderName"); string outputFileExtension = this.GetParameterOrThrow(parameters, "outputFileExtension"); string commandLineTemplate = this.GetParameterOrThrow(parameters, "commandLineTemplate"); var processor = new CommandLineConversionProcessor( executablePath, outputFolderName, outputFileExtension, commandLineTemplate); return(processor); }
/// <summary> /// Called to create a new document processor from the given initialization parameters /// </summary> /// <param name="parameters">The parameters used to configure the processor</param> /// <returns>The created processor </returns> public override IDocumentProcessor Create(IDictionary <string, string> parameters) { Precondition.NotNull(parameters, "parameters"); string timeoutInSeconds; string retryDelayInMilliSeconds; parameters.TryGetValue("timeoutInSeconds", out timeoutInSeconds); parameters.TryGetValue("retryDelayInMilliSeconds", out retryDelayInMilliSeconds); int timeoutInSecondsInt = DefaultTimeoutInSecondsInt; if (!string.IsNullOrEmpty(timeoutInSeconds)) { if (!int.TryParse(timeoutInSeconds, out timeoutInSecondsInt)) { timeoutInSecondsInt = DefaultTimeoutInSecondsInt; } else { throw new ArgumentException( string.Format("timeoutInSeconds parameter value '{0}' is not a valid number", timeoutInSeconds)); } } int retryDelayInMilliSecondsInt = DefaultRetryDelayInMilliSecondsInt; if (!string.IsNullOrEmpty(retryDelayInMilliSeconds)) { if (!int.TryParse(retryDelayInMilliSeconds, out retryDelayInMilliSecondsInt)) { retryDelayInMilliSecondsInt = DefaultRetryDelayInMilliSecondsInt; } else { throw new ArgumentException( string.Format("retryDelayInMilliSeconds parameter value '{0}' is not a valid number", timeoutInSeconds)); } } // Verify values are reasonable Precondition.Assert(() => timeoutInSecondsInt > 0, "timeout must be > 0"); Precondition.Assert(() => retryDelayInMilliSecondsInt > 0, "retryDelayInMilliSeconds must be > 0"); return(new WaitForFileProcessor(timeoutInSecondsInt, retryDelayInMilliSecondsInt)); }
private static ReadOnlyDictionary <int, string[]> LoadMapNames() { using (var file = assembly.GetManifestResourceStream("MapleCLB.Resources.Map.name.map")) { Precondition.NotNull(file); var br = new BinaryReader(file); int count = br.ReadInt32(); Dictionary <int, string[]> mapNames = new Dictionary <int, string[]>(count); for (int i = 0; i < count; i++) { int key = br.ReadInt32(); string[] name = { br.ReadString(), br.ReadString() }; mapNames[key] = name; } return(new ReadOnlyDictionary <int, string[]>(mapNames)); } }
private static ReadOnlyDictionary <int, MapNode> LoadMaps() { using (var file = assembly.GetManifestResourceStream("MapleCLB.Resources.Map.node.map")) { Precondition.NotNull(file); var br = new BinaryReader(file); int count = br.ReadInt32(); Dictionary <int, MapNode> readMap = new Dictionary <int, MapNode>(count); for (int i = 0; i < count; i++) { int key = br.ReadInt32(); var node = new MapNode(br); readMap.Add(key, node); } return(new ReadOnlyDictionary <int, MapNode>(readMap)); } }
/// <summary> /// Gets the name of the tags associated to an <see cref="IItem"/>. /// </summary> /// <param name="p_Item">The item that is being indexed.</param> /// <returns>A list of tag names.</returns> private object GetItemTagsNames(IItem p_Item) { s_Logger.TraceEntering("GetItemTagsName"); Precondition.NotNull(p_Item, () => () => p_Item); s_Logger.Debug(p_Item.Uri.DataUri); s_Database = p_Item.Database; object tagsNames = null; IEnumerable <string> tagItemsIds = GetTagItemsIds(p_Item); if (tagItemsIds.Any()) { tagsNames = GetTagItemsNames(tagItemsIds, p_Item.Language); } s_Logger.Debug("Value: " + tagsNames); s_Logger.TraceExiting("GetItemTagsName"); return(tagsNames); }
private void EndConnect(IAsyncResult iar) { var socket = iar.AsyncState as Socket; Precondition.NotNull(socket); try { socket.EndConnect(iar); if (socket.Connected) { var session = new Session(socket, SessionType.CLIENT, aesCipher); OnConnected?.Invoke(this, session); session.Start(null); } else { Debug.WriteLine("Failed to connect, let's try again?"); Connect(); } } catch (SocketException ex) { OnError?.Invoke(this, ex.SocketErrorCode); } }
/// <inheritDoc /> public void Process(CoveoPostItemProcessingPipelineArgs p_Args) { s_Logger.TraceEntering(); Precondition.NotNull(p_Args, () => () => p_Args); ID limitedAccessFieldId = new ID(LimitedAccessFieldId); ID fieldToHideId = new ID(FieldToHideId); ID previewFieldId = new ID(PreviewFieldId); CoveoIndexableItem coveoIndexableItem = p_Args.CoveoItem; SitecoreIndexableItem sitecoreIndexableItem = p_Args.Item as SitecoreIndexableItem; if (coveoIndexableItem != null && sitecoreIndexableItem != null && !sitecoreIndexableItem.Item.Paths.IsMediaItem && sitecoreIndexableItem.Item[limitedAccessFieldId] == LIMITED_ACCESS_VALUE) { // Check if a preview text has been specified. IIndexableDataField previewField = sitecoreIndexableItem.Fields.FirstOrDefault(arg => (ID)arg.Id == previewFieldId); byte[] encodedPreview = null; if (previewField != null) { string previewText = previewField.Value.ToString(); if (!String.IsNullOrEmpty(previewText)) { encodedPreview = Encoding.UTF8.GetBytes(previewText); } } // Duplicates metadata. Dictionary <string, object> newMetadata = new Dictionary <string, object>(coveoIndexableItem.Metadata) { { LIMITED_ACCESS_METADATA_FIELDNAME, true } }; // Add a hidden field containing the original binary data for relevance if (coveoIndexableItem.BinaryData != null) { newMetadata.Add(HIDDEN_CONTENT_METADATA_FIELDNAME, Encoding.UTF8.GetString(coveoIndexableItem.BinaryData)); } if (!String.IsNullOrEmpty(FieldToHideId)) { IIndexableDataField fieldToHide = sitecoreIndexableItem.Fields.FirstOrDefault(arg => (ID)arg.Id == fieldToHideId); if (fieldToHide != null) { newMetadata.Remove(fieldToHide.Name); } } string newUniqueId = coveoIndexableItem.UniqueId + LIMITED_ACCESS_ITEM_SUFFIX; CoveoIndexableItem strippedItem = new CoveoIndexableItem { // Custom fields. // Replace the data with the preview text. This way, the preview will be used for the new item's quickview. BinaryData = encodedPreview, UniqueId = newUniqueId, Metadata = newMetadata, // Fields that are inherited from the parent item. BinaryDataMimeType = coveoIndexableItem.BinaryDataMimeType, BinaryDataPath = coveoIndexableItem.BinaryDataPath, ClickableUri = coveoIndexableItem.ClickableUri, FileName = coveoIndexableItem.FileName, HasSubItems = coveoIndexableItem.HasSubItems, Id = coveoIndexableItem.Id, IsDeletedItem = coveoIndexableItem.IsDeletedItem, ModifiedDate = coveoIndexableItem.ModifiedDate, Parent = coveoIndexableItem.Parent, ParentId = coveoIndexableItem.ParentId, Path = coveoIndexableItem.Path, Permissions = CreateAnonymousAccessRule(), PrintablePath = coveoIndexableItem.PrintablePath, Title = coveoIndexableItem.Title }; p_Args.OutputCoveoItems.Add(strippedItem); } s_Logger.TraceExiting(); }
/// <inheritDoc /> public void Process(CoveoPostItemProcessingPipelineArgs p_Args) { s_Logger.TraceEntering(); Precondition.NotNull(p_Args, () => () => p_Args); CoveoIndexableItem coveoIndexableItem = p_Args.CoveoItem; SitecoreIndexableItem sitecoreIndexableItem = p_Args.Item as SitecoreIndexableItem; ISearchIndex searchIndex = m_CoveoIndexFetcher.GetCoveoSearchIndex(sitecoreIndexableItem); IFieldNameTranslator translator = searchIndex.FieldNameTranslator as IFieldNameTranslator; bool isFieldRemoverActive = IsFieldRemoverActive(sitecoreIndexableItem); bool isPreviewRemoverActive = IsPreviewRemoverActive(sitecoreIndexableItem); string newUniqueId = coveoIndexableItem.UniqueId + LimitedItemSuffix; string newUri = coveoIndexableItem.Uri + LimitedItemSuffix; byte[] hiddenButSearchableItemPreview = coveoIndexableItem.BinaryData; if (coveoIndexableItem != null && sitecoreIndexableItem != null && (isFieldRemoverActive || isPreviewRemoverActive)) { // Add information in metadata to spot the duplicate and to indicates which fields needs to be stripped Dictionary <string, object> newMetadata = new Dictionary <string, object>(coveoIndexableItem.Metadata); String[] SitecoreFieldsToHide = newMetadata[SITECORE_FIELDS_TO_HIDE_ID_LIST].ToString().Split(CHAR_SEPARATOR_FOR_FIELDS_TO_REMOVE); List <string> fieldsToHideList = new List <string>(); foreach (string field in SitecoreFieldsToHide) { fieldsToHideList.Add(translator.TranslateToCoveoFormat(sitecoreIndexableItem.GetFieldById(new ID(field)).Name)); } ; newMetadata.Add(REMOVED_FIELDS_NAME_METADATA_KEY, string.Join(STRING_SEPARATOR_FOR_FIELDS_TO_REMOVE, fieldsToHideList)); newMetadata.Add(ITEM_IS_A_COPY_METADATA_KEY, CHECKBOX_FIELD_CHECKED_VALUE); CoveoIndexableItem strippedItem = new CoveoIndexableItem { //Modify the ID, the metadata and the URI UniqueId = newUniqueId, Metadata = newMetadata, Uri = newUri, //Add anonymous permissions Permissions = CreateAnonymousAccessRule(), //Copy the rest of the original item data BinaryData = coveoIndexableItem.BinaryData, BinaryDataMimeType = coveoIndexableItem.BinaryDataMimeType, BinaryDataPath = coveoIndexableItem.BinaryDataPath, ClickableUri = coveoIndexableItem.ClickableUri, FileName = coveoIndexableItem.FileName, HasSubItems = coveoIndexableItem.HasSubItems, Id = coveoIndexableItem.Id, IsDeletedItem = coveoIndexableItem.IsDeletedItem, ModifiedDate = coveoIndexableItem.ModifiedDate, Parent = coveoIndexableItem.Parent, ParentId = coveoIndexableItem.ParentId, Path = coveoIndexableItem.Path, PrintablePath = coveoIndexableItem.PrintablePath, Title = coveoIndexableItem.Title, }; p_Args.OutputCoveoItems.Add(strippedItem); } ; s_Logger.TraceExiting(); }
public TokenResponse(T token) { Precondition.NotNull(token, "token"); this.Token = token; }
protected UserScript(Client client) : base(client) { manager = client.ScriptManager; Precondition.NotNull(manager); }