Exemplo n.º 1
0
 public Configuration(string datafilepath, string logfilepath, string solutionfilepath, int randomseed, int numberofruns, AlgorithmTypes algorithmtype)
 {
     this.datafilepath = datafilepath;
     this.logfilepath = logfilepath;
     this.solutionfilepath = solutionfilepath;
     this.randomseed = randomseed;
     this.numberofruns = numberofruns;
     this.algorithmtype = algorithmtype;
 }
Exemplo n.º 2
0
 public Configuration()
 {
     this.datafilepath = "";
     this.logfilepath = "";
     this.solutionfilepath = "";
     this.randomseed = 0;
     this.numberofruns = 1;
     this.algorithmtype = AlgorithmTypes.RANDOM;
 }
Exemplo n.º 3
0
 public Configuration(string datafilepath, string logfilepath, string solutionfilepath, int randomseed, int numberofruns, AlgorithmTypes algorithmtype, double penaltycoefficient)
 {
     this.datafilepath = datafilepath;
     this.logfilepath = logfilepath;
     this.solutionfilepath = solutionfilepath;
     this.randomseed = randomseed;
     this.numberofruns = numberofruns;
     this.algorithmtype = algorithmtype;
     this.penaltycoefficient = penaltycoefficient;
 }
Exemplo n.º 4
0
        public static FormMinimizeProblems GetInstance(AlgorithmTypes type)
        {
            if (Instance == null)
            {
                Instance = new FormMinimizeProblems();
            }

            _algorithmType = type;
            return(Instance);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Instantiates an instance of a class that implements IAlgorithmFactory
        /// </summary>
        /// <param name="algorithmType"></param>
        /// <returns></returns>
        public static AlgorithmFactory GetFactory(AlgorithmTypes algorithmType)
        {
            switch (algorithmType)
            {
            case AlgorithmTypes.Graph:
                return(new GraphFactory());

            case AlgorithmTypes.LinkedList:
                return(new LinkedListFactory());

            case AlgorithmTypes.SortAndSearch:
                return(new SortAndSearchFactory());
            }

            return(null);
        }
Exemplo n.º 6
0
        public static string AlgorithmName(AlgorithmTypes alg)
        {
            switch (alg)
            {
            case AlgorithmTypes.Greedy:
                return("Greedy");

            case AlgorithmTypes.Random:
                return("Random");

            case AlgorithmTypes.Heuristic:
                return("Heuristic");

            default:
                return("I do not know this algorithm");
            }
        }
Exemplo n.º 7
0
         public static RequiredValidationMode Create(AlgorithmTypes algorithmType)
         {
             // loop thru all registered implementations
             foreach (Type impl in _registeredImplementations)
             {
                 // get attributes for this type
                 object[] attrlist = impl.GetCustomAttributes(true);
 
                 // loop thru all attributes for this class
                 foreach (object attr in attrlist)
                 {
                     if (attr is AlgorithmAttribute)
                     {
                         if (((AlgorithmAttribute)attr).AlgorithmType.Equals(algorithmType))
                         {
                             return (RequiredValidationMode)System.Activator.CreateInstance(impl);
                         }
                     }
                 }
             }
             throw new Exception("Could not find a RequiredValidationMode implementation for this AlgorithmType");
         }
        private AlgorithmTypes Translate(String input)
        {
            AlgorithmTypes result = AlgorithmTypes.MD5;//default

            bool isSha1   = Regex.IsMatch(input, "^(SHA1|SHA-1|)$");
            bool isSha224 = Regex.IsMatch(input, "^(SHA224|SHA-224)$");
            bool isSha256 = Regex.IsMatch(input, "^(SHA256|SHA-256)$");
            bool isSha384 = Regex.IsMatch(input, "^(SHA384|SHA-384)$");
            bool isSha512 = Regex.IsMatch(input, "^(SHA512|SHA-512)$");
            bool isMd5    = Regex.IsMatch(input, "^(MD5|MD-5)$");

            if (isSha1)
            {
                return(AlgorithmTypes.SHA1);
            }
            if (isSha224)
            {
                return(AlgorithmTypes.SHA224);
            }
            if (isSha256)
            {
                return(AlgorithmTypes.SHA256);
            }
            if (isSha384)
            {
                return(AlgorithmTypes.SHA384);
            }
            if (isSha512)
            {
                return(AlgorithmTypes.SHA512);
            }
            if (isMd5)
            {
                return(AlgorithmTypes.MD5);
            }

            return(result);
        }
Exemplo n.º 9
0
        public bool loadFromFile(string path)
        {
            StreamReader infile;
            try
            {
                 infile = new StreamReader(path);
            }
            catch(Exception e)
            {
                Console.WriteLine("Load ConfigFile Exception: " + e.Message);
                return false;
            }

            this.datafilepath = infile.ReadLine().Split(new string[] { ": " }, StringSplitOptions.None)[1];

            string algortype = infile.ReadLine().Split(new string[] { ": " }, StringSplitOptions.None)[1];
            Console.WriteLine(algortype);
            if(algortype.ToUpper() == "RANDOM")
            {
                this.algorithmtype = AlgorithmTypes.RANDOM;
                this.randomseed = Convert.ToInt32(infile.ReadLine().Split(new string[] { ": " }, StringSplitOptions.None)[1]);
                this.numberofruns = Convert.ToInt32(infile.ReadLine().Split(new string[] { ": " }, StringSplitOptions.None)[1]);
                this.penaltycoefficient = Convert.ToDouble(infile.ReadLine().Split(new string[] { ": " }, StringSplitOptions.None)[1]);
                this.logfilepath = infile.ReadLine().Split(new string[] { ": " }, StringSplitOptions.None)[1];
                this.solutionfilepath = infile.ReadLine().Split(new string[] { ": " }, StringSplitOptions.None)[1];
            }
            else if(algortype.ToUpper() == "MULAMBDA")
            {
                this.algorithmtype = AlgorithmTypes.MULAMBDA;
                this.randomseed = Convert.ToInt32(infile.ReadLine().Split(new string[] { ": " }, StringSplitOptions.None)[1]);
                this.numberofruns = Convert.ToInt32(infile.ReadLine().Split(new string[] { ": " }, StringSplitOptions.None)[1]);
                this.populationsize = Convert.ToInt32(infile.ReadLine().Split(new string[] { ": " }, StringSplitOptions.None)[1]);
                this.numberofchildren = Convert.ToInt32(infile.ReadLine().Split(new string[] { ": " }, StringSplitOptions.None)[1]);
                this.usencrossover = Convert.ToBoolean(infile.ReadLine().Split(new string[] { ": " }, StringSplitOptions.None)[1]);
                this.useuniformcrossover = Convert.ToBoolean(infile.ReadLine().Split(new string[] { ": " }, StringSplitOptions.None)[1]);
                this.numberofcrossoverpoints = Convert.ToInt32(infile.ReadLine().Split(new string[] { ": "}, StringSplitOptions.None)[1]);
                this.usektournamentforparent = Convert.ToBoolean(infile.ReadLine().Split(new string[] { ": " }, StringSplitOptions.None)[1]);
                this.usefitnessproportionforparent = Convert.ToBoolean(infile.ReadLine().Split(new string[] { ": " }, StringSplitOptions.None)[1]);
                this.parenttournamentsize = Convert.ToInt32(infile.ReadLine().Split(new string[] { ": " }, StringSplitOptions.None)[1]);
                this.bitstoflip = Convert.ToInt32(infile.ReadLine().Split(new string[] { ": " }, StringSplitOptions.None)[1]);
                this.usektournamentforsurvivor = Convert.ToBoolean(infile.ReadLine().Split(new string[] { ": " }, StringSplitOptions.None)[1]);
                this.usetruncationforsurvivor = Convert.ToBoolean(infile.ReadLine().Split(new string[] { ": " }, StringSplitOptions.None)[1]);
                this.survivortournamentsize = Convert.ToInt32(infile.ReadLine().Split(new string[] { ": "}, StringSplitOptions.None)[1]);
                this.terminationconvergence = Convert.ToInt32(infile.ReadLine().Split(new string[] { ": "}, StringSplitOptions.None)[1]);
                this.penaltycoefficient = Convert.ToDouble(infile.ReadLine().Split(new string[] { ": " }, StringSplitOptions.None)[1]);
                this.numberofevals = Convert.ToInt32(infile.ReadLine().Split(new string[] { ": " }, StringSplitOptions.None)[1]);
                this.logfilepath = infile.ReadLine().Split(new string[] { ": " }, StringSplitOptions.None)[1];
                this.solutionfilepath = infile.ReadLine().Split(new string[] { ": " }, StringSplitOptions.None)[1];
            }
            else
            {
                throw new Exception("Invalid algorithm type: " + algortype);
            }

            return true;
        }
Exemplo n.º 10
0
        //HeuristicAlgorithm znajduje sie w AI_Heuristic.cs

        /// <summary>
        /// Zwraca ruch wg wybranego algorytmu.
        /// </summary>
        /// <param name="playerPossibleMoves">Mozliwe ruchy gracza.</param>
        /// <param name="trickPosition">Pozycja w lewie.</param>
        /// <param name="curTrickCards">Karty w lewie(od 0 do 3).</param>
        /// <param name="alg">Wybrany algorytm - enum.</param>
        /// <returns>Zwraca wyliczona karte wg wybranego algorytmu.</returns>
        public Card ChooseAlgorithm(Deck playerPossibleMoves, int trickPosition, List <Card> curTrickCards, AlgorithmTypes alg)
        {
            switch (alg)
            {
            case AlgorithmTypes.Random:
            {
                return(RandomAlgorithm(playerPossibleMoves, trickPosition, curTrickCards));
            }

            case AlgorithmTypes.Greedy:
            {
                return(GreedyAlgorithm(playerPossibleMoves, trickPosition, curTrickCards));
            }

            case AlgorithmTypes.Heuristic:
            {
                //HeuristicAlgorithm(...) znajduje sie w AI_Heuristic.cs
                return(HeuristicAlgorithm(playerPossibleMoves, trickPosition, curTrickCards));
            }

            default:
                return(RandomAlgorithm(playerPossibleMoves, trickPosition, curTrickCards));
            }
        }
Exemplo n.º 11
0
        public bool loadFromFile(string path)
        {
            StreamReader infile;
            try
            {
                 infile = new StreamReader(path);
            }
            catch(Exception e)
            {
                Console.WriteLine("Load ConfigFile Exception: " + e.Message);
                return false;
            }

            this.datafilepath = infile.ReadLine().Split(new string[] { ": " }, StringSplitOptions.None)[1];

            string algortype = infile.ReadLine().Split(new string[] { ": " }, StringSplitOptions.None)[1];

            if(algortype.ToUpper() == "RANDOM")
                this.algorithmtype = AlgorithmTypes.RANDOM;
            else
            {
                throw new Exception("Invalid algorithm type: " + algortype);
            }
            this.randomseed = Convert.ToInt32(infile.ReadLine().Split(new string[] { ": " }, StringSplitOptions.None)[1]);
            this.numberofruns = Convert.ToInt32(infile.ReadLine().Split(new string[] { ": " }, StringSplitOptions.None)[1]);
            this.logfilepath = infile.ReadLine().Split(new string[] { ": " }, StringSplitOptions.None)[1];
            this.solutionfilepath = infile.ReadLine().Split(new string[] { ": " }, StringSplitOptions.None)[1];

            return true;
        }
        public override void Execute()
        {
            var eventModel = CurrentActionProperties(TargetCollection, this.GetType().Name);

            OnTrigger(new PreingestEventArgs {
                Description = String.Format("Start running checksum for container '{0}'.", TargetCollection), Initiate = DateTimeOffset.Now, ActionType = PreingestActionStates.Started, PreingestAction = eventModel
            });

            var  anyMessages = new List <String>();
            bool isSuccess   = false;

            try
            {
                base.Execute();

                if (HashType == null)
                {
                    throw new ApplicationException("Algorithm is not set!");
                }

                string sessionFolder = Path.Combine(ApplicationSettings.DataFolderName, SessionGuid.ToString());

                //list of output result json files
                var outputJson = new DirectoryInfo(Path.Combine(ApplicationSettings.DataFolderName, SessionGuid.ToString())).GetFiles("*.*", SearchOption.TopDirectoryOnly).ToList();
                //list all files from guid folder
                var allFiles = new DirectoryInfo(Path.Combine(ApplicationSettings.DataFolderName, SessionGuid.ToString())).GetFiles("*.*", SearchOption.AllDirectories).ToList();
                //list of only files without json
                var targetFiles = allFiles.Where(item => !outputJson.Exists((x) => { return(x.FullName == item.FullName); })).ToList();

                var jsonData = new List <String[]>();

                if (HashType.ProcessingMode == ExecutionMode.CalculateAndCompare)
                {
                    var metadataFiles = this.IsToPX ? targetFiles.Where(item => item.Name.EndsWith(".metadata", StringComparison.InvariantCultureIgnoreCase)).ToList() : targetFiles.Where(item => item.Name.EndsWith(".mdto.xml", StringComparison.InvariantCultureIgnoreCase)).ToList();
                    eventModel.Summary.Processed = metadataFiles.Count();
                    //compare modus: compare checksum algorithm/value in metadata with self check algorithm/value
                    if (IsToPX)
                    {
                        var listOfFiles = metadataFiles.Select(item => new
                        {
                            Fullname = item.FullName,
                            ToPX     = DeserializerHelper.DeSerializeObjectFromXmlFile <Entities.ToPX.v2_3_2.topxType>(item)
                        }).Where(item => item.ToPX.Item is Entities.ToPX.v2_3_2.bestandType).Select(item => new
                        {
                            Fullname = item.Fullname,
                            Bestand  = item.ToPX.Item as Entities.ToPX.v2_3_2.bestandType
                        }).ToList();

                        eventModel.Summary.Processed = listOfFiles.Count();

                        listOfFiles.ForEach(topx =>
                        {
                            var fixityList = topx.Bestand.formaat.Select(fixity => fixity.fysiekeIntegriteit != null ?
                                                                         new
                            {
                                FixitiyAlgorithm = fixity.fysiekeIntegriteit.algoritme != null ? fixity.fysiekeIntegriteit.algoritme.Value : String.Empty,
                                FixitiyValue     = fixity.fysiekeIntegriteit.waarde != null ? fixity.fysiekeIntegriteit.waarde.Value : String.Empty
                            } :
                                                                         new
                            {
                                FixitiyAlgorithm = string.Empty,
                                FixitiyValue     = string.Empty
                            }).ToList();

                            fixityList.ForEach(fixity =>
                            {
                                bool isEmptyAlgorithm = String.IsNullOrEmpty(fixity.FixitiyAlgorithm);
                                bool isEmptyValue     = String.IsNullOrEmpty(fixity.FixitiyValue);

                                if (isEmptyAlgorithm && isEmptyValue)
                                {
                                    anyMessages.Add(String.Format("No algorithm + value found in '{0}'", topx.Fullname));
                                }

                                if (isEmptyAlgorithm && !isEmptyValue)
                                {
                                    anyMessages.Add(String.Format("No algorithm, but value found in '{0}'", topx.Fullname));
                                }

                                if (!isEmptyAlgorithm && isEmptyValue)
                                {
                                    anyMessages.Add(String.Format("Algorithm found, but no value found in '{0}'", topx.Fullname));
                                }

                                if (!isEmptyAlgorithm && !isEmptyValue)
                                {
                                    //todo, set algorithm first
                                    AlgorithmTypes foundAlgorithm = Translate(fixity.FixitiyAlgorithm);
                                    var fixityCheckResult         = RunFixityCheck(new FileInfo(topx.Fullname.Replace(".metadata", String.Empty, StringComparison.InvariantCultureIgnoreCase)), foundAlgorithm, fixity.FixitiyValue);

                                    anyMessages.AddRange(fixityCheckResult.Where(item => item.Type == ResultType.InfoType.Message).SelectMany(item => item.Data.ToArray()));
                                    jsonData.AddRange(fixityCheckResult.Where(item => item.Type == ResultType.InfoType.Action).Select(item => item.Data.ToArray()));
                                }
                            });
                        });
                    }

                    if (IsMDTO)
                    {
                        var listOfFiles = metadataFiles.Select(item
                                                               => new
                        {
                            Fullname = item.FullName,
                            MDTO     = DeserializerHelper.DeSerializeObjectFromXmlFile <Entities.MDTO.v1_0.mdtoType>(item)
                        }).Where(item => item.MDTO.Item is Entities.MDTO.v1_0.bestandType).Select(item => new
                        {
                            Fullname = item.Fullname,
                            Bestand  = item.MDTO.Item as Entities.MDTO.v1_0.bestandType
                        }).ToList();

                        eventModel.Summary.Processed = listOfFiles.Count();

                        listOfFiles.ForEach(mdto =>
                        {
                            var fixityList = mdto.Bestand.checksum.Select(fixity => new
                            {
                                FixitiyAlgorithm = fixity.checksumAlgoritme != null ? fixity.checksumAlgoritme.begripLabel : String.Empty,
                                FixitiyValue     = fixity.checksumWaarde
                            }).ToList();

                            fixityList.ForEach(fixity =>
                            {
                                bool isEmptyAlgorithm = String.IsNullOrEmpty(fixity.FixitiyAlgorithm);
                                bool isEmptyValue     = String.IsNullOrEmpty(fixity.FixitiyValue);

                                if (isEmptyAlgorithm && isEmptyValue)
                                {
                                    anyMessages.Add(String.Format("No algorithm + value found in '{0}'", mdto.Fullname));
                                }

                                if (isEmptyAlgorithm && !isEmptyValue)
                                {
                                    anyMessages.Add(String.Format("No algorithm, but value found in '{0}'", mdto.Fullname));
                                }

                                if (!isEmptyAlgorithm && isEmptyValue)
                                {
                                    anyMessages.Add(String.Format("Algorithm found, but no value found in '{0}'", mdto.Fullname));
                                }

                                if (!isEmptyAlgorithm && !isEmptyValue)
                                {
                                    //todo, set algorithm first
                                    AlgorithmTypes foundAlgorithm = Translate(fixity.FixitiyAlgorithm);
                                    var fixityCheckResult         = RunFixityCheck(new FileInfo(mdto.Fullname.Replace(".mdto.xml", String.Empty, StringComparison.InvariantCultureIgnoreCase)), foundAlgorithm, fixity.FixitiyValue);

                                    anyMessages.AddRange(fixityCheckResult.Where(item => item.Type == ResultType.InfoType.Message).SelectMany(item => item.Data.ToArray()));
                                    jsonData.AddRange(fixityCheckResult.Where(item => item.Type == ResultType.InfoType.Action).Select(item => item.Data.ToArray()));
                                }
                            });
                        });
                    }
                    eventModel.Properties.Messages = anyMessages.ToArray();
                }

                if (HashType.ProcessingMode == ExecutionMode.OnlyCalculate)
                {
                    var binaryFiles = this.IsToPX ? targetFiles.Where(item => !item.Name.EndsWith(".metadata", StringComparison.InvariantCultureIgnoreCase)).ToList() : targetFiles.Where(item => !item.Name.EndsWith(".mdto.xml", StringComparison.InvariantCultureIgnoreCase)).ToList();
                    eventModel.Summary.Processed = binaryFiles.Count();

                    foreach (FileInfo file in binaryFiles)
                    {
                        var fixityCheckResult = RunFixityCheck(file, HashType.ChecksumType);
                        anyMessages.AddRange(fixityCheckResult.Where(item => item.Type == ResultType.InfoType.Message).SelectMany(item => item.Data.ToArray()));
                        jsonData.AddRange(fixityCheckResult.Where(item => item.Type == ResultType.InfoType.Action).Select(item => item.Data.ToArray()));
                    }
                    eventModel.Properties.Messages = new string[] { HashType.ChecksumType.ToString() };
                }

                eventModel.ActionData       = jsonData.ToArray();
                eventModel.Summary.Accepted = jsonData.Count();
                eventModel.Summary.Rejected = anyMessages.Count();

                if (eventModel.Summary.Rejected > 0)
                {
                    eventModel.ActionResult.ResultValue = PreingestActionResults.Error;
                }
                else
                {
                    eventModel.ActionResult.ResultValue = PreingestActionResults.Success;
                }

                isSuccess = true;
            }
            catch (Exception e)
            {
                isSuccess = false;
                anyMessages.Clear();
                anyMessages.Add(String.Format("Running checksum with collection: '{0}' failed!", TargetCollection));
                anyMessages.Add(e.Message);
                anyMessages.Add(e.StackTrace);

                Logger.LogError(e, "Running checksum with collection: '{0}' failed!", TargetCollection);

                eventModel.ActionResult.ResultValue = PreingestActionResults.Failed;
                eventModel.Properties.Messages      = anyMessages.ToArray();
                eventModel.Summary.Processed        = 1;
                eventModel.Summary.Accepted         = 0;
                eventModel.Summary.Rejected         = 1;

                OnTrigger(new PreingestEventArgs {
                    Description = "An exception occured while running checksum!", Initiate = DateTimeOffset.Now, ActionType = PreingestActionStates.Failed, PreingestAction = eventModel
                });
            }
            finally
            {
                if (isSuccess)
                {
                    OnTrigger(new PreingestEventArgs {
                        Description = "Checksum run with a collection is done.", Initiate = DateTimeOffset.Now, ActionType = PreingestActionStates.Completed, PreingestAction = eventModel
                    });
                }
            }
        }
        private List <ResultType> RunFixityCheck(FileInfo binaryFiles, AlgorithmTypes useAlgorithm, string valueToCompare = null)
        {
            List <ResultType> checkResult = new List <ResultType>();

            string currentCalculation = string.Empty, url = string.Empty, urlPart = string.Empty;

            try
            {
                switch (useAlgorithm)
                {
                default:
                case AlgorithmTypes.MD5:
                {
                    urlPart            = "checksum-md5";
                    url                = String.Format("http://{0}:{1}/hooks/{3}?file={2}", ApplicationSettings.ChecksumServerName, ApplicationSettings.ChecksumServerPort, binaryFiles.FullName, urlPart);
                    currentCalculation = ChecksumHelper.CreateMD5Checksum(binaryFiles, url);
                }
                break;

                case AlgorithmTypes.SHA1:
                {
                    urlPart            = "checksum-sha1";
                    url                = String.Format("http://{0}:{1}/hooks/{3}?file={2}", ApplicationSettings.ChecksumServerName, ApplicationSettings.ChecksumServerPort, binaryFiles.FullName, urlPart);
                    currentCalculation = ChecksumHelper.CreateSHA1Checksum(binaryFiles, url);
                }
                break;

                case AlgorithmTypes.SHA224:
                {
                    urlPart            = "checksum-sha224";
                    url                = String.Format("http://{0}:{1}/hooks/{3}?file={2}", ApplicationSettings.ChecksumServerName, ApplicationSettings.ChecksumServerPort, binaryFiles.FullName, urlPart);
                    currentCalculation = ChecksumHelper.CreateSHA224Checksum(binaryFiles, url);
                }
                break;

                case AlgorithmTypes.SHA256:
                {
                    urlPart            = "checksum-sha256";
                    url                = String.Format("http://{0}:{1}/hooks/{3}?file={2}", ApplicationSettings.ChecksumServerName, ApplicationSettings.ChecksumServerPort, binaryFiles.FullName, urlPart);
                    currentCalculation = ChecksumHelper.CreateSHA256Checksum(binaryFiles, url);
                }
                break;

                case AlgorithmTypes.SHA384:
                {
                    urlPart            = "checksum-sha384";
                    url                = String.Format("http://{0}:{1}/hooks/{3}?file={2}", ApplicationSettings.ChecksumServerName, ApplicationSettings.ChecksumServerPort, binaryFiles.FullName, urlPart);
                    currentCalculation = ChecksumHelper.CreateSHA384Checksum(binaryFiles, url);
                }
                break;

                case AlgorithmTypes.SHA512:
                {
                    urlPart            = "checksum-sha512";
                    url                = String.Format("http://{0}:{1}/hooks/{3}?file={2}", ApplicationSettings.ChecksumServerName, ApplicationSettings.ChecksumServerPort, binaryFiles.FullName, urlPart);
                    currentCalculation = ChecksumHelper.CreateSHA512Checksum(binaryFiles, url);
                }
                break;
                }
            }
            catch (Exception e)
            {
                checkResult.Add(new ResultType
                {
                    Type = ResultType.InfoType.Message,
                    Data = new string[] { binaryFiles.FullName, "Failed to run fixity checksum!", e.Message, e.StackTrace }
                });
            }
            finally {
                if (!String.IsNullOrEmpty(currentCalculation) && HashType.ProcessingMode == ExecutionMode.OnlyCalculate)
                {
                    checkResult.Add(new ResultType
                    {
                        Type = ResultType.InfoType.Action,
                        Data = new string[] { binaryFiles.FullName, currentCalculation }
                    });
                }

                if (!String.IsNullOrEmpty(currentCalculation) && HashType.ProcessingMode == ExecutionMode.CalculateAndCompare)
                {
                    if (currentCalculation.Equals(valueToCompare, StringComparison.InvariantCultureIgnoreCase))
                    {
                        checkResult.Add(new ResultType
                        {
                            Type = ResultType.InfoType.Action,
                            Data = new string[] { binaryFiles.FullName,
                                                  useAlgorithm.ToString(),
                                                  string.Format("Our calculation : {0}", currentCalculation),
                                                  string.Format("Provided value : {0}", valueToCompare), }
                        });
                    }
                    else
                    {
                        checkResult.Add(new ResultType
                        {
                            Type = ResultType.InfoType.Message,
                            Data = new string[] { String.Format("Fixity comparison with file '{0}' using algorithm '{1}' failed!{2}Our calculation: {3}{2}Provided value:{4}  ", binaryFiles.FullName, useAlgorithm, Environment.NewLine, currentCalculation, valueToCompare) }
                        });
                    }
                }
            }

            return(checkResult);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Zagrywa karte wyliczona przez algorytm.
        /// </summary>
        /// <param name="playerPossibleMoves">Wszystkie mozliwe ruchy gracza.</param>
        /// <param name="playerTrick">Kupka na ktora gracz zagrywa karte.</param>
        /// <param name="usedCards">Reka w ktorej przechowywane sa zagrane karty gracza.</param>
        /// <returns>Zagrana karta.</returns>
        private Card PlayCardChosenAlgorithm(Deck playerPossibleMoves, DeckShape playerTrick, Hand usedCards, AlgorithmTypes chosenAlg)
        {
            //tutaj jest wybor algorytmu - akurat teraz jest losowa karta z gory
            //var card = playerPossibleMoves.RandomCard;
            var card = ChooseAlgorithm(playerPossibleMoves, currentTrick.Count, currentTrick, chosenAlg);

            //zagraj karte zwrocona przez algorytm
            Card playedCard = new Card(card.Rank, card.Suit, playerPossibleMoves);

            PlayCard(playerPossibleMoves, playerTrick.Deck, card);

            //wylaczyc zeby dzialalo jeszcze szybciej
            //ExtraFunctions.WaitTime(10);

            usedCards.AddPlayed(playedCard);
            usedCards.SortLow();
            return(playedCard);
        }
Exemplo n.º 15
0
 public AlgorithmAttribute(AlgorithmTypes algorithmtype)
 {
     AlgorithmType = algorithmtype;
 }
 public MyAttribute(AlgorithmTypes algorithm = AlgorithmTypes.None)
 {
     AlgorithmType = algorithm;
 }
 public bool IsValidAlgorithm(string algorithmType)
 {
     return(AlgorithmTypes.Contains(algorithmType));
 }