private void StartUpload(FileSource fileSource)
        {
            try
            {
                var allDirectories = Helpers.Helpers.GetSubdirectoriesContainingOnlyFiles(fileSource.LocalDirectoryPath);

                foreach (var directory in allDirectories)
                {
                    var allFilesInADirectory = Directory.GetFiles(directory);

                    foreach (var file in allFilesInADirectory)
                    {
                        var testString = directory.Remove(0, fileSource.LocalDirectoryPath.Length);

                        var bucketName = fileSource.BucketName + @"/" + fileSource.S3FolderName + @"/" + fileSource.LocalDirectoryName + directory.Remove(0, fileSource.LocalDirectoryPath.Length).Replace("\\", "/");
                        var localFilePath = file;
                        UploadFileToAmazon(bucketName, localFilePath);
                    }
                }
            }
            catch (Exception ex)
            {
                Helpers.Helpers.LogExceptions(ex.Message);
            }
        }
Пример #2
0
        public void AddFile( Resource resource, byte[] fileInBytes, FileSource source )
        {
            //Check if we have a valid file
            Check( resource, fileInBytes );

            //See if we have file
            if ( _files.ContainsKey( resource.Id ) )
            {
                if ( IsNewer( _files[ resource.Id ], resource ) )
                    UpdateFile( resource, fileInBytes, source );
                else return;
            }
            else
            {
                SaveToDisk( fileInBytes, resource );
                _files.Add( resource.Id, resource );
            }

            //Check what the source is and who we should inform
            switch ( source )
            {
                case FileSource.ActivityManager:
                    if ( FileAdded != null )
                        FileAdded( this, new FileEventArgs( resource ) );
                    break;
                case FileSource.ActivityClient:
                    if ( FileCopied != null )
                        FileCopied( this, new FileEventArgs( resource ) );
                    break;
            }
            Log.Out( "FileStore", string.Format( "Added file {0} to store", resource.Name ), LogCode.Log );
        }
Пример #3
0
        protected override void ProcessRecord()
        {
            source = new FileSource { Name = Name, Root = PathUtilities.GetRelativePath(Root.FullName), Converter = new FileToEntryConverter()};

            if (!String.IsNullOrEmpty(InstallMode))
            {
                var mode = (InstallMode) Enum.Parse(typeof (InstallMode), InstallMode);
                if (mode != Sitecore.Install.Utils.InstallMode.Undefined)
                {
                    source.Converter.Transforms.Add(
                        new InstallerConfigurationTransform(
                            new BehaviourOptions(mode, MergeMode.Undefined)));
                }
            }

            if (string.IsNullOrEmpty(IncludeFilter))
            {
                IncludeFilter = "*.*";
            }

            source.Include.Add(new FileNameFilter(IncludeFilter));
            source.Include.Add(new FileDateFilter(FileDateFilter.FileDateFilterType.CreatedFilter));
            source.Include.Add(new FileDateFilter(FileDateFilter.FileDateFilterType.ModifiedFilter));

            if (!string.IsNullOrEmpty(ExcludeFilter))
            {
                var filter = new FileNameFilter(ExcludeFilter);
                source.Exclude.Add(filter);
            }
            WriteObject(source, false);
        }
Пример #4
0
        protected override void ProcessRecord()
        {
            source = new FileSource {Name = Name, Root = Root, Converter = new FileToEntryConverter()};

            if (string.IsNullOrEmpty(IncludeFilter))
            {
                IncludeFilter = "*.*";
            }

            source.Include.Add(new FileNameFilter(IncludeFilter));
            source.Include.Add(new FileDateFilter(FileDateFilter.FileDateFilterType.CreatedFilter));
            source.Include.Add(new FileDateFilter(FileDateFilter.FileDateFilterType.ModifiedFilter));

            if (!string.IsNullOrEmpty(ExcludeFilter))
            {
                var filter = new FileNameFilter(ExcludeFilter);
                source.Exclude.Add(filter);
            }
            WriteObject(source, false);
        }
Пример #5
0
        protected UriRef GetPathFromSource(FileSource source)
        {
            UriRef result = null;

            if (source != null)
            {
                string sourcePath = (source as FileSource).Location;

                if (Path.IsPathRooted(sourcePath))
                {
                    result = new UriRef(sourcePath);
                }
                else
                {
                    string fullPath = Path.Combine(_sourceDir.FullName, sourcePath);
                    result = new UriRef(fullPath);
                }
            }

            return(result);
        }
Пример #6
0
        private async Task Demo05_ManyToOne()
        {
            Console.WriteLine(nameof(Demo05_ManyToOne));
            var length = 1200;

            System.IO.File.WriteAllBytes("ones.bin", GetArray(length, 1));
            System.IO.File.WriteAllBytes("twos.bin", GetArray(length, 2));

            var multiStart  = new MultiStart();
            var fileSource1 = new FileSource("ones.bin");
            var fileSource2 = new FileSource("twos.bin");
            var manytoOne   = new ManyToOne();
            var fileWriter  = new FileWriter("threes.bin");

            multiStart.Connect(fileSource1, fileSource2);
            fileSource1.Connect(manytoOne);
            fileSource2.Connect(manytoOne);
            manytoOne.Connect(fileWriter);

            await multiStart.Start();
        }
Пример #7
0
        public void Decompress()
        {
            var fs     = new FileSource();
            var buffer = new byte[] { };

            // Vector tiles are compressed.
            fs.Request(
                "https://api.mapbox.com/v4/mapbox.mapbox-streets-v7/0/0/0.vector.pbf",
                (Response res) => {
                buffer = res.Data;
            });

            fs.WaitForAllRequests();

            //tiles are automatically decompressed during HttpRequest on full .Net framework
#if NETFX_CORE
            Assert.Less(buffer.Length, Compression.Decompress(buffer).Length);
#else
            Assert.AreEqual(buffer.Length, Compression.Decompress(buffer).Length);
#endif
        }
