Esempio n. 1
0
    public void Open(Pfm.MarshallerOpenOp op)
    {
        string[] nameParts         = op.NameParts();
        int      createFileType    = op.CreateFileType();
        long     newExistingOpenId = op.NewExistingOpenId();
        int      perr    = 0;
        bool     existed = false;

        Pfm.OpenAttribs openAttribs  = new Pfm.OpenAttribs();
        long            parentFileId = 0;
        string          endName      = null;

        if (nameParts.Length == 0)
        {
            if (folderOpenId == 0)
            {
                folderOpenId = newExistingOpenId;
            }
            existed                      = true;
            openAttribs.openId           = folderOpenId;
            openAttribs.openSequence     = 1;
            openAttribs.accessLevel      = Pfm.accessLevelReadData;
            openAttribs.attribs.fileType = Pfm.fileTypeFolder;
            openAttribs.attribs.fileId   = helloRootId;
        }
        else if (nameParts.Length == 1)
        {
            if (nameParts[0].ToLowerInvariant() != helloFileName.ToLowerInvariant())
            {
                perr = Pfm.errorNotFound;
            }
            else
            {
                if (fileOpenId == 0)
                {
                    fileOpenId = newExistingOpenId;
                }
                existed                      = true;
                openAttribs.openId           = fileOpenId;
                openAttribs.openSequence     = 1;
                openAttribs.accessLevel      = Pfm.accessLevelReadData;
                openAttribs.attribs.fileType = Pfm.fileTypeFile;
                openAttribs.attribs.fileId   = helloFileId;
                openAttribs.attribs.fileSize = helloFileData.Length;
                endName                      = helloFileName;
            }
        }
        else
        {
            perr = Pfm.errorParentNotFound;
        }
        if (perr == Pfm.errorNotFound && createFileType != 0)
        {
            perr = Pfm.errorAccessDenied;
        }

        op.Complete(perr, existed, openAttribs, parentFileId, endName, 0, null, 0, null);
    }
Esempio n. 2
0
    // Pfm.FormatterDispatch.Open
    // Open existing file, or create new file.
    public void Open(Pfm.MarshallerOpenOp op)
    {
        string[] nameParts         = op.NameParts();
        int      createFileType    = op.CreateFileType();
        int      createFileFlags   = op.CreateFileFlags();
        long     writeTime         = op.WriteTime();
        long     newCreateOpenId   = op.NewCreateOpenId();
        long     newExistingOpenId = op.NewExistingOpenId();
        int      perr;
        bool     existed = false;

        Pfm.OpenAttribs openAttribs  = new Pfm.OpenAttribs();
        long            parentFileId = 0;
        string          endName      = null;

        File parent;
        File file;

        perr = FileFindName(nameParts, out parent, out file, out endName);
        if (perr == 0)
        {
            existed = true;
            if (parent != null)
            {
                parentFileId = parent.fileId;
            }
            if (file.openId == 0)
            {
                file.openId = newExistingOpenId;
            }
            FileOpened(file, ref openAttribs);
        }
        else if (perr == Pfm.errorNotFound && createFileType != Pfm.fileTypeNone)
        {
            file = new File(createFileType, createFileFlags, writeTime);
            FileNameAdd(parent, writeTime, endName, file);
            file.openId = newCreateOpenId;
            FileOpened(file, ref openAttribs);
            parentFileId = parent.fileId;
            perr         = 0;
        }

        op.Complete(perr, existed, openAttribs, parentFileId, endName, 0, null, 0, null);
    }
Esempio n. 3
0
        public void Open(Pfm.MarshallerOpenOp op)
        {
            int  perr    = 0;
            bool existed = false;

            Pfm.OpenAttribs openAttribs       = new Pfm.OpenAttribs();
            long            parentFileId      = 0;
            string          endName           = null;
            long            newExistingOpenId = op.NewExistingOpenId();

            var names = op.NameParts();

            string des = "open:opennedid:" + opennedid.ToString() + ";names:" + String.Join(";", names);

            Debug.WriteLine(des);

            if (names.Length == 0)
            {
                if (opennedid == 0)
                {
                    opennedid = newExistingOpenId;
                    Entry entry = new Entry();
                    entry.isdir = 1;
                    opens.Add(opennedid, entry);
                }
                existed                      = true;
                openAttribs.openId           = opennedid;
                openAttribs.openSequence     = 1;
                openAttribs.accessLevel      = Pfm.accessLevelReadData;
                openAttribs.attribs.fileId   = GetFileId(opens[opennedid]);
                openAttribs.attribs.fileType = Pfm.fileTypeFolder;
            }
            else// if (names.Length == 1)
            {
                Entry entry = GetEntryByName(names);
                if (entry == null)
                {
                    perr = Pfm.errorNotFound;
                }
                else
                {
                    long id = GetOpenId(entry, newExistingOpenId);
                    existed                      = true;
                    openAttribs.openId           = id;
                    openAttribs.openSequence     = 1;
                    openAttribs.accessLevel      = Pfm.accessLevelReadData;
                    openAttribs.attribs.fileType = entry.isdir != 0 ? Pfm.fileTypeFolder : Pfm.fileTypeFile;
                    openAttribs.attribs.fileId   = GetFileId(entry);
                    openAttribs.attribs.fileSize = entry.size;
                    SetAttTime(ref openAttribs.attribs, entry);

                    endName = entry.server_filename;
                }
            }
            //else
            //{
            //    Debug.WriteLine(string.Format("opendId:{0},names:{1}", opennedid, String.Join(";", names)));
            //    perr = Pfm.errorParentNotFound;
            //}
            op.Complete(perr, existed, openAttribs, parentFileId, endName, 0, null, 0, null);
        }