当前位置: 首页>>代码示例>>C#>>正文


C# IRepository.Update方法代码示例

本文整理汇总了C#中IRepository.Update方法的典型用法代码示例。如果您正苦于以下问题:C# IRepository.Update方法的具体用法?C# IRepository.Update怎么用?C# IRepository.Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IRepository的用法示例。


在下文中一共展示了IRepository.Update方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MainAsync

        static async Task MainAsync(IRepository<SampleEntity> repo)
        {
            foreach (var s in await repo.GetAllAsync())
            {
                Console.WriteLine("{0} | {1}", s.ID, s.Name);
            }

            // Paged Set //
            Console.WriteLine("\nPage = 2 - Page Size = 2 :");
            var some = await repo.GetAsync(2, 2, s => s.ID);
            foreach (var s in some)
            {
                Console.WriteLine("{0} | {1}", s.ID, s.Name);
            }
                
            // Updating //
            var fox = await repo.FindAsync(e => e.Name == "Fox");
            fox.Name = "Dog";

            repo.Update(fox, fox.ID);

            // Deleting //
            Console.WriteLine("\n " + await repo.DeleteAsync(repo.Get(5)) + "\n");

            foreach (var e in repo.GetAll())
                Console.WriteLine(e.ID + " | " + e.Name);
        }
开发者ID:ioab,项目名称:.NET-EF6-GenericRepository,代码行数:27,代码来源:Program.cs

示例2: Update_Should_Save_Modified_Business_Name

        public void Update_Should_Save_Modified_Business_Name(IRepository<Contact, string> repository)
        {
            var contact = new Contact { Name = "Test User" };
            repository.Add(contact);

            var contact2 = new Contact { Name = "Test User 2" };
            repository.Add(contact2);

            contact.Name = "Test User - Updated";
            repository.Update(contact);

            var updated = repository.Get(contact.ContactId);
            var notUpdated = repository.Get(contact2.ContactId);

            updated.Name.ShouldEqual("Test User - Updated");
            notUpdated.Name.ShouldEqual("Test User 2");
        }
开发者ID:mgmccarthy,项目名称:SharpRepository,代码行数:17,代码来源:RepositoryUpdateTests.cs

示例3: Update_Should_Update_Multiple_Items

        public void Update_Should_Update_Multiple_Items(IRepository<Contact, string> repository)
        {
            IList<Contact> contacts = new List<Contact>
                                        {
                                            new Contact {Name = "Contact 1"},
                                            new Contact {Name = "Contact 2"},
                                            new Contact {Name = "Contact 3"},
                                        };

            repository.Add(contacts);
            var items = repository.GetAll().ToList();
            items.Count().ShouldEqual(3);

            foreach (var contact in contacts.Take(2))
            {
                contact.Name += "UPDATED";
            }

            repository.Update(contacts);
            items = repository.GetAll().ToList();
            items.Count(x => x.Name.EndsWith("UPDATED")).ShouldEqual(2);
        }
开发者ID:mgmccarthy,项目名称:SharpRepository,代码行数:22,代码来源:RepositoryUpdateTests.cs

