Пример #1
0
        /// <summary>
        /// Removes links between document and employees in SAP.
        /// NOT USED!
        /// </summary>
        /// <param name="env"></param>
        /// <param name="deletedIDs">List of employee IDs to be removed.</param>
        private void removeLinks(EventHandlerEnvironment env, IEnumerable <string> deletedIDs, SAPDataSource source)
        {
            foreach (string employeeID in deletedIDs)
            {
                string documentID = env.ObjVerEx.Properties.GetProperty(DocumentIDProperty).GetValueAsLocalizedText();
                string repository = env.ObjVerEx.Properties.GetProperty(ContentRepositoryProperty).GetValueAsUnlocalizedText();

                // Remove the link with RFC function
                IRfcFunction rfcFunction = SAPHelper.CreateFunction("ARCHIV_DELETE_META", source.getDestination());                    // Not usable outside SAP
                rfcFunction.SetValue("ARCHIV_ID", repository);
                rfcFunction.SetValue("SAP_OBJECT", "PREL");
                rfcFunction.SetValue("ARC_DOC_ID", documentID);
                rfcFunction.SetValue("OBJECT_ID", employeeID);
                try
                {
                    string result  = SAPHelper.InvokeRFC(rfcFunction, source.getDestination());
                    string message = "Removed link between document: " + documentID + "\n" +
                                     "and employee: " + employeeID + "\n" +
                                     result;
                    SysUtils.ReportInfoToEventLog(message);
                }
                catch (Exception ex)
                {
                    SysUtils.ReportErrorToEventLog("SAPDocumentConnector", ex.Message, ex);
                    throw new RfcInvalidParameterException(ex.Message);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Creates links between document and employees in SAP.
        /// </summary>
        /// <param name="env"></param>
        /// <param name="documentType"></param>
        /// <param name="newSAPObjects"></param>
        private void createLinks(StateEnvironment env, string documentType, string SAPObjectType, IEnumerable <string> newSAPObjects, SAPDataSource source)
        {
            foreach (string employeeID in newSAPObjects)
            {
                // Generate and set SAP properties
                string documentID = GUIDToDocumentID(env);
                env.ObjVerEx.Properties.SetProperty(DocumentIDProperty, MFDataType.MFDatatypeText, documentID);

                // Set properties required by SAP
                env.ObjVerEx.Properties.SetProperty(ComponentPropertiesProperty, MFDataType.MFDatatypeMultiLineText,
                                                    "ComponentID=data|ContentType=application/pdf|FileID=" + GetFileID(env) +
                                                    "|Filename=data.pdf|ADate=" + GetSAPDateFromTS(env.ObjVerEx.GetProperty(20).Value.GetValueAsTimestamp().UtcToLocalTime()) +
                                                    "|ATime=" + GetSAPTimeFromTS(env.ObjVerEx.GetProperty(20).Value.GetValueAsTimestamp().UtcToLocalTime()) +
                                                    "|MDate=" + GetSAPDateFromTS(env.ObjVerEx.GetProperty(21).Value.GetValueAsTimestamp().UtcToLocalTime()) +
                                                    "|MTime=" + GetSAPTimeFromTS(env.ObjVerEx.GetProperty(21).Value.GetValueAsTimestamp().UtcToLocalTime()) +
                                                    "|AppVer=|Charset=");
                env.ObjVerEx.SetProperty(DocumentProtectionProperty, MFDataType.MFDatatypeText, "rud");
                env.ObjVerEx.SetProperty(ArchiveLinkVersionProperty, MFDataType.MFDatatypeText, "0046");

                // Save properties
                env.ObjVerEx.SaveProperties();

                // Get SAP repository
                if (env.ObjVerEx.Properties.GetProperty(ContentRepositoryProperty) == null)
                {
                    throw new Exception("No SAP repository defined.");
                }
                string repository = env.ObjVerEx.Properties.GetProperty(ContentRepositoryProperty).GetValueAsUnlocalizedText();

                // Get filename
                string fileName = env.ObjVerEx.Title;

                // Get description
                string        description = "";
                PropertyValue descProp;
                if (env.ObjVerEx.Properties.TryGetProperty(DocumentDescriptionProperty, out descProp))
                {
                    description = descProp.GetValueAsLocalizedText();
                }

                // Do the link with RFC function
                IRfcFunction rfcFunction = SAPHelper.CreateFunction("ARCHIV_CONNECTION_INSERT", source.getDestination());
                rfcFunction.SetValue("ARCHIV_ID", repository);
                rfcFunction.SetValue("AR_OBJECT", documentType);
                rfcFunction.SetValue("SAP_OBJECT", SAPObjectType);
                rfcFunction.SetValue("ARC_DOC_ID", documentID);
                rfcFunction.SetValue("OBJECT_ID", employeeID);

                // Is the file info in use
                if (config.UseFileInfo == "true")
                {
                    rfcFunction.SetValue("FILENAME", fileName);
                    rfcFunction.SetValue("DESCR", description);
                    rfcFunction.SetValue("CREATOR", employeeID);
                }

                //
                try
                {
                    string result  = SAPHelper.InvokeRFC(rfcFunction, source.getDestination());
                    string message = "Linked document: " + documentID + ", type: " + documentType + "\n" +
                                     "with SAP object: " + employeeID + ", type: " + SAPObjectType + "\n" +
                                     "Filename: " + fileName + ", Description: " + description + "\n" +
                                     result;
                    SysUtils.ReportInfoToEventLog(message);
                }
                catch (Exception ex)
                {
                    // Show failed FRC call in Event viewer.
                    StringBuilder message = new StringBuilder()
                                            .AppendLine("ARCHIV_CONNECTION_INSERT")
                                            .AppendFormat(" - ARCHIV_ID: '{0}'", repository).AppendLine()
                                            .AppendFormat(" - AR_OBJECT: '{0}'", documentType).AppendLine()
                                            .AppendFormat(" - SAP_OBJECT: '{0}'", SAPObjectType).AppendLine()
                                            .AppendFormat(" - ARC_DOC_ID: '{0}'", documentID).AppendLine()
                                            .AppendFormat(" - OBJECT_ID: '{0}'", employeeID).AppendLine();
                    if (config.UseFileInfo == "true")
                    {
                        message
                        .AppendFormat(" - FILENAME: '{0}'", fileName).AppendLine()
                        .AppendFormat(" - DESCR: '{0}'", description).AppendLine()
                        .AppendFormat(" - CREATOR: '{0}'", employeeID).AppendLine();
                    }
                    message.AppendLine().AppendLine(ex.Message);
                    SysUtils.ReportErrorToEventLog("SAPDocumentConnector", message.ToString(), ex);

                    throw new RfcInvalidParameterException(ex.Message);
                }
            }
        }