コード例 #1
0
        public int writeToArray(List <sbyte> newData)
        {       //returns time of operation of -1 in case of failure
            DateTime start, end;

            start = DateTime.Now;

            if (newData.Capacity > arrayCapacity)
            {
                return(-1);
            }
            int hdd     = 0; //disk number
            int mem     = 0; //memory slot number
            int counter = 0;

            do
            {
                if (array.getDisk(hdd).getFreeSpace() >= 1)
                {
                    if (array.getDisk(hdd).getState())
                    {
                        if (counter == 2)
                        {
                            array.getDisk(hdd).writeToEnd(xor(hdd - 1, hdd - 2, mem, mem));
                            counter = 0;
                            hdd++;
                        }
                        else
                        {
                            array.getDisk(hdd).writeToEnd(newData.ElementAt(mem));
                            counter++;
                            hdd++;
                        }
                    }
                    else
                    {
                        return(-1);
                    }
                    if (hdd >= array.Count)
                    {
                        hdd = 0;
                        mem++;
                        if (mem >= array.getDisk(0).getSize())
                        {
                            return(-128);
                        }
                    }
                }
            } while (mem < newData.Count);

            end = DateTime.Now;
            TimeSpan resultTime = end - start;

            return(resultTime.Seconds * 1000 + resultTime.Milliseconds + Convert.ToInt32(array.getWriteLatency(0)));
        }
コード例 #2
0
ファイル: raid0.cs プロジェクト: hutoroff/raidModel
        public int writeToArray(List <sbyte> newData)
        {
            DateTime start, end;

            start = DateTime.Now;

            if (isEnoughDisks() == 0)
            {
                return(-1);
            }
            if (newData.Capacity > arrayCapacity)
            {
                return(-1);
            }
            int mem = 0;
            int hdd = 0;

            do
            {
                if (array.getDisk(hdd).getFreeSpace() >= 1)
                {
                    if (array.getDiskState(hdd))
                    {
                        if (array.writeToDisk(hdd, newData.ElementAt(mem)) == 1)
                        {
                            return(-1);
                        }
                        hdd++;
                        if (hdd >= array.Count)
                        {
                            hdd = 0;
                            mem++;
                            if (mem >= array.getDisk(0).getSize())
                            {
                                return(-1);
                            }
                        }
                    }
                    else
                    {
                        return(-1);
                    }
                }
                else
                {
                    return(-1);
                }
            } while (mem < newData.Count);

            end = DateTime.Now;
            TimeSpan resultTime = end - start;

            return(resultTime.Seconds * 1000 + resultTime.Milliseconds + Convert.ToInt32(array.getWriteLatency(0)));
        }
コード例 #3
0
ファイル: raid1.cs プロジェクト: hutoroff/raidModel
        public int writeToArray(List <sbyte> newData)
        {       //returns time of operation of -1 in case of failure
            DateTime start, end;

            start = DateTime.Now;

            if (newData.Capacity > arrayCapacity)
            {
                return(-1);
            }
            int mem = 0;
            int hdd = 0;

            while (mem < newData.Count())
            {
                if (array.getDisk(hdd).getFreeSpace() >= 1)
                {
                    bool failure = false;
                    if (array.getDisk(hdd).getState())                                //if first disk OK
                    {
                        array.getDisk(hdd).writeToEnd(newData.ElementAt(mem));        //write to it
                    }
                    else
                    {
                        failure = true;
                    }

                    if (array.getDisk(hdd + 1).getState())                              //if second disk OK
                    {
                        array.getDisk(hdd + 1).writeToEnd(newData.ElementAt(mem));      //write mirror to it
                    }
                    else
                    {
                        failure = true;
                    }

                    if (failure)
                    {
                        if (array.Count >= hdd + 2)
                        {
                            hdd += 2;
                        }
                        else
                        {
                            return(-1);
                        }
                    }
                    else
                    {
                        mem++;
                    }
                }
                else
                {
                    if (array.Count >= hdd + 2 && array.getDisk(hdd + 2).getFreeSpace() >= 1)
                    {
                        hdd += 2;
                        array.getDisk(hdd).writeToEnd(newData.ElementAt(mem));
                        array.getDisk(hdd + 1).writeToEnd(newData.ElementAt(mem));
                        mem++;
                    }
                    else
                    {
                        return(-1);
                    }
                }
            }

            end = DateTime.Now;
            TimeSpan resultTime = end - start;

            return((resultTime.Seconds * 1000 + resultTime.Milliseconds + Convert.ToInt32(array.getWriteLatency(0))) * 4);
        }