Esempio n. 1
0
    public static void processWireCone(GizmoCoords coords,
                                       int uSegments, int vSegments, float vPivot, LineCallback lineCallback)
    {
        if (lineCallback == null)
        {
            throw new System.ArgumentNullException();
        }

        var southPole = coords.pos - coords.yVec * vPivot;
        var northPole = southPole + coords.yVec;

        if (uSegments < 3)
        {
            uSegments = 3;
        }
        if (vSegments < 1)
        {
            vSegments = 1;
        }

        coords.pos = southPole;
        processUvSurface <GizmoCoords>(uSegments, vSegments, 0, uSegments, 0, vSegments,
                                       northPole, southPole, true, true,
                                       (u, v, data) => getConeVertex(u, v, data),
                                       lineCallback, coords);
    }
Esempio n. 2
0
        public void EnumerateSegments(LineCallback lc, ArcCallback ac, BezierCallback bc)
        {
            double penx = 0.0, peny = 0.0;

            foreach (GFXPathMoveTo mt in PathPoints)
            {
                if (mt is GFXPathBezierTo)
                {
                    var bez = mt as GFXPathBezierTo;
                    bc(penx, peny, bez.XC1, bez.YC1, bez.XC2, bez.YC2, bez.X, bez.Y);
                }
                else if (mt is GFXPathArcTo)
                {
                    var arc = mt as GFXPathArcTo;
                    ac(penx, peny, arc.X, arc.Y, arc.Bulge);
                }
                else if (mt is GFXPathLineTo)
                {
                    lc(penx, peny, mt.X, mt.Y);
                }

                penx = mt.X;
                peny = mt.Y;
            }
        }
Esempio n. 3
0
 /// <summary>
 /// 读取一行
 /// </summary>
 /// <typeparam name="TState"></typeparam>
 /// <param name="callback"></param>
 /// <param name="state"></param>
 public void ReadLine <TState>(LineCallback <TState> callback, TState state)
 {
     if (data != null && dataOffset < data.Size) // 存在可用
     {
         var packet = data.Buffer;
         for (; dataOffset < data.Size; dataOffset++)
         {
             if (bufferOffset == MaxLineSize) // 读取至超出最大行数据时,中止管道处理
             {
                 Trace.TraceError("Line buffer is overflow.");
                 pipeline.Interrupte();
                 return;
             }
             if (packet[dataOffset] == '\n' && bufferOffset > 0 && buffer[bufferOffset - 1] == '\r') // 解析至 \r\n
             {
                 dataOffset++;                                                                       // packet缓冲区指针向后移动指向 \n 的后续字符
                 var length = bufferOffset - 1;                                                      /*char \r*/
                 bufferOffset = 0;                                                                   // 重置缓冲
                 callback(pipeline, buffer, length, state);
                 return;
             }
             else
             {
                 buffer[bufferOffset++] = (char)packet[dataOffset];
             }
         }
     }
     GetPacketData(MaxLineSize, ProcessData <TState>, new object[] { callback, state });
 }
Esempio n. 4
0
 public override void WriteLine(string?value)
 {
     if (!SuppressOutput)
     {
         base.WriteLine(value);
     }
     LineCallback?.Invoke(value ?? String.Empty);
 }
