Пример #1
0
        public static void Build(IConfigurationBuilder config, string environment)
        {
            // The SECRETS" folder is outside of our Github repo. In this folder is:
            //    appsettings.Secrets.json - secrets used in both production and development.
            //    appsettings.Production.json - production-only settings
            // At the solution root is stored appsettings.Development.json. This file is read by
            // both WebApp & WorkflowApp.
            // Appsettings that are set later will override earlier ones.
            // https://andrewlock.net/including-linked-files-from-outside-the-project-directory-in-asp-net-core/

            if (environment == "Development")
            {
                // For development, get the appsettings files from the SECRETS and solution folders.
                string solutionFolder = GMFileAccess.GetSolutionFolder();
                string secretsFolder  = GMFileAccess.GetSecretsFolder();

                config
                .AddJsonFile(Path.Combine(solutionFolder, "appsettings.Development.json"), optional: true)
                .AddJsonFile(Path.Combine(secretsFolder, "appsettings.Secrets.json"), optional: true);
            }
            else
            {
                // Otherwise, assume that the appsettings files are in the deployment folder.
                config
                .AddJsonFile("appsettings.Secrets.json", optional: true)
                .AddJsonFile($"appsettings.{environment}.json", optional: true);
            }

            // Allow appsettings to be overidden by an optional "appsettings.json" file in the project folder.
            // Currently, neither WebApp nor WorkflowApp have one.
            config.AddJsonFile("appsettings.json", optional: true);

            // Environment settings override all else.
            config.AddEnvironmentVariables();
        }
Пример #2
0
        private static bool update = true; // if true, only re-translate files that were edited (NOT WORKING)

        public static void Main(string[] args)
        {
            // create service collection
            var services = new ServiceCollection();

            ConfigureServices(services);

            // create service provider
            var serviceProvider = services.BuildServiceProvider();

            GMFileAccess.SetGoogleCredentialsEnvironmentVariable();

            TranslateDocs translate = serviceProvider.GetService <TranslateDocs>();

            // ################  Translate documentation files ########################

            // UNCOMMENT one of the following lines as you prefer
            //TranslateDocumentsLanguages(allDocuments, allLanguages, update);
            //translate.TranslateDocuments(allDocuments, someLanguages, update);
            //translate.TranslateDocuments(someDocuments, allLanguages, update);
            //translate.TranslateDocuments(someDocuments, someLanguages, update);


            // ################  Add new language to lookup arrays for GUI ########################

            // UNCOMMENT this to add a new language to the arrays.
            //translate.AddNewLanguageToArrays("hu", "Hungarian")
        }
