예제 #1
0
        public async Task ConnectAsync(CancellationToken cancellationToken = default)
        {
            if (Charset.GetCharset(_options.Charset) == null)
            {
                throw FbException.Create("Invalid character set specified");
            }

            try
            {
                _db = await ClientFactory.CreateDatabaseAsync(_options, cancellationToken).ConfigureAwait(false);

                _db.Charset    = Charset.GetCharset(_options.Charset);
                _db.Dialect    = _options.Dialect;
                _db.PacketSize = _options.PacketSize;

                var dpb = BuildDpb(_db, _options);

                if (string.IsNullOrEmpty(_options.UserID) && string.IsNullOrEmpty(_options.Password))
                {
                    await _db.AttachWithTrustedAuthAsync(dpb, _options.Database, _options.CryptKey, cancellationToken).ConfigureAwait(false);
                }
                else
                {
                    await _db.AttachAsync(dpb, _options.Database, _options.CryptKey, cancellationToken).ConfigureAwait(false);
                }
            }
            catch (IscException ex)
            {
                throw FbException.Create(ex);
            }
        }
예제 #2
0
        public async Task Connect(AsyncWrappingCommonArgs async)
        {
            if (Charset.GetCharset(_options.Charset) == null)
            {
                throw new FbException("Invalid character set specified");
            }

            try
            {
                _db = await ClientFactory.CreateDatabase(_options, async).ConfigureAwait(false);

                _db.Charset    = Charset.GetCharset(_options.Charset);
                _db.Dialect    = _options.Dialect;
                _db.PacketSize = _options.PacketSize;

                var dpb = BuildDpb(_db, _options);

                if (string.IsNullOrEmpty(_options.UserID) && string.IsNullOrEmpty(_options.Password))
                {
                    await _db.AttachWithTrustedAuth(dpb, _options.DataSource, _options.Port, _options.Database, _options.CryptKey, async).ConfigureAwait(false);
                }
                else
                {
                    await _db.Attach(dpb, _options.DataSource, _options.Port, _options.Database, _options.CryptKey, async).ConfigureAwait(false);
                }
            }
            catch (IscException ex)
            {
                throw new FbException(ex.Message, ex);
            }
        }
예제 #3
0
        private static Charset GetItemOutboundMimeCharsetInternal(Item item, OutboundConversionOptions options)
        {
            object  obj            = item.TryGetProperty(InternalSchema.InternetCpid);
            bool    valueOrDefault = item.GetValueOrDefault <bool>(InternalSchema.IsAutoForwarded, false);
            string  className      = item.ClassName;
            Charset charset        = null;

            if (valueOrDefault || (obj is PropertyError && !item.Body.IsBodyDefined) || (options != null && options.DetectionOptions.PreferredCharset != null && (options.DetectionOptions.RequiredCoverage < 100 || ObjectClass.IsTaskRequest(className) || ObjectClass.IsMeetingMessage(className))))
            {
                charset = ConvertUtils.DetectOutboundCharset(item, options, obj, !valueOrDefault);
                if (charset != null)
                {
                    if (!item.CharsetDetector.IsItemCharsetKnownWithoutDetection(BodyCharsetFlags.DisableCharsetDetection, charset, out charset))
                    {
                        throw new InvalidOperationException();
                    }
                    return(charset);
                }
            }
            if (!(obj is PropertyError) && Charset.TryGetCharset((int)obj, out charset) && ConvertUtils.TryTransformCharset(ref charset))
            {
                return(charset);
            }
            object obj2 = item.TryGetProperty(InternalSchema.Codepage);

            if (!(obj2 is PropertyError) && Charset.TryGetCharset((int)obj2, out charset))
            {
                charset = charset.Culture.MimeCharset;
                if (ConvertUtils.TryTransformCharset(ref charset))
                {
                    return(charset);
                }
            }
            return(Charset.GetCharset(65001));
        }
