Exemple #1
0
        internal void Update(IMedium med)
        {
            if (med.Id != UUID)
            {
                return;
            }
            //AllowedTypes = med.AllowedTypes.Cast<MediumType>().ToArray();
            Description  = med.Description;
            DeviceType   = med.DeviceType;
            Differencing = med.Parent != null;
            HasChildren  = med.Children != null && med.Children.Length > 0;
            Format       = med.Format;
            Location     = med.Location;
            Variant      = med.Variant.Cast <MediumVariant>().Aggregate((cur, next) => cur | next);
            VirtualSize  = med.LogicalSize;
            Name         = med.Name;
            ReadOnly     = med.ReadOnly != 0;
            Size         = med.Size;
            State        = med.State;
            MediumType   = med.Type;
            string cypher = null;

            try { med.GetEncryptionSettings(out cypher); } catch { }
            EncryptionKey = cypher;
            AttachedToIds = med.MachineIds.Cast <string>().ToArray();
            AttachedTo    = string.Join(", ", Client.VBox.Machines.Cast <IMachine>().Where(m => AttachedToIds.Any(id => string.Equals(m.Id, id, StringComparison.Ordinal))).Select(m => m.Name));
            //med.MediumFormat.DescribeProperties(out Array pNames, out Array pDesc, out Array pTypes, out Array pFlags, out Array pDef);
            var props = med.GetProperties(null, out var retNames);

            Properties.Clear();
            for (var i = 0; i < retNames.Length; i++)
            {
                Properties.Add(retNames.GetValue(i)?.ToString(), props.GetValue(i)?.ToString());
            }
        }
Exemple #2
0
 protected Light(LightType type, Transform lightToWorld, IMedium mediumInterface, int nSamples = 1)
 {
     Type            = type;
     LightToWorld    = lightToWorld;
     MediumInterface = mediumInterface;
     WorldToLight    = Transform.Invert(lightToWorld);
     NSamples        = System.Math.Max(1, nSamples);
 }
Exemple #3
0
 public SpotLight(Transform lightToWorld, IMedium m, Spectrum I, float totalWidth, float falloffStart)
     : base(LightType.DeltaDirection, lightToWorld, m)
 {
     _I               = I;
     _pLight          = lightToWorld * Point.Zero;
     _cosTotalWidth   = Cos(Rad(totalWidth));
     _cosFalloffStart = Cos(Rad(falloffStart));
 }
 public MediamReattachInfo(IMachine m, IMedium med, IMediumAttachment att)
 {
     MachineId      = m.Id;
     MediumId       = med.Id;
     ControllerName = att.Controller;
     ContollerPort  = att.Port;
     DeviceSlot     = att.Device;
     DeviceType     = med.DeviceType;
 }
 internal bool MergeToBase(string vm, ref string uuid, ref IMedium baseMedium)
 {
     Logger.Info("In MergeToBase");
     try
     {
         this.InternalOpenMachine(vm);
         string controllerName = (string)null;
         IMediumAttachment[] mediumAttachments = this.GetMediumAttachments(ref controllerName);
         int     aControllerPort = 0;
         int     aDevice         = 0;
         IMedium medium1         = (IMedium)null;
         foreach (IMediumAttachment mediumAttachment in mediumAttachments)
         {
             Logger.Info("Attached mediums are " + mediumAttachment.Medium.Name + " " + mediumAttachment.Type.ToString());
             if (mediumAttachment.Medium.Name.Contains("Data"))
             {
                 IMedium medium2 = mediumAttachment.Medium;
                 medium1    = this.GetTargetMedium(medium2);
                 baseMedium = medium1;
                 Logger.Info("Found TargetMedium is =" + medium1.Name);
                 if (medium1 == medium2)
                 {
                     Logger.Info("Disk not having a parent tree so need of merging");
                     DiskCompactionHelper.mInstance.InternalCloseMachine();
                     return(true);
                 }
                 aControllerPort = mediumAttachment.Port;
                 aDevice         = mediumAttachment.Device;
                 this.Machine.DetachDevice(controllerName, aControllerPort, aDevice);
                 this.Machine.SaveSettings();
                 this.InternalCloseMachine();
                 Utils.GetVmIdFromVmName(vm);
                 IProgress progress = medium2.MergeTo(medium1);
                 double    num      = 5.0;
                 while (progress.Completed == 0)
                 {
                     Thread.Sleep(200);
                     this.ParentWindow.UpdateProgress(num + (double)(progress.Percent / 10U));
                     Logger.Debug(string.Format("Merging : {0}%", (object)progress.Percent));
                 }
                 uuid = medium1.Id;
                 break;
             }
         }
         DiskCompactionHelper.mInstance.InternalOpenMachine(vm);
         this.Machine.AttachDevice(controllerName, aControllerPort, aDevice, DeviceType.DeviceType_HardDisk, medium1);
         this.Machine.SaveSettings();
         this.InternalCloseMachine();
         return(true);
     }
     catch (Exception ex)
     {
         Logger.Error("Error in merging disk err:" + ex.ToString());
     }
     return(false);
 }
 public SyntaxRecursiveParser(
     bool shouldIgnoreUndefinedTokens,
     int undefinedTokenClassId,
     IMedium axiom
 )
 {
     this.shouldIgnoreUndefinedTokens = shouldIgnoreUndefinedTokens;
     this.undefinedTokenClassId = undefinedTokenClassId;
     this.axiom = axiom;
 }
