Пример #1
0
        public static long ExportCatalogUpdates(IRFProcessingContext context, string path, RFDate startDate, RFDate?endDate = null, string password = null)
        {
            long c = 0;

            var keysInScope = context.SearchKeys(typeof(RFCatalogKey), startDate, endDate, 99999, null, false).Where(k => k.IsValid && k.Key.Plane == RFPlane.User).ToList();

            foreach (var keyDate in keysInScope.GroupBy(k => k.UpdateTime.Date))
            {
                var fileName = Path.Combine(path, String.Format("RIFF_{0}_Updates_{1}.zip", context.Environment, keyDate.Key.ToString("yyyyMMdd")));

                context.SystemLog.Info(typeof(RFCatalogMaintainer), "Exporting {0} documents into {1}", keyDate.Count(), fileName);

                var  exportableDocuments = new Dictionary <string, byte[]>();
                long cnt = 1;
                foreach (var key in keyDate)
                {
                    var doc = context.LoadEntry(key.Key) as RFDocument;
                    if (doc != null)
                    {
                        var docName = RFFileHelpers.SanitizeFileName(string.Format("{0}_{1}_{2}_{3}_{4}.xml",
                                                                                   doc.Key.GraphInstance?.ValueDate?.ToString() ?? "none",
                                                                                   doc.Key.GraphInstance?.Name ?? "none",
                                                                                   doc.Key.GetType().Name,
                                                                                   doc.Key.FriendlyString(),
                                                                                   cnt++));
                        exportableDocuments.Add(docName, Encoding.UTF8.GetBytes(RFXMLSerializer.PrettySerializeContract(doc)));
                        c++;
                    }
                }
                ZIPUtils.ZipFiles(fileName, exportableDocuments, password);
            }
            return(c);
        }
Пример #2
0
        public FileResult GetProcessDomain(string processName, string instanceName, DateTime?instanceDate)
        {
            using (var activity = new RFEngineActivity(Context, EngineConfig))
            {
                RFGraphProcessorDomain domain = null;
                var engineConfig  = activity.GetEngineConfig();
                var graphInstance = new RFGraphInstance
                {
                    Name      = string.IsNullOrWhiteSpace(instanceName) ? null : instanceName,
                    ValueDate = instanceDate.HasValue ? new RFDate(instanceDate.Value.Date) : RFDate.NullDate
                };

                foreach (var graph in engineConfig.Graphs.Values)
                {
                    var process = graph.Processes.Values.FirstOrDefault(p => RFGraphDefinition.GetFullName(graph.GraphName, p.Name) == processName);
                    if (process != null)
                    {
                        var processor = process.Processor();
                        domain = processor.CreateDomain();
                        if (domain != null)
                        {
                            foreach (var propertyInfo in domain.GetType().GetProperties())
                            {
                                var          ioBehaviourAttribute = (propertyInfo.GetCustomAttributes(typeof(RFIOBehaviourAttribute), true).FirstOrDefault() as RFIOBehaviourAttribute);
                                RFCatalogKey ioKey = null;
                                if (ioBehaviourAttribute != null)
                                {
                                    var ioBehaviour = ioBehaviourAttribute.IOBehaviour;
                                    var ioMapping   = process.IOMappings.FirstOrDefault(m => m.PropertyName == propertyInfo.Name);
                                    if (ioMapping != null)
                                    {
                                        ioKey = ioMapping.Key.CreateForInstance(graphInstance);
                                        var options = RFGraphInstance.ImplyOptions(ioMapping);
                                        var entry   = Context.LoadEntry(ioKey, options) as RFDocument;
                                        if (entry != null)
                                        {
                                            propertyInfo.SetValue(domain, entry.Content);
                                        }
                                    }
                                }
                            }
                        }
                        break;
                    }
                }

                if (domain != null)
                {
                    var xmlString = RFXMLSerializer.PrettySerializeContract(domain);
                    return(File(
                               Encoding.UTF8.GetBytes(xmlString),
                               "text/xml",
                               String.Format("{0}_{1}_{2}.xml", processName, instanceName ?? String.Empty, instanceDate.Value.ToString("yyyy-MM-dd"))
                               ));
                }
            }
            return(null);
        }
