示例#1
0
        private void txtValues_TextChanged(Object eventSender, EventArgs eventArgs)
        {
            int Index = Array.IndexOf(txtValues, eventSender);

            if (!codeGeneratedChange)
            {
                editingData         = true;
                codeGeneratedChange = true;
                //UPGRADE_WARNING: (2080) IsEmpty was upgraded to a comparison and has a new behavior. More Information: http://www.vbtonet.com/ewis/ewi2080.aspx
                if (!String.IsNullOrEmpty(txtValues[0].Text))
                {
                    changedStockPrice = Double.Parse(txtValues[0].Text);
                }
                //UPGRADE_WARNING: (2080) IsEmpty was upgraded to a comparison and has a new behavior. More Information: http://www.vbtonet.com/ewis/ewi2080.aspx
                if (!String.IsNullOrEmpty(txtValues[1].Text))
                {
                    changedStock = Double.Parse(txtValues[1].Text);
                }
                switch (Index)
                {
                case 1:
                    if (changedStock > currentStock)
                    {
                        changedStock = currentStock;
                        modMain.LogStatus("Cannot pass the original stock, to add more, add a new stock manually", this);
                        txtValues[1].Text = changedStock.ToString();
                    }
                    break;
                }
                lblNewQuantity.Text     = StringsHelper.Format(changedStock * Double.Parse(currentQuantityPerUnit), "##,###.00") + currentUnit;
                lblCurrentQuantity.Text = StringsHelper.Format(currentStock * Double.Parse(currentQuantityPerUnit), "##,###.00") + currentUnit;
                codeGeneratedChange     = false;
            }
        }
示例#2
0
        public static SafeFreeCredentials AcquireCredentialsHandle(SSPIInterface secModule, string package, Interop.SspiCli.CredentialUse intent, Interop.SspiCli.SCHANNEL_CRED scc)
        {
            if (NetEventSource.IsEnabled)
            {
                NetEventSource.Enter(null, package);
                NetEventSource.Log.AcquireCredentialsHandle(package, intent, scc);
            }

            SafeFreeCredentials outCredential = null;
            int errorCode = secModule.AcquireCredentialsHandle(
                package,
                intent,
                ref scc,
                out outCredential);

            if (errorCode != 0)
            {
                if (NetEventSource.IsEnabled)
                {
                    NetEventSource.Error(null, StringsHelper.Format(Strings.net_log_operation_failed_with_error, nameof(AcquireCredentialsHandle), $"0x{errorCode:X}"));
                }
                throw new Win32Exception(errorCode);
            }

            if (NetEventSource.IsEnabled)
            {
                NetEventSource.Exit(null, outCredential);
            }
            return(outCredential);
        }
 private void DisplayTotals()
 {
     currentTotal     = currentFreightCharge + currentSubTotal + currentTotalTax;
     txtSubTotal.Text = StringsHelper.Format(currentSubTotal, "#,##0.00");
     txtTotalTax.Text = StringsHelper.Format(currentTotalTax, "#,##0.00");
     txtTotal.Text    = StringsHelper.Format(currentTotal, "#,##0.00");
 }
        internal static unsafe SafeFreeCredentials AcquireCredentialsHandle(string package, bool isServer, NetworkCredential credential)
        {
            SafeSspiAuthDataHandle authData = null;

            try
            {
                Interop.SECURITY_STATUS result = Interop.SspiCli.SspiEncodeStringsAsAuthIdentity(
                    credential.UserName, credential.Domain,
                    credential.Password, out authData);

                if (result != Interop.SECURITY_STATUS.OK)
                {
                    if (NetEventSource.IsEnabled)
                    {
                        NetEventSource.Error(null, StringsHelper.Format(Strings.net_log_operation_failed_with_error, nameof(Interop.SspiCli.SspiEncodeStringsAsAuthIdentity), $"0x{(int)result:X}"));
                    }
                    throw new Win32Exception((int)result);
                }

                return(SSPIWrapper.AcquireCredentialsHandle(GlobalSSPI.SSPIAuth,
                                                            package, (isServer ? Interop.SspiCli.CredentialUse.SECPKG_CRED_INBOUND : Interop.SspiCli.CredentialUse.SECPKG_CRED_OUTBOUND), ref authData));
            }
            finally
            {
                if (authData != null)
                {
                    authData.Dispose();
                }
            }
        }
