コード例 #1
0
 protected virtual void PortConnectedHandler(PortModel arg1, ConnectorModel arg2)
 {
     // Do nothing for a standard node.
 }
コード例 #2
0
ファイル: ConnectorViewModel.cs プロジェクト: nmeek/Dynamo
        /// <summary>
        /// Construct a view and start drawing.
        /// </summary>
        /// <param name="port"></param>
        public ConnectorViewModel(WorkspaceViewModel workspace, PortModel port)
        {
            this.workspaceViewModel = workspace;
            IsConnecting = true;
            _activeStartPort = port;

            Redraw(port.Center);
        }
コード例 #3
0
 public void CreateT_Should_Throw_WhenNullId()
 {
     Assert.That(() => PortModel.Create <string>(null, PortDirection.Input), Throws.ArgumentNullException);
 }
コード例 #4
0
ファイル: Watch.cs プロジェクト: vikrantmygamma/Dynamo
 private void OnPortDisconnected(PortModel obj)
 {
     ResetWatch();
 }
コード例 #5
0
        protected override void DeserializeCore(XmlElement nodeElement, SaveContext context)
        {
            List <XmlNode> childNodes = nodeElement.ChildNodes.Cast <XmlNode>().ToList();

            if (!Controller.IsInSyncWithNode(this))
            {
                Controller.SyncNodeWithDefinition(this);
                OnNodeModified();
            }
            else if (Controller.Definition == null || Controller.Definition.IsProxy)
            {
                foreach (XmlNode subNode in childNodes)
                {
                    if (subNode.Name.Equals("Outputs"))
                    {
                        var data =
                            subNode.ChildNodes.Cast <XmlNode>()
                            .Select(
                                (outputNode, i) =>
                                new
                        {
                            data = new PortData(outputNode.Attributes[0].Value, Properties.Resources.ToolTipOutput + (i + 1)),
                            idx  = i
                        });

                        foreach (var dataAndIdx in data)
                        {
                            if (OutPorts.Count > dataAndIdx.idx)
                            {
                                OutPorts[dataAndIdx.idx] = new PortModel(PortType.Output, this, dataAndIdx.data);
                            }
                            else
                            {
                                OutPorts.Add(new PortModel(PortType.Output, this, dataAndIdx.data));
                            }
                        }
                    }
                    else if (subNode.Name.Equals("Inputs"))
                    {
                        var data =
                            subNode.ChildNodes.Cast <XmlNode>()
                            .Select(
                                (inputNode, i) =>
                                new
                        {
                            data = new PortData(inputNode.Attributes[0].Value, Properties.Resources.ToolTipInput + (i + 1)),
                            idx  = i
                        });

                        foreach (var dataAndIdx in data)
                        {
                            if (InPorts.Count > dataAndIdx.idx)
                            {
                                InPorts[dataAndIdx.idx] = new PortModel(PortType.Input, this, dataAndIdx.data);
                            }
                            else
                            {
                                InPorts.Add(new PortModel(PortType.Input, this, dataAndIdx.data));
                            }
                        }
                    }

                    #region Legacy output support

                    else if (subNode.Name.Equals("Output"))
                    {
                        var data = new PortData(subNode.Attributes[0].Value, Properties.Resources.ToolTipFunctionOutput);

                        if (OutPorts.Any())
                        {
                            OutPorts[0] = new PortModel(PortType.Output, this, data);
                        }
                        else
                        {
                            OutPorts.Add(new PortModel(PortType.Output, this, data));
                        }
                    }

                    #endregion
                }

                RegisterAllPorts();
            }

            base.DeserializeCore(nodeElement, context); //Base implementation must be called

            XmlNode nameNode = childNodes.LastOrDefault(subNode => subNode.Name.Equals("Name"));
            if (nameNode != null && nameNode.Attributes != null)
            {
                Name = nameNode.Attributes["value"].Value;
            }

            XmlNode descNode = childNodes.LastOrDefault(subNode => subNode.Name.Equals("Description"));
            if (descNode != null && descNode.Attributes != null)
            {
                Description = descNode.Attributes["value"].Value;
            }
        }
コード例 #6
0
        public PortViewModel(NodeViewModel node, PortModel port)
        {
            _node = node;
            _port = port;

            _port.PropertyChanged += _port_PropertyChanged;
            _node.PropertyChanged += _node_PropertyChanged;
            _node.WorkspaceViewModel.PropertyChanged += Workspace_PropertyChanged;
        }
コード例 #7
0
        public PortModel Clone(PortModel item)
        {
            var newItem = Mapper.Map <PortModel, PortModel>(item);

            return(newItem);
        }
コード例 #8
0
ファイル: PortServices.cs プロジェクト: edalonzoh90/Egulf
        public List <PortModel> Get(PortModel filter)
        {
            PortDA da = new PortDA();

            return(da.Get(filter));
        }
コード例 #9
0
ファイル: VesselServices.cs プロジェクト: edalonzoh90/Egulf
        public RequestResult <VesselModel> InsUpdComplete(VesselModel vessel,
                                                          VesselSpecificInfoModel vesselSpecificInfo,
                                                          SpecificInformationModel specificInfo,
                                                          VesselCostModel vesselCost)
        {
            RequestResult <VesselModel> resp = new RequestResult <VesselModel>()
            {
                Status = Status.Success
            };
            SpecificInformationServices specificInfoServices       = new SpecificInformationServices();
            CabinSpecificationServices  cabinSpecificationServices = new CabinSpecificationServices();
            RegionServices     regionServices = new RegionServices();
            PortServices       portServices   = new PortServices();
            TransactionOptions scopeOptions   = new TransactionOptions();

            //scopeOptions.IsolationLevel = IsolationLevel.ReadCommitted;
            using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required, scopeOptions))
            {
                try
                {
                    //Ciclo para ir a buscar diferentes puntos en el mapa, en caso de que el q se me asigne de forma aleatoria, se encuentre ya en BD
                    int valLocation = 2;
                    int test        = 1;
                    int cont        = 0;
                    while (valLocation > test && cont <= 100)
                    {
                        //Si se va a insertar, le agregamos un punto en el mapa
                        if (vessel.VesselId == null)
                        {
                            test = 0;
                            PortModel port = portServices.GetById((int)vessel.HomePort.PortId);
                            vessel.Location = regionServices.GetLocation(port.Region.RegionId);
                        }
                        else    //De lo contrario verificamos si ha cambiado su puerto, si cambió le asignamos una nueva locación
                        {
                            test = 1;
                            int?RegionIdAct = portServices.GetById((int)vessel.HomePort.PortId).Region.RegionId;
                            int?RegionIdAnt = GetById((int)vessel.VesselId).HomePort.Region.RegionId;
                            if (RegionIdAnt != RegionIdAct)
                            {
                                vessel.Location = regionServices.GetLocation(RegionIdAct);
                            }
                        }

                        //Verificamos si existe otro Barco en el mismo punto
                        if (vessel.Location.Lat == 0)
                        {
                            test = valLocation;
                        }
                        else
                        {
                            valLocation =
                                Get(new VesselModel()
                            {
                                Location = new LatLng()
                                {
                                    Lat = vessel.Location.Lat,
                                    Lng = vessel.Location.Lng
                                }
                            }).Count();
                        }
                        cont++;
                    }
                    if (cont == 100)
                    {
                        throw new Exception("Se ha alcanzado el número de barcos permitidos para una región");
                    }

                    RequestResult <VesselModel> res1 = InsUpd(vessel);
                    if (res1.Status != Status.Success)
                    {
                        throw new Exception(res1.Message);
                    }

                    vesselSpecificInfo.VesselId       = res1.Data.VesselId;
                    vesselSpecificInfo.UserModifiedId = vessel.UserModifiedId;
                    RequestResult <VesselSpecificInfoModel> res2 = InsUpdSpecificInfo(vesselSpecificInfo);
                    if (res2.Status != Status.Success)
                    {
                        throw new Exception(res2.Message);
                    }

                    specificInfo.MatchableId = res1.Data.VesselId;
                    specificInfo.Type        = SpecificInformationModel.VESSEL_TYPE;
                    RequestResult <SpecificInformationModel> res3 = specificInfoServices.InsUpd(specificInfo);
                    if (res3.Status != Status.Success)
                    {
                        throw new Exception(res3.Message);
                    }

                    List <CabinSpecificationModel>          lstCabins = specificInfo.GetCabinSpecificationList(CabinSpecificationModel.VESSEL_TYPE);
                    RequestResult <CabinSpecificationModel> respC;
                    foreach (CabinSpecificationModel cabin in lstCabins)
                    {
                        respC = cabinSpecificationServices.InsUpd(cabin);
                        if (respC.Status != Status.Success)
                        {
                            throw new Exception(respC.Message);
                        }
                    }

                    vesselCost.VesselId = res1.Data.VesselId;
                    RequestResult <VesselCostModel> res4 = InsUpdCost(vesselCost);
                    if (res4.Status != Status.Success)
                    {
                        throw new Exception(res4.Message);
                    }

                    resp = res1;
                    ts.Complete();
                }
                catch (Exception ex)
                {
                    resp.Status  = Status.Error;
                    resp.Message = ex.Message;
                    ts.Dispose();
                    throw new Exception(ex.Message);
                }
            }

            return(resp);
        }
コード例 #10
0
 public bool DeletePort(PortModel port, object whereFromDelete)
 {
     return(true);
 }
