コード例 #1
0
        internal void OnSelectUploadTransport(SelectUploadTransportArgs e)
        {
            var handler = SelectUploadTransport;

            if (handler != null)
            {
                handler(this, e);
            }
        }
コード例 #2
0
ファイル: DeliveryService.cs プロジェクト: xafdelta/xafdelta
        /// <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);
        }
コード例 #3
0
ファイル: DeliveryService.cs プロジェクト: xafdelta/xafdelta
        /// <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);
        }
コード例 #4
0
ファイル: Module.cs プロジェクト: xafdelta/xafdelta
 internal void OnSelectUploadTransport(SelectUploadTransportArgs e)
 {
     var handler = SelectUploadTransport;
     if (handler != null) handler(this, e);
 }