示例#5
0
文件: frmSales.cs 项目: xxdoc/SKS
        public void ViewSales(string RcrdFld, string RcrdStr)
        {
            if (cboCashier.SelectedIndex == 0)
            {
                modConnection.ExecuteSql("Select record_no, ProductId, description, gross_amount, net_amount, vat, quantity from tblSales where " + RcrdFld + " LIKE '" + RcrdStr + "%' and format(date_sold, 'm') = " +
                                         cboMonth.SelectedIndex.ToString() + " and format(date_sold,'yyyy') = " + cboYear.Text + " Order by record_no ASC");
            }
            else
            {
                modConnection.ExecuteSql("Select record_no, ProductId, description, gross_amount, net_amount, vat, quantity from tblSales where " + RcrdFld + " LIKE '" + RcrdStr + "%' and format(date_sold, 'm') = " +
                                         cboMonth.SelectedIndex.ToString() + " and format(date_sold,'yyyy') = " + cboYear.Text + " and cashier_id = '" + cboCashier.Text + "' Order by record_no ASC");
            }
            lvwSales.Items.Clear();
            ListViewItem x = null;

            foreach (DataRow iteration_row in modConnection.rs.Tables[0].Rows)
            {
                x = (ListViewItem)lvwSales.Items.Add(Convert.ToString(iteration_row[0]));
                for (modMain.i = 1; modMain.i <= (modConnection.rs.FieldsMetadata.Count - 1); modMain.i++)
                {
                    ListViewHelper.GetListViewSubItem(x, modMain.i).Text = Convert.ToString(iteration_row[modMain.i]);
                }
            }
            modConnection.ExecuteSql("Select format(sum(net_amount),'#0.00') from tblSales where format(date_sold, 'm') = " + cboMonth.SelectedIndex.ToString() + " and format(date_sold,'yyyy') = " + cboYear.Text);
            lblTotalSales.Text = "P " + Conversion.Val(StringsHelper.Format(modConnection.rs[0], "#,##0.00")).ToString();

            modConnection.ExecuteSql("Select ProductId from tblSales where quantity = (Select max(quantity) from tblSales) and format(date_sold, 'm') = " + cboMonth.SelectedIndex.ToString() + " and format(date_sold,'yyyy') = " + cboYear.Text);
            lblSellable.Text = Convert.ToString(modConnection.rs[0]);
        }
示例#6
0
        internal static string FmtSexa(double N, bool ShowPlus)
        {
            string result = "";

            string sg = "+";             // Assume positive

            if (N < 0)
            {             // Check neg.
                N  = -N;  // Make pos.
                sg = "-"; // Remember sign
            }

            int    m  = Convert.ToInt32((N > 0) ? Math.Floor(N) : Math.Ceiling(N));         // Units (deg or hr)
            string us = StringsHelper.Format(m, "00");

            N = (N - m) * 60d;
            m = Convert.ToInt32((N > 0) ? Math.Floor(N) : Math.Ceiling(N));             // Minutes
            string ms = StringsHelper.Format(m, "00");

            N = (N - m) * 60d;
            m = Convert.ToInt32((N > 0) ? Math.Floor(N) : Math.Ceiling(N));             // Minutes
            string ss = StringsHelper.Format(m, "00");

            result = us + ":" + ms + ":" + ss;
            if (ShowPlus || (sg == "-"))
            {
                result = sg + result;
            }

            return(result);
        }
示例#7
0
 private void ReCalculateTotals(double previous, double current)
 {
     currentSubTotal  = currentSubTotal - previous + current;
     currentTotalTax  = currentSubTotal * currentTax * 0.01d;
     currentTotal     = currentFreightCharge + currentSubTotal + currentTotalTax;
     txtSubTotal.Text = StringsHelper.Format(currentSubTotal, "#,##0.00");
     txtTotalTax.Text = StringsHelper.Format(currentTotalTax, "#,##0.00");
     txtTotal.Text    = StringsHelper.Format(currentTotal, "#,##0.00");
 }
 private void AddToTotals(double current)
 {
     currentSubTotal += current;
     currentTotalTax  = currentSubTotal * currentTax;
     currentTotal     = currentFreightCharge + currentSubTotal + currentTotalTax;
     txtSubTotal.Text = StringsHelper.Format(currentSubTotal, "#,##0.00");
     txtTotalTax.Text = StringsHelper.Format(currentTotalTax, "#,##0.00");
     txtTotal.Text    = StringsHelper.Format(currentTotal, "#,##0.00");
 }
示例#9
0
            private static string GetGssApiDisplayStatus(Status majorStatus, Status minorStatus)
            {
                string majorError = GetGssApiDisplayStatus(majorStatus, isMinor: false);
                string minorError = GetGssApiDisplayStatus(minorStatus, isMinor: true);

                return((majorError != null && minorError != null) ?
                       StringsHelper.Format(Strings.net_gssapi_operation_failed_detailed, majorError, minorError) :
                       StringsHelper.Format(Strings.net_gssapi_operation_failed, majorStatus.ToString("x"), minorStatus.ToString("x")));
            }
示例#10
0
        private void RetrieveDataProduct()
        {
            if (editingData)
            {
                if (Mobilize.Web.MessageBox.Show("Do you want to cancel previous edited data?", "Data edition", Mobilize.Web.MessageBoxButtons.YesNo, Mobilize.Web.MessageBoxIcon.Question) != Mobilize.Web.DialogResult.Yes)
                {
                    return;
                }
            }

            bool setEmpty = true;

            Mobilize.Web.ListViewItem withVar = null;
            if (!(lvStocks.FocusedItem is null))
            {
                // UPGRADE_WARNING: (2080) IsEmpty was upgraded to a comparison and has a new behavior. More Information: https://www.mobilize.net/vbtonet/ewis/ewi2080
                if (!(lvStocks.FocusedItem is null))
                {
                    currentIdStock           = Convert.ToInt32(double.Parse(lvStocks.FocusedItem.Text));
                    withVar                  = lvStocks.FocusedItem;
                    currentStock             = double.Parse(Mobilize.Web.ListView.GetListViewSubItem(withVar, 1).Text);
                    currentStockPrice        = double.Parse(Mobilize.Web.ListView.GetListViewSubItem(withVar, 4).Text);
                    codeGeneratedChange      = true;
                    txtOriginalQuantity.Text = currentStock.ToString();
                    txtOriginalPrice.Text    = currentStockPrice.ToString();
                    txtStockID.Text          = currentIdStock.ToString();
                    txtValues[0].Text        = currentStockPrice.ToString();
                    txtValues[1].Text        = currentStock.ToString();
                    lblNewQuantity.Text      = StringsHelper.Format(currentStock * double.Parse(currentQuantityPerUnit), "##,###.00") + currentUnit;
                    lblCurrentQuantity.Text  = StringsHelper.Format(currentStock * double.Parse(currentQuantityPerUnit), "##,###.00") + currentUnit;
                    codeGeneratedChange      = false;
                    setEmpty                 = false;
                    txtValues[0].ReadOnly    = false;
                    txtValues[1].ReadOnly    = false;
                    txtValues[0].Focus();
                }
            }

            if (setEmpty)
            {
                codeGeneratedChange      = true;
                txtOriginalQuantity.Text = "";
                txtOriginalPrice.Text    = "";
                txtStockID.Text          = "";
                txtValues[0].Text        = "";
                txtValues[1].Text        = "";
                lblNewQuantity.Text      = "";
                lblCurrentQuantity.Text  = "";
                codeGeneratedChange      = false;
            }

            editingData = false;
        }
