/// <summary>
        /// Writes matrix and branches (if exists) to specified file.
        /// </summary>
        /// <param name="matrixInfo">Matrix and branches (if exists).</param>
        /// <param name="filePath">File path.</param>
        public static void Write(MatrixInfoToWrite matrixInfo, String filePath)
        {
            String directoryPath = ExplorerSettings.TracingDirectory;
            if (!Directory.Exists(directoryPath))
                Directory.CreateDirectory(directoryPath);

            MatrixWriter(matrixInfo.Matrix, filePath);
            if(matrixInfo.Branches != null)
                BranchesWriter(matrixInfo.Branches, filePath);
        }
        /// <summary>
        /// Traces the adjacency matrix of generated network to file.
        /// </summary>
        public bool Trace(string tracingPath)
        {
            try
            {
                Logger.Write("Research - " + ResearchName +
                             ". TRACING STARTED for network - " + NetworkID.ToString());

                if (TracingIsNotSupported())
                {
                    return(true);
                }

                if (RandNetSettings.TracingType == TracingType.Matrix)
                {
                    MatrixInfoToWrite matrixInfo = new MatrixInfoToWrite();
                    matrixInfo.Matrix = networkGenerator.Container.GetMatrix();
                    if (networkGenerator.Container is AbstractHierarchicContainer)
                    {
                        matrixInfo.Branches = (networkGenerator.Container as AbstractHierarchicContainer).GetBranches();
                    }
                    matrixInfo.ActiveStates = (networkGenerator.Container as AbstractNetworkContainer).GetActiveStatuses();

                    FileManager.Write(matrixInfo, tracingPath);
                }
                else if (RandNetSettings.TracingType == TracingType.Neighbourship)
                {
                    NeighbourshipInfoToWrite neighbourshipInfo = new NeighbourshipInfoToWrite();
                    neighbourshipInfo.Neighbourship = networkGenerator.Container.GetNeighbourship();
                    if (networkGenerator.Container is AbstractHierarchicContainer)
                    {
                        neighbourshipInfo.Branches = (networkGenerator.Container as AbstractHierarchicContainer).GetBranches();
                    }
                    neighbourshipInfo.ActiveStates = (networkGenerator.Container as AbstractNetworkContainer).GetActiveStatuses();

                    FileManager.Write(neighbourshipInfo, tracingPath);
                }

                UpdateStatus(NetworkStatus.StepCompleted);

                Logger.Write("Research - " + ResearchName +
                             ". TRACING FINISHED for network - " + NetworkID.ToString());
            }
            catch (CoreException ex)
            {
                UpdateStatus(NetworkStatus.Failed);

                Logger.Write("Research - " + ResearchName +
                             "TRACING FAILED for network - " + NetworkID.ToString() +
                             ". Exception message: " + ex.Message);
                return(false);
            }

            return(true);
        }
        // TODO add to interface
        public void Trace(String directoryName, String subDirectoryName, String fileName)
        {
            String tracingDirectory = RandNetSettings.TracingDirectory;
            String dPath            = tracingDirectory + "\\" + directoryName;
            String sdPath           = dPath + "\\" + subDirectoryName;
            String fPath            = sdPath + "\\" + fileName;

            if (tracingDirectory != "")
            {
                if (!Directory.Exists(dPath))
                {
                    Directory.CreateDirectory(dPath);
                }
                if (!Directory.Exists(sdPath))
                {
                    Directory.CreateDirectory(sdPath);
                }

                if (RandNetSettings.TracingType == TracingType.Matrix)
                {
                    MatrixInfoToWrite matrixInfo = new MatrixInfoToWrite();
                    matrixInfo.Matrix       = GetMatrix();
                    matrixInfo.Branches     = null;
                    matrixInfo.ActiveStates = GetActiveStatuses();
                    FileManager.Write(matrixInfo, fPath);
                }
                else if (RandNetSettings.TracingType == TracingType.Neighbourship)
                {
                    NeighbourshipInfoToWrite neighbourshipInfo = new NeighbourshipInfoToWrite();
                    neighbourshipInfo.Neighbourship = GetNeighbourship();
                    neighbourshipInfo.Branches      = null;
                    neighbourshipInfo.ActiveStates  = GetActiveStatuses();
                    FileManager.Write(neighbourshipInfo, fPath);
                }
            }
        }
        /// <summary>
        /// Writes matrix and branches (if exists) to specified file.
        /// </summary>
        /// <param name="matrixInfo">Matrix and branches (if exists).</param>
        /// <param name="filePath">File path.</param>
        public static void Write(MatrixInfoToWrite matrixInfo, String filePath)
        {
            String directoryPath = RandNetSettings.TracingDirectory;
            if (!Directory.Exists(directoryPath))
                Directory.CreateDirectory(directoryPath);

            WriteMatrix(matrixInfo.Matrix, filePath);
            if (matrixInfo.Branches != null)
                WriteBranches(matrixInfo.Branches, filePath);
        }
        // TODO add to interface
        public void Trace(String directoryName, String subDirectoryName, String fileName)
        {
            String tracingDirectory = ExplorerSettings.TracingDirectory;
            String dPath = tracingDirectory + "\\" + directoryName;
            String sdPath = dPath + "\\" + subDirectoryName;
            String fPath = sdPath + "\\" + fileName;
            if (tracingDirectory != "")
            {
                if (!Directory.Exists(dPath))
                    Directory.CreateDirectory(dPath);
                if (!Directory.Exists(sdPath))
                    Directory.CreateDirectory(sdPath);

                MatrixInfoToWrite matrixInfo = new MatrixInfoToWrite();
                matrixInfo.Matrix = GetMatrix();
                matrixInfo.Branches = null;
                FileManager.Write(matrixInfo, fPath);
            }
        }
        public override Task StartResearch()
        {
            ValidateResearchParameters();

            StatusInfo = new ResearchStatusInfo(ResearchStatus.Running, 0);
            CustomLogger.Write("Research ID - " + ResearchID.ToString() +
                               ". Research - " + ResearchName + ". STARTED STRUCTURAL RESEARCH.");

            MatrixPath        mp       = ((MatrixPath)ResearchParameterValues[ResearchParameter.InputPath]);
            List <MatrixPath> matrixes = new List <MatrixPath>();

            Debug.Assert((File.GetAttributes(mp.Path) & FileAttributes.Directory) == FileAttributes.Directory);
            Debug.Assert(Directory.GetFiles(mp.Path, "*.txt").Count() == 1);
            MatrixPath m = new MatrixPath();

            m.Path = Directory.GetFiles(mp.Path, "*.txt")[0];
            m.Size = mp.Size;
            matrixes.Add(m);
            NetworkInfoToRead mr = FileManager.Read(m.Path, m.Size);

            // TODO FIX
            Debug.Assert(mr is MatrixInfoToRead);

            string storageString = Storage.StorageString;

            // depraceting sql storage

            /*if (Storage.GetStorageType() != StorageType.SQLStorage)
             * {*/
            storageString += ResearchName;
            if (!Directory.Exists(storageString))
            {
                Directory.CreateDirectory(storageString);
            }
            //}

            foreach (string fn in Directory.GetFiles(mp.Path, "*.sm"))
            {
                int[] s;
                FileManager.ReadSubnetworkMatrix(fn, out s);
                MatrixInfoToWrite tmp = new MatrixInfoToWrite();
                // TODO FIX
                //tmp.Matrix = CreateMatrixForSubgraph((mr as MatrixInfoToRead).Matrix, s);

                // Create temporary .txt files for each matrix
                string tmpFileName = storageString + "\\" + Path.GetFileNameWithoutExtension(fn);
                FileManager.Write(RandNetSettings.TracingDirectory, tmp, tmpFileName);

                MatrixPath sm = new MatrixPath();
                sm.Path = tmpFileName + ".txt";
                matrixes.Add(sm);
            }

            ResearchType rt = ResearchType.Basic;   // subresearch type is not supported and is always Basic

            subResearches = new List <AbstractResearch>();
            foreach (MatrixPath p in matrixes)
            {
                AbstractResearch r = AbstractResearch.CreateResearchByType(rt);
                r.ResearchName   = ResearchName + "_" + Path.GetFileNameWithoutExtension(p.Path);
                r.GenerationType = GenerationType.Static;
                r.ModelType      = ModelType;

                Debug.Assert(r.GenerationParameterValues.ContainsKey(GenerationParameter.AdjacencyMatrix));
                r.GenerationParameterValues[GenerationParameter.AdjacencyMatrix] = p;

                r.AnalyzeOption = AnalyzeOption;

                r.Storage = AbstractResultStorage.CreateStorage(Storage.GetStorageType(), storageString);
                r.OnUpdateResearchStatus += method;

                subResearches.Add(r);
            }

            if (subResearches.Count() != 0)
            {
                ++currentResearchIndex;
                return(subResearches[currentResearchIndex].StartResearch());
            }

            return(Task.Run(() => {}));
        }
        public override void StartResearch()
        {
            ValidateResearchParameters();

            StatusInfo = new ResearchStatusInfo(ResearchStatus.Running, 0);
            Logger.Write("Research ID - " + ResearchID.ToString() +
                ". Research - " + ResearchName + ". STARTED STRUCTURAL RESEARCH.");

            MatrixPath mp = ((MatrixPath)ResearchParameterValues[ResearchParameter.InputPath]);
            List<MatrixPath> matrixes = new List<MatrixPath>();

            Debug.Assert((File.GetAttributes(mp.Path) & FileAttributes.Directory) == FileAttributes.Directory);
            Debug.Assert(Directory.GetFiles(mp.Path, "*.txt").Count() == 1);
            MatrixPath m = new MatrixPath();
            m.Path = Directory.GetFiles(mp.Path, "*.txt")[0];
            m.Size = mp.Size;
            matrixes.Add(m);
            MatrixInfoToRead mr = FileManager.Read(m.Path, m.Size);

            string storageString = Storage.StorageString;
            if (Storage.GetStorageType() != StorageType.SQLStorage)
            {
                storageString += ResearchName;
                if (!Directory.Exists(storageString))
                    Directory.CreateDirectory(storageString);
            }

            foreach (string fn in Directory.GetFiles(mp.Path, "*.sm"))
            {
                int[] s;
                FileManager.ReadSubgraphMatrix(fn, out s);
                MatrixInfoToWrite tmp = new MatrixInfoToWrite();
                tmp.Matrix = CreateMatrixForSubgraph(mr.Matrix, s);

                // Create temporary .txt files for each matrix
                string tmpFileName = storageString + "\\" + Path.GetFileNameWithoutExtension(fn);
                FileManager.Write(tmp, tmpFileName);

                MatrixPath sm = new MatrixPath();
                sm.Path = tmpFileName + ".txt";
                matrixes.Add(sm);
            }

            ResearchType rt = ResearchType.Basic;   // subresearch type is not supported and is always Basic

            subResearches = new List<AbstractResearch>();
            foreach (MatrixPath p in matrixes)
            {
                AbstractResearch r = AbstractResearch.CreateResearchByType(rt);
                r.ResearchName = ResearchName + "_" + Path.GetFileNameWithoutExtension(p.Path);
                r.GenerationType = GenerationType.Static;
                r.ModelType = ModelType;

                Debug.Assert(r.GenerationParameterValues.ContainsKey(GenerationParameter.AdjacencyMatrix));
                r.GenerationParameterValues[GenerationParameter.AdjacencyMatrix] = p;

                r.AnalyzeOption = AnalyzeOption;

                r.Storage = AbstractResultStorage.CreateStorage(Storage.GetStorageType(), storageString);
                r.OnUpdateResearchStatus += method;

                subResearches.Add(r);
            }

            if (subResearches.Count() != 0)
            {
                ++currentResearchIndex;
                subResearches[currentResearchIndex].StartResearch();
            }
        }
        /// <summary>
        /// Traces the adjacency matrix of generated network to file.
        /// </summary>
        public bool Trace(string tracingPath)
        {
            try
            {
                UpdateStatus(NetworkStatus.Tracing, "Tracing.");

                MatrixInfoToWrite matrixInfo = new MatrixInfoToWrite();
                matrixInfo.Matrix = networkGenerator.Container.GetMatrix();
                if (networkGenerator.Container is AbstractHierarchicContainer)
                    matrixInfo.Branches = (networkGenerator.Container as AbstractHierarchicContainer).GetBranches();

                FileManager.Write(matrixInfo, tracingPath);

                UpdateStatus(NetworkStatus.TracingCompleted, "Tracing Completed.");
            }
            catch (SystemException ex)
            {
                UpdateStatus(NetworkStatus.Failed, "Tracing Failed.");
                return false;
            }

            return true;
        }
        /// <summary>
        /// Traces the adjacency matrix of generated network to file.
        /// </summary>
        public bool Trace(string tracingPath)
        {
            try
            {
                Logger.Write("Research - " + ResearchName +
                    ". TRACING STARTED for network - " + NetworkID.ToString());

                MatrixInfoToWrite matrixInfo = new MatrixInfoToWrite();
                matrixInfo.Matrix = networkGenerator.Container.GetMatrix();
                if (networkGenerator.Container is AbstractHierarchicContainer)
                    matrixInfo.Branches = (networkGenerator.Container as AbstractHierarchicContainer).GetBranches();

                FileManager.Write(matrixInfo, tracingPath);

                UpdateStatus(NetworkStatus.StepCompleted);

                Logger.Write("Research - " + ResearchName +
                        ". TRACING FINISHED for network - " + NetworkID.ToString());
            }
            catch (CoreException ex)
            {
                UpdateStatus(NetworkStatus.Failed);

                Logger.Write("Research - " + ResearchName +
                    "TRACING FAILED for network - " + NetworkID.ToString() +
                    ". Exception message: " + ex.Message);
                return false;
            }

            return true;
        }