Beispiel #1
0
        private static IEnumerator _LoadFromResources(
            XlsxRequest request, _LoadingResult result)
        {
            var             scheme = _GetUriScheme(request.uri) + "://";
            var             path   = request.uri.Substring(scheme.Length);
            ResourceRequest req    = null;
            TextAsset       ta     = null;

            req = Resources.LoadAsync <TextAsset>(path);
            if (req != null)
            {
                while (!req.isDone)
                {
                    result.progress = Mathf.Clamp(
                        req.progress, result.progress, 0.99F
                        );
                    yield return(null);
                }
                result.progress = 1;
                ta = req.asset as TextAsset;
            }
            if (!ta)
            {
                result.error = "Asset not found.";
            }
            else
            {
                result.stream = new MemoryStream(ta.bytes);
            }
            result.progress = 1;
        }
Beispiel #2
0
        private List <Schema> _CreateSchemas(
            XlsxRequest request, int readerIndex)
        {
            var reader   = _readers[readerIndex];
            var schemas  = new List <Schema>();
            var dtsTexts = _MakeDtsTexts(request, reader);

            foreach (var text in dtsTexts)
            {
                var schema = Schema.Parse(
                    readerIndex, requests[readerIndex].uri,
                    reader.sheetIndex, reader.sheetName,
                    text.Key, text.Value
                    );
                if (schema == null)
                {
                    continue;
                }
                if (!schema.isValid || _tables.ContainsKey(schema.name))
                {
                    _erroredSchemas.Add(schema);
                }
                else
                {
                    _tables.Add(schema.name, null);
                    schemas.Add(schema);
                }
            }
            return(schemas);
        }
Beispiel #3
0
        public XlsxRequest SetFieldTypeConverter(IFieldTypeConverter ftc)
        {
            var clone = new XlsxRequest(this);

            clone.fieldTypeConverter = ftc;
            return(clone);
        }
Beispiel #4
0
        public XlsxRequest SetPassword(string password)
        {
            var clone = new XlsxRequest(this);

            clone.password = password;
            return(clone);
        }
Beispiel #5
0
        public XlsxRequest SetWebRequestCreator(
            WebRequestCreator webRequestCreator)
        {
            var clone = new XlsxRequest(this);

            clone.webRequestCreator = webRequestCreator;
            return(clone);
        }
Beispiel #6
0
 internal XlsxRequest(XlsxRequest src)
 {
     this.uri = src.uri;
     this.webRequestCreator  = src.webRequestCreator;
     this.password           = src.password;
     this.fieldTypeConverter = src.fieldTypeConverter;
     this.pdtsTexts          = src.pdtsTexts;
 }
Beispiel #7
0
        private List <KeyValuePair <CellRef, string> > _MakeDtsTexts(
            XlsxRequest request, XlsxReader reader)
        {
            var texts = new List <KeyValuePair <CellRef, string> >();

            foreach (var pdtsText in request.pdtsTexts)
            {
                if (pdtsText.sheetIndex == reader.sheetIndex)
                {
                    texts.Add(new KeyValuePair <CellRef, string>(
                                  pdtsText.cellRef, pdtsText.text
                                  ));
                }
            }
            texts.AddRange(reader.GetCellComments());
            return(texts);
        }
Beispiel #8
0
        public static XlsxRequest[] SetDefaultPassword(
            this XlsxRequest[] src, string password)
        {
            if (src == null)
            {
                throw new System.ArgumentNullException("src");
            }
            var dst = new XlsxRequest[src.Length];

            for (var n = 0; n < dst.Length; ++n)
            {
                dst[n] = src[n];
                if (string.IsNullOrEmpty(dst[n].password))
                {
                    dst[n] = dst[n].SetPassword(password);
                }
            }
            return(dst);
        }
Beispiel #9
0
        public static XlsxRequest[] SetDefaultWebRequestCreator(
            this XlsxRequest[] src, WebRequestCreator webRequestCreator)
        {
            if (src == null)
            {
                throw new System.ArgumentNullException("src");
            }
            var dst = new XlsxRequest[src.Length];

            for (var n = 0; n < dst.Length; ++n)
            {
                dst[n] = src[n];
                if (dst[n].webRequestCreator == null)
                {
                    dst[n] = dst[n].SetWebRequestCreator(webRequestCreator);
                }
            }
            return(dst);
        }
Beispiel #10
0
        public static XlsxRequest[] SetDefaultFieldTypeConverter(
            this XlsxRequest[] src, DataTable.IFieldTypeConverter ftc)
        {
            if (src == null)
            {
                throw new System.ArgumentNullException("src");
            }
            var dst = new XlsxRequest[src.Length];

            for (var n = 0; n < dst.Length; ++n)
            {
                dst[n] = src[n];
                if (dst[n].fieldTypeConverter == null)
                {
                    dst[n] = dst[n].SetFieldTypeConverter(ftc);
                }
            }
            return(dst);
        }
Beispiel #11
0
        public XlsxRequest AddPdtsText(int sheetIndex, string schemaText)
        {
            if (sheetIndex < 0)
            {
                throw new System.ArgumentOutOfRangeException("sheetIndex");
            }
            if (schemaText == null)
            {
                throw new System.ArgumentNullException("schemaText");
            }
            schemaText = schemaText.Trim();
            var clone   = new XlsxRequest(this);
            var schemas = new List <PdtsText>(clone.pdtsTexts);
            var cellRef = new CellRef("PREDEF1");

            cellRef = new CellRef(cellRef.row + schemas.Count, cellRef.col);
            schemas.Add(new PdtsText(sheetIndex, cellRef, schemaText));
            clone.pdtsTexts = schemas.AsReadOnly();
            return(clone);
        }
Beispiel #12
0
        private static IEnumerator _LoadFromWebRequest(
            XlsxRequest request, _LoadingResult result)
        {
            WebRequestCreator createWebRequest = (uri) => {
                WebRequest webReq = null;
                if (request.webRequestCreator != null)
                {
                    webReq = request.webRequestCreator(uri);
                }
                if (webReq == null)
                {
                    webReq = new WebRequest(uri);
                }
                if (webReq.downloadHandler == null)
                {
                    webReq.downloadHandler = new DownloadHandlerBuffer();
                }
                return(webReq);
            };

            using (var webReq = createWebRequest(request.uri)) {
                webReq.SendWebRequest();
                while (!webReq.isDone)
                {
                    result.progress = Mathf.Clamp(
                        webReq.downloadProgress, result.progress, 0.99F
                        );
                    yield return(null);
                }
                if (webReq.isNetworkError || webReq.isHttpError)
                {
                    result.error = webReq.error;
                }
                else
                {
                    var bytes = webReq.downloadHandler.data;
                    result.stream = new MemoryStream(bytes);
                }
            }
            result.progress = 1;
        }
Beispiel #13
0
        private static IEnumerator _LoadFromFile(
            XlsxRequest request, _LoadingResult result)
        {
            var scheme = _GetUriScheme(request.uri);
            var si     = 0;

            if (!string.IsNullOrEmpty(scheme))
            {
                si = (scheme + "://").Length;
            }
            var path = request.uri;

            switch (scheme)
            {
            case "data": path = Application.dataPath; break;

            case "pdata": path = Application.persistentDataPath; break;
            }
            if (si > 0)
            {
                path += "/" + request.uri.Substring(si);
            }
            if (File.Exists(path))
            {
                result.stream = new FileStream(path,
                                               FileMode.Open, FileAccess.Read, FileShare.ReadWrite
                                               );
            }
            else
            {
                result.stream = null;
                result.error  = "File not found.";
            }
            result.progress = 1;
            yield break;
        }