コード例 #1
0
ファイル: CsvFormatPlug.cs プロジェクト: REALTOBIZ/DbWebApi
        public HttpResponseMessage Respond(ApiController apiController, string sp, IDictionary<string, object> parameters,
			MediaTypeHeaderValue negotiatedMediaType, Encoding negotiatedEncoding)
        {
            HttpResponseMessage csvResponse = apiController.Request.CreateResponse();
            IDictionary<string, string> queryStrings = apiController.Request.GetQueryStringDictionary();
            int[] resultSetChoices = new int[] { GetQueryResultSetIndex(queryStrings, DbWebApiOptions.QueryStringContract.ResultSetParameterName) };

            csvResponse.Content = new PushStreamContent((stream, httpContent, transportContext) =>
            {
                StreamWriter textWriter = (negotiatedEncoding == null) ? new StreamWriter(stream) : new StreamWriter(stream, negotiatedEncoding);

                using (DalCenter dbContext = new DalCenter(queryStrings))
                {
                    CsvExporter csvExporter = new CsvExporter(textWriter);

                    dbContext.ExecuteDbApi(sp, parameters, null,
                        readHeader =>
                        {
                            string[] headers = new string[readHeader.VisibleFieldCount];

                            for (int i = 0; i < headers.Length; i++)
                                headers[i] = dbContext.ResolvePropertyName(readHeader.GetName(i));

                            csvExporter.WriteHeader(headers);
                        },
                        readRow =>
                        {
                            object[] values = new object[readRow.VisibleFieldCount];

                            readRow.GetColumnValues(values);

                            csvExporter.WriteRow(values);
                        },
                        null, null, resultSetChoices);

                    textWriter.Flush();
                }

                stream.Close();
            }, negotiatedMediaType ?? _DefaultMediaType);

            csvResponse.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = queryStrings.GetQueryFileName(DbWebApiOptions.QueryStringContract.FileNameParameterName, FormatShortName) };

            return csvResponse;
        }
コード例 #2
0
        public static int DetectSpChanges(int elapsedMinutes)
        {
            int cntExpired = -1;
            string detectDdlChangesProc = ConfigHelper.DetectDdlChangesProc;

            if (string.IsNullOrEmpty(detectDdlChangesProc) || elapsedMinutes < 1)
                SwitchDerivedParametersCache(false);
            else
            {
                SwitchDerivedParametersCache(true);

                using (DalCenter dbContext = new DalCenter())
                {
                    cntExpired = dbContext.InvalidateAlteredSpFromCache(detectDdlChangesProc, TimeSpan.FromMinutes(elapsedMinutes));
                }

                LastDetectSpChangesTime = DateTime.Now;
            }

            return cntExpired;
        }