/// <summary>
        /// Clones the specified research.
        /// </summary>
        /// <param name="id">ID of research to clone.</param>
        /// <returns>ID of created Research.</returns>
        public static Guid CloneResearch(Guid id)
        {
            try
            {
                AbstractResearch researchToClone = existingResearches[id];

                AbstractResearch r = AbstractResearch.CreateResearchByType(researchToClone.GetResearchType());
                existingResearches.Add(r.ResearchID, r);
                r.ModelType = researchToClone.ModelType;
                r.Storage   = AbstractResultStorage.CreateStorage(researchToClone.Storage.GetStorageType(),
                                                                  researchToClone.Storage.StorageString);
                r.GenerationType = researchToClone.GenerationType;
                r.TracingPath    = researchToClone.TracingPath;
                r.CheckConnected = researchToClone.CheckConnected;

                r.RealizationCount = researchToClone.RealizationCount;

                r.ResearchParameterValues   = researchToClone.ResearchParameterValues;
                r.GenerationParameterValues = researchToClone.GenerationParameterValues;
                r.AnalyzeOption             = researchToClone.AnalyzeOption;

                return(r.ResearchID);
            }
            catch (KeyNotFoundException)
            {
                throw new CoreException("Specified research does not exist.");
            }
        }
        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;
                // depracate sql storage

                /*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>
 /// Sets storage for specified research.
 /// </summary>
 /// <param name="id">ID of research.</param>
 /// <param name="storage">The storage type for saving results of analyze.</param>
 /// <param name="storageString">Connection string or file path for data storage.</param>
 public static void SetResearchStorage(Guid id, StorageType storageType, string storageString)
 {
     try
     {
         existingResearches[id].Storage = AbstractResultStorage.CreateStorage(storageType, storageString);
     }
     catch (KeyNotFoundException)
     {
         throw new CoreException("Specified research does not exists.");
     }
 }
        /// <summary>
        /// Creates a default research and adds to existingResearches.
        /// </summary>
        /// <param name="researchType">The type of research to create.</param>
        /// <returns>ID of created Research.</returns>
        public static Guid CreateResearch(ResearchType researchType)
        {
            AbstractResearch r = AbstractResearch.CreateResearchByType(researchType);

            existingResearches.Add(r.ResearchID, r);
            r.ModelType      = GetAvailableModelTypes(r.ResearchID)[0];
            r.ResearchName   = "Default";
            r.Storage        = AbstractResultStorage.CreateStorage(StorageType.XMLStorage, RandNetSettings.StorageDirectory);
            r.TracingPath    = "";
            r.CheckConnected = false;

            return(r.ResearchID);
        }
        /// <summary>
        /// Creates a research and adds to existingResearches.
        /// </summary>
        /// <param name="researchType">The type of research to create.</param>
        /// <param name="modelType">The model type of research to create.</param>
        /// <param name="researchName">The name of research.</param>
        /// <param name="storage">The storage type for saving results of analyze.</param>
        /// <param name="storageString">Connection string or file path for data storage.</param>
        /// <param name="tracingPath">Path, if tracing is on, and empty string otherwise.</param>
        /// <param name="checkConnected">Specifies if check for network's connected is on.</param>
        /// <returns>ID of created Research.</returns>
        public static Guid CreateResearch(ResearchType researchType,
                                          ModelType modelType,
                                          string researchName,
                                          StorageType storage,
                                          string storageString,
                                          GenerationType generationType,
                                          string tracingPath,
                                          bool checkConnected)
        {
            AbstractResearch r = AbstractResearch.CreateResearchByType(researchType);

            existingResearches.Add(r.ResearchID, r);
            r.ModelType      = modelType;
            r.ResearchName   = researchName;
            r.Storage        = AbstractResultStorage.CreateStorage(storage, storageString);
            r.GenerationType = generationType;
            r.TracingPath    = tracingPath;
            r.CheckConnected = checkConnected;

            return(r.ResearchID);
        }
        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(() => {}));
        }
Example #7
0
 public void SetResearchStorage(StorageType storageType)
 {
     research.Storage = AbstractResultStorage.CreateStorage(storageType, RandNetSettings.StorageDirectory);
 }