Example #1
0
 public J2534Err PassThruConnect(int deviceId, ProtocolID protocolId, ConnectFlag flags, BaudRate baudRate, ref int channelId)
 {
     if (!IsLoaded)
     {
         return(J2534Err.ERR_DLL_NOT_LOADED);
     }
     return((J2534Err)_wrapper.Connect(deviceId, (int)protocolId, (int)flags, (int)baudRate, ref channelId));
 }
Example #2
0
        public static J2534Err PassThruConnect(int deviceId, ProtocolID protocolId, ConnectFlag flags, BaudRate baudRate, ref int channelId)
        {
            Log.WriteTimestamp("", "PTConnect({0}, {1}, {2}, {3}, {4})", deviceId, protocolId, flags, baudRate, channelId);

            var result = Loader.Lib.PassThruConnect(deviceId, protocolId, flags, baudRate, ref channelId);

            Log.WriteTimestamp("  ", "{0}: {1}", (int)result, result);

            return result;
        }
Example #3
0
        public static J2534Err PassThruConnect(int deviceId, ProtocolID protocolId, ConnectFlag flags, BaudRate baudRate, ref int channelId)
        {
            Log.WriteTimestamp("", "PTConnect({0}, {1}, {2}, {3}, {4})", deviceId, protocolId, flags, baudRate, channelId);

            var result = Loader.Lib.PassThruConnect(deviceId, protocolId, flags, baudRate, ref channelId);

            Log.WriteTimestamp("  ", "{0}: {1}", (int)result, result);

            return(result);
        }
Example #4
0
 /// <summary>
 /// Opens a channel on the device using the specified parameters
 /// </summary>
 /// <param name="ProtocolID">Connection protocol</param>
 /// <param name="Baud">Connection baud-rate</param>
 /// <param name="ConnectFlags">Connection flags</param>
 /// <returns>A connected J2534Channel object</returns>
 public Channel GetChannel(Protocol ProtocolID, Baud Baud, ConnectFlag ConnectFlags, bool ChannelLevelSync = false)
 {
     using (HeapInt hChannelID = new HeapInt())
     {
         lock (sync)
         {
             API.CheckResult(API.PTConnect(deviceId, (int)ProtocolID, (int)ConnectFlags, (int)Baud, (IntPtr)hChannelID));
         }
         var NewChannel = new Channel(this, ProtocolID, Baud, ConnectFlags, hChannelID.Value, ChannelLevelSync ? new object() : sync);
         OnDisposing += NewChannel.Dispose;
         return(NewChannel);
     }
 }
Example #5
0
 internal Channel(Device Device, Protocol ProtocolID, Baud Baud, ConnectFlag ConnectFlags, int ChannelID, object Sync)
 {
     sync               = Sync;
     channelId          = ChannelID;
     hJ2534MessageArray = new HeapMessageArray(ProtocolID, CONST.HEAPMESSAGEBUFFERSIZE);
     API               = Device.API;
     this.Device       = Device;
     this.ProtocolID   = ProtocolID;
     this.ConnectFlags = ConnectFlags;
     DefaultTxTimeout  = 100;
     DefaultRxTimeout  = 300;
     DefaultTxFlag     = TxFlag.NONE;
 }
        private MapiStore ConnectToTargetMailbox(bool mailboxMustExist, string serverLegDN, string serverFqdn, MailboxConnectFlags mailboxConnectFlags)
        {
            MrsTracer.Provider.Function("MapiDestinationMailbox.ConnectToTargetMailbox", new object[0]);
            base.CheckDisposed();
            MapiStore     mapiStore     = null;
            Guid          guidMdb       = Guid.Empty;
            string        text          = null;
            bool          flag          = false;
            OpenStoreFlag openStoreFlag = OpenStoreFlag.UseAdminPrivilege | OpenStoreFlag.TakeOwnership | OpenStoreFlag.OverrideHomeMdb | OpenStoreFlag.FailIfNoMailbox | OpenStoreFlag.NoLocalization | OpenStoreFlag.MailboxGuid | OpenStoreFlag.DisconnectedMailbox;

            if (base.MbxType == MailboxType.DestMailboxCrossOrg)
            {
                openStoreFlag |= OpenStoreFlag.XForestMove;
            }
            ConnectFlag connectFlag = ConnectFlag.UseAdminPrivilege;

            if (base.Credential == null)
            {
                connectFlag |= ConnectFlag.UseRpcContextPool;
            }
            if (!mailboxMustExist)
            {
                bool flag2;
                for (;;)
                {
                    flag2 = false;
                    MrsTracer.Provider.Debug("Checking if destination mailbox exists...", new object[0]);
                    using (ExRpcAdmin rpcAdmin = base.GetRpcAdmin())
                    {
                        try
                        {
                            using (base.RHTracker.Start())
                            {
                                flag2 = MapiUtils.IsMailboxInDatabase(rpcAdmin, base.MdbGuid, base.MailboxGuid);
                            }
                        }
                        catch (MapiExceptionMdbOffline)
                        {
                            if (!flag)
                            {
                                MrsTracer.Provider.Debug("GetMailboxTableInfo returned MdbOffline, forcing AM rediscovery", new object[0]);
                                base.ResolveMDB(true);
                                serverLegDN = base.ServerDN;
                                serverFqdn  = base.ServerFqdn;
                                flag        = true;
                                continue;
                            }
                            throw;
                        }
                    }
                    break;
                }
                if (!flag2)
                {
                    MrsTracer.Provider.Debug("Mailbox {0} does not exist in database {1}", new object[]
                    {
                        base.MailboxGuid,
                        base.MdbGuid
                    });
                    return(null);
                }
                MrsTracer.Provider.Debug("Mailbox {0} exists in database {1}", new object[]
                {
                    base.MailboxGuid,
                    base.MdbGuid
                });
            }
            string userName;
            string domainName;
            string password;

            base.GetCreds(out userName, out domainName, out password);
            if (base.IsTitanium)
            {
                if (base.MbxType == MailboxType.DestMailboxCrossOrg && mailboxMustExist)
                {
                    base.RunADRecipientOperation(false, delegate(IRecipientSession adSession)
                    {
                        ADUser aduser = adSession.Read(base.MailboxId) as ADUser;
                        if (aduser == null)
                        {
                            throw new RecipientNotFoundPermanentException(base.MailboxGuid);
                        }
                        if (aduser.Database == null || !aduser.Database.Equals(base.MdbId))
                        {
                            MrsTracer.Provider.Debug("Stamping homeMDB on the destination Ti user", new object[0]);
                            aduser.Database = base.MdbId;
                            adSession.Save(aduser);
                            using (ExRpcAdmin rpcAdmin2 = base.GetRpcAdmin())
                            {
                                rpcAdmin2.PurgeCachedMailboxObject(base.MailboxGuid);
                            }
                        }
                    });
                }
            }
            else
            {
                guidMdb = base.MdbGuid;
                text    = guidMdb.ToString();
                if (mailboxMustExist && this.ServerVersion < Server.E14MinVersion)
                {
                    MrsTracer.Provider.Debug("E12 stores do not support open-by-mdb-guid functionality. Will use random mdb guid to connect to a newly created mailbox.", new object[0]);
                    guidMdb = Guid.NewGuid();
                    text    = "(random)";
                }
            }
            TimeSpan timeSpan;
            TimeSpan callTimeout;

            if (base.Credential != null)
            {
                timeSpan    = base.TestIntegration.RemoteMailboxConnectionTimeout;
                callTimeout = base.TestIntegration.RemoteMailboxCallTimeout;
            }
            else
            {
                timeSpan    = base.TestIntegration.LocalMailboxConnectionTimeout;
                callTimeout = base.TestIntegration.LocalMailboxCallTimeout;
            }
            string applicationId = "Client=MSExchangeMigration";

            if ((mailboxConnectFlags & MailboxConnectFlags.PublicFolderHierarchyReplication) != MailboxConnectFlags.None)
            {
                applicationId = "Client=PublicFolderSystem;Action=PublicFolderHierarchyReplication";
            }
            for (;;)
            {
                string text2 = (!string.IsNullOrEmpty(serverFqdn)) ? serverFqdn : serverLegDN;
                try
                {
                    using (base.RHTracker.Start())
                    {
                        ConnectFlag connectFlag2 = connectFlag;
                        if (base.IsTitanium)
                        {
                            connectFlag2 |= ConnectFlag.AllowLegacyStore;
                            MrsTracer.Provider.Debug("Opening Ti MapiStore: serverDN='{0}', mailboxDN='{1}', connectFlags=[{2}], openStoreFlags=[{3}], timeout={4}", new object[]
                            {
                                text2,
                                base.MailboxDN,
                                connectFlag2,
                                openStoreFlag,
                                timeSpan
                            });
                            mapiStore = MapiStore.OpenMailbox(text2, Server.GetSystemAttendantLegacyDN(serverLegDN), base.MailboxDN, userName, domainName, password, null, connectFlag2, openStoreFlag, null, null, applicationId, timeSpan, callTimeout);
                        }
                        else
                        {
                            if (base.IsExchange2007)
                            {
                                connectFlag2 |= ConnectFlag.AllowLegacyStore;
                            }
                            MrsTracer.Provider.Debug("Opening MapiStore: serverDN='{0}', mailbox='{1}', mailboxGuid={2}, dbGuid={3}, connectFlags=[{4}], openStoreFlags=[{5}], timeout={6}", new object[]
                            {
                                text2,
                                base.TraceMailboxId,
                                base.MailboxGuid.ToString(),
                                text,
                                connectFlag2,
                                openStoreFlag,
                                timeSpan
                            });
                            mapiStore = MapiStore.OpenMailbox(text2, Server.GetSystemAttendantLegacyDN(serverLegDN), base.MailboxGuid, guidMdb, userName, domainName, password, connectFlag2, openStoreFlag, null, null, applicationId, timeSpan, callTimeout, null);
                        }
                        MapiUtils.StartMapiDeadSessionChecking(mapiStore, base.TraceMailboxId);
                    }
                }
                catch (MapiExceptionNotFound originalException)
                {
                    base.VerifyMdbIsOnline(originalException);
                    if (mailboxMustExist)
                    {
                        throw;
                    }
                }
                catch (MapiExceptionWrongServer originalException2)
                {
                    if (base.IsTitanium)
                    {
                        base.VerifyMdbIsOnline(originalException2);
                        if (mailboxMustExist)
                        {
                            throw;
                        }
                    }
                    else
                    {
                        if (!flag)
                        {
                            MrsTracer.Provider.Debug("OpenMailbox returned WrongServer, forcing AM rediscovery", new object[0]);
                            base.ResolveMDB(true);
                            serverLegDN = base.ServerDN;
                            serverFqdn  = base.ServerFqdn;
                            flag        = true;
                            continue;
                        }
                        throw;
                    }
                }
                catch (MapiExceptionLogonFailed originalException3)
                {
                    if (!base.IsTitanium && !flag)
                    {
                        MrsTracer.Provider.Debug("OpenMailbox returned LogonFailed, forcing AM rediscovery", new object[0]);
                        base.ResolveMDB(true);
                        serverLegDN = base.ServerDN;
                        serverFqdn  = base.ServerFqdn;
                        flag        = true;
                        continue;
                    }
                    base.VerifyMdbIsOnline(originalException3);
                    if (mailboxMustExist)
                    {
                        throw;
                    }
                }
                catch (MapiExceptionMailboxInTransit innerException)
                {
                    throw this.GetMailboxInTransitException(innerException);
                }
                break;
            }
            return(mapiStore);
        }
Example #7
0
 public J2534Err Connect(int deviceId, ProtocolID protocolId, ConnectFlag flags, int baudRate, ref int channelId)
 {
     return((J2534Err)m_wrapper.Connect(deviceId, (int)protocolId, (int)flags, baudRate, ref channelId));
 }
Example #8
0
 /// <summary>
 /// connect to selected protocol
 /// Must provide protocol, speed, connection flags, recommended optional is pins
 /// </summary>
 private Response <J2534Err> ConnectToProtocol(ProtocolID ReqProtocol, BaudRate Speed, ConnectFlag ConnectFlags)
 {
     OBDError = J2534Port.Functions.PassThruConnect(DeviceID, ReqProtocol, ConnectFlags, Speed, ref ChannelID);
     if (OBDError != J2534Err.STATUS_NOERROR)
     {
         return(Response.Create(ResponseStatus.Error, OBDError));
     }
     Protocol       = ReqProtocol;
     IsProtocolOpen = true;
     return(Response.Create(ResponseStatus.Success, OBDError));
 }
Example #9
0
 public J2534Err Connect(int deviceId, ProtocolID protocolId, ConnectFlag flags, int baudRate, ref int channelId)
 {
     return (J2534Err)m_wrapper.Connect(deviceId, (int)protocolId, (int)flags, baudRate, ref channelId);
 }
