private String ExportToExcel(String schema)
        {
            InvokeResultDescriptor result = new InvokeResultDescriptor();
            String res = String.Empty;
            try
            {
                String sessionId = String.Empty;
                String connection = String.Empty;
                try
                {
                    MdxQueryArgs args = XmlSerializationUtility.XmlStr2Obj<MdxQueryArgs>(schema);
                    if (args != null)
                    {
                        sessionId = args.SessionId;
                        connection = args.Connection;
                        DefaultQueryExecuter queryExecuter = new DefaultQueryExecuter(GetConnection(args.Connection));
                        if (args.Queries.Count > 0)
                        {
                            res = queryExecuter.GetCellSetDescription(args.Queries[0], ref sessionId);
                        }
                    }
                }
                catch (AdomdConnectionException connection_ex)
                {
                    result.Content = connection_ex.Message;
                    result.ContentType = InvokeContentType.Error;
                }
                catch (AdomdErrorResponseException response_ex)
                {
                    result.Content = response_ex.Message;
                    result.ContentType = InvokeContentType.Error;
                }
                catch (AdomdUnknownResponseException unknown_ex)
                {
                    result.Content = unknown_ex.Message;
                    result.ContentType = InvokeContentType.Error;
                }
                catch (InvalidOperationException invalid_ex)
                {
                    result.Content = invalid_ex.Message;
                    result.ContentType = InvokeContentType.Error;
                }

                if (!String.IsNullOrEmpty(res))
                {
                    CellSetData cs = CellSetData.Deserialize(res);
                    PivotDataProvider pivotProvider = new PivotDataProvider(new CellSetDataProvider(cs));
                    res = ExportHelper.ExportToExcel(pivotProvider);
                }

                result.Content = res;
                if (UseCompress)
                {
                    // Архивация строки
                    String compesed = ZipCompressor.CompressAndConvertToBase64String(res);
                    result.Content = compesed;
                    result.IsArchive = true;
                }
                result.ContentType = InvokeContentType.MultidimData;
                result.Headers.Add(new Header(InvokeResultDescriptor.SESSION_ID, sessionId));
                result.Headers.Add(new Header(InvokeResultDescriptor.CONNECTION_ID, connection));
            }
            catch (Exception)
            {
                throw;
            }
            return InvokeResultDescriptor.Serialize(result);
        }
