예제 #1
0
        public static Dictionary <string, JObject> ProcessCSVDirectory(DirectoryWrapper csvDirWrapper, DirectoryWrapper jsonDirWrapper)
        {
            DirectoryInfo csvDir  = csvDirWrapper.CreateInfo();
            DirectoryInfo jsonDir = jsonDirWrapper.CreateInfo();

            if (!csvDir.Exists)
            {
                throw new ArgumentException("Directory does not exist: " + csvDir + ".");
            }

            if (!jsonDir.Exists)
            {
                throw new ArgumentException("Directory does not exist: " + jsonDir + ".");
            }

            Dictionary <string, JObject> processedCsv = new Dictionary <string, JObject>();

            foreach (FileInfo csvFile in csvDir.GetFiles())
            {
                FileWrapper csvWrapper = new FileWrapper(csvFile);
                JObject     tableCsv   = ProcessCSV(csvWrapper);

                processedCsv.Add(csvWrapper.FullName, tableCsv);
            }

            return(processedCsv);
        }
예제 #2
0
    protected override void Awake()
    {
        totalLatitudes  /= dataScale;
        totalLongitudes /= dataScale;
        apiRange        *= dataScale;

        switch (dataSource)
        {
        case DataSource.SERVER:
            http       = gameObject.AddComponent <HTTPRequestWrapper>();
            fileSystem = new FileWrapper();
            fileSystem.SetDirectory(Application.persistentDataPath + "/");
            break;

        case DataSource.CSV:
            csv = gameObject.GetComponent <JAXAOpenAPICSVWrapper>();
            break;
        }

        foreach (DataType type in Enum.GetValues(typeof(DataType)))
        {
            currentDatas.Add(type, new float[(totalLongitudes + 1) * totalLatitudes]);
        }

        base.Awake();
    }
        public IRepository <TModel> GetRepository <TModel>() where TModel : class, IIdentifiable <TModel>
        {
            var fileName    = Path.Combine(baseDirectory, Path.ChangeExtension(typeof(TModel).Name, "json"));
            var fileWrapper = new FileWrapper(fileName);

            return(new JsonRepository <TModel>(fileWrapper));
        }
예제 #4
0
        private async Task ReadFile(string url, IProgress <int> progressReporter)
        {
            try
            {
                using (var fs = FileWrapper.OpenRead(url))
                {
                    var bytesRead = 0;
                    do
                    {
                        await PauseTokenSource.Token.WaitWhilePausedAsync(CancellationTokenSource.Token);

                        var segment = await Buffer.GetEmptySegmentAsync(CancellationTokenSource.Token);

                        bytesRead = await fs.ReadAsync(segment.Array, segment.Offset, segment.Count,
                                                       CancellationTokenSource.Token);

                        progressReporter.Report(bytesRead);

                        await Buffer.FillSegmentAsync(segment, bytesRead, CancellationTokenSource.Token);
                    } while (bytesRead > 0);
                }
            }
            finally
            {
                Buffer.CompleteAdding();
            }
        }
예제 #5
0
        public bool Save(string filepath)
        {
            var fileAccess = new FileWrapper();

            try
            {
                string path = filepath;
                if (String.IsNullOrEmpty(Path.GetExtension(filepath)))
                {
                    path = $"{filepath}.config";
                }
                var fi = new FileInfo(path);

                if (fi.Exists)
                {
                    var backupPath = $"{fi.FullName}.{DateTime.Now:yyyyMMddHHmmss}.bak";

                    fi.CopyTo(backupPath);
                }

                if (!String.IsNullOrEmpty(fi.DirectoryName) && !Directory.Exists(fi.DirectoryName))
                {
                    Directory.CreateDirectory(fi.DirectoryName);
                }

                string json = JsonConvert.SerializeObject(GetAll());
                fileAccess.Write(fi.FullName, json);
            }
            catch
            {
                throw;
            }

            return(true);
        }
        public FileWrapper UploadFileInCRM(String entityType,
                                           int entityid,
                                           Stream file,
                                           ContentType contentType,
                                           ContentDisposition contentDisposition,
                                           IEnumerable <System.Web.HttpPostedFileBase> files)
        {
            var folderid = GetRootFolderID();

            FileWrapper uploadedFile = null;

            if (files != null && files.Any())
            {
                //For case with multiple files
                foreach (var postedFile in files)
                {
                    //   bool createNewIfExist;

                    //  if (existFilesTitle.Contains(postedFile.FileName))
                    //       createNewIfExist = false;
                    //   else
                    //   bool createNewIfExist = true;

                    uploadedFile = SaveFile(folderid, postedFile.InputStream, new ContentType(postedFile.ContentType), new ContentDisposition {
                        FileName = postedFile.FileName, Size = postedFile.ContentLength
                    }, true);
                }
            }
            else if (file != null)
            {
                uploadedFile = SaveFile(folderid, file, contentType, contentDisposition, true);
            }

            return(uploadedFile);
        }
        private void _service_Connected(object sender, PviEventArgs e)
        {
            string serviceName = String.Empty;

            if (sender is Service service)
            {
                serviceName = service.FullName;
            }

            var cpuWrapper      = new CpuWrapper(_service, _eventNotifier);
            var variableWrapper = new VariableWrapper(_service, _eventNotifier);

            var fw         = new FileWrapper();
            var cpuManager = new CpuManager(cpuWrapper);

            var variableInfo = new VariableInfoCollection(fw);

            var variableManager = new VariableManager(variableWrapper, variableInfo);

            var pviEventMsg = Utils.FormatPviEventMessage($"ServiceWrapper._service_Connected; ServiceName={serviceName}", e);

            _eventNotifier.OnPviServiceConnected(sender, new PviApplicationEventArgs()
            {
                Message         = pviEventMsg,
                ServiceWrapper  = this,
                CpuManager      = cpuManager,
                CpuWrapper      = cpuWrapper,
                VariableManager = variableManager,
                VariableWrapper = variableWrapper
            });

            _pollingService = new PollingService(_service, cpuManager);
            _pollingService.Start();
        }
