Ejemplo n.º 1
0
        /// <summary>
        /// Read file at path, split the contents in chunks and store them together with a StreamChunk.
        /// </summary>
        public static ChunkHash GenerateChunk(string path, Repo repo)
        {
            StreamChunk message = new StreamChunk ();

            using (Stream stream = new FileStream(path, FileMode.Open)) {
                BinaryReader br = new BinaryReader (stream);

                message.Size = (ulong)stream.Length;

                while (true) {
                    byte[] data = br.ReadBytes (4096);
                    if (data.Length == 0)
                        break;

                    Chunk c = new Chunk (data);
                    ChunkHash ch = repo.WriteChunk (c);

                    message.Chunks.Add (ch.bytes);
                }
            }

            byte[] messageBytes = StreamChunk.SerializeToBytes (message);
            Chunk messageChunk = new Chunk (messageBytes);
            ChunkHash messageHash = repo.WriteChunk (messageChunk);

            return messageHash;
        }
Ejemplo n.º 2
0
 public static void Run(Repo localRepo)
 {
     Stream stdin = Console.OpenStandardInput ();
     Stream stdout = Console.OpenStandardOutput ();
     PipeServer s = new PipeServer (stdin, stdout, localRepo);
     s.Run ();
 }
Ejemplo n.º 3
0
        public static ChunkHash GenerateChunk(string path, Repo repo)
        {
            string fullPath = Path.GetFullPath (path);
            TreeChunk tree = new TreeChunk ();

            //Subdirectories
            string[] dirs = Directory.GetDirectories (fullPath);
            foreach (string d in dirs) {
                TreeFile df = new TreeFile ();
                df.Name = Path.GetFileName (d);
                df.TreeChunkHash = TreeChunk.GenerateChunk (d, repo).bytes;
                tree.Directories.Add (df);
            }

            //Files
            string[] files = Directory.GetFiles (fullPath);
            foreach (string f in files) {
                TreeFile ff = new TreeFile ();
                ff.Name = Path.GetFileName (f);
                ff.TreeChunkHash = StreamChunk.GenerateChunk (f, repo).bytes;
                tree.Files.Add (ff);
            }

            Chunk treeChunk = new Chunk (TreeChunk.SerializeToBytes (tree));
            ChunkHash ch = repo.WriteChunk (treeChunk);

            return ch;
        }
        private static void OneSide(Repo repo, SyntaxTree local, SyntaxTree remote, SyntaxTree ancestor, string path)
        {
            //Fake a call te to GetRemoteChange() by placeing the remote and ancestor trees into the RemoteChangesData list
            repo.PullRequests.Clear();
            repo.PullRequests.Add(new PullRequest
            {
                Updated = DateTime.Now,
                Files = new[] { new Core.RepoFile {
                    BaseTree = ancestor,
                    HeadTree = remote,
                    Filename = path,
                    Status = RepoFile.StatusEnum.Modified,
                } },
                Title = "Fake Pull Request",
                Url = "http://github.com/example/repo",
                Number = 1,
                State = "open",
                LastWrite = DateTime.MinValue,
                Base = new PullRequest.HeadBase { Sha = "" },
                Head = new PullRequest.HeadBase { Sha = "" },
            });
            var pr = repo.PullRequests.First();
            pr.ParentRepo = repo;
            pr.ValidFiles.First().ParentPullRequst = pr;

            var res = Analysis.ForFalsePositive(repo, local);
            Assert.IsTrue(res.Any());
        }
Ejemplo n.º 5
0
        public static void Load(Repo repo)
        {
            var nasajpl = new FlickrUser { User = "******" };
            repo.Insert (nasajpl);

            repo.Insert (new TwitterSearch { Search = "nasa" });
        }
Ejemplo n.º 6
0
        public static IEnumerable<string> Update(Repo[] repos, Ref[] allNewRefs)
        {
            Dictionary<Repo, Ref[]> updates = new Dictionary<Repo, Ref[]>();
            var oldRefs = repos.SelectMany(r => r.Refs).ToArray();

            foreach (var repo in repos)
            {
                var newRefs = allNewRefs.Where(r => r.Alias == repo.Alias).ToArray();
                updates[repo] = newRefs;

                foreach (var r in newRefs)
                {
                    /* determine what happened */
                    var existingRef = repo.Refs.FirstOrDefault(q => q.Name == r.Name);
                    if (existingRef != null && existingRef.Sha == r.Sha)
                        continue;

                    yield return CharacterizeChange(existingRef, r, oldRefs);
                }

                foreach (var q in repo.Refs)
                    if (!newRefs.Any(r => r.Name == q.Name))
                        yield return CharacterizeChange(q, null, oldRefs);
            }

            foreach (var repo in repos)
                repo.Refs = updates[repo];
        }
 public void TestInsert()
 {
     var repo = new Repo<Country>(new DbContextFactory());
     var country = new Country { Name = "testCountry" };
     country = repo.Insert(country);
     repo.Save();
     var country1 = repo.Get(country.Id);
     Assert.AreEqual(country.Name, country1.Name);
 }
