public SpreadsheetConfiguration ProcessConfiguration(SpreadsheetConfiguration configuration, Stream inputFile)
 {
     using (InitializeProvider(configuration))
     {
         return(_provider.ProcessConfiguration(configuration, inputFile));
     }
 }
        public ActionResult UpdateConfiguration(FormCollection form)
        {
            SpreadsheetConfiguration configuration = GetConfiguration(form["context"], form["endpoint"]);

            if (configuration != null)
            {
                foreach (SpreadsheetTable workSheet in configuration.Tables)
                {
                    if (workSheet.Name == form["Name"])
                    {
                        workSheet.Label = form["Label"];
                    }
                    if (workSheet.Columns != null)
                    {
                        foreach (SpreadsheetColumn column in workSheet.Columns)
                        {
                            if (column.Name == form["Name"])
                            {
                                column.Label = form["Label"];
                            }
                        }
                    }
                }
                _repository.Configure(form["context"], form["endpoint"], form["datalayer"], configuration, null);
                return(Json(new { success = true }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(new { success = false }, JsonRequestBehavior.AllowGet));
            }
        }
        public JsonResult Upload(FormCollection form)
        {
            try
            {
                string datalayer     = "org.iringtools.adapter.datalayer.SpreadsheetDatalayer, SpreadsheetDatalayer";
                string savedFileName = string.Empty;

                HttpFileCollectionBase files = Request.Files;

                foreach (string file in files)
                {
                    HttpPostedFileBase hpf = files[file] as HttpPostedFileBase;
                    if (hpf.ContentLength == 0)
                    {
                        continue;
                    }
                    string fileLocation = string.Format(@"{0}SpreadsheetData.{1}.{2}.xlsx", _settings["AppDataPath"], form["Scope"], form["Application"]);


                    SpreadsheetConfiguration configuration = new SpreadsheetConfiguration()
                    {
                        Location = fileLocation
                    };

                    if (form["Generate"] != null)
                    {
                        configuration.Generate = true;
                        configuration          = _repository.ProcessConfiguration(configuration, hpf.InputStream);
                        hpf.InputStream.Flush();
                        hpf.InputStream.Position = 0;
                        _repository.Configure(form["Scope"], form["Application"], datalayer, configuration, hpf.InputStream);
                    }
                    else
                    {
                        configuration.Generate = false;
                        configuration          = _repository.ProcessConfiguration(configuration, hpf.InputStream);
                    }

                    SetConfiguration(form["Scope"], form["Application"], configuration);

                    //break;
                }
            }
            catch (Exception ex)
            {
                ;
                return(new JsonResult()
                {
                    ContentType = "text/html",
                    Data = PrepareErrorResponse(ex)
                });
            }
            return(new JsonResult()
            {
                ContentType = "text/html",
                Data = new { success = true }
            });
        }
 public SpreadsheetConfiguration GetConfiguration()
 {
     if (_configuration == null)
     {
         _configuration = new SpreadsheetConfiguration()
         {
             Tables = new List <SpreadsheetTable>()
         }
     }
     ;
     return(_configuration);
 }
        public List <WorksheetPart> GetWorksheets(SpreadsheetConfiguration configuration)
        {
            List <WorksheetPart> wp = new List <WorksheetPart>();

            using (InitializeProvider(configuration))
            {
                foreach (SpreadsheetTable st in configuration.Tables)
                {
                    wp.Add(_provider.GetWorksheetPart(st));
                }
                return(wp);
            }
        }
 private SpreadsheetProvider InitializeProvider(SpreadsheetConfiguration configuration)
 {
     try
     {
         if (_provider == null)
         {
             _provider = new SpreadsheetProvider(configuration);
         }
     }
     catch (Exception ex)
     {
         PrepareErrorResponse(ex);
     }
     return(_provider);
 }
 public List <SpreadsheetColumn> GetColumns(SpreadsheetConfiguration configuration, string worksheetName)
 {
     using (InitializeProvider(configuration))
     {
         SpreadsheetTable table = configuration.Tables.Find(c => c.Name == worksheetName);
         if (table != null)
         {
             return(_provider.GetColumns(table));
         }
         else
         {
             return(new List <SpreadsheetColumn>());
         }
     }
 }
        public void Configure(string context, string endpoint, string datalayer, SpreadsheetConfiguration configuration, Stream inputFile)
        {
            try
            {
                using (InitializeProvider(configuration))
                {
                    List <MultiPartMessage> requestMessages = new List <MultiPartMessage>();

                    if (datalayer != null)
                    {
                        requestMessages.Add(new MultiPartMessage
                        {
                            name    = "DataLayer",
                            message = datalayer,
                            type    = MultipartMessageType.FormData
                        });

                        requestMessages.Add(new MultiPartMessage
                        {
                            name    = "Configuration",
                            message = Utility.Serialize <XElement>(Utility.SerializeToXElement(configuration), true),
                            type    = MultipartMessageType.FormData
                        });
                        if (inputFile != null)
                        {
                            inputFile.Position = 0;
                            requestMessages.Add(new MultiPartMessage
                            {
                                name     = "SourceFile",
                                fileName = configuration.Location,
                                message  = inputFile,
                                //mimeType = "application/zip",
                                mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
                                type     = MultipartMessageType.File
                            });
                            inputFile.Flush();
                        }

                        string response = String.Empty;
                        _client.PostMultipartMessage(string.Format("/{0}/{1}/configure", context, endpoint), requestMessages, ref response);
                    }
                }
            }
            catch (Exception ex)
            {
                PrepareErrorResponse(ex);
            }
        }
        public SpreadsheetProvider(AdapterSettings settings)
        {
            _settings          = settings;
            _configurationPath = Path.Combine(_settings["AppDataPath"], "spreadsheet-configuration." + _settings["Scope"] + ".xml");

            if (File.Exists(_configurationPath))
            {
                InitializeProvider(Utility.Read <SpreadsheetConfiguration>(_configurationPath));

                if (_configuration.Generate)
                {
                    _configuration          = ProcessConfiguration(_configuration, null);
                    _configuration.Generate = false;
                    Utility.Write <SpreadsheetConfiguration>(_configuration, _configurationPath, true);
                }
            }
        }
        public SpreadsheetConfiguration GetConfiguration(string scope, string application)
        {
            SpreadsheetConfiguration obj = null;

            try
            {
                XElement element = _client.Get <XElement>(string.Format("/{0}/{1}/configuration", scope, application));
                if (!element.IsEmpty)
                {
                    obj = Utility.DeserializeFromXElement <SpreadsheetConfiguration>(element);
                }
            }
            catch (Exception ex)
            {
                PrepareErrorResponse(ex);
            }

            return(obj);
        }
        public override Response Configure(XElement configuration)
        {
            Response resp = new Response()
            {
                StatusList = new List <Status>()
            };

            try
            {
                SpreadsheetConfiguration config = Utility.DeserializeFromXElement <SpreadsheetConfiguration>(configuration);
                string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, _settings["AppDataPath"], string.Format("spreadsheet-configuration.{0}.xml", _settings["scope"]));
                Utility.Write <SpreadsheetConfiguration>(config, path, true);
            }
            catch (Exception)
            {
                Status stat = new Status {
                    Level = StatusLevel.Error
                };
                resp.StatusList.Add(stat);
            }
            return(resp);
        }
        public JsonResult Configure(FormCollection form)
        {
            SpreadsheetConfiguration configuration = GetConfiguration(form["Scope"], form["Application"]);

            if (configuration != null)
            {
                _repository.Configure(form["Scope"], form["Application"], form["DataLayer"], configuration, null);
                return(new JsonResult() //(6)
                {
                    ContentType = "text/html",
                    Data = new { success = true }
                });
            }

            else
            {
                return(new JsonResult() //(6)
                {
                    ContentType = "text/html",
                    Data = new { success = false }
                });
            }
        }