コード例 #11
0
ファイル: Creator.cs プロジェクト: ZMaciej/EdisonSimulator
        public static Element CreateElementByType(ElementType type, double width, double height, double top, double left)
        {
            Element toReturn;

            switch (type)
            {
            case ElementType.Element:
                toReturn = new Element();
                break;

            case ElementType.Port:
                toReturn = new PortModel();
                break;

            case ElementType.ResistorInSeries:
                toReturn = new LumpedElement(ElementType.ResistorInSeries, ElementType.ResistorInSeries.ToString());
                break;

            case ElementType.ResistorInParallel:
                toReturn = new LumpedElement(ElementType.ResistorInParallel, ElementType.ResistorInParallel.ToString());
                break;

            case ElementType.InductorInSeries:
                toReturn = new LumpedElement(ElementType.InductorInSeries, ElementType.InductorInSeries.ToString());
                break;

            case ElementType.InductorInParallel:
                toReturn = new LumpedElement(ElementType.InductorInParallel, ElementType.InductorInParallel.ToString());
                break;

            case ElementType.CapacitorInSeries:
                toReturn = new LumpedElement(ElementType.CapacitorInSeries, ElementType.CapacitorInSeries.ToString());
                break;

            case ElementType.CapacitorInParallel:
                toReturn = new LumpedElement(ElementType.CapacitorInParallel, ElementType.CapacitorInParallel.ToString());
                break;

            case ElementType.OpenCircuit:
                toReturn = new OpenCircuitModel();
                break;

            case ElementType.ShortCircuit:
                toReturn = new ShortCircuitModel();
                break;

            case ElementType.TransmissionLine:
                toReturn = new TransmissionLineModel();
                break;

            case ElementType.ImportedComponent:
                toReturn = new ImportedComponentModel();
                break;

            default:
                toReturn = new Element();
                break;
            }

            toReturn.Position = new Point(left, top);
            toReturn.Size     = new Size(width, height);

            return(toReturn);
        }
コード例 #12
0
 public bool AddPort(PortModel port, object whereToAdd)
 {
     return(true);
 }
コード例 #13
0
 /// <summary>
 /// Gets the port capacity of a port. This is called portModel?.GetDefaultCapacity() by NodeModel.GetPortCapacity(portModel)
 /// </summary>
 /// <param name="portModel"></param>
 /// <param name="capacity"></param>
 /// <returns></returns>
 public virtual bool GetPortCapacity(PortModel portModel, out PortCapacity capacity)
 {
     capacity = default;
     return(false);
 }
コード例 #14
0
 public string LockPort(PortModel model)
 {
     return(db.LockRecord(typeof(Port).ToString(), model.Id));
 }
コード例 #15
0
        void MakeConnectionImpl(MakeConnectionCommand command)
        {
            Guid nodeId = command.ModelGuid;

            switch (command.ConnectionMode)
            {
                case MakeConnectionCommand.Mode.Begin:
                    BeginConnection(nodeId, command.PortIndex, command.Type);
                    break;

                case MakeConnectionCommand.Mode.End:
                    EndConnection(nodeId, command.PortIndex, command.Type);
                    break;

                case MakeConnectionCommand.Mode.Cancel:
                    activeStartPort = null;
                    break;
            }
        }
コード例 #16
0
 public static Port ToEntity(this PortModel model)
 {
     return(AutoMapperConfiguration.Mapper.Map <PortModel, Port>(model));
 }
コード例 #17
0
        void EndConnection(Guid nodeId, int portIndex, PortType portType)
        {
            // Check if the node from which the connector starts is valid and has not been deleted
            if (activeStartPort.Owner == null) return;

            var startNode = CurrentWorkspace.GetModelInternal(activeStartPort.Owner.GUID);
            if (startNode == null) return;

            var node = CurrentWorkspace.GetModelInternal(nodeId) as NodeModel;
            if (node == null) return;

            bool isInPort = portType == PortType.Input;
            
            PortModel portModel = isInPort ? node.InPorts[portIndex] : node.OutPorts[portIndex];

            var models = GetConnectorsToAddAndDelete(portModel, activeStartPort);

            WorkspaceModel.RecordModelsForUndo(models, CurrentWorkspace.UndoRecorder);
            activeStartPort = null;
        }
コード例 #18
0
 public static Port ToEntity(this PortModel model, Port destination)
 {
     return(AutoMapperConfiguration.Mapper.Map(model, destination));
 }
コード例 #19
0
 protected virtual void PortConnectedHandler(PortModel arg1, ConnectorModel arg2)
 {
     // Do nothing for a standard node.
 }
コード例 #20
0
 public LinkModel AddLink(PortModel source, PortModel?target = null)
 => AddLink <LinkModel>(source, target);
コード例 #21
0
 protected virtual void PortDisconnectedHandler(PortModel port)
 {
     DeleteGeometryForIdentifier(port.Owner.AstIdentifierBase);
 }