Пример #8
0
        public void Start(string filePath, int blockSize, int blockCount)
        {
            var fileStream  = System.IO.File.Open(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read);
            var blockSource = new ByteStreamToBlock(fileStream, blockSize);
            var circb       = new CircularBuffer <byte[]>((int)Math.Log(blockCount, 2));
            var buffer      = new RefillBuffer <byte[]>(circb, blockSource, 1);

            buffer.Start();


            src = new FileSource(buffer, 0);
            var docType = new DocTypeEBML(new DocTypeMatroskaV2());
            var reader  = new EBMLReader(src, docType);

            //while(circb.ProducerCanWrite() && fileStream.Position != fileStream.Length) Thread.Sleep(20);


            (new Thread(Speed)).Start();
            SpeedRecurse(reader);
            finished = true;
        }
Пример #9
0
        public void TestByteRecordReaderRead()
        {
            string filename = ".unittestfile" + nameof(TestByteRecordReaderCreate);

            CreateCsvTempFile(filename);

            FileSource source = new FileSource(filename, Path.GetTempPath());

            ByteRecordReader reader = new ByteRecordReader(source, 2, 1);

            Assert.Throws <InvalidOperationException>(() => reader.Read(1));

            reader.Prepare();

            Assert.AreEqual(new[] { new byte[] { 5 }, new byte[] { 3 }, new byte[] { 4 } }, reader.Read(4));

            source.Dispose();
            reader.Dispose();

            DeleteTempFile(filename);
        }
Пример #10
0
        public void Prefer_File_Over_Environment()
        {
            var values = new[]
            {
                "Test=fromFile",
                "test=fromFile"
            };

            var dict = new Dictionary <string, string>
            {
                { "Test", "fromEnv" },
            };

            EnvironmentVariableSource.SetEnvironment(dict);
            FileSource.SetEnvironment(values);
            EnvironmentVariableRepository.SetConfigurationType(ConfigurationTypeEnum.PreferFile);
            var output = ConfigurationParser.Parse <PreferClass>(EnvironmentVariableRepository);

            Assert.Equal("fromFile", output.Test);
            Assert.Equal("fromFile", output.test);
        }
