internal static bool CreateDefaultSettingsFile(string projectId)
        {
            try
            {
                var result = S3UploadHelper.GetAssetFromS3(EnvironmentConstants.ApplicationConfiguration.AWSS3Configuration.AWS_AccessKey,
                                                           EnvironmentConstants.ApplicationConfiguration.AWSS3Configuration.AWS_SecretKey,
                                                           AmazonAWSConstants.ResourceBucketName,
                                                           string.Format(Kitsune.API2.EnvConstants.Constants.ProjectDefaultSettingsFile, projectId));

                string fileContent = String.Empty;
                if (result != null && result.IsSuccess)
                {
                    fileContent = result.File != null ? result.File.Content : String.Empty;
                }
                CreateOrUpdateProjectConfigRequestModel request = new CreateOrUpdateProjectConfigRequestModel()
                {
                    File = new ConfigFile
                    {
                        Content = fileContent
                    },
                    ProjectId = projectId
                };
                CreateOrUpdateProjectConfig(request);
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
        internal static bool CreateDefaultStaticIndexResource(string projectId)
        {
            try
            {
                if (_kitsuneServer == null)
                {
                    InitializeConnection();
                }
                var ResourceCollection = _kitsuneDatabase.GetCollection <KitsuneResource>(KitsuneResourceCollectionName);
                var dateTime           = DateTime.Now;

                #region
                foreach (var file in Kitsune.API2.EnvConstants.Constants.ProjectDefaultFiles)
                {
                    KitsuneResource resourceCollection = new KitsuneResource
                    {
                        ProjectId    = projectId,
                        SourcePath   = file,
                        CreatedOn    = dateTime,
                        UpdatedOn    = dateTime,
                        ResourceType = GetResourceType(file),
                        IsStatic     = true,
                        Version      = 1,
                        IsDefault    = file.Contains("/index.html")
                    };
                    ResourceCollection.InsertOne(resourceCollection);

                    //upload the object to S3
                    var result = S3UploadHelper.GetAssetFromS3(EnvironmentConstants.ApplicationConfiguration.AWSS3Configuration.AWS_AccessKey,
                                                               EnvironmentConstants.ApplicationConfiguration.AWSS3Configuration.AWS_SecretKey,
                                                               AmazonAWSConstants.ResourceBucketName,
                                                               $"static/defaults_new{file}");

                    string defaultHtmlData = String.Empty;
                    if (result != null && result.IsSuccess)
                    {
                        defaultHtmlData = result.File.Content;


                        Byte[] byteHtmlData   = Encoding.ASCII.GetBytes(defaultHtmlData);
                        var    saveResult     = S3UploadHelper.SaveAssetsAndReturnObjectkey(EnvironmentConstants.ApplicationConfiguration.AWSS3Configuration.AWS_AccessKey, EnvironmentConstants.ApplicationConfiguration.AWSS3Configuration.AWS_SecretKey, projectId + file, byteHtmlData, AmazonAWSConstants.SourceBucketName, result.File.ContentType);
                        var    demosaveResult = S3UploadHelper.SaveAssetsAndReturnObjectkey(EnvironmentConstants.ApplicationConfiguration.AWSS3Configuration.AWS_AccessKey, EnvironmentConstants.ApplicationConfiguration.AWSS3Configuration.AWS_SecretKey, projectId + "/cwd" + file, byteHtmlData, AmazonAWSConstants.DemoBucketName, result.File.ContentType);
                    }
                }

                #endregion


                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Esempio n. 3
0
        public Images(string fileDirectoryPath, string archiveDirectoryPath, IEnumerable <string> fileNames, string stagingTableName, string formatFilePath, string summaryReportErrorToEmailAddress,
                      string summaryReportFromEmailAddress, string summaryReportFromAddressFriendlyName, string destinationPath,
                      string sqlaServerPath, string sqlbServerPath, string localSqlPath, string temporaryUploadPath, string daysToRun)
            : base(ServiceLogger.FlatFileType.Images, FlatFiles.FileFormat.TXT, FlatFiles.CompressType.Zip,
                   fileDirectoryPath, archiveDirectoryPath, stagingTableName, formatFilePath, summaryReportErrorToEmailAddress, summaryReportFromEmailAddress, summaryReportFromAddressFriendlyName,
                   sqlaServerPath, sqlbServerPath, localSqlPath, temporaryUploadPath, daysToRun, false)
        {
            foreach (var fileName in fileNames)
            {
                _fileNames.Add(fileName);
            }

            DestinationDirectoryPath = destinationPath;

            imageUploadHelper = new S3UploadHelper(Settings.Default.AWSAccessKey, Settings.Default.AWSSecretKey, Settings.Default.AWSRegionName, Settings.Default.AWSS3ImageBucketName);
        }
        public Images(string fileDirectoryPath, string archiveDirectoryPath, IEnumerable<string> fileNames, string stagingTableName, string formatFilePath, string summaryReportErrorToEmailAddress,
            string summaryReportFromEmailAddress, string summaryReportFromAddressFriendlyName, string destinationPath,
            string sqlaServerPath, string sqlbServerPath,string localSqlPath, string temporaryUploadPath, string daysToRun)
            : base(ServiceLogger.FlatFileType.Images, FlatFiles.FileFormat.TXT, FlatFiles.CompressType.Zip,
            fileDirectoryPath, archiveDirectoryPath, stagingTableName, formatFilePath, summaryReportErrorToEmailAddress, summaryReportFromEmailAddress, summaryReportFromAddressFriendlyName,
            sqlaServerPath, sqlbServerPath, localSqlPath, temporaryUploadPath, daysToRun, false)
        {
            foreach (var fileName in fileNames)
            {
                _fileNames.Add(fileName);
            }

            DestinationDirectoryPath = destinationPath;

            imageUploadHelper = new S3UploadHelper(Settings.Default.AWSAccessKey, Settings.Default.AWSSecretKey, Settings.Default.AWSRegionName, Settings.Default.AWSS3ImageBucketName);

        }
        /// <summary>
        /// gets this file from s3
        /// </summary>
        /// <param name="sourcePath"></param>
        public static Stream GetS3File(string sourcePath)
        {
            var s3 = new S3UploadHelper(Settings.Default.AWSAccessKey,
                 Settings.Default.AWSSecretKey,
                 Settings.Default.AWSRegionName,
                 Settings.Default.AWSS3BucketName);

            var response = s3.GetFile(sourcePath);

            //  convert to memory stream so that we can seek

            if (response.Item == null)
            {
                return null;
            }
            else
            {
                return response.Item;
            }


        }
        /// <summary>
        /// uploads this file stream to the S3 Archive bucket
        /// </summary>
        /// <param name="archivePath"></param>
        /// <param name="fileStream"></param>
        /// <param name="fileName"></param>
        /// <param name="tempFolder"></param>
        public static void CopyFileToS3Archive(string archivePath, Stream fileStream, string fileName, string tempFolder)
        {
            var uploader = new S3UploadHelper(Settings.Default.AWSAccessKey,
                Settings.Default.AWSSecretKey,
                Settings.Default.AWSRegionName,
                Settings.Default.AWSS3BucketName);

            var archiveFileName = archivePath + fileName;
            uploader.Upload(fileStream, archiveFileName, tempFolder);
        }
        /// <summary>
        /// adds the stream to s3 with the specified key
        /// </summary>
        /// <param name="fileStream"></param>
        /// <param name="key"></param>
        /// <param name="tempFolder"></param>
        public static void AddS3File(Stream fileStream, string key, string tempFolder)
        {
            var uploader = new S3UploadHelper(Settings.Default.AWSAccessKey,
                Settings.Default.AWSSecretKey,
                Settings.Default.AWSRegionName,
                Settings.Default.AWSS3BucketName);

            uploader.Upload(fileStream, key, tempFolder);
        }
        /// <summary>
        /// returns whether the specified item exits in the s3 bucket
        /// </summary>
        /// <param name="sourcePath"></param>
        /// <returns></returns>
        public static bool S3FileExists(string sourcePath)
        {
            var s3 = new S3UploadHelper(Settings.Default.AWSAccessKey,
                  Settings.Default.AWSSecretKey,
                  Settings.Default.AWSRegionName,
                  Settings.Default.AWSS3BucketName);

            var response = s3.FileExists(sourcePath);
            return !string.IsNullOrEmpty(response.Item);
        }
        /// <summary>
        /// deletes this file from s3
        /// </summary>
        /// <param name="sourcePath"></param>
        public static void DeleteS3File(string sourcePath)
        {
            var s3 = new S3UploadHelper(Settings.Default.AWSAccessKey,
                 Settings.Default.AWSSecretKey,
                 Settings.Default.AWSRegionName,
                 Settings.Default.AWSS3BucketName);

            s3.DeleteFile(sourcePath);
        }