Beispiel #1
0
        public static void ExecuteJobThroughSteps(ProgramOptions programOptions)
        {
            // Read job file from the location

            logger.Info("Starting job from status {0}({0:d})", programOptions.ReportJob.Status);
            loggerConsole.Info("Starting job from status {0}({0:d})", programOptions.ReportJob.Status);

            // Run the step and move to next until things are done
            while (programOptions.ReportJob.Status != JobStatus.Done && programOptions.ReportJob.Status != JobStatus.Error)
            {
                logger.Info("Executing job step {0}({0:d})", programOptions.ReportJob.Status);
                loggerConsole.Info("Executing job step {0}({0:d})", programOptions.ReportJob.Status);

                JobStepBase jobStep = getJobStepFromFactory(programOptions.ReportJob.Status);
                if (jobStep != null)
                {
                    if (jobStep.ShouldExecute(programOptions) == true)
                    {
                        if (jobStep.Execute(programOptions) == false)
                        {
                            programOptions.ReportJob.Status = JobStatus.Error;
                        }
                    }
                }
                if (programOptions.ReportJob.Status != JobStatus.Error)
                {
                    programOptions.ReportJob.Status = jobStepsLinked.Find(programOptions.ReportJob.Status).Next.Value;
                }

                // Save progress of the report in case we want to resume or rerun later
                FileIOHelper.WriteReportJobToFile(programOptions.ReportJob, programOptions.ReportJobFilePath);
            }

            return;
        }
Beispiel #2
0
        private void AddProfile(Profile profileData = null)
        {
            var isNew = profileData == null;

            var newName = GetFileName("Profile Name", Paths.ProfilePath, new[] { Vendor.ProfileExtension }, "", "Create");

            if (string.Empty == newName)
            {
                return;
            }

            var root = (null != _contextProfile && _contextProfile.FileName != null)
                ? Path.GetDirectoryName(_contextProfile.FileName) ?? Paths.ProfilePath : Paths.ProfilePath;

            var newFileName = Path.Combine(root, newName + Vendor.ProfileExtension);

            DeleteIfExists(newFileName);

            var profile = isNew ? new Profile() : profileData;

            profile.FileName      = newFileName;
            profile.Name          = newName;
            profile.FileIOHandler = FileIOHelper.GetNativeHelper();
            SaveProfile(profile);

            RefreshProfileComboBox(newName);
        }
Beispiel #3
0
        public static async Task SaveLibraryIndex(List <int> l)
        {
            var j    = Newtonsoft.Json.JsonConvert.SerializeObject(l);
            var file = await FileIOHelper.GetFileFromLocalAsync("LibraryIndex");

            await FileIO.WriteTextAsync(file, j);
        }
    /// <summary>
    /// Attempts to upload a single file a Tableau Server, and then make it a published workbook
    /// </summary>
    /// <param name="localFilePath"></param>
    /// <returns></returns>
    private bool AttemptUploadSingleFile_Inner(
        string localFilePath,
        string projectId,
        CredentialManager.Credential dbCredentials,
        WorkbookPublishSettings publishSettings)
    {
        string uploadSessionId;

        try
        {
            var fileUploader = new UploadFile(_onlineUrls, _onlineSession, localFilePath, _uploadChunkSizeBytes, _uploadChunkDelaySeconds);
            uploadSessionId = fileUploader.ExecuteRequest();
        }
        catch (Exception exFileUpload)
        {
            this.StatusLog.AddError("Unexpected error attempting to upload file " + localFilePath + ", " + exFileUpload.Message);
            throw exFileUpload;
        }

        SiteWorkbook workbook;

        this.StatusLog.AddStatus("File chunks upload successful. Next step, make it a published workbook", -10);
        try
        {
            string fileName   = Path.GetFileNameWithoutExtension(localFilePath);
            string uploadType = RemoveFileExtensionDot(Path.GetExtension(localFilePath).ToLower());
            workbook = FinalizePublish(
                uploadSessionId,
                FileIOHelper.Undo_GenerateWindowsSafeFilename(fileName), //[2016-05-06] If the name has escapted characters, unescape them
                uploadType,
                projectId,
                dbCredentials,
                publishSettings);
            StatusLog.AddStatus("Upload content details: " + workbook.ToString(), -10);
            StatusLog.AddStatus("Success! Uploaded workbook " + Path.GetFileName(localFilePath));
        }
        catch (Exception exPublishFinalize)
        {
            this.StatusLog.AddError("Unexpected error finalizing publish of file " + localFilePath + ", " + exPublishFinalize.Message);
            LogManualAction_UploadWorkbook(localFilePath);
            throw exPublishFinalize;
        }

        //See if we want to reassign ownership of the workbook
        if (_attemptOwnershipAssignment)
        {
            try
            {
                AttemptOwnerReassignment(workbook, publishSettings, _siteUsers);
            }
            catch (Exception exOwnershipAssignment)
            {
                this.StatusLog.AddError("Unexpected error reassigning ownership of published workbook " + workbook.Name + ", " + exOwnershipAssignment.Message);
                LogManualAction_ReassignOwnership(workbook.Name);
                throw exOwnershipAssignment;
            }
        }

        return(true);     //Success
    }
    public static T Read(string path)
    {
        string text = FileIOHelper.ReadFile(path);


        return(JsonUtility.FromJson <T>(text));
    }
