Exemplo n.º 1
0
            void FindString(string text, int startIndex, int endIndex, string[] words)
            {
                int storedStartIndex = startIndex;
                for (int i = 0; i < words.Length; ++i)
                {
                    while (true)
                    {
                        int index = text.IndexOf(words[i], startIndex);
                        if (index < 0)
                        {
                            startIndex++;
                        }
                        else
                        {
                            // ilbe?
                            Info info = new Info();
                            info.startIndex = index;
                            info.endIndex = index + words[i].Length;
                            ilbeInfo.Add(info);

                            startIndex = index + words[i].Length;
                        }

                        if (startIndex >= endIndex)
                        {
                            startIndex = storedStartIndex;
                            break;
                        }
                    }
                }
            }
Exemplo n.º 2
0
 internal void setInfoTime(Info info)
 {
     this.serietextBox1.Text = info.serie;
     this.chansontextBox1.Text = info.chanson;
     this.languagecomboBox2.Text = info.language;
     this.numerocomboBox2.Text = info.num.ToString();
     this.typecomboBox1.Text = info.type;
 }
Exemplo n.º 3
0
        public InfoTreeViewModel(Info _rootInfo)
        {
            this.rootInfo = new InfoViewModel(_rootInfo);

            this.firstGeneration = new ReadOnlyCollection<InfoViewModel>(
                    new InfoViewModel[] {
                        this.rootInfo
                    });
        }
Exemplo n.º 4
0
        private InfoViewModel(Info _info, InfoViewModel _parent)
        {
            this.info = _info;
            this.parent = _parent;

            this.children = new ReadOnlyCollection<InfoViewModel>(
                (from __child in this.info.Children
                 select new InfoViewModel(__child, this))
                 .ToList<InfoViewModel>());
        }
Exemplo n.º 5
0
        private void button2_Click(object sender, EventArgs e)
        {
            Info info = new Info("", "", 0, "", "", "");
            switch (this.mode)
            {

                case Emode.CHANGE_TIME_NAME:
                    ((TimingMadShoken.mainForm)Owner).setTimeName(info);
                    break;
                case Emode.NOUVEAU_TIME:
                    ((TimingMadShoken.mainForm)Owner).nouveauTime(info);
                    break;
            }
        }
Exemplo n.º 6
0
    private void Run_Click(object sender, RoutedEventArgs e)
        {

            setup();
            worker.DoWork += delegate (object s, DoWorkEventArgs args)
            {
                    do
                    {           
                        // Generate mating pool
                        population.naturalSelection();
                        //Create next generation
                        population.generate();
                        // Calculate fitness
                        population.calcFitness();
                        // If we found the target phrase, stop
                        if (population.isFinished())
                        {
                        break;
                        }
                    Info i = new Info();
                    i.BestAnswer = population.getBest();
                    i.Generations = population.getGenerations();
                    i.AverageFitness = Math.Round(population.getAverageFitness(),4);
                    i.PopulationMax = popmax;
                    i.AllPhrases = population.allPhrases();
                    i.MutationsRate = mutationRate;
                    worker.ReportProgress(0,i);

                    }
                    while (true);
                };
            worker.ProgressChanged += delegate (object s, ProgressChangedEventArgs args)
            {
                Info info = (Info)args.UserState;
                txtBestAnswer.Content = info.BestAnswer;
                txtTotalGeneration.Content = info.Generations;
                txtAvgFitness.Content = info.AverageFitness.ToString();
                txtTotalPopulation.Text = Convert.ToString(popmax);
                txtMutationRate.Text = Convert.ToString(mutationRate);
                txtPhrases.Content = info.AllPhrases;

            };
            worker.RunWorkerCompleted += delegate (object se, RunWorkerCompletedEventArgs rwe)
            {

            };
            worker.RunWorkerAsync();
        }
Exemplo n.º 7
0
        private void button1_Click(object sender, EventArgs e)
        {
            int num = 0;
            int.TryParse(this.numerocomboBox2.Text, out num);

            Info info = new Info(this.serietextBox1.Text, this.typecomboBox1.Text
                , num
                , chansontextBox1.Text, this.languagecomboBox2.Text, this.artistetextBox.Text);

            switch (this.mode)
            {
                case Emode.CHANGE_TIME_NAME:
                    ((TimingMadShoken.mainForm)Owner).setTimeName(info);
                    break;
                case Emode.NOUVEAU_TIME:
                    ((TimingMadShoken.mainForm)Owner).nouveauTime(info);
                    break;
            }
        }