Ejemplo n.º 8
0
 public static void TestInsert()
 {
     var r = new Repo<Country>(new DbContextFactory());
     var c = new Country {Name = "Asaaa"};
     r.Insert(c);
     r.Save();
     var o = r.Get(c.Id);
     Assert.AreEqual(c.Name, o.Name);
 }
Ejemplo n.º 9
0
        public static void ReserveRoom(string person, string roomNumber, DateTime enterTime, DateTime leaveTime)
        {
            dynamic repo = new Repo();

            dynamic room = repo.GetRoomByNumber(roomNumber);
            dynamic customer = repo.GetPerson(person);
            if (customer == null)
            {
                customer = repo.AddPerson(person);
            }
            room.Reserve(customer, enterTime, leaveTime);
        }
Ejemplo n.º 10
0
        public static void LoadTest(Repo repo)
        {
            Load(repo);

            repo.Insert(new Blog() { Url = "http://life-with-aspergers.blogspot.com/feeds/posts/default" });

            repo.Insert(new Podcast() { Url = "blog.stackoverflow.com" });
            repo.Insert(new Podcast() { Url = "noagendashow.com" });

            repo.Insert(new FlickrTags() { Tags = "star trek" });

            repo.Insert(new CraigslistForSale() { Search = "bike", List="seattle", MinPrice=100, MaxPrice=200 });
        }
        public static void TestRemove()
        {
            var repo = new Repo<Country>(new DbContextFactory());
            var country = new Country { Name = "testCountry" };
            country = repo.Insert(country);
            repo.Save();

            repo.Delete(country);
            repo.Save();

            var country1 = repo.Get(country.Id);
            Assert.IsTrue(country1.IsDeleted);
        }
Ejemplo n.º 12
0
        public static void TestRemove()
        {
            var r = new Repo<Country>(new DbContextFactory());
            var c = new Country {Name = "a"};
            r.Insert(c);
            r.Save();

            r.Delete(c);
            r.Save();

            var o = r.Get(c.Id);
            Assert.IsTrue(o.IsDeleted);
        }
Ejemplo n.º 13
0
        static void Main(string[] args)
        {
            Console.WriteLine("***\r\nBegin program - WITH logging\r\n");
            IRepository<Customer> customerRepo = new Repo<Customer>();
            IRepository<Customer> loggerRepo = new LoggerRepository<Customer>(customerRepo);

            var customer = new Customer { Id = 1, Name = "Tero Testaaja", Address = "Testikatu 1" };
            loggerRepo.Add(customer);
            loggerRepo.Update(customer);
            loggerRepo.Delete(customer);

            Console.WriteLine("\r\nEnd program - WITH logging\r\n***");
            Console.ReadLine();
        }
Ejemplo n.º 14
0
        public static void Extract(Repo store, ChunkHash cid, string targetPath)
        {
            Directory.CreateDirectory (targetPath);

            Chunk c = store.ReadChunk (cid);
            TreeChunk tree = TreeChunk.Deserialize (c.Data);

            foreach (TreeFile file in tree.Files) {
                StreamChunk.Extract (store, ChunkHash.FromHashBytes (file.TreeChunkHash), Path.Combine (targetPath, file.Name));
            }

            foreach (TreeFile subdir in tree.Directories) {
                TreeChunk.Extract (store, ChunkHash.FromHashBytes (subdir.TreeChunkHash), Path.Combine (targetPath, subdir.Name));
            }
        }
Ejemplo n.º 15
0
        public static void Extract(Repo store, ChunkHash fileHash, string targetPath)
        {
            Chunk chunk = store.ReadChunk (fileHash);
            StreamChunk streamChunk = StreamChunk.Deserialize<StreamChunk> (chunk.Data);

            using (FileStream file = File.Open(targetPath, FileMode.Create)) {
                foreach (byte[] hashBytes in streamChunk.Chunks) {
                    Chunk fc = store.ReadChunk (ChunkHash.FromHashBytes (hashBytes));
                    file.Write (fc.Data, 0, fc.Data.Length);
                }

                //Verify length
                if (file.Length != (long)streamChunk.Size)
                    throw new InvalidDataException ("Invalid file length");
            }
        }