Beispiel #6
0
        public void ReadFromFileTest()
        {
            var filepath = @"D:\\Weather Info\\Source\CityList.txt";
            IEnumerable <City> cities = FileIOHelper.ReadFromFile(filepath);

            Assert.AreEqual(10, cities.Count());
        }
Beispiel #7
0
        public static async void JsonUnitTest()
        {
            Dictionary <int, Notification> notificationStore = new Dictionary <int, Notification>();
            var dataSource = new DataSource();

            for (int i = 0; i < 5; i++)
            {
                var notification = new Notification()
                {
                    Id           = i,
                    HtmlUrl      = new Uri("http://details.HtmlUrl"),
                    UserId       = i * 10,
                    SubjectTitle = String.Format("note.Subject.Title {0}", i.ToString()),
                    Body         = String.Format("details.Body {0}", i.ToString()),
                    TimeStamp    = DateTimeHelper.DateTimeToUtcString(DateTime.UtcNow)
                };
                notificationStore.Add(i, notification);
            }

            var text = JsonHelper.StorageToJsonString("Notifications", notificationStore);
            await FileIOHelper.WriteUtf8ToLocalFileAsync("GitMeTests", "Notifications", text);

            var text2 = await FileIOHelper.ReadLocalFileAsync("GitMeTests", "Notifications");

            await FileIOHelper.WriteUtf8ToSDAsync("GitMeTests", "JsonUnitTesttext.json", text);

            await FileIOHelper.WriteUtf8ToSDAsync("GitMeTests", "JsonUnitTesttext2.json", text2);

            Dictionary <int, Notification> notes  = JsonHelper.DeserializeToStorage("Notifications", text);
            Dictionary <int, Notification> notes2 = JsonHelper.DeserializeToStorage("Notifications", text2);

            bool b = String.Equals(notes[0].Body, notes2[0].Body);

            return;
        }
        public async Task <IActionResult> Index(IFormFile file)
        {
            if (file == null || file.Length == 0)
            {
                return(Content("file not selected"));
            }

            var destPath = _configuration["DestinationDir"];

            using (var stream = new FileStream(file.FileName, FileMode.Create))
            {
                await file.CopyToAsync(stream);
            }

            IEnumerable <City> cities = FileIOHelper.ReadFromFile(file.FileName);

            Parallel.ForEach(cities, (currentCity) =>
            {
                IWeatherFetcher wf = new WeatherFetcher(_configuration["WeatherAPIUrl"], _configuration["WeatherAPIKey"]);
                var currentWeather = wf.GetCurrentWeather(currentCity.CityId);
                var dirInfo        = FileIOHelper.CreateDestinationFolder(destPath);
                FileIOHelper.WriteToJsonFile <CurrentWeather>($"{dirInfo.FullName}\\{currentCity.Cityname}_{currentCity.CityId} .txt", currentWeather, append: false);
            });

            ViewBag.Message = string.Format("Report generated at specified destination path.\\nCurrent Date and Time: {0}", DateTime.Now.ToString());
            return(View());
        }