Esempio n. 5
0
 public static void unitCircleLoop2D(int numSegments, LineCallback lineCallback)
 {
     if (lineCallback == null)
     {
         throw new System.ArgumentNullException();
     }
     unitCircleLoop2D(numSegments, (a, b, data) => {
         data(a, b);
     }, lineCallback);
 }
 public static extern Int32 lineInitializeEx(
     // Uygulamanın, TAPI kullanımına ait handle.
     ref IntPtr lphLineApp,
     // Client uygulamaya (veya DLL) ait instance handle (null değer alabilir).
     IntPtr hInstance,
     // Geri çağrılır fonksiyonumuzun adresi.
     LineCallback lpfnCallback,
     // Uygulama adı.
     string lpszFriendlyAppName,
     // Bulunan hatların sayısı.
     ref UInt32 lpdwNumDevs,
     // TAPI tarafından desteklenen versiyonu verir.
     ref UInt32 lpdwAPIVersion,
     // LINEINITIALIZEEXPARAMS yapısı.
     LINEINITIALIZEEXPARAMS lpLineInitializeExParams);
 public static extern Int32 lineOpen(
     // TAPI ait handle.
     IntPtr hLineApp,
     // Açılacak hattın tanıtıcı nosu.
     UInt32 dwDeviceID,
     // Açılan hatta ait handle
     ref IntPtr hLine,
     // TAPI versiyonu
     UInt32 dwAPIVersion,
     // dwExtVersion: Özel kullanım. Sıfır değeri verilebilir.
     UInt32 dwExtVersion,
     // Geri çağrılır fonksiyon nesnesi (TAPI tarafından yorumlanmaz)
     LineCallback dwCallbackInstance,
     // Uygulamanın çağrıyla ilgili ayrıcalıklarının parametresi
     Enums.LineCallPrivilege dwPrivileges,
     // Çağrı ortamıyla ilgili parametre.
     Enums.LineMediaMode dwMediaModes,
     // LINECALLPARAMS yapısı
     LINECALLPARAMS lpCallParams);
        //*********************************
        // TAPIClass sınıfı constructor   *
        //*********************************
        // TAPIClass sınıfı yapıcı metodu.
        // sAppName: Uygulama adı.
        public TAPIClass(string sAppName)
        {
            m_sAppName = sAppName;
            m_iTAPIVer = TAPISuppVer;
            // Uygulamaya ait handle, m_hInstance değişkenine atanıyor.
            m_hInstance = WindowsAPI.GetModuleHandle(null);
            // LineClass tipinde yeni bir koleksiyon yarat.
            m_ListLine = new List <LineClass>();
            // Şimdi LineCallback tipinden delegenin bir örneğini yaratalım.
            // Temsilcimiz LineCallbackEventHandler metoduna işaret etmektedir.
            // Burada geri çağrılır metodumuz kaydediliyor.
            m_CallBack = new LineCallback(LineCallbackEventHandler);

            try
            {
                // LINEINITIALIZEEXPARAMS yapı nesnesi tanımlıyoruz.
                LINEINITIALIZEEXPARAMS initExParams = new LINEINITIALIZEEXPARAMS();
                // Uygulamamız için saklı pencere olay bildirimi mekanizması seçiyoruz.
                initExParams.dwOptions = (int)Enums.LineInitializeExOptions.LINEINITIALIZEEXOPTION_USEHIDDENWINDOW;

                // Uygulamanın TAPI kaynaklarını kullanmasını başlatır ve
                // hazır telefon hatlarının sayısını bulur.
                Int32 lineErr = lineInitializeEx(ref m_hLineApp,
                                                 m_hInstance,
                                                 m_CallBack,
                                                 m_sAppName,
                                                 ref m_iNumLines,
                                                 ref m_iTAPIVer,
                                                 initExParams);

                // lineInitializeEx çağrısından dönen değeri kontrol et.
                if (lineErr == TAPI_SUCCESS)
                {
                    // Bir hat sayısı bulunup bulunmadığını kontrol et.
                    if (m_iNumLines > 0)
                    {
                        // Bulunan hatların bilgilerini doldur.
                        InitializeTAPILines();

                        // Telefonumuzun kullandığı ülke ve alan kodu bulundu mu?
                        if (!GetCurrentLocationInfo())
                        {
                            //MessageBox.Show("tapiGetLocationInfo fonksiyonu çağrısı başarısız.\n" +
                            //    "Ülke ve alan kodu alınamadı.");
                        }
                    }
                    else
                    {
                        //MessageBox.Show("Bağlı bir telefon hattı bulunamadı.");
                    }//if m_iNumLines
                }
                else
                {
                    //MessageBox.Show("lineInitializeEx fonksiyonu çağrısı başarısız.");
                }//if lineErr == 0
            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.Message);
            }
        }//constructor
