Example #1
0
        public bool CanEqualiseWithThis(PipeData Pipe)
        {
            if (Pipe.NetCompatible == false)
            {
                return(PipeFunctions.CanEqualiseWith(this.pipeData, Pipe));
            }

            return(true);
        }
Example #2
0
        protected override void HandleMessage(object data)
        {
            PipeData pipeData = data as PipeData;

            if (OnPipeReceive != null)
            {
                OnPipeReceive.Invoke(this, new PipeRecieveEventArgs {
                    Data = pipeData.Data, Client = _pipe
                });
            }
        }
Example #3
0
 public void PipeMessage(NamedPipeConnection <PipeData, PipeData> conn, PipeData message)
 {
     Console.WriteLine("Received " + message.id);
     if (message.id == "SigWorldData")
     {
         SigWorldData data = (SigWorldData)message.data.ToObject();
         if (data != null)
         {
             Console.WriteLine(string.Format("CLIENT WORLD: {0}", data.world));
         }
     }
 }
Example #4
0
        /// <summary>
        /// Parse the source text for pipe token and replace
        /// the token with the correct text depending on the
        /// given survey answers
        /// </summary>
        public string PipeValuesInText(int questionId, string sourceText, VoterAnswersData.VotersAnswersDataTable surveyAnswers, string languageCode)
        {
            Regex regex = new Regex(@"\[{2}((\S)+)\]{2}");

            if (surveyAnswers != null)
            {
                Match match = regex.Match(sourceText);
                if (match.Success)
                {
                    if (HttpContext.Current != null)
                    {
                        if (HttpContext.Current.Cache["NSurvey:PipeData"] == null)
                        {
                            HttpContext.Current.Cache.Insert("NSurvey:PipeData", new Surveys().GetSurveyPipeDataFromQuestionId(questionId), null, DateTime.Now.AddMinutes(1.0), TimeSpan.Zero);
                        }
                        this._pipeData = (PipeData)HttpContext.Current.Cache["NSurvey:PipeData"];
                    }
                    else
                    {
                        this._pipeData = new Surveys().GetSurveyPipeDataFromQuestionId(questionId);
                    }
                    while (match.Success)
                    {
                        string str = match.Groups[1].ToString();
                        if (str.Length > 0)
                        {
                            PipeData.QuestionsRow[] rowArray = (PipeData.QuestionsRow[]) this._pipeData.Questions.Select("QuestionPipeAlias='" + str + "'");
                            if (rowArray.Length > 0)
                            {
                                sourceText = sourceText.Replace("[[" + str + "]]", this.PipeQuestionAnswers(rowArray[0].QuestionId, surveyAnswers, languageCode));
                            }
                            else
                            {
                                PipeData.AnswersRow[] rowArray2 = (PipeData.AnswersRow[]) this._pipeData.Answers.Select("AnswerPipeAlias='" + str + "'");
                                if (rowArray2.Length > 0)
                                {
                                    sourceText = sourceText.Replace("[[" + str + "]]", this.PipeAnswerText(rowArray2[0].AnswerId, surveyAnswers));
                                }
                            }
                        }
                        match = match.NextMatch();
                    }
                }
                match = regex.Match(sourceText);
                if ((match.Length > 0) && (this.previousMatchCount != match.Length))
                {
                    this.previousMatchCount = match.Length;
                    return(this.PipeValuesInText(questionId, sourceText, surveyAnswers, languageCode));
                }
            }
            return(sourceText);
        }
Example #5
0
 private void LoadLinkRoutes(Object s, EventArgs e)
 {
     // just set the Route points once per Load
     myDiagram.LayoutCompleted -= LoadLinkRoutes;
     foreach (Link link in myDiagram.Links)
     {
         PipeData d = link.Data as PipeData;
         if (d == null || d.Points == null)
         {
             continue;
         }
         link.Route.Points = (IList <Point>)d.Points;
     }
     myDiagram.PartManager.UpdatesRouteDataPoints = true; // OK for CustomPartManager to update PipeData.Points automatically
 }
