Exemple #1
0
        public override bool Execute(CommandActivity commandActivity)
        {
            var incomingTypeVeReferenceId = "2AC5CF72-AC04-4346-980F-214B34FD9FD0";
            var incomingTypeGsReferenceId = "B4BA6AA3-513F-40A4-BB27-7C6D652BE181";

            var restoreCtxId = ApplicationContext.CurrentID;

            try
            {
                var sourceFileCase = (FileCase)commandActivity.WorkItem;

                if (sourceFileCase == null)
                {
                    throw new ActivityCommandException("").WithUserMessage(LocalizedUserMessages.NoFile
                                                                           .ToLocalizedName()
                                                                           .FormatWith(commandActivity));
                }

                if (!sourceFileCase.CanEdit(true))
                {
                    throw new ActivityCommandException("").WithUserMessage(LocalizedUserMessages.NotEditable
                                                                           .ToLocalizedName()
                                                                           .FormatWith(sourceFileCase));
                }

                //Parse tenant information from incoming
                string targetTenantId = String.Empty;

                var sourceIncoming = sourceFileCase.BaseFile.BaseIncomings
                                     .Where(i => i.IncomingType.ToHasReferenceID().ReferenceID.ToUpper() ==
                                            incomingTypeVeReferenceId.ToUpper())
                                     .OrderByDescending(t => t.CreatedAt)
                                     .FirstOrDefault();
                if (sourceIncoming == null)
                {
                    throw new ActivityCommandException("").WithUserMessage(LocalizedUserMessages.IncomingNotFound
                                                                           .ToLocalizedName()
                                                                           .FormatWith(sourceFileCase.BaseFile));
                }

                var targetFileCaseUri = new Uri(sourceIncoming.GetProperty("#LHIND_Monatsgespraeche_SourceFileCaseUrl") as string);

                targetTenantId = HttpUtility.ParseQueryString(targetFileCaseUri.Query).Get("TenantID");

                var sourceFileCaseUrl = UrlProvider.Current.GetOpenWorkListItemUrl(sourceFileCase);

                //Create eCH-0147 container
                var messageExport = Containers.Global.Resolve <IMessageExport>();
                var eChExport     = messageExport.Export(sourceFileCase);

                sourceFileCase.AddFileCaseContent(eChExport);

                //switch tenant
                using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope())
                    using (TenantSection.SwitchToTenant(Tenant.FindByUnqiueIdentifier(targetTenantId)))
                    {
                        //Create new incoming, set specialdata properties
                        var incoming = Incoming.NewObject();
                        ApplicationContext.CurrentID = incoming.ApplicationContextID;

                        incoming.Subject      = sourceFileCase.DisplayName + " - eCH Response";
                        incoming.IncomingType =
                            new ReferenceHandle <IncomingTypeClassificationType>(incomingTypeGsReferenceId)
                            .GetObject();
                        incoming.ExternalNumber = sourceFileCase.FormattedNumber;
                        incoming.Remark         = sourceFileCase.WorkInstruction;
                        using (new SpecialdataIgnoreReadOnlySection())
                        {
                            incoming.SetProperty("#LHIND_Monatsgespraeche_SourceFileCaseUrl", sourceFileCaseUrl);
                        }

                        var targeteChDocument = Document.NewObject(incoming);
                        ((IDocument)targeteChDocument).Name = sourceFileCase.GetMultilingualValue(fc => fc.Title) + " (" +
                                                              sourceFileCase.FormattedNumber + ") - eCH Import";
                        targeteChDocument.PhysicallyPresent = false;
                        targeteChDocument.Type =
                            (DocumentClassificationType)ClassificationType.GetObject(WellKnownObjects
                                                                                     .DocumentClassification.EchImport.GetObjectID());

                        using (SecurityFreeSection.Activate())
                            using (TenantSection.DisableQueryRestrictions())
                                using (var handle = eChExport.ActiveContent.GetContent())
                                {
                                    targeteChDocument.ActiveContent.SetContent(handle, "zip", "application/zip");

                                    var targetFile = ImportHelper.TenantKnowsObject(targeteChDocument, true);
                                    if (targetFile != null)
                                    {
                                        incoming.LeadingGroup = targetFile.LeadingGroup;
                                        incoming.Insert(targetFile);
                                    }
                                    else
                                    {
                                        incoming.LeadingGroup = UserHelper.Current.GetActaNovaUserExtension().StandardGroup != null
                                ? UserHelper.Current.GetActaNovaUserExtension().StandardGroup.AsTenantGroup()
                                : UserHelper.Current.OwningGroup.AsTenantGroup();
                                    }
                                }

                        ClientTransaction.Current.Commit();
                    }
            }
            catch (Exception ex)
            {
                s_logger.Error(ex.Message, ex);
                throw;
            }
            finally
            {
                ApplicationContext.CurrentID = restoreCtxId;
            }

            return(true);
        }