Esempio n. 9
0
 /// <summary>
 /// Reads the listing data for ASCII encoding.
 /// </summary>
 /// <remarks>Skips non-ASCII chars found in the stream</remarks>
 /// <returns>array of listing lines</returns>
 private ArrayList ReadASCIIListingData(string dirname, LineCallback lineCallback, object state) 
 {
     log.Debug("Reading ASCII listing data");
     BufferedStream bstr = new BufferedStream(GetInputStream());
     MemoryStream mstr = new MemoryStream();
     int b;
     long size = 0;
     long monitorCount = 0;
     ArrayList lines = new ArrayList(10);
     try
     {
         while ((b = bstr.ReadByte()) != -1 && !cancelTransfer) 
         {
             // end of line?
             if (b == '\r' || b == '\n')
             {
                 if (mstr.Length > 0)
                 {
                     byte[] mstrbytes = mstr.ToArray();
                     string line = Encoding.ASCII.GetString(mstrbytes, 0, mstrbytes.Length);
                     lines.Add(line);
                     if (lineCallback != null)
                         lineCallback(line, state);
                     log.Debug("-->" + line);
                     mstr = new MemoryStream();
                 }
             }
             else if (b < 0x20 || b > 0x7f)  // strip out non-printable chars
                 continue;
             else
                 mstr.WriteByte((byte)b);
             size++;
             monitorCount++;
             if (transferNotifyListings && BytesTransferred != null && 
                 !cancelTransfer && monitorCount >= monitorInterval)
             {
                 BytesTransferred(this, new BytesTransferredEventArgs(dirname, size, 0));
                 monitorCount = 0;
             }       
         }
         if (lineCallback != null)
             lineCallback(null, state);
         if (transferNotifyListings && BytesTransferred != null)
             BytesTransferred(this, new BytesTransferredEventArgs(dirname, size, 0));
     }
     finally
     {
         CloseDataSocket(bstr); // need to close here
     }
     return lines;   
 }
Esempio n. 10
0
 /// <summary>
 /// Reads the listing data for a particular encoding
 /// </summary>
 /// <param name="enc">encoding</param>
 /// <returns>array of listing lines</returns>
 private ArrayList ReadListingData(string dirname, Encoding enc, LineCallback lineCallback, object state) 
 {
     StreamReader input = new StreamReader(GetInputStream(), enc);
             
     // read a line at a time
     ArrayList lines = new ArrayList(10);
     string line = null;
     long size = 0;
     long monitorCount = 0;
     try
     {
         while ((line = ReadLine(input)) != null && !cancelTransfer)
         {
             size += line.Length;
             monitorCount += line.Length;
             if (lineCallback != null)
                 lineCallback(line, state);
             lines.Add(line);
             if (transferNotifyListings && BytesTransferred != null && 
                 !cancelTransfer && monitorCount >= monitorInterval)
             {
                 BytesTransferred(this, new BytesTransferredEventArgs(dirname, size, 0));
                 monitorCount = 0;
             }
             log.Debug("-->" + line);
         }
         if (lineCallback != null)
             lineCallback(null, state);
         if (transferNotifyListings && BytesTransferred != null)
             BytesTransferred(this, new BytesTransferredEventArgs(dirname, size, 0));
         return lines;
     }
     finally
     {
         CloseDataSocket(input); // need to close here
     }
 }