Exemple #7
0
            /// <summary>
            /// Removes the given item from the collection
            /// </summary>
            /// <returns>True, if the item was removed, otherwise False</returns>
            /// <param name="item">The item that should be removed</param>
            public override bool Remove(IModelElement item)
            {
                IUserAttribute userAttributeItem = item.As <IUserAttribute>();

                if (((userAttributeItem != null) &&
                     this._parent.AssetProperites.Remove(userAttributeItem)))
                {
                    return(true);
                }
                IReliabilityInfo reliabilityInfoItem = item.As <IReliabilityInfo>();

                if (((reliabilityInfoItem != null) &&
                     this._parent.ReliabilityInfos.Remove(reliabilityInfoItem)))
                {
                    return(true);
                }
                if (((userAttributeItem != null) &&
                     this._parent.Ratings.Remove(userAttributeItem)))
                {
                    return(true);
                }
                IQualificationRequirement qualificationRequirementItem = item.As <IQualificationRequirement>();

                if (((qualificationRequirementItem != null) &&
                     this._parent.QualificationRequirements.Remove(qualificationRequirementItem)))
                {
                    return(true);
                }
                IAssetPropertyCurve assetPropertyCurveItem = item.As <IAssetPropertyCurve>();

                if (((assetPropertyCurveItem != null) &&
                     this._parent.AssetPropertyCurves.Remove(assetPropertyCurveItem)))
                {
                    return(true);
                }
                IDimensionsInfo dimensionsInfoItem = item.As <IDimensionsInfo>();

                if (((dimensionsInfoItem != null) &&
                     this._parent.DimensionsInfos.Remove(dimensionsInfoItem)))
                {
                    return(true);
                }
                IMedium mediumItem = item.As <IMedium>();

                if (((mediumItem != null) &&
                     this._parent.Mediums.Remove(mediumItem)))
                {
                    return(true);
                }
                return(false);
            }
 public static void Reattach(IMedium vdi, Stack <MediamReattachInfo> att)
 {
     while (att.Count > 0)
     {
         var i       = att.Pop();
         var machine = Client.VBox.FindMachine(i.MachineId);
         if (machine == null)
         {
             continue;
         }
         using (var ml = new MachineLock(machine))
             ml.Raw.AttachDevice(i.ControllerName, i.ContollerPort, i.DeviceSlot, i.DeviceType, vdi);
     }
 }
Exemple #9
0
        /// <summary>
        /// Creates states for token.
        /// </summary>
        /// <remarks>
        /// Loops are gathered in reference list.
        /// Parsed nodes are gathered in parsed nodes list.
        /// When all the branches hit bottom or reached loop point
        /// - resolves loops by duplicating first links from parsed
        /// nodes in place of loop point.
        /// </remarks>
        /// <param name="token">Token to be processed.</param>
        /// <param name="states">List of all states created so far.</param>
        /// <param name="rootState">Parent state of all states a.k.a. 0th state.</param>
        private void CreateStatesForToken(IMedium token, List <FiniteState> states, FiniteState rootState)
        {
            // If there is a recursive case then the token cannot be converted
            // in to finite automaton.
            if (token.Recursion != null)
            {
                throw new Exception($"Finit automaton cannot be built on left-recursive token. " +
                                    $"{token}::={(IFactor)token}");
            }

            // List of looped references
            var references = new List <(int stateId, IMedium referencedNode)>();

            // List of parsed nodes and their nextStates
            // Value is a list of links gotten while parsing the node.
            // For example:
            // after parsing a node we got next states:
            // a->state1
            // b->state2
            // c->state3
            // d->state4
            // but part of them were already there from the root state
            // and part were created from processing the node.
            // Assuming that a and b links are related to the node,
            // they will be saved as a list of links for this node.
            // Hence, they will be used to resolve loop points.
            var parsedNodes = new Dictionary <IMedium, NextFiniteStates>();

            parsedNodes[token] = CreateFiniteStatesForTokenFromFactor(token, token, states, rootState, references, parsedNodes, token as IDefinedToken);


            // Now get rid of references
            foreach ((int stateId, IMedium referencedNode) in references)
            {
                // We duplicate nextStates of nodes referenced.
                var nextStatesToInsert = parsedNodes[referencedNode].ToDictionary(n => n.Key, n => n.Value);

                // Try insert next states.
                foreach (var newNext in nextStatesToInsert)
                {
                    if (states[stateId].Links.ContainsKey(newNext.Key))
                    {
                        throw new Exception($"Looped state {stateId} already defines transition with given key {newNext.Key}.");
                    }

                    states[stateId].Links[newNext.Key] = newNext.Value;
                }
            }
        }