Example #2
0
        private String ExportToExcel(String schema)
        {
            InvokeResultDescriptor result = new InvokeResultDescriptor();
            String res = String.Empty;

            try
            {
                String sessionId  = String.Empty;
                String connection = String.Empty;
                try
                {
                    MdxQueryArgs args = XmlSerializationUtility.XmlStr2Obj <MdxQueryArgs>(schema);
                    if (args != null)
                    {
                        sessionId  = args.SessionId;
                        connection = args.Connection;
                        DefaultQueryExecuter queryExecuter = new DefaultQueryExecuter(GetConnection(args.Connection));
                        if (args.Queries.Count > 0)
                        {
                            res = queryExecuter.GetCellSetDescription(args.Queries[0], ref sessionId);
                        }
                    }
                }
                catch (AdomdConnectionException connection_ex)
                {
                    result.Content     = connection_ex.Message;
                    result.ContentType = InvokeContentType.Error;
                }
                catch (AdomdErrorResponseException response_ex)
                {
                    result.Content     = response_ex.Message;
                    result.ContentType = InvokeContentType.Error;
                }
                catch (AdomdUnknownResponseException unknown_ex)
                {
                    result.Content     = unknown_ex.Message;
                    result.ContentType = InvokeContentType.Error;
                }
                catch (InvalidOperationException invalid_ex)
                {
                    result.Content     = invalid_ex.Message;
                    result.ContentType = InvokeContentType.Error;
                }

                if (!String.IsNullOrEmpty(res))
                {
                    CellSetData       cs            = CellSetData.Deserialize(res);
                    PivotDataProvider pivotProvider = new PivotDataProvider(new CellSetDataProvider(cs));
                    res = ExportHelper.ExportToExcel(pivotProvider);
                }

                result.Content = res;
                if (UseCompress)
                {
                    // Архивация строки
                    String compesed = ZipCompressor.CompressAndConvertToBase64String(res);
                    result.Content   = compesed;
                    result.IsArchive = true;
                }
                result.ContentType = InvokeContentType.MultidimData;
                result.Headers.Add(new Header(InvokeResultDescriptor.SESSION_ID, sessionId));
                result.Headers.Add(new Header(InvokeResultDescriptor.CONNECTION_ID, connection));
            }
            catch (Exception)
            {
                throw;
            }
            return(InvokeResultDescriptor.Serialize(result));
        }
        String ExecuteQuery(String schema)
        {
            InvokeResultDescriptor result = new InvokeResultDescriptor();
            String res = String.Empty;
            try
            {
                String sessionId = String.Empty;
                MdxQueryArgs args = XmlSerializationUtility.XmlStr2Obj<MdxQueryArgs>(schema);
                if (args != null)
                {
                    sessionId = args.SessionId;
                    DefaultQueryExecuter queryExecuter = new DefaultQueryExecuter(GetConnection(args.Connection));
                    if (args.Queries.Count > 0)
                    {
                        result.ContentType = InvokeContentType.MultidimData;

                        switch (args.Type)
                        {
                            case QueryTypes.Update:
                            case QueryTypes.CommitTransaction:
                            case QueryTypes.RollbackTransaction:
                                List<String> results = new List<String>();
                                result.ContentType = InvokeContentType.UpdateResult;
                                foreach (var query in args.Queries)
                                {
                                    try
                                    {
                                        // Method return a value of one (1). 
                                        queryExecuter.ExecuteNonQuery(query, ref sessionId);
                                        results.Add(String.Empty);
                                    }
                                    catch (AdomdConnectionException connection_ex)
                                    {
                                        results.Add(connection_ex.Message);
                                    }
                                    catch (AdomdErrorResponseException response_ex)
                                    {
                                        results.Add(response_ex.Message);
                                    }
                                    catch (AdomdUnknownResponseException unknown_ex)
                                    {
                                        results.Add(unknown_ex.Message);
                                    }
                                    catch(InvalidOperationException invalid_ex)
                                    {
                                        results.Add(invalid_ex.Message);
                                    }
                                }
                                res = XmlSerializationUtility.Obj2XmlStr(results, Common.Namespace);
                                break;
                            case QueryTypes.Select:
                                try
                                {
                                    res = queryExecuter.GetCellSetDescription(args.Queries[0], ref sessionId);
                                }
                                catch (AdomdConnectionException connection_ex)
                                {
                                    res = connection_ex.Message;
                                    result.ContentType = InvokeContentType.Error;
                                }
                                catch (AdomdErrorResponseException response_ex)
                                {
                                    res = response_ex.Message;
                                    result.ContentType = InvokeContentType.Error;
                                }
                                catch (AdomdUnknownResponseException unknown_ex)
                                {
                                    res = unknown_ex.Message;
                                    result.ContentType = InvokeContentType.Error;
                                }
                                catch (InvalidOperationException invalid_ex)
                                {
                                    res = invalid_ex.Message;
                                    result.ContentType = InvokeContentType.Error;
                                }
                                break;
                            case QueryTypes.DrillThrough:
                                try
                                {
                                    var table = queryExecuter.ExecuteReader(args.Queries[0], ref sessionId);
                                    if (table != null)
                                    {
                                        res = XmlSerializationUtility.Obj2XmlStr(DataTableHelper.Create(table));
                                    }
                                }
                                catch (AdomdConnectionException connection_ex)
                                {
                                    res = connection_ex.Message;
                                    result.ContentType = InvokeContentType.Error;
                                }
                                catch (AdomdErrorResponseException response_ex)
                                {
                                    res = response_ex.Message;
                                    result.ContentType = InvokeContentType.Error;
                                }
                                catch (AdomdUnknownResponseException unknown_ex)
                                {
                                    res = unknown_ex.Message;
                                    result.ContentType = InvokeContentType.Error;
                                }
                                catch (InvalidOperationException invalid_ex)
                                {
                                    res = invalid_ex.Message;
                                    result.ContentType = InvokeContentType.Error;
                                }
                                break;
                        }
                    }
                }
                result.Content = res;
                System.Diagnostics.Debug.WriteLine("CellSetData size: " + res.Length);

                if (UseCompress)
                {
                    DateTime start = DateTime.Now;
                    // Архивация строки
                    String compesed = ZipCompressor.CompressAndConvertToBase64String(res);
                    System.Diagnostics.Debug.WriteLine("CellSetData compression time: " + (DateTime.Now - start).ToString());
                    System.Diagnostics.Debug.WriteLine("CellSetData compressed size: " + compesed.Length);

                    result.Content = compesed;
                    result.IsArchive = true;
                }
                
                result.Headers.Add(new Header(InvokeResultDescriptor.SESSION_ID, sessionId));
                result.Headers.Add(new Header(InvokeResultDescriptor.CONNECTION_ID, args.Connection));
            }
            catch (Exception ex)
            {
                throw;
            }
            return InvokeResultDescriptor.Serialize(result);
        }