Esempio n. 11
0
        private string[] Dir(string dirname, bool full, LineCallback lineCallback, object state)
        {
            CheckConnection(true);
            
            try
            {
                // set up data channel
                data = control.CreateDataSocket(connectMode);
                data.Timeout = timeout;
                
                // send the retrieve command
                string command = full ? "LIST ":"NLST ";
                if (showHiddenFiles)
                    command += "-a ";
                if (dirname != null)
                    command += dirname;
                
                // some FTP servers bomb out if NLST has whitespace appended
                command = command.Trim();
                FTPReply reply = control.SendCommand(command);
                
                // check the control response. wu-ftp returns 550 if the
                // directory is empty, so we handle 550 appropriately. Similarly
                // proFTPD returns 450. If dir is empty, some servers return 226 Transfer complete
                lastValidReply = control.ValidateReply(reply, "125", "226", "150", "450", "550");
                
                // an empty array of files for 450/550
                string[] result = new string[0];
                
                // a normal reply ... extract the file list
                string replyCode = lastValidReply.ReplyCode;
                if (!replyCode.Equals("450") && !replyCode.Equals("550") && !replyCode.Equals("226"))
                {
                    // get a character input stream to read data from
                    Encoding enc = controlEncoding == null ? Encoding.ASCII : controlEncoding;
                    ArrayList lines = null;
                    // reset the cancel flag
                    cancelTransfer = false;
                    try
                    {
                        if (enc.Equals(Encoding.ASCII))
                        {
                            lines = ReadASCIIListingData(dirname, lineCallback, state);
                        }
                        else
                        {
                            lines = ReadListingData(dirname, enc, lineCallback, state);
                        }

                        // check the control response
                        reply = control.ReadReply();
                        lastValidReply = control.ValidateReply(reply, "226", "250");
                    }
                    catch (SystemException ex)
                    {
                        ValidateTransferOnError();
                        log.Error("SystemException in directory listing", ex);
                        throw;
                    }
                    
                    // empty array is default
                    if (!(lines.Count == 0))
                    {
                        log.Debug("Found " + lines.Count + " listing lines");
                        result = new string[lines.Count];
                        lines.CopyTo(result);
                    }
                    else
                        log.Debug("No listing data found");
                }
                else { // throw exception if not a "no files" message or transfer complete
					string replyText = lastValidReply.ReplyText.ToUpper();
                    if (!dirEmptyStrings.Matches(replyText)
                        && !transferCompleteStrings.Matches(replyText))
                        throw new FTPException(reply);
                }
                return result;
            }
            finally
            {
                CloseDataSocket();
            }
        }
Esempio n. 12
0
    public static void processWireCube(GizmoCoords coords, bool makePivotAxes, Vector3 pivotOffset, LineCallback lineCallback)
    {
        if (lineCallback == null)
        {
            throw new System.ArgumentNullException();
        }

        var a  = coords.pos - coords.xVec * pivotOffset.x - coords.yVec * pivotOffset.y - coords.zVec * pivotOffset.z;
        var b  = a + coords.xVec;
        var c  = a + coords.yVec;
        var d  = b + coords.yVec;
        var a1 = a + coords.zVec;
        var b1 = b + coords.zVec;
        var c1 = c + coords.zVec;
        var d1 = d + coords.zVec;

        lineCallback(a, b);
        lineCallback(a, c);
        lineCallback(b, d);
        lineCallback(c, d);
        lineCallback(a1, b1);
        lineCallback(a1, c1);
        lineCallback(b1, d1);
        lineCallback(c1, d1);
        lineCallback(a, a1);
        lineCallback(b, b1);
        lineCallback(c, c1);
        lineCallback(d, d1);

        if (!makePivotAxes)
        {
            return;
        }

        var pivotX = coords.pos - pivotOffset.x * coords.xVec;
        var pivotY = coords.pos - pivotOffset.y * coords.yVec;
        var pivotZ = coords.pos - pivotOffset.z * coords.zVec;

        lineCallback(pivotX, pivotX + coords.xVec);
        lineCallback(pivotY, pivotY + coords.yVec);
        lineCallback(pivotZ, pivotZ + coords.zVec);
    }
Esempio n. 13
0
    public static void processUvSurface <Data>(int uSegments, int vSegments,
                                               int minUSegment, int maxUSegment, int minVSegment, int maxVSegment,
                                               Vector3 northPole, Vector3 southPole, bool capNorthPole, bool capSouthPole,
                                               UvSurfaceCallback <Data> surfaceCallback, LineCallback lineCallback, Data data)
    {
        if (lineCallback == null)
        {
            throw new System.ArgumentNullException();
        }
        if (lineCallback == null)
        {
            throw new System.ArgumentNullException();
        }

        if (uSegments <= 0)
        {
            throw new System.ArgumentException();
        }
        if (vSegments <= 0)
        {
            throw new System.ArgumentException();
        }

        float uStep = 1.0f / (float)uSegments;
        float vStep = 1.0f / (float)vSegments;

        float minV = vStep * (float)minVSegment;
        float maxV = vStep * (float)maxVSegment;

        for (int iU = minUSegment; iU < maxUSegment; iU++)
        {
            float curU  = uStep * (float)iU;
            float nextU = curU + uStep;

            {
                var south1 = surfaceCallback(curU, minV, data);
                var south2 = surfaceCallback(nextU, minV, data);
                lineCallback(south1, south2);

                if (capSouthPole)
                {
                    lineCallback(southPole, south1);
                }

                if (capNorthPole)
                {
                    var north1 = surfaceCallback(curU, maxV, data);
                    lineCallback(northPole, north1);
                }
            }

            for (int iV = minVSegment + 1; iV <= maxVSegment; iV++)
            {
                float curV  = vStep * (float)iV;
                float prevV = curV - vStep;
                var   a     = surfaceCallback(curU, curV, data);
                var   b     = surfaceCallback(nextU, curV, data);
                var   c     = surfaceCallback(curU, prevV, data);
                lineCallback(a, b);
                lineCallback(a, c);
            }
        }
    }