Exemplo n.º 8
0
 private void ProjectsInfo_Load()
 {
     StreamReader sr = null;
     string line;
     try {
         sr = File.OpenText("projects.dat");
         projectInfoList = new List<Info>();
         while ((line = sr.ReadLine()) != null) {
             if (line.StartsWith("#")) {
                 Info item = new Info();
                 sr.ReadLine();
                 item.Name = sr.ReadLine();
                 for (int i = 0; i < 3; i++)
                     sr.ReadLine();
                 item.Members = sr.ReadLine().Split(new char[] { '|' });
                 projectInfoList.Add(item);
             }
         }
     } catch (FileNotFoundException fe) {
         Console.WriteLine(fe.StackTrace);
         MessageBox.Show("读取项目数据信息失败!", "提示");
         Application.Exit();
     } finally {
         if (sr != null)
             sr.Close();
     }
     bsProjectInfo.DataSource = projectInfoList;
     projectsListBox.DataSource = bsProjectInfo;
     projectsListBox.DisplayMember = "Name";
 }
Exemplo n.º 9
0
 private void UpdateInfo(Info gInfo)
 {
     gInfo.turn = (gInfo.turn == Players.Player1 ? Players.Player2 : Players.Player1);
     player_turn.Text = gInfo.turn.ToString();
     deck_left.Text = gInfo.deckLeft.ToString();
     player1_points.Text = gInfo.player2points.ToString();
     player1_cards.Text = gInfo.player2cards.ToString();
     player2_points.Text = gInfo.player1points.ToString();
     player2_cards.Text = gInfo.player1cards.ToString();
 }
Exemplo n.º 10
0
        private void GameOver(Info gInfo)
        {
            player_turn.Text = gInfo.turn.ToString();
             deck_left.Text = gInfo.deckLeft.ToString();
             player1_points.Text = gInfo.player2points.ToString();
             player1_cards.Text = gInfo.player2cards.ToString();
             player2_points.Text = gInfo.player1points.ToString();
             player2_cards.Text = gInfo.player1cards.ToString();

             Playing = false;

             MessageBox.Show("Score : " + gInfo.player2points + " - " + gInfo.player1points + "\n" + (gInfo.player2points > gInfo.player1points ? "Player 1" : "Player 2") + " wins ");
        }
Exemplo n.º 11
0
        private Info GetHistoricFileInfo(string fileName)
        {
            Info fileInfo = null;

            try
            {
                // Validate the file name to determine whether the given file is actually a historic file
                if (!Regex.IsMatch(fileName, string.Format(".+_.+_to_.+\\{0}$", FileExtension)))
                    return null;

                if (File.Exists(fileName))
                {
                    // We'll open the file and get relevant information about it.
                    ArchiveFile historicArchiveFile = new ArchiveFile();

                    historicArchiveFile.FileName = fileName;
                    historicArchiveFile.StateFile = m_stateFile;
                    historicArchiveFile.IntercomFile = m_intercomFile;
                    historicArchiveFile.MetadataFile = m_metadataFile;
                    historicArchiveFile.FileAccessMode = FileAccess.Read;

                    try
                    {
                        historicArchiveFile.Open();

                        fileInfo = new Info(fileName)
                        {
                            StartTimeTag = historicArchiveFile.Fat.FileStartTime,
                            EndTimeTag = historicArchiveFile.Fat.FileEndTime
                        };
                    }
                    catch (Exception ex)
                    {
                        OnHistoricFileListBuildException(new InvalidOperationException(string.Format("Failed to open historic data file \"{0}\" due to exception: {1}", FilePath.GetFileName(fileName), ex.Message), ex));
                    }
                    finally
                    {
                        historicArchiveFile.Dispose();
                    }
                }
                else
                {
                    // We'll resolve to getting the file information from its name only if the file no longer exists
                    // at the location. This will be the case when file is moved to a different location. In this
                    // case the file information we provide is only as good as the file name.
                    string datesString = FilePath.GetFileNameWithoutExtension(fileName).Substring((FilePath.GetFileNameWithoutExtension(m_fileName) + "_").Length);
                    string[] fileStartEndDates = datesString.Split(new string[] { "_to_" }, StringSplitOptions.None);

                    fileInfo = new Info(fileName);

                    if (fileStartEndDates.Length == 2)
                    {
                        fileInfo.StartTimeTag = new TimeTag(Convert.ToDateTime(fileStartEndDates[0].Replace('!', ':')));
                        fileInfo.EndTimeTag = new TimeTag(Convert.ToDateTime(fileStartEndDates[1].Replace('!', ':')));
                    }
                }
            }
            catch (Exception ex)
            {
                OnHistoricFileListBuildException(new InvalidOperationException(string.Format("Failed during information access attempt for historic data file \"{0}\" due to exception: {1}", FilePath.GetFileName(fileName), ex.Message), ex));
            }

            return fileInfo;
        }
