Exemple #1
0
        private void Watcher_Created(object sender, FileSystemEventArgs e)
        {
            if (!File.Exists(jpgFile))
            {
                return;
            }
            else
            {
                Thread.Sleep(5000);
                using (var fs = new FileStream(jpgFile, FileMode.Open))
                {
                    // 封包体
                    byte[] bodyBytes = new byte[fs.Length];
                    fs.Read(bodyBytes, 0, bodyBytes.Length);
                    fs.Close();
                    // 封包头
                    PkgHeader header = new PkgHeader();
                    header.Id       = ++id;
                    header.BodySize = bodyBytes.Length;
                    byte[] headerBytes = server.StructureToByte <PkgHeader>(header);


                    // 组合最终发送的封包 (封包头+封包体)
                    byte[] sendBytes = Utils.GetSendBuffer(headerBytes, bodyBytes);
                    server.Send(ID, sendBytes, sendBytes.Length);
                }
            }
            count            = 0;
            watcher.Created -= Watcher_Created;
            watcher.Dispose();
            Utils.delDir(path + now);
        }
Exemple #2
0
        //Rvt导出为Ifc 事件
        private void Uiapp_Idling(object sender, Autodesk.Revit.UI.Events.IdlingEventArgs e)
        {
            if (count != 0)
            {
                return;
            }
            if (File.Exists(rvtName))
            {
                try
                {
                    Document doc = uiapp.Application.OpenDocumentFile(rvtName);
                    using (Transaction transaction = new Transaction(doc, "ifcexporter"))
                    {
                        transaction.Start();
                        IFCExportOptions opt = null;
                        doc.Export(path, ifcName, opt);
                        transaction.Commit();
                    }
                    doc.Close();
                    return;
                }
                catch (Exception ex)
                {
                    TaskDialog.Show("error", ex.ToString());
                }
                finally
                {
                    #region 发送生成的ifc
                    if (File.Exists(rvtName.Replace(".rvt", ".ifc")))
                    {
                        using (var fs = new FileStream(rvtName.Replace(".rvt", ".ifc"), FileMode.Open))
                        {
                            // 封包体
                            byte[] bodyBytes = new byte[fs.Length];
                            fs.Read(bodyBytes, 0, bodyBytes.Length);
                            fs.Close();
                            // 封包头
                            PkgHeader header = new PkgHeader();
                            header.Id       = ++id;
                            header.BodySize = bodyBytes.Length;
                            byte[] headerBytes = server.StructureToByte <PkgHeader>(header);


                            // 组合最终发送的封包 (封包头+封包体)
                            byte[] sendBytes = GetSendBuffer(headerBytes, bodyBytes);
                            server.Send(ID, sendBytes, sendBytes.Length);
                        }
                        delDir(path);//发送完成,删除文件
                    }
                    else
                    {
                        TaskDialog.Show("", rvtName.Replace(".rvt", ".ifc"));
                    }
                    #endregion
                }
                count++;
            }
        }