コード例 #22
0
        public async void ListenerCallback(IAsyncResult result)
        {
            HttpListener listener = (HttpListener)result.AsyncState;

            if (!listener.IsListening)
            {
                string err_msg = "!listener.IsListening";
                Log.Debug(TAG, err_msg);
                logsDB.AddLogRow(LogStatusesEnum.Error, err_msg, TAG);
                return;
            }
            // Call EndGetContext to complete the asynchronous operation.
            HttpListenerContext context = listener.EndGetContext(result);
            HttpListenerRequest request = context.Request;
            string remote_ip_address    = request.RemoteEndPoint.Address.ToString();

            string s_request = $"ListenerCallback() - request: {request.Url} from > {remote_ip_address}";

            Log.Debug(TAG, s_request);
            logsDB.AddLogRow(LogStatusesEnum.Info, s_request, TAG);

            // Obtain a response object.
            HttpListenerResponse response = context.Response;

            Android.Net.Uri uri = Android.Net.Uri.Parse(request.Url.ToString());

            string pt    = uri.GetQueryParameter("pt");
            string dir   = uri.GetQueryParameter("dir");
            string mdid  = uri.GetQueryParameter("mdid");
            string v     = uri.GetQueryParameter("v");
            string value = uri.GetQueryParameter("value");
            string st    = uri.GetQueryParameter("st");
            string m     = uri.GetQueryParameter("m");
            string click = uri.GetQueryParameter("click");
            string cnt   = uri.GetQueryParameter("cnt");

            HardwareModel hardware;
            string        hw_name = string.Empty;

            lock (DatabaseContext.DbLocker)
            {
                using (DatabaseContext db = new DatabaseContext(gs.DatabasePathBase))
                {
                    hardware = db.Hardwares.FirstOrDefault(x => x.Address == remote_ip_address);
                }
            }

            hw_name = hardware?.Name ?? string.Empty;
            if (string.IsNullOrEmpty(hw_name))
            {
                hw_name = remote_ip_address;
            }
            else
            {
                hw_name += $" ({remote_ip_address})";
            }

            string bot_message = $"Сообщение от устройства \"{hw_name}\": {Environment.NewLine}";

            if (!string.IsNullOrWhiteSpace(pt))
            {
                if (Regex.IsMatch(pt, @"^\d+$"))
                {
                    PortModel portHardware = null;
                    int       pt_num_int   = -1;
                    pt_num_int = int.Parse(pt);
                    if (pt_num_int > -1 && hardware != null)
                    {
                        lock (DatabaseContext.DbLocker)
                        {
                            using (DatabaseContext db = new DatabaseContext(gs.DatabasePathBase))
                            {
                                portHardware = db.Ports.FirstOrDefault(x => x.HardwareId == hardware.Id && x.PortNumb == pt_num_int);
                            }
                        }
                        if (portHardware != null)
                        {
                            Log.Debug(TAG, "Поиск триггера");

                            List <ScriptModel> scripts_triggers = null;
                            lock (DatabaseContext.DbLocker)
                            {
                                using (DatabaseContext db = new DatabaseContext(gs.DatabasePathBase))
                                {
                                    scripts_triggers = db.Scripts.Where(x => x.TriggerPortId == portHardware.Id).Include(x => x.Commands).ToList();
                                }
                            }
                            if (scripts_triggers != null && scripts_triggers.Count > 0)
                            {
                                Log.Debug(TAG, $"Нaйдено триггеров: {scripts_triggers.Count}");
                                foreach (ScriptModel trigger_script in scripts_triggers)
                                {
                                    string url_request_port_state = $"http://{hardware.Address}/{hardware.Password}/?pt={pt}&cmd=get";
                                    Log.Debug(TAG, $"Зпрос состояния порта: {url_request_port_state}");

                                    HttpWebRequest request_port_state = new HttpWebRequest(new Uri(url_request_port_state))
                                    {
                                        Timeout = 5000
                                    };
                                    try
                                    {
                                        using (HttpWebResponse response_port_state = (HttpWebResponse)request_port_state.GetResponse())
                                        {
                                            if (response_port_state.StatusCode == HttpStatusCode.OK)
                                            {
                                                string responseFromServer = string.Empty;

                                                using (Stream dataStream = response_port_state.GetResponseStream())
                                                    using (StreamReader reader = new StreamReader(dataStream))
                                                    {
                                                        responseFromServer = reader.ReadToEnd();
                                                    }
                                                if (string.IsNullOrEmpty(responseFromServer))
                                                {
                                                    //"Пустой ответ устройства.";
                                                    continue;
                                                }
                                                else if (responseFromServer.ToLower() == "unauthorized")
                                                {
                                                    //"Пароль, указаный в настройкх устройства не подошёл.";
                                                    continue;
                                                }
                                                else
                                                {
                                                    Log.Debug(TAG, $"Cостояние порта: {responseFromServer}");
                                                    if ((trigger_script.TriggerPortState == true && !responseFromServer.ToLower().StartsWith("on/")) || (trigger_script.TriggerPortState == false && responseFromServer.ToLower().StartsWith("off/")))
                                                    {
                                                        continue;
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                //$"Ошибка выполнения запроса. StatusCode:\"{response.StatusCode}\"; StatusDescription:\"{response.StatusDescription}\"";
                                                continue;
                                            }
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        //$"Сбой обработки команды:{ex.Message}";
                                        continue;
                                    }


                                    TaskModel task;
                                    lock (DatabaseContext.DbLocker)
                                    {
                                        using (DatabaseContext db = new DatabaseContext(gs.DatabasePathBase))
                                        {
                                            task = new TaskModel()
                                            {
                                                Name = "http trigger",
                                                TaskInitiatorType = TaskInitiatorsTypes.Trigger,
                                                TaskInitiatorId   = hardware.Id,
                                                ScriptId          = trigger_script.Id
                                            };
                                            db.Tasks.Add(task);
                                            db.SaveChanges();
                                        }
                                    }

                                    BackgroundWorker bw = new BackgroundWorker();
                                    bw.DoWork             += new DoWorkEventHandler(aForegroundService.RunScriptAction);
                                    bw.ProgressChanged    += (object sender, ProgressChangedEventArgs e) => { };
                                    bw.RunWorkerCompleted += (object sender, RunWorkerCompletedEventArgs e) => { };
                                    bw.RunWorkerAsync(task);
                                }
                            }
                        }
                    }

                    if (!string.IsNullOrWhiteSpace(pt) && string.IsNullOrWhiteSpace(portHardware?.Name))
                    {
                        pt = $"Порт: P{pt}; ";
                    }
                    else
                    {
                        pt = $"Порт: \"{portHardware.Name}\" (P{pt}); ";
                    }
                }
                else
                {
                    pt = $"Порт: {pt}; ";
                }
                bot_message += $"{pt}";
            }

            if (!string.IsNullOrWhiteSpace(m))
            {
                m            = (m == "1" ? "Освобождние после длительного удержания" : $"Длительное удержание") + "; ";
                bot_message += $"{m}";
            }

            if (!string.IsNullOrWhiteSpace(click))
            {
                click        = (click == "1" ? "обычный клик" : "двойной клик") + "; ";
                bot_message += $"{click}";
            }

            if (!string.IsNullOrWhiteSpace(dir))
            {
                if (dir == "0")//падение значения
                {
                    dir = "Значение опустилось ниже порога; ";
                }
                else if (dir == "1")//повышение знчения
                {
                    dir = "Значение превышает пороговое; ";
                }
                else
                {
                    dir = $"ошибка определения вектора 'dir':{dir}; ";
                }
                bot_message += $"{dir}";
            }

            if (!string.IsNullOrWhiteSpace(mdid))
            {
                mdid         = $"mdid=\"{mdid}\"; ";
                bot_message += $"{mdid}";
            }

            if (!string.IsNullOrWhiteSpace(st))
            {
                st           = $"st=\"{st}\"; ";
                bot_message += $"{st}";
            }

            if (!string.IsNullOrWhiteSpace(v))
            {
                v            = $"v=\"{v}\"; ";
                bot_message += $"{v}";
            }

            if (!string.IsNullOrWhiteSpace(value))
            {
                value        = $"value=\"{value}\"; ";
                bot_message += $"{value}";
            }

            string token = Preferences.Get(Constants.TELEGRAM_TOKEN, string.Empty);

            if (!string.IsNullOrWhiteSpace(token))
            {
                TelegramClientCore telegramClient = new TelegramClientCore(token);
                if (telegramClient?.Me != null)
                {
                    List <UserModel> users;
                    lock (DatabaseContext.DbLocker)
                    {
                        using (DatabaseContext db = new DatabaseContext(gs.DatabasePathBase))
                        {
                            users = db.Users.Where(x => x.AlarmSubscriber).ToList();
                        }
                    }

                    List <TelegramUserModel> t_users;
                    foreach (UserModel user in users)
                    {
                        lock (DatabaseContext.DbLocker)
                        {
                            using (DatabaseContext db = new DatabaseContext(gs.DatabasePathBase))
                            {
                                t_users = db.TelegramUsers.Where(xx => xx.LinkedUserId == user.Id).ToList();
                            }
                        }
                        foreach (TelegramUserModel telegramUser in t_users)
                        {
                            await telegramClient.sendMessage(telegramUser.TelegramId.ToString(), bot_message.Trim());
                        }
                    }
                }
            }

            string log_msg = $"incoming http request (from > {remote_ip_address}): {request.Url.Query}";
            //log_msg = "telegramClient?.Me == null";
            //Log.Info(TAG, log_msg);
            //using (LogsContext log = new LogsContext())
            //{
            //    log.AddLogRow(LogStatusesEnum.Info, log_msg, TAG);
            //}

            // Construct a response.
            string responseString = "Hello world!";

            byte[] buffer = Encoding.UTF8.GetBytes(responseString);
            // Get a response stream and write the response to it.
            response.ContentLength64 = buffer.Length;
            System.IO.Stream output = response.OutputStream;
            await output.WriteAsync(buffer, 0, buffer.Length);

            // You must close the output stream.
            output.Close();
            result = httpServer.BeginGetContext(new AsyncCallback(ListenerCallback), httpServer);
        }
コード例 #23
0
ファイル: CodeBlockNode.cs プロジェクト: whztt07/Dynamo
        /// <summary>
        ///     Deletes all the connections and saves their data (the start and end port)
        ///     so that they can be recreated if needed.
        /// </summary>
        /// <param name="portConnections">A list of connections that will be destroyed</param>
        private void SaveAndDeleteConnectors(OrderedDictionary inportConnections, OrderedDictionary outportConnections)
        {
            //----------------------------Inputs---------------------------------
            for (int i = 0; i < InPorts.Count; i++)
            {
                PortModel portModel = InPorts[i];
                string    portName  = portModel.ToolTipContent;
                if (portModel.Connectors.Count != 0)
                {
                    inportConnections.Add(portName, new List <PortModel>());
                    foreach (ConnectorModel connector in portModel.Connectors)
                    {
                        (inportConnections[portName] as List <PortModel>).Add(connector.Start);
                        Workspace.UndoRecorder.RecordDeletionForUndo(connector);
                    }
                }
                else
                {
                    inportConnections.Add(portName, null);
                }
            }

            //Delete the connectors
            foreach (PortModel inport in InPorts)
            {
                inport.DestroyConnectors();
            }

            //Clear out all the port models
            for (int i = InPorts.Count - 1; i >= 0; i--)
            {
                InPorts.RemoveAt(i);
            }


            //----------------------------Outputs---------------------------------
            for (int i = 0; i < OutPorts.Count; i++)
            {
                PortModel portModel = OutPorts[i];
                string    portName  = portModel.ToolTipContent;
                if (portModel.ToolTipContent.Equals(Formatting.ToolTipForTempVariable))
                {
                    portName += i.ToString(CultureInfo.InvariantCulture);
                }
                if (portModel.Connectors.Count != 0)
                {
                    outportConnections.Add(portName, new List <PortModel>());
                    foreach (ConnectorModel connector in portModel.Connectors)
                    {
                        (outportConnections[portName] as List <PortModel>).Add(connector.End);
                        Workspace.UndoRecorder.RecordDeletionForUndo(connector);
                    }
                }
                else
                {
                    outportConnections.Add(portName, null);
                }
            }

            //Delete the connectors
            foreach (PortModel outport in OutPorts)
            {
                outport.DestroyConnectors();
            }

            //Clear out all the port models
            for (int i = OutPorts.Count - 1; i >= 0; i--)
            {
                OutPorts.RemoveAt(i);
            }
        }
コード例 #24
0
 protected override void PortConnectedHandler(PortModel arg1, ConnectorModel arg2)
 {
     UpdateUpstream();
 }
コード例 #25
0
 public PortAddInvokedMessage(PortModel portModel)
 {
     PortModel = portModel;
 }
コード例 #26
0
 protected override void PortDisconnectedHandler(PortModel obj)
 {
     OnClear();
 }
コード例 #27
0
 protected override void OnDefineNode()
 {
     InstancePort = AddInstanceInput <Unknown>(null, "Instance");
     ValuePort    = AddDataInputPort <Unknown>("Value");
 }
コード例 #28
0
 void DefinePorts(TypeHandle aType, TypeHandle bType, TypeHandle outputType)
 {
     m_InputAPort     = AddDataInput("A", aType, nameof(PortName.PortA));
     m_InputBPort     = AddDataInput("B", bType, nameof(PortName.PortB));
     m_MainOutputPort = AddDataOutputPort("Out", outputType);
 }
コード例 #29
0
        public static IGraphElement CreatePort(this ElementBuilder elementBuilder, IStore store, PortModel model)
        {
            var ui = new Port();

            ui.Setup(model, store, elementBuilder.GraphView);
            return(ui);
        }
コード例 #30
0
        public async void GetHttp(string url)
        {
            Log.Debug(TAG, $"GetHttp - {url}");

            Android.Net.Uri uri = Android.Net.Uri.Parse(url);
            if (uri.Host == "ab-log.ru")
            {
                if (!url.EndsWith("/"))
                {
                    url += "/";
                }
                url += "?ref=https://github.com/badhitman/ab-log-app";
                await Browser.OpenAsync(url, BrowserLaunchMode.External);

                return;
            }

            HardwareSystemSettingsLayout.RemoveAllViews();
            HardwareSystemSettingsLayout.AddView(new ProgressBar(this)
            {
                Indeterminate = true
            });

            webView = new WebView(this);
            webView.Settings.JavaScriptEnabled = true;
            webView.Settings.JavaScriptCanOpenWindowsAutomatically = true;
            webView.Settings.DomStorageEnabled = true;

            MyWebViewClient myWebViewClient = new MyWebViewClient();

            myWebViewClient.ShouldUrlLoading += delegate(string new_url) { GetHttp(new_url); };

            webView.SetWebViewClient(myWebViewClient);
            string html_raw = string.Empty;

            string cf  = uri.GetQueryParameter("cf") ?? string.Empty;
            string pt  = uri.GetQueryParameter("pt") ?? string.Empty;
            string eip = uri.GetQueryParameter("eip") ?? string.Empty;
            string pwd = uri.GetQueryParameter("pwd") ?? string.Empty;

            string pn            = uri.GetQueryParameter("pn") ?? string.Empty;
            string pty           = uri.GetQueryParameter("pty") ?? string.Empty;
            string set_port_name = uri.GetQueryParameter("set_port_name");

            if (set_port_name != null)
            {
                url = url
                      .Replace($"set_port_name={WebUtility.UrlEncode(set_port_name)}", string.Empty)
                      .Replace("?&", "?");

                if (!string.IsNullOrEmpty(pn))
                {
                    PortModel portHardware = GetPortHardware(pn);
                    if (portHardware == null)
                    {
                        return;
                    }

                    if (portHardware.Name != set_port_name)
                    {
                        portHardware.Name = set_port_name;
                        lock (DatabaseContext.DbLocker)
                        {
                            using (DatabaseContext db = new DatabaseContext(gs.DatabasePathBase))
                            {
                                db.Ports.Update(portHardware);
                                db.SaveChanges();
                            }
                        }
                    }
                }
            }

            using (HttpClient client = new HttpClient()
            {
                Timeout = new TimeSpan(0, 0, 5)
            })
            {
                try
                {
                    HttpResponseMessage httpResponseMessage = await client.GetAsync(url);

                    html_raw = await httpResponseMessage.Content.ReadAsStringAsync();
                }
                catch (Exception ex)
                {
                    Toast.MakeText(this, ex.Message, ToastLength.Long).Show();
                    StartActivity(new Intent(Application.Context, typeof(HardwaresListActivity)));
                    return;
                }
            }



            await Task.Run(() =>
            {
                html_raw = html_raw.Replace("<br>", $"<br>{System.Environment.NewLine}");

                string onload_js;

                /////////////////////////////////////////////////////////////
                /// настройки: основные (ip,gw и т.п.)
                if (cf == "1")
                {
                    onload_js = MyWebViewClient.onload_cf1_js;

                    bool set_ip_address = !string.IsNullOrWhiteSpace(eip);
                    bool set_password   = !string.IsNullOrWhiteSpace(pwd);

                    if (set_ip_address || set_password)
                    {
                        Log.Debug(TAG, "save data to DB");
                        lock (DatabaseContext.DbLocker)
                        {
                            using (DatabaseContext db = new DatabaseContext(gs.DatabasePathBase))
                            {
                                List <string> messages = new List <string>();
                                if (set_ip_address && hardware.Address != eip)
                                {
                                    hardware.Address = eip;
                                    messages.Add(GetText(Resource.String.hardware_ip_are_saved_title));
                                }
                                if (set_password && hardware.Password != pwd)
                                {
                                    hardware.Password = pwd;
                                    messages.Add(GetText(Resource.String.hardware_password_are_saved_title));
                                }
                                if (messages.Count > 0)
                                {
                                    db.Hardwares.Update(hardware);
                                    db.SaveChanges();
                                    RunOnUiThread(() =>
                                    {
                                        Toast.MakeText(this, $" • {string.Join($"{System.Environment.NewLine} • ", messages)}", ToastLength.Short).Show();
                                    });
                                    StartActivity(new Intent(Application.Context, typeof(HardwaresListActivity)));
                                    return;
                                }
                            }
                        }
                    }

                    if (external_web_mode)
                    {
                        html_raw = form_regex.Replace(html_raw, (Match match) => { return($"<form action=\"{match.Groups[1].Value}\">{System.Environment.NewLine}"); });

                        html_raw = html_raw
                                   .Replace("<form", $"<div class=\"card mt-2\">{System.Environment.NewLine}<div class=\"card-body\">{System.Environment.NewLine}<form")
                                   .Replace("</form>", $"{System.Environment.NewLine}</form>{System.Environment.NewLine}</div>{System.Environment.NewLine}</div>")
                                   .Replace("</style>", $"</style>{System.Environment.NewLine}")
                                   .Replace("<option", $"{System.Environment.NewLine}<option")
                                   .Replace("<select", "<select class=\"form-control\"");

                        html_raw = a_href_regex.Replace(html_raw, (Match match) =>
                        {
                            switch (match.Groups[2].Value.ToLower())
                            {
                            case "back":
                                return($"<a href=\"{match.Groups[1].Value}\" class=\"btn btn-primary btn-sm\" role=\"button\">{match.Groups[2].Value}</a>");

                            default:
                                return($"<a href=\"{match.Groups[1].Value}\" class=\"btn btn-outline-info btn-sm\" role=\"button\">{match.Groups[2].Value}</a>");
                            }
                        });

                        html_raw = input_regex.Replace(html_raw, (Match match) =>
                        {
                            string input_raw         = match.Groups[0].Value;
                            bool input_with_out_type = true;
                            input_raw = input_type_regex.Replace(input_raw, (Match sub_match) =>
                            {
                                input_with_out_type   = false;
                                string input_type_raw = sub_match.Groups[0].Value;
                                switch (sub_match.Groups[1].Value.ToLower())
                                {
                                case "checkbox":
                                    return($" class=\"form-check-input pb-4 mb-4 ml-1\" {input_type_raw}");

                                case "submit":
                                    return($" class=\"btn btn-outline-primary btn-block\" {input_type_raw}");

                                case "hidden":
                                    return(input_type_raw);

                                default:
                                    return($" class=\"form-control\" {input_type_raw}");
                                }
                            });

                            if (input_with_out_type)
                            {
                                input_raw = input_raw.Replace("<input", "<input class=\"form-control\"");
                            }

                            input_raw = input_name_regex.Replace(input_raw, (Match sub_match) =>
                            {
                                string input_name_raw = sub_match.Groups[1].Value;
                                switch (input_name_raw.ToLower())
                                {
                                case "eip":
                                    return($" placeholder=\"IP адрес устройства\" name=\"{input_name_raw}\"");

                                case "pwd":
                                    return($" placeholder=\"Пароль\" name=\"{input_name_raw}\"");

                                case "gw":
                                    return($" placeholder=\"Шлюз\" name=\"{input_name_raw}\"");

                                case "sip":
                                    return($" placeholder=\"IP-адрес главного сервера\" name=\"{input_name_raw}\"");

                                case "auth":
                                    return($" placeholder=\"MQTT пароль\" name=\"{input_name_raw}\"");

                                case "sct":
                                    return($" placeholder=\"Скрипт обработки сообщений\" name=\"{input_name_raw}\"");

                                //case "rtf":
                                //    return $"{sub_match.Groups[0].Value} <small class=\"form-text text-muted\">Принудительная доставка MQTT</small>";
                                case "pr":
                                    return($" placeholder=\"Сторожевой сценарий\" name=\"{input_name_raw}\"");

                                default:
                                    return($" name=\"{input_name_raw}\"");
                                }
                            });

                            return(input_raw);
                        });
                        int connected_status = html_raw.ToLower().IndexOf("disconnected");
                        if (connected_status > 0)
                        {
                            html_raw = $"{html_raw.Substring(0, connected_status)}<div class=\"d-flex justify-content-end pt-3\"><span class=\"badge badge-secondary\">Disconnected</span></div>{html_raw.Substring(connected_status + 12)}";
                        }
                        else
                        {
                            connected_status = html_raw.ToLower().IndexOf("connected");
                            if (connected_status > 0)
                            {
                                html_raw = $"{html_raw.Substring(0, connected_status)}<div class=\"d-flex justify-content-end pt-3\"><span class=\"badge badge-success\">Connected</span></div>{html_raw.Substring(connected_status + 9)}";
                            }
                        }

                        html_raw += $"{System.Environment.NewLine}<div class=\"alert alert-info mt-3\" role=\"alert\"><h6>Информация</h6>" +
                                    "<p><strong>IP:</strong> адрес устройства (MAC-адрес устройства генерируется динамически на основе IP-адреса)</p>" +
                                    "<p><strong>Pwd:</strong> пароль для доступа к устройству (максимально 3 символа)</p>" +
                                    "<p><strong>GW:</strong> шлюз. Имеет смысл указывать только если сервер находится за пределами текущей IP-сети. Если не указан, то в поле отображается значение 255.255.255.255</p>" +
                                    "<p><strong>SRV:</strong> IP-адрес главного сервера (HTTP/MQTT), на который MegaD-2561 будет отправлять сообщения о сработавших входах. После IP-адреса возможно указать порт. По умолчанию 80.</p>" +
                                    "<p><strong>Script:</strong> <mark>(в случае использования HTTP)</mark> скрипт на сервере, который обрабатывает сообщения от устройства и формирует ответы (максимально 15 символов).</p>" +
                                    "<p><strong>Wdog:</strong> функция слежения за сервером. Если используется сервер (указан его IP-адрес и скрипт), то устройство примерно раз в 2 минуты проверяет его доступность и в случае, если сервер не отвечает выполняет сценарий порта, который указывается в поле Wdog. Подробнее о сценариях описано ниже.</p>" +
                                    "<p><strong>UART:</strong> выбор режима UART-портов (P32/P33) - работа с GSM-модулем типа SIM800L; работа в режиме RS485-Modbus RTU.</p>" +
                                    "<p><strong>Uptime:</strong> время работы устройства после старта</p>" +
                                    "<p><strong>Temp:</strong> температура микросхемы часов реального времени DS3231, температура внутри корпуса (только для версии MegaD-2561-RTC)</p>" +
                                    "</div>";
                    }
                }
                /////////////////////////////////////////////////////////////
                /// настройки: Megad-ID
                else if (cf == "2")
                {
                    onload_js = MyWebViewClient.onload_cf2_js;

                    if (external_web_mode)
                    {
                        html_raw = html_raw
                                   .Replace("Megad-ID:", $"{System.Environment.NewLine}<label>Megad-ID:</label>{System.Environment.NewLine}")
                                   .Replace("<input type=hidden name=cf value=2>", $"<input type=\"hidden\" name=\"cf\" value=\"2\"/>")
                                   .Replace("<form", $"<div class=\"card mt-2\">{System.Environment.NewLine}<div class=\"card-body\">{System.Environment.NewLine}<form")
                                   .Replace("</form>", $"{System.Environment.NewLine}</form>{System.Environment.NewLine}</div>{System.Environment.NewLine}</div>")
                                   .Replace("</style>", $"</style>{System.Environment.NewLine}")
                                   .Replace("<input type=submit value=Save>", "<input class=\"btn btn-outline-primary btn-block\" type=\"submit\" value=\"Save\">")
                                   .Replace("<input name=mdid", "<input class=\"form-control\" name=\"mdid\" placeholder=\"Идентификатор\"");

                        html_raw = Regex.Replace(html_raw, @"srv loop:\s+(<input[^>]+>)", (Match match) =>
                        {
                            string input_raw = match.Groups[1].Value
                                               .Replace("type=checkbox", "type=\"checkbox\"")
                                               .Replace(">", " />")
                                               .Replace("<input", "<input id=\"srv-loop\" class=\"custom-control-input\"");
                            return($"<div class=\"custom-control custom-checkbox\">{System.Environment.NewLine}{input_raw}{System.Environment.NewLine}<label for=\"srv-loop\" class=\"custom-control-label\">srv loop</label>{System.Environment.NewLine}</div>{System.Environment.NewLine}");
                        });

                        html_raw = form_regex.Replace(html_raw, (Match match) => { return($"<form action=\"{match.Groups[1].Value}\">{System.Environment.NewLine}"); });
                        html_raw = a_href_regex.Replace(html_raw, (Match match) => { return($"<a href=\"{match.Groups[1].Value}\" class=\"btn btn-primary btn-sm\" role=\"button\">{match.Groups[2].Value}</a>"); });

                        html_raw += "<div class=\"alert alert-info mt-3\" role=\"alert\"><h4>Информация</h4><p><strong>Megad-ID</strong> используется в MQTT для формирования подписки <code>Topic</code>, а тк же <code>ClientId</code>. Например, если назначить это значение <u>droid</u>, то упрвляющий блок подпишется в MQTT брокере на топик <u>droid/cmd</u> с идентификатором клиента <u>megad-droid</u>. В то же время: состояние портов управляющий блок будет публиковать в топиках с именами подстать номерам портов. Например для порта №30(P30) сообщения от блока будут в топике <u>droid/30</u>. Информация о всех событиях MQTT подписок/сообщений в брокере доступна в логах приложения.</p><p><strong>srv loop</strong> включает режим регулярной отправки (раз в минуту) на сервер состояние всех портов</p></div>";
                    }
                }
                /////////////////////////////////////////////////////////////
                /// настройки: XT1
                else if (cf == "3")
                {
                    onload_js = MyWebViewClient.onload_cf3_js;

                    if (external_web_mode)
                    {
                        html_raw = a_href_regex.Replace(html_raw, (Match m) =>
                        {
                            switch (m.Groups[2].Value.ToLower())
                            {
                            case "back":
                                return($"<a href=\"{m.Groups[1].Value}\" class=\"btn btn-primary btn-sm\" role=\"button\">{m.Groups[2].Value}</a>");

                            default:
                                return($"<a href=\"{m.Groups[1].Value}\" class=\"btn btn-outline-info btn-block\" role=\"button\">{m.Groups[2].Value}</a>");
                            }
                        });
                    }
                }
                /////////////////////////////////////////////////////////////
                /// настройки: XT2
                else if (cf == "4")
                {
                    onload_js = MyWebViewClient.onload_cf4_js;

                    if (external_web_mode)
                    {
                        html_raw = a_href_regex.Replace(html_raw, (Match m) =>
                        {
                            switch (m.Groups[2].Value.ToLower())
                            {
                            case "back":
                                return($"<a href=\"{m.Groups[1].Value}\" class=\"btn btn-primary btn-sm\" role=\"button\">{m.Groups[2].Value}</a>");

                            default:
                                return($"<a href=\"{m.Groups[1].Value}\" class=\"btn btn-outline-info btn-block\" role=\"button\">{m.Groups[2].Value}</a>");
                            }
                        });
                    }
                }
                /////////////////////////////////////////////////////////////
                /// настройки: cron
                else if (cf == "7")
                {
                    onload_js = MyWebViewClient.onload_cf7_js;

                    if (external_web_mode)
                    {
                        html_raw = html_raw
                                   .Replace("<input type=hidden name=cf value=7>", $"<input type=\"hidden\" name=\"cf\" value=\"7\"/>")
                                   .Replace("<form", $"<div class=\"card mt-2\">{System.Environment.NewLine}<div class=\"card-body\">{System.Environment.NewLine}<form")
                                   .Replace("</form>", $"{System.Environment.NewLine}</form>{System.Environment.NewLine}</div>{System.Environment.NewLine}</div>")
                                   .Replace("</style>", $"</style>{System.Environment.NewLine}")
                                   .Replace("<input type=submit value=Save>", "<input class=\"btn btn-outline-primary btn-block\" type=\"submit\" value=\"Save\"/>");

                        html_raw = Regex.Replace(html_raw, @"<input name=([\w\d]+)", (Match match) =>
                        {
                            return($"<input class=\"form-control\" name=\"{match.Groups[1].Value}\"");
                        });

                        html_raw = form_regex.Replace(html_raw, (Match match) => { return($"<form action=\"{match.Groups[1].Value}\">{System.Environment.NewLine}"); });
                        html_raw = a_href_regex.Replace(html_raw, (Match match) => { return($"<a href=\"{match.Groups[1].Value}\" class=\"btn btn-primary btn-sm\" role=\"button\">{match.Groups[2].Value}</a>"); });

                        html_raw += "<div class=\"alert alert-info mt-3\" role=\"alert\"><h4>Информация</h4>" +
                                    "<p><strong>Cur time:</strong> текущее время. В квадратных скобках указан день недели (1-7). Например [5] - пятница.</p>" +
                                    "<p><strong>Set time:</strong> здесь можно задать время. Формат ЧЧ:ММ:СС:ДН, то есть 15:30:00:5 - последняя цифра - день недели</p>" +
                                    "<p><strong>SCL/SDA:</strong> порты микроконтроллера, к которым подключены часы. Здесь указывается не номер порта (как обычно), а его индекс (можно посмотреть в документации). Это сделано для того, чтобы имелась возможность подключить часы не только к разъему XT2 (зеленые клеммники внизу) и исполнительным модулям MegaD-14-IOR, но и к внутреннему 16-пиновому разъему XP4.</p>" +
                                    "<div class=\"shadow p-3 mb-4 bg-white rounded\">В случае использования контроллера в исполнении MegaD-2561-RTC можно оставить эти поля пустыми. Контроллер сам определит наличие платы часов, подключенных к служебному разъему XP4 и синхронизируется с ними.</div>" +
                                    "<p><strong>T/Act:</strong>  Сами задания. Их может быть 5 шт.</p>" +
                                    "<p><strong>T:</strong> Расписание в формате ЧЧ:ММ:ДН</p>" +
                                    "<div class=\"shadow p-3 mb-4 bg-white rounded\"><code>14:30:0</code> - выполнять в 14:30 каждый день (последний 0 - означает каждый день)<br/>" +
                                    "<code>08:00:3</code> - выполнить в 8:00 в среду(3 - среда)<br/>" +
                                    "<code>03:15:3-7</code> - выполнять в 03:15 со среды по воскресенье включительно(3-7)<br/>" +
                                    "<code>*:/03:0</code> - выполняется каждые 3 минуты.Вместо значения \"час\" необходимо задать '*'.Последний ':0' - дни недели. 0 - каждый день.День недели учитывается.Можно задать выполнение циклической операции в определенные дни недели.<br/>" +
                                    "<code>/02:15:0</code> - выполняется каждые 2 часа в 15 минут.То есть в 2:15; 4:15; 6:15 и т.д.</div>" +
                                    "<p><strong>Act:</strong> стандартное поле сценария. Важно, что здесь работают паузы (команды p). То есть, если необходимо включить, например, автополив на 30 минут, то не обязательно разносить это на два задания. Можно ограничится одним.</p>" +
                                    "<div class=\"shadow p-3 mb-4 bg-white rounded\">" +
                                    "<code>7:1;P10;7:0</code> - включить седьмой порт, далее следует пауза 10 секунд, после чего порт будет выключен.<br/>" +
                                    "<code>10:1;P600;10:0</code> - включить десятый порт, далее следует пауза 600 секунд, после чего порт будет выключен.<br/>" +
                                    "<code>8:1;9:0;12:2</code> - включить восьмой порт и выключить девятый, а двендцтый переключить в противоположное состояние.</div>" +
                                    "</div>";
                    }
                }
                /////////////////////////////////////////////////////////////
                /// настройки: rogram
                else if (cf == "9")
                {
                    onload_js = MyWebViewClient.onload_cf9_js;

                    if (external_web_mode)
                    {
                        html_raw = html_raw
                                   .Replace("<input type=hidden name=cf value=9>", $"<input type=\"hidden\" name=\"cf\" value=\"9\"/>")
                                   .Replace("<form", $"<div class=\"card mt-2\">{System.Environment.NewLine}<div class=\"card-body\">{System.Environment.NewLine}<form")
                                   .Replace("</style>", $"</style>{System.Environment.NewLine}") +
                                   $"{System.Environment.NewLine}</form>{System.Environment.NewLine}</div>{System.Environment.NewLine}</div>";

                        html_raw = a_href_regex.Replace(html_raw, (Match match) =>
                        {
                            if (match.Groups[2].Value.ToLower() == "back")
                            {
                                return($"<a href=\"{match.Groups[1].Value}\" class=\"btn btn-primary btn-sm\" role=\"button\">{match.Groups[2].Value}</a>");
                            }
                            else
                            {
                                return($"<a href=\"{match.Groups[1].Value}\" class=\"badge badge-info mt-2\" role=\"button\">{match.Groups[2].Value}</a>");
                            }
                        });

                        html_raw += "<div class=\"alert alert-info mt-3\" role=\"alert\"><h6>Программирование условий для выполнения сценариев</h6>" +
                                    "<p>Контроллер MegaD-2561 может выполнять заданные команды (сценарии) в случае возникновения какого-то события: нажата кнопка, температура выросла выше определенного значения и т.д. Для этого в настройках соответствующих портов присутствует поле \"Act\". Но у этого штатного механизма есть ряд ограничений: он работает для входов (IN, ADC, DSen/1W), но не работает для выходов (OUT); нельзя задать дополнительное условие для выполнение сценария (например: нажата кнопка -> включить свет, но только в том случае, если датчик освещенности не выше определенного заданного значения).</p><p>Для решения подобных задач предназначен данный раздел <strong>Program</strong>, который позволяет задавать сценарии в том числе для выходов и строить цепочки подчиненных условий. Таким образом, в каких-то не очень сложных задачах можно обойтись только средствами контроллера без использования сервера.</p>" +
                                    "</div>";
                    }
                }
                /////////////////////////////////////////////////////////////
                /// конфигурация условий/сценариев в разделе rogram
                else if (cf == "10")
                {
                    onload_js  = MyWebViewClient.onload_cf10_js;
                    string prn = uri.GetQueryParameter("prn") ?? string.Empty;
                    if (external_web_mode)
                    {
                        html_raw = html_raw
                                   .Replace($"<a href=/{hardware.Password}/?cf=9>Back</a><br>", $"<a class=\"btn btn-primary btn-sm\" role=\"button\" href=\"/{hardware.Password}/?cf=9\">Back</a><br>")
                                   .Replace("<input type=hidden name=cf value=10>", $"<input type=\"hidden\" name=\"cf\" value=\"10\"/>")
                                   .Replace("<input type=submit name=pcl value=clear><br>", "<input type=submit name=pcl value=clear>")
                                   .Replace("<form", $"<div class=\"card mt-2\">{System.Environment.NewLine}<div class=\"card-body\">{System.Environment.NewLine}<form")
                                   .Replace("<select", "<label>тип сравнения: </label><select class=\"custom-select\"")
                                   .Replace("</form>", $"{System.Environment.NewLine}</form>")
                                   .Replace(" name=prp ", " name=prp type=\"number\"")
                                   .Replace("</style>", $"</style>{System.Environment.NewLine}") +
                                   $"{System.Environment.NewLine}</div>{System.Environment.NewLine}</div>";

                        html_raw = form_regex.Replace(html_raw, (Match match) => { return($"<form action=\"{match.Groups[1].Value}\">{System.Environment.NewLine}"); });

                        html_raw = input_regex.Replace(html_raw, (Match match) =>
                        {
                            string input_raw         = match.Groups[0].Value;
                            bool input_with_out_type = true;
                            input_raw = input_type_regex.Replace(input_raw, (Match sub_match) =>
                            {
                                input_with_out_type   = false;
                                string input_type_raw = sub_match.Groups[0].Value;
                                switch (sub_match.Groups[1].Value.ToLower())
                                {
                                case "checkbox":
                                    return($" class=\"form-check-input pb-4 mb-4 ml-1\" {input_type_raw}");

                                case "submit":
                                    return($" class=\"btn btn-outline-primary btn-block my-2\" {input_type_raw}");

                                case "hidden":
                                    return(input_type_raw);

                                default:
                                    return($" class=\"form-control\" {input_type_raw}");
                                }
                            });

                            if (input_with_out_type)
                            {
                                input_raw = input_raw.Replace("<input", "<input class=\"form-control\"");
                            }

                            return(input_raw);
                        });

                        html_raw += $"{System.Environment.NewLine}<div class=\"alert alert-info mt-3\" role=\"alert\"><h6>Программирование условий для выполнения сценариев</h6>" +
                                    "<p>Задается номер порта, тип сравнения (больше / меньше / равно), значение, сценарий, тип условия (основное / подчиненное).</p>" +
                                    "</div>";
                    }
                }
                /////////////////////////////////////////////////////////////
                /// настройка порта
                else if (!string.IsNullOrWhiteSpace(pt))
                {
                    onload_js = MyWebViewClient.onload_pt_js;

                    PortModel portHardware = GetPortHardware(pt);
                    if (portHardware == null)
                    {
                        return;
                    }

                    if (external_web_mode)
                    {
                        if (html_raw.Contains("selected>Out<option"))
                        {
                            if (html_raw.Contains($"P{pt}/ON<br>"))
                            {
                                html_raw = html_raw.Replace($"<a href=/{hardware.Password}/?pt={pt}&cmd={pt}:1>ON</a>", $"<nav class=\"nav nav-pills nav-fill\"><a class=\"nav-item nav-link active\" href=\"/{hardware.Password}/?pt={pt}&cmd={pt}:1\">ON</a>");
                                html_raw = html_raw.Replace($"<a href=/{hardware.Password}/?pt={pt}&cmd={pt}:0>OFF</a>", $"<a class=\"nav-item nav-link btn btn-outline-secondary ml-2\" href=\"/{hardware.Password}/?pt={pt}&cmd={pt}:0\">OFF</a></nav>");
                            }
                            else
                            {
                                html_raw = html_raw.Replace($"<a href=/{hardware.Password}/?pt={pt}&cmd={pt}:1>ON</a>", $"<nav class=\"nav nav-pills nav-fill\"><a class=\"nav-item nav-link btn btn-outline-secondary mr-2\" href=\"/{hardware.Password}/?pt={pt}&cmd={pt}:1\">ON</a>");
                                html_raw = html_raw.Replace($"<a href=/{hardware.Password}/?pt={pt}&cmd={pt}:0>OFF</a>", $"<a class=\"nav-item nav-link active\" href=\"/{hardware.Password}/?pt={pt}&cmd={pt}:0\">OFF</a></nav>");
                            }
                        }

                        html_raw = a_href_regex.Replace(html_raw, (Match match) =>
                        {
                            return($"<a class=\"btn btn-primary btn-sm\" role=\"button\" href=\"{match.Groups[1].Value}\">Back</a> <a class=\"btn btn-info btn-sm\" role=\"button\" onclick=\"window.location.reload()\">Reload</a>");
                        });

                        html_raw = html_raw
                                   .Replace("<style>input,select{margin:1px}</style>", string.Empty)
                                   .Replace($"<form action=/{hardware.Password}/>", $"{System.Environment.NewLine}<div class=\"card mt-2\">{System.Environment.NewLine}<div class=\"card-body\">{System.Environment.NewLine}<form action=\"/{hardware.Password}/\">{System.Environment.NewLine}<div class=\"form-group\"><label>Name</label><input type=\"text\" name=\"set_port_name\" class=\"form-control\" placeholder=\"Наименовние\" value=\"{portHardware.Name}\"></div>")
                                   .Replace("<input type=submit value=Save>", "<input class=\"btn btn-outline-primary btn-block\" type=\"submit\" value=\"Save\"/>")
                                   .Replace("</form>", $"{System.Environment.NewLine}</form>{System.Environment.NewLine}</div>{System.Environment.NewLine}</div>")
                                   .Replace("Type <select", "Type <select class=\"form-control\"")
                                   .Replace("Val <input", "Val <input type=\"number\" class=\"form-control\"")
                                   .Replace("Hst <input", "Hst <input type=\"number\" class=\"form-control\"")
                                   .Replace("Sen <select name=d>", "Sen <select class=\"form-control\" name=d>")
                                   .Replace("<input name=misc", "<input name=\"misc\" class=\"form-control\"")
                                   .Replace("Group <input", "Group <input class=\"form-control\"")
                                   .Replace($"<a href=/{hardware.Password}/?pt={pt}&cmd=list>Device List</a>", $"<a class=\"btn btn-info btn-block\" href=\"/{hardware.Password}/?pt={pt}&cmd=list\" role=\"button\">Device List</a>")
                                   .Replace($"<input type=hidden name=pn value={pt}>", $"<input type=\"hidden\" name=\"pn\" value=\"{pt}\"/>{System.Environment.NewLine}");

                        //
                        html_raw = Regex.Replace(html_raw, @"Act\s+(<input[^>]+>)\s+(<input[^>]+>)<br>", (Match match) =>
                        {
                            return("<div class=\"input-group mb-3\">" +
                                   "<div class=\"input-group-prepend\">" +
                                   "<span class=\"input-group-text\">Act</span>" +
                                   "</div>" +
                                   match.Groups[1].Value.Replace("<input", "<input type=\"text\" class=\"form-control\"") +
                                   "<div class=\"input-group-append\">" +
                                   "<div class=\"input-group-text\">" +
                                   match.Groups[2].Value +
                                   "</div></div></div>");
                        });
                        //
                        html_raw = Regex.Replace(html_raw, @"Net\s+(<input[^>]+>)\s+(<input[^>]+>)<br>", (Match match) =>
                        {
                            return("<div class=\"input-group mb-3\">" +
                                   "<div class=\"input-group-prepend\">" +
                                   "<span class=\"input-group-text\">Net</span>" +
                                   "</div>" +
                                   match.Groups[1].Value.Replace("<input", "<input type=\"text\" class=\"form-control\"") +
                                   "<div class=\"input-group-append\">" +
                                   "<div class=\"input-group-text\">" +
                                   match.Groups[2].Value +
                                   "</div></div></div>");
                        });
                        //
                        html_raw = Regex.Replace(html_raw, @"Mode\s+(<select name=m.+</select>)\s+(<input[^>]+>)<br>", (Match match) =>
                        {
                            return("<div class=\"input-group mb-3\">" +
                                   "<div class=\"input-group-prepend\">" +
                                   "<span class=\"input-group-text\">Mode</span>" +
                                   "</div>" +
                                   match.Groups[1].Value.Replace("<select", "<select class=\"custom-select\"") +
                                   "<div class=\"input-group-append\">" +
                                   "<div class=\"input-group-text\">" +
                                   match.Groups[2].Value +
                                   "</div></div></div>");
                        });

                        html_raw = html_raw.Replace("Mode <select name=m>", "Mode <select class=\"form-control\" name=m>")
                                   .Replace("Default: <select name=d", "Default: <select class=\"form-control\" name=d");

                        string config_port_help_html;
                        using (StreamReader sr = new StreamReader(Assets.Open("config-port-help.html")))
                        {
                            config_port_help_html = sr.ReadToEnd();
                            //using (StreamWriter sw = new StreamWriter(MyWebViewClient.config_port_help_html, false))
                            //{
                            //    await sw.WriteAsync(await sr.ReadToEndAsync());
                            //}
                        }

                        html_raw += $"{System.Environment.NewLine}<div class=\"alert alert-info mt-3\" role=\"alert\"><h6>Информация</h6>" +
                                    "<p>Поле <strong>Type</strong> может принимать следующие значения:<br/>" +
                                    "<code>IN</code> - Вход(например, \"сухой контакт, выключатели света\", U - Sensor, датчик протечки, охранные датчики и т.д.)<br/>" +
                                    "<code>OUT</code> - Выход(например, включение электроприборов)<br/>" +
                                    "<code>DSen</code> - Цифровой датчик(например, датчики температуры DS18B20, температуры - влажности DHT22, считыватели iButton, Wiegand - 26)<br/>" +
                                    "<code>I2C</code> - Датчики или иные устройств, подключаемые по шине I2C<br/>" +
                                    "<code>ADC</code> - АЦП, аналого - цифровой преобразователь(например, подключение аналоговых датчиков освещенности, давления, газа и т.д.) Доступен не для всех портов.</p>" +
                                    "</div>" + config_port_help_html;
                        config_port_help_html = null;
                    }
                }
                /////////////////////////////////////////////////////////////
                /// настройки: начальное навигационное окно
                else
                {
                    onload_js = MyWebViewClient.onload_root_js;
                    if (!external_web_mode)
                    {
                        foreach (string s in supported_firmwares)
                        {
                            external_web_mode = html_raw.Contains(s);
                            if (external_web_mode)
                            {
                                break;
                            }
                        }
                    }

                    if (external_web_mode)
                    {
                        html_raw = a_href_regex.Replace(html_raw.Replace("<br>", string.Empty), (Match m) =>
                        {
                            switch (m.Groups[2].Value.ToLower())
                            {
                            case "config":
                                return($"<a href=\"{m.Groups[1].Value}\" class=\"btn btn-primary btn-block mt-2\" role=\"button\">{m.Groups[2].Value}</a>");

                            case "xp1":
                                return($"<a href=\"{m.Groups[1].Value}\" class=\"btn btn-outline-info btn-block\" role=\"button\">{m.Groups[2].Value} // P0-P13 & P14</a>");

                            case "xp2":
                                return($"<a href=\"{m.Groups[1].Value}\" class=\"btn btn-outline-info btn-block\" role=\"button\">{m.Groups[2].Value} // P15(0)-P28(13) & P29(14)</a>");

                            case "ab-log.ru":
                                return($"<a href=\"{m.Groups[1].Value}\"><u>{m.Groups[2].Value}</u></a>");

                            default:
                                return($"<a href=\"{m.Groups[1].Value}\" class=\"btn btn-outline-primary btn-block\" role=\"button\">{m.Groups[2].Value}</a>");
                            }
                        });
                    }
                }

                if (html_raw == "Unauthorized")
                {
                    html_raw +=
                        "<div style=\"color: #721c24; background-color: #f8d7da; border-color: #f5c6cb; margin-top: 1rem; padding: .75rem 1.25rem; margin-bottom: 1rem; border: 1px solid transparent; box-sizing: border-box; font-size: 1rem; font-weight: 400; line-height: 1.5;\">" +
                        $"Пароль доступа неверный</div>";
                }
                else if (!external_web_mode && html_raw.Length > 12 && html_raw != "Unauthorized")
                {
                    html_raw +=
                        "<div style=\"color: #856404; background-color: #fff3cd; border-color: #ffeeba; margin-top: 1rem; padding: .75rem 1.25rem; margin-bottom: 1rem; border: 1px solid transparent; box-sizing: border-box; font-size: 1rem; font-weight: 400; line-height: 1.5;\">" +
                        $"Режим модифицированого WEB интерфейса отключён. Версия вашей прошивки не поддерживается.<hr/>Поддерживаются прошивки: <span style=\"color: #fff;background-color: #007bff;display: inline-block;padding: .25em .4em;font-size: 75%;font-weight: 700;line-height: 1;text-align: center;white-space: nowrap;vertical-align: baseline;border-radius: .25rem;box-sizing: border-box;\">{String.Join("</span><span style=\"color: #fff;background-color: #007bff;display: inline-block;padding: .25em .4em;font-size: 75%;font-weight: 700;line-height: 1;text-align: center;white-space: nowrap;vertical-align: baseline;border-radius: .25rem;box-sizing: border-box;\">", supported_firmwares)}</span></div>";
                }
                else
                {
                    html_raw =
                        $"<link rel=\"stylesheet\" href=\"file:///{MyWebViewClient.bootstrap_min_css}\">" + System.Environment.NewLine +
                        $"<script src=\"file:///{MyWebViewClient.jquery_slim_min_js}\"></script>" + System.Environment.NewLine +
                        $"<script src=\"file:///{MyWebViewClient.popper_min_js}\" ></script>" + System.Environment.NewLine +
                        $"<script src=\"file:///{MyWebViewClient.bootstrap_min_js}\"></script>" + System.Environment.NewLine +
                        $"<script src=\"file:///{onload_js}\"></script>" + System.Environment.NewLine + html_raw;
                }
            });

            webView.LoadDataWithBaseURL(url, html_raw, "text/html", "utf-8", url);

            HardwareSystemSettingsLayout.RemoveAllViews();
            HardwareSystemSettingsLayout.AddView(webView);
        }
コード例 #31
0
        /// <summary>
        ///     Deletes all the connections and saves their data (the start and end port)
        ///     so that they can be recreated if needed.
        /// </summary>
        /// <param name="inportConnections">A list of connections that will be destroyed</param>
        /// <param name="outportConnections"></param>
        private void SaveAndDeleteConnectors(IDictionary inportConnections, IDictionary outportConnections)
        {
            //----------------------------Inputs---------------------------------
            foreach (var portModel in InPorts)
            {
                var portName = portModel.ToolTipContent;
                if (portModel.Connectors.Count != 0)
                {
                    inportConnections.Add(portName, new List <PortModel>());
                    foreach (var connector in portModel.Connectors)
                    {
                        (inportConnections[portName] as List <PortModel>).Add(connector.Start);
                    }
                }
                else
                {
                    inportConnections.Add(portName, null);
                }
            }

            //Delete the connectors
            foreach (PortModel inport in InPorts)
            {
                inport.DestroyConnectors();
            }

            //Clear out all the port models
            for (int i = InPorts.Count - 1; i >= 0; i--)
            {
                InPorts.RemoveAt(i);
            }


            //----------------------------Outputs---------------------------------
            for (int i = 0; i < OutPorts.Count; i++)
            {
                PortModel portModel = OutPorts[i];
                string    portName  = portModel.ToolTipContent;
                if (portModel.ToolTipContent.Equals(Formatting.TOOL_TIP_FOR_TEMP_VARIABLE))
                {
                    portName += i.ToString(CultureInfo.InvariantCulture);
                }
                if (portModel.Connectors.Count != 0)
                {
                    outportConnections.Add(portName, new List <PortModel>());
                    foreach (ConnectorModel connector in portModel.Connectors)
                    {
                        (outportConnections[portName] as List <PortModel>).Add(connector.End);
                    }
                }
                else
                {
                    outportConnections.Add(portName, null);
                }
            }

            //Delete the connectors
            foreach (PortModel outport in OutPorts)
            {
                outport.DestroyConnectors();
            }

            //Clear out all the port models
            for (int i = OutPorts.Count - 1; i >= 0; i--)
            {
                OutPorts.RemoveAt(i);
            }
        }
コード例 #32
0
 // Restore default button/window text and trigger UI update
 private void Node_PortDisconnected(PortModel obj)
 {
     SelectedItems = new Dictionary <string, DMSurface>();
 }
コード例 #33
0
        void BeginConnection(Guid nodeId, int portIndex, PortType portType)
        {
            bool isInPort = portType == PortType.Input;
            activeStartPort = null;

            var node = CurrentWorkspace.GetModelInternal(nodeId) as NodeModel;
            if (node == null)
                return;
            PortModel portModel = isInPort ? node.InPorts[portIndex] : node.OutPorts[portIndex];

            // Test if port already has a connection, if so grab it and begin connecting 
            // to somewhere else (we don't allow the grabbing of the start connector).
            if (portModel.Connectors.Count > 0 && portModel.Connectors[0].Start != portModel)
            {
                activeStartPort = portModel.Connectors[0].Start;
                // Disconnect the connector model from its start and end ports
                // and remove it from the connectors collection. This will also
                // remove the view model.
                ConnectorModel connector = portModel.Connectors[0];
                if (CurrentWorkspace.Connectors.Contains(connector))
                {
                    var models = new List<ModelBase> { connector };
                    CurrentWorkspace.RecordAndDeleteModels(models);
                    connector.Delete();
                }
            }
            else
            {
                activeStartPort = portModel;
            }
        }
コード例 #34
0
        public PortStateDataResponse(PortModel portModel)
        {
            Name           = portModel.AreaName;
            PortType       = portModel.PortType;
            GoodCategories = new List <IPortGoodCategory>();

            // TODO: Clean this up to be less verbose.
            var ships       = new PortGoodCategory <PortGood>("Ships", new List <PortGood>());
            var weapons     = new PortGoodCategory <PortGood>("Weapons", new List <PortGood>());
            var resources   = new PortGoodCategory <PortGood>("Resources", new List <PortGood>());
            var defenses    = new PortGoodCategory <PortGood>("Planetary Defenses", new List <PortGood>());
            var consumables = new PortGoodCategory <PortGood>("Consumables", new List <PortGood>());//Would be nice to have things to repair health, give temp buffs, etc...
            var components  = new PortGoodCategory <PortGood>("Components", new List <PortGood>());
            var modules     = new PortGoodCategory <PortGood>("Modules", new List <PortGood>());

            foreach (var uidata in portModel.Cargo.UIComponent.Goods)
            {
                var category      = PortHelper.GetPortGoodCategory(uidata.Key);
                var quantity      = portModel.Cargo.PortGoodCounts[uidata.Key];
                var purchasePrice = portModel.Cargo.Prices_ShipPurchaseFromPort[uidata.Key];

                switch (category)
                {
                case PortGoodCategory.Ship:
                {
                    var pg = new PortGood(uidata.Key, uidata.Value, "asseturl", purchasePrice, quantity);
                    ships.Goods.Add(pg);
                    break;
                }

                case PortGoodCategory.Weapon:
                {
                    var pg = new PortGood(uidata.Key, uidata.Value, "asseturl", purchasePrice, quantity);
                    weapons.Goods.Add(pg);
                    break;
                }

                case PortGoodCategory.Resource:
                {
                    var pg = new PortGood(uidata.Key, uidata.Value, "assetUrl", purchasePrice, quantity);
                    resources.Goods.Add(pg);
                    break;
                }

                case PortGoodCategory.Defenses:
                {
                    var pg = new PortGood(uidata.Key, uidata.Value, "asseturl", purchasePrice, quantity);
                    defenses.Goods.Add(pg);
                    break;
                }

                case PortGoodCategory.Consumables:
                {
                    var pg = new PortGood(uidata.Key, uidata.Value, "asseturl", purchasePrice, quantity);
                    consumables.Goods.Add(pg);
                    break;
                }

                case PortGoodCategory.Components:
                {
                    var pg = new PortGood(uidata.Key, uidata.Value, "asseturl", purchasePrice, quantity);
                    components.Goods.Add(pg);
                    break;
                }
                }
            }


            foreach (var m in portModel.Cargo.UIComponent.Modules)
            {
                var purchasePrice = 666f;//I don't know exactly how we're going to get the purchase price yet

                var pg = new ModulePortGood(m.Key, PortWareIdentifier.Module, m.Value, "asseturl", purchasePrice, 1);
                modules.Goods.Add(pg);
            }



            GoodCategories.Add(ships);
            GoodCategories.Add(weapons);
            GoodCategories.Add(resources);
            GoodCategories.Add(defenses);
            GoodCategories.Add(consumables);
            GoodCategories.Add(components);
            GoodCategories.Add(modules);
        }
コード例 #35
0
        static Dictionary<ModelBase, UndoRedoRecorder.UserAction> GetConnectorsToAddAndDelete(
            PortModel endPort, PortModel startPort)
        {
            ConnectorModel connectorToRemove = null;

            // Remove connector if one already exists
            if (endPort.Connectors.Count > 0 && endPort.PortType == PortType.Input)
            {
                connectorToRemove = endPort.Connectors[0];
                connectorToRemove.Delete();
            }

            // We could either connect from an input port to an output port, or 
            // another way around (in which case we swap first and second ports).
            PortModel firstPort, secondPort;
            if (endPort.PortType != PortType.Input)
            {
                firstPort = endPort;
                secondPort = startPort;
            }
            else
            {
                // Create the new connector model
                firstPort = startPort;
                secondPort = endPort;
            }

            ConnectorModel newConnectorModel = ConnectorModel.Make(
                firstPort.Owner,
                secondPort.Owner,
                firstPort.Index,
                secondPort.Index);

            // Record the creation of connector in the undo recorder.
            var models = new Dictionary<ModelBase, UndoRedoRecorder.UserAction>();
            if (connectorToRemove != null)
            {
                models.Add(connectorToRemove, UndoRedoRecorder.UserAction.Deletion);
            }
            models.Add(newConnectorModel, UndoRedoRecorder.UserAction.Creation);
            return models;
        }
コード例 #36
0
        public T AddLink <T>(PortModel source, PortModel?target = null) where T : LinkModel
        {
            var link = (T)Activator.CreateInstance(typeof(T), source, target);

            return(AddLink(link, source, target));
        }
コード例 #37
0
ファイル: NodeViewModel.cs プロジェクト: mikeyforrest/Dynamo
 /// <summary>
 /// Registers the port events.
 /// </summary>
 /// <param name="item">PortModel.</param>
 /// <returns></returns>
 private PortViewModel SubscribePortEvents(PortModel item)
 {
     PortViewModel portViewModel = new PortViewModel(this, item);            
     portViewModel.MouseEnter += OnRectangleMouseEnter;
     portViewModel.MouseLeave += OnRectangleMouseLeave;
     portViewModel.MouseLeftButtonDown += OnMouseLeftButtonDown;
     return portViewModel;
 }
コード例 #38
0
 internal void CancelConnection()
 {
     multipleConnections = false;
     this.SetActiveConnectors(null);
     firstStartPort = null;
 }
コード例 #39
0
 protected virtual void PortDisconnectedHandler(PortModel port)
 {
     if (port.PortType == PortType.Input)
     {
         DeleteGeometryForIdentifier(port.Owner.AstIdentifierBase);
     }
 }
コード例 #40
0
        void EndConnection(Guid nodeId, int portIndex, PortType portType)
        {
            bool isInPort = portType == PortType.Input;

            var node = CurrentWorkspace.GetModelInternal(nodeId) as NodeModel;
            if (node == null)
                return;
            
            PortModel portModel = isInPort ? node.InPorts[portIndex] : node.OutPorts[portIndex];

            var models = GetConnectorsToAddAndDelete(portModel, activeStartPort);

            WorkspaceModel.RecordModelsForUndo(models, CurrentWorkspace.UndoRecorder);
            activeStartPort = null;
        }