public override void StopResearch()
        {
            currentManager.Cancel();
            StatusInfo = new ResearchStatusInfo(ResearchStatus.Stopped, StatusInfo.CompletedStepsCount);

            Logger.Write("Research ID - " + ResearchID.ToString() +
                ". Research - " + ResearchName + ". STOPPED BASIC RESEARCH.");
        }
        public override void StartResearch()
        {
            ValidateResearchParameters();

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

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

            Debug.Assert((File.GetAttributes(mp.Path) & FileAttributes.Directory) == FileAttributes.Directory);
            foreach (string fn in Directory.GetFiles(mp.Path, "*.txt"))
            {
                MatrixPath m = new MatrixPath();
                m.Path = fn;
                m.Size = mp.Size;
                matrixes.Add(m);
            }

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

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

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

                r.AnalyzeOption = AnalyzeOption;

                string storageString = Storage.StorageString;
                if (Storage.GetStorageType() != StorageType.SQLStorage)
                {
                    storageString += ResearchName;
                    if (!Directory.Exists(storageString))
                        Directory.CreateDirectory(storageString);
                }
                r.Storage = AbstractResultStorage.CreateStorage(Storage.GetStorageType(), storageString);
                r.OnUpdateResearchStatus += method;

                subResearches.Add(r);
            }

            if (subResearches.Count() != 0)
            {
                ++currentResearchIndex;
                subResearches[currentResearchIndex].StartResearch();
            }
        }
        /// <summary>
        /// Creates single EnsembleManager, runs in background thread.
        /// </summary>
        public override void StartResearch()
        {
            ValidateResearchParameters();

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

            ManagerRunner r = new ManagerRunner(currentManager.Run);
            r.BeginInvoke(new AsyncCallback(RunCompleted), null);
        }
        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();
            }
        }
 private void method(object sender, ResearchEventArgs e)
 {
     ResearchStatus rs = GetSubresearchStatus(e.ResearchID);
     if (rs == ResearchStatus.Completed)
     {
         Interlocked.Increment(ref currentResearchIndex);
         if (currentResearchIndex >= subResearches.Count())
             StatusInfo = new ResearchStatusInfo(ResearchStatus.Completed, (uint)currentResearchIndex);
         else
         {
             StatusInfo = new ResearchStatusInfo(ResearchStatus.Running, StatusInfo.CompletedStepsCount + 1);
             subResearches[currentResearchIndex].StartResearch();
         }
     }
 }
        public override void StopResearch()
        {
            if (subResearches != null)
            {
                foreach (AbstractResearch r in subResearches)
                    r.StopResearch();

                StatusInfo = new ResearchStatusInfo(ResearchStatus.Stopped, StatusInfo.CompletedStepsCount);

                Logger.Write("Research ID - " + ResearchID.ToString() +
                    ". Research - " + ResearchName + ". STOPPED STRUCTURAL RESEARCH.");
            }
        }
 private void AbstractResearch_OnUpdateNetworkStatus(object sender, NetworkEventArgs e)
 {
     switch (e.Status)
     {
         case NetworkStatus.StepCompleted:
             StatusInfo = new ResearchStatusInfo(ResearchStatus.Running, StatusInfo.CompletedStepsCount + 1);
             break;
         case NetworkStatus.Failed:
             StatusInfo = new ResearchStatusInfo(ResearchStatus.Failed, StatusInfo.CompletedStepsCount);
             break;
         default:
             Debug.Assert(false);
             break;
     }
 }
        /// <summary>
        /// Saves the results of research analyze.
        /// </summary>
        protected void SaveResearch()
        {
            if (result.EnsembleResults.Count() != 0 && result.EnsembleResults[0] == null)
                return;
            result.ResearchID = ResearchID;
            result.ResearchName = ResearchName;
            result.ResearchType = GetResearchType();
            result.ModelType = modelType;
            result.RealizationCount = realizationCount;
            result.Size = result.EnsembleResults[0].NetworkSize;
            result.Edges = result.EnsembleResults[0].EdgesCount;
            result.Date = DateTime.Now;

            result.ResearchParameterValues = ResearchParameterValues;
            result.GenerationParameterValues = GenerationParameterValues;

            Storage.Save(result);
            StatusInfo = new ResearchStatusInfo(ResearchStatus.Completed, StatusInfo.CompletedStepsCount + 1);

            Logger.Write("Research - " + ResearchName + ". Result is SAVED");
        }