Beispiel #9
0
        public async Task SaveDataAsync(string currentId, string resstr, DataSource source)
        {
            try
            {
                switch (source)
                {
                case DataSource.HeWeather:
                    await FileIOHelper.SaveStringtoStorageAsync(currentId + "_H", resstr);

                    break;

                case DataSource.Caiyun:
                    await FileIOHelper.SaveStringtoStorageAsync(currentId + "_C", resstr);

                    break;

                case DataSource.Wunderground:
                    await FileIOHelper.SaveStringtoStorageAsync(currentId + "_W", resstr);

                    break;

                default:
                    break;
                }
            }
            catch (Exception)
            {
            }
        }
Beispiel #10
0
        private string GetDBfileInfo()
        {
            try
            {
                LogHelper.WriteMethodLog(true);
                string tempzip = Path.Combine(AppSettings.XXPTempFolder, ConstHelper.BC_DBZipName);
                if (File.Exists(tempzip))
                {
                    FileIOHelper.DeleteFile(tempzip);
                }
                ZipHelper.Zip(AppSettings.XXPDBFolder, tempzip);
                FileInfo tempzipInfo = new FileInfo(tempzip);

                LeveldbOperator.OpenDB(AppSettings.XXPDBFolder);
                string strLastblock = LeveldbOperator.GetValue(ConstHelper.BC_LastKey);
                Block  block        = JsonHelper.Deserialize <Block>(strLastblock);
                LeveldbOperator.CloseDB();

                DBFileInfo dbinfo = new DBFileInfo(tempzipInfo.Length, block.Header.Height);
                return(JsonHelper.Serializer <DBFileInfo>(dbinfo));;
            }
            catch (Exception ex)
            {
                LogHelper.WriteErrorLog(ex.Message);
                return(string.Empty);
            }
            finally
            {
                LogHelper.WriteMethodLog(false);
            }
        }
Beispiel #11
0
 internal void ImmersiveIn(Uri uri)
 {
     continueUpdate();
     if (uri == null)
     {
         backBlur.ImmersiveOut(false);
         return;
     }
     if (Canvas != null)
     {
         var task = Canvas.RunOnGameLoopThreadAsync(async() =>
         {
             using (var stream = await FileIOHelper.ReadRandomAccessStreamByUriAsync(uri))
             {
                 if (Canvas != null)
                 {
                     await backBlur.LoadSurfaceAsync(Canvas, stream);
                 }
             }
             backBlur.ImmersiveIn();
         });
     }
     if (!EnableBGBlur)
     {
         stopUpdate();
     }
     if (EnableDynamic && ((condition == WeatherCondition.cloudy) || (condition == WeatherCondition.few_clouds) || (condition == WeatherCondition.partly_cloudy) || (condition == WeatherCondition.overcast)))
     {
         smoke.ImmersiveIn();
     }
 }
Beispiel #12
0
        private void btnProvisionFromAzureAd_Click(object sender, EventArgs e)
        {
            var statusLogs = new TaskStatusLogs();

            statusLogs.AddStatus("Starting...");
            UpdateStatusText(statusLogs, true);

            string pathSecrets = txtPathToSecrets.Text;

            if (!File.Exists(pathSecrets))
            {
                MessageBox.Show("Secrets file does not exist at specified path (" + pathSecrets + ")");
                return;
            }


            string pathProvisionPlan = txtPathToAzureAdProvisioningConfig.Text;

            if (!File.Exists(pathProvisionPlan))
            {
                MessageBox.Show("Config file does not exist at specified path (" + pathProvisionPlan + ")");
                return;
            }

            string pathOutput =
                Path.Combine(
                    Path.GetDirectoryName(pathProvisionPlan),
                    "out");

            FileIOHelper.CreatePathIfNeeded(pathOutput);

            //Show the user a command line that they can use to run this same work
            GenerateProvisioningCommandLine(
                CommandLineParser.Command_ProvisionFromAzure,
                pathSecrets,
                pathProvisionPlan,
                pathOutput);

            //Run the work
            try
            {
                ProvisionFromAzureAd(
                    statusLogs,
                    pathSecrets,
                    txtPathToAzureAdProvisioningConfig.Text,
                    pathOutput);
            }
            catch (Exception exError)
            {
                MessageBox.Show("Error: " + exError.Message);
            }

            UpdateStatusText(statusLogs, true);

            //Open the file explorer to the output directory
            if (Directory.Exists(pathOutput))
            {
                System.Diagnostics.Process.Start(pathOutput);
            }
        }
        private int extractAuditLogEvents(JobConfiguration jobConfiguration, JobTarget jobTarget, ControllerApi controllerApi)
        {
            JArray listOfAuditEvents = new JArray();

            foreach (JobTimeRange jobTimeRange in jobConfiguration.Input.HourlyTimeRanges)
            {
                string auditEventsJSON = controllerApi.GetAuditEvents(jobTimeRange.From, jobTimeRange.To);
                if (auditEventsJSON != String.Empty)
                {
                    JArray listOfAuditEventsInTimeRange = JArray.Parse(auditEventsJSON);
                    if (listOfAuditEventsInTimeRange != null)
                    {
                        // Load audit log events
                        foreach (JObject auditEvent in listOfAuditEventsInTimeRange)
                        {
                            listOfAuditEvents.Add(auditEvent);
                        }
                    }
                }
            }

            if (listOfAuditEvents.Count > 0)
            {
                FileIOHelper.WriteJArrayToFile(listOfAuditEvents, FilePathMap.AuditEventsDataFilePath(jobTarget));

                logger.Info("{0} audit events from {1:o} to {2:o}", listOfAuditEvents.Count, jobConfiguration.Input.TimeRange.From, jobConfiguration.Input.TimeRange.To);
                loggerConsole.Info("{0} audit events", listOfAuditEvents.Count);
            }

            return(listOfAuditEvents.Count);
        }