예제 #8
0
        public Measuring()
        {
            var minBufferSize = 1024 * 8;
            var maxBufferSize = 1024 * 2024;

#if UseExampleFile
            var nameOfFileToCompress = "example.txt";
            var fileToCompressInfo   = new FileInfo(nameOfFileToCompress);
            var nameOfCompressedFile = Path.Combine(fileToCompressInfo.DirectoryName,
                                                    $"{Path.GetFileNameWithoutExtension(fileToCompressInfo.FullName)}.gz");
            var nameOfDecompressedFile = Path.Combine(fileToCompressInfo.DirectoryName,
                                                      $"{Path.GetFileNameWithoutExtension(fileToCompressInfo.Name)}-decompressed{fileToCompressInfo.Extension}");

            var fileToCompress    = new FileWrapper(fileToCompressInfo);
            var compressedFile    = new FileWrapper(nameOfCompressedFile);
            var decompressingFile = compressedFile;
            var decompressedFile  = new FileWrapper(nameOfDecompressedFile);
#elif UseStub
            var fileToCompress       = new StubFile();
            var compressedFile       = new StubFile();
            var compressedFileTarget = compressedFile;
            var compressedFileSource = compressedFile;
            var decompressedFile     = new StubFile();
            var decompressedFile     = decompressedFile;
#endif

            _configuration = new Configuration(
                minBufferSize,
                maxBufferSize,
                fileToCompress,
                compressedFile,
                decompressingFile,
                decompressedFile);
        }
예제 #9
0
        private void WriteFileToDisk(FileWrapper fWrapper)
        {
            MemoryStream buffer = fWrapper.DecrytptedData();

            FileInfo file = new FileInfo(Path.GetFullPath("./Resources/out/" + fWrapper.Info().Name));


            if (!Directory.Exists(file.DirectoryName))
            {
                Directory.CreateDirectory(file.DirectoryName);
            }
            //    if (File.Exists(file.FullName))
            //        try
            //        {
            //            File.Create(file.FullName);
            //        }
            //        catch (IOException e1)
            //        {
            //            throw new TraceSdkException("Failed to create output file");
            //        }
            //}

            using (FileStream fs = new FileStream(file.FullName, FileMode.Create, System.IO.FileAccess.Write))
            {
                byte[] bytes = new byte[buffer.Length];
                buffer.Read(bytes, 0, (int)buffer.Length);
                fs.Write(bytes, 0, bytes.Length);
                buffer.Close();
            }
        }
        private Activity GetFileActivity(FileEntry fileEntry, DateTimeRange range)
        {
            object wrapper;

            if (fileEntry is File)
                wrapper = new FileWrapper((File) fileEntry);
            else
                wrapper = new FolderWrapper((Folder) fileEntry);

            var activity = new Activity(Documents, wrapper)
            {
                Action = (range.In(fileEntry.CreateOn) ? ActivityAction.Created : ActivityAction.Undefined) | (range.In(fileEntry.ModifiedOn) ? ActivityAction.Updated : ActivityAction.Undefined) | (range.In(fileEntry.SharedToMeOn) ? ActivityAction.Shared : ActivityAction.Undefined),
                ItemType = "file",
            };

            if (range.In(fileEntry.CreateOn))
            {
                activity.CreatedBy = fileEntry.CreateBy;
                activity.When = fileEntry.CreateOn;
            }
            else if (range.In(fileEntry.ModifiedOn))
            {
                activity.CreatedBy = fileEntry.ModifiedBy;
                activity.When = fileEntry.ModifiedOn;
            }
            else if (range.In(fileEntry.SharedToMeOn))
            {
                activity.CreatedBy = new Guid(fileEntry.SharedToMeBy);
                activity.When = fileEntry.SharedToMeOn;
            }

            return activity;
        }
        public FileWrapper DeleteCRMFile(int fileid)
        {
            if (fileid < 0)
            {
                throw new ArgumentException();
            }

            var file = FilesDaoFactory.GetFileDao().GetFile(fileid);

            if (file == null)
            {
                throw new ItemNotFoundException();
            }
            var result = new FileWrapper(file);

            var _eventsDao = DaoFactory.RelationshipEventDao;
            var eventIDs   = _eventsDao.RemoveFile(file);
            var events     = new List <RelationshipEvent>();

            eventIDs.ForEach(id => events.Add(_eventsDao.GetByID(id)));

            foreach (var evt in events)
            {
                DomainObject entityObj;
                var          entityTitle = evt.ContactID > 0
                                  ? GetEntityTitle(EntityType.Contact, evt.ContactID, false, out entityObj)
                                  : GetEntityTitle(evt.EntityType, evt.EntityID, false, out entityObj);
                var messageAction = GetFilesDetachAction(evt.EntityType, evt.ContactID);

                MessageService.Send(Request, messageAction, MessageTarget.Create(file.ID), entityTitle, file.Title);
            }

            return(result);
        }