Example #6
0
        public void Start()
        {
            var task = Task.Factory.StartNew(() =>
            {
                var server = new NamedPipeServerStream(this.pipeName);
                server.WaitForConnection();
                StreamReader reader = new StreamReader(server);
                StreamWriter writer = new StreamWriter(server);
                while (true)
                {
                    var line = reader.ReadLine();

                    PipeData pipeData    = new PipeData();
                    pipeData.PipeDataStr = line;
                    this.OnPipeDataReceived(pipeData);

                    writer.Flush();
                }
            });
        }
Example #7
0
        private void LoadFolderData()
        {
            Working(true);

            //new Thread(() =>
            //{

            foreach (String file in Directory.GetFiles(SelectedFolder, "MAR*.tmp"))
            {
                PipeData p = PipeData.ParsePipeData(file);
                Disp(() =>
                {
                    PipeDataCollection.Add(p);
                    OnPropertyChanged("PipeDataCollection");
                });
            }

            Working(false);

            // });

            PipeDataCollectionOriginal = new ReadOnlyObservableCollection <PipeData>(PipeDataCollection);
        }
Example #8
0
        // save and load the model data as XML, visible in the "Saved" tab of the Demo
        private void Save_Click(object sender, RoutedEventArgs e)
        {
            var model = myDiagram.Model as MyModel;

            if (model == null)
            {
                return;
            }
            // no data-binding of Route.Points means we have to copy the Points data explicitly
            foreach (Link link in myDiagram.Links)
            {
                PipeData d = link.Data as PipeData;
                if (d == null)
                {
                    continue;
                }
                d.Points = link.Route.Points;
            }
            XElement root = model.Save <ItemData, PipeData>("Diagram", "Item", "Pipe");

            Demo.MainPage.Instance.SavedXML = root.ToString();
            LoadButton.IsEnabled            = true;
            model.IsModified = false;
        }
Example #9
0
 public void RemovePipe(PipeData pipeData)
 {
     pipeList.Remove(pipeData);
 }
Example #10
0
 public void AddPipe(PipeData pipeData)
 {
     pipeList.Add(pipeData);
 }
Example #11
0
 private void ProcessPipe(PipeData pipeData)
 {
     pipeData.TickUpdate();
 }
Example #12
0
 //This makes it so electrical Stuff can be done on its own thread
 public void SetPipeData(PipeData InPipeData)
 {
     //Logger.Log("seting " + this.name);
     pipeData = InPipeData;
 }
 public void RemovePipe(PipeData pipeData)
 {
     pipeToAdd.TryTake(out pipeData);
 }
 public void AddPipe(PipeData pipeData)
 {
     pipeToAdd.Add(pipeData);
 }
Example #15
0
 protected virtual void OnPipeDataReceived(PipeData e)
 {
     PipeDataReceived?.Invoke(this, e);
 }
