Пример #1
0
        public void AddDataInputs()
        {
            var sut = new DataInputCollection
            {
                new DataInput("a"), "b"
            };

            sut.Count.Should().Be(3);
        }
Пример #2
0
        /// <summary>
        /// Compila el archivo
        /// </summary>
        /// <param name="inputs">Colección de entradas</param>
        /// <param name="pathForEnvironmentVariable">Ruta para variable de entorno</param>
        public void Compile(DataInputCollection inputs, string pathForEnvironmentVariable)
        {
            // Cargar topología
            if (Items != null)
            {
                foreach (TopologyItem item in Items.Values)
                {
                    if (item.Item is IDataInput)
                    {
                        inputs.Add((IDataInput)item.Item);
                    }
                }

                if (Relations != null)
                {
                    foreach (Relation rel in Relations)
                    {
                        if (rel.From == rel.To)
                        {
                            continue;
                        }

                        TopologyItem from, to;
                        if (Items.TryGetValue(rel.From, out from) && Items.TryGetValue(rel.To, out to) && from != null && to != null)
                        {
                            if (to.Item is IDataProcess)
                            {
                                from.Item.Process.Add((IDataProcess)to.Item);
                            }
                        }
                    }
                }

                // Si los remplazo en diseño, ahora mismo se cambiarian en real, tendria que runearse una copia, y no el de edición
                RemplaceVariables(inputs, Variables, null);
            }

            LasterHelper.SetEnvironmentPath(pathForEnvironmentVariable);
        }
Пример #3
0
 public LasterService(DataInputCollection inputs)
 {
     this.inputs = inputs;
 }
Пример #4
0
        public void HaveDefault()
        {
            var sut = new DataInputCollection();

            sut["default"].Should().NotBeNull();
        }
Пример #5
0
        static void Main(string[] args)
        {
            Application.ThreadException += Application_ThreadException;
            // Error al cargar la libería
            ReflectionHelper.RedirectAssembly("Newtonsoft.Json", new Version(9, 0), "30ad4fe6b2a6aeed");

#if DEBUG
            if (Debugger.IsAttached)
            {
                //args = new string[] { "--edit", @"C:\Users\Fernando\Desktop\ejemplo.tly" };
                //args = new string[] { "--install",/* "--name=Laster",*/ @"C:\Users\Fernando\Desktop\ejemplo.tly" };
                //args = new string[] { "--service", @"C:\Users\Fernando\Desktop\ejemplo.tly" };
            }
#endif
            bool          isService = false, isEdit = false;
            List <string> cfgFiles = new List <string>();

            if (args != null && args.Length > 0)
            {
                string name    = "LasterService";
                int    install = 0;
                foreach (string arg in args)
                {
                    if (string.IsNullOrEmpty(arg))
                    {
                        continue;
                    }

                    if (!arg.StartsWith("--") && File.Exists(arg))
                    {
                        cfgFiles.Add(arg);
                    }
                    else
                    {
                        string iz, dr;
                        StringHelper.Split(arg, '=', out iz, out dr);

                        switch (iz)
                        {
                        case "--name": { name = dr.Trim(); break; }

                        case "--service": { isService = true; break; }

                        case "--edit": { isEdit = true; break; }

                        case "--install": { install = 1; break; }

                        case "--uninstall": { install = -1; break; }

                        default:
                        {
                            break;
                        }
                        }
                    }
                }

                if (install != 0)
                {
                    // Requiere acción de instalación
                    if (install == 1)
                    {
                        LasterServiceInstaller.Install(name, cfgFiles.ToArray());
                    }
                    else
                    {
                        LasterServiceInstaller.Uninstall(name);
                    }
                    return;
                }
            }

            bool efects = false;
            Application.OleRequired();
            DataInputCollection inputs = new DataInputCollection();

            // Leer el contenido del final del archivo para ver si contiene una configuración
            byte[] pack = new byte[8];
            using (FileStream fs = new FileStream(Application.ExecutablePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                fs.Seek(fs.Length - pack.Length, SeekOrigin.Begin);
                if (fs.Read(pack, 0, pack.Length) == pack.Length)
                {
                    if (Encoding.ASCII.GetString(pack, pack.Length - 4, 4) == "PACK")
                    {
                        // Sacar el tamaño
                        int l = BitConverter.ToInt32(pack, 0);
                        fs.Seek(fs.Length - pack.Length - l, SeekOrigin.Begin);

                        byte[] data = new byte[l];
                        if (fs.Read(data, 0, l) == l)
                        {
                            // Sacar el contenido
                            data = CompressHelper.Compress(data, 0, l, false);

                            string       json   = Encoding.UTF8.GetString(data);
                            PacketHeader header = SerializationHelper.DeserializeFromJson <PacketHeader>(json);
                            if (header != null)
                            {
                                header.Encrypt(false);

                                json = Encoding.UTF8.GetString(header.D);
                                if (isEdit)
                                {
                                    // Edición
                                    if (!efects)
                                    {
                                        Application.SetCompatibleTextRenderingDefault(true);
                                        Application.EnableVisualStyles();
                                        efects = true;
                                    }

                                    string pwd = FInputText.ShowForm("Edit", "Insert edit password", "", true);
                                    if (!string.IsNullOrEmpty(pwd))
                                    {
                                        byte[] hash = Encoding.UTF8.GetBytes(pwd);
                                        hash = HashHelper.HashRaw(HashHelper.EHashType.Sha512, hash, 0, hash.Length);

                                        for (int x = header.H.Length - 1; x >= 0; x--)
                                        {
                                            if (header.H[x] != hash[x])
                                            {
                                                return;
                                            }
                                        }

                                        cfgFiles.Add(json);
                                    }
                                }
                                else
                                {
                                    // Ejecución

                                    TLYFile file = TLYFile.Load(json);
                                    if (file != null)
                                    {
                                        file.Compile(inputs, Application.ExecutablePath);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // Ver si quiere editar o ejecutar una configuración
            if (!isEdit && (inputs == null || inputs.Count == 0))
            {
                foreach (string s in cfgFiles)
                {
                    TLYFile file = TLYFile.LoadFromFile(s);
                    if (file != null)
                    {
                        file.Compile(inputs, s);
                    }
                }
            }

            // Ver si se ejecuta como servicio
            if (isService)
            {
                ITopologyItem.OnException += ITopologyItem_OnException;
                ServiceBase[] ServicesToRun = new ServiceBase[] { new LasterService(inputs) };
                ServiceBase.Run(ServicesToRun);
            }
            else
            {
                // Ver si se ejecuta o se muestra la edición
                if (inputs != null && inputs.Count > 0)
                {
                    ITopologyItem.OnException += ITopologyItem_OnException;
                    if (inputs.Start())
                    {
                        Application.Run();
                    }
                }
                else
                {
                    if (!efects)
                    {
                        Application.SetCompatibleTextRenderingDefault(true);
                        Application.EnableVisualStyles();
                        efects = true;
                    }

                    // Editar en caso de que haya alguna configuración esa, sino una nueva
                    Application.Run(new FEditTopology(cfgFiles.Count == 0 ? null : cfgFiles[0]));
                }
            }
        }