Exemplo n.º 1
0
        private void CheckPosition(int x, int y, ComponentAction action, Action onNoMatch = null)
        {
            if (this.components.Count == 0)
            {
                return;
            }

            for (int i = 0; i < 3; i++)
            {
                if (this.components[i].containsPoint(x, y))
                {
                    action(null, i);
                    return;
                }
            }
            for (int i = 3; i < this.components.Count; i++)
            {
                if (this.components[i].containsPoint(x, y))
                {
                    action(this.statuses[(i - 3) / UpdateMenu.sections.Length], i % UpdateMenu.sections.Length);
                    return;
                }
            }

            onNoMatch?.Invoke();
        }
Exemplo n.º 2
0
 public Component()
 {
     codeField       = new Code();
     dependencyField = new ObservableCollection <Dependency>();
     parameterField  = new ObservableCollection <Parameter>();
     actionField     = ComponentAction.None;
     languageField   = Language.csharp;
 }
Exemplo n.º 3
0
    /// <summary>
    /// Call a function on a component if it exists. Useful for one-off components that won't need to be reused.
    /// </summary>
    /// <param name="action">The function to be called.</param>
    /// <typeparam name="T">The type of component to call on.</typeparam>
    /// <returns>Whether or not the component exists.</returns>
    public static bool GetComponentCallbackOrIgnore <T>(this GameObject gameObject, ComponentAction <T> action) where T : Component
    {
        var component = gameObject.GetComponent <T>();

        if (component == null)
        {
            return(false);
        }

        action(component);
        return(true);
    }
 protected void PrintReturnCode(InstallResult result, IComponent package, ComponentAction executeAction)
 {
     if (result.IsFailure())
     {
         var installResultDetails = GetInstallResultDetails(result, package, executeAction.ToString().ToLowerInvariant());
         LogFailure(package, executeAction, installResultDetails);
     }
     else
     {
         var text = "Result: " + result;
         Logger.Trace("Package executed successfully. {0}", text);
     }
 }
Exemplo n.º 5
0
        private bool DownloadRequired(ComponentAction action, IComponent component)
        {
            if (action != ComponentAction.Update)
            {
                return(false);
            }

            if (component.CurrentState == CurrentState.Downloaded && ComponentDownloadPathStorage.Instance.TryGetValue(component, out _))
            {
                return(false);
            }


            return(true);
        }
        public async Task VersionHigher()
        {
            var dependency = new Dependency();

            dependency.Name        = "FocLauncher.dll";
            dependency.Version     = "2.0.0.0";
            dependency.Destination = ApplicationBasePath;
            dependency.Origin      = "https://example.com";

            var component = CatalogExtensions.DependencyToComponent(dependency);

            const ComponentAction expected = ComponentAction.Update;
            await _updateManager.CalculateComponentStatusAsync(component);

            Assert.AreEqual(expected, component.RequiredAction);
        }
        public async Task VersionNotSpecifiedShaNotEqual()
        {
            var dependency = new Dependency();

            dependency.Name        = "FocLauncher.dll";
            dependency.Destination = ApplicationBasePath;
            dependency.Sha2        = UpdaterUtilities.HexToArray("d32b568cd1b96d459e7291ebf4b25d007f275c9f13149beeb782fac0716613f8");
            dependency.Origin      = "https://example.com";

            var component = CatalogExtensions.DependencyToComponent(dependency);

            const ComponentAction expected = ComponentAction.Update;
            await _updateManager.CalculateComponentStatusAsync(component);

            Assert.AreEqual(expected, component.RequiredAction);
        }
        public async Task VersionEqualShaEqual()
        {
            var dependency = new Dependency();

            dependency.Name        = "FocLauncher.dll";
            dependency.Version     = "1.0.0.0";
            dependency.Destination = ApplicationBasePath;
            dependency.Sha2        = UpdaterUtilities.GetFileHash(Path.Combine(ApplicationBasePath, dependency.Name), HashType.Sha256);
            dependency.Origin      = "https://example.com";

            var component = CatalogExtensions.DependencyToComponent(dependency);

            const ComponentAction expected = ComponentAction.Keep;
            await _updateManager.CalculateComponentStatusAsync(component);

            Assert.AreEqual(expected, component.RequiredAction);
        }
        public static string ComponentActionToString(ComponentAction _action)
        {
            switch (_action)
            {
            case ComponentAction.CREATE:
                return("CREATE");

            case ComponentAction.DELETE:
                return("DELETE");

            case ComponentAction.UPDATE:
                return("UPDATE");

            default:
                return("NONE");
            }
        }
Exemplo n.º 10
0
 public ComponentActionAdapter(ComponentAction target)
 {
     _target = target;
 }