Exemplo n.º 12
0
 private bool IsNewHistoricArchiveFile(Info fileInfo)
 {
     return (fileInfo != null &&
             string.Compare(FilePath.GetDirectoryName(m_fileName), FilePath.GetDirectoryName(fileInfo.FileName), true) == 0);
 }
Exemplo n.º 13
0
 private bool FindHistoricArchiveFileForRead(Info fileInfo)
 {
     return (fileInfo != null && ((m_readSearchStartTimeTag >= fileInfo.StartTimeTag && m_readSearchStartTimeTag <= fileInfo.EndTimeTag) ||
                                  (m_readSearchEndTimeTag >= fileInfo.StartTimeTag && m_readSearchEndTimeTag <= fileInfo.EndTimeTag) ||
                                  (m_readSearchStartTimeTag < fileInfo.StartTimeTag && m_readSearchEndTimeTag > fileInfo.EndTimeTag)));
 }
Exemplo n.º 14
0
        /// <summary>
        /// Reads <see cref="ArchiveData"/> points.
        /// </summary>
        /// <param name="historianID">Historian identifier for which <see cref="ArchiveData"/> points are to be retrieved.</param>
        /// <param name="startTime">Start <see cref="TimeTag"/> (in GMT) for the <see cref="ArchiveData"/> points to be retrieved.</param>
        /// <param name="endTime">End <see cref="TimeTag"/> (in GMT) for the <see cref="ArchiveData"/> points to be retrieved.</param>
        /// <returns><see cref="IEnumerable{T}"/> object containing zero or more <see cref="ArchiveData"/> points.</returns>
        public IEnumerable<IDataPoint> ReadData(int historianID, TimeTag startTime, TimeTag endTime)
        {
            // Ensure that the current file is open.
            if (!IsOpen)
                throw new InvalidOperationException(string.Format("\"{0}\" file is not open.", m_fileName));

            // Ensure that the current file is active.
            if (m_fileType != ArchiveFileType.Active)
                throw new InvalidOperationException("Data can only be directly read from files that are Active.");

            // Ensure that the start and end time are valid.
            if (startTime > endTime)
                throw new ArgumentException("End Time preceeds Start Time in the specified timespan.");

            // Yeild to the rollover process if it is in progress.
            m_rolloverWaitHandle.WaitOne();

            List<Info> dataFiles = new List<Info>();
            if (startTime < m_fat.FileStartTime)
            {
                // Data is to be read from historic file(s).
                if (m_buildHistoricFileListThread.IsAlive)
                    m_buildHistoricFileListThread.Join();

                m_readSearchStartTimeTag = startTime;
                m_readSearchEndTimeTag = endTime;
                lock (m_historicArchiveFiles)
                {
                    dataFiles.AddRange(m_historicArchiveFiles.FindAll(FindHistoricArchiveFileForRead));
                }
            }

            if (endTime >= m_fat.FileStartTime)
            {
                // Data is to be read from the active file.
                Info activeFileInfo = new Info();
                activeFileInfo.FileName = m_fileName;
                activeFileInfo.StartTimeTag = m_fat.FileStartTime;
                activeFileInfo.EndTimeTag = m_fat.FileEndTime;
                dataFiles.Add(activeFileInfo);
            }

            // Read data from all qualifying files.
            foreach (Info dataFile in dataFiles)
            {
                ArchiveFile file = new ArchiveFile();
                IList<ArchiveDataBlock> dataBlocks;
                try
                {
                    file.FileName = dataFile.FileName;
                    file.StateFile = m_stateFile;
                    file.IntercomFile = m_intercomFile;
                    file.MetadataFile = m_metadataFile;
                    file.Open();

                    dataBlocks = file.Fat.FindDataBlocks(historianID, startTime, endTime);
                    if (dataBlocks.Count > 0)
                    {
                        // Data block before the first data block matching the search criteria might contain some data 
                        // for the specified search criteria, so look for such a data block and process its data.
                        lock (file.Fat.DataBlockPointers)
                        {
                            for (int i = dataBlocks[0].Index - 1; i >= 0; i--)
                            {
                                if (file.Fat.DataBlockPointers[i].HistorianID == historianID)
                                {
                                    foreach (ArchiveData data in file.Fat.DataBlockPointers[i].DataBlock.Read())
                                    {
                                        if (data.Time >= startTime)
                                            yield return data;
                                    }

                                    break;
                                }
                            }
                        }

                        // Read data from rest of the data blocks and scan the last data block for data matching the
                        // the search criteria as it may contain data beyond the timespan specified in the search.
                        for (int i = 0; i < dataBlocks.Count; i++)
                        {
                            if (i < dataBlocks.Count - 1)
                            {
                                // Read all the data.
                                foreach (ArchiveData data in dataBlocks[i].Read())
                                {
                                    yield return data;
                                }
                            }
                            else
                            {
                                // Scan through the data block.
                                foreach (ArchiveData data in dataBlocks[i].Read())
                                {
                                    if (data.Time <= endTime)
                                        yield return data;
                                    else
                                        yield break;
                                }
                            }
                        }
                    }
                }
                finally
                {
                    if (file.IsOpen)
                    {
                        file.Close();
                    }
                }
            }
        }