Пример #11
0
        private static void MainOps(int seed, SpoilerFile spoilerFile, State settings)
        {
            Debug.WriteLine("main ops start");
            while (true)
            {
                try
                {
                    CreateOrRestoreArchiveBackup(Globals.MainPath);
                    var mainSource = new FileSource(Globals.MainPath);

                    // ability shuffle
                    if (settings.GfAbilitiesEnable)
                    {
                        var shuffle = AbilityShuffle.Randomise(mainSource, seed, settings);
                        if (settings.SpoilerFile)
                        {
                            spoilerFile.AddAbilities(shuffle);
                        }
                    }

                    mainSource.Encode();
                    break;
                }
                catch (Exception x)
                {
                    if (x is IOException || x is UnauthorizedAccessException || x is FileNotFoundException)
                    {
                        if (HandleFileException(Globals.MainPath) == false)
                        {
                            break;
                        }
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            Debug.WriteLine("main ops end");
        }
Пример #12
0
        override public bool AddFrame(Stream st)
        {
            long sp = StartPosition + TotalSize;

            System.Console.WriteLine("block écris en " + sp.ToString());
            if (Top.EncodingNeeded(0))
            {
                FileSource.Seek(StartPosition + TotalSize, SeekOrigin.Begin);//on se met la ou on doit ajouter le block encodé



                Top.Encode(st, FileSource, -1, -1);
                BlockMarker(FileSource);//marker de fin de block
                addBlockSize(sp, (FileSource.Position - sp) + 1, 1);
            }
            else
            {
                FileSource.Seek(StartPosition + TotalSize, SeekOrigin.Begin);//on se met la ou on doit ajouter le block encodé

                st.CopyTo(FileSource);
                BlockMarker(FileSource);//marker de fin de block
                addBlockSize(sp, st.Length + 1, 1);
            }
            Console.WriteLine("taille : " + TotalSize.ToString());
            blockCount++;
            if (PredictHit(FileSource) && !Top.MaxBlockCountReach(0, blockCount))
            {
                UpdateHeader(FileSource);
                return(false);//pas de problème
            }
            else
            {
                TerminateBlock(FileSource);
                if (!Top.MaxBlockCountReach(0, blockCount))
                {
                    Console.WriteLine("echec predicteur d=" + Depth + ", on fini avec Totalize=" + TotalSize + "(entre " + FirstFrame + " et " + LastFrame + ")");
                }
                return(true);
            }
        }
Пример #13
0
        public void CheckTokensTypes_FromFile()
        {
            string path = MakeTestFile();

            TokenType[] tokenTypes = new TokenType[] {
                TokenType.INT, TokenType.IDENTIFIER,
                TokenType.PAREN_OPEN, TokenType.PAREN_CLOSE,
                TokenType.BRACE_OPEN, TokenType.INT,
                TokenType.IDENTIFIER, TokenType.ASSIGN,
                TokenType.NUMBER, TokenType.PLUS,
                TokenType.NUMBER, TokenType.SEMICOLON,
                TokenType.BRACE_CLOSE, TokenType.EOT
            };
            using (var source = new FileSource(path)) {
                var scanner = new Scanner(source);
                foreach (var type in tokenTypes)
                {
                    scanner.Next();
                    Assert.Equal(type, scanner.CurrentToken.Type);
                }
            }
        }
Пример #14
0
        public void Corrupt()
        {
            var fs     = new FileSource();
            var buffer = new byte[] { };

            // Vector tiles are compressed.
            fs.Request(
                "https://api.mapbox.com/v4/mapbox.mapbox-streets-v7/0/0/0.vector.pbf",
                (Response res) => {
                buffer = res.Data;
            });

            fs.WaitForAllRequests();

            Assert.Greater(buffer.Length, 30);

            buffer[10] = 0;
            buffer[20] = 0;
            buffer[30] = 0;

            Assert.AreEqual(buffer, Compression.Decompress(buffer));
        }
Пример #15
0
        public void TestByteRecordExtractorCreate()
        {
            string filename = ".unittestfile" + nameof(TestByteRecordExtractorCreate);

            CreateCsvTempFile(filename);

            FileSource source = new FileSource(filename, Path.GetTempPath());

            Assert.Throws <ArgumentNullException>(() => new ArrayRecordExtractor <byte>(null));
            Assert.Throws <ArgumentException>(() => new ArrayRecordExtractor <byte>(new Dictionary <string, long[][]>()
            {
                ["test"] = new long[1][] { new long[] { 1, 2, 3 } }
            }));

            ArrayRecordExtractor <byte> extractor = new ArrayRecordExtractor <byte>(ArrayRecordExtractor <byte> .ParseExtractorParameters("inputs", new[] { 0L }, new[] { 1L }));

            Assert.AreEqual(new[] { "inputs" }, extractor.SectionNames);

            source.Dispose();

            DeleteTempFile(filename);
        }
        public static string SetScenePath(string dataFolderPath, int sourceId)
        {
            if (IsSceneValid(dataFolderPath))
            {
                SceneFile_Source = new FileSource(sourceId, Path.Combine(dataFolderPath, "Stages", CurrentSceneData.Zone, GetSceneFilename(CurrentSceneData.SceneID)));

                return(SceneFile_Source.SourcePath);
            }
            else
            {
                if (File.Exists(ManiacEditor.Methods.Solution.SolutionPaths.CurrentSceneData.FilePath))
                {
                    SceneFile_Source      = new FileSource(-3, ManiacEditor.Methods.Solution.SolutionPaths.CurrentSceneData.FilePath);
                    CurrentSceneData.Zone = Path.GetFileName(CurrentSceneData.SceneDirectory);
                    return(ManiacEditor.Methods.Solution.SolutionPaths.CurrentSceneData.FilePath);
                }
                else
                {
                    throw new Exception(string.Format("Can't Find any scene file related to the following:", ManiacEditor.Methods.Solution.SolutionPaths.CurrentSceneData.FilePath));
                }
            }
        }
Пример #17
0
        /// <summary>检查系统是否启动中,如果启动中,则显示进度条</summary>
        public static void CheckStarting()
        {
            if (SystemStarted)
            {
                return;
            }
            SystemStarted = true;

            if (HttpContext.Current == null)
            {
                return;
            }

            HttpRequest  Request  = HttpContext.Current.Request;
            HttpResponse Response = HttpContext.Current.Response;

            // 在用Flush前用一次Session,避免可能出现的问题
            String sessionid = HttpContext.Current.Session.SessionID;

            // 只处理GET,因为处理POST可能丢失提交的表单数据
            if (Request.HttpMethod != "GET")
            {
                return;
            }

            // 读取资源,输出脚本
            Stream stream = FileSource.GetFileResource(Assembly.GetExecutingAssembly(), "SystemStart.htm");

            if (stream == null || stream.Length <= 0)
            {
                return;
            }

            StreamReader reader = new StreamReader(stream);

            Response.Write(reader.ReadToEnd());
            Response.Flush();
            Response.End();
        }
Пример #18
0
    public void Hotload_CreatedFile()
    {
        CreateFile("derp.yaml", "key: value");

        var fileSource = new FileSource(tempDirPath, hotload: true);

        fileSource.Preload();
        Assert.AreEqual(1, fileSource.AllFiles.Count);

        CreateFile("durr.yaml", "a: b");

        var changedFiles = new List <string>();

        fileSource.Hotload(changedFiles);

        Assert.AreEqual(2, fileSource.AllFiles.Count);

        Assert.IsTrue(fileSource.AllFiles.ContainsKey("derp"));
        Assert.IsTrue(fileSource.AllFiles.ContainsKey("durr"));

        Assert.AreEqual("b", fileSource.AllFiles["durr"].Parsed["a"].StringValue);
    }
Пример #19
0
        public void CheckTokensPositions_FromFile()
        {
            string path = MakeTestFile();

            TextPosition[] positions = new TextPosition[] {
                new TextPosition(3, 1, 18), new TextPosition(3, 5, 22), new TextPosition(3, 9, 26),
                new TextPosition(3, 10, 27), new TextPosition(4, 1, 29), new TextPosition(5, 5, 35),
                new TextPosition(5, 9, 39), new TextPosition(5, 11, 41), new TextPosition(5, 13, 43),
                new TextPosition(5, 15, 45), new TextPosition(5, 17, 47), new TextPosition(5, 18, 48),
                new TextPosition(6, 1, 67), new TextPosition(7, 1, 69),
            };
            using (var source = new FileSource(path)) {
                var scanner = new Scanner(source);
                foreach (var position in positions)
                {
                    scanner.Next();
                    Assert.Equal(position.SourcePosition, scanner.CurrentToken.Position.SourcePosition);
                    Assert.Equal(position.Row, scanner.CurrentToken.Position.Row);
                    Assert.Equal(position.Column, scanner.CurrentToken.Position.Column);
                }
            }
        }
Пример #20
0
        private static void GiveFieldReward(FileSource fieldSource, int encounterID, int opCode, int[] args, string message)
        {
            var boss        = Boss.Encounters[encounterID];
            var fieldPath   = Field.FieldScript.GetFieldPath(boss.FieldID);
            var innerSource = new FileSource(fieldPath, fieldSource);

            // add message
            var msdPath   = Path.Combine(fieldPath, boss.FieldID + Globals.MessageFileExtension);
            var fieldText = MessageFile.FromSource(innerSource, msdPath);
            var msgID     = fieldText.Messages.Count;

            fieldText.Messages.Add(message);

            // give reward
            var field  = Field.FieldScript.FromSource(fieldSource, boss.FieldID);
            var script = field.Entities[boss.FieldEntity].Scripts[boss.FieldScript];
            var index  = script.Instructions.FindLastIndex(i => i.OpCode == Field.FieldScript.OpCodesReverse["battle"]) + 1;

            var awardInstructions = new List <Field.Instruction>();
            var push = Field.FieldScript.OpCodesReverse["pshn_l"];

            foreach (var a in args)
            {
                awardInstructions.Add(new Field.Instruction(push, a));
            }
            awardInstructions.Add(new Field.Instruction(opCode));

            // show message
            awardInstructions.Add(new Field.Instruction(push, 0));
            awardInstructions.Add(new Field.Instruction(push, msgID));
            awardInstructions.Add(new Field.Instruction(push, 70));
            awardInstructions.Add(new Field.Instruction(push, 70));
            awardInstructions.Add(new Field.Instruction(Field.FieldScript.OpCodesReverse["amesw"]));

            // apply changes
            script.Instructions.InsertRange(index, awardInstructions);
            innerSource.ReplaceFile(msdPath, fieldText.Encode());
            innerSource.ReplaceFile(Field.FieldScript.GetFieldPath(boss.FieldID) + "\\" + boss.FieldID + Globals.ScriptFileExtension, field.Encode());
        }
Пример #21
0
        public void Execute(string[] args, IWorker worker)
        {
            var parser = new ArgumentParser(args);

            parser.CheckIfCanBeExecuted();

            if (args[0] == CommandNames.Help)
            {
                ShowHelp(args, worker);
                return;
            }

            var files       = new FileSource().GetFiles(args[1]);
            var commandPool = files.Select(file => new CommandFactory().ChooseCommand(args[0], file, worker, args[2])).ToList();

            if (!commandPool.Any(command => command.IsPlanningCommand()))
            {
                commandPool.ForEach(command => command.Execute());
                return;
            }

            foreach (var command in commandPool)
            {
                try
                {
                    command.Execute();
                    ShowPlan(command, worker);
                }
                catch (Exception e)
                {
                    worker.WriteLine("Command " + command.Accept(new GetCommandNameVisitor())
                                     + "cannot be executed for file" + command.Accept(new GetFilePathVisitor())
                                     + "because of exception:\n" + e.Message);
                }
            }

            SaveChanges(files, worker, args.Contains("--backup-ignore"));
        }
Пример #22
0
        protected override void InitData()
        {
            base.InitData();

            if (Meta.Count > 0)
            {
                return;
            }

            #region 新数据添加
            var tbname = Meta.TableName;
            var cnname = Meta.ConnName;

            // 异步初始化
            ThreadPoolX.QueueUserWorkItem(() =>
            {
                if (XTrace.Debug)
                {
                    XTrace.WriteLine("开始初始化{0}地区数据……", typeof(TEntity).Name);
                }

                // 异步初始化需要注意分表分库的可能
                Meta.ProcessWithSplit(cnname, tbname, () =>
                {
                    using (var sr = new StreamReader(FileSource.GetFileResource(Assembly.GetExecutingAssembly(), "AreaCode.txt")))
                    {
                        Import(sr);
                    }
                    return(null);
                });

                if (XTrace.Debug)
                {
                    XTrace.WriteLine("完成初始化{0}地区数据!", typeof(TEntity).Name);
                }
            });
            #endregion
        }
Пример #23
0
        public static void Apply(FileSource fieldSource, Dictionary <int, int> shuffle)
        {
            var musicOps = new int[] { FieldScript.OpCodesReverse["setbattlemusic"], FieldScript.OpCodesReverse["musicload"] };

            // load list of scripts to search for music changes
            var scripts = MusicLoads.Select(m => new Tuple <string, int, int>(m.FieldName, m.Entity, m.Script)).ToList();

            // add any extra changes from free roam boss clouds
            scripts.AddRange(Boss.Bosses.Where(b => !string.IsNullOrEmpty(b.FieldID)).Select(b => new Tuple <string, int, int>(b.FieldID, b.FieldEntity, b.FieldScript)));

            // remove duplicates
            scripts = scripts.Distinct().ToList();

            // search all these scripts & replace the music IDs with random ones
            foreach (var fieldName in scripts.Select(s => s.Item1).Distinct())
            {
                var field = FieldScript.FromSource(fieldSource, fieldName);

                foreach (var s in scripts.Where(s => s.Item1 == fieldName))
                {
                    var script = field.Entities[s.Item2].Scripts[s.Item3];
                    for (int i = 0; i < script.Instructions.Count; i++)
                    {
                        if (musicOps.Contains(script.Instructions[i].OpCode) && i > 0)
                        {
                            // update the previous instruction (where the track ID is pushed onto the stack)
                            var prevParam = script.Instructions[i - 1].Param;
                            if (shuffle.ContainsKey(prevParam))
                            {
                                field.Entities[s.Item2].Scripts[s.Item3].Instructions[i - 1].Param = shuffle[prevParam];
                            }
                        }
                    }
                }

                field.SaveToSource(fieldSource, fieldName);
            }
        }
Пример #24
0
    public void Hotload_CreatedFile()
    {
        CreateFile("derp.bytes", "key: value");
        CreateFile("index.bytes", "- derp");

        var fs = new FileSource(m_tmpDir, true);

        fs.Preload(() => {});

        CreateFile("durr.bytes", "a: b");
        CreateFile("index.bytes", "- derp\n- durr");

        var index = fs.GetFiles()[0];
        var fi    = fs.TryHotload(index);

        Assert.AreEqual(2, fi.Parsed.Count);

        var files = fs.GetFiles();

        Assert.AreEqual(3, files.Count);
        Assert.AreEqual("durr", files[2].Name);
        Assert.AreEqual("b", files[2].Parsed["a"].StringValue);
    }
Пример #25
0
        public static void Apply(FileSource fieldSource, Dictionary <int, int> shuffle)
        {
            // take a script from the start field
            var scriptField  = "start0";
            var scriptEntity = 0;
            var scriptId     = 0;
            var script       = App.ReadEmbeddedFile(string.Format("FF8Mod.Maelstrom.FieldScripts.{0}.{1}.{2}.txt", scriptField, scriptEntity, scriptId));

            // move cards to their assigned decks
            foreach (var card in shuffle.Keys)
            {
                // if you getcard before you setcard, it reveals the location in the card menu
                // script += Environment.NewLine + GetCard(i);

                script += Environment.NewLine + SetCard(shuffle[card], card);
            }

            // save the script
            var field = FieldScript.FromSource(fieldSource, scriptField);

            field.ReplaceScript(scriptEntity, scriptId, script);
            StorySkip.SaveToSource(fieldSource, scriptField, field.Encode()); // todo: put this somewhere more sensible
        }
Пример #26
0
        public void EditPost_IfModelStateIsInvalid()
        {
            var userId     = 3;
            var fileSource = new FileSource
            {
                PostedFile = new List <HttpPostedFileBase>
                {
                    new Mock <HttpPostedFileBase>().Object
                }
            };
            var person = new PersonWithIUserData
            {
                Id     = ValidId,
                UserId = userId,
                Photos = fileSource
            };

            _personController.ModelState.AddModelError("", "Something is wrong");

            var viewResult = Assert.IsType <ViewResult>(_personController.Edit(person));
            var model      = viewResult.Model as Person;

            Assert.Equal("", viewResult.ViewName);
            Assert.Equal(person, viewResult.Model);
            Assert.Equal("Persons", _personController.ViewBag.Title);
            Assert.Equal("Edit Person", _personController.ViewBag.SubTitle);

            var crumb = (_personController.ViewBag.Crumbs as List <Crumb>).First();

            Assert.Equal("Persons", crumb.Label);
            Assert.Equal("Index", crumb.ActionName);
            Assert.Equal("Persons", crumb.ControllerName);
            Assert.Equal(3, model.Id);
            Assert.Equal("", viewResult.ViewName);

            _fileSourceHelper.Verify(_ => _.LoadFiles(fileSource, false), Times.Once);
        }
Пример #27
0
        public static void Apply(FileSource menuSource, State settings)
        {
            // pull the relevant file out of the archive
            var file      = menuSource.GetFile(ArchivePath);
            var mes3bytes = file.Skip(FileOffset).Take(FileLength);
            var mes3      = TextFile.FromBytes(mes3bytes, true);

            // set names
            mes3.Pages[NamesPage].Strings[Squall]    = settings.NameSquall;
            mes3.Pages[NamesPage].Strings[Rinoa]     = settings.NameRinoa;
            mes3.Pages[NamesPage].Strings[Angelo]    = settings.NameAngelo;
            mes3.Pages[NamesPage].Strings[Quezacotl] = settings.NameQuezacotl;
            mes3.Pages[NamesPage].Strings[Shiva]     = settings.NameShiva;
            mes3.Pages[NamesPage].Strings[Ifrit]     = settings.NameIfrit;
            mes3.Pages[NamesPage].Strings[Siren]     = settings.NameSiren;
            mes3.Pages[NamesPage].Strings[Brothers]  = settings.NameBrothers;
            mes3.Pages[NamesPage].Strings[Diablos]   = settings.NameDiablos;
            mes3.Pages[NamesPage].Strings[Carbuncle] = settings.NameCarbuncle;
            mes3.Pages[NamesPage].Strings[Leviathan] = settings.NameLeviathan;
            mes3.Pages[NamesPage].Strings[Pandemona] = settings.NamePandemona;
            mes3.Pages[NamesPage].Strings[Cerberus]  = settings.NameCerberus;
            mes3.Pages[NamesPage].Strings[Alexander] = settings.NameAlexander;
            mes3.Pages[NamesPage].Strings[Doomtrain] = settings.NameDoomtrain;
            mes3.Pages[NamesPage].Strings[Bahamut]   = settings.NameBahamut;
            mes3.Pages[NamesPage].Strings[Cactuar]   = settings.NameCactuar;
            mes3.Pages[NamesPage].Strings[Tonberry]  = settings.NameTonberry;
            mes3.Pages[NamesPage].Strings[Eden]      = settings.NameEden;
            mes3.Pages[NamesPage].Strings[Boko]      = settings.NameBoko;
            mes3.Pages[NamesPage].Strings[Griever]   = settings.NameGriever;

            // apply changes
            var newFile = file.Take(FileOffset).ToList();

            newFile.AddRange(mes3.Encode());
            newFile.AddRange(file.Skip(FileOffset + FileLength));
            menuSource.ReplaceFile(ArchivePath, newFile);
        }
Пример #28
0
        public void TestMinibatchIteratorYield(int minibatchSize)
        {
            string filename = ".unittestfile" + nameof(TestMinibatchIteratorYield);

            CreateCsvTempFile(filename);
            SigmaEnvironment.Clear();

            FileSource         source    = new FileSource(filename, Path.GetTempPath());
            CsvRecordExtractor extractor = (CsvRecordExtractor) new CsvRecordReader(source).Extractor(new CsvRecordExtractor(new Dictionary <string, int[][]> {
                ["inputs"] = new[] { new[] { 0 } }
            }));
            ExtractedDataset    dataset  = new ExtractedDataset("test", 1, new DiskCacheProvider(Path.GetTempPath() + "/" + nameof(TestMinibatchIteratorYield)), true, extractor);
            MinibatchIterator   iterator = new MinibatchIterator(minibatchSize, dataset);
            IComputationHandler handler  = new CpuFloat32Handler();
            SigmaEnvironment    sigma    = SigmaEnvironment.Create("test");

            Assert.Throws <ArgumentNullException>(() => iterator.Yield(null, null).GetEnumerator().MoveNext());
            Assert.Throws <ArgumentNullException>(() => iterator.Yield(handler, null).GetEnumerator().MoveNext());
            Assert.Throws <ArgumentNullException>(() => iterator.Yield(null, sigma).GetEnumerator().MoveNext());

            int index = 0;

            foreach (var block in iterator.Yield(handler, sigma))
            {
                //pass through each more than 5 times to ensure consistency
                if (index++ > 20)
                {
                    break;
                }

                Assert.Contains(block["inputs"].GetValue <float>(0, 0, 0), new float[] { 5.1f, 4.9f, 4.7f });
            }

            dataset.Dispose();

            DeleteTempFile(filename);
        }
Пример #29
0
        public static ExcelPackage GetExcelPackageSource(string excelFile, FileSource source)
        {
            ExcelPackage package;

            switch (source)
            {
            case FileSource.FileSystem:
            {
                package = new ExcelPackage(new FileInfo(excelFile));
                break;
            }

            case FileSource.OneDrive:
            {
                package = new ExcelPackage(GraphHelper.GetFileAsync(excelFile).Result);
                break;
            }

            default:
                throw new ArgumentOutOfRangeException($"Source {source} is not implemented!");
            }

            return(package);
        }
Пример #30
0
        private async void ImportPdf_Click(object sender, RoutedEventArgs e)
        {
            if (note.IsPdfPresent)
            {
                MessageDialogResult result = await this.ShowMessageAsync(
                    "You have already imported a PDF file!",
                    "You will loose currently imported PDF file from your note. Do you want to continue?",
                    MessageDialogStyle.AffirmativeAndNegative);

                if (result != MessageDialogResult.Affirmative)
                {
                    return;
                }
            }

            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Filter = "PDF Files (.pdf)|*.pdf";
            if (dialog.ShowDialog() == true)
            {
                fs = new FileSource(dialog.FileName);
                note.AddPdf(fs);
            }
        }
Пример #31
0
        public void TestCsvRecordExtractorExtract()
        {
            string filename = ".unittestfile" + nameof(TestCsvRecordExtractorCreate);

            CreateCsvTempFile(filename);

            FileSource         source    = new FileSource(filename, Path.GetTempPath());
            CsvRecordExtractor extractor = (CsvRecordExtractor) new CsvRecordReader(source).Extractor(new CsvRecordExtractor(new Dictionary <string, IList <int> > {
                ["inputs"] = new[] { 0, 1, 2 }
            }));

            Assert.Throws <InvalidOperationException>(() => extractor.ExtractDirect(3, new CpuFloat32Handler()));

            extractor.Prepare();

            Assert.Throws <ArgumentNullException>(() => extractor.ExtractDirect(3, null));
            Assert.Throws <ArgumentException>(() => extractor.ExtractDirect(-1, new CpuFloat32Handler()));

            Assert.AreEqual(5, extractor.ExtractDirect(3, new CpuFloat32Handler())["inputs"].GetValue <int>(0, 0, 0));

            source.Dispose();

            DeleteTempFile(filename);
        }
Пример #32
0
        static void Main(string[] args)
        {
            // if (args.Length <= 0) {
            //     System.Console.WriteLine("fatal error: no input files");
            //     return;
            // }
            string name = "../UnitTests/TestFiles/correctfile3.ml"; //args[0];

            using (var source = new FileSource(name)) {
                try {
                    var scanner = new Scanner(source);
                    var parser  = new Parser.Parser(scanner);
                    var program = parser.Parse();
                    program.Execute();
                }
                catch (LexerException e) {
                    System.Console.WriteLine(e.Message);
                }
                catch (UnexpectedToken e) {
                    var sb = new StringBuilder(e.Message);
                    sb.Append(" at line: "); sb.Append(e.Position.Row);
                    sb.Append(", column: "); sb.Append(e.Position.Column);
                    sb.Append("\nSource:\n"); sb.Append(source.GetLineFromPosition(e.Position));
                    sb.Append("\n");
                    for (int i = 1; i < e.Position.Column; ++i)
                    {
                        sb.Append(" ");
                    }
                    sb.Append("^");
                    System.Console.WriteLine(sb.ToString());
                }
                catch (ExecutionException e) {
                    System.Console.WriteLine(e.Message);
                }
            }
        }
Пример #33
0
        public void Retrieve(Func <string> skuToken, string accessToken, Action <MapboxToken> callback)
        {
            if (_fs == null)
            {
                _fs = new FileSource(skuToken);
            }

            _fs.Request(
                Utils.Constants.BaseAPI + "tokens/v2?access_token=" + accessToken,
                (Response response) =>
            {
                if (response.HasError)
                {
                    callback(new MapboxToken()
                    {
                        HasError     = true,
                        ErrorMessage = response.ExceptionsAsString
                    });
                    return;
                }
                callback(MapboxToken.FromResponseData(response.Data));
            }
                );
        }
Пример #34
0
        /// <summary>
        ///     Creates a <see cref="CsvTableDataLoaderFactory" /> instance.
        /// </summary>
        /// <returns>
        ///     A <see cref="CsvTableDataLoaderFactory" /> instance.
        /// </returns>
        public ITableDataLoaderFactory CreateTableDataLoaderFactory()
        {
            FileSource source = new FileSource(this.path);

            return new CsvTableDataLoaderFactory(source);
        }
Пример #35
0
        public DirectoryInfo GetDir(string path, FileSource source = FileSource.All, int remainingdepth = -1)
        {
            if(remainingdepth == -1)
                remainingdepth = DirInfoMaxRecursionDepth;
            var result = new DirectoryInfo
            {
                Subdirectories = new List<DirectoryInfo>(),
                Files = new List<string>(),
                Name = String.IsNullOrWhiteSpace(path) ? "<>" : Path.GetFileName(path)
            };

            if(source.HasFlag(FileSource.LocalUserData) && !Path.IsPathRooted(path))
            {
                string userdatapath = Path.Combine(DataFolder, path);
                if (Directory.Exists(userdatapath))
                {
                    if (remainingdepth > 0)
                        foreach (string directory in Directory.GetDirectories(userdatapath))
                        {
                            var dirinfo = GetDir(directory, FileSource.Local, remainingdepth - 1); //Iterate as local since it's now a complete Path
                            result.Subdirectories.Add(dirinfo);
                        }
                    result.Files.AddRange(Directory.GetFiles(userdatapath).Select(Path.GetFileName));
                }
            }

            if (source.HasFlag(FileSource.Local))
            {
                string localpath = Path.IsPathRooted(path) ? path : Path.Combine(Environment.CurrentDirectory, path);
                if (Directory.Exists(localpath))
                {
                    if (remainingdepth > 0)
                        foreach (string directory in Directory.GetDirectories(localpath))
                            result.Subdirectories.Add(GetDir(directory, FileSource.Local, remainingdepth - 1));
                    result.Files.AddRange(Directory.GetFiles(localpath).Select(Path.GetFileName));
                }
            }

            //ToDo: Iterate on compressed FS and network FS

            return RemoveDoubleFiles(result);
        }
Пример #36
0
 public void DownloadFile( Resource resource, string path, FileSource source, string _connectionId = null )
 {
     Rest.DownloadStream( path, _connectionId ).ContinueWith( stream =>
     {
         Log.Out( "FileStore", string.Format( "Finished download for {0}", resource.Name ), LogCode.Log );
         AddFile( resource, stream.Result, source );
     } );
     Log.Out( "FileStore", string.Format( "Started download for {0}", resource.Name ), LogCode.Log );
 }
Пример #37
0
 public void AddFile( Resource resource, Stream stream, FileSource source )
 {
     AddFile( resource, GetBytesFromStream( resource, stream ), source );
 }
Пример #38
0
        public void Start(string filePath, int blockSize, int blockCount)
        {
            var fileStream = System.IO.File.Open(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read);
            var blockSource = new ByteStreamToBlock(fileStream, blockSize);
            var circb = new CircularBuffer<byte[]>((int)Math.Log(blockCount, 2));
            var buffer = new RefillBuffer<byte[]>(circb, blockSource, 1);
            buffer.Start();

            src = new FileSource(buffer, 0);
            var docType = new DocTypeEBML(new DocTypeMatroskaV2());
            var reader = new EBMLReader(src, docType);

            //while(circb.ProducerCanWrite() && fileStream.Position != fileStream.Length) Thread.Sleep(20);

            (new Thread(Speed)).Start();
            SpeedRecurse(reader);
            finished = true;
        }
Пример #39
0
        string GettingHashSHA1ForAnyFile(string filePath, FileSource FileOption)
        {
            Byte[] shaHash;
            string base64Hash;

            using (System.IO.Stream stream = System.IO.File.OpenRead(filePath))
            {
                shaHash = System.Security.Cryptography.SHA1.Create().ComputeHash(stream);
            }

            base64Hash = Convert.ToBase64String(shaHash);
            if (FileOption == FileSource.File1) _hashFile1 = base64Hash; else _hashFile2 = base64Hash;

            return base64Hash;
        }
Пример #40
0
        public void UpdateFile( Resource resource, byte[] fileInBytes, FileSource source )
        {
            SaveToDisk( fileInBytes, resource );
            _files[ resource.Id ] = resource;

            switch ( source )
            {
                case FileSource.ActivityManager:
                    if ( FileChanged != null )
                        FileChanged( this, new FileEventArgs( resource ) );
                    break;
            }
            Log.Out( "FileStore", string.Format( "Updated file {0} to store", resource.Name ), LogCode.Log );
        }
Пример #41
0
 public void UpdateFile( Resource resource, Stream stream, FileSource source )
 {
     UpdateFile( resource, GetBytesFromStream( resource, stream ), source );
 }
Пример #42
0
          //for Laconfig we dont need to adjust names as the are properly escaped
          //protected override string AdjustNodeName(string name)
          //{   
             
          //}
    
       #endregion

       #region .pvt
            private void readFromFile()
            {
              using(var fsrc = new FileSource(m_FileName))
                  read(fsrc);
            }
Пример #43
0
        string FindFile(FileSource FileOption)
        {
            string result = string.Empty;
            int size = -1;
            //this.imgLst.Images.Clear();
            _fileOption = FileOption;

            ofDialog1.FileName = String.Empty;
            ofDialog1.Title = _fileOption == FileSource.File1 ? "Buscar Archivo #1" : "Buscar Archivo #2";

            DialogResult openFileResult = ofDialog1.ShowDialog();
            try
            {
                if (openFileResult == System.Windows.Forms.DialogResult.OK)
                {
                    result = ofDialog1.FileName;
                    result = (new System.IO.FileInfo(ofDialog1.FileName)).Directory.ToString();
                    GettingHashSHA1ForAnyFile(ofDialog1.FileName, _fileOption);
                    DisplayItems(ofDialog1.FileName);
                    size = 0;
                }
            }
            catch (Exception)
            {

                throw;
            }

            return result;
        }
Пример #44
0
 public TokenizerContext(FileSource file)
 {
     File = file;
 }
Пример #45
0
 public DownloadState( Resource resource, FileSource fileSource )
 {
     Resource = resource;
     FileSource = fileSource;
 }
Пример #46
0
        void DetectFileTypes()
        {
            string fn = VirtualBoxPath + @"\VBoxDD.dll";
            if (!File.Exists(fn))
                _VBoxDD = FileSource.Missing;
            else
            {
                try
                {
                    using (FileStream fs = new FileStream(fn, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                    {
                        bool sizeMatch = (fs.Length < FileSizeThreshold);
                        if (fs.Length > 50 * 1024 * 1024)
                            _VBoxDD = FileSource.Unknown;
                        else
                        {
                            byte[] data = new byte[fs.Length];
                            if (fs.Read(data, 0, (int)fs.Length) != (int)fs.Length)
                                _VBoxDD = FileSource.Unknown;
                            else
                            {
                                bool foundSig1 = find(data, Encoding.ASCII.GetBytes("~kdVMvA"));
                                bool foundSig2 = find(data, Encoding.ASCII.GetBytes("++kdVMvA"));

                                if ((foundSig1 != foundSig2) || (foundSig1 != sizeMatch))
                                    _VBoxDD = FileSource.Unknown;
                                else
                                    _VBoxDD = sizeMatch ? FileSource.VirtualKD : FileSource.VirtualBox;
                            }

                        }
                    }

                }
                catch (System.Exception)
                {
                    _VBoxDD = FileSource.Unknown;
                }
            }

            fn = VirtualBoxPath + @"\VBoxDD0.dll";
            if (!File.Exists(fn))
                _VBoxDD0 = FileSource.Missing;
            else
            {
                try
                {
                    using (FileStream fs = new FileStream(fn, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                    {
                        bool sizeMatch = (fs.Length < FileSizeThreshold);
                        _VBoxDD0 = sizeMatch ? FileSource.Unknown : FileSource.VirtualBox;
                    }

                }
                catch (System.Exception)
                {
                    _VBoxDD0 = FileSource.Unknown;
                }
            }
        }
Пример #47
0
        public static string [] GetFiles (FileSource source, string path = "")
		{
			var files = new string[0];

			if (source == FileSource.Directory)
				files = Directory.GetFiles (path);
			else if (source == FileSource.CurrentDirectory)
				files = Directory.GetFiles (Directory.GetCurrentDirectory());
			else if (source == FileSource.EnvironmentVariable)
				files = Directory.GetFiles (Environment.GetEnvironmentVariable (path));
			else if (source == FileSource.NautilusSelection)
				files = Nautilus.SelectedFiles;
			else if (source == FileSource.NautilusCurrentDirectory)
				files = Directory.GetFiles (Nautilus.CurrentDirectory);
			else if (source == FileSource.Nautilus)
				files = (Nautilus.IsNothingSelected)? Directory.GetFiles (Nautilus.CurrentDirectory) : Nautilus.SelectedFiles;

			// TODO: Realize commandline

			return files;
		}
Пример #48
0
		/// <summary>
		/// Add files using the multipart content-type
		/// </summary>
		/// <param name="fileName">The file name and extension</param>
		/// <param name="fileType">The file type</param>
		/// <param name="folderId">The id of the folder</param>
		/// <param name="description">The description of the file</param>
		/// <param name="source">The source of the original file</param>
		/// <param name="data">The data contained in the file being uploaded</param>
		/// <returns>Returns the file Id associated with the uploaded file</returns>
		public string AddLibraryFilesMultipart(string fileName, FileType fileType, string folderId, string description, FileSource source, byte[] data)
		{
			if(string.IsNullOrEmpty(fileName))
			{
				throw new IllegalArgumentException(Config.Errors.FileNameNull);
			}

			var extension = Path.GetExtension(fileName).ToLowerInvariant();
			string[] fileTypes = new string[5] { ".jpeg", ".jpg", ".gif", ".png", ".pdf" };

			if (!((IList<string>)fileTypes).Contains(extension))
			{
			    throw new IllegalArgumentException(Config.Errors.FileTypeInvalid);
			}

			if(string.IsNullOrEmpty(folderId) || string.IsNullOrEmpty(description))
			{
				throw new IllegalArgumentException(Config.Errors.FieldNull);
			}

			if(data == null)
			{
				throw new IllegalArgumentException(Config.Errors.FileNull);
			}

			return MyLibraryService.AddLibraryFilesMultipart(this.AccessToken, this.APIKey, fileName, fileType, folderId, description, source, data);
		}
Пример #49
0
		/// <summary>
		/// Add files using the multipart content-type
		/// </summary>
		/// <param name="accessToken">Access token.</param>
        /// <param name="apiKey">The API key for the application</param>
		/// <param name="fileName">The file name and extension</param>
		/// <param name="fileType">The file type</param>
		/// <param name="folderId">The id of the folder</param>
		/// <param name="description">The description of the file</param>
		/// <param name="source">The source of the original file</param>
		/// <param name="data">The data contained in the file being uploaded</param>
		/// <returns>Returns the file Id associated with the uploaded file</returns>
		public string AddLibraryFilesMultipart(string accessToken, string apiKey, string fileName, FileType fileType, string folderId, string description, FileSource source, byte[] data)
		{
			string result = null;
			string url = String.Concat(Config.Endpoints.BaseUrl, Config.Endpoints.MyLibraryFiles);
			byte[] content = MultipartBuilder.CreateMultipartContent(fileName, data, null, fileType.ToString(), folderId, description, source.ToString());
			CUrlResponse response = RestClient.PostMultipart(url, accessToken, apiKey, content);

            if (response.IsError)
            {
                throw new CtctException(response.GetErrorMessage());
            }

			if(!response.IsError && response.StatusCode == System.Net.HttpStatusCode.Accepted)
			{
				string location = response.Headers["Location"];
				int idStart = location.LastIndexOf("/") + 1;
				result = location.Substring(idStart);
			}

			return result;
		}
Пример #50
0
 void UpdateFileSource()
 {
     fs             = fs ?? new FileSource(this);
     fs.AccessToken = Token;
 }
Пример #51
0
		/// <summary>
		/// Add files using the multipart content-type
		/// </summary>
		/// <param name="fileName">The file name and extension</param>
		/// <param name="fileType">The file type</param>
		/// <param name="folderId">The id of the folder</param>
		/// <param name="description">The description of the file</param>
		/// <param name="source">The source of the original file</param>
		/// <param name="data">The data contained in the file being uploaded</param>
		/// <returns>Returns the file Id associated with the uploaded file</returns>
		public string AddLibraryFilesMultipart(string fileName, FileType fileType, string folderId, string description, FileSource source, byte[] data)
		{
            if (string.IsNullOrEmpty(fileName))
            {
                throw new IllegalArgumentException(CTCT.Resources.Errors.FileNameNull);
            }

            var extension = Path.GetExtension(fileName).ToLowerInvariant();
            string[] fileTypes = new string[5] { ".jpeg", ".jpg", ".gif", ".png", ".pdf" };

            if (!((IList<string>)fileTypes).Contains(extension))
            {
                throw new IllegalArgumentException(CTCT.Resources.Errors.FileTypeInvalid);
            }

            if (string.IsNullOrEmpty(folderId) || string.IsNullOrEmpty(description))
            {
                throw new IllegalArgumentException(CTCT.Resources.Errors.FieldNull);
            }

            if (data == null)
            {
                throw new IllegalArgumentException(CTCT.Resources.Errors.FileNull);
            }

			string result = null;
			string url = String.Concat(Settings.Endpoints.Default.BaseUrl, Settings.Endpoints.Default.MyLibraryFiles);
			byte[] content = MultipartBuilder.CreateMultipartContent(fileName, data, null, fileType.ToString(), folderId, description, source.ToString());
            RawApiResponse response = RestClient.PostMultipart(url, UserServiceContext.AccessToken, UserServiceContext.ApiKey, content);

            if (response.IsError)
            {
                throw new CtctException(response.GetErrorMessage());
            }

			if(!response.IsError && response.StatusCode == System.Net.HttpStatusCode.Accepted)
			{
				string location = response.Headers["Location"];
				int idStart = location.LastIndexOf("/") + 1;
				result = location.Substring(idStart);
			}

			return result;
		}