Ejemplo n.º 16
0
        public void IntsToEntities()
        {
            WindsorRegistrar.RegisterSingleton(typeof(IRepo<>), typeof(Repo<>));
            WindsorRegistrar.RegisterSingleton(typeof(IDbContextFactory), typeof(DbContextFactory));
            using (var scope = new TransactionScope())
            {
                var repo = new Repo<cm.Product>(new DbContextFactory());
                var product1 = new cm.Product { Name = "a" };
                var product2 = new cm.Product { Name = "b" };

                product1 = repo.Insert(product1);
                product2 = repo.Insert(product2);
                repo.Save();

                var promotionInput = new PromotionInput { Products = new List<int> { product1.Id, product2.Id } };
                var promotion = new cm.Promotion();

                promotion.InjectFrom<IntsToEntities>(promotionInput);

                Assert.IsNotNull(promotion.Products);
                Assert.AreEqual(2, promotion.Products.Count);
                Assert.AreEqual(product1.Id, promotion.Products.First().Id);
            }
        }
        public void IntsToEntities()
        {
            WindsorRegistrar.RegisterSingleton(typeof(IRepo<>), typeof(Repo<>));
            WindsorRegistrar.RegisterSingleton(typeof(IDbContextFactory), typeof(DbContextFactory));
            using (var scope = new TransactionScope())
            {
                var repo = new Repo<Meal>(new DbContextFactory());
                var meal1 = new Meal { Name = "a" };
                var meal2 = new Meal { Name = "b" };

                meal1 = repo.Insert(meal1);
                meal2 = repo.Insert(meal2);
                repo.Save();

                var dinnerInput = new DinnerInput { Meals = new List<int> { meal1.Id, meal2.Id } };
                var dinner = new Dinner();

                dinner.InjectFrom<IntsToEntities>(dinnerInput);

                Assert.IsNotNull(dinner.Meals);
                Assert.AreEqual(2, dinner.Meals.Count);
                Assert.AreEqual(meal1.Id, dinner.Meals.First().Id);
            }
        }
Ejemplo n.º 18
0
 public IActionResult GetPreferences() =>
 Repo
 .GetPreferences()
 .ToActionResult(x => ToGetPrefReply(x));
Ejemplo n.º 19
0
        public void OneTest()
        {
            Repo reposit = new Repo();

            reposit.BuildDataList();
        }
Ejemplo n.º 20
0
 public void TypeOfToList()
 {
     var meta  = Repo.GetTypeMeta <Pages>();
     var pages = Repo.TypeOf <Pages>().ToList();
 }
Ejemplo n.º 21
0
 protected TreeBaseViewModel(Repo repo) : base(repo)
 {
 }
Ejemplo n.º 22
0
 public IActionResult Create(OrgRequest r) =>
 Repo
 .Create(r.ToModel())
 .ToActionResult(x => new { x.Value.Id, Message = "Organization created" });
Ejemplo n.º 23
0
 public IActionResult Update(int orgId, OrgRequest r) =>
 Repo
 .Update(r.ToModel(orgId))
 .RefreshToken(ActualUser)
 .ToActionResult(x => new { Message = "Organization updated", x.Value.Bag.Token });
Ejemplo n.º 24
0
 public JawboneController(Repo.Interfaces.IJawboneRepository repo)
 {
     _repo = repo;
 }
Ejemplo n.º 25
0
 public IActionResult AddMember(int orgId, OrgMembersRequest r) =>
 Repo
 .AddMember(orgId, r.LoginOrEmail, r.Role)
 .RevokeToken()
 .ToActionResult(x => new { Message = "User added to organization" });
Ejemplo n.º 26
0
 public IActionResult UpdateMember(int orgId, int userId, OrgMemberUpdateRequest r) =>
 Repo
 .UpdateMember(orgId, userId, r.Role.Value)
 .RevokeToken()
 .ToActionResult(x => new { Message = "Organization user updated" });
        public PartialViewResult Add(int siteID)
        {
            var r = Repo.Add(siteID);

            return(PartialView("View", r));
        }
Ejemplo n.º 28
0
        public void Copy_SourceDoesNotExist_ThrowsMercurialExecutionException()
        {
            Repo.Init();

            Assert.Throws <MercurialExecutionException>(() => Repo.Copy("test1.txt", "test2.txt"));
        }
Ejemplo n.º 29
0
 public void Copy_NoRepository_ThrowsMercurialExecutionException()
 {
     Assert.Throws <MercurialExecutionException>(() => Repo.Copy("test1.txt", "test2.txt"));
 }
Ejemplo n.º 30
0
 public IActionResult UpdatePreferences(OrgPreferencesRequest r) =>
 Repo
 .UpdatePreferences(r.ToModel(ActualUser.OrgId))
 .RefreshPreferences(ActualUser, DataContext)
 .RefreshToken(true)
 .ToActionResult(x => new { Message = "Preferences updated", x.Value.Bag.Token });