Exemplo n.º 15
0
    /// <summary>
    /// Move a collection of <see cref="Part"/>s by a given offset.
    /// </summary>
    /// <param name="parts">
    /// a <c>Dictionary</c> of parts,
    /// mapped to <see cref="Info"/> values that include the nodes' original locations
    /// </param>
    /// <param name="offset">a <c>Point</c> value in model coordinates</param>
    /// <remarks>
    /// This respects the <see cref="Part.CanMove"/> predicate for nodes
    /// when this is the <see cref="Northwoods.GoXam.Diagram.CurrentTool"/>.
    /// This tries to avoid routing the links that are being moved.
    /// </remarks>
    public virtual void MoveParts(Dictionary<Part, Info> parts, Point offset) {
      if (parts == null || parts.Count == 0) return;
      if (Double.IsNaN(offset.X)) offset.X = 0;
      if (Double.IsNaN(offset.Y)) offset.Y = 0;
      //?? can't optimize a zero offset move, due to possible need to snap the nodes
      //if (offset.X == 0 && offset.Y == 0) return;

      bool dragging = (this.Diagram != null && this.Diagram.CurrentTool == this);
      bool wassuspended = this.SuspendedRouting;
      if (!wassuspended) SuspendRouting(parts);

      List<NodeInfoPair> nestednodes = new List<NodeInfoPair>();
      List<KeyValuePair<Part, Info>> linkkvps = new List<KeyValuePair<Part, Info>>();
      foreach (KeyValuePair<Part, Info> kvp in parts) {
        Node n = kvp.Key as Node;
        if (n != null) {
          Info ginfo = FindContainingInfo(n, parts);
          if (ginfo != null) {
            nestednodes.Add(new NodeInfoPair() { Node=n, Info=kvp.Value, GroupInfo=ginfo });
          } else if (!dragging || n.CanMove()) {  // only check CanMove() if the user is dragging
            Point oldloc = kvp.Value.Point;
            Point newloc = ComputeMove(n, new Point(oldloc.X + offset.X, oldloc.Y + offset.Y), parts);
            //Diagram.Debug("  " + Diagram.Str(n) + " from: " + Diagram.Str(oldloc) + " to: " + Diagram.Str(newloc));
            n.Location = newloc;
            kvp.Value.Shifted = Geo.Subtract(newloc, oldloc);
          }
        } else {
          Link l = kvp.Key as Link;
          if (l != null) linkkvps.Add(kvp);
        }
      }

      foreach (NodeInfoPair nip in nestednodes) {
        Point oldloc = nip.Info.Point;
        Point newloc = Geo.Add(oldloc, nip.GroupInfo.Shifted);
        nip.Node.Location = newloc;
      }

      foreach (KeyValuePair<Part, Info> kvp in linkkvps) {
        Link link = kvp.Key as Link;
        if (link == null) continue;
        Route route = link.Route;
        if (route.SuspendsRouting) {  // need to move the route explicitly
          Node from = link.FromNode;
          Node to = link.ToNode;
          if (this.DraggedLink != null && this.DraggableLinks) {
            Point oldlinkoff = kvp.Value.Point;
            parts[link] = new Info() { Point = offset };
            route.MovePoints(Geo.Subtract(offset, oldlinkoff));
          } else {
            Info info;
            Point fromoff = new Point(0, 0);
            if (from != null) {
              Point oldfromloc = new Point();
              if (parts.TryGetValue(from, out info)) oldfromloc = info.Point;
              Point newfromloc = from.Location;
              fromoff = Geo.Subtract(newfromloc, oldfromloc);
            }
            Point tooff = new Point(0, 0);
            if (to != null) {
              Point oldtoloc = new Point();
              if (parts.TryGetValue(to, out info)) oldtoloc = info.Point;
              Point newtoloc = to.Location;
              tooff = Geo.Subtract(newtoloc, oldtoloc);
            }
            if (from != null && to != null) {  // connected on both ends
              // if both ends moved the same amount, can keep the original route
              if (Geo.IsApprox(fromoff, tooff)) {
                Point oldlinkoff = kvp.Value.Point;
                Point linkoff = Geo.Subtract(fromoff, oldlinkoff);
                parts[link] = new Info() { Point = fromoff };
                route.MovePoints(linkoff);
              } else {  // don't try to maintain shape of path
                route.SuspendsRouting = false;
                route.InvalidateRoute();
              }
            } else {  // only one or neither end is connected
              Point oldlinkoff = kvp.Value.Point;
              Point off;
              if (from != null) off = fromoff;
              else if (to != null) off = tooff;
              else off = offset;
              parts[link] = new Info() { Point = off };
              route.MovePoints(Geo.Subtract(off, oldlinkoff));
            }
          }
        } else {  // move explicitly if partly or fully disconnected
          if (link.FromNode == null || link.ToNode == null) {
            Point oldlinkoff = kvp.Value.Point;
            parts[link] = new Info() { Point = offset };
            route.MovePoints(Geo.Subtract(offset, oldlinkoff));
          }
        }
      }

      if (!wassuspended) ResumeRouting(parts);
    }