Пример #3
0
        public void AddNewLanguageToArrays(string language, string languageName)
        {

            // Document page titles in sidebar
            string docpagesFile = Path.Combine(GMFileAccess.GetClientAppFolder(), @"src\app\about-project\document-pages.ts");
            string docpages = @"""Overview"", ""Workflow"", ""Project status"", ""Setup"", ""Developer notes"", ""Database"", ""Design""";
            string translated = translateInCloud.TranslateText(docpages, language);  // translate
            translated = Regex.Replace(translated, @"„|”|“", @"""");        // replace other version of double quotes.
            string text = File.ReadAllText(docpagesFile);
            string newtext = text.Replace(@"]//ADD_HERE", @"]," + Environment.NewLine + @"    [""" + languageName + @""", """ + language + @""", " + translated + @"]//ADD_HERE");
            File.WriteAllText(docpagesFile, newtext);

            // Dashboard card titles in header
            string dashtitlesFile = Path.Combine(GMFileAccess.GetClientAppFolder(), @"src\app\dashboard\dashboard-titles.ts");
            string dashtitles = @"""Politics"", ""Legislation"", ""Meetings"", ""Govmeeting News"", ""Edit Transcript"", ""Add Tags to Transcript"", ""View Transcript"", ""Issues"", ""Officials"", ""Virtual Meeting"", ""Chat"", ""Charts"", ""Notes"", ""Meeting Minutes"", ""Work Items"", ""Alerts""";
            translated = translateInCloud.TranslateText(dashtitles, language);  // translate
            translated = Regex.Replace(translated, @"„|”|“", @"""");        // replace other version of double quotes.
            text = File.ReadAllText(dashtitlesFile);
            newtext = text.Replace(@"]//ADD_HERE", @"]," + Environment.NewLine + @"    [""" + languageName + @""", """ + language + @""", " + translated + @"]//ADD_HERE");
            File.WriteAllText(dashtitlesFile, newtext);

            // Language choices in dropdown box in sidenav header
            string sidenavheaderFile = Path.Combine(GMFileAccess.GetClientAppFolder(), @"src\app\sidenav\sidenav-header\sidenav-header.ts");
            // {enname: 'English', value: 'en', viewValue: 'English'}
            translated = translateInCloud.TranslateText(languageName, language);  // translate
            text = File.ReadAllText(sidenavheaderFile);
            newtext = text.Replace(@"}//ADD_HERE", @"}," + Environment.NewLine + @"    {enname: '" + languageName + @"', value: '" + language + @"', viewValue: '" + translated + @"'}//ADD_HERE");
            File.WriteAllText(sidenavheaderFile, newtext);
        }
Пример #4
0
        private void TranslateOneDocument(string file, string language, bool deletePrior)
        {
            string newFile = file.Replace(".en.md", "." + language + ".md");

            if (File.Exists(newFile) && deletePrior)
            {
                File.Delete(newFile);
            }


            if (!File.Exists(newFile))
            {
                string contents     = GMFileAccess.Readfile(file);
                var    htmlContents = CommonMark.CommonMarkConverter.Convert(contents);
                //string htmlFile = f.Replace(".en.md", ".en.html");
                //File.WriteAllText(htmlFile, htmlContents);

                string translated = translateInCloud.TranslateHtml(htmlContents, language);
                //string htmlNewFile = f.Replace(".en.md", "." + language + ".html");
                //File.WriteAllText(htmlNewFile, translated);

                string replaced = ReplaceSomeStrings(translated);
                File.WriteAllText(newFile, replaced);

                // Wait 10 seconds. GCP didn't like me running a close loop.
                Task.Delay(10000).Wait();
            }
        }
        public static void Main(string[] args)
        {
            // https://pioneercode.com/post/dependency-injection-logging-and-configuration-in-a-dot-net-core-console-app

            // create service collection
            var services = new ServiceCollection();

            ConfigureServices(services);

            // create service provider
            var serviceProvider = services.BuildServiceProvider();

            //var m = serviceProvider.GetService<IMeetingRepository>();

            var    config        = serviceProvider.GetService <IOptions <AppSettings> >().Value;
            string testfilesPath = config.TestfilesPath;
            string datafilesPath = config.DatafilesPath;

            // Delete PROCESSING folder?
            if (config.DeleteProcessingFolderOnStartup)
            {
                GMFileAccess.DeleteDirectoryContents(datafilesPath + @"\PROCESSING");
            }

            // Copy test data to Datafiles
            InitializeFileTestData.CopyTestData(testfilesPath, datafilesPath);

            // entry to run app
            serviceProvider.GetService <WorkflowController>().Run();
        }
Пример #6
0
        static string AddPath(string name)
        {
            // our work folder
            string testdataFolder = Path.Combine(GMFileAccess.GetTestdataFolder(), "DevelopTranscription");

            return(Path.Combine(testdataFolder, name));
        }
        public static void Main(string[] args)
        {
            // create service collection
            var services = new ServiceCollection();

            ConfigureServices(services);

            // create service provider
            var serviceProvider = services.BuildServiceProvider();

            // Get appsettings
            //var config = serviceProvider.GetService<IOptions<AppSettings>>().Value;

            // Find path to the _SECRETS folder
            string credentialsFilePath;
            string secrets = GMFileAccess.FindParentFolderWithName("_SECRETS");

            // If it exists look there for Google Application Credentials.
            if (secrets != null)
            {
                credentialsFilePath = Path.Combine(secrets, "TranscribeAudio.json");
            }
            else
            {
                Console.WriteLine("ERROR: Can't located Google Application Credentials");
                return;
            }

            // Google Cloud libraries automatically use the environment variable GOOGLE_APPLICATION_CREDENTIALS
            // to authenticate to Google Cloud. Here we set this variable to the path of the credentials file,
            // which is defined in appsettings.json in the _SECRETS folder
            Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", credentialsFilePath);

            serviceProvider.GetService <TranslateDocs>().Run(args);
        }
Пример #8
0
        // The purpose of deletePrior is to facilitate resuming translation if we abort and restart.
        // Normally, this is set to true, since we always delete the prior translations.
        // If we set it to false and manually delete the translations before starting,
        // then if we abort the process, we can restart it and it will only translate those
        // which haven't been done yet.
        private void TranslateDocument(string document, string language, bool deletePrior)
        {
            string file = GetEnglishDocumentPath(document);
            string newFile = GetTranslatedDocumentPath(document, language);

            if (File.Exists(newFile) && deletePrior)
            {
                File.Delete(newFile);
            }

            if (!File.Exists(newFile))
            {
                string contents = GMFileAccess.Readfile(file);
                var htmlContents = CommonMark.CommonMarkConverter.Convert(contents);
                //string htmlFile = file.Replace(".md", ".html");
                //File.WriteAllText(htmlFile, htmlContents);

                string doNotEdit = "<!-- Do not edit this file. It was translated by Google. -->\n";

                contents = doNotEdit + contents;

                string translated = translateInCloud.TranslateHtml(htmlContents, language);
                //string htmlNewFile = newfile.Replace(".md", ".html");
                //File.WriteAllText(htmlNewFile, translated);

                string replaced = ReplaceSomeStrings(translated);

                File.WriteAllText(newFile, doNotEdit + replaced);

                // Wait 30 seconds. GCP didn't like me running a close loop.
                Task.Delay(30000).Wait();
            }
        }
Пример #9
0
        // Copy sample test data from the "testdata" folder to the "DATAFILES" folder.
        public static void CopyTestData(string testfilesPath, string datafilesPath)
        {
            string[] dirs = new string[]
            {
                // This data is for a meeting that was transcribed from an .mp4 file and
                //  the transcript is currently being proofread. When you run WebApp and click on "Fixasr",
                // this is the data that you will see.
                @"USA_ME_LincolnCounty_BoothbayHarbor_Selectmen_en\2017-02-15",     // For Fixasr
                //@"USA_ME_LincolnCounty_BoothbayHarbor_Selectmen_en\2017-01-09",     // For Fixasr

                // This data is for a meeting for which was retrieved as a PDF file of the transcript.
                // The preprocessing was completed. We are now on the step of adding tags. When you run WebApp
                // and click on "Addtags", this is the data that you will see.
                @"USA_PA_Philadelphia_Philadelphia_CityCouncil_en\2014-09-25",       // For Addtags

                // This data is for a meeting that was transcribed, fixed and tags added. We can now view the completed
                // transcript. When you run WebApp and click on "ViewMeeting", this is the data that you will see.
                @"USA_ME_LincolnCounty_BoothbayHarbor_Selectmen_en\2014-09-08",     // For ViewMeeting
            };

            foreach (string dir in dirs)
            {
                string source      = Path.Combine(testfilesPath, dir);
                string destination = Path.Combine(datafilesPath, "PROCESSING", dir);
                if (!Directory.Exists(destination))
                {
                    Directory.CreateDirectory(destination);
                    GMFileAccess.CopyContents(source, destination);
                }
            }
        }
Пример #10
0
        static void Main(string[] args)
        {
            ////LoadDatabase loadDatabase = new LoadDatabase();
            string projectFolder  = GMFileAccess.FindParentFolderWithName("DevelopLoadDatabase");
            string sampleDataFile = Path.Combine(projectFolder, "SampleTranscriptViewModel.json");

            ////loadDatabase.LoadSampleData(sampleDataFile);
        }
Пример #11
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            string outputFolder = Path.Combine(GMFileAccess.GetTestdataFolder(), "DevelopRetrieval");

            USA_TX_TravisCounty_Austin_CityCouncil_en getTrans = new USA_TX_TravisCounty_Austin_CityCouncil_en();

            DateTime lastMeetingTime = new DateTime(2020, 1, 1);
            bool     result          = getTrans.Do(lastMeetingTime, outputFolder);
        }
Пример #12
0
        public static void Main()
        {
            // https://pioneercode.com/post/dependency-injection-logging-and-configuration-in-a-dot-net-core-console-app

            string secrets             = GMFileAccess.GetSolutionSiblingFolder("SECRETS");
            string credentialsFilePath = Path.Combine(secrets, "TranscribeAudio.json");

            Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", credentialsFilePath);

            //StorageClient storageClient = StorageClient.Create();
            //string secrets = GMFileAccess.FindParentFolderWithName("SECRETS");


            // create service collection
            var services = new ServiceCollection();

            ConfigureServices(services);

            // create service provider
            var serviceProvider = services.BuildServiceProvider();

            //var m = serviceProvider.GetService<IMeetingRepository>();

            var    config        = serviceProvider.GetService <IOptions <AppSettings> >().Value;
            string testfilesPath = config.TestdataPath;
            string datafilesPath = config.DatafilesPath;

            var logger = serviceProvider.GetService <ILogger <Program> >();

            // Google Cloud libraries automatically use the environment variable GOOGLE_APPLICATION_CREDENTIALS
            // to authenticate to Google Cloud. Here we set this variable to the path of the credentials file,
            // which is defined in app.settings.json.
            //string credentialsFilePath = config.GoogleApplicationCredentials;
            //if (!File.Exists(credentialsFilePath)){
            //    logger.LogError("Credentials File does not exists: ${credentialsFilePath}");
            //}
            //Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", credentialsFilePath);

            //StorageClient storageClient = StorageClient.Create();

            // Copy test data to Datafiles
            if (config.InitializeWithTestData)
            {
                string err = InitializeFileTestData.CopyTestData(testfilesPath, datafilesPath, config.DeleteProcessingFolderOnStartup);
                if (err != null)
                {
                    logger.LogError(err);
                }
            }

            // entry to run app
            serviceProvider.GetService <WorkflowController>().Run();
        }
Пример #13
0
        static void TranscribeVideo(
            SampleVideo sample,              // sample video to use
            string fixedTags,                // file in which to save the fixed transcription
            string audio,                    // file in which to save the extracted audio
            bool useSmallSample,             // if true, use a small sample of the video/audio
            bool useAudioFileAlreadyInCloud, // if true, use prior audio in cloud if it exists
            string rawTranscription)         // file in which to save the raw transcription
        {
            string videofilePath                   = sample.filepath;
            string objectName                      = sample.objectname;
            RepeatedField <string> phrases         = sample.phrases;
            AudioProcessing        audioProcessing = new AudioProcessing();

            string googleCloudBucketName = "govmeeting-transcribe";

            TranscribeParameters transParams = new TranscribeParameters
            {
                audiofilePath              = audio,
                objectName                 = objectName,
                GoogleCloudBucketName      = googleCloudBucketName,
                useAudioFileAlreadyInCloud = useAudioFileAlreadyInCloud,
                language        = "en",
                MinSpeakerCount = 2,
                MaxSpeakerCount = 6,
                phrases         = phrases
            };

            // Clean up from last run
            File.Delete(audio);
            File.Delete(fixedTags);

            if (useSmallSample)
            {
                string shortVideoFile = videofilePath.Replace(".mp4", "-3min.mp4");
                //SplitRecording splitRecording = new SplitRecording();
                audioProcessing.ExtractPart(videofilePath, shortVideoFile, 60, 3 * 60);
                videofilePath = shortVideoFile;
            }

            audioProcessing.Extract(videofilePath, audio);

            GMFileAccess.SetGoogleCredentialsEnvironmentVariable();

            // Transcribe the audio file
            TranscribeAudio transcribe     = new TranscribeAudio();
            Transcribed_Dto response       = transcribe.TranscribeAudioFile(transParams, rawTranscription);
            string          responseString = JsonConvert.SerializeObject(response, Formatting.Indented);

            File.WriteAllText(fixedTags, responseString);

            WriteCopyOfResponse(responseString, fixedTags);
        }
Пример #14
0
        private void ConfigureLoggingService()
        {
            // Set a variable in the gdc which is be used in NLog.config for the
            // base path of our app: ${gdc:item=appbasepath}
            string logfilesPath = GMFileAccess.GetSolutionSiblingFolder(Configuration["Logging:LogfilesPath"]);

            //string logfilesPath = GMFileAccess.GetFullPath(Configuration["AppSettings:LogfilesPath"]);
            GlobalDiagnosticsContext.Set("logfilesPath", logfilesPath);

            // Create an instance of NLog.Logger manually here since it is not available
            // from dependency injection yet.
            logger = LogManager.LoadConfiguration("nlog.config").GetCurrentClassLogger();
        }
Пример #15
0
        //public IServiceCollection AddCQR(this IServiceCollection services)
        //{
        //    services.AddMediatR(Assembly.GetExecutingAssembly());
        //    services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>));
        //    services.AddValidatorsFromAssembly(Assembly.GetExecutingAssembly());
        //    return services;
        //}

        private void ConfigureAppsettings(IServiceCollection services)
        {
            services.AddOptions();
            services.Configure <AppSettings>(Configuration.GetSection("AppSettings"));
            services.Configure <AppSettings>(myOptions =>
            {
                logger.Info("Modify the configuration path options to be full paths.");
                // Modify the configuration path options to be full paths.
                myOptions.DatafilesPath = GMFileAccess.GetSolutionSiblingFolder(myOptions.DatafilesPath);
                myOptions.TestdataPath  = GMFileAccess.GetSolutionSiblingFolder(myOptions.TestdataPath);
                logger.Info("DatafilesPath: {0}, TestdataPath: {2}",
                            myOptions.DatafilesPath, myOptions.TestdataPath);
            });
        }
Пример #16
0
        public static void Main(string[] args)
        {
            // create service collection
            var services = new ServiceCollection();

            ConfigureServices(services);

            // create service provider
            var serviceProvider = services.BuildServiceProvider();


            GMFileAccess.SetGoogleCredentialsEnvironmentVariable();

            serviceProvider.GetService <TranslateDocs>().Run(args);
        }
Пример #17
0
        //public bool SaveLatest(string stringValue)
        //{
        //    return true;
        //}

        string GetByPath(string path)
        {
            try
            {
                string fixasrString = GMFileAccess.Readfile(path);
                if (fixasrString != null)
                {
                    return(fixasrString);
                }
            }
            catch
            {
                return(null);
            }
            return(null);
        }
Пример #18
0
        public void TestMoveToCloudAndTranscribe(string language)
        {
            AudioProcessing audioProcessing = new AudioProcessing();

            string baseName     = "USA_ME_LincolnCounty_BoothbayHarbor_Selectmen_EN_2017-02-15";
            string videoFile    = Path.Combine(config.TestdataPath, baseName + ".mp4");
            string outputFolder = Path.Combine(config.TestdataPath, "TestMoveToCloudAndTranscribe");

            GMFileAccess.DeleteAndCreateDirectory(outputFolder);

            string outputBasePath = Path.Combine(outputFolder, baseName);
            string shortFile      = outputBasePath + ".mp4";
            string audioFile      = outputBasePath + ".flac";
            string jsonFile       = outputBasePath + ".json";


            // Extract short version
            //SplitRecording splitRecording = new SplitRecording();
            audioProcessing.ExtractPart(videoFile, shortFile, 60, 4 * 60);

            // Extract audio.
            audioProcessing.Extract(shortFile, audioFile);

            // Transcribe
            //TranscribeAudio ta = new TranscribeAudio(_config);

            //TranscribeResultOrig response = new TranscribeResultOrig();
            Transcribed_Dto response = new Transcribed_Dto();

            // TODO - signature of TranscribeInCloud has changed.
            // response = transcribe.MoveToCloudAndTranscribe(audioFile, baseName + ".flac", config.GoogleCloudBucketName, config.UseAudioFileAlreadyInCloud, language);

            string stringValue = JsonConvert.SerializeObject(response, Formatting.Indented);

            File.WriteAllText(outputBasePath + "-rsp.json", stringValue);

            // Modify Transcript json format
            //ModifyTranscriptJson_1 mt = new ModifyTranscriptJson_1();
            ModifyTranscriptJson mt = new ModifyTranscriptJson();
            //FixasrViewModel fixasr = mt.Modify(response);
            EditMeeting_Dto meetingEditDto = mt.Modify(response);

            // Create JSON file
            //stringValue = JsonConvert.SerializeObject(fixasr, Formatting.Indented);
            stringValue = JsonConvert.SerializeObject(meetingEditDto, Formatting.Indented);
            File.WriteAllText(jsonFile, stringValue);
        }
Пример #19
0
        public void TestReformatOfTranscribeResponse()
        {
            string inputFile = testfilesPath + @"\USA_ME_LincolnCounty_BoothbayHarbor_Selectmen_EN_2017-02-15-rsp.json";

            string outputFolder = Path.Combine(testfilesPath, "TestReformatOfTranscribeResponse");

            GMFileAccess.DeleteAndCreateDirectory(outputFolder);
            string outputFile = outputFolder + @"\USA_ME_LincolnCounty_BoothbayHarbor_Selectmen_EN_2017-02-15.json";

            string stringValue = File.ReadAllText(inputFile);
            var    transcript  = JsonConvert.DeserializeObject <Transcribed_Dto>(stringValue);

            ModifyTranscriptJson convert        = new ModifyTranscriptJson();
            EditMeeting_Dto      meetingEditDto = convert.Modify(transcript);

            stringValue = JsonConvert.SerializeObject(meetingEditDto, Formatting.Indented);
            File.WriteAllText(outputFile, stringValue);
        }
Пример #20
0
        public void DoSomethingToAllFiles(string lang)
        {
            var files = from f in Directory.EnumerateFiles(folder)
                        where f.EndsWith("." + lang + ".md")
                        select f;

            foreach (string file in files)
            {
                if (!File.Exists(file))
                {
                    Console.WriteLine("ERROR: file does not exist: " + file);
                    continue;
                }

                string contents = GMFileAccess.Readfile(file);

                // Do something
            }
        }
Пример #21
0
        public void DoWork(Meeting meeting)
        {
            ////string workfolderName = dBOperations.GetWorkFolderName(meeting);
            string workfolderName = "kjkjkjkjkoou9ukj";  // TODO - CA
            string workFolderPath = config.DatafilesPath + workfolderName;

            if (!GMFileAccess.CreateDirectory(workFolderPath))
            {
                // We were not able to create a folder for processing this video.
                // Probably because the folder already exists.
                Console.WriteLine("ProcessTranscriptsFiles.cs - ERROR: could not create work folder");
                return;
            }

            string sourceFilePath = Path.Combine(config.DatafilesPath, "RECEIVED", meeting.SourceFilename);

            if (!File.Exists(sourceFilePath))
            {
                logger.LogError("Source file does not exist: ${sourceFilePath}");
                return;
            }

            string destFilePath = Path.Combine(config.DatafilesPath, "PROCESSING", meeting.SourceFilename);

            if (File.Exists(destFilePath))
            {
                logger.LogError("Destination file already exists: ${destFilePath}");
            }
            else
            {
                File.Move(sourceFilePath, destFilePath);
            }


            //transcriptProcess.Process(destFilePath, workFolderPath, meeting.Language);
        }
Пример #22
0
        public void ConfigureServices(IServiceCollection services)
        {
            // Set a variable in the gdc which is be used in NLog.config for the
            // base path of our app: ${gdc:item=appbasepath}
            string logfilesPath = GMFileAccess.GetFullPath(configuration["AppSettings:LogfilesPath"]);

            GlobalDiagnosticsContext.Set("logfilesPath", logfilesPath);

            // Create an instance of NLog.Logger manually here since it is not available
            // from dependency injection yet.
            logger = LogManager.LoadConfiguration("nlog.config").GetCurrentClassLogger();

            logger.Info("Just set value in GDC for NLog and created NLog.Logger instance");
            logger.Info("Modify some AppSettings");

            services.AddOptions();
            services.Configure <AppSettings>(configuration.GetSection("AppSettings"));
            services.Configure <AppSettings>(myOptions =>
            {
                // Modify the configuration path options to be full paths.
                myOptions.LogfilesPath  = GMFileAccess.GetFullPath(myOptions.LogfilesPath);
                myOptions.DatafilesPath = GMFileAccess.GetFullPath(myOptions.DatafilesPath);
                myOptions.TestfilesPath = GMFileAccess.GetFullPath(myOptions.TestfilesPath);
                Console.WriteLine("Datafile path = " + myOptions.DatafilesPath);
            });

            logger.Info("Add ApplicationDbContext");

            services.AddTransient <dBOperations>();
            // We will be able to access ApplicationDbContext in a controller with:
            //    public MyController(ApplicationDbContext context) { ... }

            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlServer(
                                                             configuration["AppSettings:ConnectionString"]
                                                             //sqlServerOptions => sqlServerOptions.MigrationsAssembly("DatabaseAccess_Lib")
                                                             //sqlServerOptions => sqlServerOptions.MigrationsAssembly("WebApp")
                                                             ));

            logger.Info("Add Add Authentication");

            //ConfigureAuthenticationServices(services);
            ConfigureAuthenticationServices(services, logger);

            logger.Info("Add MVC");

            services.AddMvc()
            // The ContractResolver option is to prevent the case of Json field names
            // being changed when retrieved by client.
            // https://codeopinion.com/asp-net-core-mvc-json-output-camelcase-pascalcase/
            .AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver())
            .AddXmlSerializerFormatters();

            logger.Info("Enable Feature Folders");

            // This enables the use of "Feature Folders".
            // https://scottsauber.com/2016/04/25/feature-folder-structure-in-asp-net-core/
            services.Configure <RazorViewEngineOptions>(options =>
            {
                options.ViewLocationExpanders.Add(new FeatureLocationExpander());
            });

            //logger.Info("Add SPA static files");
            //// In production, the Angular files will be served from this directory
            //services.AddSpaStaticFiles(configuration =>
            //{
            //    configuration.RootPath = "../../FrontEnd/ClientApp/dist";
            //    //configuration.RootPath = "ClientApp/dist";
            //});

            logger.Info("Add Application services");

            bool UseDatabaseStubs = (configuration["AppSettings:UseDatabaseStubs"] == "True") ? true : false;

            AddApplicationServices(services, logger, UseDatabaseStubs);

            services.AddSingleton(configuration);
        }
Пример #23
0
        private static void ConfigureServices(IServiceCollection services)
        {
            var environmentName = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");

            // add configured instance of logging
            //services.AddSingleton(new LoggerFactory()
            //    .AddConsole()
            //    .AddDebug());

            // add logging
            services.AddLogging();

            // build configuration
            var config = new ConfigurationBuilder();

            BuildConfig.Build(config, environmentName);

            //// appsettings.json is copied to the output folder during the build.
            //// Otherwise, we would need to set appsettingsdir as follows:
            //// string appsettingsdir = Directory.GetCurrentDirectory() + @"\..\..\..";

            //// Location of appsettings.json
            //string appsettingsdir = Directory.GetCurrentDirectory();

            //string devSettingFile = $"appsettings.{environmentName}.json";
            //// Find path to the SECRETS folder
            //string secrets = GMFileAccess.GetSolutionSiblingFolder("SECRETS");
            //// If it exists look there for environment settings file.
            //if (secrets != null)
            //{
            //    devSettingFile = Path.Combine(secrets, $"appsettings.{environmentName}.json");
            //}

            //var configuration = new ConfigurationBuilder()
            //    // TODO - The following path will only work in development.
            //    // It isn't yet decided how WorkflowApp will run in production.
            //    // Will it be a separate .EXE or a .LIB loaded by WebApp?
            //    .SetBasePath(appsettingsdir)
            //    .AddJsonFile("appsettings.json", false)
            //    .AddJsonFile(devSettingFile, optional: true)
            //    .Build();

            var configuration = config.Build();

            services.AddOptions();
            services.Configure <AppSettings>(configuration.GetSection("AppSettings"));
            services.Configure <AppSettings>(myOptions =>
            {
                // Modify paths to be full paths.
                myOptions.DatafilesPath = GMFileAccess.GetSolutionSiblingFolder(myOptions.DatafilesPath);
                myOptions.TestdataPath  = GMFileAccess.GetSolutionSiblingFolder(myOptions.TestdataPath);
                myOptions.GoogleApplicationCredentials = GMFileAccess.GetSolutionSiblingFolder(myOptions.GoogleApplicationCredentials);
            });

            // add services
            //services.AddTransient<IOptions<AppSettings>>();
            services.AddTransient <ApplicationDbContext>();
            ////services.AddTransient<IDBOperations, DBOperationsStub>();
            services.AddTransient <IRecordingProcess, RecordingProcess>();
            services.AddTransient <TranscribeAudio>();
            services.AddTransient <ITranscriptProcess, TranscriptProcess>();
            //services.AddTransient<ILoadTranscript, LoadTranscript_Stub>();
            services.AddTransient <IFileRepository, FileRepository>();


            // services.AddTransient<IMeetingRepository, MeetingRepository_Stub>();
            // services.AddTransient<IGovbodyRepository, GovbodyRepository_Stub>();
            //services.AddSingleton<IMeetingRepository, MeetingRepository_Stub>();
            //services.AddSingleton<IGovbodyRepository, GovbodyRepository_Stub>();
            //services.AddSingleton<IGovLocationRepository, GovLocationRepository_Stub>();
            //services.AddSingleton<IGovLocationRepository, GovLocationRepository_Stub>();
            services.AddSingleton <IRetrieveNewFiles, RetrieveNewFiles>();

            // TODO make singletons
            services.AddTransient <WF1_Retrieve>();
            services.AddTransient <WF2_Process>();
            services.AddTransient <WF3_Transcribe>();
            services.AddTransient <WF4_Tag>();
            services.AddTransient <WF5_Edit>();
            services.AddTransient <WF6_View>();
            services.AddTransient <WF7_Load>();
            services.AddTransient <WF8_Alert>();

            // add app
            services.AddTransient <WorkflowController>();
        }
Пример #24
0
        private static void ConfigureServices(IServiceCollection services)
        {
            var environmentName = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");

            // add configured instance of logging
            services.AddSingleton(new LoggerFactory()
                                  .AddConsole()
                                  .AddDebug());

            // add logging
            services.AddLogging();

            // build configuration

            // appsettings.json is copied to the output folder during the build.
            // Otherwise, we would need to set appsettingsdir as follows:
            // string appsettingsdir = Directory.GetCurrentDirectory() + @"\..\..\..";

            // Location of appsettings.json
            string appsettingsdir = Directory.GetCurrentDirectory();

            string devSettingFile = $"appsettings.{environmentName}.json";
            // Find path to the _SECRETS folder
            string secrets = GMFileAccess.FindParentFolderWithName("_SECRETS");

            // If it exists look there for environment settings file.
            if (secrets != null)
            {
                devSettingFile = Path.Combine(secrets, $"appsettings.{environmentName}.json");
            }

            var configuration = new ConfigurationBuilder()
                                // TODO - The following path will only work in development.
                                // It isn't yet decided how WorkflowApp will run in production.
                                // Will it be a separate .EXE or a .LIB loaded by WebApp?
                                .SetBasePath(appsettingsdir)
                                .AddJsonFile("appsettings.json", false)
                                .AddJsonFile(devSettingFile, optional: true)
                                .Build();

            services.AddOptions();
            services.Configure <AppSettings>(configuration.GetSection("AppSettings"));
            services.Configure <AppSettings>(myOptions =>
            {
                // Modify paths to be full paths.
                myOptions.DatafilesPath = GMFileAccess.GetFullPath(myOptions.DatafilesPath);
                myOptions.TestfilesPath = GMFileAccess.GetFullPath(myOptions.TestfilesPath);
                myOptions.GoogleApplicationCredentials = GMFileAccess.GetFullPath(myOptions.GoogleApplicationCredentials);
            });

            // add services
            //services.AddTransient<IOptions<AppSettings>>();
            services.AddTransient <ApplicationDbContext>();
            services.AddTransient <dBOperations>();
            services.AddTransient <RecordingProcess>();
            services.AddTransient <TranscribeAudio>();
            services.AddTransient <TranscriptProcess>();
            //services.AddTransient<ILoadTranscript, LoadTranscript_Stub>();
            services.AddTransient <AddtagsRepository>();
            services.AddTransient <FixasrRepository>();
            services.AddTransient <IMeetingRepository, MeetingRepository_Stub>();
            services.AddTransient <IGovBodyRepository, GovBodyRepository_Stub>();
            services.AddTransient <WF_RetrieveOnlineFiles>();
            services.AddTransient <WF_ProcessReceivedFiles>();
            services.AddTransient <WF_ProcessRecordings>();
            services.AddTransient <WF_ProcessTranscripts>();
            services.AddTransient <WF_ProcessTagged>();
            services.AddTransient <WF_ProcessProofread>();
            services.AddTransient <WF_LoadDatabase>();

            // add app
            services.AddTransient <WorkflowController>();
        }
Пример #25
0
        public static string CopyTestData(string testfilesPath, string datafilesPath, bool deleteProcessing)
        {
            if (!Directory.Exists(datafilesPath))
            {
                Directory.CreateDirectory(datafilesPath);
                Directory.CreateDirectory(datafilesPath + "/RECEIVED");
                Directory.CreateDirectory(datafilesPath + "/PROCESSING");
                Directory.CreateDirectory(datafilesPath + "/COMPLETED");
            }
            else
            {
                if (deleteProcessing)
                {
                    GMFileAccess.DeleteDirectoryContents(Path.Combine(datafilesPath, "PROCESSING"));
                }
            }

            if (!Directory.Exists(testfilesPath))
            {
                Directory.CreateDirectory(testfilesPath);
                return("TESTDATA folder missing");
            }

            // These are the test files that we will copy.
            string[] files = new string[]
            {
                // This meeting exists in MeetingRepository_Stub.cs
                //  as meeting #4 and status = "Received"
                "USA_PA_Philadelphia_Philadelphia_CityCouncil_en_2017-12-07.pdf",

                // This meeting exists in MeetingRepository_Stub.cs
                //  as meeting #5 and status = "Received"
                "USA_ME_LincolnCounty_BoothbayHarbor_Selectmen_en_2017-01-09.mp4",

                // This meeting is not present in MeetingRepository_Stub.cs.
                // ProcessIncomingFiles in WorkflowApp should recognize that fact,
                // and create a new meeting record for this file.
                "USA_ME_LincolnCounty_BoothbayHarbor_Selectmen_en_2017-02-15.mp4"
            };

            if (files.Length == 0)
            {
                return("TESTDATA folder empty");
            }

            foreach (string file in files)
            {
                string source = Path.Combine(testfilesPath, file);

                if (File.Exists(source))
                {
                    string destination = Path.Combine(datafilesPath, "RECEIVED", file);
                    if (!File.Exists(destination))
                    {
                        // For testing, use only the first 9 minutes of the video recordings.
                        if (file.EndsWith(".mp4"))
                        {
                            //SplitRecording splitRecording = new SplitRecording();
                            AudioProcessing audioProcessing = new AudioProcessing();
                            audioProcessing.ExtractPart(source, destination, 0, 540);  // 9 * 60 sec.
                        }
                        else
                        {
                            File.Copy(source, destination);
                        }
                    }
                }
            }
            return(null);
        }