Exemple #2
0
        public override bool Execute(CommandActivity commandActivity)
        {
            //Set template reference for FF
            var incomingTypeVeReferenceId = "2AC5CF72-AC04-4346-980F-214B34FD9FD0";

            var restoreCtxId = ApplicationContext.CurrentID;

            try
            {
                var sourceFileCase = (FileCase)commandActivity.WorkItem;

                if (sourceFileCase == null)
                {
                    throw new ActivityCommandException("").WithUserMessage(LocalizedUserMessages.NoFileCase
                                                                           .ToLocalizedName()
                                                                           .FormatWith(commandActivity));
                }

                if (!sourceFileCase.CanEdit(true))
                {
                    throw new ActivityCommandException("").WithUserMessage(LocalizedUserMessages.NotEditable
                                                                           .ToLocalizedName()
                                                                           .FormatWith(sourceFileCase));
                }

                //Read specialdata and document values
                var terminGs = sourceFileCase.GetProperty("#LHIND_Monatsgespraeche_TerminGs").ToString() ?? "";

                var datum = sourceFileCase.GetProperty("#LHIND_Monatsgespraeche_Datum").ToString() ?? "";

                var title = sourceFileCase.GetProperty("#LHIND_Monatsgespraeche_TitelIdp") as string;

                var ffAmtObject = sourceFileCase.GetProperty("#LHIND_Monatsgespraeche_Federfuehrung") as SpecialdataCatalogValue;
                var ffAmt       = "";
                if (ffAmtObject != null)
                {
                    ffAmt = ffAmtObject.DisplayName;
                }

                var auftrag = sourceFileCase.GetProperty("#LHIND_Monatsgespraeche_Auftrag") as string;

                var bemerkung = sourceFileCase.GetProperty("#LHIND_Monatsgespraeche_Bemerkungen") as string;

                var rueckfragenAnObject = sourceFileCase.GetProperty("#LHIND_Monatsgespraeche_RueckfragenAn") as TenantUser;
                var rueckfragenAn       = "";
                if (rueckfragenAnObject != null)
                {
                    rueckfragenAn = rueckfragenAnObject.DisplayName;
                }

                var sourceFileCaseUrl = UrlProvider.Current.GetOpenWorkListItemUrl(sourceFileCase);

                //Create eCH-0147 container
                var messageExport = Containers.Global.Resolve <IMessageExport>();
                var eChExport     = messageExport.Export(sourceFileCase);

                sourceFileCase.AddFileCaseContent(eChExport);

                //switch tenant
                using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope())
                    using (TenantSection.SwitchToTenant(UserHelper.Current.Tenant))
                    {
                        //Create new incoming, set specialdata properties
                        var incoming = Incoming.NewObject();
                        ApplicationContext.CurrentID = incoming.ApplicationContextID;

                        incoming.Subject      = sourceFileCase.DisplayName + " - eCH-Dossier";
                        incoming.IncomingType =
                            new ReferenceHandle <IncomingTypeClassificationType>(incomingTypeVeReferenceId).GetObject();
                        incoming.ExternalNumber = sourceFileCase.FormattedNumber;
                        incoming.Remark         = sourceFileCase.WorkInstruction;

                        using (new SpecialdataIgnoreReadOnlySection())
                        {
                            incoming.SetProperty("#LHIND_Monatsgespraeche_VE_TerminGs", terminGs);
                            incoming.SetProperty("#LHIND_Monatsgespraeche_VE_Titel", title);
                            incoming.SetProperty("#LHIND_Monatsgespraeche_VE_Federführung", ffAmt);
                            incoming.SetProperty("#LHIND_Monatsgespraeche_VE_Auftrag", auftrag);
                            incoming.SetProperty("#LHIND_Monatsgespraeche_VE_Bemerkungen", bemerkung);
                            incoming.SetProperty("#LHIND_Monatsgespraeche_VE_Datum", datum);
                            incoming.SetProperty("#LHIND_Monatsgespraeche_VE_RückfragenAn", rueckfragenAn);
                            incoming.SetProperty("#LHIND_Monatsgespraeche_SourceFileCaseUrl", sourceFileCaseUrl);
                        }

                        var targeteChDocument = Document.NewObject(incoming);
                        ((IDocument)targeteChDocument).Name = sourceFileCase.GetMultilingualValue(fc => fc.Title) + " (" +
                                                              sourceFileCase.FormattedNumber + ") - eCH Import";
                        targeteChDocument.PhysicallyPresent = false;
                        targeteChDocument.Type =
                            (DocumentClassificationType)ClassificationType.GetObject(WellKnownObjects
                                                                                     .DocumentClassification.EchImport.GetObjectID());

                        using (TenantSection.DisableQueryRestrictions())
                            using (var handle = eChExport.ActiveContent.GetContent())
                            {
                                targeteChDocument.ActiveContent.SetContent(handle, "zip", "application/zip");
                            }

                        var targetFile = ImportHelper.TenantKnowsObject(targeteChDocument, true);
                        if (targetFile != null)
                        {
                            incoming.LeadingGroup = targetFile.LeadingGroup;
                            incoming.Insert(targetFile);
                        }
                        else
                        {
                            incoming.LeadingGroup = UserHelper.Current.GetActaNovaUserExtension().StandardGroup != null
                            ? UserHelper.Current.GetActaNovaUserExtension().StandardGroup.AsTenantGroup()
                            : UserHelper.Current.OwningGroup.AsTenantGroup();
                        }

                        ClientTransaction.Current.Commit();
                    }
            }
            catch (Exception ex)
            {
                s_logger.Error(ex.Message);
                throw;
            }
            finally
            {
                ApplicationContext.CurrentID = restoreCtxId;
            }

            return(true);
        }