Exemple #10
0
        public DiffuseAreaLight(Transform lightToWorld,
                                IMedium mediumInterface,
                                Spectrum Lemit,
                                int nSamples,
                                IShape shape,
                                bool twoSided = false)
            : base(lightToWorld, mediumInterface, nSamples)
        {
            _mediumInterface = mediumInterface;
            _lemit           = Lemit;
            _shape           = shape;
            _twoSided        = twoSided;
            _area            = shape.Area();

            // TODO: Check for scale
        }
Exemple #11
0
        public static Stack <MediamReattachInfo> Detach(IMedium vdi)
        {
            var attInfo = new Stack <MediamReattachInfo>();

            foreach (var machine in Client.VBox.Machines.Cast <IMachine>().Where(m => vdi.MachineIds.Cast <string>().Any(id => string.Equals(m.Id, id, StringComparison.Ordinal))))
            {
                var medAtt = machine.MediumAttachments.Cast <IMediumAttachment>().FirstOrDefault(ma => ma.Medium?.Id == vdi.Id);
                if (medAtt == null)
                {
                    throw new ArgumentException(nameof(vdi));
                }
                attInfo.Push(new MediamReattachInfo(machine, vdi, medAtt));
                using (var ml = new MachineLock(machine))
                    ml.Raw.DetachDevice(medAtt.Controller, medAtt.Port, medAtt.Device);
            }
            return(attInfo);
        }
Exemple #12
0
            /// <summary>
            /// Adds the given element to the collection
            /// </summary>
            /// <param name="item">The item to add</param>
            public override void Add(IModelElement item)
            {
                IUserAttribute assetProperitesCasted = item.As <IUserAttribute>();

                if ((assetProperitesCasted != null))
                {
                    this._parent.AssetProperites.Add(assetProperitesCasted);
                }
                IReliabilityInfo reliabilityInfosCasted = item.As <IReliabilityInfo>();

                if ((reliabilityInfosCasted != null))
                {
                    this._parent.ReliabilityInfos.Add(reliabilityInfosCasted);
                }
                IUserAttribute ratingsCasted = item.As <IUserAttribute>();

                if ((ratingsCasted != null))
                {
                    this._parent.Ratings.Add(ratingsCasted);
                }
                IQualificationRequirement qualificationRequirementsCasted = item.As <IQualificationRequirement>();

                if ((qualificationRequirementsCasted != null))
                {
                    this._parent.QualificationRequirements.Add(qualificationRequirementsCasted);
                }
                IAssetPropertyCurve assetPropertyCurvesCasted = item.As <IAssetPropertyCurve>();

                if ((assetPropertyCurvesCasted != null))
                {
                    this._parent.AssetPropertyCurves.Add(assetPropertyCurvesCasted);
                }
                IDimensionsInfo dimensionsInfosCasted = item.As <IDimensionsInfo>();

                if ((dimensionsInfosCasted != null))
                {
                    this._parent.DimensionsInfos.Add(dimensionsInfosCasted);
                }
                IMedium mediumsCasted = item.As <IMedium>();

                if ((mediumsCasted != null))
                {
                    this._parent.Mediums.Add(mediumsCasted);
                }
            }
        internal int MergeAndCompact()
        {
            if (!this.Init())
            {
                return(-4);
            }
            string uuid = (string)null;
            string str  = "Android";

            if (!string.IsNullOrEmpty(App.sOpt.vmname))
            {
                str = App.sOpt.vmname;
            }
            if (!((IEnumerable <string>)RegistryManager.Instance.VmList).Contains <string>(str))
            {
                return(-9);
            }
            IMedium baseMedium = (IMedium)null;

            if (!this.MergeToBase(str, ref uuid, ref baseMedium))
            {
                return(-5);
            }
            string name = baseMedium.Name;

            this.ParentWindow.UpdateProgress(18.0);
            Utils.StartHiddenFrontend(str, "bgp");
            if (!Utils.WaitForBootComplete(str, "bgp"))
            {
                return(-6);
            }
            this.ParentWindow.UpdateProgress(25.0);
            if (!this.FreeDiskSpace(str))
            {
                return(-7);
            }
            Utils.StopFrontend(str, true);
            Thread.Sleep(2000);
            this.ParentWindow.UpdateProgress(98.0);
            return(!this.CompactMedium(name, str, true) ? -8 : 0);
        }