예제 #12
0
        public void LoadsInputFromAGivenFile(FileWrapper wrapper)
        {
            string inputPath = null;

            try
            {
                // -- Setup
                var expected = new[] { "multiply 9", "apply 5" };

                inputPath = Path.GetTempFileName();
                File.WriteAllLines(inputPath, expected);

                // -- Arrange

                // -- Act
                var actual = wrapper.ReadAllLines(inputPath);

                // -- Assert
                Assert.Equal(expected.Length, actual.Length);
                Assert.Equal(expected[0], actual[0]);
                Assert.Equal(expected[1], actual[1]);
            }
            finally
            {
                // -- Teardown
                if (File.Exists(inputPath))
                {
                    File.Delete(inputPath);
                }
            }
        }
예제 #13
0
        public void UploadFile()
        {
            IFormatter  formatter   = new BinaryFormatter();
            FileWrapper fileWrapper = new FileWrapper(_fileName, GetFileData(_filePath));

            _serializer.WriteToStream(_connect.GetStream(), fileWrapper);
        }
        public FileWrapper DeleteCRMFile(int fileid)
        {
            if (fileid < 0)
            {
                throw new ArgumentException();
            }

            var file = FilesDaoFactory.GetFileDao().GetFile(fileid);

            if (file == null)
            {
                throw new ItemNotFoundException();
            }
            var result = new FileWrapper(file);

            var _eventsDao = DaoFactory.GetRelationshipEventDao();
            var eventIDs   = _eventsDao.RemoveFile(file);
            var events     = new List <RelationshipEvent>();

            eventIDs.ForEach(id => events.Add(_eventsDao.GetByID(id)));
            //events for audit log

            MessageService.Send(_context, MessageAction.CrmEntityDetachedFile, file.Title);

            return(result);
        }
예제 #15
0
        public DsfDropBoxDownloadActivity()
        {
            DisplayName   = "Download from Dropbox";
            OverwriteFile = false;

            DropboxFile = new FileWrapper();
        }
예제 #16
0
        public bool Open(string filepath)
        {
            var fileAccess = new FileWrapper();

            lock (_syncLock)
            {
                try
                {
                    if (File.Exists(filepath))
                    {
                        var json = fileAccess.Read(filepath);
                        var list = JsonConvert.DeserializeObject <List <CpuInfo> >(json);
                        _cpuLookup.Clear();
                        foreach (var cpu in list)
                        {
                            AddOrUpdate(cpu);
                        }
                    }
                }
                catch
                {
                    throw;
                }
            }

            return(true);
        }
        /// <summary>
        /// Saves a file via the file storage Web API
        /// </summary>
        /// <param name="file">the file to save.</param>
        /// <returns>a storage result indicating the success of the attempt.  If successful the FileUrl property will be populated with a Url to retrieve the resource as needed.</returns>
        public async Task<FileStorageResult> SaveFileAsync(FileWrapper file)
        {
            var result = new FileStorageResult();

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(storageApiUrl);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                try
                {
                    var response = await client.PostAsJsonAsync("api/File", file);

                    result.Success = response.IsSuccessStatusCode;

                    if (!result.Success)
                    {
                        result.Errors.Add(response.ReasonPhrase);
                    }
                    else
                    {
                        result.FileUrl = response.Headers.Location.AbsoluteUri;
                    }
                }
                catch (Exception e)
                {
                    result.Success = false;
                    result.StorageException = e;
                }
            }

            return result;
        }
        public void LoadsInputFromAGivenFile(FileWrapper wrapper)
        {
            string inputPath = null;
            try
            {
                // -- Setup
                var expected = new[] {"multiply 9", "apply 5"};

                inputPath = Path.GetTempFileName();
                File.WriteAllLines(inputPath, expected);

                // -- Arrange

                // -- Act
                var actual = wrapper.ReadAllLines(inputPath);

                // -- Assert
                Assert.Equal(expected.Length, actual.Length);
                Assert.Equal(expected[0], actual[0]);
                Assert.Equal(expected[1], actual[1]);
            }
            finally
            {
                // -- Teardown
                if (File.Exists(inputPath))
                    File.Delete(inputPath);
            }
        }