示例#11
0
        private void txtValues_TextChanged(object eventSender, EventArgs eventArgs)
        {
            int Index = Array.IndexOf(this.txtValues, eventSender);

            if (!codeGeneratedChange)
            {
                editingData         = true;
                codeGeneratedChange = true;
                // UPGRADE_WARNING: (2080) IsEmpty was upgraded to a comparison and has a new behavior. More Information: https://www.mobilize.net/vbtonet/ewis/ewi2080
                if (!string.IsNullOrEmpty(txtValues[0].Text))
                {
                    quantity = double.Parse(txtValues[0].Text);
                }

                // UPGRADE_WARNING: (2080) IsEmpty was upgraded to a comparison and has a new behavior. More Information: https://www.mobilize.net/vbtonet/ewis/ewi2080
                if (!string.IsNullOrEmpty(txtValues[1].Text))
                {
                    stockPrice = double.Parse(txtValues[1].Text);
                }

                // UPGRADE_WARNING: (2080) IsEmpty was upgraded to a comparison and has a new behavior. More Information: https://www.mobilize.net/vbtonet/ewis/ewi2080
                if (!string.IsNullOrEmpty(txtValues[2].Text))
                {
                    unitPrice = double.Parse(txtValues[2].Text);
                }

                switch (Index)
                {
                case 0:
                case 2:
                    txtValues[1].Text = (unitPrice * quantity).ToString();
                    break;

                case 1:
                    txtValues[2].Text = (stockPrice / quantity).ToString();
                    break;
                }

                lblNewQuantity.Text = StringsHelper.Format(quantity * double.Parse(currentQuantityPerUnit), "##,###.00") + currentUnit;
                codeGeneratedChange = false;
            }
        }
示例#12
0
        public static SafeFreeCredentials AcquireCredentialsHandle(SSPIInterface secModule, string package, Interop.SspiCli.CredentialUse intent, ref SafeSspiAuthDataHandle authdata)
        {
            if (NetEventSource.IsEnabled)
            {
                NetEventSource.Log.AcquireCredentialsHandle(package, intent, authdata);
            }

            SafeFreeCredentials credentialsHandle = null;
            int errorCode = secModule.AcquireCredentialsHandle(package, intent, ref authdata, out credentialsHandle);

            if (errorCode != 0)
            {
                if (NetEventSource.IsEnabled)
                {
                    NetEventSource.Error(null, StringsHelper.Format(Strings.net_log_operation_failed_with_error, nameof(AcquireCredentialsHandle), $"0x{errorCode:X}"));
                }
                throw new Win32Exception(errorCode);
            }

            return(credentialsHandle);
        }
            internal int Copy(byte[] destination, int offset)
            {
                Debug.Assert(destination != null, "target destination cannot be null");
                Debug.Assert((offset >= 0 && offset < destination.Length) || destination.Length == 0, "invalid offset " + offset);

                if (_data == IntPtr.Zero || _length == 0)
                {
                    return(0);
                }

                // Using Convert.ToInt32 to throw an exception in the unlikely event of too large value of _length
                int sourceLength         = Convert.ToInt32(_length);
                int destinationAvailable = destination.Length - offset;  // amount of space in the given buffer

                if (sourceLength > destinationAvailable)
                {
                    throw new GssApiException(StringsHelper.Format(Strings.net_context_buffer_too_small, sourceLength, destinationAvailable));
                }

                Marshal.Copy(_data, destination, offset, sourceLength);
                return(sourceLength);
            }
示例#14
0
        public unsafe int QueryContextAttributes(SafeDeleteContext context, Interop.SspiCli.ContextAttribute attribute, byte[] buffer, Type handleType, out SafeHandle refHandle)
        {
            refHandle = null;
            if (handleType != null)
            {
                if (handleType == typeof(SafeFreeContextBuffer))
                {
                    refHandle = SafeFreeContextBuffer.CreateEmptyHandle();
                }
                else if (handleType == typeof(SafeFreeCertContext))
                {
                    refHandle = new SafeFreeCertContext();
                }
                else
                {
                    throw new ArgumentException(StringsHelper.Format(Strings.SSPIInvalidHandleType, handleType.FullName), nameof(handleType));
                }
            }

            fixed(byte *bufferPtr = buffer)
            {
                return(SafeFreeContextBuffer.QueryContextAttributes(context, attribute, bufferPtr, refHandle));
            }
        }