Beispiel #14
0
        public RoadNetwork()
        {
            string modelFilePath = ConfigurationSettings.AppSettings["ModelFile"];
            Model  model         = (Model)FileIOHelper.loadObject(modelFilePath);

            NetworkModel = model;
        }
Beispiel #15
0
        private async void AccountDataDeleteInvokedHandler(IUICommand command)
        {
            // Display message showing the label of the command that was invoked
            switch ((int)command.Id)
            {
            case 0:
                try
                {
                    await FileIOHelper.WriteUtf8ToLocalFileAsync("Data", "Notifications.json", "");

                    await FileIOHelper.WriteUtf8ToLocalFileAsync("Data", "Repositories.json", "");

                    await FileIOHelper.WriteUtf8ToLocalFileAsync("Data", "Users.json", "");

                    DataState.LastDataFetchSuccess = false;
                    DataState.LastDataFetchAt      = DateTime.UtcNow;
                    NotifyUser(Constants.AccountDataDeleteSuccess, NotifyType.StatusMessage);
                    return;
                }
                catch
                {
                    // ignore
                }
                break;

            default:
                break;
            }
            NotifyUser(Constants.AccountDataDeleteSuccess2, NotifyType.StatusMessage);
        }
Beispiel #16
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="serverName"></param>
        public List <SiteDatasource> ExecuteRequest()
        {
            var downloadedContent = new List <SiteDatasource>();

            //Depending on the HTTP download file type we want different file extensions
            var typeMapper = new DownloadPayloadTypeHelper("tdsx", "tds");

            var datasources = Datasources;

            if (datasources == null)
            {
                Login.Logger.Error("NULL datasources. Aborting download.");
                return(null);
            }

            //For each datasource, download it and save it to the local file system
            foreach (var dsInfo in datasources)
            {
                //Local path save the workbook
                string urlDownload = Urls.Url_DatasourceDownload(Login, dsInfo);
                Login.Logger.Information("Starting Datasource download " + dsInfo.Name);
                try
                {
                    //Generate the directory name we want to download into
                    var pathToSaveTo = FileIOHelper.EnsureProjectBasedPath(
                        LocalSavePath,
                        DownloadToProjectDirectories,
                        dsInfo,
                        Login.Logger);

                    var fileDownloaded       = this.DownloadFile(urlDownload, pathToSaveTo, dsInfo.Name, typeMapper);
                    var fileDownloadedNoPath = System.IO.Path.GetFileName(fileDownloaded);
                    Login.Logger.Information("Finished Datasource download " + fileDownloadedNoPath);

                    //Add to the list of our downloaded data sources
                    if (!string.IsNullOrEmpty(fileDownloaded))
                    {
                        downloadedContent.Add(dsInfo);

                        //Generate the metadata file that has additional server provided information about the workbook
                        if (GenerateInfoFile)
                        {
                            Helpers.DatasourcePublishSettings.CreateSettingsFile(dsInfo, fileDownloaded, SiteUserLookup);
                        }
                    }
                    else
                    {
                        //We should never hit this code; just being defensive
                        Login.Logger.Error("Download error, no local file path for downloaded content");
                    }
                }
                catch (Exception ex)
                {
                    Login.Logger.Error("Error during Datasource download " + dsInfo.Name + "\r\n  " + urlDownload + "\r\n  " + ex.ToString());
                }
            }

            //Return the set of successfully downloaded content
            return(downloadedContent);
        }