예제 #19
0
 void TestSetup(out IFile fileWrapper, out IDirectory directoryWrapper, out Mock <IDev2Activity> activity)
 {
     SetupDataObject();
     fileWrapper      = new FileWrapper();
     directoryWrapper = new DirectoryWrapper();
     activity         = new Mock <IDev2Activity>();
 }
        public FileWrapper UploadFileInCRM(
            string entityType,
            int entityid,
            Stream file,
            ContentType contentType,
            ContentDisposition contentDisposition,
            IEnumerable <System.Web.HttpPostedFileBase> files,
            bool storeOriginalFileFlag
            )
        {
            FilesSettings.StoreOriginalFiles = storeOriginalFileFlag;

            var folderid = GetRootFolderID();

            var fileNames = new List <string>();

            FileWrapper uploadedFile = null;

            if (files != null && files.Any())
            {
                //For case with multiple files
                foreach (var postedFile in files)
                {
                    uploadedFile = SaveFile(folderid, postedFile.InputStream, postedFile.FileName);
                    fileNames.Add(uploadedFile.Title);
                }
            }
            else if (file != null)
            {
                uploadedFile = SaveFile(folderid, file, contentDisposition.FileName);
                fileNames.Add(uploadedFile.Title);
            }

            return(uploadedFile);
        }
예제 #21
0
 private void DeleteIfExists(string url)
 {
     if (FileWrapper.Exists(url))
     {
         FileWrapper.Delete(url);
     }
 }
예제 #22
0
        /// <summary>
        /// Setup custom rules overriding autowired ones, for example in cases
        /// where an interface has multiple implementations, and cases where
        /// a singleton is preferred to new instances.
        /// </summary>
        private static void SetupCustomRules(ContainerBuilder builder)
        {
            // Make sure the configuration is read only once.
            IConfig config = new Config(new ConfigData(new Logger(Uptime.ProcessId)));

            builder.RegisterInstance(config).As <IConfig>().SingleInstance();

            // Service configuration is generated by the entry point, so we
            // prepare the instance here.
            builder.RegisterInstance(config.LoggingConfig).As <ILoggingConfig>().SingleInstance();
            builder.RegisterInstance(config.ServicesConfig).As <IServicesConfig>().SingleInstance();
            builder.RegisterInstance(config.BlobStorageConfig).As <IBlobStorageConfig>().SingleInstance();

            // Instantiate only one logger
            var logger = new Logger(Uptime.ProcessId, config.LoggingConfig);

            builder.RegisterInstance(logger).As <ILogger>().SingleInstance();

            var threadWrapper = new ThreadWrapper();

            // Auth and CORS setup
            Auth.Startup.SetupDependencies(builder, config);

            // By default the DI container create new objects when injecting
            // dependencies. To improve performance we reuse some instances,
            // for example to reuse IoT Hub connections, as opposed to creating
            // a new connection every time.
            //builder.RegisterType<Foo>().As<IFoo>().SingleInstance();
            ICloudStorageWrapper cloudStorageWrapper = new CloudStoragWrapper();
            IBlobStorageHelper   blobStorageHelper   = new BlobStorageHelper(config.BlobStorageConfig, cloudStorageWrapper, logger);
            IFileWrapper         fileWrapper         = new FileWrapper();

            IDeviceGroupsWriter deviceGroupsWriter = new DeviceGroupsWriter(config.BlobStorageConfig, blobStorageHelper, fileWrapper, logger);

            builder.RegisterInstance(deviceGroupsWriter).As <IDeviceGroupsWriter>().SingleInstance();

            IHttpClient    httpClient    = new HttpClient(logger);
            IDevicesClient devicesClient = new DevicesClient(httpClient, config.ServicesConfig, logger);

            builder.RegisterInstance(devicesClient).As <IDevicesClient>().SingleInstance();
            IDeviceGroupsClient deviceGroupsClient = new DeviceGroupsClient(
                httpClient,
                devicesClient,
                config.ServicesConfig,
                logger,
                threadWrapper);

            builder.RegisterInstance(deviceGroupsClient).As <IDeviceGroupsClient>().SingleInstance();

            // Event Hub Classes
            IEventProcessorHostWrapper eventProcessorHostWrapper = new EventProcessorHostWrapper();

            builder.RegisterInstance(eventProcessorHostWrapper).As <IEventProcessorHostWrapper>().SingleInstance();
            IEventHubStatus eventHubStatus = new EventHubStatus();

            builder.RegisterInstance(eventHubStatus).As <IEventHubStatus>().SingleInstance();
            IEventProcessorFactory eventProcessorFactory = new DeviceEventProcessorFactory(eventHubStatus, config.ServicesConfig, logger);

            builder.RegisterInstance(eventProcessorFactory).As <IEventProcessorFactory>().SingleInstance();
        }
        // disclaimer: visual studio doesn't support adding dependent file under linked file
        // so no dependent transformed config under linked app.config in designer
        private static void CreateConfigFiles(Project project, ProjectItem projectItem)
        {
            string appConfigName           = projectItem.Name;
            var    buildConfigurationNames = project.GetBuildConfigurationNames();
            var    projectFileIsDirty      = false;
            // get app.config directory. new transform config will be created there.
            //var path = projectItem.GetFullPath();
            string path = null;

            if (projectItem.IsLink())
            {
                path = Directory.GetParent(projectItem.ContainingProject.FullName).FullName;
            }
            else
            {
                path = Directory.GetParent(projectItem.GetFullPath()).FullName;
            }

            foreach (var buildConfigurationName in buildConfigurationNames)
            {
                var dependentConfig         = GetTransformConfigName(appConfigName, buildConfigurationName);
                var dependentConfigFullPath = Path.Combine(path, dependentConfig);
                // check if config file exist
                if (!FileWrapper.Exists(dependentConfigFullPath))
                {
                    using (var file = FileWrapper.AppendText(dependentConfigFullPath))
                    {
                        file.Write(DependencyConfigContent);
                    }
                    projectFileIsDirty = true;
                    projectItem.ProjectItems.AddFromFile(dependentConfigFullPath);
                    //project.ProjectItems.AddFromFile(dependentConfigFullPath);
                }
            }
        }