Пример #3
0
        public FileResult DownloadEntry(string type, long keyReference)
        {
            using (var dataEditor = new RFDataEditorActivity(Context, Username))
            {
                var entry = dataEditor.GetDocumentForDownload(type, keyReference);
                if (entry != null)
                {
                    var shortType = System.IO.Path.GetExtension(type).TrimStart('.');
                    var content   = entry.Content;
                    if (content is IRFDataSet)
                    {
                        var namePart = entry.Key.FriendlyString();
                        Array.ForEach(Path.GetInvalidFileNameChars(), c => namePart = namePart.Replace(c.ToString(), String.Empty));
                        var date = (entry.Key.GraphInstance != null ? entry.Key.GraphInstance.ValueDate : null) ?? DateTime.Now;

                        return(File(RIFF.Interfaces.Formats.XLSX.XLSXGenerator.ExportToXLSX(type, content as IRFDataSet), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
                                    String.Format("{0}_{3}-{1}-{2}.xlsx", namePart, shortType, keyReference, date.ToString("yyyyMMdd"))));
                    }
                    else if (entry.Content is RFFile)
                    {
                        var file = entry.Content as RFFile;
                        return(File(file.Data, ImplyContentType(file.ContentName), file.Attributes.FileName));
                    }
                    else if (entry.Content is RFRawReport)
                    {
                        var report     = entry.Content as RFRawReport;
                        var csvBuilder = new StringBuilder();
                        foreach (var section in report.Sections)
                        {
                            try
                            {
                                csvBuilder.Append(CSVBuilder.FromDataTable(section.AsDataTable()));
                            }
                            catch (Exception ex)
                            {
                                Log.Warning(this, "Error exporting section {0} of report {1} to .csv: {2}", section.Name, report.ReportCode, ex.Message);
                            }
                        }
                        return(File(Encoding.UTF8.GetBytes(csvBuilder.ToString()), "text/csv", String.Format("{0}_{1}.csv", report.ReportCode, report.ValueDate.ToString("yyyy-MM-dd"))));
                    }
                    else
                    {
                        var namePart = entry.Key.FriendlyString();
                        Array.ForEach(Path.GetInvalidFileNameChars(), c => namePart = namePart.Replace(c.ToString(), String.Empty));
                        var date = (entry.Key.GraphInstance != null ? entry.Key.GraphInstance.ValueDate : null) ?? DateTime.Now;

                        var xml = RFXMLSerializer.PrettySerializeContract(content);
                        return(File(Encoding.UTF8.GetBytes(xml), "text/xml", String.Format("{0}_{3}-{1}-{2}.xml", namePart, shortType, keyReference, date.ToString("yyyyMMdd"))));
                    }
                }
            }
            return(null);
        }
Пример #4
0
 public FileResult ExportEntry(string type, long keyReference)
 {
     using (var dataEditor = new RFDataEditorActivity(Context, Username))
     {
         var entry = dataEditor.GetDocumentForDownload(type, keyReference);
         if (entry != null)
         {
             var shortType = System.IO.Path.GetExtension(type).TrimStart('.');
             var xml       = RFXMLSerializer.PrettySerializeContract(entry);
             return(File(Encoding.UTF8.GetBytes(xml), "text/xml", String.Format("RFDocument_{0}-{1}-{2}.xml", shortType, keyReference, DateTime.Now.ToString("yyyyMMdd_HHmmss"))));
         }
     }
     return(null);
 }
        public object GetDocumentForEdit(string type, long keyReference)
        {
            var entry = GetDocumentForDownload(type, keyReference);

            if (entry != null)
            {
                return(new
                {
                    Key = RFXMLSerializer.PrettySerializeContract(entry.Key),
                    Content = RFXMLSerializer.PrettySerializeContract(entry.Content)
                });
            }
            return(null);
        }
Пример #6
0
        public void SerializationTests()
        {
            // type-aware serialization
            var testDoc           = CreateTestDocument();
            var reserializeText   = RFXMLSerializer.DeserializeContract(typeof(TestDocument).FullName, RFXMLSerializer.PrettySerializeContract(testDoc));
            var reserializeBinary = RFXMLSerializer.BinaryDeserializeContract(typeof(TestDocument).FullName, RFXMLSerializer.BinarySerializeContract(testDoc));

            CompareTestDoc(reserializeText as TestDocument);
            CompareTestDoc(reserializeBinary as TestDocument);

            // generic XML serialization, we reserialize to avoid namespace declaration order issues
            var originalXmlString = RFXMLSerializer.BinaryDeserializeXML(RFXMLSerializer.BinarySerializeContract(testDoc));

            Assert.True(originalXmlString.NotBlank());
            Assert.True(originalXmlString.Length > 500);
            var binaryRepresentation  = RFXMLSerializer.BinarySerializeXML(originalXmlString);
            var reserializedXmlString = RFXMLSerializer.BinaryDeserializeXML(binaryRepresentation);

            Assert.Equal(originalXmlString, reserializedXmlString);
        }