Example #13
0
        public void InitializeProvider(SpreadsheetConfiguration configuration)
        {
            if (configuration != null)
            {
                _configuration = configuration;

                if (File.Exists(_configuration.Location))
                {
                    // if (_stream == null) _stream = OpenStream(_configuration.Location);
                    if (_document == null)
                    {
                        _document = GetDocument(_configuration.Location);
                    }
                    if (_configuration.Generate)
                    {
                        _configuration          = ProcessConfiguration(_configuration, null);
                        _configuration.Generate = false;
                        Utility.Write <SpreadsheetConfiguration>(_configuration, _configurationPath, true);
                    }

                    Dispose();
                }
            }
        }
        private void SetConfiguration(string context, string endpoint, SpreadsheetConfiguration configuration)
        {
            string key = string.Format(_keyFormat, context, endpoint);

            Session[key] = configuration;
        }
Example #15
0
        //private Stream _stream = null;

        public SpreadsheetProvider(SpreadsheetConfiguration configuration)
        {
            InitializeProvider(configuration);
        }
Example #16
0
        public SpreadsheetConfiguration ProcessConfiguration(SpreadsheetConfiguration configuration, Stream inputFile)
        {
            Dispose();
            List <SpreadsheetTable> tables = new List <SpreadsheetTable>();

            if (inputFile == null)
            {
                _document = GetDocument(_configuration.Location);
            }
            else
            {
                _document = SpreadsheetDocument.Open(inputFile, false);

                //C:\iring-tools\branches\2.4.x
                //_document = SpreadsheetDocument.Open("C:\\iring-tools\\branches\\2.4.x\\Test890.xlsx", false);
            }
            DefinedNames definedNames = _document.WorkbookPart.Workbook.DefinedNames;

            if (definedNames != null)
            {
                foreach (DefinedName definedName in definedNames)
                {
                    SpreadsheetTable table = new SpreadsheetTable
                    {
                        TableType = TableType.DefinedName,
                        Name      = definedName.Name,
                        Label     = definedName.Name,
                        Reference = definedName.InnerText,
                        HeaderRow = 1
                    };
                    table.Columns    = GetColumns(table);
                    table.Identifier = table.Columns[0].Name;

                    tables.Add(table);
                }
            }

            Sheets sheets = _document.WorkbookPart.Workbook.Sheets;

            if (sheets != null)
            {
                foreach (Sheet sheet in sheets)
                {
                    if (sheet.Name.InnerText.StartsWith("Sheet"))
                    {
                        continue;
                    }
                    WorksheetPart    worksheetPart = (WorksheetPart)_document.WorkbookPart.GetPartById(sheet.Id);
                    SpreadsheetTable table         = new SpreadsheetTable
                    {
                        TableType = TableType.Worksheet,
                        Name      = sheet.Name,
                        Label     = sheet.Name,
                        Reference = string.Format("'{0}!'{1}", sheet.Name, worksheetPart.Worksheet.SheetDimension.Reference),
                        HeaderRow = 1
                    };

                    table.Columns    = GetColumns(table);
                    table.Identifier = table.Columns[0].Name;

                    tables.Add(table);
                }
            }
            configuration.Tables = tables;
            return(configuration);
        }
        public override XElement GetConfiguration()
        {
            SpreadsheetConfiguration sc = _provider.GetConfiguration();

            return(Utility.SerializeToXElement <SpreadsheetConfiguration>(sc));
        }
        public JsonResult GetNode(FormCollection form)
        {
            List <JsonTreeNode> nodes = new List <JsonTreeNode>();

            if (_repository != null)
            {
                SpreadsheetConfiguration configuration = GetConfiguration(form["scope"], form["application"]);

                if (configuration != null)
                {
                    switch (form["type"])
                    {
                    case "ExcelWorkbookNode":
                    {
                        List <SpreadsheetTable> worksheets = configuration.Tables;

                        if (worksheets != null)
                        {
                            foreach (SpreadsheetTable worksheet in worksheets)
                            {
                                List <JsonTreeNode> columnNodes       = new List <JsonTreeNode>();
                                JsonTreeNode        keyIdentifierNode = new JsonTreeNode()
                                {
                                    text     = "Identifier",
                                    type     = "Identifier",
                                    expanded = true,
                                    leaf     = false,
                                    children = new List <JsonTreeNode>()
                                };

                                JsonTreeNode dataPropertiesNode = new JsonTreeNode()
                                {
                                    text     = "Columns",
                                    type     = "columns",
                                    expanded = true,
                                    leaf     = false,
                                    children = new List <JsonTreeNode>()
                                };

                                JsonTreeNode dataObjectNode = new JsonTreeNode()
                                {
                                    nodeType = "async",
                                    type     = "ExcelWorksheetNode",
                                    icon     = "Content/img/excelworksheet.png",
                                    id       = worksheet.Name,
                                    text     = worksheet.Name.Equals(worksheet.Label) ? worksheet.Name : string.Format("{0} [{1}]", worksheet.Name, worksheet.Label),
                                    expanded = false,
                                    leaf     = false,
                                    children = new List <JsonTreeNode>()
                                    {
                                        keyIdentifierNode, dataPropertiesNode
                                    },
                                    record = worksheet
                                };

                                columnNodes.Add(dataPropertiesNode);

                                if (worksheet.Columns != null)
                                {
                                    foreach (SpreadsheetColumn column in worksheet.Columns)
                                    {
                                        if (column.Name.ToUpper() == worksheet.Identifier.ToUpper())
                                        {
                                            JsonTreeNode keyNode = new JsonTreeNode
                                            {
                                                nodeType = "async",
                                                type     = "ExcelColumnNode",
                                                icon     = "Content/img/excelcolumn.png",
                                                id       = worksheet.Name + "/" + column.Name,
                                                text     = column.Name.Equals(column.Label) ? column.Name : string.Format("{0} [{1}]", column.Name, column.Label),
                                                expanded = false,
                                                leaf     = true,
                                                children = null,
                                                record   = new
                                                {
                                                    Datatype = column.DataType.ToString(),
                                                    Index    = column.ColumnIdx,
                                                    Label    = column.Label.ToString(),
                                                    Name     = column.Name.ToString()
                                                }
                                            };
                                            keyIdentifierNode.children.Add(keyNode);
                                        }
                                        else
                                        {
                                            JsonTreeNode columnNode = new JsonTreeNode
                                            {
                                                nodeType = "async",
                                                type     = "ExcelColumnNode",
                                                icon     = "Content/img/excelcolumn.png",
                                                id       = worksheet.Name + "/" + column.Name,
                                                text     = column.Name.Equals(column.Label) ? column.Name : string.Format("{0} [{1}]", column.Name, column.Label),
                                                expanded = false,
                                                leaf     = true,
                                                children = null,
                                                // record = column
                                                record = new
                                                {
                                                    Datatype = column.DataType.ToString(),
                                                    Index    = column.ColumnIdx,
                                                    Label    = column.Label.ToString(),
                                                    Name     = column.Name.ToString()
                                                }
                                            };

                                            dataPropertiesNode.children.Add(columnNode);
                                        }
                                    }
                                    nodes.Add(dataObjectNode);
                                }
                            }
                        }

                        break;
                    }
                    }
                }
            }

            return(Json(nodes, JsonRequestBehavior.AllowGet));
        }