Ejemplo n.º 31
0
 public IActionResult GetMembersLookup() =>
 Repo
 .GetMembers(ActualUser.OrgId)
 .ToActionResult(x => ToMembersLookupReply(x));
Ejemplo n.º 32
0
 public IActionResult GetMembers(int orgId) =>
 Repo
 .GetMembers(orgId)
 .ToActionResult(x => ToMembersReply(x, orgId));
Ejemplo n.º 33
0
 public PipeServer(Stream sin, Stream sout, Repo localRepo)
 {
     this.input = sin;
     this.output = sout;
     this.localRepo = localRepo;
 }
Ejemplo n.º 34
0
 public IQueryable <Category> GetAll()
 {
     return(Repo.GetAll <Category>());
 }
Ejemplo n.º 35
0
 public OpenPgpRepo(Repo backendRepo)
     : base(backendRepo)
 {
     this.Recipients = new List<PgpPublicKey> ();
 }
Ejemplo n.º 36
0
        private UserMaster GetUserMasterDetails()
        {
            var isOperationSuccessful = Getemail(out var email);

            return(!isOperationSuccessful ? null : Repo.GetUserMaster(email));
        }
Ejemplo n.º 37
0
 public RouteRepo(Repo backendRepo)
     : base(backendRepo)
 {
     this.RouteMessage = new RouteMessage ();
 }
Ejemplo n.º 38
0
 public TreeViewModel(Repo repo) : base(repo)
 {
 }
Ejemplo n.º 39
0
 /// <summary>
 /// Encrypts all chunks before sending them to the backend repo
 /// </summary>
 /// <param name="backendRepo">
 /// This is where the encrypted chunks are sent
 /// </param>
 /// <param name="keyStorage">
 /// If decrypting, this is where we look for private keys
 /// </param>
 public EncryptedRepo(Repo backendRepo, KeyStorage keyStorage)
     : base(backendRepo)
 {
     this.keyStorage = keyStorage;
 }
Ejemplo n.º 40
0
        public ActionResult Index()
        {
            var repo = new Repo();

            return(View(model: repo.Get()));
        }
Ejemplo n.º 41
0
 public void ReadTree(Tree tree, Repo repo)
 {
     ReadTree ("", tree, repo);
 }
Ejemplo n.º 42
0
 public void GetTypeMetaAll()
 {
     var meta = Repo.GetTypeMetaAll();
 }
Ejemplo n.º 43
0
        public void ReadTree(string prefix, Tree tree, Repo repo)
        {
            TreeEntry[] treeEntries = tree.Entries;

            foreach (TreeEntry te in treeEntries) {
                string name;

                if (!String.IsNullOrEmpty (prefix))
                    name = String.Format ("{0}/{1}", prefix, te.Name);
                else
                    name = te.Name;

            //				if (te.IsTree (repo))
            //					ReadTree (name, tree, repo);
            }
        }
Ejemplo n.º 44
0
 public GitHubAuthTest()
 {
     var repoLoc = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), nameof(SemDiff),"semdiffdotnet", repository);
     Directory.CreateDirectory(repoLoc);
     repo = new Repo(repoLoc, owner, repository);
 }
Ejemplo n.º 45
0
 public IActionResult RemoveMember(int orgId, int userId) =>
 Repo
 .RemoveMember(orgId, userId)
 .RevokeToken()
 .ToActionResult(x => new { Message = "User removed from organization" });
Ejemplo n.º 46
0
 public void SaveDemo(string sr)
 {
     var result = ZedDemo(sr);
     var thing = new Repo();
     _repo.Add(thing);
 }
Ejemplo n.º 47
0
 public void LastSessionLocalFiles()
 {
     repo.AssertRateLimit();
     var requests = repo.GetPullRequestsAsync().Result;
     repo.UpdateLocalSavedList();
     var newRepo = new Repo(repo.LocalGitDirectory, repo.Owner, repo.RepoName);
     newRepo.GetCurrentSaved();
     Assert.IsNotNull(newRepo.PullRequests);
 }
Ejemplo n.º 48
0
 public static CommandRaisesEvent Instance(Repo repo) => new CommandRaisesEvent(repo);
Ejemplo n.º 49
0
 private void Update()
 {
     Repo.Modificar(Sala);
 }
Ejemplo n.º 50
0
 public void TestInit()
 {
     repo = GetDummyRepo(nameof(RepoTests), owner, repository);
 }
Ejemplo n.º 51
0
 public CommandRaisesEvent(Repo repo)
 {
     _repo = repo;
 }