Example #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UriDatasource" /> class.
 /// </summary>
 /// <param name="http">DashboardHttp object containing request</param>
 /// <param name="httpContext">Http web context or null if not a web request</param>
 public UriDatasource(DashboardHttp http, HttpContextBase httpContext)
 {
     this.configuration = new FeedConfiguration(httpContext);
     this.configurationContext = httpContext;
     this.httpRequest = http;
     this.GetConfigSettings();
 }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FileDatasource" /> class.
        /// Can be overwritten with
        /// FileName property. 
        /// </summary>
        /// <param name="pathToFilename">full path to filename including postpend slash</param>
        /// <param name="httpContext">HttpContextBase - used to determine config file location</param>
        public FileDatasource(string pathToFilename, HttpContextBase httpContext)
        {
            // set this once in constructor
            this.configurationContext = httpContext;
            this.config = new FeedConfiguration(this.configurationContext);

            this.FileName = pathToFilename + this.config.SerializedFeedListFile;

            if (string.IsNullOrEmpty(this.FileName))
            {
                throw new NullReferenceException("FileDatasource::FileDatasource - FileName is null or empty");
            }
        }
        /// <summary>
        /// This defines the behavior of the UntypedActor.
        /// This method is called for every message received by the actor.
        /// </summary>
        /// <param name="message">The message.</param>
        protected override void OnReceive(object message)
        {
            Logger.Log(LogSeverity.Debug, LogCategory, $"{this.config?.Name ?? "?"} received '{message}'.");

            switch (message)
            {
            case null:
                break;

            case FeedConfiguration cfg:
                this.config     = cfg;
                this.downloader = Context.ActorOf <ShowDownloader>(Support.Cleanup.MakeActorName(cfg.Name + "-showdownloader"));
                this.Self.Tell(LoadCommand);
                break;

            case LoadCommand:
                // read the feed and fire off the "Process"
                this.podcast = this.LoadFeed();
                this.Self.Tell(ProcessCommand);
                break;

            case ProcessCommand:
                // queue the various shows for download on the single downloader
                this.ReadAllShows();
                break;

            case ShowProgressMessage spm:
                if (spm.FeedName is null)
                {
                    spm = new ShowProgressMessage(this.config.Name, spm.FileName, spm.BytesRead, spm.Message);
                }

                Context.Parent.Tell(spm, this.Self);
                break;

            case FileStored stored:
                //// have the PodcastManager update the stored "latest download" date.
                Context.Parent.Tell(stored.SetFeedName(this.config.Name));
                break;

            case QueueIsDoneMessage:
                Context.Stop(Context.Sender);
                Context.Parent.Tell(new ShowProgressMessage(this.config.Name, "--", 0, "Feed is done"));
                Context.Parent.Tell(PodcastManager.FeedIsDoneMessage);
                break;

            default:
                Logger.Log(LogSeverity.Warning, LogCategory, "Ignoring unknown message in FeedDownloader: " + message);
                break;
            }
        }
        public void Get()
        {
            // arrange
            HttpContextBase httpContext = null;

            FeedConfiguration dashboardConfiguration = new FeedConfiguration(httpContext);
            string pathToFilename = Setup.GetDataPath();

            FileDatasource fileDatasource = new FileDatasource(pathToFilename, httpContext);

            fileDatasource.RssFeeds = this.rssFeeds;
            fileDatasource.Set();

            // act
            RssFeeds actual = fileDatasource.Get();

            // assert
            Assert.IsTrue(actual.Equals(this.rssFeeds));

            // cleanup
            File.Delete(fileDatasource.FileName);
        }
Example #5
0
        /// <summary>
        /// Get all config settings. Sets 
        /// dashboardURI. Creates new DashboardHttp
        /// for httpRequest. Calls BuildHttpGet. All
        /// of these can be overwritten/called again
        /// later.
        /// </summary>
        private void GetConfigSettings()
        {
            this.configuration = new FeedConfiguration(this.configurationContext);

            // need an http requester - this can always be overwritten
            this.dashboardURI = new Uri(this.configuration.AzureUri);
            this.httpRequest = new DashboardHttp(this.dashboardURI);
        }
