using System;
using System.Collections.Generic;
using System.ServiceModel;
using System.Text;
using System.Web.Services.Protocols;
using MemoQServicesClient.TMService;

namespace MemoQServicesClient
{
    class Demos
    {
        //public void Demo_Faults_WCF()
        //{
        //    try
        //    {
        //        // string res = tmService.LookupSegment(...);
        //    }
        //    catch (FaultException<InvalidSessionIdFault> e)
        //    {
        //        // E.g. re-login user
        //    }
        //    catch (FaultException<RequestXmlFormatFault> e)
        //    {
        //        // This is a kind of programmatic error, handle it specially
        //    }
        //    catch (FaultException<GenericFault> e)
        //    {
        //        // Uncategorized expected server errors (generic faults)
        //        // E.g. display the message of the fault to the user
        //        // in a user friendly error screen.
        //    }
        //    catch (FaultException<UnexpectedFault> e)
        //    {
        //        // Unexpected server errors
        //        // E.g. show the user an “internal server error” screen
        //        // Also log stack trace:
        //        Log.WriteError(e.Detail.StackTrace);
        //    }
        //    catch (FaultException e)
        //    {
        //        // All other faults (UnauthorizedAccessFault, NoLicenseFault, TMFault, etc.),
        //        // Handle them the same way
        //    }

        //}

        public void Demo_Faults_ASMX()
        {

try
{
    // string res = tmService.LookupSegment(...);
}
catch (SoapException e)
{
    // All other faults (UnauthorizedAccessFault, NoLicenseFault, TMFault),
    // handle them the same way
    switch (e.Code.Name)
    {
        case "InvalidSessionIdFault":
        // E.g. re-login user
            break;
        case "RequestXmlFormatFault":
            // This is a kind of programmatic error, handle it specially
            break;
        case "Unexpected":
            // Unexpected server errors
            // E.g. show the user an “internal server error” screen
            // The stack trace is in Detail in XML format, if you want it.
            break;
        default:
            if (e.Code.Name.StartsWith("Generic"))
            {
            // Uncategorized expected server errors (generic faults)
            // E.g. display the message of the fault to the user
            // in a user friendly error screen.
            }
            else
            {
                // All other faults (UnauthorizedAccessFault, NoLicenseFault,
                // TMFault, etc.),
                // Handle them the same way
            }
            break;
    }
}

        }
    }

}