예제 #24
0
        private async Task WriteFile(string url, IProgress <int> progressReporter)
        {
            try
            {
                using (var fs = FileWrapper.OpenWrite(url))
                {
                    while (await Buffer.OutputAvailableAsync(CancellationTokenSource.Token))
                    {
                        await PauseTokenSource.Token.WaitWhilePausedAsync(CancellationTokenSource.Token);

                        var segment = await Buffer.GetFilledSegmentAsync(CancellationTokenSource.Token);

                        await fs.WriteAsync(segment.Array, segment.Offset, segment.Count, CancellationTokenSource.Token);

                        progressReporter.Report(segment.Count);

                        await Buffer.FreeSegmentAsync(segment, CancellationTokenSource.Token);
                    }
                }
            }
            catch (Exception)
            {
                DeleteIfExists(url);
                throw;
            }
        }
예제 #25
0
        public void Setup()
        {
            _sfp                  = new StandardFolderProvider();
            _folderInfo           = new Mock <IFolderInfo>();
            _fileInfo             = new Mock <IFileInfo>();
            _fileWrapper          = new Mock <IFile>();
            _directoryWrapper     = new Mock <IDirectory>();
            _folderManager        = new Mock <IFolderManager>();
            _fileManager          = new Mock <IFileManager>();
            _pathUtils            = new Mock <IPathUtils>();
            _portalControllerMock = new Mock <IPortalController>();
            _portalControllerMock.Setup(p => p.GetPortalSettings(Constants.CONTENT_ValidPortalId))
            .Returns(GetPortalSettingsDictionaryMock());
            _portalControllerMock.Setup(p => p.GetCurrentPortalSettings()).Returns(GetPortalSettingsMock());
            _cryptographyProviderMock = new Mock <CryptographyProvider>();
            _cryptographyProviderMock.Setup(c => c.EncryptParameter(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(Guid.NewGuid().ToString("N"));
            _localeControllerMock = new Mock <ILocaleController>();
            _localeControllerMock.Setup(l => l.GetLocales(Constants.CONTENT_ValidPortalId)).Returns(new Dictionary <string, Locale>
            {
                { "en-us", new Locale() }
            });

            FileWrapper.RegisterInstance(_fileWrapper.Object);
            DirectoryWrapper.RegisterInstance(_directoryWrapper.Object);
            FolderManager.RegisterInstance(_folderManager.Object);
            FileManager.RegisterInstance(_fileManager.Object);
            PathUtils.RegisterInstance(_pathUtils.Object);
            PortalController.SetTestableInstance(_portalControllerMock.Object);
            ComponentFactory.RegisterComponentInstance <CryptographyProvider>("CryptographyProviderMock", _cryptographyProviderMock.Object);
            LocaleController.RegisterInstance(_localeControllerMock.Object);
        }
예제 #26
0
        public static JObject FindFields(FileWrapper fileWrapper)
        {
            Dictionary <string, HashSet <string> > fields = new Dictionary <string, HashSet <string> >();

            using (StreamReader streamReader = new StreamReader(new FileStream(fileWrapper.CreateInfo().ToString(), FileMode.Open, FileAccess.Read), Encoding.UTF8))
            {
                string[] fieldNames = streamReader.ReadLine().Split(",");
                string   line;
                while ((line = streamReader.ReadLine()) != null)
                {
                    JObject  JsonElement = new JObject();
                    string[] fieldValues = line.Split(",");
                    for (int i = 0; i < fieldValues.Length; i++)
                    {
                        string fieldName  = fieldNames[i];
                        string fieldValue = fieldValues[i];

                        if ("".Equals(fieldValue))
                        {
                            continue;
                        }

                        if (!fields.ContainsKey(fieldName))
                        {
                            fields.Add(fieldName, new HashSet <string>());
                        }

                        fields[fieldName].Add(fieldValue);
                    }
                }
            }

            return(FindFields(fields));
        }
예제 #27
0
        public void GetWidth_ReturnsCorrectValue()
        {
            const int width       = 1024;
            var       fileWrapper = new FileWrapper(new FileInfo("nest_by_mrfloki-dcgzwvz.png"));

            Assert.AreEqual(width, fileWrapper.GetWidth());
        }
 public DsfDropBoxDownloadActivity()
 {
     // ReSharper disable once VirtualMemberCallInContructor
     DisplayName   = "Download from Dropbox";
     OverwriteFile = false;
     // ReSharper disable once VirtualMemberCallInContructor
     DropboxFile = new FileWrapper();
 }
예제 #29
0
        public DsfDropBoxDownloadActivity()
            : this(new DropboxClientWrapperFactory())
        {
            DisplayName   = "Download from Dropbox";
            OverwriteFile = false;

            DropboxFile = new FileWrapper();
        }
 static ConfigTransformManager()
 {
     // add default vs service
     VsService           = VsServices.Instance;
     ProjectXmlTransform = new VsProjectXmlTransform();
     FileWrapper         = new FileWrapper();
     StreamManager       = new StreamManager();
 }
예제 #31
0
 public TestCoverageCatalog(IResourceCatalog resourceCatalog)
 {
     _directoryWrapper = new DirectoryWrapper();
     _fileWrapper      = new FileWrapper();
     _directoryWrapper.CreateIfNotExists(EnvironmentVariables.TestCoveragePath);
     _serializer = new Dev2JsonSerializer();
     _serviceAllTestsCoverageModelToFactory = CustomContainer.Get <IServiceTestCoverageModelToFactory>() ?? new ServiceTestCoverageModelToFactory(resourceCatalog);
 }
예제 #32
0
        public void Given_Null_Path_When_Exists_Invoked_Then_It_Should_Return_False()
        {
            var wrapper = new FileWrapper();

            var result = wrapper.Exists(null);

            result.Should().BeFalse();
        }
예제 #33
0
 public TestCatalog()
 {
     _directoryWrapper = new DirectoryWrapper();
     _fileWrapper      = new FileWrapper();
     _directoryWrapper.CreateIfNotExists(EnvironmentVariables.TestPath);
     Tests       = new ConcurrentDictionary <Guid, List <IServiceTestModelTO> >();
     _serializer = new Dev2JsonSerializer();
 }
예제 #34
0
        public void FailsFastOnNullInput(FileWrapper wrapper)
        {
            // -- Arrange

            // -- Act

            // -- Assert
            Assert.ThrowsAny<ArgumentNullException>(() => wrapper.ReadAllLines(null));
        }
예제 #35
0
        public void ImplementsIFile(FileWrapper wrapper)
        {
            // -- Arrange

            // -- Act

            // -- Assert
            Assert.IsAssignableFrom<IFile>(wrapper);
        }
예제 #36
0
 public void Shim_All_IsFileEmpty_Return_False_If_New_Create_File_WithText()
 {
     sut = new FileWrapper(new FileHelper());
     using (ShimsContext.Create())
     {
         ShimFileHelper.AllInstances.IsEmptyString = delegate { return false; };
         Assert.IsFalse(sut.IsFileEmpty(fileName));
     }
 }
예제 #37
0
        public void IsFileExist_Return_True_If_New_Create_File()
        {
            sut = new FileWrapper(new FileHelper());
            using(File.Create(fileName))
            {

            }
            Assert.IsTrue(sut.IsFileExist(fileName));
        }
예제 #38
0
 public void IsFileEmpty_Return_False_If_New_Create_File_WithText()
 {
     sut = new FileWrapper(new FileHelper());
     using (StreamWriter writer = File.CreateText(fileName))
     {
         writer.WriteLine("Hello, World!");
         writer.Flush();
     }
     Assert.IsFalse(sut.IsFileEmpty(fileName));
 }
        public static FileWrapper ToFileWrapper(this FileDetails fileDetails, byte[] payload)
        {
            var fileWrapper = new FileWrapper();

            fileWrapper.FileName = fileDetails.FileName;
            fileWrapper.ApplicationName = fileDetails.ApplicationName;
            fileWrapper.Sha256Checksum = fileDetails.Checksum;
            fileWrapper.MimeType = fileDetails.MimeType;
            fileWrapper.Payload = payload;

            return fileWrapper;
        }
        public void FileWrapper_ToMetaData_Returns_Properly_Hydrated()
        {
            var fileWrapper = new FileWrapper();
            fileWrapper.ApplicationName = "application";
            fileWrapper.FileName = "file.txt";
            fileWrapper.MimeType = "mimetype";
            fileWrapper.Payload = new byte []{1, 0, 1};

            var metaData = fileWrapper.ToMetaData();

            Assert.AreEqual(metaData.ApplicationName, fileWrapper.ApplicationName);
            Assert.AreEqual(metaData.FileName, fileWrapper.FileName);
            Assert.AreEqual(metaData.MimeType, fileWrapper.MimeType);
            Assert.AreEqual(metaData.Checksum, Checksummer.ComputeChecksum(fileWrapper.Payload));
        }
    public static void Main()
    {
        //
        // <=> ao Try-with-resources do Java
        //
        using(FileWrapper fs = new FileWrapper("out.txt")){
            // FileWrapper fs = new FileWrapper("out.txt");
            // Wait for user to hit <Enter>
            Console.WriteLine("Wait for user to hit <Enter>");
            Console.ReadLine();
            // GC.Collect();
            // GC.WaitForPendingFinalizers();
        }

        Console.WriteLine("Wait for user to hit <Enter>");
        Console.ReadLine();
    }
예제 #42
0
        public async Task<HttpResponseMessage> SaveFileAsync(FileWrapper file)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            // todo: consider rolling this into a validation attribute.  
            if (!string.IsNullOrEmpty(file.Sha256Checksum))
            {
                if (!Checksummer.ChecksumsMatch(file.Sha256Checksum, file.Payload))
                {
                    logger.Info(string.Format("Checksum mismatch for file with name: {0} from application: {1}", file.FileName, file.ApplicationName));
                    return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "The checksum submitted did not match the server computed SHA256 checksum.");
                }
            }

            try
            {
                var uniqueFileName = Guid.NewGuid() + "_" + file.FileName;
                var filePath = BuildFilePathAndAppendFileName(baseFileStoragePath, file.ApplicationName, uniqueFileName);
                await fileStorageProvider.StoreFile(filePath, file.Payload);

                var metaData = file.ToMetaData();
                metaData.StoragePath = filePath;
                var fileId = await metaDataRepository.SaveFileMetaDataAsync(metaData);

                var response = Request.CreateResponse(HttpStatusCode.Created, file);
                response.Headers.Location = new Uri(Url.Link("GetFileById", new { id = fileId}));

                return response;
            }
            catch (Exception e)
            {
                logger.Error(string.Format("error saving file with name: {0} for application: {1}", file.FileName, file.ApplicationName), e);
                return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "File Storage API experienced an error.  This has been reported.  Please try again shortly.");
            }
        }
        // Parses the file on the meter's processing thread and kicks off processing of the meter data set.
        private void ParseFile(string connectionString, SystemSettings systemSettings, string filePath, string meterKey, DataReaderWrapper dataReaderWrapper, FileWrapper fileWrapper)
        {
            FileGroup fileGroup = null;
            MeterDataSet meterDataSet;
            int queuedFileCount;

            // Keep track of the number of operations in thread queues
            queuedFileCount = Interlocked.Decrement(ref m_queuedFileCount);

            if (m_stopped || m_disposed)
            {
                dataReaderWrapper.Dispose();
                return;
            }

            using (dataReaderWrapper)
            using (DbAdapterContainer dbAdapterContainer = new DbAdapterContainer(systemSettings.DbConnectionString, systemSettings.DbTimeout))
            {
                try
                {
                    // Keep track of the meters and files currently being processed
                    if ((object)meterKey != null)
                        m_activeFiles[meterKey] = filePath;

                    ThreadContext.Properties["Meter"] = meterKey;

                    // Create the file group
                    fileGroup = fileWrapper.GetFileGroup(dbAdapterContainer.GetAdapter<FileInfoDataContext>(), systemSettings.XDATimeZoneInfo);

                    // Parse the file to turn it into a meter data set
                    OnStatusMessage($"Parsing data from file \"{filePath}\"...");
                    dataReaderWrapper.DataObject.Parse(filePath);
                    OnStatusMessage($"Finished parsing data from file \"{filePath}\".");
                    meterDataSet = dataReaderWrapper.DataObject.MeterDataSet;

                    // If the data reader does not return a data set,
                    // there is nothing left to do
                    if ((object)meterDataSet == null)
                        return;

                    // Data reader has finally outlived its usefulness
                    dataReaderWrapper.Dispose();

                    // Set file path, file group, connection string,
                    // and meter asset key for the meter data set
                    meterDataSet.FilePath = filePath;
                    meterDataSet.FileGroup = fileGroup;
                    meterDataSet.ConnectionString = connectionString;
                    meterDataSet.Meter.AssetKey = meterKey;

                    // Shift date/time values to the configured time zone and set the start and end time values on the file group
                    ShiftTime(meterDataSet, meterDataSet.Meter.GetTimeZoneInfo(systemSettings.DefaultMeterTimeZoneInfo), systemSettings.XDATimeZoneInfo);
                    SetDataTimeRange(meterDataSet, dbAdapterContainer.GetAdapter<FileInfoDataContext>());

                    // Determine whether the file duration is within a user-defined maximum tolerance
                    ValidateFileDuration(meterDataSet.FilePath, systemSettings.MaxFileDuration, meterDataSet.FileGroup);

                    // Determine whether the timestamps in the file extend beyond user-defined thresholds
                    ValidateFileTimestamps(meterDataSet.FilePath, meterDataSet.FileGroup, systemSettings, dbAdapterContainer.GetAdapter<FileInfoDataContext>());

                    // Process the meter data set
                    OnStatusMessage($"Processing meter data from file \"{filePath}\"...");
                    ProcessMeterDataSet(meterDataSet, systemSettings, dbAdapterContainer);
                    OnStatusMessage($"Finished processing data from file \"{filePath}\".");
                }
                catch (Exception ex)
                {
                    // There seems to be a problem here where the outer exception's call stack
                    // was overwritten by the call stack of the point where it was thrown
                    ExceptionDispatchInfo exInfo = ExceptionDispatchInfo.Capture(ex);

                    try
                    {
                        // Attempt to set the error flag on the file group
                        if ((object)fileGroup != null)
                            fileGroup.Error = 1;
                    }
                    catch (Exception fileGroupError)
                    {
                        // Log any exceptions that occur when attempting to set the error flag on the file group
                        string message = $"Exception occurred setting error flag on file group: {fileGroupError.Message}";
                        OnProcessException(new Exception(message, fileGroupError));
                    }

                    // Throw the original exception
                    exInfo.Throw();
                }
                finally
                {
                    if ((object)fileGroup != null)
                    {
                        try
                        {
                            // Attempt to set the processing end time of the file group
                            fileGroup.ProcessingEndTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, systemSettings.XDATimeZoneInfo);
                            dbAdapterContainer.GetAdapter<FileInfoDataContext>().SubmitChanges();
                        }
                        catch (Exception ex)
                        {
                            // Log any exceptions that occur when attempting to set processing end time on the file group
                            string message = $"Exception occurred setting processing end time on file group: {ex.Message}";
                            OnProcessException(new Exception(message, ex));
                        }
                    }

                    // Keep track of the meters and files currently being processed
                    if ((object)meterKey != null)
                        m_activeFiles.TryRemove(meterKey, out filePath);

                    ThreadContext.Properties.Remove("Meter");
                }
            }
        }