Esempio n. 14
0
    public static void processUvSphere(GizmoCoords coords, int uSegments, int vSegments, LineCallback lineCallback)
    {
        if (lineCallback == null)
        {
            throw new System.ArgumentNullException();
        }

        if (uSegments < 3)
        {
            uSegments = 3;
        }
        if (vSegments < 2)
        {
            vSegments = 12;
        }

        Vector3 northPole = getSphereVertex(0.0f, 1.0f, coords);
        Vector3 southPole = getSphereVertex(0.0f, 0.0f, coords);

        processUvSurface <GizmoCoords>(uSegments, vSegments, 0, uSegments, 1, vSegments - 1,
                                       northPole, southPole, true, true,
                                       (u, v, data) => getSphereVertex(u, v, data),
                                       lineCallback, coords);
    }
        //*********************************
        // TAPIClass sınıfı constructor   *
        //*********************************
        // TAPIClass sınıfı yapıcı metodu.
        // sAppName: Uygulama adı.
        public TAPIClass(string sAppName)
        {
            m_sAppName = sAppName;
            m_iTAPIVer = TAPISuppVer;
            // Uygulamaya ait handle, m_hInstance değişkenine atanıyor.
            m_hInstance = WindowsAPI.GetModuleHandle(null);
            // LineClass tipinde yeni bir koleksiyon yarat.
            m_ListLine = new List<LineClass>();
            // Şimdi LineCallback tipinden delegenin bir örneğini yaratalım.
            // Temsilcimiz LineCallbackEventHandler metoduna işaret etmektedir.
            // Burada geri çağrılır metodumuz kaydediliyor.
            m_CallBack = new LineCallback(LineCallbackEventHandler);

            try
            {
                // LINEINITIALIZEEXPARAMS yapı nesnesi tanımlıyoruz.
                LINEINITIALIZEEXPARAMS initExParams = new LINEINITIALIZEEXPARAMS();
                // Uygulamamız için saklı pencere olay bildirimi mekanizması seçiyoruz.
                initExParams.dwOptions = (int)Enums.LineInitializeExOptions.LINEINITIALIZEEXOPTION_USEHIDDENWINDOW;

                // Uygulamanın TAPI kaynaklarını kullanmasını başlatır ve
                // hazır telefon hatlarının sayısını bulur.
                Int32 lineErr = lineInitializeEx(ref m_hLineApp,
                    m_hInstance,
                    m_CallBack,
                    m_sAppName,
                    ref m_iNumLines,
                    ref m_iTAPIVer,
                    initExParams);

                // lineInitializeEx çağrısından dönen değeri kontrol et.
                if (lineErr == TAPI_SUCCESS)
                {
                    // Bir hat sayısı bulunup bulunmadığını kontrol et.
                    if (m_iNumLines > 0)
                    {
                        // Bulunan hatların bilgilerini doldur.
                        InitializeTAPILines();

                        // Telefonumuzun kullandığı ülke ve alan kodu bulundu mu?
                        if (!GetCurrentLocationInfo())
                        {
                            MessageBox.Show("tapiGetLocationInfo fonksiyonu çağrısı başarısız.\n" +
                                "Ülke ve alan kodu alınamadı.");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Bağlı bir telefon hattı bulunamadı.");
                    }//if m_iNumLines
                }
                else
                {
                    MessageBox.Show("lineInitializeEx fonksiyonu çağrısı başarısız.");
                }//if lineErr == 0
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }