1005 lines
39 KiB
HTML
1005 lines
39 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="fa" dir="rtl">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<title>راهنمای گامبهگام توسعه XCodeFileContentExtractor | پروژه xAiApi</title>
|
||
<style>
|
||
@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;600;700;800&display=swap');
|
||
|
||
:root {
|
||
--primary: #1a365d;
|
||
--primary-light: #2c5282;
|
||
--accent: #c9a961;
|
||
--accent-dark: #a8893f;
|
||
--bg: #faf9f6;
|
||
--card-bg: #ffffff;
|
||
--text: #1a202c;
|
||
--text-muted: #4a5568;
|
||
--border: #e2e8f0;
|
||
--success: #38a169;
|
||
--danger: #e53e3e;
|
||
--warning: #dd6b20;
|
||
--shadow: 0 4px 6px rgba(0,0,0,0.05), 0 10px 30px rgba(26,54,93,0.08);
|
||
}
|
||
|
||
* { box-sizing: border-box; margin: 0; padding: 0; }
|
||
|
||
body {
|
||
font-family: 'Vazirmatn', Tahoma, sans-serif;
|
||
background: var(--bg);
|
||
color: var(--text);
|
||
line-height: 1.9;
|
||
font-size: 15px;
|
||
padding: 30px 15px;
|
||
}
|
||
|
||
.document-container {
|
||
max-width: 950px;
|
||
margin: 0 auto;
|
||
background: var(--card-bg);
|
||
box-shadow: var(--shadow);
|
||
border-radius: 12px;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.document-header {
|
||
background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
|
||
color: white;
|
||
padding: 50px 40px 40px;
|
||
position: relative;
|
||
border-bottom: 4px solid var(--accent);
|
||
}
|
||
|
||
.document-header::before {
|
||
content: '';
|
||
position: absolute;
|
||
top: 0; right: 0;
|
||
width: 200px; height: 200px;
|
||
background: radial-gradient(circle, rgba(201,169,97,0.15) 0%, transparent 70%);
|
||
border-radius: 50%;
|
||
transform: translate(50%, -50%);
|
||
}
|
||
|
||
.header-top {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
margin-bottom: 30px;
|
||
position: relative;
|
||
z-index: 1;
|
||
}
|
||
|
||
.company-badge {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 12px;
|
||
}
|
||
|
||
.company-logo {
|
||
width: 60px; height: 60px;
|
||
background: var(--accent);
|
||
border-radius: 12px;
|
||
box-shadow: 0 4px 12px rgba(0,0,0,0.2);
|
||
}
|
||
|
||
.doc-meta {
|
||
text-align: left;
|
||
font-size: 12px;
|
||
opacity: 0.9;
|
||
}
|
||
|
||
.doc-meta div { margin-bottom: 3px; }
|
||
|
||
.document-title {
|
||
text-align: center;
|
||
position: relative;
|
||
z-index: 1;
|
||
padding: 20px 0;
|
||
}
|
||
|
||
.document-title .label {
|
||
display: inline-block;
|
||
background: rgba(201,169,97,0.2);
|
||
color: var(--accent);
|
||
padding: 4px 16px;
|
||
border-radius: 20px;
|
||
font-size: 12px;
|
||
font-weight: 600;
|
||
margin-bottom: 15px;
|
||
border: 1px solid rgba(201,169,97,0.4);
|
||
}
|
||
|
||
.document-title h1 {
|
||
font-size: 28px;
|
||
font-weight: 800;
|
||
margin-bottom: 10px;
|
||
letter-spacing: -0.5px;
|
||
}
|
||
|
||
.document-title h2 {
|
||
font-size: 16px;
|
||
font-weight: 400;
|
||
opacity: 0.9;
|
||
}
|
||
|
||
.document-body {
|
||
padding: 40px;
|
||
}
|
||
|
||
.intro-text {
|
||
background: linear-gradient(to left, #f7fafc, #edf2f7);
|
||
border-right: 4px solid var(--accent);
|
||
padding: 20px 25px;
|
||
border-radius: 8px;
|
||
margin-bottom: 35px;
|
||
font-size: 14px;
|
||
color: var(--text-muted);
|
||
}
|
||
|
||
.section {
|
||
margin-bottom: 40px;
|
||
page-break-inside: avoid;
|
||
}
|
||
|
||
.section-header {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 15px;
|
||
padding-bottom: 12px;
|
||
border-bottom: 2px solid var(--border);
|
||
margin-bottom: 20px;
|
||
}
|
||
|
||
.section-number {
|
||
width: 50px; height: 50px;
|
||
background: linear-gradient(135deg, var(--primary), var(--primary-light));
|
||
color: white;
|
||
border-radius: 12px;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
font-weight: 800;
|
||
font-size: 20px;
|
||
flex-shrink: 0;
|
||
box-shadow: 0 4px 10px rgba(26,54,93,0.2);
|
||
}
|
||
|
||
.section-title { flex: 1; }
|
||
|
||
.section-title h3 {
|
||
font-size: 19px;
|
||
font-weight: 700;
|
||
color: var(--primary);
|
||
margin-bottom: 2px;
|
||
}
|
||
|
||
.section-title .subtitle {
|
||
font-size: 12px;
|
||
color: var(--text-muted);
|
||
}
|
||
|
||
.section-content {
|
||
padding-right: 10px;
|
||
}
|
||
|
||
.section-content p {
|
||
margin-bottom: 12px;
|
||
text-align: justify;
|
||
text-indent: 20px;
|
||
}
|
||
|
||
.section-content p.no-indent { text-indent: 0; }
|
||
|
||
.highlight-box {
|
||
background: linear-gradient(to left, #fffaf0, #fef5e7);
|
||
border: 1px solid #f6e05e;
|
||
border-right: 4px solid var(--accent);
|
||
padding: 18px 22px;
|
||
border-radius: 8px;
|
||
margin: 20px 0;
|
||
font-size: 14px;
|
||
}
|
||
|
||
.highlight-box strong {
|
||
color: var(--accent-dark);
|
||
}
|
||
|
||
.info-box {
|
||
background: linear-gradient(to left, #ebf8ff, #e6f6ff);
|
||
border: 1px solid #90cdf4;
|
||
border-right: 4px solid var(--primary-light);
|
||
padding: 18px 22px;
|
||
border-radius: 8px;
|
||
margin: 20px 0;
|
||
font-size: 14px;
|
||
}
|
||
|
||
.success-box {
|
||
background: linear-gradient(to left, #f0fff4, #e6fffa);
|
||
border: 1px solid #9ae6b4;
|
||
border-right: 4px solid var(--success);
|
||
padding: 18px 22px;
|
||
border-radius: 8px;
|
||
margin: 20px 0;
|
||
font-size: 14px;
|
||
}
|
||
|
||
.warning-box {
|
||
background: linear-gradient(to left, #fffaf0, #fef5e7);
|
||
border: 1px solid #fbd38d;
|
||
border-right: 4px solid var(--warning);
|
||
padding: 18px 22px;
|
||
border-radius: 8px;
|
||
margin: 20px 0;
|
||
font-size: 14px;
|
||
}
|
||
|
||
.styled-table {
|
||
width: 100%;
|
||
border-collapse: collapse;
|
||
margin: 20px 0;
|
||
background: white;
|
||
border-radius: 8px;
|
||
overflow: hidden;
|
||
box-shadow: 0 2px 8px rgba(0,0,0,0.05);
|
||
}
|
||
|
||
.styled-table thead {
|
||
background: linear-gradient(135deg, var(--primary), var(--primary-light));
|
||
color: white;
|
||
}
|
||
|
||
.styled-table th {
|
||
padding: 14px 16px;
|
||
text-align: right;
|
||
font-weight: 600;
|
||
font-size: 13px;
|
||
}
|
||
|
||
.styled-table td {
|
||
padding: 13px 16px;
|
||
border-bottom: 1px solid var(--border);
|
||
font-size: 13px;
|
||
}
|
||
|
||
.styled-table tbody tr:last-child td { border-bottom: none; }
|
||
.styled-table tbody tr:nth-child(even) { background: #f8fafc; }
|
||
|
||
.styled-table .highlight-row {
|
||
background: #fffaf0 !important;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.comparison-grid {
|
||
display: grid;
|
||
grid-template-columns: 1fr 1fr;
|
||
gap: 20px;
|
||
margin: 25px 0;
|
||
}
|
||
|
||
.comparison-card {
|
||
background: #f8fafc;
|
||
border: 2px solid var(--border);
|
||
border-radius: 10px;
|
||
padding: 20px;
|
||
position: relative;
|
||
}
|
||
|
||
.comparison-card.recommended {
|
||
border-color: var(--success);
|
||
background: linear-gradient(to left, #f0fff4, #e6fffa);
|
||
}
|
||
|
||
.comparison-card .card-badge {
|
||
position: absolute;
|
||
top: -10px;
|
||
right: 20px;
|
||
background: var(--success);
|
||
color: white;
|
||
padding: 3px 12px;
|
||
border-radius: 15px;
|
||
font-size: 11px;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.comparison-card h4 {
|
||
font-size: 16px;
|
||
font-weight: 700;
|
||
color: var(--primary);
|
||
margin-bottom: 15px;
|
||
padding-bottom: 10px;
|
||
border-bottom: 2px solid var(--border);
|
||
}
|
||
|
||
.comparison-card.recommended h4 {
|
||
border-bottom-color: var(--success);
|
||
}
|
||
|
||
.comparison-card ul {
|
||
list-style: none;
|
||
padding: 0;
|
||
}
|
||
|
||
.comparison-card ul li {
|
||
padding: 8px 0;
|
||
border-bottom: 1px solid var(--border);
|
||
font-size: 13px;
|
||
display: flex;
|
||
justify-content: space-between;
|
||
}
|
||
|
||
.comparison-card ul li:last-child { border-bottom: none; }
|
||
|
||
.comparison-card ul li .value {
|
||
font-weight: 600;
|
||
color: var(--primary);
|
||
}
|
||
|
||
.quote-box {
|
||
background: linear-gradient(135deg, #f7fafc, #edf2f7);
|
||
border-right: 4px solid var(--accent);
|
||
padding: 20px 25px;
|
||
border-radius: 8px;
|
||
margin: 20px 0;
|
||
position: relative;
|
||
}
|
||
|
||
.quote-box::before {
|
||
content: '"';
|
||
position: absolute;
|
||
top: -10px;
|
||
right: 15px;
|
||
font-size: 60px;
|
||
color: var(--accent);
|
||
opacity: 0.3;
|
||
font-family: Georgia, serif;
|
||
}
|
||
|
||
.quote-box p {
|
||
font-style: italic;
|
||
color: var(--text-muted);
|
||
margin-bottom: 10px;
|
||
text-indent: 0 !important;
|
||
}
|
||
|
||
.quote-box .source {
|
||
font-size: 12px;
|
||
color: var(--text-muted);
|
||
text-align: left;
|
||
font-style: normal;
|
||
}
|
||
|
||
.stats-grid {
|
||
display: grid;
|
||
grid-template-columns: repeat(3, 1fr);
|
||
gap: 15px;
|
||
margin: 25px 0;
|
||
}
|
||
|
||
.stat-card {
|
||
background: linear-gradient(135deg, var(--primary), var(--primary-light));
|
||
color: white;
|
||
padding: 20px;
|
||
border-radius: 10px;
|
||
text-align: center;
|
||
box-shadow: 0 4px 12px rgba(26,54,93,0.2);
|
||
}
|
||
|
||
.stat-card .stat-value {
|
||
font-size: 24px;
|
||
font-weight: 800;
|
||
margin-bottom: 5px;
|
||
color: var(--accent);
|
||
line-height: 1.3;
|
||
}
|
||
|
||
.stat-card .stat-label {
|
||
font-size: 12px;
|
||
opacity: 0.9;
|
||
}
|
||
|
||
.timeline {
|
||
position: relative;
|
||
padding: 20px 0;
|
||
margin: 25px 0;
|
||
}
|
||
|
||
.timeline::before {
|
||
content: '';
|
||
position: absolute;
|
||
right: 50%;
|
||
top: 0;
|
||
bottom: 0;
|
||
width: 3px;
|
||
background: var(--border);
|
||
transform: translateX(50%);
|
||
}
|
||
|
||
.timeline-item {
|
||
display: flex;
|
||
margin-bottom: 20px;
|
||
position: relative;
|
||
}
|
||
|
||
.timeline-item:nth-child(odd) {
|
||
flex-direction: row-reverse;
|
||
}
|
||
|
||
.timeline-content {
|
||
width: 45%;
|
||
background: #f8fafc;
|
||
border: 1px solid var(--border);
|
||
border-radius: 8px;
|
||
padding: 15px;
|
||
position: relative;
|
||
}
|
||
|
||
.timeline-item:nth-child(odd) .timeline-content {
|
||
margin-left: 5%;
|
||
}
|
||
|
||
.timeline-item:nth-child(even) .timeline-content {
|
||
margin-right: 5%;
|
||
}
|
||
|
||
.timeline-dot {
|
||
position: absolute;
|
||
right: 50%;
|
||
top: 20px;
|
||
width: 16px;
|
||
height: 16px;
|
||
background: var(--accent);
|
||
border: 3px solid white;
|
||
border-radius: 50%;
|
||
transform: translateX(50%);
|
||
box-shadow: 0 2px 6px rgba(0,0,0,0.2);
|
||
z-index: 1;
|
||
}
|
||
|
||
.timeline-content h5 {
|
||
font-size: 14px;
|
||
font-weight: 700;
|
||
color: var(--primary);
|
||
margin-bottom: 8px;
|
||
}
|
||
|
||
.timeline-content p {
|
||
font-size: 12px;
|
||
color: var(--text-muted);
|
||
text-indent: 0 !important;
|
||
margin-bottom: 0 !important;
|
||
}
|
||
|
||
.reference-list {
|
||
list-style: none;
|
||
padding: 0;
|
||
margin: 20px 0;
|
||
}
|
||
|
||
.reference-list li {
|
||
background: #f8fafc;
|
||
border-right: 3px solid var(--primary-light);
|
||
padding: 15px 20px;
|
||
margin-bottom: 10px;
|
||
border-radius: 6px;
|
||
font-size: 13px;
|
||
}
|
||
|
||
.reference-list li strong {
|
||
color: var(--primary);
|
||
display: block;
|
||
margin-bottom: 5px;
|
||
}
|
||
|
||
.reference-list li .ref-source {
|
||
font-size: 11px;
|
||
color: var(--text-muted);
|
||
margin-top: 5px;
|
||
}
|
||
|
||
.conclusion-box {
|
||
background: linear-gradient(135deg, var(--primary), var(--primary-light));
|
||
color: white;
|
||
padding: 30px;
|
||
border-radius: 12px;
|
||
margin: 30px 0;
|
||
text-align: center;
|
||
box-shadow: 0 8px 20px rgba(26,54,93,0.3);
|
||
}
|
||
|
||
.conclusion-box h3 {
|
||
font-size: 22px;
|
||
font-weight: 800;
|
||
margin-bottom: 15px;
|
||
color: var(--accent);
|
||
}
|
||
|
||
.conclusion-box p {
|
||
font-size: 14px;
|
||
line-height: 1.8;
|
||
text-indent: 0 !important;
|
||
margin-bottom: 15px;
|
||
}
|
||
|
||
.conclusion-box .highlight {
|
||
background: rgba(201,169,97,0.2);
|
||
padding: 15px 20px;
|
||
border-radius: 8px;
|
||
margin-top: 20px;
|
||
border: 1px solid rgba(201,169,97,0.4);
|
||
}
|
||
|
||
.document-footer {
|
||
background: var(--primary);
|
||
color: white;
|
||
padding: 25px 40px;
|
||
text-align: center;
|
||
font-size: 12px;
|
||
margin-top: 40px;
|
||
}
|
||
|
||
.document-footer .footer-brand {
|
||
font-weight: 700;
|
||
color: var(--accent);
|
||
margin-bottom: 5px;
|
||
font-size: 14px;
|
||
}
|
||
|
||
.footer-divider {
|
||
width: 60px;
|
||
height: 2px;
|
||
background: var(--accent);
|
||
margin: 10px auto;
|
||
}
|
||
|
||
.page-info {
|
||
text-align: center;
|
||
padding: 15px;
|
||
font-size: 11px;
|
||
color: var(--text-muted);
|
||
border-top: 1px solid var(--border);
|
||
margin-top: 30px;
|
||
}
|
||
|
||
.code-block {
|
||
background: #1a202c;
|
||
color: #e2e8f0;
|
||
padding: 18px 22px;
|
||
border-radius: 8px;
|
||
margin: 15px 0;
|
||
font-family: 'Consolas', 'Courier New', monospace;
|
||
font-size: 12px;
|
||
line-height: 1.7;
|
||
direction: ltr;
|
||
text-align: left;
|
||
overflow-x: auto;
|
||
border-left: 4px solid var(--accent);
|
||
white-space: pre;
|
||
}
|
||
|
||
.code-block .kw { color: #f6ad55; }
|
||
.code-block .type { color: #63b3ed; }
|
||
.code-block .str { color: #9ae6b4; }
|
||
.code-block .cmt { color: #718096; font-style: italic; }
|
||
|
||
@media print {
|
||
body { background: white; padding: 0; }
|
||
.document-container { box-shadow: none; border-radius: 0; }
|
||
.section { page-break-inside: avoid; }
|
||
}
|
||
|
||
@media (max-width: 768px) {
|
||
.document-body { padding: 25px 20px; }
|
||
.document-header { padding: 30px 20px; }
|
||
.comparison-grid { grid-template-columns: 1fr; }
|
||
.stats-grid { grid-template-columns: 1fr; }
|
||
.header-top { flex-direction: column; gap: 15px; }
|
||
.doc-meta { text-align: center; }
|
||
}
|
||
</style>
|
||
</head>
|
||
<body>
|
||
|
||
<div class="document-container">
|
||
|
||
<header class="document-header">
|
||
<div class="header-top">
|
||
<div class="company-badge">
|
||
<div class="company-logo"></div>
|
||
</div>
|
||
<div class="doc-meta">
|
||
<div>شماره مستند: TECH-1405-015</div>
|
||
<div>نسخه: ۱.۰</div>
|
||
<div>تاریخ تهیه: ۲۹ مهر ۱۴۰۵</div>
|
||
<div>طبقهبندی: محرمانه</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="document-title">
|
||
<span class="label">IMPLEMENTATION GUIDE</span>
|
||
<h1>راهنمای گامبهگام توسعه XCodeFileContentExtractor</h1>
|
||
<h2>پیادهسازی Extractor مخصوص فایلهای کد منبع در زیرسیستم استخراج محتوای xAiApi</h2>
|
||
</div>
|
||
</header>
|
||
|
||
<div class="document-body">
|
||
|
||
<div class="intro-text">
|
||
<strong>به کارفرمای محترم،</strong><br>
|
||
این مستند حاصل طراحی و پیادهسازی گامبهگام <code style="font-family: monospace; background: #edf2f7; padding: 2px 6px; border-radius: 4px;">XCodeFileContentExtractor</code> در زیرسیستم <code style="font-family: monospace; background: #edf2f7; padding: 2px 6px; border-radius: 4px;">xAiApi/Providers/Extractors</code> است. هدف از تهیه این مستند، ارائه نقشه اجرایی دقیق برای افزودن Extractor مخصوص فایلهای کد منبع (C#، Python، JavaScript، TypeScript، Java و ...) به سامانه هوش مصنوعی میباشد، به گونهای که با ساختار موجود همراستا بوده و بدون ایجاد ناسازگاری، قابل استقرار در محیط عملیاتی باشد.
|
||
</div>
|
||
|
||
<div class="section">
|
||
<div class="section-header">
|
||
<div class="section-number">۱</div>
|
||
<div class="section-title">
|
||
<h3>خلاصه اجرایی</h3>
|
||
<div class="subtitle">Executive Summary</div>
|
||
</div>
|
||
</div>
|
||
<div class="section-content">
|
||
<p>توسعه <code style="font-family: monospace; background: #edf2f7; padding: 2px 6px; border-radius: 4px;">XCodeFileContentExtractor</code> در هفت گام مشخص و قابل پیگیری انجام میشود. هر گام خروجی مشخصی دارد و تا قبل از ورود به گام بعدی، صحت آن قابل اعتبارسنجی است. این رویکرد گامبهگام، ریسک ورود کد ناسازگار به سامانه را به حداقل میرساند.</p>
|
||
|
||
<div class="stats-grid">
|
||
<div class="stat-card">
|
||
<div class="stat-value">۷<br>گام</div>
|
||
<div class="stat-label">مراحل اجرایی توسعه Extractor</div>
|
||
</div>
|
||
<div class="stat-card">
|
||
<div class="stat-value">۲<br>متد اصلی</div>
|
||
<div class="stat-label">پیادهسازی در قرارداد پایه</div>
|
||
</div>
|
||
<div class="stat-card">
|
||
<div class="stat-value">۱<br>ثبت در DI</div>
|
||
<div class="stat-label">ثبت بهعنوان Singleton در Startup</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="highlight-box">
|
||
<strong>نتیجه کلیدی:</strong> با رعایت این هفت گام، Extractor جدید با الگوی موجود (سایر Extractor ها) کاملاً همراستا بوده و بدون نیاز به تغییر در Composite Extractor، در زنجیره استخراج محتوا قابل استفاده خواهد بود.
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="section">
|
||
<div class="section-header">
|
||
<div class="section-number">۲</div>
|
||
<div class="section-title">
|
||
<h3>درک قرارداد پایه (IXFileContentExtractorBase)</h3>
|
||
<div class="subtitle">Understanding the Base Contract</div>
|
||
</div>
|
||
</div>
|
||
<div class="section-content">
|
||
<p>پیش از هر اقدامی، لازم است قراردادی که هر Extractor باید پیادهسازی کند بهطور کامل درک شود. در فایل <code style="font-family: monospace; background: #edf2f7; padding: 2px 6px; border-radius: 4px;">xAiApi/Interfaces/Extractors/IXFileContentExtractor.cs</code> اینترفیس زیر تعریف شده است:</p>
|
||
|
||
<div class="code-block"><span class="kw">public interface</span> <span class="type">IXFileContentExtractorBase</span>
|
||
{
|
||
<span class="type">bool</span> CanExtract(<span class="type">string</span> mimeType);
|
||
|
||
<span class="type">Task<string></span> ExtractAsync(
|
||
<span class="type">Stream</span> fileStream,
|
||
<span class="type">string</span> mimeType,
|
||
<span class="type">CancellationToken</span> cancellationToken = <span class="kw">default</span>
|
||
);
|
||
|
||
<span class="type">Task<XFileExtractionResult></span> ExtractRichAsync(
|
||
<span class="type">Stream</span> fileStream,
|
||
<span class="type">string</span> fileName,
|
||
<span class="type">string</span> mimeType,
|
||
<span class="type">CancellationToken</span> cancellationToken = <span class="kw">default</span>
|
||
);
|
||
}</div>
|
||
|
||
<p>سه متد فوق، حداقل الزامات هر Extractor هستند. متد <code style="font-family: monospace;">CanExtract</code> تعیین میکند که آیا Extractor از MIME مشخصی پشتیبانی میکند یا خیر؛ متد <code style="font-family: monospace;">ExtractAsync</code> نسخه ساده بازگشت متن است؛ و متد <code style="font-family: monospace;">ExtractRichAsync</code> نسخه غنیتر است که امکان بازگشت تصاویر، رونویسی صوت و اطلاعات تکمیلی را فراهم میکند.</p>
|
||
|
||
<div class="info-box">
|
||
<strong>💡 نکته مهم:</strong> در Extractor مخصوص فایلهای کد، نیازی به بازگشت تصویر یا صوت نیست؛ بنابراین هر دو متد <code style="font-family: monospace;">ExtractAsync</code> و <code style="font-family: monospace;">ExtractRichAsync</code> صرفاً متن کد را بازمیگردانند و <code style="font-family: monospace;">ExtractRichAsync</code> میتواند بهسادگی متد <code style="font-family: monospace;">ExtractAsync</code> را فراخوانی کند.
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="section">
|
||
<div class="section-header">
|
||
<div class="section-number">۳</div>
|
||
<div class="section-title">
|
||
<h3>گام اول و دوم: تعریف اینترفیس و اسکلت کلاس</h3>
|
||
<div class="subtitle">Step 1 & 2 — Interface and Class Skeleton</div>
|
||
</div>
|
||
</div>
|
||
<div class="section-content">
|
||
<p>در گام نخست، یک اینترفیس اختصاصی برای Extractor کد تعریف میشود. این کار با الگوی موجود در سایر Extractor ها (مانند <code style="font-family: monospace;">IXAudioFileContentExtractor</code> و <code style="font-family: monospace;">IXPowerPointFileContentExtractor</code>) کاملاً همراستا است. فایل اینترفیس در مسیر <code style="font-family: monospace; background: #edf2f7; padding: 2px 6px; border-radius: 4px;">xAiApi/Interfaces/Extractors/IXCodeFileContentExtractor.cs</code> قرار میگیرد:</p>
|
||
|
||
<div class="code-block"><span class="kw">namespace</span> xAiApi.Interfaces.Extractors
|
||
{
|
||
<span class="cmt">/// <summary></span>
|
||
<span class="cmt">/// Extractor for source code files (cs, py, js, ts, java, ...)</span>
|
||
<span class="cmt">/// </summary></span>
|
||
<span class="kw">public interface</span> <span class="type">IXCodeFileContentExtractor</span> : <span class="type">IXFileContentExtractorBase</span>
|
||
{ }
|
||
}</div>
|
||
|
||
<p>در گام دوم، اسکلت کلاس پیادهسازی در مسیر <code style="font-family: monospace; background: #edf2f7; padding: 2px 6px; border-radius: 4px;">xAiApi/Providers/Extractors/XCodeFileContentExtractor.cs</code> ایجاد میشود. این اسکلت شامل تعریف آرایه MIME Types پشتیبانیشده و امضای سه متد قرارداد پایه است:</p>
|
||
|
||
<div class="code-block"><span class="kw">using</span> System;
|
||
<span class="kw">using</span> System.IO;
|
||
<span class="kw">using</span> System.Linq;
|
||
<span class="kw">using</span> System.Text;
|
||
<span class="kw">using</span> System.Threading;
|
||
<span class="kw">using</span> xAiModels.Models;
|
||
<span class="kw">using</span> System.Threading.Tasks;
|
||
<span class="kw">using</span> xAiApi.Interfaces.Extractors;
|
||
|
||
<span class="kw">namespace</span> xAiApi.Providers.Extractors
|
||
{
|
||
<span class="kw">public class</span> <span class="type">XCodeFileContentExtractor</span> : <span class="type">IXCodeFileContentExtractor</span>
|
||
{
|
||
<span class="kw">private static readonly string</span>[] SupportedMimeTypes = [ ];
|
||
|
||
<span class="kw">public bool</span> CanExtract(<span class="type">string</span> mimeType) => <span class="kw">false</span>;
|
||
<span class="kw">public</span> <span class="type">Task<string></span> ExtractAsync(...) => <span class="kw">null</span>;
|
||
<span class="kw">public</span> <span class="type">Task<XFileExtractionResult></span> ExtractRichAsync(...) => <span class="kw">null</span>;
|
||
}
|
||
}</div>
|
||
|
||
<div class="success-box">
|
||
<strong>✓ خروجی این گام:</strong> دو فایل جدید ایجاد شده که کامپایل میشوند اما هنوز منطقی ندارند. این وضعیت پایهای، نقطه شروع امنی برای گامهای بعدی است.
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="section">
|
||
<div class="section-header">
|
||
<div class="section-number">۴</div>
|
||
<div class="section-title">
|
||
<h3>گام سوم و چهارم: تعریف MIME Types و پیادهسازی CanExtract</h3>
|
||
<div class="subtitle">Step 3 & 4 — MIME Types and CanExtract</div>
|
||
</div>
|
||
</div>
|
||
<div class="section-content">
|
||
<p>در گام سوم، فهرست MIME Types پشتیبانیشده تعریف میشود. فایلهای کد منبع معمولاً با MIME Type مشخصی ارسال نمیشوند و بسیاری از سامانهها آنها را با <code style="font-family: monospace;">text/plain</code> یا <code style="font-family: monospace;">application/octet-stream</code> میفرستند. از این رو، این Extractor باید مجموعهای از MIME Types صریح و همچنین یک شناسه امن برای حالتهای عمومی داشته باشد:</p>
|
||
|
||
<table class="styled-table">
|
||
<thead>
|
||
<tr>
|
||
<th>پسوند فایل</th>
|
||
<th>MIME Type متداول</th>
|
||
<th>وضعیت پوشش</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr><td>.cs</td><td>text/x-csharp</td><td style="color: var(--success); font-weight: 600;">پوشش داده میشود</td></tr>
|
||
<tr><td>.py</td><td>text/x-python</td><td style="color: var(--success); font-weight: 600;">پوشش داده میشود</td></tr>
|
||
<tr><td>.js</td><td>application/javascript</td><td style="color: var(--success); font-weight: 600;">پوشش داده میشود</td></tr>
|
||
<tr><td>.ts</td><td>application/typescript</td><td style="color: var(--success); font-weight: 600;">پوشش داده میشود</td></tr>
|
||
<tr><td>.java</td><td>text/x-java</td><td style="color: var(--success); font-weight: 600;">پوشش داده میشود</td></tr>
|
||
<tr><td>.go</td><td>text/x-go</td><td style="color: var(--success); font-weight: 600;">پوشش داده میشود</td></tr>
|
||
<tr><td>.rs</td><td>text/x-rust</td><td style="color: var(--success); font-weight: 600;">پوشش داده میشود</td></tr>
|
||
<tr class="highlight-row"><td><strong>.php / .rb / .c / .cpp / .sql / .yaml</strong></td><td><strong>متنوع</strong></td><td style="color: var(--success); font-weight: 700;">پوشش داده میشود</td></tr>
|
||
</tbody>
|
||
</table>
|
||
|
||
<p>آرایه MIME Types در کلاس بهصورت زیر تعریف میشود:</p>
|
||
|
||
<div class="code-block"><span class="kw">private static readonly string</span>[] SupportedMimeTypes =
|
||
[
|
||
<span class="str">"text/x-csharp"</span>, <span class="str">"application/x-csharp"</span>,
|
||
<span class="str">"text/x-python"</span>, <span class="str">"application/x-python"</span>,
|
||
<span class="str">"application/javascript"</span>, <span class="str">"text/javascript"</span>,
|
||
<span class="str">"application/typescript"</span>, <span class="str">"text/typescript"</span>,
|
||
<span class="str">"text/x-java"</span>, <span class="str">"text/x-java-source"</span>,
|
||
<span class="str">"text/x-go"</span>, <span class="str">"text/x-rust"</span>,
|
||
<span class="str">"text/x-ruby"</span>, <span class="str">"text/x-php"</span>,
|
||
<span class="str">"text/x-c"</span>, <span class="str">"text/x-c++"</span>,
|
||
<span class="str">"text/x-sql"</span>, <span class="str">"application/x-yaml"</span>,
|
||
<span class="str">"text/yaml"</span>
|
||
];</div>
|
||
|
||
<p>در گام چهارم، متد <code style="font-family: monospace;">CanExtract</code> پیادهسازی میشود. این متد بررسی میکند که آیا MIME ورودی (پس از نرمالسازی به حروف کوچک) در فهرست پشتیبانیشده قرار دارد یا خیر:</p>
|
||
|
||
<div class="code-block"><span class="kw">public bool</span> CanExtract(<span class="type">string</span> mimeType)
|
||
{
|
||
<span class="kw">return</span> SupportedMimeTypes.Contains(
|
||
mimeType?.ToLowerInvariant() ?? <span class="type">string</span>.Empty
|
||
);
|
||
}</div>
|
||
|
||
<div class="warning-box">
|
||
<strong>⚠ نکته اجرایی:</strong> در صورت نیاز به تشخیص دقیقتر بر اساس پسوند فایل (بهجای اتکای صرف به MIME Type)، میتوان در گامهای بعدی از پارامتر <code style="font-family: monospace;">fileName</code> در <code style="font-family: monospace;">ExtractRichAsync</code> استفاده کرد. اما این تغییر نباید در <code style="font-family: monospace;">CanExtract</code> اعمال شود چون این متد تنها MIME Type را دریافت میکند.
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="section">
|
||
<div class="section-header">
|
||
<div class="section-number">۵</div>
|
||
<div class="section-title">
|
||
<h3>گام پنجم و ششم: پیادهسازی ExtractAsync و ExtractRichAsync</h3>
|
||
<div class="subtitle">Step 5 & 6 — ExtractAsync and ExtractRichAsync</div>
|
||
</div>
|
||
</div>
|
||
<div class="section-content">
|
||
<p>در گام پنجم، منطق اصلی استخراج متن از فایل کد پیادهسازی میشود. از آنجا که فایلهای کد منبع، فایلهای متنی هستند، استخراج صرفاً خواندن کامل جریان با <code style="font-family: monospace;">StreamReader</code> است. برخلاف <code style="font-family: monospace;">XPlainTextFileContentExtractor</code>، این Extractor باید محتوای کد را با حفظ ساختار (خطوط، تودرتویی و کاراکترهای خاص) بازگرداند:</p>
|
||
|
||
<div class="code-block"><span class="kw">public async</span> <span class="type">Task<string></span> ExtractAsync(
|
||
<span class="type">Stream</span> fileStream,
|
||
<span class="type">string</span> mimeType,
|
||
<span class="type">CancellationToken</span> cancellationToken = <span class="kw">default</span>
|
||
)
|
||
{
|
||
<span class="cmt">// Read entire source code as UTF-8 (with BOM detection) ...</span>
|
||
<span class="kw">using var</span> reader = <span class="kw">new</span> <span class="type">StreamReader</span>(
|
||
fileStream,
|
||
<span class="type">Encoding</span>.UTF8,
|
||
detectEncodingFromByteOrderMarks: <span class="kw">true</span>,
|
||
leaveOpen: <span class="kw">false</span>
|
||
);
|
||
|
||
<span class="kw">var</span> content = <span class="kw">await</span> reader.ReadToEndAsync();
|
||
|
||
<span class="cmt">// Normalize line endings for consistent downstream processing ...</span>
|
||
content = content?
|
||
.Replace(<span class="str">"\r\n"</span>, <span class="str">"\n"</span>)
|
||
.Replace(<span class="str">"\r"</span>, <span class="str">"\n"</span>);
|
||
|
||
<span class="kw">return</span> content ?? <span class="type">string</span>.Empty;
|
||
}</div>
|
||
|
||
<p>در گام ششم، متد <code style="font-family: monospace;">ExtractRichAsync</code> پیادهسازی میشود. این متد صرفاً متد <code style="font-family: monospace;">ExtractAsync</code> را فراخوانی کرده و نتیجه را در قالب <code style="font-family: monospace;">XFileExtractionResult</code> بازمیگرداند. از آنجا که فایل کد تصویر یا صوت ندارد، صرفاً فیلد <code style="font-family: monospace;">Text</code> پر میشود:</p>
|
||
|
||
<div class="code-block"><span class="kw">public async</span> <span class="type">Task<XFileExtractionResult></span> ExtractRichAsync(
|
||
<span class="type">Stream</span> fileStream,
|
||
<span class="type">string</span> fileName,
|
||
<span class="type">string</span> mimeType,
|
||
<span class="type">CancellationToken</span> cancellationToken = <span class="kw">default</span>
|
||
)
|
||
{
|
||
<span class="kw">var</span> content = <span class="kw">await</span> ExtractAsync(
|
||
mimeType: mimeType,
|
||
fileStream: fileStream,
|
||
cancellationToken: cancellationToken
|
||
);
|
||
|
||
<span class="kw">return new</span> <span class="type">XFileExtractionResult</span>
|
||
{
|
||
Text = content,
|
||
FileName = fileName,
|
||
MimeType = mimeType
|
||
};
|
||
}</div>
|
||
|
||
<div class="success-box">
|
||
<strong>✓ خروجی این گام:</strong> کلاس <code style="font-family: monospace;">XCodeFileContentExtractor</code> اکنون بهطور کامل سه متد قرارداد پایه را پیادهسازی کرده و از نظر منطقی آماده استفاده است. تنها گام باقیمانده، ثبت در DI است.
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="section">
|
||
<div class="section-header">
|
||
<div class="section-number">۶</div>
|
||
<div class="section-title">
|
||
<h3>گام هفتم: ثبت Extractor در Dependency Injection</h3>
|
||
<div class="subtitle">Step 7 — Register in DI Container</div>
|
||
</div>
|
||
</div>
|
||
<div class="section-content">
|
||
<p>در گام نهایی، Extractor جدید باید در متد <code style="font-family: monospace;">AddXAiFileContentExtractors</code> واقع در فایل <code style="font-family: monospace; background: #edf2f7; padding: 2px 6px; border-radius: 4px;">xAiApi/DI/XDIHelperExtension.cs</code> ثبت شود. ثبت بهصورت <code style="font-family: monospace;">Singleton</code> و با اینترفیس <code style="font-family: monospace;">IXFileContentExtractorBase</code> انجام میشود تا Composite Extractor بتواند آن را در فهرست خود ببیند:</p>
|
||
|
||
<div class="code-block"><span class="kw">public static void</span> AddXAiFileContentExtractors(
|
||
<span class="kw">this</span> <span class="type">IServiceCollection</span> source
|
||
)
|
||
{
|
||
<span class="cmt">// Register existing extractors ...</span>
|
||
source.AddSingleton<<span class="type">IXFileContentExtractorBase</span>, <span class="type">XPdfFileContentExtractor</span>>();
|
||
source.AddSingleton<<span class="type">IXFileContentExtractorBase</span>, <span class="type">XDocxFileContentExtractor</span>>();
|
||
source.AddSingleton<<span class="type">IXFileContentExtractorBase</span>, <span class="type">XImageFileContentExtractor</span>>();
|
||
source.AddSingleton<<span class="type">IXFileContentExtractorBase</span>, <span class="type">XAudioFileContentExtractor</span>>();
|
||
source.AddSingleton<<span class="type">IXFileContentExtractorBase</span>, <span class="type">XExcelFileContentExtractor</span>>();
|
||
source.AddSingleton<<span class="type">IXFileContentExtractorBase</span>, <span class="type">XVisionFileContentExtractor</span>>();
|
||
source.AddSingleton<<span class="type">IXFileContentExtractorBase</span>, <span class="type">XPlainTextFileContentExtractor</span>>();
|
||
source.AddSingleton<<span class="type">IXFileContentExtractorBase</span>, <span class="type">XPowerPointFileContentExtractor</span>>();
|
||
|
||
<span class="cmt">// Register new Code Extractor ...</span>
|
||
source.AddSingleton<<span class="type">IXFileContentExtractorBase</span>, <span class="type">XCodeFileContentExtractor</span>>();
|
||
|
||
<span class="cmt">// Composite extractor ...</span>
|
||
source.AddSingleton<<span class="type">IXFileContentExtractor</span>, <span class="type">XFileContentExtractor</span>>();
|
||
}</div>
|
||
|
||
<div class="info-box">
|
||
<strong>💡 نکته مهم:</strong> ترتیب ثبت در DI در حالت فعلی Composite Extractor تأثیری ندارد، زیرا <code style="font-family: monospace;">GetExtractors</code> همه پیادهسازیها را دریافت میکند و اولین Extractor که <code style="font-family: monospace;">CanExtract</code> را <code style="font-family: monospace;">true</code> برگرداند انتخاب میشود. با این حال، چون MIME Types این Extractor با <code style="font-family: monospace;">XPlainTextFileContentExtractor</code> همپوشانی ندارد، تداخلی رخ نخواهد داد.
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="section">
|
||
<div class="section-header">
|
||
<div class="section-number">۷</div>
|
||
<div class="section-title">
|
||
<h3>اعتبارسنجی و جمعبندی</h3>
|
||
<div class="subtitle">Validation & Final Summary</div>
|
||
</div>
|
||
</div>
|
||
<div class="section-content">
|
||
<p>پس از پایان هفت گام، صحت پیادهسازی باید با مجموعهای از تستهای پایه اعتبارسنجی شود. جدول زیر چکلیست نهایی را ارائه میدهد:</p>
|
||
|
||
<table class="styled-table">
|
||
<thead>
|
||
<tr>
|
||
<th>#</th>
|
||
<th>مورد اعتبارسنجی</th>
|
||
<th>روش بررسی</th>
|
||
<th>وضعیت مورد انتظار</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td>۱</td>
|
||
<td>کامپایل موفق پروژه</td>
|
||
<td>Build در Visual Studio</td>
|
||
<td style="color: var(--success); font-weight: 600;">بدون خطا</td>
|
||
</tr>
|
||
<tr>
|
||
<td>۲</td>
|
||
<td>تشخیص صحیح MIME Type</td>
|
||
<td>فراخوانی <code style="font-family: monospace;">CanExtract</code> با <code style="font-family: monospace;">text/x-csharp</code></td>
|
||
<td style="color: var(--success); font-weight: 600;">بازگشت true</td>
|
||
</tr>
|
||
<tr>
|
||
<td>۳</td>
|
||
<td>استخراج محتوای یک فایل <code style="font-family: monospace;">.cs</code> نمونه</td>
|
||
<td>فراخوانی <code style="font-family: monospace;">ExtractAsync</code></td>
|
||
<td style="color: var(--success); font-weight: 600;">بازگشت متن کامل کد</td>
|
||
</tr>
|
||
<tr>
|
||
<td>۴</td>
|
||
<td>استخراج از مسیر Composite</td>
|
||
<td>فراخوانی <code style="font-family: monospace;">IXFileContentExtractor.ExtractAsync</code></td>
|
||
<td style="color: var(--success); font-weight: 600;">انتخاب خودکار Extractor</td>
|
||
</tr>
|
||
<tr>
|
||
<td>۵</td>
|
||
<td>عدم تداخل با PlainText Extractor</td>
|
||
<td>بررسی MIME Types مشترک</td>
|
||
<td style="color: var(--success); font-weight: 600;">هیچ همپوشانی وجود ندارد</td>
|
||
</tr>
|
||
<tr class="highlight-row">
|
||
<td><strong>۶</strong></td>
|
||
<td><strong>یکپارچگی با endpoint ExtractContent</strong></td>
|
||
<td><strong>ارسال فایل کد از طریق API</strong></td>
|
||
<td style="color: var(--success); font-weight: 700;">بازگشت محتوا با نام فایل</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
|
||
<div class="conclusion-box">
|
||
<h3>🎯 جمعبندی</h3>
|
||
<p>توسعه <code style="font-family: monospace; color: var(--accent);">XCodeFileContentExtractor</code> در هفت گام مشخص و با رعایت کامل الگوی موجود انجام شد. این Extractor بدون نیاز به تغییر در Composite Extractor یا سایر بخشهای سامانه، بهصورت خودکار در زنجیره استخراج محتوا قرار میگیرد.</p>
|
||
<div class="highlight">
|
||
<strong>💎 ارزش افزوده:</strong><br>
|
||
پوشش فایلهای کد منبع (C#، Python، JS، TS، Java و ...) + یکپارچگی کامل با معماری موجود + عدم تداخل با Extractor های فعلی
|
||
</div>
|
||
</div>
|
||
|
||
<div class="info-box">
|
||
<strong>📞 گام بعدی:</strong> پس از تأیید این مستند، پیادهسازی هفت گام فوق قابل آغاز است. پیشنهاد میشود پس از اتمام، یک تست یکپارچگی از طریق endpoint <code style="font-family: monospace;">ExtractContent</code> با ارسال یک فایل کد نمونه انجام شود تا صحت انتخاب خودکار Extractor توسط Composite تأیید گردد.
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="page-info">
|
||
این مستند محرمانه بوده و صرفاً جهت ارائه به کارفرمای محترم تهیه شده است. هرگونه کپیبرداری یا افشا بدون اجازه کتبی ممنوع است.
|
||
</div>
|
||
|
||
</div>
|
||
|
||
<footer class="document-footer">
|
||
<div class="footer-brand">طراحی و توسعه: هادی خزاعی اصل</div>
|
||
<div class="footer-divider"></div>
|
||
<div>تاریخ تهیه: ۲۹ مهر ۱۴۰۵ | نسخه: ۱.۰ | طبقهبندی: محرمانه</div>
|
||
</footer>
|
||
|
||
</div>
|
||
|
||
</body>
|
||
</html> |