Example #10
0
        public static MapiStore GetSystemMailbox(Guid mdbGuid, string dcName, NetworkCredential cred, bool allowCrossSiteLogon)
        {
            bool        flag        = false;
            ConnectFlag connectFlag = ConnectFlag.UseAdminPrivilege | ConnectFlag.AllowLegacyStore;
            string      userName;
            string      password;
            string      domainName;
            TimeSpan    connectionTimeout;
            TimeSpan    callTimeout;

            if (cred != null)
            {
                userName          = cred.UserName;
                password          = cred.Password;
                domainName        = cred.Domain;
                connectionTimeout = TestIntegration.Instance.RemoteMailboxConnectionTimeout;
                callTimeout       = TestIntegration.Instance.RemoteMailboxCallTimeout;
            }
            else
            {
                userName          = null;
                password          = null;
                domainName        = null;
                connectFlag      |= ConnectFlag.UseRpcContextPool;
                connectionTimeout = TestIntegration.Instance.LocalMailboxConnectionTimeout;
                callTimeout       = TestIntegration.Instance.LocalMailboxCallTimeout;
            }
            DatabaseInformation databaseInformation;

            for (;;)
            {
                FindServerFlags findServerFlags = FindServerFlags.FindSystemMailbox;
                if (flag)
                {
                    findServerFlags |= FindServerFlags.ForceRediscovery;
                }
                databaseInformation = MapiUtils.FindServerForMdb(mdbGuid, dcName, cred, findServerFlags);
                if (!allowCrossSiteLogon && !databaseInformation.IsInLocalSite)
                {
                    break;
                }
                MapiStore result;
                try
                {
                    MapiStore mapiStore = MapiStore.OpenMailbox(databaseInformation.ServerFqdn, Server.GetSystemAttendantLegacyDN(databaseInformation.ServerDN), databaseInformation.SystemMailboxGuid, mdbGuid, userName, domainName, password, connectFlag, OpenStoreFlag.UseAdminPrivilege | OpenStoreFlag.TakeOwnership | OpenStoreFlag.MailboxGuid, CultureInfo.InvariantCulture, null, "Client=MSExchangeMigration", connectionTimeout, callTimeout, null);
                    MapiUtils.StartMapiDeadSessionChecking(mapiStore, mdbGuid.ToString());
                    result = mapiStore;
                }
                catch (MapiExceptionWrongServer)
                {
                    if (!flag)
                    {
                        MrsTracer.Common.Debug("OpenMailbox returned WrongServer, forcing AM rediscovery", new object[0]);
                        flag = true;
                        continue;
                    }
                    throw;
                }
                catch (MapiExceptionLogonFailed)
                {
                    if (!flag)
                    {
                        MrsTracer.Common.Debug("OpenMailbox returned LogonFailed, forcing AM rediscovery", new object[0]);
                        flag = true;
                        continue;
                    }
                    throw;
                }
                catch (MapiExceptionUnknownUser)
                {
                    if (!flag)
                    {
                        MrsTracer.Common.Debug("OpenMailbox returned UnknownUser, forcing AM rediscovery", new object[0]);
                        flag = true;
                        continue;
                    }
                    throw;
                }
                return(result);
            }
            throw new CrossSiteLogonTransientException(mdbGuid, databaseInformation.ServerGuid, databaseInformation.ServerSite.ToString(), CommonUtils.LocalSiteId.ToString());
        }