Beispiel #17
0
        private int extractHealthRuleViolations(JobConfiguration jobConfiguration, JobTarget jobTarget, ControllerApi controllerApi)
        {
            JArray listOfHealthRuleViolations = new JArray();

            foreach (JobTimeRange jobTimeRange in jobConfiguration.Input.HourlyTimeRanges)
            {
                long fromTimeUnix = UnixTimeHelper.ConvertToUnixTimestamp(jobTimeRange.From);
                long toTimeUnix   = UnixTimeHelper.ConvertToUnixTimestamp(jobTimeRange.To);

                string healthRuleViolationsJSON = controllerApi.GetHealthRuleViolations(jobTarget.ApplicationID, fromTimeUnix, toTimeUnix);
                if (healthRuleViolationsJSON != String.Empty)
                {
                    // Load health rule violations
                    JArray healthRuleViolationsInHour = JArray.Parse(healthRuleViolationsJSON);
                    foreach (JObject healthRuleViolation in healthRuleViolationsInHour)
                    {
                        listOfHealthRuleViolations.Add(healthRuleViolation);
                    }
                }
            }

            if (listOfHealthRuleViolations.Count > 0)
            {
                FileIOHelper.WriteJArrayToFile(listOfHealthRuleViolations, FilePathMap.HealthRuleViolationsDataFilePath(jobTarget));

                logger.Info("{0} health rule violations from {1:o} to {2:o}", listOfHealthRuleViolations.Count, jobConfiguration.Input.TimeRange.From, jobConfiguration.Input.TimeRange.To);
                loggerConsole.Info("{0} health rule violations", listOfHealthRuleViolations.Count);
            }

            return(listOfHealthRuleViolations.Count);
        }
    public static void Write(string path, T data)
    {
        string file_path = path;
        string json      = JsonUtility.ToJson(data, true);

        FileIOHelper.WriteFile(file_path, json);
    }
Beispiel #19
0
        private int extractEvents(JobConfiguration jobConfiguration, JobTarget jobTarget, ControllerApi controllerApi, string eventType)
        {
            JArray listOfEvents = new JArray();

            foreach (JobTimeRange jobTimeRange in jobConfiguration.Input.HourlyTimeRanges)
            {
                long fromTimeUnix = UnixTimeHelper.ConvertToUnixTimestamp(jobTimeRange.From);
                long toTimeUnix   = UnixTimeHelper.ConvertToUnixTimestamp(jobTimeRange.To);

                string eventsJSON = controllerApi.GetEvents(jobTarget.ApplicationID, eventType, fromTimeUnix, toTimeUnix);
                if (eventsJSON != String.Empty)
                {
                    // Load events
                    JArray eventsInHour = JArray.Parse(eventsJSON);
                    foreach (JObject interestingEvent in eventsInHour)
                    {
                        listOfEvents.Add(interestingEvent);
                    }
                }
            }

            if (listOfEvents.Count > 0)
            {
                FileIOHelper.WriteJArrayToFile(listOfEvents, this.FilePathMap.EventsDataFilePath(jobTarget, eventType));

                logger.Info("{0} {1} events from {2:o} to {3:o}", eventType, listOfEvents.Count, jobConfiguration.Input.TimeRange.From, jobConfiguration.Input.TimeRange.To);
                loggerConsole.Info("{0} {1} events", eventType, listOfEvents.Count);
            }

            return(listOfEvents.Count);
        }
Beispiel #20
0
        public void ReadFromFileCheckIfFiledoesnotExistTest()
        {
            var filepath = @"D:\\Weather Info\\Destination";
            var cities   = FileIOHelper.ReadFromFile(filepath);

            Assert.IsNull(cities);
        }