Exemplo n.º 11
0
        private PackageActivities CreateDownloadInstallActivities(IComponent component, ComponentAction action, bool isPresent)
        {
            ComponentDownloadTask downloadComponent;
            ComponentInstallTask  install;

            if (DownloadRequired(action, component))
            {
                downloadComponent           = new ComponentDownloadTask(component);
                downloadComponent.Canceled += (_, __) => _linkedCancellationTokenSource?.Cancel();
                install = new ComponentInstallTask(component, action, downloadComponent, isPresent);
            }
            else
            {
                downloadComponent = null;
                install           = new ComponentInstallTask(component, action, isPresent);
            }

            return(new PackageActivities
            {
                Download = downloadComponent,
                Install = install
            });
        }
 private static void LogFailure(IComponent package, ComponentAction executeAction, string details)
 {
     Logger.Error(package != null
         ? $"Package '{package.Name}' failed to {executeAction.ToString().ToLowerInvariant()}. {details}"
         : $"Failed to {executeAction.ToString().ToLowerInvariant()}. {details}");
 }
Exemplo n.º 13
0
        public static void TranslateIntoComponents(List <ComponentMessage> _messages, ComponentFactory _comp_factory,
                                                   out List <ParameterStructure.Component.Component> new_comps_created)
        {
            new_comps_created = new List <ParameterStructure.Component.Component>();
            if (_messages == null)
            {
                return;
            }
            if (_messages.Count == 0)
            {
                return;
            }
            if (_comp_factory == null)
            {
                return;
            }

            // 1. Modify the components
            Dictionary <Component, ComponentAction> updated = new Dictionary <Component, ComponentAction>();

            foreach (ComponentMessage msg in _messages)
            {
                ParameterStructure.Component.Component comp = null;
                ComponentAction action_to_take = ComponentAction.NONE;
                if (msg.CompID > -1)
                {
                    // handling of existing components
                    comp           = _comp_factory.GetByID(msg.CompID);
                    action_to_take = (msg.ActionToTake == MessageAction.DELETE) ? ComponentAction.DELETE : ComponentAction.UPDATE;
                }
                else
                {
                    Debug.WriteLine("CB: creating new component from {0}", msg.CompDescr);
                    // create a new component (adds it to the top level of the component record of the Factory)
                    // NOTE: should happen only for components describing a space
                    comp = _comp_factory.CreateEmptyComponent(false);
                    new_comps_created.Add(comp);
                    ////comp.Name = GeometryUtils.Relationship2GeometryToCompNameDE(msg.GeomType);
                    comp.Name        = msg.CompDescr;
                    comp.Description = "Representation";
                    action_to_take   = ComponentAction.CREATE;
                }
                if (comp != null)
                {
                    Debug.WriteLine("CB: calling 'UpdateComponentFromMessage' with {0} for {1}", action_to_take, msg.CompDescr);
                    ComponentMessageTranslator.UpdateComponentFromMessage(comp, msg, _comp_factory.Caller, true);
                    _comp_factory.UpdateConnectivity(comp); // for Relation2Geometry Type CONTAINED_IN -> propagates realization
                    if (!(updated.ContainsKey(comp)))
                    {
                        updated.Add(comp, action_to_take);
                    }
                }
            }

            // 2. Adjust the relationships btw the components
            // NOTE: includes deletion of all automatically generated sub-components and
            // replacing them with the new automatically created components

            List <long> parent_ids = new List <long>();

            foreach (ComponentMessage msg in _messages)
            {
                if (msg.CompParentID < 0 && msg.CompRepParentID > -1)
                {
                    // the parent was just generated...
                    int  index         = _messages.FindIndex(x => x.CompRepID == msg.CompRepParentID);
                    long new_parent_id = updated.ElementAt(index).Key.ID;
                    parent_ids.Add(new_parent_id);
                }
                else
                {
                    // the parent existed already before the call to this method OR
                    // there is no parent
                    parent_ids.Add(msg.CompParentID);
                }
            }

            List <List <long> > ref_comp_ids = _messages.Select(x => new List <long>(x.CompRefIds)).ToList();

            // happens independent of the current user (references have a higher priority than writing access)
            _comp_factory.AdjustSubAndRefComponentDependenciesAfterAutomaticGeneration(updated, parent_ids, ref_comp_ids);
        }
 public ComponentInstallTask(IComponent component, ComponentAction action, bool isPresent = false)
 {
     Component  = component ?? throw new ArgumentNullException(nameof(component));
     Action     = action;
     _isPresent = isPresent;
 }
 public ComponentInstallTask(IComponent component, ComponentAction action, ComponentDownloadTask download, bool isPresent = false) :
     this(component, action, isPresent)
 {
     _download = download;
 }