Example #16
0
        public void PipeMessage(NamedPipeConnection <PipeData, PipeData> conn, PipeData message)
        {
            Type type = Type.GetType(message.id + ",FFMemoryParser");

            if (type == null)
            {
                return;
            }

            Object obj = message.data.ToObject();

            if (obj != null)
            {
                if (type.Name == "SignatureList")
                {
                    Memory.SignatureList data = (obj as Memory.SignatureList);
                    if (data != null)
                    {
                        foreach (Signature item in data)
                        {
                            Console.WriteLine(string.Format("Signature {0} Not found!", item.Key));
                        }
                    }
                }

                if (type.Name == "SigWorldData")
                {
                    SigWorldData data = (obj as SigWorldData);
                    if (data != null)
                    {
                        World = data.world;
                    }
                }
                if (type.Name == "SigCharIdData")
                {
                    SigCharIdData data = (obj as SigCharIdData);
                    if (data != null)
                    {
                        CharacterID = data.id;
                        OnCharacterId?.Invoke(this, CharacterID);
                    }
                }
                // ...
                if (type.Name == "SigPerfData")
                {
                    SigPerfData data = (obj as SigPerfData);
                    if (data != null)
                    {
                        performanceData = data;

                        OnPerformanceChanged?.Invoke(this, performanceData);
                    }
                }
                if (type.Name == "SigActorsData")
                {
                    SigActorsData data = (obj as SigActorsData);
                    if (data != null)
                    {
                        actorData = data;

                        ActorData local = null;
                        if (actorData.currentActors.Count > 0)
                        {
                            local = actorData.currentActors.First().Value;
                        }
                        if (localPlayer == null || local.name != localPlayer.name)
                        {
                            localPlayer = local;
                            if (localPlayer != null)
                            {
                                OnLocalPlayerLogin?.Invoke(this, localPlayer);
                            }
                            else
                            {
                                OnLocalPlayerLogout?.Invoke(this, localPlayer);
                            }
                        }
                    }
                }
                if (type.Name == "SigChatLogData")
                {
                    SigChatLogData data = (obj as SigChatLogData);
                    if (data != null)
                    {
                        foreach (ChatLogItem item in data.chatMessages)
                        {
                            OnChatReceived?.Invoke(this, item);
                        }
                    }
                }
                if (type.Name == "SigChatInputData")
                {
                    SigChatInputData data = (obj as SigChatInputData);
                    if (data != null)
                    {
                        ChatInputOpen = data.open;
                        if (data.open)
                        {
                            Console.WriteLine(data.text);
                        }
                    }
                }
            }
        }