示例4: DeployAsync

        public async Task DeployAsync(IRepository repository, ChangeSet changeSet, string deployer, bool clean, bool needFileUpdate = true)
        {
            using (var deploymentAnalytics = new DeploymentAnalytics(_analytics, _settings))
            {
                Exception exception = null;
                ITracer tracer = _traceFactory.GetTracer();
                IDisposable deployStep = null;
                ILogger innerLogger = null;
                string targetBranch = null;

                // If we don't get a changeset, find out what branch we should be deploying and get the commit ID from it
                if (changeSet == null)
                {
                    targetBranch = _settings.GetBranch();

                    changeSet = repository.GetChangeSet(targetBranch);

                    if (changeSet == null)
                    {
                        throw new InvalidOperationException(String.Format("The current deployment branch is '{0}', but nothing has been pushed to it", targetBranch));
                    }
                }

                string id = changeSet.Id;
                IDeploymentStatusFile statusFile = null;
                try
                {
                    deployStep = tracer.Step("DeploymentManager.Deploy(id)");
                    // Remove the old log file for this deployment id
                    string logPath = GetLogPath(id);
                    FileSystemHelpers.DeleteFileSafe(logPath);

                    statusFile = GetOrCreateStatusFile(changeSet, tracer, deployer);
                    statusFile.MarkPending();

                    ILogger logger = GetLogger(changeSet.Id);

                    if (needFileUpdate)
                    {
                        using (tracer.Step("Updating to specific changeset"))
                        {
                            innerLogger = logger.Log(Resources.Log_UpdatingBranch, targetBranch ?? id);

                            using (var writer = new ProgressWriter())
                            {
                                // Update to the specific changeset or branch
                                repository.Update(targetBranch ?? id);
                            }
                        }
                    }

                    if (_settings.ShouldUpdateSubmodules())
                    {
                        using (tracer.Step("Updating submodules"))
                        {
                            innerLogger = logger.Log(Resources.Log_UpdatingSubmodules);

                            repository.UpdateSubmodules();
                        }
                    }

                    if (clean)
                    {
                        tracer.Trace("Cleaning {0} repository", repository.RepositoryType);

                        innerLogger = logger.Log(Resources.Log_CleaningRepository, repository.RepositoryType);

                        repository.Clean();
                    }

                    // set to null as Build() below takes over logging
                    innerLogger = null;

                    // Perform the build deployment of this changeset
                    await Build(changeSet, tracer, deployStep, repository, deploymentAnalytics);
                }
                catch (Exception ex)
                {
                    exception = ex;

                    if (innerLogger != null)
                    {
                        innerLogger.Log(ex);
                    }

                    if (statusFile != null)
                    {
                        MarkStatusComplete(statusFile, success: false);
                    }

                    tracer.TraceError(ex);

                    deploymentAnalytics.Error = ex.ToString();

                    if (deployStep != null)
                    {
                        deployStep.Dispose();
                    }
                }

//.........这里部分代码省略.........
开发者ID:NorimaConsulting,项目名称:kudu,代码行数:101,代码来源:DeploymentManager.cs

示例5: Deploy

        public void Deploy(IRepository repository, ChangeSet changeSet, string deployer, bool clean)
        {
            ITracer tracer = _traceFactory.GetTracer();
            IDisposable deployStep = null;
            ILogger innerLogger = null;
            string targetBranch = null;

            // If we don't get a changeset, find out what branch we should be deploying and get the commit ID from it
            if (changeSet == null)
            {
                targetBranch = _settings.GetBranch();

                changeSet = repository.GetChangeSet(targetBranch);
            }

            string id = changeSet.Id;
            IDeploymentStatusFile statusFile = null;
            try
            {
                deployStep = tracer.Step("DeploymentManager.Deploy(id)");

                // Remove the old log file for this deployment id
                string logPath = GetLogPath(id);
                FileSystemHelpers.DeleteFileSafe(logPath);

                statusFile = GetOrCreateStatusFile(changeSet, tracer, deployer);
                statusFile.MarkPending();

                ILogger logger = GetLogger(changeSet.Id);

                using (tracer.Step("Updating to specific changeset"))
                {
                    innerLogger = logger.Log(Resources.Log_UpdatingBranch, targetBranch ?? id);

                    using (var writer = new ProgressWriter())
                    {
                        // Update to the the specific changeset
                        repository.ClearLock();
                        repository.Update(id);
                    }
                }

                using (tracer.Step("Updating submodules"))
                {
                    innerLogger = logger.Log(Resources.Log_UpdatingSubmodules);

                    repository.UpdateSubmodules();
                }

                if (clean)
                {
                    tracer.Trace("Cleaning {0} repository", repository.RepositoryType);

                    innerLogger = logger.Log(Resources.Log_CleaningRepository, repository.RepositoryType);

                    repository.Clean();
                }

                // set to null as Build() below takes over logging
                innerLogger = null;

                // Perform the build deployment of this changeset
                Build(id, tracer, deployStep);
            }
            catch (Exception ex)
            {
                if (innerLogger != null)
                {
                    innerLogger.Log(ex);
                }

                if (statusFile != null)
                {
                    statusFile.MarkFailed();
                }

                tracer.TraceError(ex);

                if (deployStep != null)
                {
                    deployStep.Dispose();
                }

                throw;
            }
        }
开发者ID:plurby,项目名称:kudu,代码行数:86,代码来源:DeploymentManager.cs

示例6: Sync

        internal ChangeSet Sync(DropboxHandler.DropboxInfo deploymentInfo, string branch, ILogger logger, IRepository repository)
        {
            DropboxDeployInfo info = deploymentInfo.DeployInfo;

            _logger = logger;

            _successCount = 0;
            _fileCount = 0;
            _failedCount = 0;
            _retriedCount = 0;

            if (_settings.GetValue(CursorKey) != info.OldCursor)
            {
                throw new InvalidOperationException(Resources.Error_MismatchDropboxCursor);
            }

            if (!repository.IsEmpty())
            {
                // git checkout --force <branch>
                repository.ClearLock();
                repository.Update(branch);
            }

            ChangeSet changeSet;
            string message = null;
            try
            {
                using (_tracer.Step("Synch with Dropbox"))
                {
                    // Sync dropbox => repository directory
                    ApplyChanges(deploymentInfo);
                }

                message = String.Format(CultureInfo.CurrentCulture,
                            Resources.Dropbox_Synchronized,
                            deploymentInfo.DeployInfo.Deltas.Count());
            }
            catch (Exception)
            {
                message = String.Format(CultureInfo.CurrentCulture,
                            Resources.Dropbox_SynchronizedWithFailure,
                            _successCount,
                            deploymentInfo.DeployInfo.Deltas.Count(),
                            _failedCount);

                throw;
            }
            finally
            {
                _logger.Log(message);

                _logger.Log(String.Format("{0} downloaded files, {1} successful retries.", _fileCount, _retriedCount));

                _status.Open(deploymentInfo.TargetChangeset.Id).UpdateMessage(message);

                _status.Open(deploymentInfo.TargetChangeset.Id).UpdateProgress(String.Format(CultureInfo.CurrentCulture, Resources.Dropbox_Committing, _successCount));

                // Commit anyway even partial change
                changeSet = repository.Commit(message, String.Format("{0} <{1}>", info.UserName, info.Email));
            }

            // Save new dropboc cursor
            LogInfo("Update dropbox cursor");
            _settings.SetValue(CursorKey, info.NewCursor);

            return changeSet;
        }
开发者ID:bogdansa,项目名称:kudu,代码行数:67,代码来源:DropboxHelper.cs

示例7: Sync

        internal async Task<ChangeSet> Sync(DropboxInfo dropboxInfo, string branch, IRepository repository)
        {
            DropboxDeployInfo deployInfo = dropboxInfo.DeployInfo;

            ResetStats();

            if (_settings.GetValue(CursorKey) != deployInfo.OldCursor)
            {
                throw new InvalidOperationException(Resources.Error_MismatchDropboxCursor);
            }

            // initial sync, remove default content
            // for simplicity, we do it blindly whether or not in-place
            // given the end result is the same
            if (String.IsNullOrEmpty(deployInfo.OldCursor) && DeploymentHelper.IsDefaultWebRootContent(_environment.WebRootPath))
            {
                string hoststarthtml = Path.Combine(_environment.WebRootPath, Constants.HostingStartHtml);
                FileSystemHelpers.DeleteFileSafe(hoststarthtml);
            }

            if (!repository.IsEmpty())
            {
                // git checkout --force <branch>
                repository.Update(branch);
            }

            ChangeSet changeSet = null;
            string message = null;
            try
            {
                using (_tracer.Step("Sync with Dropbox"))
                {
                    if (dropboxInfo.OAuthVersion == 2)
                    {
                        // Fetch the deltas
                        await UpdateDropboxDeployInfo(deployInfo);
                    }

                    // Sync dropbox => repository directory
                    await ApplyChanges(dropboxInfo, useOAuth20: dropboxInfo.OAuthVersion == 2);
                }

                message = String.Format(CultureInfo.CurrentCulture,
                            Resources.Dropbox_Synchronized,
                            deployInfo.Deltas.Count);
            }
            catch (Exception)
            {
                message = String.Format(CultureInfo.CurrentCulture,
                            Resources.Dropbox_SynchronizedWithFailure,
                            _successCount,
                            deployInfo.Deltas.Count,
                            _failedCount);

                throw;
            }
            finally
            {
                Logger.Log(message);

                Logger.Log(String.Format("{0} downloaded files, {1} successful retries.", _fileCount, _retriedCount));

                IDeploymentStatusFile statusFile = _status.Open(dropboxInfo.TargetChangeset.Id);
                statusFile.UpdateMessage(message);
                statusFile.UpdateProgress(String.Format(CultureInfo.CurrentCulture, Resources.Dropbox_Committing, _successCount));

                // Commit anyway even partial change
                if (repository.Commit(message, String.Format("{0} <{1}>", deployInfo.UserName, deployInfo.Email ?? deployInfo.UserName)))
                {
                    changeSet = repository.GetChangeSet("HEAD");
                }
            }

            // Save new dropboc cursor
            LogInfo("Update dropbox cursor");
            _settings.SetValue(CursorKey, deployInfo.NewCursor);

            return changeSet;
        }
开发者ID:albertjan,项目名称:kudu,代码行数:79,代码来源:DropboxHelper.cs

示例8: Persist

 internal static void Persist(IRepository<Instance> instanceRepository, Instance instanceToPersist, SaveMechanic saveMechanic)
 {
     switch(saveMechanic)
     {
         case SaveMechanic.Add:
             instanceRepository.Add(instanceToPersist);
             break;
         case SaveMechanic.Update:
             instanceRepository.Update(instanceToPersist);
             break;
         default:
             throw new InvalidOperationException("Unknown save mechanic. This should never happen.");
     }
 }
开发者ID:nelsonwellswku,项目名称:stack-it-net,代码行数:14,代码来源:UpdateInstance.cs

示例9: Deal

 /// <summary>
 /// Method updates product status for "saled", because the Deal is done
 /// </summary>
 /// <param name="product"></param>
 /// <param name="id"></param>
 public static void Deal(IRepository<Product> product, int id)
 {
     Console.WriteLine("Consratulations! You have bought the product {0} on address {1}", product.GetItem(id).name, product.GetItem(id).address);
     Product saledProduct = new Product(id, product.GetItem(id).name, product.GetItem(id).address, "saled");
     product.Update(saledProduct);
 }
开发者ID:WilliamRobertMontgomery,项目名称:asp-dot-net-training-project,代码行数:11,代码来源:Realtor.cs

示例10: Changed

        private void Changed(IRepository rep, FileSystemEventArgs e)
        {
            try
            {
                IList<AttachmentInfo> list = (rep as Feng.NH.INHibernateRepository).List<AttachmentInfo>(NHibernate.Criterion.DetachedCriteria.For<AttachmentInfo>()
                    .Add(NHibernate.Criterion.Expression.Eq("FileName", e.Name)));

                if (list == null || list.Count == 0)
                {
                    Created(rep, e);
                }

                FileInfo fi = new FileInfo(e.FullPath);
                FileStream fs = fi.OpenRead();
                byte[] bytes = new byte[fs.Length];
                fs.Read(bytes, 0, Convert.ToInt32(fs.Length));
                fs.Close();

                list[0].Data = bytes;
                rep.Update(list[0]);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Changed Members of Watcher Error:" + ex.Message);
            }
        }
开发者ID:qq5013,项目名称:mERP-HD,代码行数:26,代码来源:process_watcher.cs

示例11: UpdateImage

        private Image UpdateImage(IRootPathProvider pathProvider, IRepository repository, Image image, HttpFile newImage)
        {
            if (this.HasNewImage(image, newImage))
            {
                // delete the image
                if (image != null)
                {
                    image.Delete();
                }

                // add the new image
                image = new Image() { Filename = newImage.Name };
                repository.Add(image);
                image.SaveImage(newImage.Value);
                repository.Update(image);
            }

            return image;
        }
开发者ID:nfink,项目名称:Haven,代码行数:19,代码来源:AdminModule.cs


注:本文中的IRepository.Update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。