studio
2023.10
false
重要 :
このコンテンツの一部は機械翻訳によって処理されており、完全な翻訳を保証するものではありません。 新しいコンテンツの翻訳は、およそ 1 ~ 2 週間で公開されます。
UiPath logo, featuring letters U and I in white

Studio ガイド

最終更新日時 2025年9月3日

ベスト プラクティス

コード化されたオートメーションの効率性、保守性、およびスケーラビリティを確保するには、ベスト プラクティスに従う必要があります。このセクションでは、コードを活用したオートメーション ソリューションの構築を開始するときに覚えておくべき主なベスト プラクティスの概要を示します。これらのベスト プラクティスに従えば、特にコードの構成、エラーの処理方法の実装、または再利用可能なコンポーネントの作成時に、コード化されたオートメーションを設計するのに役立ちます。

並列処理

Parallelism improves performance, and implementing it in coded automations is easier. A Parallel.ForEach loop can increase the speed with which an automation executes.

入れ子になったクラス

コード化されたオートメーション (CS ファイル) では、ローコードのオートメーション (XAML ファイル) 内の入れ子になったクラスの変数や引数の使用または呼び出しはサポートされていません。[ワークフロー ファイルを呼び出し] アクティビティを使用してこのような種類の引数を呼び出したり、このような引数を XAML ファイル内に作成したりしようとすると、エラーが発生します。入れ子になったクラスの変数や引数は、他の CS ファイル内でのみ使用することをお勧めします。

コード化されたワークフローの継承

コード化されたワークフローの継承により、コードの再利用性とモジュール性が向上し、子クラスが親クラスの機能を継承および拡張するクラス階層を作成できます。この継承階層により、コードの整理が容易になり、複数のクラス間で共通の機能が重複するのを回避できます。さらに、親クラスに対する変更は自動的に子クラスにも反映され、バグや不整合が発生する可能性が低くなるため、メンテナンスと更新が簡素化されます。
CodedWorkflowParentFile (CodedWorkflow を継承し、カスタム メソッドを含む中間クラス)、および MyCustomWorkflowAnotherCustomWorkflow (ParentFile を継承する派生クラス) の 3 つのクラスを使用して継承がどのように機能するかを見てみましょう。以下の表は、これらのクラスとファイル間の継承がどのように機能するかを示しています。
コード化されたオートメーション説明コード
CodedWorkflow (read-only partial class) このクラスは、すべてのコード化されたワークフローの基盤として機能し、CodedWorkflowBase クラスから継承された、すべてのワークフローに共通する基本的なメソッドとプロパティが含まれています。この例では、他のすべてのワークフローが最終的に継承するクラスです。
重要: 他のワークフローに継承させるファイルも、CodedWorkflow クラスと、暗黙的に CodedWorkflowBase クラスを継承する必要があります。これにより、すべてのワークフローが重要な機能を継承し、予期したとおりに動作するようになります。
public partial class CodedWorkflow : CodedWorkflowBase
    {
        public CodedWorkflow()
        {
         //...

    }
}public partial class CodedWorkflow : CodedWorkflowBase
    {
        public CodedWorkflow()
        {
         //...

    }
}
ParentFile (code source file containing an intermediate class and a custom method) このクラスは、CodedWorkflow を継承し、カスタム メソッドと機能を追加します。この例では、Orchestrator でのジョブの開始などの特定のアクションを実行する CustomMethod というカスタム メソッドが含まれています。
public class ParentFile : CodedWorkflow
{
    public void CustomMethod(string processName, string folderPath, 
    StartProcessDtoJobPriority jobPriority, bool resumeOnSameContext, 
    out string jobId)
    {
        // Enter your custom code here.
        // For example, use the StartJob API inside this custom method.
        jobId = system.StartJob(processName, folderPath, jobPriority, resumeOnSameContext);
    }
}public class ParentFile : CodedWorkflow
{
    public void CustomMethod(string processName, string folderPath, 
    StartProcessDtoJobPriority jobPriority, bool resumeOnSameContext, 
    out string jobId)
    {
        // Enter your custom code here.
        // For example, use the StartJob API inside this custom method.
        jobId = system.StartJob(processName, folderPath, jobPriority, resumeOnSameContext);
    }
}
MyCustomWorkflow and AnotherCustomWorkflow (coded workflows that inherit the code source file) これらのクラスは ParentFile を継承し、メソッドをオーバーライドするか、異なるパラメーター値を指定して、ワークフローをさらにカスタマイズします。この例では、MyCustomWorkflowAnotherCustomWorkflow があり、どちらも ParentFile を継承します。
public class MyCustomWorkflow : ParentFile
    {
        [Workflow]
        public void Execute()
        {
            // You can now call CustomMethod from the base class.
            string processName = "YourProcessName";
            string folderPath = "YourFolderPath";
            StartProcessDtoJobPriority jobPriority = StartProcessDtoJobPriority.Normal;
            bool resumeOnSameContext = false;
            string jobId;

            // Call the custom method from the base class.
            CustomMethod(processName, folderPath, 
            jobPriority, resumeOnSameContext, out jobId);
        }
    }public class MyCustomWorkflow : ParentFile
    {
        [Workflow]
        public void Execute()
        {
            // You can now call CustomMethod from the base class.
            string processName = "YourProcessName";
            string folderPath = "YourFolderPath";
            StartProcessDtoJobPriority jobPriority = StartProcessDtoJobPriority.Normal;
            bool resumeOnSameContext = false;
            string jobId;

            // Call the custom method from the base class.
            CustomMethod(processName, folderPath, 
            jobPriority, resumeOnSameContext, out jobId);
        }
    }
結論として、ParentFileCodedWorkflow を継承するため、ParentFile を継承するクラスは、CodedWorkflow の機能とメソッドを間接的に継承します。つまり、MyCustomWorkflowAnotherCustomWorkflow はどちらも、部分クラス CodedWorkflow から中間 ParentFile を介して、コア機能と他のカスタム クラス (CustomMethod など) を継承します。

カスタム サービスを登録する

To enhance your coded automations, using custom logic, you can register custom services that you later use in your coded automations. Visit Registering custom services to learn how to register your own custom service.

Before および After コンテキスト

Within test cases, the Before and After contexts allow you to execute certain actions before and after the test case is run. These contexts are commonly used to set up and tear down resources, perform logging, and manage the test environment. Visit Before and After contexts to learn how the contexts behave and how to implement them.

ヒントとコツ

効率的で堅牢なコード化されたオートメーションを設計するには、以下に記載されているヒントとコツを参考にしてください。これらの情報は、コードを最適化し、エラーを回避して、パフォーマンスを最大限に高めるのに役立ちます。
  • 名前空間は変更しないことをお勧めします。
  • アクションをクラス内に格納し、プロジェクト全体で再利用して、コードの重複を回避します。
  • 設計時にインポートしたものの不要になった名前空間は削除できます。
  • 複数のアプリケーションからデータを取得する必要がある場合は、コード化されたオートメーションのフェーズを分離して、さまざまなソースからのデータが混在しないようにします。

このページは役に立ちましたか?

サポートを受ける
RPA について学ぶ - オートメーション コース
UiPath コミュニティ フォーラム
Uipath Logo
信頼とセキュリティ
© 2005-2025 UiPath. All rights reserved.