예제 #44
0
 public void Shim_Static_IsFileNullOrEmpty_Return_False_If_New_Create_File_WithText()
 {
     sut = new FileWrapper(new FileHelper());
     using (ShimsContext.Create())
     {
         ShimFileHelper.IsNullOrEmptyString = name => false;
         Assert.IsFalse(sut.IsFileNullOrEmpty(fileName));
     }
 }
예제 #45
0
 public ElaUnit WriteString(string str, FileWrapper fs)
 {
     var sw = new StreamWriter(fs.Stream);
     sw.Write(str);
     sw.Flush();
     return ElaUnit.Instance;
 }
예제 #46
0
 public void Shim_One_IsFileEmpty_Return_False_If_New_Create_File_WithText()
 {
     using (ShimsContext.Create())
     {
         var shimFileHelper = new ShimFileHelper();
         shimFileHelper.IsEmptyString = name => false;
         sut = new FileWrapper(shimFileHelper.Instance);
         Assert.IsFalse(sut.IsFileEmpty(fileName));
     }
 }
예제 #47
0
 public string ReadLine(FileWrapper fs)
 {
     var sr = new StreamReader(fs.Stream);
     return sr.ReadLine();
 }
예제 #48
0
 public ElaUnit CloseFile(FileWrapper fs)
 {
     fs.Dispose();
     return ElaUnit.Instance;
 }
예제 #49
0
        public void Stub_IsFileExist_Return_True_If_New_Create_File()
        {
            var fileHelper = new StubFileHelper();
            fileHelper.IsNullString = name => false;

            sut = new FileWrapper(fileHelper);
            Assert.IsTrue(sut.IsFileExist(fileName));
        }
예제 #50
0
        private FileWrapper GetWrapper(string fileName, out bool isVersioned)
        {
            isVersioned = false;
            if (string.IsNullOrWhiteSpace(fileName)) return null;

            var lastDirectorySeparatorIndex = fileName.LastIndexOf('\\');
            var firstPeriodIndex = lastDirectorySeparatorIndex < 0
                ? fileName.IndexOf('.')
                : fileName.IndexOf('.', lastDirectorySeparatorIndex);
            var lastPeriodIndex = fileName.LastIndexOf('.');

            var fullExtension = firstPeriodIndex < 0 ? "" : fileName.Substring(firstPeriodIndex);
            var extension = lastPeriodIndex < 0 ? "" : fileName.Substring(lastPeriodIndex);
            var baseFileName = firstPeriodIndex < 0 ? fileName : fileName.Substring(0, firstPeriodIndex);

            var versionSuffix = "_v" + _version;
            isVersioned = baseFileName.EndsWith(versionSuffix);
            if (isVersioned)
            {
                var fileNameWithoutVersion = baseFileName.Substring(0, baseFileName.Length - versionSuffix.Length);
                fileName = fileNameWithoutVersion + fullExtension;
            }

            var fileCache = _fileCache;
            FileWrapper wrapper;
            lock (fileCache)
            {
                if (fileCache.TryGetValue(fileName, out wrapper)) return wrapper;

                var fileTypes = _fileTypes;
                FileTypeInfo fileTypeInfo;
                lock (fileTypes)
                {
                    if (!fileTypes.TryGetValue(extension, out fileTypeInfo))
                        fileTypeInfo = _defaultFileTypeInfo;
                }

                wrapper = new FileWrapper(_uiDirectoryInfo, fileName, fileTypeInfo);
                fileCache.Add(fileName, wrapper);
            }
            return wrapper;
        }
예제 #51
0
 public string ReadAllLines(FileWrapper fs)
 {
     var sr = new StreamReader(fs.Stream);
     return sr.ReadToEnd();
 }