Beispiel #21
0
        /// <summary>
        /// Provision the site based on the provisioning manifest in a file
        /// </summary>
        /// <param name="statusLogs">Store status logs here</param>
        /// <param name="pathSecrets">Where the log in secrets are</param>
        /// <param name="pathProvisioningManifest">Where the provisioning steps are</param>
        /// <param name="outputPath">Where output files go</param>
        private void ProvisionFromFileManifest(TaskStatusLogs statusLogs, string pathSecrets, string pathProvisioningManifest, string outputPath)
        {
            //Load the config from the files
            var secretsConfig = new ProvisionConfigSiteAccess(pathSecrets);

            //Load the user provisioning instructions
            var provisionUsersInfo = new ProvisionUserInstructions(
                pathProvisioningManifest);

            var provisionSite = new ProvisionSite(secretsConfig, provisionUsersInfo, this, statusLogs);

            provisionSite.Execute();

            //---------------------------------------------------------------------
            //Generate an output file
            //---------------------------------------------------------------------
            FileIOHelper.CreatePathIfNeeded(outputPath);

            var outputFilePath = Path.Combine(outputPath, "ProvisionSiteOutput.csv");

            provisionSite.CSVResultsReport.GenerateCSVFile(outputFilePath);

            statusLogs.AddStatusHeader("Done!");
            ((IShowLogs)this).NewLogResultsToShow(statusLogs);
        }
Beispiel #22
0
        public void WriteToJsonFileTest()
        {
            string path          = "D:\\Weather Info\\Source";
            var    directoryInfo = FileIOHelper.CreateDestinationFolder(path);
            var    now           = DateTime.Now;
            var    yearName      = now.ToString("yyyy");
            var    monthName     = now.ToString("MMMM");
            var    dayName       = now.ToString("dd-MM-yyyy");
            string filepath      = $"{path}\\{yearName}\\{monthName}\\{dayName}";


            City city = new City()
            {
                Cityname = "London", CityId = "2643741"
            };

            IWeatherFetcher wf                  = new WeatherFetcher("http://api.openweathermap.org", "aa69195559bd4f88d79f9aadeb77a8f6");
            var             currentWeather      = wf.GetCurrentWeather(city.CityId);
            var             destinationFilepath = $"{filepath}\\{city.Cityname}_{city.CityId}.txt";

            FileIOHelper.WriteToJsonFile <CurrentWeather>(destinationFilepath, currentWeather, append: false);

            var DoesFileExist = File.Exists(destinationFilepath);

            Assert.IsTrue(DoesFileExist);
        }
        private void readGranularRangeOfMetricsIntoEntities(
            Dictionary <string, DBEntityBase> entitiesDictionaryByName,
            JobTimeRange jobTimeRange,
            JobTarget jobTarget,
            List <MetricExtractMapping> entityMetricExtractMappingList,
            string entityFolderName,
            string entityType,
            Dictionary <string, List <MetricValue> > metricValuesDictionary)
        {
            List <MetricExtractMapping> entityMetricExtractMappingListFiltered = entityMetricExtractMappingList.Where(m => m.EntityType == entityType).ToList();

            foreach (MetricExtractMapping metricExtractMapping in entityMetricExtractMappingListFiltered)
            {
                List <AppDRESTMetric> metricData = FileIOHelper.LoadListOfObjectsFromFile <AppDRESTMetric>(FilePathMap.MetricHourRangeDataFilePath(jobTarget, entityFolderName, metricExtractMapping.FolderName, jobTimeRange));
                if (metricData != null)
                {
                    List <MetricValue> metricValues = readMetricsIntoEntities(metricData, entitiesDictionaryByName, jobTarget, jobTimeRange);
                    if (metricValues != null)
                    {
                        if (metricValuesDictionary.ContainsKey(metricExtractMapping.FolderName) == false)
                        {
                            metricValuesDictionary.Add(metricExtractMapping.FolderName, metricValues);
                        }
                        else
                        {
                            metricValuesDictionary[metricExtractMapping.FolderName].AddRange(metricValues);
                        }
                    }
                }
            }
        }