Exemplo n.º 16
0
    private void AddCopies(bool undoable) {
      if (this.CopiedParts == null) {
        Diagram diagram = this.Diagram;
        if (diagram == null || diagram.IsReadOnly /* || !diagram.AllowInsert */) return;
        IDiagramModel model = diagram.Model;  // this model must support the data
        if (model == null) return;
        PartManager mgr = diagram.PartManager;
        if (mgr == null) return;
        if (this.DraggedParts == null) return;
        RestoreOriginalLocations();
        mgr.TemporaryParts = !undoable;
        model.SkipsUndoManager = !undoable;

        this.StartPoint = diagram.FirstMousePointInModel;
        ICopyDictionary dict = CopyParts(model);
        IDataCollection copieddata = dict.Copies;

        Dictionary<Part, Info> copiedparts = new Dictionary<Part, Info>();
        foreach (Node n in this.DraggedParts.Keys.OfType<Node>().Where(CanCopyNode)) {
          Node c = mgr.FindNodeForData(dict.FindCopiedNode(n.Data), model);
          if (c != null) {
            copiedparts[c] = new Info() { Point = n.Location };
          }
        }
        foreach (Link l in mgr.FindLinksForData(copieddata)) {
          copiedparts[l] = new Info();
        }
        this.CopiedParts = copiedparts;

        mgr.TemporaryParts = false;

        CheckForDraggedLink(copiedparts.Keys);
        if (this.DraggedLink != null) {
          Route route = this.DraggedLink.Route;
          Rect b = Geo.Bounds(route.Points);
          Point off = new Point(this.StartPoint.X - (b.X+b.Width/2),
                                this.StartPoint.Y - (b.Y+b.Height/2));
          route.MovePoints(off);
        }
      }
    }
Exemplo n.º 17
0
 private void GatherMembers(Dictionary<Part, Info> map, Part p, bool dragging) {
   if (map.ContainsKey(p)) return;
   // only check CanMove or CanCopy when dragging interactively, because this is the Diagram.CurrentTool
   if (dragging && !p.CanMove() && !p.CanCopy()) return;
   Node n = p as Node;
   if (n != null) {
     map[n] = new Info() { Point = n.Location };
     if (((int)this.Inclusions & 1 /*?? EffectiveCollectionInclusions.Members */) != 0) {
       Group g = n as Group;
       if (g != null) {
         foreach (Node c in g.MemberNodes) {
           GatherMembers(map, c, dragging);
         }
         foreach (Link c in g.MemberLinks) {
           GatherMembers(map, c, dragging);
         }
       }
     }
     if (((int)this.Inclusions & 2 /*?? EffectiveCollectionInclusions.ConnectingLinks */) != 0) {
       foreach (Link l in n.LinksConnected) {
         if (map.ContainsKey(l)) continue;
         Node from = l.FromNode;
         Node to = l.ToNode;
         //??? NOTMOVABLELINK
         if (from != null && map.ContainsKey(from) && to != null && map.ContainsKey(to)) {
           GatherMembers(map, l, dragging);
         }
       }
     }
     if ((this.Inclusions & EffectiveCollectionInclusions.TreeChildren) != 0) {
       Diagram diagram = n.Diagram;
       var nodes = (diagram != null && diagram.TreePath == Northwoods.GoXam.Layout.TreePath.Source) ? n.NodesInto : n.NodesOutOf;
       foreach (Node c in nodes) {
         GatherMembers(map, c, dragging);
       }
     }
   } else {
     Link l = p as Link;
     if (l != null) {
       map[l] = new Info();
       if (((int)this.Inclusions & 4 /*?? EffectiveCollectionInclusions.LinkLabelNodes */) != 0) {
         Node lab = l.LabelNode;
         if (lab != null) {
           GatherMembers(map, lab, dragging);
         }
       }
     }
   }
 }
