public FtpBinding(FtpConfiguration config, ParameterInfo parameter, TraceWriter trace, FtpAttribute ftpAttribute)
 {
     _config = config;
     _parameter = parameter;
     _trace = trace;
     _ftpAttribute = ftpAttribute;
 }
 /// <summary>
 /// This WebHook declares its route, and is invoked by POST requests
 /// to http://localhost:{port}/Sample/HookB.
 /// </summary>
 public static async Task HookB(
     [WebHookTrigger("Sample/HookB")] HttpRequestMessage request, 
     TraceWriter trace)
 {
     string body = await request.Content.ReadAsStringAsync();
     trace.Info(string.Format("HookB invoked! Body: {0}", body));
 }
 public CacheReceiver(RedisConfiguration config, string channelOrKey, string lastValueKeyName, TraceWriter trace)
 {
     _config = config;
     _channelOrKey = channelOrKey;
     _lastValueKeyName = lastValueKeyName;
     _trace = trace;
 }
        // On Timer, grab items from RSS Feed
        public void RSSFeedProcessor(
            [TimerTrigger("0 */5 * * * *", RunOnStartup=true)] TimerInfo timer, 
            [Queue("SaveQuestions")] ICollector<Question> outQ, 
            TraceWriter log)
        {
            log.Verbose("RSS Feed Processor started");
            Console.WriteLine("RSS Feed Processor started");

            foreach (var feeds in mFeedSources)
            {
                switch(feeds.Key){
                    case "StackOverflow":
                        foreach (var feed in feeds.Value) {
                            try {
                                using (XmlReader reader = XmlReader.Create(feed.Value)) {
                                    SyndicationFeed rss = SyndicationFeed.Load(reader);

                                    foreach (SyndicationItem item in rss.Items) {
                                        outQ.Add(ProcessStackOverflowEntry(item, feed.Key));
                                    }
                                }
                            }
                            catch (Exception e)
                            {
                                log.Error(String.Format("Couldn't read from feed - {0}", feeds.Value), e);
                            }
                        }
                        break;
                    default:
                        log.Warning(String.Format("Couldn't recognize feed format: {0}", feeds.Key),"RSSFeedProcessor");
                        break;
                }
            }
        }
 public FSharpCompiler(IFunctionMetadataResolver metadataResolver, OptimizationLevel optimizationLevel, TraceWriter traceWriter)
 {
     _metadataResolver = metadataResolver;
     _optimizationLevel = optimizationLevel;
     _traceWriter = traceWriter;
     _hashRRegex = new Regex(@"^\s*#r\s+", RegexOptions.Compiled | RegexOptions.IgnoreCase);
 }
        public static async Task SingletonJob([QueueTrigger("singleton-test")] WorkItem workItem, TraceWriter trace)
        {
            trace.Info("Singleton method started");

            await Task.Delay(10 * 1000);

            trace.Info("Singleton method completed");
        }
 public SingletonManager(IStorageAccountProvider accountProvider, IBackgroundExceptionDispatcher backgroundExceptionDispatcher, SingletonConfiguration config, TraceWriter trace, INameResolver nameResolver = null)
 {
     _accountProvider = accountProvider;
     _nameResolver = nameResolver;
     _backgroundExceptionDispatcher = backgroundExceptionDispatcher;
     _config = config;
     _trace = trace;
 }
 public WebHookDispatcher(WebHooksConfiguration webHooksConfig, JobHost host, JobHostConfiguration config, TraceWriter trace)
 {
     _functions = new ConcurrentDictionary<string, ITriggeredFunctionExecutor>();
     _trace = trace;
     _port = webHooksConfig.Port;
     _types = config.TypeLocator.GetTypes().ToArray();
     _host = host;
 }
 public TimerTriggerBinding(ParameterInfo parameter, TimerTriggerAttribute attribute, TimersConfiguration config, TraceWriter trace)
 {
     _attribute = attribute;
     _parameter = parameter;
     _config = config;
     _trace = trace;
     _bindingContract = CreateBindingDataContract();
 }
        public static async Task WebHookTrigger(HttpRequestMessage request, TraceWriter traceWriter)
        {
            string body = await request.Content.ReadAsStringAsync();

            InvokeData = body;

            traceWriter.Info(string.Format("C# WebHookTrigger function received message '{0}'", body));
        }
        public static void SendSimplePubSubMessage([Redis("simpleMessages", Mode.PubSub)] out string message, TextWriter log, TraceWriter trace)
        {
            message = "this is a test";

            log.WriteLine("sending message: " + message);

            trace.Info(string.Format("New message sent: {0}", message));
        }
 public FunctionAssemblyLoadContext(FunctionMetadata functionMetadata, Assembly functionAssembly, IFunctionMetadataResolver resolver, TraceWriter traceWriter)
 {
     _metadataResolver = resolver;
     _loadedAssemblies = ImmutableArray<Assembly>.Empty;
     _traceWriter = traceWriter;
     FunctionAssembly = functionAssembly;
     Metadata = functionMetadata;
 }
 public FileTriggerBinding(FilesConfiguration config, ParameterInfo parameter, TraceWriter trace)
 {
     _config = config;
     _parameter = parameter;
     _trace = trace;
     _attribute = parameter.GetCustomAttribute<FileTriggerAttribute>(inherit: false);
     _bindingContract = CreateBindingContract();
 }
 public SingletonManager(IStorageBlobClient blobClient, IBackgroundExceptionDispatcher backgroundExceptionDispatcher, SingletonConfiguration config, TraceWriter trace)
 {
     _backgroundExceptionDispatcher = backgroundExceptionDispatcher;
     _directory = blobClient.GetContainerReference(HostContainerNames.Hosts)
                            .GetDirectoryReference(HostDirectoryNames.SingletonLocks);
     _config = config;
     _trace = trace;
 }
 public FunctionMetadataResolver(FunctionMetadata metadata, TraceWriter traceWriter)
 {
     _functionMetadata = metadata;
     _traceWriter = traceWriter;
     _packageAssemblyResolver = new PackageAssemblyResolver(metadata);
     _privateAssembliesPath = GetBinDirectory(metadata);
     _scriptResolver = ScriptMetadataResolver.Default.WithSearchPaths(_privateAssembliesPath);
 }
 /// <summary>
 /// Demonstrates binding to a custom POCO Type, including model binding in other
 /// binders to values from that POCO.
 /// </summary>
 public static void HookC(
     [WebHookTrigger] Order order,
     [File(@"{OrderId}_{CustomerName}.txt", FileAccess.Write)] out string output,
     TraceWriter trace)
 {
     output = "Order Received!";
     trace.Info(string.Format("HookC invoked! OrderId: {0}", order.OrderId));
 }
        /// <summary>
        /// GitHub WebHook example, showing integration with the ASP.NET WebHooks SDK.
        /// The route uses the format {receiver}/{id} where the receiver "github" corresponds
        /// to the <see cref="GitHubWebHookReceiver"/> that was registered on startup via
        /// <see cref="WebHooksConfiguration.UseReceiver{T}"/>, and the "issues" Id component
        /// corresponds to the "Issues" secret configured in app.config.
        /// Incoming requests will be authenticated by <see cref="GitHubWebHookReceiver"/> prior
        /// to invoking this job function.
        /// </summary>
        public static void GitHub(
            [WebHookTrigger("github/issues")] string body,
            TraceWriter trace)
        {
            dynamic issueEvent = JObject.Parse(body);

            trace.Info(string.Format("GitHub Issues WebHook invoked - Issue: '{0}', Action: '{1}', ",
                issueEvent.issue.title, issueEvent.action));
        }
 public FunctionMetadataResolver(FunctionMetadata metadata, ICollection<ScriptBindingProvider> bindingProviders, TraceWriter traceWriter)
 {
     _functionMetadata = metadata;
     _traceWriter = traceWriter;
     _packageAssemblyResolver = new PackageAssemblyResolver(metadata);
     _privateAssembliesPath = GetBinDirectory(metadata);
     _scriptResolver = ScriptMetadataResolver.Default.WithSearchPaths(_privateAssembliesPath);
     _extensionSharedAssemblyProvider = new ExtensionSharedAssemblyProvider(bindingProviders);
 }
 public FileListener(FilesConfiguration config, FileTriggerAttribute attribute, ITriggeredFunctionExecutor triggerExecutor, TraceWriter trace)
 {
     _config = config;
     _attribute = attribute;
     _triggerExecutor = triggerExecutor;
     _trace = trace;
     _cancellationTokenSource = new CancellationTokenSource();
     _watchPath = Path.Combine(_config.RootPath, _attribute.GetNormalizedPath());
 }
        protected ScriptHost(ScriptHostConfiguration scriptConfig) 
            : base(scriptConfig.HostConfig)
        {
            ScriptConfig = scriptConfig;

            if (scriptConfig.FileLoggingEnabled)
            {
                string hostLogFilePath = Path.Combine(scriptConfig.RootLogPath, "Host");
                _traceWriter = new FileTraceWriter(hostLogFilePath, TraceLevel.Verbose);
                scriptConfig.HostConfig.Tracing.Tracers.Add(_traceWriter);
            }
            else
            {
                _traceWriter = NullTraceWriter.Instance;
            }

            if (scriptConfig.TraceWriter != null)
            {
                scriptConfig.HostConfig.Tracing.Tracers.Add(scriptConfig.TraceWriter);
            }
            else
            {
                scriptConfig.TraceWriter = NullTraceWriter.Instance;
            }

            if (scriptConfig.FileWatchingEnabled)
            {
                _fileWatcher = new FileSystemWatcher(scriptConfig.RootScriptPath)
                {
                    IncludeSubdirectories = true,
                    EnableRaisingEvents = true
                };
                _fileWatcher.Changed += OnFileChanged;
                _fileWatcher.Created += OnFileChanged;
                _fileWatcher.Deleted += OnFileChanged;
                _fileWatcher.Renamed += OnFileChanged;
            }

            // If a file change should result in a restart, we debounce the event to
            // ensure that only a single restart is triggered within a specific time window.
            // This allows us to deal with a large set of file change events that might
            // result from a bulk copy/unzip operation. In such cases, we only want to
            // restart after ALL the operations are complete and there is a quiet period.
            _restart = (e) =>
            {
                _traceWriter.Verbose(string.Format("File change of type '{0}' detected for '{1}'", e.ChangeType, e.FullPath));
                _traceWriter.Verbose("Host configuration has changed. Signaling restart.");

                // signal host restart
                _restartEvent.Set();
            };
            _restart = _restart.Debounce(500);

            // take a snapshot so we can detect function additions/removals
            _directoryCountSnapshot = Directory.EnumerateDirectories(ScriptConfig.RootScriptPath).Count();
        }
 public RedisTriggerBinding(ParameterInfo parameter, RedisAccount account, string channelOrKey, Mode mode, RedisConfiguration config, TraceWriter trace)
 {
     _parameter = parameter;
     _account = account;
     _channelOrKey = channelOrKey;
     _mode = mode;
     _config = config;
     _bindingDataProvider = BindingDataProvider.FromType(parameter.ParameterType);
     _trace = trace;
 }
        public RedisChannelListener(string channelOrKey, ITriggeredFunctionExecutor triggerExecutor, RedisConfiguration config, TraceWriter trace)
            : base()
        {
            _channelOrKey = channelOrKey;
            _triggerExecutor = triggerExecutor;
            _config = config;

            _redisProcessor = CreateProcessor(channelOrKey);
            _trace = trace;
        }
        public RedisProcessor(RedisProcessorContext context, TraceWriter trace)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            ChannelOrKey = context.ChannelOrKey;
            _trace = trace;
        }
 public TimerListener(TimerTriggerAttribute attribute, string timerName, TimersConfiguration config, ITriggeredFunctionExecutor executor, TraceWriter trace)
 {
     _attribute = attribute;
     _timerName = timerName;
     _config = config;
     _executor = executor;
     _trace = trace;
     _cancellationTokenSource = new CancellationTokenSource();
     _schedule = _attribute.Schedule;
     ScheduleMonitor = _attribute.UseMonitor ? _config.ScheduleMonitor : null;
 }
        public static async Task<BlobLeaseManager> CreateAsync(string accountConnectionString, TimeSpan leaseTimeout, string hostId, string instanceId, TraceWriter traceWriter)
        {
            if (leaseTimeout.TotalSeconds < 15 || leaseTimeout.TotalSeconds > 60)
            {
                throw new ArgumentOutOfRangeException(nameof(leaseTimeout), $"The {nameof(leaseTimeout)} should be between 15 and 60 seconds");
            }

            ICloudBlob blob = await GetLockBlobAsync(accountConnectionString, GetBlobName(hostId));
            var manager = new BlobLeaseManager(blob, leaseTimeout, hostId, instanceId, traceWriter);
            return manager;
        }
 public RedisCacheListener(string channelOrKey, ITriggeredFunctionExecutor triggerExecutor,
     RedisConfiguration config, TraceWriter trace)
     : base()
 {
     _channelOrKey = channelOrKey;
     _triggerExecutor = triggerExecutor;
     _config = config;
     _lastValueKeyName = _config.LastValueKeyNamePrefix + channelOrKey;
     _redisProcessor = CreateProcessor(channelOrKey);
     _trace = trace;
 }
        public TimerTriggerBinding(ParameterInfo parameter, TimerTriggerAttribute attribute, TimersConfiguration config, TraceWriter trace)
        {
            _attribute = attribute;
            _parameter = parameter;
            _config = config;
            _trace = trace;
            _bindingContract = CreateBindingDataContract();

            MethodInfo methodInfo = (MethodInfo)parameter.Member;
            _timerName = string.Format("{0}.{1}", methodInfo.DeclaringType.FullName, methodInfo.Name);
        }
        public RedisBinding(string parameterName, IArgumentBinding<RedisEntity> argumentBinding,
            RedisAccount account, RedisAttribute attribute, BindingProviderContext context, TraceWriter trace)
        {
            _parameterName = parameterName;
            _argumentBinding = argumentBinding;
            _account = account;
            _attribute = attribute;
            _mode = attribute.Mode;

            _channelOrKeyPath = BindingTemplate.FromString(attribute.ChannelOrKey);
            _trace = trace;
        }
        private async Task<bool> SendJSONtoURL(JObject json, string url, TraceWriter trace)
        {
            var client = new HttpClient();
            var response = await client.PostAsJsonAsync(url, json);

            if (response.StatusCode != HttpStatusCode.OK) {
                trace.Error(String.Format("Status Code: {0} - Content: {1}", response.StatusCode, response.Content));
                return false;
            }

            trace.Info("Finished sending message to Slack");
            return true;
        }
 // This function will be triggered on a schedule determined by the cron expression provided. In this case it will run every minute.
 // When this trigger is invoked, it enqueues a Message on the MessageQueue.
 // To learn more about TimerTriggers, go to https://github.com/Azure/azure-webjobs-sdk-extensions#timertrigger
 public static void TimedQueueMessage(
     [TimerTrigger("0 * * * * *", RunOnStartup = true)] TimerInfo timer,
     [Queue("MessageQueue")] out Message message,
     TraceWriter log
 )
 {
     // Create a new message
     message = new Message()
     {
         message = timer.FormatNextOccurrences(1)
     };
     log.Verbose("New message enqueued");
 }
    static void Main(string[] args)
    {
        // var loggerEnvironment = "AzureFunctions";
        var     loggerEnvironment = "ConsoleApp";
        ILogger logger            = null;

        if (loggerEnvironment == "AzureFunctions")
        {
            Microsoft.Azure.WebJobs.Host.TraceWriter azureFunctionLogger = null;
            logger = new AzureFunctionLogger(azureFunctionLogger);
        }
        else if (loggerEnvironment == "ConsoleApp")
        {
            logger = new TraceLogger();
        }
        var doStuff = new DoStuff(logger);

        Console.ReadKey();
    }
 public AzureFunctionLogger(Microsoft.Azure.WebJobs.Host.TraceWriter logger)
 {
     _logger = logger;
 }