Beispiel #24
0
    /// <summary>
    /// Downloads a file
    /// </summary>
    /// <param name="urlDownload"></param>
    /// <param name="downloadToDirectory"></param>
    /// <param name="baseFileName">Filename without extension</param>
    /// <returns>The path to the downloaded file</returns>
    private string DownloadFile_inner(string urlDownload, string downloadToDirectory, string baseFilename, DownloadPayloadTypeHelper downloadTypeMapper)
    {
        //[2016-05-06] Interestingly 'GetFileNameWithoutExtension' does more than remove a ".xxxx" extension; it will also remove a preceding
        //            path (e.g. GetFileNameWithoutExtension('foo/bar.xxx') -> "bar'.  This is undesirable because these characters are valid
        //            in Tableau Server content names. Since this function is supposed to be called with a 'baseFilename' that DOES NOT have a .xxx
        //            extension, it is safe to remove this call
        //baseFilename =  FileIOHelper.GenerateWindowsSafeFilename(System.IO.Path.GetFileNameWithoutExtension(baseFilename));

        //Strip off an extension if its there
        baseFilename = FileIOHelper.GenerateWindowsSafeFilename(baseFilename);


        var webClient = this.CreateLoggedInWebClient();

        using (webClient)
        {
            //Choose a temp file name to download to
            var starterName = System.IO.Path.Combine(downloadToDirectory, baseFilename + ".tmp");
            _onlineSession.StatusLog.AddStatus("Attempting file download: " + urlDownload, -10);
            webClient.DownloadFile(urlDownload, starterName); //Download the file

            //Look up the correct file extension based on the content type downloaded
            var contentType   = webClient.ResponseHeaders["Content-Type"];
            var fileExtension = downloadTypeMapper.GetFileExtension(contentType);
            var finishName    = System.IO.Path.Combine(downloadToDirectory, baseFilename + fileExtension);

            //Rename the downloaded file
            System.IO.File.Move(starterName, finishName);
            return(finishName);
        }
    }
Beispiel #25
0
        private void InitializeProfiles(bool reload = false)
        {
            var errors = new StringBuilder();

            cbProfiles.Items.Clear();
            cbProfiles.Items.Add("Select or add a profile");
            foreach (var profileFile in
                     Directory.GetFiles(Paths.ProfilePath, Vendor.All + Vendor.ProfileExtension).Where(
                         profileFile => Path.GetExtension(profileFile) == Vendor.ProfileExtension))
            {
                try {
                    var nativeIO = FileIOHelper.GetNativeHelper();
                    cbProfiles.Items.Add(nativeIO.OpenProfile(profileFile));
                }
                catch (XmlException e) {
                    errors.AppendLine(string.Format("{0}\nFailed to load because: {1}\n", profileFile, e.Message));
                }
            }

            if (errors.Length <= 0 || _suppressErrors || reload)
            {
                return;
            }

            errors.AppendLine(
                "You will continue to see this message until the offending files are fixed, moved or deleted. You can also supress this message in preferences by selecting 'Silence profile editor errors'");
            MessageBox.Show(errors.ToString(), "Errors loading some profiles");
        }
        internal List <MetricExtractMapping> getMetricsExtractMappingList(JobConfiguration jobConfiguration)
        {
            List <MetricExtractMapping> entityMetricExtractMappingList = FileIOHelper.ReadListFromCSVFile <MetricExtractMapping>(FilePathMap.EntityMetricExtractMappingFilePath(), new MetricExtractMappingReportMap());

            List <MetricExtractMapping> entityMetricExtractMappingListFiltered = new List <MetricExtractMapping>(entityMetricExtractMappingList.Count);

            foreach (string metricSet in jobConfiguration.Input.MetricsSelectionCriteria)
            {
                List <MetricExtractMapping> entityMetricExtractMappingListForMetricSet = entityMetricExtractMappingList.Where(m => m.MetricSet == metricSet).ToList();
                if (entityMetricExtractMappingListForMetricSet != null)
                {
                    logger.Info("Input job specified {0} metric set, resulted in {1} metrics from mapping file", metricSet, entityMetricExtractMappingListForMetricSet.Count);
                    loggerConsole.Info("Input job specified {0} metric set, resulted in {1} metrics from mapping file", metricSet, entityMetricExtractMappingListForMetricSet.Count);
                    entityMetricExtractMappingListFiltered.AddRange(entityMetricExtractMappingListForMetricSet);
                    foreach (MetricExtractMapping mem in entityMetricExtractMappingListForMetricSet)
                    {
                        logger.Trace("{0}, path={1}", mem, mem.MetricPath);
                    }
                }
            }
            logger.Info("Selected {0} metrics from mapping file", entityMetricExtractMappingListFiltered.Count);
            loggerConsole.Info("Selected {0} metrics from mapping file", entityMetricExtractMappingListFiltered.Count);

            return(entityMetricExtractMappingListFiltered);
        }