Exemplo n.º 18
0
    private void AddCopies(IEnumerable<Part> originals, bool undoable) {
      if (this.CopiedParts == null) {
        Diagram diagram = this.Diagram;
        if (diagram == null || diagram.IsReadOnly /* || !diagram.AllowInsert */) return;
        IDiagramModel model = diagram.Model;
        if (model == null) return;
        PartManager mgr = diagram.PartManager;
        if (mgr == null) return;
        mgr.TemporaryParts = !undoable;
        model.SkipsUndoManager = !undoable;

        this.StartPoint = diagram.LastMousePointInModel;
        ICopyDictionary dict = mgr.CopyParts(originals, model);
        IDataCollection copieddata = dict.Copies;

        Rect bounds = DiagramPanel.ComputeLocations(originals.OfType<Node>());
        Point mid = new Point(bounds.X+bounds.Width/2, bounds.Y+bounds.Height/2);
        Point loc = this.StartPoint;

        Dictionary<Part, Info> copiedparts = new Dictionary<Part, Info>();
        foreach (Node n in originals.OfType<Node>().Where(CanCopyNode)) {
          Node c = mgr.FindNodeForData(dict.FindCopiedNode(n.Data), model);
          if (c != null) {
            Point l = n.Location;
            c.Location = new Point(loc.X - (mid.X - l.X), loc.Y - (mid.Y - l.Y));
            copiedparts[c] = new Info() { Point = c.Location };
          }
        }
        foreach (Link l in mgr.FindLinksForData(copieddata)) {
          copiedparts[l] = new Info();
        }
        this.CopiedParts = copiedparts;

        mgr.TemporaryParts = false;

        CheckForDraggedLink(copiedparts.Keys);
        if (this.DraggedLink != null) {
          Route route = this.DraggedLink.Route;
          Rect b = Geo.Bounds(route.Points);
          Point off = new Point(this.StartPoint.X - (b.X+b.Width/2),
                                this.StartPoint.Y - (b.Y+b.Height/2));
          route.MovePoints(off);
        }
      }
    }
Exemplo n.º 19
0
 // Determines if the historic file is in the primary archive location (not offloaded).
 private bool IsNewHistoricArchiveFile(Info fileInfo, string fileName)
 {
     return ((object)fileInfo != null &&
             string.Compare(FilePath.GetDirectoryName(fileName), FilePath.GetDirectoryName(fileInfo.FileName), StringComparison.OrdinalIgnoreCase) == 0);
 }
Exemplo n.º 20
0
 private bool FindHistoricArchiveFileForWrite(Info fileInfo, TimeTag searchTime)
 {
     return ((object)fileInfo != null &&
             searchTime.CompareTo(fileInfo.StartTimeTag) >= 0 &&
             searchTime.CompareTo(fileInfo.EndTimeTag) <= 0);
 }
Exemplo n.º 21
0
 private bool FindHistoricArchiveFileForRead(Info fileInfo, TimeTag startTime, TimeTag endTime)
 {
     return ((object)fileInfo != null &&
         ((startTime.CompareTo(fileInfo.StartTimeTag) >= 0 && startTime.CompareTo(fileInfo.EndTimeTag) <= 0) ||
         (endTime.CompareTo(fileInfo.StartTimeTag) >= 0 && endTime.CompareTo(fileInfo.EndTimeTag) <= 0) ||
         (startTime.CompareTo(fileInfo.StartTimeTag) < 0 && endTime.CompareTo(fileInfo.EndTimeTag) > 0)));
 }
