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


C# IObjectSpace.Rollback方法代码示例

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


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

示例1: Upload

        /// <summary>
        /// Uploads pending XafDelta messages to intermidiate net storages.
        /// </summary>
        /// <param name="xafDeltaModule">The xaf delta module.</param>
        /// <param name="objectSpace">The object space.</param>
        /// <param name="worker">The worker.</param>
        public void Upload(XafDeltaModule xafDeltaModule, IObjectSpace objectSpace, ActionWorker worker)
        {
            worker.ReportProgress(Localizer.UploadStarted);

            var transportList = (from m in XafDeltaModule.XafApp.Modules
                                 where m is IXafDeltaTransport && ((IXafDeltaTransport)m).UseForUpload
                                 select m).Cast<IXafDeltaTransport>().ToList().AsReadOnly();

            if (transportList.Count > 0)
            {
                var replicas = (from r in objectSpace.GetObjects<Package>() where r.IsOutput
                                    && r.GetEventDateTime(PackageEventType.Sent) == DateTime.MinValue
                                    orderby r.PackageDateTime
                                select r).ToList();

                var tickets = (from t in objectSpace.GetObjects<Ticket>(CriteriaOperator.Parse("IsNull(ProcessingDateTime)"), true)
                               where t.Package != null && t.Package.IsInput
                               orderby t.TicketDateTime select t).ToList();

                var messages = replicas.Cast<IReplicationMessage>().Union(tickets.Cast<IReplicationMessage>()).ToList();

                var uploadData = new Dictionary<IXafDeltaTransport, List<IReplicationMessage>>();

                worker.ReportProgress(string.Format(Localizer.FoundForUpload, messages.Count()));
                foreach (var message in messages.TakeWhile(x => !worker.CancellationPending))
                {
                    var args = new SelectUploadTransportArgs(message, transportList[0]);
                    Owner.OnSelectUploadTransport(args);
                    if(args.Transport != null)
                    {
                        List<IReplicationMessage> list;
                        if(!uploadData.TryGetValue(args.Transport, out list))
                        {
                            list = new List<IReplicationMessage>();
                            uploadData.Add(args.Transport, list);
                        }
                        list.Add(message);
                    }
                }

                if(!worker.CancellationPending && uploadData.Keys.Count > 0)
                {
                    foreach (var transport in uploadData.Keys.TakeWhile(x => !worker.CancellationPending))
                    {
                        try
                        {
                            worker.ReportProgress(string.Format(Localizer.OpenTransport, transport));
                            transport.Open(TransportMode.Upload, worker);
                            var messageList = uploadData[transport];
                            foreach (var message in messageList)
                            {
                                var recipientAddress = message.RecipientAddress;
                                // worker.ReportProgress(string.Format(Localizer.UploadingFile, message));
                                transport.UploadFile(message.ToString(), message.GetData(), recipientAddress, worker);
                                if (message is Package)
                                    ((Package)message).CreateLogRecord(PackageEventType.Sent);
                                else
                                    ((Ticket) message).ProcessingDateTime = DateTime.Now;

                                objectSpace.CommitChanges();
                            }
                        }
                        catch (Exception exception)
                        {
                            objectSpace.Rollback();
                            worker.ReportError(Localizer.UploadError, exception.Message);
                        }
                        finally
                        {
                            worker.ReportProgress(string.Format(Localizer.CloseTransport, transport));
                            transport.Close();
                        }
                    }
                }
            }
            else
                worker.ReportProgress(Color.BlueViolet, Localizer.UploadTransportNotFound);
            worker.ReportProgress(Color.Blue, Localizer.UploadFinished);
        }
开发者ID:xafdelta,项目名称:xafdelta,代码行数:85,代码来源:DeliveryService.cs

示例2: Download

        /// <summary>
        /// Downloads XafDelta messages into replication storage database.
        /// </summary>
        /// <param name="xafDeltaModule">The xaf delta module.</param>
        /// <param name="objectSpace">The object space.</param>
        /// <param name="worker">The worker.</param>
        public void Download(XafDeltaModule xafDeltaModule, IObjectSpace objectSpace, ActionWorker worker)
        {
            worker.ReportProgress(Localizer.DownloadStarted);

            var transportList = (from m in xafDeltaModule.ModuleManager.Modules
                                where m is IXafDeltaTransport && ((IXafDeltaTransport) m).UseForDownload
                                select m).Cast<IXafDeltaTransport>().ToList();

            worker.ReportProgress(string.Format(Localizer.TransportFound, transportList.Count()));
            foreach (var transport in transportList.TakeWhile(x => !worker.CancellationPending))
            {
                worker.ReportProgress(string.Format(Localizer.DownloadUsing, transport));
                try
                {
                    worker.ReportProgress(string.Format(Localizer.OpenTransport, transport));
                    transport.Open(TransportMode.Download, worker);

                    var existingReplicaNames = from c in objectSpace.GetObjects<Package>() select c.FileName;

                    var fileNames = transport.GetFileNames(worker,
                        @"(" + Ticket.FileMask + "|" + Package.FileMask + ")").ToList();

                    fileNames = fileNames.Except(existingReplicaNames).ToList();

                    worker.ReportProgress(string.Format(Localizer.FilesForDownload, fileNames.Count));
                    foreach (var fileName in fileNames.TakeWhile(x => !worker.CancellationPending))
                    {
                        // worker.ReportProgress(string.Format(Localizer.DownloadFile, fileName));
                        var fileData = transport.DownloadFile(fileName, worker);
                        if(fileData != null && fileData.Length > 0)
                        {
                            if (fileName.EndsWith(Package.PackageFileExtension))
                            {
                                var replica = Package.ImportFromBytes(objectSpace, fileName, fileData);
                                replica.Save();
                            }
                            else
                            {
                                var replicaTicket = Ticket.ImportTicket(objectSpace, fileData);
                                replicaTicket.Save();
                            }
                            if (!fileName.Contains(ReplicationNode.AllNodes))
                                transport.DeleteFile(fileName, worker);
                            objectSpace.CommitChanges();
                        }
                    }
                }
                catch (Exception exception)
                {
                    objectSpace.Rollback();
                    worker.ReportError(Localizer.DownloadError, exception.Message);
                }
                finally
                {
                    worker.ReportProgress(Localizer.CloseTransport, transport);
                    transport.Close();
                }
            }
            worker.ReportProgress(Color.Blue, Localizer.DownloadFinished);
        }
开发者ID:xafdelta,项目名称:xafdelta,代码行数:66,代码来源:DeliveryService.cs

示例3: CloseObjectSpace

 protected virtual void CloseObjectSpace(IObjectSpace objectSpace, bool success)
 {
     if (objectSpace != null && !objectSpace.IsDisposed)
     {
         if (success)
         {
             objectSpace.CommitChanges();
         }
         else
         {
             objectSpace.Rollback();
         }
         objectSpace.Dispose();
     }
 }
开发者ID:LSTANCZYK,项目名称:devexpress_xaf_aurum,代码行数:15,代码来源:CustomImportOperation.cs


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