예제 #4
0
        public void Connect()
        {
            if (Charset.GetCharset(_options.Charset) == null)
            {
                throw new FbException("Invalid character set specified");
            }

            try
            {
                _db            = ClientFactory.CreateDatabase(_options);
                _db.Charset    = Charset.GetCharset(_options.Charset);
                _db.Dialect    = _options.Dialect;
                _db.PacketSize = _options.PacketSize;

                DatabaseParameterBuffer dpb = BuildDpb(_db, _options);

                if (_options.FallIntoTrustedAuth)
                {
                    _db.AttachWithTrustedAuth(dpb, _options.DataSource, _options.Port, _options.Database);
                }
                else
                {
                    _db.Attach(dpb, _options.DataSource, _options.Port, _options.Database);
                }
            }
            catch (IscException ex)
            {
                throw new FbException(ex.Message, ex);
            }
        }
예제 #5
0
        internal void ValidateCharset(bool charsetWasDefaulted, Stream contentStream)
        {
            bool strongDefault = !charsetWasDefaulted && this.charset.CodePage != 20127;
            FeInboundCharsetDetector feInboundCharsetDetector = new FeInboundCharsetDetector(this.charset.CodePage, strongDefault, true, true, true);

            byte[] byteBuffer = ScratchPad.GetByteBuffer(1024);
            int    num        = 0;
            int    num2       = 0;

            while (num2 < 4096 && (num = contentStream.Read(byteBuffer, 0, byteBuffer.Length)) != 0)
            {
                feInboundCharsetDetector.AddBytes(byteBuffer, 0, num, false);
                num2 += num;
            }
            if (num == 0)
            {
                feInboundCharsetDetector.AddBytes(byteBuffer, 0, 0, true);
            }
            int codePageChoice = feInboundCharsetDetector.GetCodePageChoice();

            if (codePageChoice != this.charset.CodePage)
            {
                this.charset = Charset.GetCharset(codePageChoice);
            }
        }
        public void Connect()
        {
            if (Charset.GetCharset(_options.Charset) == null)
            {
                throw new FbException("Invalid character set specified");
            }

            try
            {
                _db            = ClientFactory.CreateDatabase(_options);
                _db.Charset    = Charset.GetCharset(_options.Charset);
                _db.Dialect    = _options.Dialect;
                _db.PacketSize = _options.PacketSize;

                var dpb = BuildDpb(_db, _options);

                if (string.IsNullOrEmpty(_options.UserID) && string.IsNullOrEmpty(_options.Password))
                {
                    _db.AttachWithTrustedAuth(dpb, _options.DataSource, _options.Port, _options.Database, _options.CryptKey);
                }
                else
                {
                    _db.Attach(dpb, _options.DataSource, _options.Port, _options.Database, _options.CryptKey);
                }
            }
            catch (IscException ex)
            {
                throw new FbException(ex.Message, ex);
            }
        }
 public static DatabaseBase CreateDatabase(ConnectionString options)
 {
     return(options.ServerType switch
     {
         FbServerType.Default => CreateManagedDatabase(options),
         FbServerType.Embedded => new Native.FesDatabase(options.ClientLibrary, Charset.GetCharset(options.Charset)),
         _ => throw IncorrectServerTypeException(),
     });
예제 #8
0
        private Charset OverrideCharset(BodyCharsetFlags flags, Charset charset)
        {
            int num = this.OverrideCodePage(flags, charset.CodePage);

            if (charset.CodePage != num)
            {
                return(Charset.GetCharset(num));
            }
            return(charset);
        }
예제 #9
0
 // Token: 0x060001FF RID: 511 RVA: 0x000093DA File Offset: 0x000075DA
 public EncodingOptions(string charsetName, string cultureName, EncodingFlags encodingFlags)
 {
     this.cultureName   = cultureName;
     this.encodingFlags = encodingFlags;
     this.charset       = ((charsetName == null) ? null : Charset.GetCharset(charsetName));
     if (this.charset != null)
     {
         this.charset.GetEncoding();
     }
 }
예제 #10
0
 private MimePartInfo GetMimeSkeleton()
 {
     if (this.structure == null)
     {
         ConvertUtils.CallCts(ExTraceGlobals.CcOutboundMimeTracer, "ImapItemConvetrer::GetMimeSkeleton", ServerStrings.ConversionCorruptContent, delegate
         {
             this.structure = this.mimeProvider.CalculateMimeStructure(Charset.GetCharset(this.itemEncodingOptions.CharsetName));
         });
     }
     return(this.structure);
 }
예제 #11
0
        internal static Charset GetItemOutboundMimeCharset(Item item, OutboundConversionOptions options)
        {
            Charset charset   = ConvertUtils.GetItemOutboundMimeCharsetInternal(item, options);
            string  className = item.ClassName;

            if (options.DetectionOptions.PreferredCharset == null && charset.CodePage != 54936 && (ObjectClass.IsTaskRequest(className) || ObjectClass.IsMeetingMessage(className) || ObjectClass.IsCalendarItem(className)))
            {
                charset = Charset.GetCharset(65001);
            }
            return(charset);
        }
예제 #12
0
        public static IServiceManager CreateServiceManager(ConnectionString options)
        {
            switch (options.ServerType)
            {
            case FbServerType.Default:
                return(CreateManagedServiceManager(options));

            case FbServerType.Embedded:
                return(new Client.Native.FesServiceManager(options.ClientLibrary, Charset.GetCharset(options.Charset)));

            default:
                throw IncorrectServerTypeException();
            }
        }
예제 #13
0
        public static EmailMessage Create(BodyFormat bodyFormat, bool createAlternative, string charsetName)
        {
            if (bodyFormat != BodyFormat.Text && bodyFormat != BodyFormat.Html)
            {
                throw new ArgumentException(EmailMessageStrings.CannotCreateSpecifiedBodyFormat(bodyFormat.ToString()));
            }
            if (bodyFormat == BodyFormat.Text && createAlternative)
            {
                throw new ArgumentException(EmailMessageStrings.CannotCreateAlternativeBody);
            }
            Charset.GetCharset(charsetName);
            MimeTnefMessage mimeTnefMessage = new MimeTnefMessage(bodyFormat, createAlternative, charsetName);

            return(new EmailMessage(mimeTnefMessage));
        }
예제 #14
0
        protected override void BuildBody(BodyConversionCallbacks callbacks)
        {
            string charset = this.originalItem.Body.Charset;

            try
            {
                Charset charset2 = Charset.GetCharset(charset);
                this.newItem[InternalSchema.InternetCpid] = charset2.CodePage;
                this.newItem[InternalSchema.Codepage]     = ConvertUtils.MapItemWindowsCharset(charset2).CodePage;
            }
            catch (InvalidCharsetException)
            {
                ExTraceGlobals.StorageTracer.TraceDebug <string>(0L, "ForwardAsAttachmentCreation::BuildBody. Original message had invalid charset {0}", charset);
            }
        }
        public void CreateDatabase(int pageSize, bool forcedWrites, bool overwrite)
        {
            var db = ClientFactory.CreateDatabase(_options);

            var dpb = db.CreateDatabaseParameterBuffer();

            dpb.Append(IscCodes.isc_dpb_dummy_packet_interval, new byte[] { 120, 10, 0, 0 });
            dpb.Append(IscCodes.isc_dpb_sql_dialect, new byte[] { _options.Dialect, 0, 0, 0 });
            if (!string.IsNullOrEmpty(_options.UserID))
            {
                dpb.Append(IscCodes.isc_dpb_user_name, _options.UserID);
            }
            if (_options.Charset.Length > 0)
            {
                var charset = Charset.GetCharset(_options.Charset);
                if (charset == null)
                {
                    throw new ArgumentException("Character set is not valid.");
                }
                else
                {
                    dpb.Append(IscCodes.isc_dpb_set_db_charset, charset.Name);
                }
            }
            dpb.Append(IscCodes.isc_dpb_force_write, (short)(forcedWrites ? 1 : 0));
            dpb.Append(IscCodes.isc_dpb_overwrite, (overwrite ? 1 : 0));
            if (pageSize > 0)
            {
                dpb.Append(IscCodes.isc_dpb_page_size, pageSize);
            }

            try
            {
                if (string.IsNullOrEmpty(_options.UserID) && string.IsNullOrEmpty(_options.Password))
                {
                    db.CreateDatabaseWithTrustedAuth(dpb, _options.DataSource, _options.Port, _options.Database, _options.CryptKey);
                }
                else
                {
                    db.CreateDatabase(dpb, _options.DataSource, _options.Port, _options.Database, _options.CryptKey);
                }
            }
            finally
            {
                db.Detach();
            }
        }
예제 #16
0
        private IImapMimeProvider GetAttachedItemConverter(ref MimePartInfo part, ref Item item, ref EncodingOptions itemEncodingOptions, List <IDisposable> disposeList)
        {
            if (part.ContentType != MimePartContentType.ItemAttachment)
            {
                return(null);
            }
            IImapMimeProvider imapMimeProvider;

            if (part.SmimePart == null)
            {
                Attachment attachment = item.AttachmentCollection.Open(part.AttachmentId, InternalSchema.ContentConversionProperties);
                disposeList.Add(attachment);
                ItemAttachment itemAttachment = attachment as ItemAttachment;
                if (itemAttachment == null)
                {
                    StorageGlobals.ContextTraceError(ExTraceGlobals.CcOutboundMimeTracer, "ImapItemConverter::GetAttachedItemConverter: attachment is not an item.");
                    ExAssert.RetailAssert(false, "ImapItemConverter::GetAttachedItemConverter: attachment is not an item.");
                    return(null);
                }
                item = ConvertUtils.OpenAttachedItem(itemAttachment);
                if (item == null)
                {
                    return(null);
                }
                disposeList.Add(item);
                ItemToMimeConverter itemToMimeConverter = new ItemToMimeConverter(item, this.options, ConverterFlags.IsEmbeddedMessage);
                imapMimeProvider = IImapMimeProvider.CreateInstance(itemToMimeConverter);
                disposeList.Add(imapMimeProvider);
                itemEncodingOptions = itemToMimeConverter.GetItemMimeEncodingOptions(this.options);
                if (part.AttachedItemStructure != null)
                {
                    itemToMimeConverter.SetSkeletonAndSmimeDoc(part.AttachedItemStructure.Skeleton, part.AttachedItemStructure.SmimeDocument);
                }
            }
            else
            {
                imapMimeProvider = IImapMimeProvider.CreateInstance((MimePart)part.SmimePart.FirstChild, part.SmimeDocument);
                disposeList.Add(imapMimeProvider);
                itemEncodingOptions = this.itemEncodingOptions;
            }
            if (part.AttachedItemStructure == null)
            {
                part.AttachedItemStructure = imapMimeProvider.CalculateMimeStructure(Charset.GetCharset(itemEncodingOptions.CharsetName));
            }
            part = part.AttachedItemStructure;
            return(imapMimeProvider);
        }
예제 #17
0
        public async Task CreateDatabaseAsync(int pageSize, bool forcedWrites, bool overwrite, CancellationToken cancellationToken = default)
        {
            var db = await ClientFactory.CreateDatabaseAsync(_options, cancellationToken).ConfigureAwait(false);

            var dpb = db.CreateDatabaseParameterBuffer();

            dpb.Append(IscCodes.isc_dpb_dummy_packet_interval, new byte[] { 120, 10, 0, 0 });
            dpb.Append(IscCodes.isc_dpb_sql_dialect, new byte[] { _options.Dialect, 0, 0, 0 });
            if (!string.IsNullOrEmpty(_options.UserID))
            {
                dpb.Append(IscCodes.isc_dpb_user_name, _options.UserID);
            }
            if (_options.Charset.Length > 0)
            {
                var charset = Charset.GetCharset(_options.Charset);
                if (charset == null)
                {
                    throw new ArgumentException("Character set is not valid.");
                }
                else
                {
                    dpb.Append(IscCodes.isc_dpb_set_db_charset, charset.Name);
                }
            }
            dpb.Append(IscCodes.isc_dpb_force_write, (short)(forcedWrites ? 1 : 0));
            dpb.Append(IscCodes.isc_dpb_overwrite, (overwrite ? 1 : 0));
            if (pageSize > 0)
            {
                dpb.Append(IscCodes.isc_dpb_page_size, pageSize);
            }

            try
            {
                if (string.IsNullOrEmpty(_options.UserID) && string.IsNullOrEmpty(_options.Password))
                {
                    await db.CreateDatabaseWithTrustedAuthAsync(dpb, _options.Database, _options.CryptKey, cancellationToken).ConfigureAwait(false);
                }
                else
                {
                    await db.CreateDatabaseAsync(dpb, _options.Database, _options.CryptKey, cancellationToken).ConfigureAwait(false);
                }
            }
            finally
            {
                await db.DetachAsync(cancellationToken).ConfigureAwait(false);
            }
        }
예제 #18
0
        private static void CreateDatabaseImpl(string connectionString, int pageSize = 4096, bool forcedWrites = true, bool overwrite = false)
        {
            FbConnectionString options = new FbConnectionString(connectionString);

            options.Validate();

            try
            {
                DatabaseParameterBuffer dpb = new DatabaseParameterBuffer();

                dpb.Append(IscCodes.isc_dpb_version1);
                dpb.Append(IscCodes.isc_dpb_dummy_packet_interval, new byte[] { 120, 10, 0, 0 });
                dpb.Append(IscCodes.isc_dpb_sql_dialect, new byte[] { options.Dialect, 0, 0, 0 });
                if (!string.IsNullOrEmpty(options.UserID))
                {
                    dpb.Append(IscCodes.isc_dpb_user_name, options.UserID);
                }
                if (options.Charset.Length > 0)
                {
                    Charset charset = Charset.GetCharset(options.Charset);
                    if (charset == null)
                    {
                        throw new ArgumentException("Character set is not valid.");
                    }
                    else
                    {
                        dpb.Append(IscCodes.isc_dpb_set_db_charset, charset.Name);
                    }
                }
                dpb.Append(IscCodes.isc_dpb_force_write, (short)(forcedWrites ? 1 : 0));
                dpb.Append(IscCodes.isc_dpb_overwrite, (overwrite ? 1 : 0));
                if (pageSize > 0)
                {
                    dpb.Append(IscCodes.isc_dpb_page_size, pageSize);
                }

                using (FbConnectionInternal db = new FbConnectionInternal(options))
                {
                    db.CreateDatabase(dpb);
                }
            }
            catch (IscException ex)
            {
                throw new FbException(ex.Message, ex);
            }
        }
예제 #19
0
        internal static ReadOnlyCollection <AttachmentLink> InternalItemsToICal(string calendarName, IList <Item> items, ReadOnlyCollection <AttachmentLink> existingAttachmentLinks, OutboundAddressCache addressCache, bool suppressExceptionAndAttachmentDemotion, Stream stream, List <LocalizedString> errorStream, string charsetName, OutboundConversionOptions outboundConversionOptions)
        {
            Util.ThrowOnNullArgument(items, "items");
            if (!suppressExceptionAndAttachmentDemotion && items.Count != 1)
            {
                throw new ArgumentException("Non suppressExceptionAndAttachmentDemotion mode should have one and only one item to demote");
            }
            Charset          charset          = Charset.GetCharset(charsetName);
            CalendarDocument calendarDocument = new CalendarDocument();

            using (CalendarWriter calendarWriter = new CalendarWriter(new StreamWrapper(stream, false), charset.Name))
            {
                ICalOutboundContext outboundContext = new ICalOutboundContext(charset, errorStream, addressCache, outboundConversionOptions, calendarWriter, calendarName, existingAttachmentLinks, suppressExceptionAndAttachmentDemotion);
                calendarDocument.Demote(outboundContext, items);
            }
            return(existingAttachmentLinks);
        }
예제 #20
0
        private static void GenerateOldFashionedReportBody(MessageItem message, Stream outputStream, out CultureInfo cultureInfo, out Charset charset)
        {
            Encoding unicode = Encoding.Unicode;
            string   text    = ReportMessage.GenerateOldFashionedReportBody(message, out cultureInfo).ToString(cultureInfo);
            OutboundCodePageDetector outboundCodePageDetector = new OutboundCodePageDetector();

            outboundCodePageDetector.AddText(text);
            charset = Charset.GetCharset(outboundCodePageDetector.GetCodePage(Culture.GetCulture(cultureInfo.Name), false));
            using (MemoryStream memoryStream = new MemoryStream(unicode.GetBytes(text)))
            {
                new TextToHtml
                {
                    InputEncoding  = unicode,
                    OutputEncoding = charset.GetEncoding()
                }.Convert(memoryStream, outputStream);
            }
        }
예제 #21
0
        internal static IEnumerable <Item> InternalICalToItems(Stream iCalStream, string charsetName, InboundAddressCache addressCache, uint?maxBodyLength, bool hasExceptionPromotion, Func <Item> getItem, IList <LocalizedString> errorStream, out string calendarName)
        {
            Util.ThrowOnNullArgument(iCalStream, "iCalStream");
            Util.ThrowOnNullArgument(addressCache, "addressCache");
            Util.ThrowOnNullArgument(errorStream, "errorStream");
            bool flag                           = false;
            LocalizedException ex               = null;
            Charset            charset          = Charset.GetCharset(charsetName ?? "utf-8");
            CalendarDocument   calendarDocument = new CalendarDocument();
            IEnumerable <Item> result;

            using (CalendarReader calendarReader = new CalendarReader(new StreamWrapper(iCalStream, false), charset.Name, CalendarComplianceMode.Loose))
            {
                ICalInboundContext calInboundContext = new ICalInboundContext(charset, errorStream, addressCache, addressCache.Options, calendarReader, maxBodyLength, hasExceptionPromotion);
                try
                {
                    flag = (calendarDocument.Parse(calInboundContext) && calendarDocument.vCalendar.Validate());
                }
                catch (InvalidCalendarDataException ex2)
                {
                    ex = ex2;
                }
                calendarName = calInboundContext.CalendarName;
                if (!flag)
                {
                    if (ex != null)
                    {
                        ExTraceGlobals.ICalTracer.TraceError <string>((long)calendarDocument.GetHashCode(), "CalendarDocument::InternalICalToItems. Found exception: '{0}'.", ex.Message);
                        errorStream.Add(ex.LocalizedString);
                    }
                    else if (errorStream.Count != 0)
                    {
                        ExTraceGlobals.ICalTracer.TraceError <int>((long)calendarDocument.GetHashCode(), "CalendarDocument::InternalICalToItems. {0} error found.", errorStream.Count);
                        errorStream.Add(ServerStrings.InvalidICalElement("VCALENDAR"));
                    }
                    result = Array <CalendarItemBase> .Empty;
                }
                else
                {
                    result = calendarDocument.vCalendar.Promote(getItem);
                }
            }
            return(result);
        }
예제 #22
0
 internal static Charset TranslateWriteStreamCharset(Charset charset)
 {
     if (charset.Kind == CodePageKind.Unicode)
     {
         charset = charset.Culture.MimeCharset;
     }
     else if (charset.CodePage == 20127)
     {
         charset = Charset.GetCharset(28591);
         if (!charset.IsAvailable)
         {
             charset = Charset.GetCharset(1252);
         }
         if (!charset.IsAvailable)
         {
             charset = Charset.ASCII;
         }
     }
     return(charset);
 }
예제 #23
0
        private Charset DetectValueCharset(Charset defaultCharset, bool enableJisDetection, bool enableUtf8Detection, bool enableDbcsDetection, out EncodingScheme encodingScheme)
        {
            ValueIterator            valueIterator            = new ValueIterator(this.iterator.Lines, this.iterator.LinesMask);
            FeInboundCharsetDetector feInboundCharsetDetector = new FeInboundCharsetDetector(defaultCharset.CodePage, false, enableJisDetection, enableUtf8Detection, enableDbcsDetection);

            while (!valueIterator.Eof)
            {
                feInboundCharsetDetector.AddBytes(valueIterator.Bytes, valueIterator.Offset, valueIterator.Length, false);
                valueIterator.Get(valueIterator.Length);
            }
            feInboundCharsetDetector.AddBytes(null, 0, 0, true);
            int codePageChoice = feInboundCharsetDetector.GetCodePageChoice();

            if (codePageChoice != defaultCharset.CodePage)
            {
                defaultCharset = Charset.GetCharset(codePageChoice);
            }
            if (!feInboundCharsetDetector.PureAscii)
            {
                if (feInboundCharsetDetector.Iso2022JpLikely || feInboundCharsetDetector.Iso2022KrLikely)
                {
                    encodingScheme = EncodingScheme.Jis;
                }
                else
                {
                    encodingScheme = EncodingScheme.EightBit;
                }
            }
            else if (defaultCharset.Name == "iso-2022-jp" && !feInboundCharsetDetector.Iso2022KrLikely)
            {
                encodingScheme = EncodingScheme.Jis;
            }
            else
            {
                encodingScheme = EncodingScheme.None;
            }
            return(defaultCharset);
        }
예제 #24
0
        public Stream GetContentWriteStream(string charsetName)
        {
            BodyFormat bodyFormat = this.BodyFormat;

            if (bodyFormat == BodyFormat.None)
            {
                throw new InvalidOperationException(EmailMessageStrings.CannotWriteBodyDoesNotExist);
            }
            if (BodyFormat.Rtf == bodyFormat)
            {
                throw new InvalidOperationException(EmailMessageStrings.NotSupportedForRtfBody);
            }
            Charset charset;

            Charset.TryGetCharset(this.CharsetName, out charset);
            Charset charset2 = Charset.GetCharset(charsetName);
            bool    flag     = charset == null || charset.CodePage != charset2.CodePage;

            if (flag)
            {
                charset2.GetEncoding();
            }
            return(this.Message.Body_GetContentWriteStream(charset2));
        }
예제 #25
0
        private static IServiceManager CreateManagedServiceManager(FbConnectionString options)
        {
            FirebirdSql.Data.Client.Managed.Version10.GdsConnection connection = new FirebirdSql.Data.Client.Managed.Version10.GdsConnection(options.DataSource, options.Port, options.PacketSize, Charset.GetCharset(options.Charset));

            connection.Connect();
            connection.Identify(!string.IsNullOrEmpty(options.Database) ? options.Database : string.Empty);

            switch (connection.ProtocolVersion)
            {
            case IscCodes.PROTOCOL_VERSION12:
            case IscCodes.PROTOCOL_VERSION11:
            case IscCodes.PROTOCOL_VERSION10:
                return(new FirebirdSql.Data.Client.Managed.Version10.GdsServiceManager(connection));

            default:
                throw new NotSupportedException("Protocol not supported.");
            }
        }
예제 #26
0
        public static IServiceManager CreateServiceManager(FbConnectionString options)
        {
            switch (options.ServerType)
            {
            case FbServerType.Default:
                return(CreateManagedServiceManager(options));

#if (!NET_CF)
            case FbServerType.Embedded:
                // PInvoke Client
                return(new FirebirdSql.Data.Client.Native.FesServiceManager(options.ClientLibrary, Charset.GetCharset(options.Charset)));
#endif

            default:
                throw new NotSupportedException("Specified server type is not correct.");
            }
        }
예제 #27
0
        private static IDatabase CreateManagedDatabase(FbConnectionString options)
        {
            FirebirdSql.Data.Client.Managed.Version10.GdsConnection connection = new FirebirdSql.Data.Client.Managed.Version10.GdsConnection(options.DataSource, options.Port, options.PacketSize, Charset.GetCharset(options.Charset));

            connection.Connect();
            connection.Identify(options.Database);

            switch (connection.ProtocolVersion)
            {
            case IscCodes.PROTOCOL_VERSION12:
                return(new FirebirdSql.Data.Client.Managed.Version12.GdsDatabase(connection));

            case IscCodes.PROTOCOL_VERSION11:
                return(new FirebirdSql.Data.Client.Managed.Version11.GdsDatabase(connection));

            case IscCodes.PROTOCOL_VERSION10:
                return(new FirebirdSql.Data.Client.Managed.Version10.GdsDatabase(connection));

            default:
                throw new NotSupportedException("Protocol not supported.");
            }
        }
 public static async Task <DatabaseBase> CreateDatabase(ConnectionString options, AsyncWrappingCommonArgs async)
 {
     return(options.ServerType switch
     {
         FbServerType.Default => await CreateManagedDatabase(options, async).ConfigureAwait(false),
         FbServerType.Embedded => new Native.FesDatabase(options.ClientLibrary, Charset.GetCharset(options.Charset)),
         _ => throw IncorrectServerTypeException(),
     });
예제 #29
0
        public static void CreateDatabase(string connectionString, int pageSize, bool forcedWrites, bool overwrite)
        {
            FbConnectionString options = new FbConnectionString(connectionString);

            options.Validate();

            try
            {
                // DPB configuration
                DatabaseParameterBuffer dpb = new DatabaseParameterBuffer();

                // Dpb version
                dpb.Append(IscCodes.isc_dpb_version1);

                // Dummy packet	interval
                dpb.Append(IscCodes.isc_dpb_dummy_packet_interval, new byte[] { 120, 10, 0, 0 });

                // User	name
                dpb.Append(IscCodes.isc_dpb_user_name, options.UserID);

                // User	password
                dpb.Append(IscCodes.isc_dpb_password, options.Password);

                // Database	dialect
                dpb.Append(IscCodes.isc_dpb_sql_dialect, new byte[] { options.Dialect, 0, 0, 0 });

                // Character set
                if (options.Charset.Length > 0)
                {
                    Charset charset = Charset.GetCharset(options.Charset);

                    if (charset == null)
                    {
                        throw new ArgumentException("Character set is not valid.");
                    }
                    else
                    {
                        dpb.Append(IscCodes.isc_dpb_set_db_charset, charset.Name);
                    }
                }

                // Forced writes
                dpb.Append(IscCodes.isc_dpb_force_write, (short)(forcedWrites ? 1 : 0));

                // Database overwrite
                dpb.Append(IscCodes.isc_dpb_overwrite, (overwrite ? 1 : 0));

                // Page	Size
                if (pageSize > 0)
                {
                    dpb.Append(IscCodes.isc_dpb_page_size, pageSize);
                }

                // Create the new database
                FbConnectionInternal db = new FbConnectionInternal(options);
                db.CreateDatabase(dpb);
            }
            catch (IscException ex)
            {
                throw new FbException(ex.Message, ex);
            }
        }
        private bool BuildParameterDescriptor(Descriptor descriptor, FbParameter parameter, int index)
        {
            if (!parameter.IsTypeSet)
            {
                return(false);
            }

            var type    = parameter.FbDbType;
            var charset = _connection.InnerConnection.Database.Charset;

            // Check the parameter character set
            if (parameter.Charset == FbCharset.Octets && !(parameter.InternalValue is byte[]))
            {
                throw new InvalidOperationException("Value for char octets fields should be a byte array");
            }
            else if (type == FbDbType.Guid)
            {
                charset = Charset.GetCharset(Charset.Octets);
            }
            else if (parameter.Charset != FbCharset.Default)
            {
                charset = Charset.GetCharset((int)parameter.Charset);
            }

            // Set parameter Data Type
            descriptor[index].DataType = (short)TypeHelper.GetSqlTypeFromDbDataType(TypeHelper.GetDbDataTypeFromFbDbType(type), parameter.IsNullable);

            // Set parameter Sub Type
            switch (type)
            {
            case FbDbType.Binary:
                descriptor[index].SubType = 0;
                break;

            case FbDbType.Text:
                descriptor[index].SubType = 1;
                break;

            case FbDbType.Guid:
                descriptor[index].SubType = (short)charset.Identifier;
                break;

            case FbDbType.Char:
            case FbDbType.VarChar:
                descriptor[index].SubType = (short)charset.Identifier;
                if (charset.IsOctetsCharset)
                {
                    descriptor[index].Length = (short)parameter.Size;
                }
                else if (parameter.HasSize)
                {
                    var len = (short)(parameter.Size * charset.BytesPerCharacter);
                    descriptor[index].Length = len;
                }
                break;
            }

            // Set parameter length
            if (descriptor[index].Length == 0)
            {
                descriptor[index].Length = TypeHelper.GetSize((DbDataType)type) ?? 0;
            }

            // Verify parameter
            if (descriptor[index].SqlType == 0 || descriptor[index].Length == 0)
            {
                return(false);
            }

            return(true);
        }