Example #4
0
        String ExecuteQuery(String schema)
        {
            InvokeResultDescriptor result = new InvokeResultDescriptor();
            String res = String.Empty;

            try
            {
                String       sessionId = String.Empty;
                MdxQueryArgs args      = XmlSerializationUtility.XmlStr2Obj <MdxQueryArgs>(schema);
                if (args != null)
                {
                    sessionId = args.SessionId;
                    DefaultQueryExecuter queryExecuter = new DefaultQueryExecuter(GetConnection(args.Connection));
                    if (args.Queries.Count > 0)
                    {
                        result.ContentType = InvokeContentType.MultidimData;

                        switch (args.Type)
                        {
                        case QueryTypes.Update:
                        case QueryTypes.CommitTransaction:
                        case QueryTypes.RollbackTransaction:
                            List <String> results = new List <String>();
                            result.ContentType = InvokeContentType.UpdateResult;
                            foreach (var query in args.Queries)
                            {
                                try
                                {
                                    // Method return a value of one (1).
                                    queryExecuter.ExecuteNonQuery(query, ref sessionId);
                                    results.Add(String.Empty);
                                }
                                catch (AdomdConnectionException connection_ex)
                                {
                                    results.Add(connection_ex.Message);
                                }
                                catch (AdomdErrorResponseException response_ex)
                                {
                                    results.Add(response_ex.Message);
                                }
                                catch (AdomdUnknownResponseException unknown_ex)
                                {
                                    results.Add(unknown_ex.Message);
                                }
                                catch (InvalidOperationException invalid_ex)
                                {
                                    results.Add(invalid_ex.Message);
                                }
                            }
                            res = XmlSerializationUtility.Obj2XmlStr(results, Common.Namespace);
                            break;

                        case QueryTypes.Select:
                            try
                            {
                                res = queryExecuter.GetCellSetDescription(args.Queries[0], ref sessionId);
                            }
                            catch (AdomdConnectionException connection_ex)
                            {
                                res = connection_ex.Message;
                                result.ContentType = InvokeContentType.Error;
                            }
                            catch (AdomdErrorResponseException response_ex)
                            {
                                res = response_ex.Message;
                                result.ContentType = InvokeContentType.Error;
                            }
                            catch (AdomdUnknownResponseException unknown_ex)
                            {
                                res = unknown_ex.Message;
                                result.ContentType = InvokeContentType.Error;
                            }
                            catch (InvalidOperationException invalid_ex)
                            {
                                res = invalid_ex.Message;
                                result.ContentType = InvokeContentType.Error;
                            }
                            break;

                        case QueryTypes.DrillThrough:
                            try
                            {
                                var table = queryExecuter.ExecuteReader(args.Queries[0], ref sessionId);
                                if (table != null)
                                {
                                    res = XmlSerializationUtility.Obj2XmlStr(DataTableHelper.Create(table));
                                }
                            }
                            catch (AdomdConnectionException connection_ex)
                            {
                                res = connection_ex.Message;
                                result.ContentType = InvokeContentType.Error;
                            }
                            catch (AdomdErrorResponseException response_ex)
                            {
                                res = response_ex.Message;
                                result.ContentType = InvokeContentType.Error;
                            }
                            catch (AdomdUnknownResponseException unknown_ex)
                            {
                                res = unknown_ex.Message;
                                result.ContentType = InvokeContentType.Error;
                            }
                            catch (InvalidOperationException invalid_ex)
                            {
                                res = invalid_ex.Message;
                                result.ContentType = InvokeContentType.Error;
                            }
                            break;
                        }
                    }
                }
                result.Content = res;
                System.Diagnostics.Debug.WriteLine("CellSetData size: " + res.Length);

                if (UseCompress)
                {
                    DateTime start = DateTime.Now;
                    // Архивация строки
                    String compesed = ZipCompressor.CompressAndConvertToBase64String(res);
                    System.Diagnostics.Debug.WriteLine("CellSetData compression time: " + (DateTime.Now - start).ToString());
                    System.Diagnostics.Debug.WriteLine("CellSetData compressed size: " + compesed.Length);

                    result.Content   = compesed;
                    result.IsArchive = true;
                }

                result.Headers.Add(new Header(InvokeResultDescriptor.SESSION_ID, sessionId));
                result.Headers.Add(new Header(InvokeResultDescriptor.CONNECTION_ID, args.Connection));
            }
            catch (Exception ex)
            {
                throw;
            }
            return(InvokeResultDescriptor.Serialize(result));
        }