Exemple #14
0
        public static void Main(string[] args)
        {
            var producer = new Subject<IMedium>();
            producer.Subscribe(x => Console.WriteLine($"received value {x.Title}"));
            producer.Subscribe(x => Console.WriteLine($"received value {x.CurrentValue}"));

            var imediums = new IMedium[]
            {
                new Videogame("Stick of Truth", "PS3",40,"South Park PRG","Viedeogame"),
                new Videogame("Golden Sun", "GameBoy", 20, "Fantasy RPG","Viedeogame"),
                new MusikCD("Heroes","Sabaton",40,"Limited Edition Earbook","Musik CD", "Heavy Metal"),
                new MusikCD("Bigger, Better, Faster, More!","4 non Blondes", 15, "Album 1992", "Musik CD", "Alternative-Rock"),
            };
            var videogames = new []
            {
                new Videogame("Super Mario Galaxy", "Nintendo Wii", 40, "Jump and Run Game", "Viedeogame"),
                new Videogame("Lemmings", "Super Nintendo", 35, "Help the Lemmings find their way!", "Viedeogame"),
                new Videogame("Worms","PC",20, "Worms against other Worms, Strategy Game", "Viedeogame"),
                new Videogame("Pokemon","GameBoy", 25, "Catch em all!", "Viedeogame"),
                new Videogame("Halo","Xbox",30, "First person shooter", "Viedeogame"),
            };

            var musicCDs = new[]
            {
                new MusikCD("Live Licks","The Rolling Stones", 20, "Live Album 2004", "Musik CD", "Classic Rock"),
                new MusikCD("Drunken Lullabies","Flogging Molly",15, "Studio Album 2002", "Musik CD", "Irish Folk"),
                new MusikCD("Live After Death","Iron Maiden",17,"Live Album 1985", "Musik CD","Heavy Metal"),
                new MusikCD("Back in Black","AC/DC",15,"Studio Album 1980","Musik CD","Hard Rock"),
            };

            Console.WriteLine();
            foreach (var b in imediums)
            {
                Console.WriteLine("{0,-20}{1,-40}{2,8:0.00} EUR", b.MediumType, b.Title, b.CurrentValue);
            }

            Console.WriteLine();
            Console.WriteLine ("Games in Library: " + Videogame.GameCount);
            Console.WriteLine();

            foreach (var b in videogames)
            {
                Console.WriteLine("{0,-40} {1,-40} {2,8:0.00} EUR", b.Title, b.Platform, b.CurrentValue);

            }

            Console.WriteLine();

            foreach (var b in musicCDs)
            {
                Console.WriteLine("{0,-20} {1,-20} {2, -20} {3,-20} {4,8:0.00} EUR", b.Title, b.Interpret, b.Description, b.Genre, b.CurrentValue);
            }

            foreach (var b in videogames) {
                if (b.Platform == "PC") {
                    b.CurrentValue = b.CurrentValue + 5;
                }
            }

            Console.WriteLine ();

            foreach (var b in videogames)
            {
                Console.WriteLine("{0,-40} {1,-40} {2,8:0.00} EUR {3,8:0.00}", b.Title, b.Platform, b.CurrentValue,b.getValueFactor());

            }

            var json = serializer(videogames);
            using (var sw = new StreamWriter(new FileStream("test.json", FileMode.Create)))
            {
                sw.Write(json);
            }

            // using (var sr = new StreamReader(new FileStream("test.json", FileMode.Open)))
            var fs = new FileStream("test.json", FileMode.Open);
            var sr = new StreamReader(fs);

                string filetext = sr.ReadToEnd();

            var objectarray = deserializer(filetext);

            sr.Close();
            fs.Close();

            Console.WriteLine(filetext);
            Console.WriteLine();

            foreach (var i in videogames)
            {
                producer.OnNext(i); // push value i to subscribers
            }

            var ValuableMedia = imediums
                .AsParallel()
                .Where(x => x.CurrentValue > 20)
                .Select(x => "Wertvolles Medium: " + x.Title)
                ;

            Console.WriteLine();
            foreach (var x in ValuableMedia)
            {
                Console.WriteLine("{0}", x);
            }

            var FirstCDs = musicCDs
                .AsParallel()
                .Take(3)
                ;
            Console.WriteLine();

            foreach (var x in FirstCDs)
            {
                Console.WriteLine("Titel: {0}", x.Title);
            }

            TasksExample.Run(videogames);
        }