Example #11
0
        public static MapiStore GetUserMailbox(Guid mailboxGuid, Guid mdbGuid, UserMailboxFlags umFlags)
        {
            OpenStoreFlag openStoreFlag = OpenStoreFlag.UseAdminPrivilege | OpenStoreFlag.TakeOwnership | OpenStoreFlag.NoLocalization | OpenStoreFlag.MailboxGuid;
            ConnectFlag   connectFlags  = ConnectFlag.UseAdminPrivilege | ConnectFlag.UseRpcContextPool | ConnectFlag.AllowLegacyStore;

            if (umFlags.HasFlag(UserMailboxFlags.RecoveryMDB))
            {
                openStoreFlag |= OpenStoreFlag.RestoreDatabase;
            }
            if (umFlags.HasFlag(UserMailboxFlags.Disconnected) || umFlags.HasFlag(UserMailboxFlags.SoftDeleted) || umFlags.HasFlag(UserMailboxFlags.MoveDestination))
            {
                openStoreFlag |= (OpenStoreFlag.OverrideHomeMdb | OpenStoreFlag.DisconnectedMailbox);
            }
            bool      flag = false;
            TimeSpan  localMailboxConnectionTimeout = TestIntegration.Instance.LocalMailboxConnectionTimeout;
            TimeSpan  localMailboxCallTimeout       = TestIntegration.Instance.LocalMailboxCallTimeout;
            MapiStore result;

            for (;;)
            {
                FindServerFlags findServerFlags = FindServerFlags.None;
                if (flag)
                {
                    findServerFlags |= FindServerFlags.ForceRediscovery;
                }
                DatabaseInformation databaseInformation = MapiUtils.FindServerForMdb(mdbGuid, null, null, findServerFlags);
                try
                {
                    MrsTracer.Common.Debug("Opening MapiStore: serverFqdn=\"{0}\", mailboxGuid=\"{1}\", mdbGuid=\"{2}\", flags=[{3}].", new object[]
                    {
                        databaseInformation.ServerFqdn,
                        mailboxGuid,
                        mdbGuid,
                        openStoreFlag
                    });
                    MapiStore mapiStore = MapiStore.OpenMailbox(databaseInformation.ServerFqdn, Server.GetSystemAttendantLegacyDN(databaseInformation.ServerDN), mailboxGuid, mdbGuid, null, null, null, connectFlags, openStoreFlag, null, null, "Client=MSExchangeMigration", localMailboxConnectionTimeout, localMailboxCallTimeout, null);
                    MapiUtils.StartMapiDeadSessionChecking(mapiStore, mailboxGuid.ToString());
                    result = mapiStore;
                }
                catch (MapiExceptionWrongServer)
                {
                    if (!flag)
                    {
                        MrsTracer.Common.Debug("OpenMailbox returned WrongServer, forcing AM rediscovery", new object[0]);
                        flag = true;
                        continue;
                    }
                    throw;
                }
                catch (MapiExceptionLogonFailed)
                {
                    if (!flag)
                    {
                        MrsTracer.Common.Debug("OpenMailbox returned LogonFailed, forcing AM rediscovery", new object[0]);
                        flag = true;
                        continue;
                    }
                    throw;
                }
                break;
            }
            return(result);
        }