示例#15
0
        private static unsafe int EncryptDecryptHelper(OP op, SSPIInterface secModule, SafeDeleteContext context, SecurityBuffer[] input, uint sequenceNumber)
        {
            Interop.SspiCli.SecBufferDesc sdcInOut = new Interop.SspiCli.SecBufferDesc(input.Length);
            var unmanagedBuffer = new Interop.SspiCli.SecBuffer[input.Length];

            fixed(Interop.SspiCli.SecBuffer *unmanagedBufferPtr = unmanagedBuffer)
            {
                sdcInOut.pBuffers = unmanagedBufferPtr;
                GCHandle[] pinnedBuffers = new GCHandle[input.Length];
                byte[][]   buffers       = new byte[input.Length][];
                try
                {
                    for (int i = 0; i < input.Length; i++)
                    {
                        SecurityBuffer iBuffer = input[i];
                        unmanagedBuffer[i].cbBuffer   = iBuffer.size;
                        unmanagedBuffer[i].BufferType = iBuffer.type;
                        if (iBuffer.token == null || iBuffer.token.Length == 0)
                        {
                            unmanagedBuffer[i].pvBuffer = IntPtr.Zero;
                        }
                        else
                        {
                            pinnedBuffers[i]            = GCHandle.Alloc(iBuffer.token, GCHandleType.Pinned);
                            unmanagedBuffer[i].pvBuffer = Marshal.UnsafeAddrOfPinnedArrayElement(iBuffer.token, iBuffer.offset);
                            buffers[i] = iBuffer.token;
                        }
                    }

                    // The result is written in the input Buffer passed as type=BufferType.Data.
                    int errorCode;
                    switch (op)
                    {
                    case OP.Encrypt:
                        errorCode = secModule.EncryptMessage(context, ref sdcInOut, sequenceNumber);
                        break;

                    case OP.Decrypt:
                        errorCode = secModule.DecryptMessage(context, ref sdcInOut, sequenceNumber);
                        break;

                    case OP.MakeSignature:
                        errorCode = secModule.MakeSignature(context, ref sdcInOut, sequenceNumber);
                        break;

                    case OP.VerifySignature:
                        errorCode = secModule.VerifySignature(context, ref sdcInOut, sequenceNumber);
                        break;

                    default:
                        NetEventSource.Fail(null, $"Unknown OP: {op}");
                        throw NotImplemented.ByDesignWithMessage(Strings.net_MethodNotImplementedException);
                    }

                    // Marshalling back returned sizes / data.
                    for (int i = 0; i < input.Length; i++)
                    {
                        SecurityBuffer iBuffer = input[i];
                        iBuffer.size = unmanagedBuffer[i].cbBuffer;
                        iBuffer.type = unmanagedBuffer[i].BufferType;

                        if (iBuffer.size == 0)
                        {
                            iBuffer.offset = 0;
                            iBuffer.token  = null;
                        }
                        else
                        {
                            checked
                            {
                                // Find the buffer this is inside of.  Usually they all point inside buffer 0.
                                int j;
                                for (j = 0; j < input.Length; j++)
                                {
                                    if (buffers[j] == null)
                                    {
                                        continue;
                                    }

                                    byte *bufferAddress = (byte *)Marshal.UnsafeAddrOfPinnedArrayElement(buffers[j], 0);
                                    if ((byte *)unmanagedBuffer[i].pvBuffer >= bufferAddress &&
                                        (byte *)unmanagedBuffer[i].pvBuffer + iBuffer.size <= bufferAddress + buffers[j].Length)
                                    {
                                        iBuffer.offset = (int)((byte *)unmanagedBuffer[i].pvBuffer - bufferAddress);
                                        iBuffer.token  = buffers[j];
                                        break;
                                    }
                                }

                                if (j >= input.Length)
                                {
                                    NetEventSource.Fail(null, "Output buffer out of range.");
                                    iBuffer.size   = 0;
                                    iBuffer.offset = 0;
                                    iBuffer.token  = null;
                                }
                            }
                        }

                        // Backup validate the new sizes.
                        if (iBuffer.offset < 0 || iBuffer.offset > (iBuffer.token == null ? 0 : iBuffer.token.Length))
                        {
                            NetEventSource.Fail(null, $"'offset' out of range.  [{iBuffer.offset}]");
                        }

                        if (iBuffer.size < 0 || iBuffer.size > (iBuffer.token == null ? 0 : iBuffer.token.Length - iBuffer.offset))
                        {
                            NetEventSource.Fail(null, $"'size' out of range.  [{iBuffer.size}]");
                        }
                    }

                    if (NetEventSource.IsEnabled && errorCode != 0)
                    {
                        if (errorCode == Interop.SspiCli.SEC_I_RENEGOTIATE)
                        {
                            NetEventSource.Error(null, StringsHelper.Format(Strings.event_OperationReturnedSomething, op, "SEC_I_RENEGOTIATE"));
                        }
                        else
                        {
                            NetEventSource.Error(null, StringsHelper.Format(Strings.net_log_operation_failed_with_error, op, $"0x{0:X}"));
                        }
                    }

                    return(errorCode);
                }
                finally
                {
                    for (int i = 0; i < pinnedBuffers.Length; ++i)
                    {
                        if (pinnedBuffers[i].IsAllocated)
                        {
                            pinnedBuffers[i].Free();
                        }
                    }
                }
            }
        }