Example #17
0
        protected override void DropOnto(System.Windows.Point pt)
        {
            // handle dropped "Instrument"s by adding them to the Link's LabelNode (a Group)
            // and by remembering the position of the label relative to a segment of the Link.Route
            var newlabs = this.Diagram.SelectedParts.OfType <Node>().Where(n => Labelable(n)).ToList();

            if (newlabs.Count() > 0)
            {
                // see if the user is dropping onto a Link
                Link overlink = this.Diagram.Panel.FindElementAt <Link>(pt, Part.FindAncestor <Link>, p => ConsiderDragOver(pt, p), SearchLayers.Links);
                if (overlink != null)
                {
                    PipeData linkdata = overlink.Data as PipeData;
                    MyModel  model    = this.Diagram.Model as MyModel;
                    if (linkdata != null && model != null)
                    {
                        // get link's existing label group
                        ItemData labelgroup = model.GetLabelNodeForLink(linkdata);
                        if (labelgroup == null) // create it if it doesn't have one already
                        {
                            labelgroup = new InstrumentData()
                            {
                                Key = "LG", IsSubGraph = true
                            };
                            model.AddNode(labelgroup); // will provide unique Key for new group
                            model.SetLinkLabelKey(linkdata, labelgroup.Key);
                        }
                        // add each dropped label to link's label group
                        foreach (Node lab in newlabs)
                        {
                            ItemData labdata = lab.Data as ItemData;
                            if (labdata != null)
                            {
                                model.SetGroupNodeKey(labdata, labelgroup.Key);
                            }
                        }
                    }
                }
                // find closest segment for each label node and remember it and its offset
                foreach (Node lab in newlabs)
                {
                    InstrumentData labdata = lab.Data as InstrumentData;
                    if (labdata == null)
                    {
                        continue;
                    }
                    Group labcoll = lab.ContainingSubGraph;
                    if (labcoll == null)
                    {
                        continue;
                    }
                    Link link = labcoll.LabeledLink;
                    if (link != null)
                    {
                        Point labc = new Point(lab.Bounds.X + lab.Bounds.Width / 2, lab.Bounds.Y + lab.Bounds.Height / 2);
                        var   pts  = link.Route.Points;
                        if (pts.Count < 2)
                        {
                            continue;
                        }
                        int idx = link.Route.FindClosestSegment(labc);
                        if (idx >= pts.Count - 1)
                        {
                            idx = pts.Count - 2;
                        }
                        labdata.Index = idx;
                        Point a = pts[idx];
                        Point b = pts[idx + 1];
                        if (Math.Abs(a.Y - b.Y) < 0.1)
                        {
                            if (a.X < b.X)
                            {
                                labdata.Fraction = (labc.X <= a.X ? 0 : (labc.X >= b.X ? 1 : (labc.X - a.X) / (b.X - a.X)));
                                labdata.Location = new Point(0, labc.Y - a.Y);
                            }
                            else
                            {
                                labdata.Fraction = (labc.X >= a.X ? 0 : (labc.X <= b.X ? 1 : (labc.X - a.X) / (b.X - a.X)));
                                labdata.Location = new Point(0, a.Y - labc.Y);
                            }
                        }
                        else
                        {
                            if (a.Y < b.Y)
                            {
                                labdata.Fraction = (labc.Y <= a.Y ? 0 : (labc.Y >= b.Y ? 1 : (labc.Y - a.Y) / (b.Y - a.Y)));
                                labdata.Location = new Point(0, a.X - labc.X);
                            }
                            else
                            {
                                labdata.Fraction = (labc.Y >= a.Y ? 0 : (labc.Y <= b.Y ? 1 : (labc.Y - a.Y) / (b.Y - a.Y)));
                                labdata.Location = new Point(0, labc.X - a.X);
                            }
                        }
                    }
                }
            }
            else
            {
                // rotate dropped "Valve"s
                newlabs = this.Diagram.SelectedParts.OfType <Node>().Where(n => Spliceable(n)).ToList();
                if (newlabs.Count() > 0)
                {
                    // see if the user is dropping onto a Link
                    Link    overlink = this.Diagram.Panel.FindElementAt <Link>(pt, Part.FindAncestor <Link>, p => ConsiderDragOver(pt, p), SearchLayers.Links);
                    MyModel model    = this.Diagram.Model as MyModel;
                    if (overlink != null && model != null)
                    {
                        // get the data representing a Pipe
                        PipeData oldlinkdata = overlink.Data as PipeData;
                        // get the Group holding Instruments for the Pipe, if any
                        ItemData labelgroup = model.GetLabelNodeForLink(oldlinkdata);
                        var      pts        = overlink.Route.Points;
                        if (pts.Count >= 2)
                        {
                            // maybe rotate the Valve nodes
                            foreach (Node lab in newlabs)
                            {
                                Point labc = new Point(lab.Bounds.X + lab.Bounds.Width / 2, lab.Bounds.Y + lab.Bounds.Height / 2);
                                int   idx  = overlink.Route.FindClosestSegment(labc);
                                if (idx >= pts.Count - 1)
                                {
                                    idx = pts.Count - 2;
                                }
                                Point a = pts[idx];
                                Point b = pts[idx + 1];
                                // if the valve were bi-directional, this needs to be smarter?
                                int angle = 0;
                                if (Math.Abs(a.Y - b.Y) < 0.1) // horizontal
                                {
                                    angle = (a.X < b.X ? 0 : 180);
                                }
                                else
                                {
                                    angle = (a.Y < b.Y ? 90 : 270);
                                }
                                lab.RotationAngle = angle;
                                // the StackPanel.Orientation governs the relative position of the TextBlock;
                                // it is bound to the Node.RotationAngle using a ValveOrientationConverter
                            }
                        }
                        base.DropOnto(pt); // this will splice the Valve(s) into the Link
                        if (oldlinkdata != null)
                        {
                            // find one of the new Pipes
                            PipeData newlinkdata = model.GetFromLinksForNode(newlabs.First().Data as ItemData).First();
                            // this is the label group holding all of the Instruments of the original Link
                            if (labelgroup != null)
                            {
                                // attach the old group of Instruments to the new Pipe
                                model.AddNode(labelgroup);
                                model.SetLinkLabelKey(newlinkdata, labelgroup.Key);
                            }
                        }
                    }
                }
                else // handle regular nodes
                {
                    base.DropOnto(pt);
                }
            }
        }