Esempio n. 1
0
 private void OnFossilFuelChanged(FossilFuel fuel)
 {
     if (FossilFuelChanged != null)
     {
         FossilFuelChanged(this, new FossilFuelChangedEventArgs(fuel, false));
     }
 }
Esempio n. 2
0
 public FossilFuelCache(FossilFuel fossilFuel)
     : base()
 {
     this.fossilFuel     = fossilFuel;
     this.name           = fossilFuel.Name;
     this.fossilFuelType = fossilFuel.FossilFuelType;
 }
Esempio n. 3
0
 private void OnFossilFuelAdded(FossilFuel fuel)
 {
     if (FossilFuelAdded != null)
     {
         FossilFuelAdded(fuel);
     }
 }
Esempio n. 4
0
        private string GetUniqueName()
        {
            int        newIndex = 0;
            FossilFuel fossilFuel;
            string     fuelName;
            int        index;
            string     suffix;
            IList      list = catalog.GetFossilFuelList();

            for (int i = 0; i < list.Count; i++)
            {
                fossilFuel = (FossilFuel)list[i];
                fuelName   = fossilFuel.Name;

                if (!fuelName.StartsWith("Fuel "))
                {
                    continue;
                }

                index  = "Fuel ".Length;
                suffix = fuelName.Substring(index);
                char[] chars = null;
                if (suffix != null)
                {
                    chars = suffix.ToCharArray();
                }
                bool suffixIsANumber = false;
                if (chars != null && chars.Length > 0)
                {
                    suffixIsANumber = true;
                    foreach (char c in chars)
                    {
                        if (!char.IsDigit(c))
                        {
                            suffixIsANumber = false;
                            break;
                        }
                    }
                }

                if (suffixIsANumber == true)
                {
                    try
                    {
                        index = Int32.Parse(suffix);
                        if (index > newIndex)
                        {
                            newIndex = index;
                        }
                    }
                    catch (FormatException e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }
            }

            return("Fuel " + (newIndex + 1));
        }
Esempio n. 5
0
 public void RemoveFossilFuel(FossilFuel fuel)
 {
     if (fuel.IsUserDefined)
     {
         string name = fuel.Name;
         fossilFuelList.Remove(fuel);
         OnFossilFuelDeleted(name);
     }
 }
Esempio n. 6
0
 public FossilFuelCache(FossilFuel fossilFuel, FossilFuelCatalog catalog)
     : base()
 {
     this.fossilFuel     = fossilFuel;
     this.name           = fossilFuel.Name;
     this.fossilFuelType = fossilFuel.FossilFuelType;
     this.fossilFuel     = fossilFuel;
     this.catalog        = catalog;
 }
Esempio n. 7
0
 public FossilFuelCache(FossilFuel fossilFuel, FossilFuelCatalog catalog)
     : base()
 {
     this.fossilFuel            = fossilFuel;
     this.name                  = fossilFuel.Name;
     this.fossilFuelType        = fossilFuel.FossilFuelType;
     this.fossilFuel            = fossilFuel;
     this.catalog               = catalog;
     this.materialComponentList = fossilFuel.ComponentList;
 }
Esempio n. 8
0
        public FossilFuel GetFossilFuel(string name)
        {
            FossilFuel ret = null;

            foreach (FossilFuel fuel in fossilFuelList)
            {
                if (fuel.Name.Equals(name))
                {
                    ret = fuel;
                    break;
                }
            }
            return(ret);
        }
Esempio n. 9
0
        public bool IsInCatalog(FossilFuel fuel)
        {
            bool isInCatalog = false;

            foreach (FossilFuel f in fossilFuelList)
            {
                if (f.Name.Equals(fuel.Name))
                {
                    isInCatalog = true;
                    break;
                }
            }

            return(isInCatalog);
        }
Esempio n. 10
0
        public ErrorMessage UpdateFossilFuel(FossilFuel fuel)
        {
            ErrorMessage retMsg = null;

            if (IsInCatalog(fuel))
            {
                OnFossilFuelChanged(fuel);
            }
            else
            {
                retMsg = new ErrorMessage(ErrorType.SimpleGeneric, StringConstants.INAPPROPRIATE_SPECIFIED_VALUE, "There is already in the material catalog a material called " + fuel.Name);
            }

            return(retMsg);
        }
Esempio n. 11
0
        public ErrorMessage AddFossilFule(FossilFuel fuel)
        {
            ErrorMessage retMsg = null;

            if (!IsInCatalog(fuel))
            {
                fossilFuelList.Add(fuel);
                OnFossilFuelAdded(fuel);
            }
            else
            {
                retMsg = new ErrorMessage(ErrorType.SimpleGeneric, StringConstants.INAPPROPRIATE_SPECIFIED_VALUE, "There is already in the fuel catalog a fuel called " + fuel.Name);
            }
            return(retMsg);
        }
Esempio n. 12
0
        public override ErrorMessage FinishSpecifications(string fuelName, bool isNew)
        {
            ErrorMessage errorMsg = null;

            if (materialComponentList.Count < 1)
            {
                string msg = "The specified fuel contains no component.";
                errorMsg = new ErrorMessage(ErrorType.SimpleGeneric, "Inappropriate Specification", msg);
            }
            else
            {
                DoNormalization();

                if (isNew)
                {
                    if (catalog.IsInCatalog(fuelName))
                    {
                        errorMsg = new ErrorMessage(ErrorType.SimpleGeneric, StringConstants.INAPPROPRIATE_SPECIFIED_VALUE, "There is already in the catalog a fuel called " + fuelName);
                    }
                    else
                    {
                        fossilFuel = new FossilFuel(fuelName, materialComponentList, fossilFuelType, true);
                        errorMsg   = catalog.AddFossilFule(fossilFuel);
                    }
                }
                else
                {
                    if (!fuelName.Equals(fossilFuel.Name) && catalog.GetFossilFuel(fuelName) != null)
                    {
                        errorMsg = new ErrorMessage(ErrorType.SimpleGeneric, StringConstants.INAPPROPRIATE_SPECIFIED_VALUE, "There is already in the catalog a fuel called " + fuelName);
                    }
                    else
                    {
                        try
                        {
                            fossilFuel.Update(fuelName, materialComponentList);
                            errorMsg = catalog.UpdateFossilFuel(fossilFuel);
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
            }

            return(errorMsg);
        }
Esempio n. 13
0
        public override bool Equals(object obj)
        {
            FossilFuel ff      = obj as FossilFuel;
            bool       isEqual = false;

            if (ff != null && this.Name == ff.Name && this.ComponentList.Count == ff.ComponentList.Count)
            {
                bool isMaterialComponentEqual = true;
                for (int i = 0; i < this.ComponentList.Count; i++)
                {
                    MaterialComponent thisMC = this.ComponentList[i] as MaterialComponent;
                    MaterialComponent thatMC = ff.ComponentList[i] as MaterialComponent;
                    if (thisMC.Substance != thatMC.Substance || Math.Abs(thisMC.MassFraction.Value - thatMC.MassFraction.Value) > 1.0e-4)
                    {
                        isMaterialComponentEqual = false;
                        break;
                    }
                }
                isEqual = isMaterialComponentEqual;
            }
            return(isEqual);
        }
Esempio n. 14
0
 public FossilFuelChangedEventArgs(FossilFuel fossilFuel, bool isNameChangeOnly)
 {
     this.fossilFuel       = fossilFuel;
     this.isNameChangeOnly = isNameChangeOnly;
 }