Example #6
0
        /// <summary>
        /// Pull Html file from Windows Azure only once, store it,
        /// save file name.
        /// </summary>
        /// <returns>filename as string</returns>
        public static string RunBeforeTests()
        {
            Trace.TraceInformation("RunBeforeAnyTests a");

            // if there is a file with today's date, don't do anything
            string fileName = @"..\..\..\Wp7AzureMgmt.DashboardFeeds.Test\Html_634871865298370572.html";
            HttpContextBase httpContext = null;

            // file built today not found so go build it
            // runs inside same day can use today's html
            if (!File.Exists(fileName))
            {
                Trace.TraceInformation("RunBeforeAnyTests b");

                // initialize Uri
                UriDatasource uriDatasource = new UriDatasource(null, httpContext);

                DashboardHttp http = new DashboardHttp(uriDatasource.DashboardUri);

                uriDatasource.DashboardHttp = http;

                // get html and save to serialized file
                // set filename in config file as test
                uriDatasource.GetAndSaveHtml(fileName);

                // Save filename to config file so test run can use it for parsing
                FeedConfiguration dbconf = new FeedConfiguration(httpContext);
                dbconf.TestFileName = fileName;

                Trace.TraceInformation("RunBeforeAnyTests c");
            }

            Trace.TraceInformation("RunBeforeAnyTests d");

            return fileName;
        }
        public void GetHtml()
        {
            // arrange
            int lastKnownLength = 300000;
            HttpContextBase httpContext = null;

            UriDatasource uriDatasource = new UriDatasource(null, httpContext);
            FeedConfiguration config = new FeedConfiguration(null);
            DashboardHttp http = new DashboardHttp(new Uri(config.AzureUri));
            uriDatasource.DashboardHttp = http;

            // act
            string actual = uriDatasource.GetHtml();

            // save to file
            File.WriteAllText("Html_" + DateTime.Now.Ticks + ".html", actual);

            // assert

            // if this length is wrong then the file Azure returns
            // has changed since the last test
            Assert.IsTrue(lastKnownLength <= actual.Length);
        }
Example #8
0
        public dynamic Execute(dynamic parameters, INancyModule module)
        {
            module.RequiresAuthentication();

            IFeed feed;

            try
            {
                feed = module.Bind <Feed>();

                ITransaction transaction = _store.BeginTransaction();

                var existingFeedExists =
                    transaction.Query <IFeed>().Where("Name = @feedName").Parameter("feedName", feed.Name).Count() >
                    0;

                if (existingFeedExists)
                {
                    return(HttpStatusCode.Conflict);
                }

                if (!string.IsNullOrWhiteSpace(feed.ApiKey))
                {
                    ICryptoService cryptoService = new PBKDF2();

                    feed.ApiKeySalt   = cryptoService.GenerateSalt();
                    feed.ApiKeyHashed = cryptoService.Compute(feed.ApiKey);
                }

                transaction.Insert(feed);
                transaction.Commit();
                transaction.Dispose();

                transaction = _store.BeginTransaction();

                feed =
                    transaction.Query <IFeed>()
                    .Where("Name = @feedName")
                    .Parameter("feedName", feed.Name)
                    .First();

                var appFolder  = _home.InstallDirectory;
                var feedFolder = Path.Combine(appFolder, "Feeds", feed.Id.ToString());

                IFeedConfiguration config = new FeedConfiguration
                {
                    FeedId            = feed.Id,
                    PackagesDirectory = feedFolder
                };

                transaction.Insert(config);
                transaction.Commit();
                transaction.Dispose();
            }
            catch (Exception ex)
            {
                return(HttpStatusCode.InternalServerError);
            }

            feed.ApiKeyHashed = null; //Temporary until API Key table is used
            feed.ApiKeySalt   = null; //Temporary until API Key table is used

            return(feed);
        }