Example #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;
        }
Example #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 ();
 }
Example #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());
        }
Example #5
0
        public static void Load(Repo repo)
        {
            var nasajpl = new FlickrUser { User = "******" };
            repo.Insert (nasajpl);

            repo.Insert (new TwitterSearch { Search = "nasa" });
        }
Example #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);
 }
Example #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);
 }
Example #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);
        }
Example #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);
        }
Example #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);
        }
Example #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();
        }
Example #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));
            }
        }
Example #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");
            }
        }
        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);
            }
        }
Example #18
0
 public IActionResult GetPreferences() =>
 Repo
 .GetPreferences()
 .ToActionResult(x => ToGetPrefReply(x));
Example #19
0
        public void OneTest()
        {
            Repo reposit = new Repo();

            reposit.BuildDataList();
        }
Example #20
0
 public void TypeOfToList()
 {
     var meta  = Repo.GetTypeMeta <Pages>();
     var pages = Repo.TypeOf <Pages>().ToList();
 }
 protected TreeBaseViewModel(Repo repo) : base(repo)
 {
 }
Example #22
0
 public IActionResult Create(OrgRequest r) =>
 Repo
 .Create(r.ToModel())
 .ToActionResult(x => new { x.Value.Id, Message = "Organization created" });
Example #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 });
Example #24
0
 public JawboneController(Repo.Interfaces.IJawboneRepository repo)
 {
     _repo = repo;
 }
Example #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" });
Example #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));
        }
Example #28
0
        public void Copy_SourceDoesNotExist_ThrowsMercurialExecutionException()
        {
            Repo.Init();

            Assert.Throws <MercurialExecutionException>(() => Repo.Copy("test1.txt", "test2.txt"));
        }
Example #29
0
 public void Copy_NoRepository_ThrowsMercurialExecutionException()
 {
     Assert.Throws <MercurialExecutionException>(() => Repo.Copy("test1.txt", "test2.txt"));
 }
Example #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 });
Example #31
0
 public IActionResult GetMembersLookup() =>
 Repo
 .GetMembers(ActualUser.OrgId)
 .ToActionResult(x => ToMembersLookupReply(x));
Example #32
0
 public IActionResult GetMembers(int orgId) =>
 Repo
 .GetMembers(orgId)
 .ToActionResult(x => ToMembersReply(x, orgId));
Example #33
0
 public PipeServer(Stream sin, Stream sout, Repo localRepo)
 {
     this.input = sin;
     this.output = sout;
     this.localRepo = localRepo;
 }
Example #34
0
 public IQueryable <Category> GetAll()
 {
     return(Repo.GetAll <Category>());
 }
Example #35
0
 public OpenPgpRepo(Repo backendRepo)
     : base(backendRepo)
 {
     this.Recipients = new List<PgpPublicKey> ();
 }
Example #36
0
        private UserMaster GetUserMasterDetails()
        {
            var isOperationSuccessful = Getemail(out var email);

            return(!isOperationSuccessful ? null : Repo.GetUserMaster(email));
        }
Example #37
0
 public RouteRepo(Repo backendRepo)
     : base(backendRepo)
 {
     this.RouteMessage = new RouteMessage ();
 }
 public TreeViewModel(Repo repo) : base(repo)
 {
 }
Example #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;
 }
Example #40
0
        public ActionResult Index()
        {
            var repo = new Repo();

            return(View(model: repo.Get()));
        }
Example #41
0
 public void ReadTree(Tree tree, Repo repo)
 {
     ReadTree ("", tree, repo);
 }
Example #42
0
 public void GetTypeMetaAll()
 {
     var meta = Repo.GetTypeMetaAll();
 }
Example #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);
            }
        }
 public GitHubAuthTest()
 {
     var repoLoc = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), nameof(SemDiff),"semdiffdotnet", repository);
     Directory.CreateDirectory(repoLoc);
     repo = new Repo(repoLoc, owner, repository);
 }
Example #45
0
 public IActionResult RemoveMember(int orgId, int userId) =>
 Repo
 .RemoveMember(orgId, userId)
 .RevokeToken()
 .ToActionResult(x => new { Message = "User removed from organization" });
 public void SaveDemo(string sr)
 {
     var result = ZedDemo(sr);
     var thing = new Repo();
     _repo.Add(thing);
 }
Example #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);
 }
Example #48
0
 public static CommandRaisesEvent Instance(Repo repo) => new CommandRaisesEvent(repo);
Example #49
0
 private void Update()
 {
     Repo.Modificar(Sala);
 }
Example #50
0
 public void TestInit()
 {
     repo = GetDummyRepo(nameof(RepoTests), owner, repository);
 }
Example #51
0
 public CommandRaisesEvent(Repo repo)
 {
     _repo = repo;
 }