Exemplo n.º 22
0
 private void showInfo(Info minfo)
 {
     String info_str = "Infomation:\n";
     if (minfo.untestedWords < 0)
     {
         minfo.untestedWords = 0;
         return;
     }
     if (minfo.rightWords + minfo.wrongWords > minfo.totalWords)
     {
         return;
     }
     info_str += "Total Words:" + minfo.totalWords + "\n";
     info_str += "Untested Words:" + minfo.untestedWords + "\n";
     info_str += "Right Words:" + minfo.rightWords + "\n";
     info_str += "Wrong Words:" + minfo.wrongWords + "\n";
     labelInfo.Text = info_str;
 }
		public static string ReplaceText(string text, Info oldInfo, Info newInfo) {

			return FlowTemplateGenerator.ReplaceText(text, oldInfo, newInfo);

		}
Exemplo n.º 24
0
        private void exportWord_ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Info info = new Info(lab.dayDuration * lab.laboriousness, lab.N, 5, lab.Pp, lab.Kn, lab.Knp, lab.K1, lab.K2, lab.K3, lab.laboriousness);

            try
            {
                WordDocument document = new WordDocument(Application.StartupPath + "\\Resources\\report_template.dotx");
                document.ReportGeneration(info);
            }
            catch (Exception error)
            {
                MessageBox.Show("Ошибка экспорта в Microsoft Office Word.\n" + error, "Не удалось открыть файл", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Exemplo n.º 25
0
        private Info GetHistoricFileInfo(string fileName)
        {
            Info fileInfo = null;
            try
            {
                if (File.Exists(fileName))
                {
                    // We'll open the file and get relevant information about it.
                    ArchiveFile historicArchiveFile = new ArchiveFile();
                    historicArchiveFile.FileName = fileName;
                    historicArchiveFile.StateFile = m_stateFile;
                    historicArchiveFile.IntercomFile = m_intercomFile;
                    historicArchiveFile.MetadataFile = m_metadataFile;
                    try
                    {
                        historicArchiveFile.Open();
                        fileInfo = new Info();
                        fileInfo.FileName = fileName;
                        fileInfo.StartTimeTag = historicArchiveFile.Fat.FileStartTime;
                        fileInfo.EndTimeTag = historicArchiveFile.Fat.FileEndTime;
                    }
                    catch (Exception)
                    {

                    }
                    finally
                    {
                        historicArchiveFile.Dispose();
                        historicArchiveFile = null;
                    }
                }
                else
                {
                    // We'll resolve to getting the file information from its name only if the file no longer exists
                    // at the location. This will be the case when file is moved to a different location. In this
                    // case the file information we provide is only as good as the file name.
                    string datesString = FilePath.GetFileNameWithoutExtension(fileName).Substring((FilePath.GetFileNameWithoutExtension(m_fileName) + "_").Length);
                    string[] fileStartEndDates = datesString.Split(new string[] { "_to_" }, StringSplitOptions.None);

                    fileInfo = new Info();
                    fileInfo.FileName = fileName;
                    if (fileStartEndDates.Length == 2)
                    {
                        fileInfo.StartTimeTag = new TimeTag(Convert.ToDateTime(fileStartEndDates[0].Replace('!', ':')));
                        fileInfo.EndTimeTag = new TimeTag(Convert.ToDateTime(fileStartEndDates[1].Replace('!', ':')));
                    }
                }
            }
            catch (Exception)
            {

            }

            return fileInfo;
        }
Exemplo n.º 26
0
 public InfoViewModel(Info _info)
     : this(_info, null)
 {
 }
Exemplo n.º 27
0
 private bool FindHistoricArchiveFileForWrite(Info fileInfo)
 {
     return (fileInfo != null &&
             m_writeSearchTimeTag >= fileInfo.StartTimeTag &&
             m_writeSearchTimeTag <= fileInfo.EndTimeTag);
 }
Exemplo n.º 28
0
 public void ShowVersion(Info version)
 {
     string clientVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
     toolStripStatus.Text = string.Format("{0}, Сервер: {1}, Клиент: {2}", version.DbVersion,
         version.ServerVersion, clientVersion);
     serverNameTb.Text = version.ServerName;
     dbNameTb.Text = version.DbName;
     clientNameTb.Text = Environment.MachineName;
     serverVersionTb.Text = version.ServerVersion;
     dbVersionTb.Text = version.DbVersion;
     clientVersionTb.Text = clientVersion;
 }
Exemplo n.º 29
0
 private bool IsOldHistoricArchiveFile(Info fileInfo)
 {
     return (fileInfo != null &&
             !string.IsNullOrEmpty(m_fileOffloadLocation) &&
             string.Compare(FilePath.GetDirectoryName(m_fileOffloadLocation), FilePath.GetDirectoryName(fileInfo.FileName), true) == 0);
 }
Exemplo n.º 30
0
        // Read data implementation
        private IEnumerable<IDataPoint> ReadData(IEnumerable<int> historianIDs, TimeTag startTime, TimeTag endTime, IDataPoint resumeFrom, bool timeSorted)
        {
            // Yield to archive rollover process.
            m_rolloverWaitHandle.WaitOne();

            // Ensure that the current file is open.
            if (!IsOpen)
                throw new InvalidOperationException(string.Format("\"{0}\" file is not open", m_fileName));

            // Ensure that the current file is active.
            if (m_fileType != ArchiveFileType.Active)
                throw new InvalidOperationException("Data can only be directly read from files that are Active");

            // Ensure that the start and end time are valid.
            if (startTime.CompareTo(endTime) > 0)
                throw new ArgumentException("End Time precedes Start Time in the specified time span");

            List<Info> dataFiles = new List<Info>();
            bool pendingRollover = false;
            bool usingActiveFile = false;

            if (startTime.CompareTo(m_fat.FileStartTime) < 0)
            {
                // Data is to be read from historic file(s) - make sure that the list has been built
                if (m_buildHistoricFileListThread.IsAlive)
                    m_buildHistoricFileListThread.Join();

                lock (m_historicArchiveFiles)
                {
                    dataFiles.AddRange(m_historicArchiveFiles.FindAll(info => FindHistoricArchiveFileForRead(info, startTime, endTime)));
                }
            }

            if (endTime.CompareTo(m_fat.FileStartTime) >= 0)
            {
                // Data is to be read from the active file.
                Info activeFileInfo = new Info(m_fileName)
                {
                    StartTimeTag = m_fat.FileStartTime,
                    EndTimeTag = m_fat.FileEndTime
                };

                dataFiles.Add(activeFileInfo);
            }

            // Read data from all qualifying files.
            foreach (Info dataFile in dataFiles)
            {
                ArchiveFile file = null;

                try
                {
                    if (string.Compare(dataFile.FileName, m_fileName, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        // Read data from current file.
                        usingActiveFile = true;
                        file = this;

                        // Atomically increment total number of readers for active file
                        Interlocked.Increment(ref m_activeFileReaders);

                        // Handle race conditions between rollover
                        // and incrementing the active readers
                        while (m_rolloverInProgress)
                        {
                            Interlocked.Decrement(ref m_activeFileReaders);
                            m_rolloverWaitHandle.WaitOne();
                            Interlocked.Increment(ref m_activeFileReaders);
                        }
                    }
                    else
                    {
                        // Read data from historic file.
                        usingActiveFile = false;
                        file = new ArchiveFile();
                        file.FileName = dataFile.FileName;
                        file.StateFile = m_stateFile;
                        file.IntercomFile = m_intercomFile;
                        file.MetadataFile = m_metadataFile;
                        file.FileAccessMode = FileAccess.Read;
                        file.Open();
                    }

                    // Create new data point scanner for the desired points in this file and given time range
                    IArchiveFileScanner scanner;

                    if (timeSorted)
                        scanner = new TimeSortedArchiveFileScanner();
                    else
                        scanner = new ArchiveFileScanner();

                    scanner.FileAllocationTable = file.Fat;
                    scanner.HistorianIDs = historianIDs;
                    scanner.StartTime = startTime;
                    scanner.EndTime = endTime;
                    scanner.ResumeFrom = resumeFrom;
                    scanner.DataReadExceptionHandler = (sender, e) => OnDataReadException(e.Argument);

                    // Reset resumeFrom to scan from beginning after picking up where left off from roll over
                    resumeFrom = null;

                    // Return data points
                    foreach (IDataPoint dataPoint in scanner.Read())
                    {
                        yield return dataPoint;

                        // If a rollover needs to happen, we need to relinquish read lock and close file
                        if (m_rolloverInProgress)
                        {
                            resumeFrom = dataPoint;
                            pendingRollover = true;
                            break;
                        }
                    }
                }
                finally
                {
                    if (usingActiveFile)
                    {
                        // Atomically decrement active file reader count to signal in-process code that read is complete or yielded
                        Interlocked.Decrement(ref m_activeFileReaders);
                    }
                    else if ((object)file != null)
                    {
                        file.Dispose();
                    }
                }

                if (pendingRollover)
                    break;
            }

            if (pendingRollover)
            {
                // Recurse into this function with an updated start time and last read point ID so that read can
                // resume right where it left off - recursed function call will wait until rollover is complete
                foreach (IDataPoint dataPoint in ReadData(historianIDs, startTime, endTime, resumeFrom, timeSorted))
                {
                    yield return dataPoint;
                }
            }
        }