Example #12
0
        private StoreSession ConnectToTargetMailbox(bool mailboxMustExist, MailboxConnectFlags mailboxConnectFlags)
        {
            MrsTracer.Provider.Function("StorageDestinationMailbox.ConnectToTargetMailbox", new object[0]);
            base.CheckDisposed();
            StoreSession result      = null;
            ConnectFlag  connectFlag = ConnectFlag.UseAdminPrivilege;

            connectFlag |= ConnectFlag.UseRpcContextPool;
            if (!mailboxMustExist)
            {
                bool flag = false;
                MrsTracer.Provider.Debug("Checking if destination mailbox exists...", new object[0]);
                using (ExRpcAdmin rpcAdmin = base.GetRpcAdmin())
                {
                    using (base.RHTracker.Start())
                    {
                        flag = MapiUtils.IsMailboxInDatabase(rpcAdmin, base.MdbGuid, base.MailboxGuid);
                    }
                }
                if (!flag)
                {
                    MrsTracer.Provider.Debug("Mailbox {0} does not exist in database {1}", new object[]
                    {
                        base.MailboxGuid,
                        base.MdbGuid
                    });
                    return(null);
                }
                MrsTracer.Provider.Debug("Mailbox {0} exists in database {1}", new object[]
                {
                    base.MailboxGuid,
                    base.MdbGuid
                });
            }
            StoreSession storeSession = null;

            try
            {
                using (base.RHTracker.Start())
                {
                    DefaultFolderType[] foldersToInit = (DefaultFolderType[])Enum.GetValues(typeof(DefaultFolderType));
                    MailboxSession.InitializationFlags initializationFlags = MailboxSession.InitializationFlags.DefaultFolders | MailboxSession.InitializationFlags.UserConfigurationManager | MailboxSession.InitializationFlags.DeadSessionChecking | MailboxSession.InitializationFlags.RequestLocalRpc | MailboxSession.InitializationFlags.OverrideHomeMdb | MailboxSession.InitializationFlags.SuppressFolderIdPrefetch | MailboxSession.InitializationFlags.UseNamedProperties | MailboxSession.InitializationFlags.DisconnectedMailbox | MailboxSession.InitializationFlags.MoveUser;
                    if (base.MbxType == MailboxType.DestMailboxCrossOrg)
                    {
                        initializationFlags |= MailboxSession.InitializationFlags.XForestMove;
                    }
                    MrsTracer.Provider.Debug("Opening Mailbox Session: mailbox='{0}', mailboxGuid={1}, dbGuid={2}, connectFlags=[{3}], initFlags=[{4}]", new object[]
                    {
                        base.TraceMailboxId,
                        base.MailboxGuid.ToString(),
                        base.MdbGuid.ToString(),
                        connectFlag,
                        initializationFlags
                    });
                    OrganizationId organizationId;
                    if (base.PartitionHint != null)
                    {
                        ADSessionSettings adsessionSettings = ADSessionSettings.FromTenantPartitionHint(base.PartitionHint);
                        organizationId = adsessionSettings.CurrentOrganizationId;
                    }
                    else
                    {
                        organizationId = OrganizationId.ForestWideOrgId;
                    }
                    ExchangePrincipal exchangePrincipal = ExchangePrincipal.FromMailboxData(base.MailboxGuid, base.MdbGuid, organizationId, StorageMailbox.CultureInfos);
                    string            clientInfoString  = "Client=MSExchangeMigration";
                    if ((mailboxConnectFlags & MailboxConnectFlags.PublicFolderHierarchyReplication) != MailboxConnectFlags.None)
                    {
                        clientInfoString = "Client=PublicFolderSystem;Action=PublicFolderHierarchyReplication";
                    }
                    if (base.IsPublicFolderMailbox)
                    {
                        storeSession = PublicFolderSession.OpenAsMRS(exchangePrincipal, clientInfoString, OpenMailboxSessionFlags.None);
                    }
                    else
                    {
                        MailboxAccessInfo accessInfo = new MailboxAccessInfo(new WindowsPrincipal(WindowsIdentity.GetCurrent()));
                        storeSession = MailboxSession.ConfigurableOpen(exchangePrincipal, accessInfo, CultureInfo.InvariantCulture, clientInfoString, LogonType.SystemService, null, initializationFlags, foldersToInit);
                    }
                    if (!base.TestIntegration.DisableFolderCreationBlockFeature)
                    {
                        storeSession.BlockFolderCreation = true;
                    }
                    if (storeSession != null && base.Flags.HasFlag(LocalMailboxFlags.WordBreak))
                    {
                        bool invalidateAnnotations = base.Flags.HasFlag(LocalMailboxFlags.InvalidateContentIndexAnnotations);
                        storeSession.ContentIndexingSession = ContentIndexingSession.CreateSession(storeSession, invalidateAnnotations);
                    }
                    result       = storeSession;
                    storeSession = null;
                }
            }
            catch (Exception ex)
            {
                if (CommonUtils.ExceptionIs(ex, new WellKnownException[]
                {
                    WellKnownException.MapiNotFound
                }))
                {
                    base.VerifyMdbIsOnline(ex);
                    if (mailboxMustExist)
                    {
                        throw;
                    }
                }
                else
                {
                    if (CommonUtils.ExceptionIs(ex, new WellKnownException[]
                    {
                        WellKnownException.MapiMailboxInTransit
                    }))
                    {
                        throw this.GetMailboxInTransitException(ex);
                    }
                    throw;
                }
            }
            finally
            {
                if (storeSession != null)
                {
                    storeSession.Dispose();
                }
            }
            return(result);
        }