Beispiel #27
0
        public void StringStreamText()
        {
            string origin = "mother f****r what you are!\r\t";
            string actual = FileIOHelper.StreamToString(FileIOHelper.StringToStream(origin));

            Assert.AreEqual(origin, actual);
        }
Beispiel #28
0
        public static async Task WriteToStorageFile(string storageType)
        {
            string fileName = String.Format("{0}.json", storageType);
            string result;

            switch (storageType)
            {
            case "Notifications":
                result = JsonHelper.StorageToJsonString(storageType, notificationStore);
                break;

            case "Repositories":
                result = JsonHelper.StorageToJsonString(storageType, repositoryStore);
                break;

            case "Users":
                result = JsonHelper.StorageToJsonString(storageType, userStore);
                break;

            default:
                throw new ArgumentException();
            }

            await FileIOHelper.WriteUtf8ToLocalFileAsync("Data", fileName, result);

#if DEBUG
            await FileIOHelper.WriteUtf8ToSDAsync("GitMe", fileName, result);
#endif
        }
Beispiel #29
0
        private static async Task GetStorageFileAsync(string fileType)
        {
            dynamic jsonStore = await FileIOHelper.GetStorageFromLocalFileAsync("Data", fileType);

            if (jsonStore == null || jsonStore.Count == 0)
            {
                return;
            }

            foreach (var key in jsonStore.Keys)
            {
                switch (fileType)
                {
                case "Notifications":
                    notificationStore.UpdateOrInsert(key, jsonStore[key]);
                    break;

                case "Repositories":
                    repositoryStore.UpdateOrInsert(key, jsonStore[key]);
                    break;

                case "Users":
                    userStore.UpdateOrInsert(key, jsonStore[key]);
                    break;

                default:
                    throw new ArgumentException();
                }
            }
        }
Beispiel #30
0
        /// <summary>
        /// Attempts to upload a single file a Tableau Server, and then make it a published data source
        /// </summary>
        /// <param name="localFilePath"></param>
        /// <param name="projectId"></param>
        /// <param name="dbCredentials">If not NULL, then these are the DB credentials we want to associate with the content we are uploading</param>
        /// <returns></returns>
        private bool AttemptUploadSingleFile(
            string localFilePath,
            string projectId,
            CredentialManager.Credential dbCredentials,
            DatasourcePublishSettings publishSettings)
        {
            string uploadSessionId;

            try
            {
                var fileUploader = new UploadFile(Urls, Login, localFilePath, HttpClientFactory, UploadChunkSizeBytes, UploadChunkDelaySeconds);
                uploadSessionId = fileUploader.ExecuteRequest();
            }
            catch (Exception exFileUpload)
            {
                Login.Logger.Error("Unexpected error attempting to upload file " + localFilePath + ", " + exFileUpload.Message);
                throw exFileUpload;
            }

            SiteDatasource dataSource = null;

            Login.Logger.Information("File chunks upload successful. Next step, make it a published datasource");
            try
            {
                string fileName   = Path.GetFileNameWithoutExtension(localFilePath);
                string uploadType = RemoveFileExtensionDot(Path.GetExtension(localFilePath).ToLower());
                dataSource = FinalizePublish(
                    uploadSessionId,
                    FileIOHelper.Undo_GenerateWindowsSafeFilename(fileName), //[2016-05-06] If the name has escapted characters, unescape them
                    uploadType,
                    projectId,
                    dbCredentials);
                UploadeDatasources.Add(dataSource);
                Login.Logger.Information("Upload content details: " + dataSource.ToString());
                Login.Logger.Information("Success! Uploaded datasource " + Path.GetFileName(localFilePath));
            }
            catch (Exception exPublishFinalize)
            {
                Login.Logger.Error("Unexpected error finalizing publish of file " + localFilePath + ", " + exPublishFinalize.Message);
                throw exPublishFinalize;;
            }

            //See if we want to reassign ownership of the datasource
            if (AttemptOwnershipAssignment)
            {
                try
                {
                    AttemptOwnerReassignment(dataSource, publishSettings, SiteUsers);
                }
                catch (Exception exOwnershipAssignment)
                {
                    Login.Logger.Error("Unexpected error reassigning ownership of published datasource " + dataSource.Name + ", " + exOwnershipAssignment.Message);
                    LogManualAction_ReassignOwnership(dataSource.Name);
                    throw exOwnershipAssignment;
                }
            }

            return(true);     //Success
        }