示例#16
0
        public static object QueryContextAttributes(SSPIInterface secModule, SafeDeleteContext securityContext, Interop.SspiCli.ContextAttribute contextAttribute, out int errorCode)
        {
            if (NetEventSource.IsEnabled)
            {
                NetEventSource.Enter(null, contextAttribute);
            }

            int  nativeBlockSize = IntPtr.Size;
            Type handleType      = null;

            switch (contextAttribute)
            {
            case Interop.SspiCli.ContextAttribute.SECPKG_ATTR_SIZES:
                nativeBlockSize = SecPkgContext_Sizes.SizeOf;
                break;

            case Interop.SspiCli.ContextAttribute.SECPKG_ATTR_STREAM_SIZES:
                nativeBlockSize = SecPkgContext_StreamSizes.SizeOf;
                break;

            case Interop.SspiCli.ContextAttribute.SECPKG_ATTR_NAMES:
                handleType = typeof(SafeFreeContextBuffer);
                break;

            case Interop.SspiCli.ContextAttribute.SECPKG_ATTR_PACKAGE_INFO:
                handleType = typeof(SafeFreeContextBuffer);
                break;

            case Interop.SspiCli.ContextAttribute.SECPKG_ATTR_NEGOTIATION_INFO:
                handleType = typeof(SafeFreeContextBuffer);
                unsafe
                {
                    nativeBlockSize = sizeof(SecPkgContext_NegotiationInfoW);
                }
                break;

            case Interop.SspiCli.ContextAttribute.SECPKG_ATTR_CLIENT_SPECIFIED_TARGET:
                handleType = typeof(SafeFreeContextBuffer);
                break;

            case Interop.SspiCli.ContextAttribute.SECPKG_ATTR_REMOTE_CERT_CONTEXT:
                handleType = typeof(SafeFreeCertContext);
                break;

            case Interop.SspiCli.ContextAttribute.SECPKG_ATTR_LOCAL_CERT_CONTEXT:
                handleType = typeof(SafeFreeCertContext);
                break;

            case Interop.SspiCli.ContextAttribute.SECPKG_ATTR_ISSUER_LIST_EX:
                nativeBlockSize = Marshal.SizeOf <Interop.SspiCli.SecPkgContext_IssuerListInfoEx>();
                handleType      = typeof(SafeFreeContextBuffer);
                break;

            case Interop.SspiCli.ContextAttribute.SECPKG_ATTR_CONNECTION_INFO:
                nativeBlockSize = Marshal.SizeOf <SecPkgContext_ConnectionInfo>();
                break;

            case Interop.SspiCli.ContextAttribute.SECPKG_ATTR_APPLICATION_PROTOCOL:
                nativeBlockSize = Marshal.SizeOf <Interop.SecPkgContext_ApplicationProtocol>();
                break;

            default:
                throw new ArgumentException(StringsHelper.Format(Strings.net_invalid_enum, nameof(contextAttribute)), nameof(contextAttribute));
            }

            SafeHandle sspiHandle = null;
            object     attribute  = null;

            try
            {
                var nativeBuffer = new byte[nativeBlockSize];
                errorCode = secModule.QueryContextAttributes(securityContext, contextAttribute, nativeBuffer, handleType, out sspiHandle);
                if (errorCode != 0)
                {
                    if (NetEventSource.IsEnabled)
                    {
                        NetEventSource.Exit(null, $"ERROR = {ErrorDescription(errorCode)}");
                    }
                    return(null);
                }

                switch (contextAttribute)
                {
                case Interop.SspiCli.ContextAttribute.SECPKG_ATTR_SIZES:
                    attribute = new SecPkgContext_Sizes(nativeBuffer);
                    break;

                case Interop.SspiCli.ContextAttribute.SECPKG_ATTR_STREAM_SIZES:
                    attribute = new SecPkgContext_StreamSizes(nativeBuffer);
                    break;

                case Interop.SspiCli.ContextAttribute.SECPKG_ATTR_NAMES:
                    attribute = Marshal.PtrToStringUni(sspiHandle.DangerousGetHandle());
                    break;

                case Interop.SspiCli.ContextAttribute.SECPKG_ATTR_PACKAGE_INFO:
                    attribute = new SecurityPackageInfoClass(sspiHandle, 0);
                    break;

                case Interop.SspiCli.ContextAttribute.SECPKG_ATTR_NEGOTIATION_INFO:
                    unsafe
                    {
                        fixed(void *ptr = &nativeBuffer[0])
                        {
                            attribute = new NegotiationInfoClass(sspiHandle, (int)((SecPkgContext_NegotiationInfoW *)ptr)->NegotiationState);
                        }
                    }
                    break;

                case Interop.SspiCli.ContextAttribute.SECPKG_ATTR_CLIENT_SPECIFIED_TARGET:
                    attribute = Marshal.PtrToStringUni(sspiHandle.DangerousGetHandle());
                    break;

                case Interop.SspiCli.ContextAttribute.SECPKG_ATTR_LOCAL_CERT_CONTEXT:
                // Fall-through to RemoteCertificate is intentional.
                case Interop.SspiCli.ContextAttribute.SECPKG_ATTR_REMOTE_CERT_CONTEXT:
                    attribute  = sspiHandle;
                    sspiHandle = null;
                    break;

                case Interop.SspiCli.ContextAttribute.SECPKG_ATTR_ISSUER_LIST_EX:
                    attribute  = new Interop.SspiCli.SecPkgContext_IssuerListInfoEx(sspiHandle, nativeBuffer);
                    sspiHandle = null;
                    break;

                case Interop.SspiCli.ContextAttribute.SECPKG_ATTR_CONNECTION_INFO:
                    attribute = new SecPkgContext_ConnectionInfo(nativeBuffer);
                    break;

                case Interop.SspiCli.ContextAttribute.SECPKG_ATTR_APPLICATION_PROTOCOL:
                    unsafe
                    {
                        fixed(void *ptr = nativeBuffer)
                        {
                            attribute = Marshal.PtrToStructure <Interop.SecPkgContext_ApplicationProtocol>(new IntPtr(ptr));
                        }
                    }
                    break;

                default:
                    // Will return null.
                    break;
                }
            }
            finally
            {
                if (sspiHandle != null)
                {
                    sspiHandle.Dispose();
                }
            }

            if (NetEventSource.IsEnabled)
            {
                NetEventSource.Exit(null, attribute);
            }
            return(attribute);
        }