Exemple #15
0
 /// <summary>
 /// Creates finite automaton states for tokens.
 /// </summary>
 /// <remarks>
 /// Also addes token terminal symbols to separate classes.
 /// </remarks>
 /// <param name="node">Node to which factor belongs.</param>
 /// <param name="factor">Factor to be processed.</param>
 /// <param name="states">List of all states.</param>
 /// <param name="currentState">State to which links will be added.</param>
 /// <param name="references">List of loop points that refer to one of parsed nodes.</param>
 /// <param name="parsedNodes">List of nodes which have been processed.</param>
 /// <param name="tokenName">Token name.</param>
 /// <returns>List of links.</returns>
 private Dictionary <string, int> CreateFiniteStatesForTokenFromFactor(
     IMedium node,
     IFactor factor,
     List <FiniteState> states,
     FiniteState currentState,
     List <(int stateId, IMedium referencedNode)> references,
Exemple #16
0
 public PointLight(Transform lightToWorld, IMedium m, Spectrum i)
     : base(LightType.DeltaPosition, lightToWorld, m)
 {
     I       = i;
     _pLight = lightToWorld * Point.Zero;
 }
Exemple #17
0
 internal DiskInfo(IMedium med)
 {
     UUID = med.Id;
     Update(med);
 }
Exemple #18
0
 /// <summary>
 /// Creates a new observable property access proxy
 /// </summary>
 /// <param name="modelElement">The model instance element for which to create the property access proxy</param>
 public KindProxy(IMedium modelElement) :
     base(modelElement, "kind")
 {
 }
Exemple #19
0
        private void EmptyHardDisk(Session vmSession)
        {
            IProgress          progress;
            IStorageController controller = null;
            uint    inst;
            IMedium rosHdd = null;
            int     dev = 0, port;
            Boolean HddFound = false;

            /* Go through storage controllers to find IDE/SATA one */
            for (inst = 0; inst < 4; inst++)
            {
                try
                {
                    controller = rosVM.GetStorageControllerByInstance(inst);
                    if (controller.Bus == StorageBus.StorageBus_IDE ||
                        controller.Bus == StorageBus.StorageBus_SATA)
                    {
                        break;
                    }
                }
                catch (Exception exc)
                {
                    /* Just skip it */
                }
            }

            /* Now check what HDD we have connected to this controller */
            for (port = 0; port < controller.MaxPortCount; port++)
            {
                for (dev = 0; dev < controller.MaxDevicesPerPortCount; dev++)
                {
                    try
                    {
                        rosHdd = rosVM.GetMedium(controller.Name, port, dev);
                        if (rosHdd.DeviceType == DeviceType.DeviceType_HardDisk)
                        {
                            /* We found the one and only harddisk */
                            HddFound = true;
                            break;
                        }
                        rosHdd.Close();
                    }
                    catch (Exception exc)
                    {
                        /* Just skip it */
                    }
                }

                if (HddFound)
                {
                    break;
                }
            }

            /* Delete the existing hdd */
            if (HddFound)
            {
                try
                {
                    controller = rosVM.GetStorageControllerByInstance(inst);
                    vmSession.Machine.DetachDevice(controller.Name, port, dev);
                    vmSession.Machine.SaveSettings();

                    progress = rosHdd.DeleteStorage();
                    progress.WaitForCompletion(-1);
                    rosHdd.Close();
                }
                catch (Exception exc)
                {
                    Console.WriteLine("Could not delete existing HDD:" + exc);
                }
            }
            else
            {
                /* Connect to port 0, device 0 if there was no hdd found */
                port = 0;
                dev  = 0;
            }

            /* Create a new one */
            CreateHardDisk(vmSession, controller, port, dev);
        }
Exemple #20
0
 protected AreaLight(Transform lightToWorld, IMedium mediumInterface, int nSamples = 1) : base(
         LightType.Area, lightToWorld, mediumInterface, nSamples)
 {
 }
        private IMedium GetTargetMedium(IMedium medium)
        {
            IMedium parent = medium.Parent;

            return(((IEnumerable <IMedium>)parent.Children).Count <IMedium>() > 1 || ((IEnumerable <IMedium>)parent.Children).Count <IMedium>() == 1 && parent.Name == "Data.vdi" ? medium : this.GetTargetMedium(parent));
        }