public void DeleteProduct(Guid id) { ProductItem entity = context.ProductItems.FirstOrDefault(obj => obj.Id == id); if (entity != default) { context.Entry(entity).State = EntityState.Deleted; FileSystemApi.DeleteImagesDirectoryById(context.Entry(entity).Entity.Id); context.SaveChanges(); } }
public IActionResult Edit(ProductItem model, IEnumerable <IFormFile> titleImageFiles, List <double?> sizeValues) { if (ModelState.IsValid) { if (sizeValues != null) { sizeValues = sizeValues.Distinct().Where(x => x != null && x >= 0 && x <= 300).ToList(); sizeValues.Sort(); foreach (var size in sizeValues) { model.Sizes.Add(new Size(size.GetValueOrDefault())); } } model.TotalPrice = @Math.Round(model.Price * (1 - model.Discount * 0.01)); if (titleImageFiles != null && titleImageFiles.Any()) { foreach (var img in titleImageFiles) { var ext = Path.GetExtension(img.FileName).ToLowerInvariant(); if (img.Length > Config.FileSizeLimit || string.IsNullOrEmpty(ext) || !Config.PermittedExtensions.Contains(ext)) { continue; } model.Images.Add(new Image(img.FileName)); using (var stream = new FileStream( Path.Combine ( FileSystemApi.CreateTempDirectory(), img.FileName ), FileMode.Create)) { img.CopyTo(stream); } } } dataManager.ProductItems.SaveProductItem(model); return(RedirectToAction(nameof(HomeController.Index), nameof(HomeController).CutController())); } return(View(model)); }
/// <summary> /// Creates a new instance of the <see cref="IpfsEngine"/> class. /// </summary> public IpfsEngine() { // Init the core api inteface. Bitswap = new BitswapApi(this); Block = new BlockApi(this); Config = new ConfigApi(this); Dag = new DagApi(this); Dht = new DhtApi(this); FileSystem = new FileSystemApi(this); Generic = new GenericApi(this); Key = new KeyApi(this); Name = new NameApi(this); Object = new ObjectApi(this); Pin = new PinApi(this); PubSub = new PubSubApi(this); Swarm = new SwarmApi(this); }
static void Main(string[] args) { var clientId = ""; var tenantId = ""; var secret = ""; var scope = "https://storage.azure.com/.default"; var storageAccountName = ""; var fileSystemName = "myexamplehdfs"; var tokenProvider = new OAuthTokenProvider(tenantId, clientId, secret, scope); var hdfs = new FileSystemApi(storageAccountName, tokenProvider); var response = hdfs.CreateFileSystemAsync(fileSystemName).Result; hdfs.CreateDirectoryAsync(fileSystemName, "/demo").Wait(); hdfs.CreateEmptyFileAsync(fileSystemName, "/demo/", "example.txt").Wait(); var stream = new FileStream(@"C:\temp.txt", FileMode.Open, FileAccess.Read); hdfs.CreateFileAsync(fileSystemName, "/demo/", "mytest.txt", stream).Wait(); var acls = new AclEntry[] { new AclEntry( AclScope.Access, AclType.Group, "2dec2374-3c51-4743-b247-ad6f80ce4f0b", (GrantType.Read | GrantType.Execute)), new AclEntry( AclScope.Access, AclType.Group, "62049695-0418-428e-a5e4-64600d6d68d8", (GrantType.Read | GrantType.Write | GrantType.Execute)), new AclEntry( AclScope.Default, AclType.Group, "62049695-0418-428e-a5e4-64600d6d68d8", (GrantType.Read | GrantType.Write | GrantType.Execute)) }; hdfs.SetAccessControlAsync(fileSystemName, "/", acls).Wait(); Console.ReadLine(); }
public void SaveProductItem(ProductItem entity) { if (entity.Id == default) { context.Entry(entity).State = EntityState.Added; context.SaveChanges(); foreach (Image img in entity.Images) { context.Entry(img).State = EntityState.Added; } foreach (Size size in entity.Sizes) { context.Entry(size).State = EntityState.Added; } } else { foreach (Image img in entity.Images) { context.Entry(img).State = EntityState.Added; } var dbSizes = context.Sizes.Where(size => size.ProductItemId == entity.Id); if (!entity.Sizes.SequenceEqual(dbSizes.ToList())) { context.Sizes.RemoveRange(dbSizes); context.SaveChanges(); foreach (Size size in entity.Sizes) { context.Entry(size).State = EntityState.Added; } } context.Entry(entity).State = EntityState.Modified; context.SaveChanges(); } if (entity.Images.Any()) { FileSystemApi.CopyTempDirectoryById(context.Entry(entity).Entity.Id); } context.SaveChanges(); }
void Init() { // Init the core api inteface. Bitswap = new BitswapApi(this); Block = new BlockApi(this); BlockRepository = new BlockRepositoryApi(this); Bootstrap = new BootstrapApi(this); Config = new ConfigApi(this); Dag = new DagApi(this); Dht = new DhtApi(this); Dns = new DnsApi(this); FileSystem = new FileSystemApi(this); Generic = new GenericApi(this); Key = new KeyApi(this); Name = new NameApi(this); Object = new ObjectApi(this); Pin = new PinApi(this); PubSub = new PubSubApi(this); Stats = new StatsApi(this); Swarm = new SwarmApi(this); // Async properties LocalPeer = new AsyncLazy <Peer>(async() => { log.Debug("Building local peer"); var keyChain = await KeyChain().ConfigureAwait(false); log.Debug("Getting key info about self"); var self = await keyChain.FindKeyByNameAsync("self").ConfigureAwait(false); var localPeer = new Peer { Id = self.Id, PublicKey = await keyChain.GetPublicKeyAsync("self").ConfigureAwait(false), ProtocolVersion = "ipfs/0.1.0" }; var version = typeof(IpfsEngine).GetTypeInfo().Assembly.GetName().Version; localPeer.AgentVersion = $"net-ipfs/{version.Major}.{version.Minor}.{version.Revision}"; log.Debug("Built local peer"); return(localPeer); }); SwarmService = new AsyncLazy <Swarm>(async() => { log.Debug("Building swarm service"); if (Options.Swarm.PrivateNetworkKey == null) { var path = Path.Combine(Options.Repository.Folder, "swarm.key"); if (File.Exists(path)) { using (var x = File.OpenText(path)) { Options.Swarm.PrivateNetworkKey = new PreSharedKey(); Options.Swarm.PrivateNetworkKey.Import(x); } } } var peer = await LocalPeer.ConfigureAwait(false); var keyChain = await KeyChain().ConfigureAwait(false); var self = await keyChain.GetPrivateKeyAsync("self").ConfigureAwait(false); var swarm = new Swarm { LocalPeer = peer, LocalPeerKey = PeerTalk.Cryptography.Key.CreatePrivateKey(self), NetworkProtector = Options.Swarm.PrivateNetworkKey == null ? null : new Psk1Protector { Key = Options.Swarm.PrivateNetworkKey } }; if (Options.Swarm.PrivateNetworkKey != null) { log.Debug($"Private network {Options.Swarm.PrivateNetworkKey.Fingerprint().ToHexString()}"); } log.Debug("Built swarm service"); return(swarm); }); BitswapService = new AsyncLazy <BlockExchange.Bitswap>(async() => { log.Debug("Building bitswap service"); var bitswap = new BlockExchange.Bitswap { Swarm = await SwarmService.ConfigureAwait(false), BlockService = Block }; log.Debug("Built bitswap service"); return(bitswap); }); DhtService = new AsyncLazy <PeerTalk.Routing.Dht1>(async() => { log.Debug("Building DHT service"); var dht = new PeerTalk.Routing.Dht1 { Swarm = await SwarmService.ConfigureAwait(false) }; dht.Swarm.Router = dht; log.Debug("Built DHT service"); return(dht); }); PubSubService = new AsyncLazy <PeerTalk.PubSub.NotificationService>(async() => { log.Debug("Building PubSub service"); var pubsub = new PeerTalk.PubSub.NotificationService { LocalPeer = await LocalPeer.ConfigureAwait(false) }; pubsub.Routers.Add(new PeerTalk.PubSub.FloodRouter { Swarm = await SwarmService.ConfigureAwait(false) }); log.Debug("Built PubSub service"); return(pubsub); }); }
void Init() { // Init the core api inteface. Bitswap = new BitswapApi(this); Block = new BlockApi(this); Bootstrap = new BootstrapApi(this); Config = new ConfigApi(this); Dag = new DagApi(this); Dht = new DhtApi(this); Dns = new DnsApi(this); FileSystem = new FileSystemApi(this); Generic = new GenericApi(this); Key = new KeyApi(this); Name = new NameApi(this); Object = new ObjectApi(this); Pin = new PinApi(this); PubSub = new PubSubApi(this); Stats = new StatsApi(this); Swarm = new SwarmApi(this); // Async properties LocalPeer = new AsyncLazy <Peer>(async() => { log.Debug("Building local peer"); var keyChain = await KeyChain(); log.Debug("Getting key info about self"); var self = await keyChain.FindKeyByNameAsync("self"); var localPeer = new Peer(); localPeer.Id = self.Id; localPeer.PublicKey = await keyChain.GetPublicKeyAsync("self"); localPeer.ProtocolVersion = "ipfs/0.1.0"; var version = typeof(IpfsEngine).GetTypeInfo().Assembly.GetName().Version; localPeer.AgentVersion = $"net-ipfs/{version.Major}.{version.Minor}.{version.Revision}"; log.Debug("Built local peer"); return(localPeer); }); SwarmService = new AsyncLazy <Swarm>(async() => { log.Debug("Building swarm service"); var peer = await LocalPeer; var keyChain = await KeyChain(); var self = await keyChain.GetPrivateKeyAsync("self"); var swarm = new Swarm { LocalPeer = peer, LocalPeerKey = PeerTalk.Cryptography.Key.CreatePrivateKey(self) }; log.Debug("Built swarm service"); return(swarm); }); BitswapService = new AsyncLazy <BlockExchange.Bitswap>(async() => { log.Debug("Building bitswap service"); var bitswap = new BlockExchange.Bitswap { Swarm = await SwarmService, BlockService = Block }; log.Debug("Built bitswap service"); return(bitswap); }); DhtService = new AsyncLazy <PeerTalk.Routing.Dht1>(async() => { log.Debug("Building DHT service"); var dht = new PeerTalk.Routing.Dht1 { Swarm = await SwarmService }; dht.Swarm.Router = dht; log.Debug("Built DHT service"); return(dht); }); }