示例#17
0
        // called from the encoder timer to supervise active gotos
        internal static void ManageGoto()
        {
            object oLangDll = null;

            object[] EQ_Beep  = null;
            object   HC       = null;
            double   ra_diff  = 0;
            double   dec_diff = 0;

            //'''''''''''''''''''''''''''''''''''''''''''''
            // Fixed rate slew
            //'''''''''''''''''''''''''''''''''''''''''''''
            if (gGotoParams.RA_SlewActive == 1 || gGotoParams.DEC_SlewActive == 1)
            {
                // Handle as fixed rate slew
                if (gGotoParams.RA_SlewActive != 0)
                {
                    if (gGotoParams.RA_Direction == 0)
                    {
                        if (EQMath.gRA_Encoder >= gGotoParams.RA_targetencoder)
                        {
                            EQMath.eqres = UpgradeSolution1Support.PInvoke.SafeNative.eqcontrl.EQ_MotorStop(0);
                            //                    Do
                            //                        eqres = EQ_GetMotorStatus(0)
                            //                        If (eqres = EQ_NOTINITIALIZED) Or (eqres = EQ_COMNOTOPEN) Or (eqres = EQ_COMTIMEOUT) Then GoTo MG1
                            //                    Loop While (eqres And EQ_MOTORBUSY) <> 0
                            //MG1:
                            gGotoParams.RA_SlewActive = 0;
                            EQMath.eqres = UpgradeSolution1Support.PInvoke.SafeNative.eqcontrl.EQ_StartRATrack(0, EQMath.gHemisphere, EQMath.gHemisphere);
                        }
                    }
                    else
                    {
                        if (EQMath.gRA_Encoder <= gGotoParams.RA_targetencoder)
                        {
                            EQMath.eqres = UpgradeSolution1Support.PInvoke.SafeNative.eqcontrl.EQ_MotorStop(0);
                            //                    Do
                            //                        eqres = EQ_GetMotorStatus(0)
                            //                        If (eqres = EQ_NOTINITIALIZED) Or (eqres = EQ_COMNOTOPEN) Or (eqres = EQ_COMTIMEOUT) Then GoTo MG2
                            //                    Loop While (eqres And EQ_MOTORBUSY) <> 0
                            //MG2:
                            gGotoParams.RA_SlewActive = 0;
                            EQMath.eqres = UpgradeSolution1Support.PInvoke.SafeNative.eqcontrl.EQ_StartRATrack(0, EQMath.gHemisphere, EQMath.gHemisphere);
                        }
                    }
                }

                if (gGotoParams.DEC_SlewActive != 0)
                {
                    if (gGotoParams.DEC_Direction == 0)
                    {
                        if (EQMath.gDec_Encoder >= gGotoParams.DEC_targetencoder)
                        {
                            EQMath.eqres = UpgradeSolution1Support.PInvoke.SafeNative.eqcontrl.EQ_MotorStop(1);
                            //                    Do
                            //                        eqres = EQ_GetMotorStatus(1)
                            //                       If (eqres = EQ_NOTINITIALIZED) Or (eqres = EQ_COMNOTOPEN) Or (eqres = EQ_COMTIMEOUT) Then GoTo MG3
                            //                    Loop While (eqres And EQ_MOTORBUSY) <> 0
                            //MG3:
                            gGotoParams.DEC_SlewActive = 0;
                        }
                    }
                    else
                    {
                        if (EQMath.gDec_Encoder <= gGotoParams.DEC_targetencoder)
                        {
                            EQMath.eqres = UpgradeSolution1Support.PInvoke.SafeNative.eqcontrl.EQ_MotorStop(1);
                            //                    Do
                            //                        eqres = EQ_GetMotorStatus(1)
                            //                        If (eqres = EQ_NOTINITIALIZED) Or (eqres = EQ_COMNOTOPEN) Or (eqres = EQ_COMTIMEOUT) Then GoTo MG4
                            //                    Loop While (eqres And EQ_MOTORBUSY) <> 0
                            //MG4:
                            gGotoParams.DEC_SlewActive = 0;
                        }
                    }
                }


                if (gGotoParams.RA_SlewActive == 0 && gGotoParams.DEC_SlewActive == 0)
                {
                    switch (gGotoParams.SuperSafeMode)
                    {
                    case 0:
                        // rough fixed rate slew complete
                        CalcEncoderTargets();
                        ra_diff  = Math.Abs(gGotoParams.RA_targetencoder - EQMath.gRA_Encoder);
                        dec_diff = Math.Abs(gGotoParams.DEC_targetencoder - EQMath.gDec_Encoder);
                        //UPGRADE_TODO: (1067) Member Add_Message is not defined in type Variant. More Information: https://www.mobilize.net/vbtonet/ewis/ewi1067
                        HC.Add_Message("Goto: FRSlew complete ra_diff=" + ra_diff.ToString() + " dec_diff=" + dec_diff.ToString());
                        if ((ra_diff < EQMath.gTot_RA / 360d) && (dec_diff < EQMath.gTot_DEC / 540d))
                        {
                            // initiate a standard itterative goto if within a 3/4 of a degree.
                            gGotoParams.rate = 0;
                            StartSlew(gGotoParams.RA_targetencoder, gGotoParams.DEC_targetencoder, gGotoParams.RA_currentencoder, gGotoParams.DEC_currentencoder);
                        }
                        else
                        {
                            // Do another rough slew.
                            //UPGRADE_TODO: (1067) Member Add_Message is not defined in type Variant. More Information: https://www.mobilize.net/vbtonet/ewis/ewi1067
                            HC.Add_Message("Goto: FRSlew");
                            gFRSlewCount++;
                            if (gFRSlewCount >= 5)
                            {
                                //if we can't get close after 5 attempts then abandon the FR slew
                                //and use the full speed iterative slew
                                gFRSlewCount     = 0;
                                gGotoParams.rate = 0;
                            }
                            StartSlew(gGotoParams.RA_targetencoder, gGotoParams.DEC_targetencoder, gGotoParams.RA_currentencoder, gGotoParams.DEC_currentencoder);
                        }

                        break;

                    case 1:
                        // move to RA target
                        CalcEncoderTargets();
                        gGotoParams.SuperSafeMode = 0;
                        StartSlew(gGotoParams.RA_targetencoder, gGotoParams.DEC_targetencoder, gGotoParams.RA_currentencoder, gGotoParams.DEC_currentencoder);

                        //                Case 2
                        //                    ' we're at a limit about to go to target
                        //                    Call CalcEncoderTargets
                        //                    gGotoParams.SuperSafeMode = 0
                        //                    Call StartSlew(gGotoParams.RA_targetencoder, gGotoParams.DEC_targetencoder, gGotoParams.RA_currentencoder, gGotoParams.DEC_currentencoder)

                        break;

                    case 3:
                        // were at a limit position
                        if (gGotoParams.RA_targetencoder > EQMath.RAEncoder_Home_pos)
                        {
                            // dual axis slew to limit position nearest to target
                            gGotoParams.SuperSafeMode = 1;
                            if (!Limits.RALimitsActive())
                            {
                                StartSlew(gRAMeridianWest, gGotoParams.DEC_targetencoder, EQMath.gEmulRA, EQMath.gEmulDEC);
                            }
                            else
                            {
                                StartSlew(EQMath.gRA_Limit_West, gGotoParams.DEC_targetencoder, EQMath.gEmulRA, EQMath.gEmulDEC);
                            }
                        }
                        else
                        {
                            // dual axis slew to limit position nearest to target
                            gGotoParams.SuperSafeMode = 1;
                            if (!Limits.RALimitsActive())
                            {
                                StartSlew(gRAMeridianEast, gGotoParams.DEC_targetencoder, EQMath.gEmulRA, EQMath.gEmulDEC);
                            }
                            else
                            {
                                StartSlew(EQMath.gRA_Limit_East, gGotoParams.DEC_targetencoder, EQMath.gEmulRA, EQMath.gEmulDEC);
                            }
                        }

                        break;
                    }
                }
                return;
            }

            //'''''''''''''''''''''''''''''''''''''''''''''
            // Iterative slew - variable rate
            //'''''''''''''''''''''''''''''''''''''''''''''
            if ((Convert.ToInt32(EQMath.gRAStatus) & Convert.ToInt32(Common.EQ_MOTORBUSY)) == 0)
            {
                //At This point RA motor has completed the slew
                EQMath.gRAStatus_slew = true;
                if ((Convert.ToInt32(EQMath.gDECStatus) & Convert.ToInt32(Common.EQ_MOTORBUSY)) != 0)
                {
                    // The DEC motor is still moving so start sidereal tracking to hold position in RA
                    EQMath.eqres = UpgradeSolution1Support.PInvoke.SafeNative.eqcontrl.EQ_StartRATrack(0, EQMath.gHemisphere, EQMath.gHemisphere);
                }
            }

            if ((Convert.ToInt32(EQMath.gDECStatus) & Convert.ToInt32(Common.EQ_MOTORBUSY)) == 0 && EQMath.gRAStatus_slew)
            {
                //DEC and RA motors have finished slewing at this point
                //We need to check if a new slew is needed to reduce the any difference
                //Caused by the Movement of the earth during the slew process

                switch (gGotoParams.SuperSafeMode)
                {
                case 0:
                    // decrement the slew retry count
                    gSlewCount--;

                    // calculate the difference (arcsec)  between target and current coords
                    ra_diff  = 3600 * Math.Abs(EQMath.gRA - gTargetRA);
                    dec_diff = 3600 * Math.Abs(EQMath.gDec - gTargetDec);

                    if ((gSlewCount > 0) && (EQMath.gTrackingStatus > 0))
                    {                             // Retry only if tracking is enabled
                        // aim to get within the goto resolution (default = 10 steps)
                        if (gGotoResolution > 0 && ra_diff <= gRAGotoRes && dec_diff <= gDECGotoRes)
                        {
                            goto slewcomplete;
                        }
                        else
                        {
                            //Re Execute a new RA-Only slew here
                            CalcEncoderTargets();
                            gGotoParams.rate = 0;
                            StartSlew(gGotoParams.RA_targetencoder, gGotoParams.DEC_targetencoder, gGotoParams.RA_currentencoder, gGotoParams.DEC_currentencoder);
                        }
                    }
                    else
                    {
                        goto slewcomplete;
                    }

                    break;

                case 1:
                    // move to target
                    gGotoParams.SuperSafeMode = 0;
                    CalcEncoderTargets();
                    gGotoParams.rate = 0;
                    //kick of an iterative slew to get us accurately to target RA
                    StartSlew(gGotoParams.RA_targetencoder, gGotoParams.DEC_targetencoder, gGotoParams.RA_currentencoder, gGotoParams.DEC_currentencoder);

                    //            Case 2
                    //                ' At a limit about to slew to target
                    //                Call CalcEncoderTargets
                    //                gGotoParams.SuperSafeMode = 0
                    //               Call StartSlew(gGotoParams.RA_targetencoder, gGotoParams.DEC_targetencoder, gEmulRA, gEmulDEC)

                    break;

                case 3:
                    // we are at a limit position
                    if (gGotoParams.RA_targetencoder > EQMath.RAEncoder_Home_pos)
                    {
                        // dual axis slew to limit position nearest to target
                        gGotoParams.SuperSafeMode = 1;
                        if (!Limits.RALimitsActive())
                        {
                            StartSlew(gRAMeridianWest, gGotoParams.DEC_targetencoder, EQMath.gEmulRA, EQMath.gEmulDEC);
                        }
                        else
                        {
                            StartSlew(EQMath.gRA_Limit_West, gGotoParams.DEC_targetencoder, EQMath.gEmulRA, EQMath.gEmulDEC);
                        }
                    }
                    else
                    {
                        // dual axis slew to limit position nearest to target
                        gGotoParams.SuperSafeMode = 1;
                        if (!Limits.RALimitsActive())
                        {
                            StartSlew(gRAMeridianEast, gGotoParams.DEC_targetencoder, EQMath.gEmulRA, EQMath.gEmulDEC);
                        }
                        else
                        {
                            StartSlew(EQMath.gRA_Limit_West, gGotoParams.DEC_targetencoder, EQMath.gEmulRA, EQMath.gEmulDEC);
                        }
                    }


                    break;
                }
            }
            return;

slewcomplete:
            EQMath.gSlewStatus           = false;
            EQMath.gRAStatus_slew        = false;
            Limits.gSupressHorizonLimits = false;

            // slew may have terminated early if parked
            if (EQMath.gEQparkstatus != 1)
            {
                // we've reached the desired target coords - resume tracking.
                switch (EQMath.gTrackingStatus)
                {
                case 0:
                case 1:
                    Tracking.EQStartSidereal();
                    break;

                case 2:
                case 3:
                case 4:
                    Tracking.RestartTracking();
                    break;
                }

                //UPGRADE_TODO: (1067) Member GetLangString is not defined in type Variant. More Information: https://www.mobilize.net/vbtonet/ewis/ewi1067
                //UPGRADE_TODO: (1067) Member Add_Message is not defined in type Variant. More Information: https://www.mobilize.net/vbtonet/ewis/ewi1067
                HC.Add_Message(Convert.ToString(oLangDll.GetLangString(5018)) + " " + EQMath.FmtSexa(EQMath.gRA, false) + " " + EQMath.FmtSexa(EQMath.gDec, true));
                //UPGRADE_TODO: (1067) Member Add_Message is not defined in type Variant. More Information: https://www.mobilize.net/vbtonet/ewis/ewi1067
                HC.Add_Message("Goto: SlewItereations=" + (gMaxSlewCount - gSlewCount).ToString());
                //UPGRADE_TODO: (1067) Member Add_Message is not defined in type Variant. More Information: https://www.mobilize.net/vbtonet/ewis/ewi1067
                HC.Add_Message("Goto: " + "RaDiff=" + StringsHelper.Format(Conversion.Str(ra_diff), "000.00") + " DecDiff=" + StringsHelper.Format(Conversion.Str(dec_diff), "000.00"));

                // goto complete
                object tempAuxVar = EQ_Beep[6];
            }

            if (gDisbleFlipGotoReset == 0)
            {
                //UPGRADE_TODO: (1067) Member ChkForceFlip is not defined in type Variant. More Information: https://www.mobilize.net/vbtonet/ewis/ewi1067
                HC.ChkForceFlip.value = 0;
            }
        }